remove static functions from System class

This commit is contained in:
proddy
2021-03-01 22:21:18 +01:00
parent a092d83fad
commit ea5b6e5c58
17 changed files with 62 additions and 37 deletions

View File

@@ -1,5 +1,7 @@
#include <APSettingsService.h> #include <APSettingsService.h>
#include "../../src/emsesp_stub.hpp" // proddy added
APSettingsService::APSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager) APSettingsService::APSettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
: _httpEndpoint(APSettings::read, APSettings::update, this, server, AP_SETTINGS_SERVICE_PATH, securityManager) : _httpEndpoint(APSettings::read, APSettings::update, this, server, AP_SETTINGS_SERVICE_PATH, securityManager)
, _fsPersistence(APSettings::read, APSettings::update, this, fs, AP_SETTINGS_FILE) , _fsPersistence(APSettings::read, APSettings::update, this, fs, AP_SETTINGS_FILE)
@@ -21,7 +23,7 @@ void APSettingsService::reconfigureAP() {
void APSettingsService::loop() { void APSettingsService::loop() {
// if we have an ETH connection, quit // if we have an ETH connection, quit
if (emsesp::System::ethernet_connected()) { if (emsesp::EMSESP::system_.ethernet_connected()) {
return; return;
} }
unsigned long currentMillis = uuid::get_uptime(); unsigned long currentMillis = uuid::get_uptime();
@@ -51,8 +53,8 @@ void APSettingsService::startAP() {
WiFi.softAP(_state.ssid.c_str(), _state.password.c_str()); WiFi.softAP(_state.ssid.c_str(), _state.password.c_str());
if (!_dnsServer) { if (!_dnsServer) {
IPAddress apIp = WiFi.softAPIP(); IPAddress apIp = WiFi.softAPIP();
Serial.print(F("Starting captive portal on ")); // Serial.print(F("Starting captive portal on "));
Serial.println(apIp); // Serial.println(apIp);
_dnsServer = new DNSServer; _dnsServer = new DNSServer;
_dnsServer->start(DNS_PORT, "*", apIp); _dnsServer->start(DNS_PORT, "*", apIp);
} }
@@ -60,7 +62,7 @@ void APSettingsService::startAP() {
void APSettingsService::stopAP() { void APSettingsService::stopAP() {
if (_dnsServer) { if (_dnsServer) {
Serial.println(F("Stopping captive portal")); // Serial.println(F("Stopping captive portal"));
_dnsServer->stop(); _dnsServer->stop();
delete _dnsServer; delete _dnsServer;
_dnsServer = nullptr; _dnsServer = nullptr;

View File

@@ -8,9 +8,7 @@
#include <DNSServer.h> #include <DNSServer.h>
#include <IPAddress.h> #include <IPAddress.h>
#include <uuid/common.h> #include <uuid/common.h> // proddy added for get_uptime()
#include "../../src/system.h" // proddy added
#define MANAGE_NETWORK_DELAY 10000 #define MANAGE_NETWORK_DELAY 10000

View File

@@ -5,7 +5,6 @@
#include <AsyncTCP.h> #include <AsyncTCP.h>
#include <WiFi.h> #include <WiFi.h>
#include <ETH.h>
#include <FeaturesService.h> #include <FeaturesService.h>
#include <APSettingsService.h> #include <APSettingsService.h>
@@ -25,9 +24,7 @@
#include <NetworkSettingsService.h> #include <NetworkSettingsService.h>
#include <NetworkStatus.h> #include <NetworkStatus.h>
#ifdef PROGMEM_WWW
#include <WWWData.h> #include <WWWData.h>
#endif
class ESP8266React { class ESP8266React {
public: public:

View File

@@ -1,13 +1,6 @@
#include <MqttSettingsService.h> #include <MqttSettingsService.h>
// forward declarators #include "../../src/emsesp_stub.hpp" // proddy added
namespace emsesp {
class EMSESP {
public:
static Mqtt mqtt_;
static DallasSensor dallassensor_;
};
} // namespace emsesp
/** /**
* Retains a copy of the cstr provided in the pointer provided using dynamic allocation. * Retains a copy of the cstr provided in the pointer provided using dynamic allocation.

View File

@@ -6,6 +6,7 @@
#include <FSPersistence.h> #include <FSPersistence.h>
#include <AsyncMqttClient.h> #include <AsyncMqttClient.h>
#include <ESPUtils.h> #include <ESPUtils.h>
#include <uuid/common.h> #include <uuid/common.h>
#define MQTT_RECONNECTION_DELAY 1000 #define MQTT_RECONNECTION_DELAY 1000
@@ -60,7 +61,6 @@ static String generateClientId() {
#define FACTORY_MQTT_MAX_TOPIC_LENGTH 128 #define FACTORY_MQTT_MAX_TOPIC_LENGTH 128
#endif #endif
#define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off #define EMSESP_DEFAULT_BOOL_FORMAT 1 // on/off
#define EMSESP_DEFAULT_DALLAS_FORMAT 1 // sensorid #define EMSESP_DEFAULT_DALLAS_FORMAT 1 // sensorid
#define EMSESP_DEFAULT_HA_CLIMATE_FORMAT 1 // current temp #define EMSESP_DEFAULT_HA_CLIMATE_FORMAT 1 // current temp
@@ -69,10 +69,6 @@ static String generateClientId() {
#define EMSESP_DEFAULT_HA_ENABLED false #define EMSESP_DEFAULT_HA_ENABLED false
#define EMSESP_DEFAULT_PUBLISH_TIME 10 #define EMSESP_DEFAULT_PUBLISH_TIME 10
#include "../../src/system.h"
#include "../../src/mqtt.h"
#include "../../src/dallassensor.h"
class MqttSettings { class MqttSettings {
public: public:
// host and port - if enabled // host and port - if enabled

View File

@@ -1,5 +1,7 @@
#include <MqttStatus.h> #include <MqttStatus.h>
#include "../../src/emsesp_stub.hpp" // proddy added
MqttStatus::MqttStatus(AsyncWebServer * server, MqttSettingsService * mqttSettingsService, SecurityManager * securityManager) MqttStatus::MqttStatus(AsyncWebServer * server, MqttSettingsService * mqttSettingsService, SecurityManager * securityManager)
: _mqttSettingsService(mqttSettingsService) { : _mqttSettingsService(mqttSettingsService) {
server->on(MQTT_STATUS_SERVICE_PATH, server->on(MQTT_STATUS_SERVICE_PATH,

View File

@@ -9,8 +9,6 @@
#include <ESPAsyncTCP.h> #include <ESPAsyncTCP.h>
#endif #endif
#include "../../src/mqtt.h" // proddy added
#include <MqttSettingsService.h> #include <MqttSettingsService.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <AsyncJson.h> #include <AsyncJson.h>

View File

@@ -1,5 +1,7 @@
#include <NetworkStatus.h> #include <NetworkStatus.h>
#include "../../src/emsesp_stub.hpp" // proddy added
NetworkStatus::NetworkStatus(AsyncWebServer * server, SecurityManager * securityManager) { NetworkStatus::NetworkStatus(AsyncWebServer * server, SecurityManager * securityManager) {
server->on(NETWORK_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&NetworkStatus::networkStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED)); server->on(NETWORK_STATUS_SERVICE_PATH, HTTP_GET, securityManager->wrapRequest(std::bind(&NetworkStatus::networkStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED));
} }
@@ -8,7 +10,7 @@ void NetworkStatus::networkStatus(AsyncWebServerRequest * request) {
AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_NETWORK_STATUS_SIZE); AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_NETWORK_STATUS_SIZE);
JsonObject root = response->getRoot(); JsonObject root = response->getRoot();
bool ethernet_connected = emsesp::System::ethernet_connected(); bool ethernet_connected = emsesp::EMSESP::system_.ethernet_connected();
wl_status_t wifi_status = WiFi.status(); wl_status_t wifi_status = WiFi.status();
// see if Ethernet is connected // see if Ethernet is connected

View File

@@ -4,7 +4,7 @@
#include <WiFi.h> #include <WiFi.h>
#include <AsyncTCP.h> #include <AsyncTCP.h>
#include "../../src/system.h" // proddy added #include <ETH.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <AsyncJson.h> #include <AsyncJson.h>

View File

@@ -1,5 +1,7 @@
#include <OTASettingsService.h> #include <OTASettingsService.h>
#include "../../src/emsesp_stub.hpp" // proddy added
OTASettingsService::OTASettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager) OTASettingsService::OTASettingsService(AsyncWebServer * server, FS * fs, SecurityManager * securityManager)
: _httpEndpoint(OTASettings::read, OTASettings::update, this, server, OTA_SETTINGS_SERVICE_PATH, securityManager) : _httpEndpoint(OTASettings::read, OTASettings::update, this, server, OTA_SETTINGS_SERVICE_PATH, securityManager)
, _fsPersistence(OTASettings::read, OTASettings::update, this, fs, OTA_SETTINGS_FILE) , _fsPersistence(OTASettings::read, OTASettings::update, this, fs, OTA_SETTINGS_FILE)
@@ -39,11 +41,11 @@ void OTASettingsService::configureArduinoOTA() {
_arduinoOTA->onStart([]() { _arduinoOTA->onStart([]() {
// Serial.println(F("Starting")); // Serial.println(F("Starting"));
emsesp::System::upload_status(true); emsesp::EMSESP::system_.upload_status(true);
}); });
_arduinoOTA->onEnd([]() { _arduinoOTA->onEnd([]() {
// Serial.println(F("\r\nEnd")); // Serial.println(F("\r\nEnd"));
emsesp::System::upload_status(false); emsesp::EMSESP::system_.upload_status(false);
}); });
// _arduinoOTA->onProgress([](unsigned int progress, unsigned int total) { // _arduinoOTA->onProgress([](unsigned int progress, unsigned int total) {

View File

@@ -13,8 +13,6 @@
#include <ArduinoOTA.h> #include <ArduinoOTA.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include "../../src/system.h" // proddy added
#ifndef FACTORY_OTA_PORT #ifndef FACTORY_OTA_PORT
#define FACTORY_OTA_PORT 8266 #define FACTORY_OTA_PORT 8266
#endif #endif

View File

@@ -2,6 +2,8 @@
#if FT_ENABLED(FT_SECURITY) #if FT_ENABLED(FT_SECURITY)
#include "../../src/emsesp_stub.hpp" // proddy added
SecuritySettingsService::SecuritySettingsService(AsyncWebServer * server, FS * fs) SecuritySettingsService::SecuritySettingsService(AsyncWebServer * server, FS * fs)
: _httpEndpoint(SecuritySettings::read, SecuritySettings::update, this, server, SECURITY_SETTINGS_PATH, this) : _httpEndpoint(SecuritySettings::read, SecuritySettings::update, this, server, SECURITY_SETTINGS_PATH, this)
, _fsPersistence(SecuritySettings::read, SecuritySettings::update, this, fs, SECURITY_SETTINGS_FILE) , _fsPersistence(SecuritySettings::read, SecuritySettings::update, this, fs, SECURITY_SETTINGS_FILE)

View File

@@ -6,8 +6,6 @@
#include <HttpEndpoint.h> #include <HttpEndpoint.h>
#include <FSPersistence.h> #include <FSPersistence.h>
#include "../../src/version.h" // added by proddy
#ifndef FACTORY_ADMIN_USERNAME #ifndef FACTORY_ADMIN_USERNAME
#define FACTORY_ADMIN_USERNAME "admin" #define FACTORY_ADMIN_USERNAME "admin"
#endif #endif

View File

@@ -12,7 +12,6 @@
#include <SecurityManager.h> #include <SecurityManager.h>
#include <uuid/log.h> // proddy added #include <uuid/log.h> // proddy added
#include "../../src/system.h" // proddy added
#define MAX_ESP_STATUS_SIZE 1024 #define MAX_ESP_STATUS_SIZE 1024
#define SYSTEM_STATUS_SERVICE_PATH "/rest/systemStatus" #define SYSTEM_STATUS_SERVICE_PATH "/rest/systemStatus"

View File

@@ -2,6 +2,8 @@
#if FT_ENABLED(FT_SECURITY) #if FT_ENABLED(FT_SECURITY)
#include "../../src/emsesp_stub.h" // proddy added
SecuritySettingsService::SecuritySettingsService(AsyncWebServer* server, FS* fs) : SecuritySettingsService::SecuritySettingsService(AsyncWebServer* server, FS* fs) :
_httpEndpoint(SecuritySettings::read, SecuritySettings::update, this, server, SECURITY_SETTINGS_PATH, this), _httpEndpoint(SecuritySettings::read, SecuritySettings::update, this, server, SECURITY_SETTINGS_PATH, this),
_fsPersistence(SecuritySettings::read, SecuritySettings::update, this, fs, SECURITY_SETTINGS_FILE), _fsPersistence(SecuritySettings::read, SecuritySettings::update, this, fs, SECURITY_SETTINGS_FILE),

View File

@@ -6,8 +6,6 @@
#include <HttpEndpoint.h> #include <HttpEndpoint.h>
#include <FSPersistence.h> #include <FSPersistence.h>
#include "../../src/version.h" // added by proddy
#ifndef FACTORY_ADMIN_USERNAME #ifndef FACTORY_ADMIN_USERNAME
#define FACTORY_ADMIN_USERNAME "admin" #define FACTORY_ADMIN_USERNAME "admin"
#endif #endif

38
src/emsesp_stub.hpp Normal file
View File

@@ -0,0 +1,38 @@
/*
* EMS-ESP - https://github.com/proddy/EMS-ESP
* Copyright 2020 Paul Derbyshire
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef EMSESP_EMSESP_STUB_H
#define EMSESP_EMSESP_STUB_H
// forward declarator
// used to bind EMS-ESP functions to external frameworks
#include "system.h"
#include "mqtt.h"
#include "dallassensor.h"
#include "version.h"
namespace emsesp {
class EMSESP {
public:
static Mqtt mqtt_;
static System system_;
static DallasSensor dallassensor_;
};
} // namespace emsesp
#endif