Browse Source
adopt explicit initialization - with the exception of trivial classes (#122)
master
rjwats
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with
31 additions and
16 deletions
-
lib/framework/APSettingsService.cpp
-
lib/framework/APSettingsService.h
-
lib/framework/FSPersistence.h
-
lib/framework/MqttSettingsService.cpp
-
lib/framework/MqttSettingsService.h
-
lib/framework/SecuritySettingsService.cpp
-
lib/framework/SecuritySettingsService.h
-
lib/framework/WiFiSettingsService.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); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -68,12 +68,12 @@ class APSettingsService : public StatefulService<APSettings> { |
|
|
|
HttpEndpoint<APSettings> _httpEndpoint; |
|
|
|
FSPersistence<APSettings> _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(); |
|
|
|
|
|
@ -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<T>* _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 |
|
|
|
|
|
@ -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), |
|
|
|
|
|
@ -121,19 +121,22 @@ class MqttSettingsService : public StatefulService<MqttSettings> { |
|
|
|
FSPersistence<MqttSettings> _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); |
|
|
|
|
|
@ -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); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -77,7 +77,7 @@ class SecuritySettingsService : public StatefulService<SecuritySettings>, public |
|
|
|
private: |
|
|
|
HttpEndpoint<SecuritySettings> _httpEndpoint; |
|
|
|
FSPersistence<SecuritySettings> _fsPersistence; |
|
|
|
ArduinoJsonJWT _jwtHandler = ArduinoJsonJWT(FACTORY_JWT_SECRET); |
|
|
|
ArduinoJsonJWT _jwtHandler; |
|
|
|
|
|
|
|
void configureJWTHandler(); |
|
|
|
|
|
|
|
|
|
@ -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) { |
|
|
|