From 4fa491e309d2e03d0e0490d252c54ddfc5d65890 Mon Sep 17 00:00:00 2001 From: rjwats Date: Thu, 21 May 2020 23:41:29 +0100 Subject: [PATCH] adopt explicit initialization - with the exception of trivial classes (#122) --- lib/framework/APSettingsService.cpp | 3 ++- lib/framework/APSettingsService.h | 6 +++--- lib/framework/FSPersistence.h | 5 +++-- lib/framework/MqttSettingsService.cpp | 10 +++++++++- lib/framework/MqttSettingsService.h | 15 +++++++++------ lib/framework/SecuritySettingsService.cpp | 3 ++- lib/framework/SecuritySettingsService.h | 2 +- lib/framework/WiFiSettingsService.cpp | 3 ++- 8 files changed, 31 insertions(+), 16 deletions(-) diff --git a/lib/framework/APSettingsService.cpp b/lib/framework/APSettingsService.cpp index b8ed252..980621f 100644 --- a/lib/framework/APSettingsService.cpp +++ b/lib/framework/APSettingsService.cpp @@ -8,7 +8,8 @@ APSettingsService::APSettingsService(AsyncWebServer* server, FS* fs, SecurityMan AP_SETTINGS_SERVICE_PATH, securityManager), _fsPersistence(APSettings::serialize, APSettings::deserialize, this, fs, AP_SETTINGS_FILE), - _dnsServer(nullptr) { + _dnsServer(nullptr), + _lastManaged(0) { addUpdateHandler([&](const String& originId) { reconfigureAP(); }, false); } diff --git a/lib/framework/APSettingsService.h b/lib/framework/APSettingsService.h index ec82b73..2366183 100644 --- a/lib/framework/APSettingsService.h +++ b/lib/framework/APSettingsService.h @@ -68,12 +68,12 @@ class APSettingsService : public StatefulService { HttpEndpoint _httpEndpoint; FSPersistence _fsPersistence; - // for the mangement delay loop - unsigned long _lastManaged; - // for the captive portal DNSServer* _dnsServer; + // for the mangement delay loop + unsigned long _lastManaged; + void reconfigureAP(); void manageAP(); void startAP(); diff --git a/lib/framework/FSPersistence.h b/lib/framework/FSPersistence.h index 152f5b2..19b7ae8 100644 --- a/lib/framework/FSPersistence.h +++ b/lib/framework/FSPersistence.h @@ -20,7 +20,8 @@ class FSPersistence { _jsonDeserializer(jsonDeserializer), _statefulService(statefulService), _fs(fs), - _filePath(filePath) { + _filePath(filePath), + _updateHandlerId(0) { enableUpdateHandler(); } @@ -85,7 +86,7 @@ class FSPersistence { StatefulService* _statefulService; FS* _fs; char const* _filePath; - update_handler_id_t _updateHandlerId = 0; + update_handler_id_t _updateHandlerId; protected: // We assume the deserializer supplies sensible defaults if an empty object diff --git a/lib/framework/MqttSettingsService.cpp b/lib/framework/MqttSettingsService.cpp index b367377..29ce527 100644 --- a/lib/framework/MqttSettingsService.cpp +++ b/lib/framework/MqttSettingsService.cpp @@ -27,7 +27,15 @@ MqttSettingsService::MqttSettingsService(AsyncWebServer* server, FS* fs, Securit server, MQTT_SETTINGS_SERVICE_PATH, securityManager), - _fsPersistence(MqttSettings::serialize, MqttSettings::deserialize, this, fs, MQTT_SETTINGS_FILE) { + _fsPersistence(MqttSettings::serialize, MqttSettings::deserialize, this, fs, MQTT_SETTINGS_FILE), + _retainedHost(nullptr), + _retainedClientId(nullptr), + _retainedUsername(nullptr), + _retainedPassword(nullptr), + _reconfigureMqtt(false), + _disconnectedAt(0), + _disconnectReason(AsyncMqttClientDisconnectReason::TCP_DISCONNECTED), + _mqttClient() { #ifdef ESP32 WiFi.onEvent( std::bind(&MqttSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2), diff --git a/lib/framework/MqttSettingsService.h b/lib/framework/MqttSettingsService.h index c9aaf87..5535329 100644 --- a/lib/framework/MqttSettingsService.h +++ b/lib/framework/MqttSettingsService.h @@ -121,19 +121,22 @@ class MqttSettingsService : public StatefulService { FSPersistence _fsPersistence; // Pointers to hold retained copies of the mqtt client connection strings. - // Required as AsyncMqttClient holds refrences to the supplied connection strings. - char* _retainedHost = nullptr; - char* _retainedClientId = nullptr; - char* _retainedUsername = nullptr; - char* _retainedPassword = nullptr; + // This is required as AsyncMqttClient holds refrences to the supplied connection strings. + char* _retainedHost; + char* _retainedClientId; + char* _retainedUsername; + char* _retainedPassword; - AsyncMqttClient _mqttClient; + // variable to help manage connection bool _reconfigureMqtt; unsigned long _disconnectedAt; // connection status AsyncMqttClientDisconnectReason _disconnectReason; + // the MQTT client instance + AsyncMqttClient _mqttClient; + #ifdef ESP32 void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info); void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info); diff --git a/lib/framework/SecuritySettingsService.cpp b/lib/framework/SecuritySettingsService.cpp index 30b6940..cc01ded 100644 --- a/lib/framework/SecuritySettingsService.cpp +++ b/lib/framework/SecuritySettingsService.cpp @@ -7,7 +7,8 @@ SecuritySettingsService::SecuritySettingsService(AsyncWebServer* server, FS* fs) server, SECURITY_SETTINGS_PATH, this), - _fsPersistence(SecuritySettings::serialize, SecuritySettings::deserialize, this, fs, SECURITY_SETTINGS_FILE) { + _fsPersistence(SecuritySettings::serialize, SecuritySettings::deserialize, this, fs, SECURITY_SETTINGS_FILE), + _jwtHandler(FACTORY_JWT_SECRET) { addUpdateHandler([&](const String& originId) { configureJWTHandler(); }, false); } diff --git a/lib/framework/SecuritySettingsService.h b/lib/framework/SecuritySettingsService.h index 5db6a94..97c7f00 100644 --- a/lib/framework/SecuritySettingsService.h +++ b/lib/framework/SecuritySettingsService.h @@ -77,7 +77,7 @@ class SecuritySettingsService : public StatefulService, public private: HttpEndpoint _httpEndpoint; FSPersistence _fsPersistence; - ArduinoJsonJWT _jwtHandler = ArduinoJsonJWT(FACTORY_JWT_SECRET); + ArduinoJsonJWT _jwtHandler; void configureJWTHandler(); diff --git a/lib/framework/WiFiSettingsService.cpp b/lib/framework/WiFiSettingsService.cpp index 42c96eb..0f4442b 100644 --- a/lib/framework/WiFiSettingsService.cpp +++ b/lib/framework/WiFiSettingsService.cpp @@ -7,7 +7,8 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit server, WIFI_SETTINGS_SERVICE_PATH, securityManager), - _fsPersistence(WiFiSettings::serialize, WiFiSettings::deserialize, this, fs, WIFI_SETTINGS_FILE) { + _fsPersistence(WiFiSettings::serialize, WiFiSettings::deserialize, this, fs, WIFI_SETTINGS_FILE), + _lastConnectionAttempt(0) { // We want the device to come up in opmode=0 (WIFI_OFF), when erasing the flash this is not the default. // If needed, we save opmode=0 before disabling persistence so the device boots with WiFi disabled in the future. if (WiFi.getMode() != WIFI_OFF) {