adopt explicit initialization - with the exception of trivial classes (#122)
This commit is contained in:
parent
db0d98d425
commit
4fa491e309
@ -8,7 +8,8 @@ APSettingsService::APSettingsService(AsyncWebServer* server, FS* fs, SecurityMan
|
|||||||
AP_SETTINGS_SERVICE_PATH,
|
AP_SETTINGS_SERVICE_PATH,
|
||||||
securityManager),
|
securityManager),
|
||||||
_fsPersistence(APSettings::serialize, APSettings::deserialize, this, fs, AP_SETTINGS_FILE),
|
_fsPersistence(APSettings::serialize, APSettings::deserialize, this, fs, AP_SETTINGS_FILE),
|
||||||
_dnsServer(nullptr) {
|
_dnsServer(nullptr),
|
||||||
|
_lastManaged(0) {
|
||||||
addUpdateHandler([&](const String& originId) { reconfigureAP(); }, false);
|
addUpdateHandler([&](const String& originId) { reconfigureAP(); }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,12 +68,12 @@ class APSettingsService : public StatefulService<APSettings> {
|
|||||||
HttpEndpoint<APSettings> _httpEndpoint;
|
HttpEndpoint<APSettings> _httpEndpoint;
|
||||||
FSPersistence<APSettings> _fsPersistence;
|
FSPersistence<APSettings> _fsPersistence;
|
||||||
|
|
||||||
// for the mangement delay loop
|
|
||||||
unsigned long _lastManaged;
|
|
||||||
|
|
||||||
// for the captive portal
|
// for the captive portal
|
||||||
DNSServer* _dnsServer;
|
DNSServer* _dnsServer;
|
||||||
|
|
||||||
|
// for the mangement delay loop
|
||||||
|
unsigned long _lastManaged;
|
||||||
|
|
||||||
void reconfigureAP();
|
void reconfigureAP();
|
||||||
void manageAP();
|
void manageAP();
|
||||||
void startAP();
|
void startAP();
|
||||||
|
@ -20,7 +20,8 @@ class FSPersistence {
|
|||||||
_jsonDeserializer(jsonDeserializer),
|
_jsonDeserializer(jsonDeserializer),
|
||||||
_statefulService(statefulService),
|
_statefulService(statefulService),
|
||||||
_fs(fs),
|
_fs(fs),
|
||||||
_filePath(filePath) {
|
_filePath(filePath),
|
||||||
|
_updateHandlerId(0) {
|
||||||
enableUpdateHandler();
|
enableUpdateHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +86,7 @@ class FSPersistence {
|
|||||||
StatefulService<T>* _statefulService;
|
StatefulService<T>* _statefulService;
|
||||||
FS* _fs;
|
FS* _fs;
|
||||||
char const* _filePath;
|
char const* _filePath;
|
||||||
update_handler_id_t _updateHandlerId = 0;
|
update_handler_id_t _updateHandlerId;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// We assume the deserializer supplies sensible defaults if an empty object
|
// We assume the deserializer supplies sensible defaults if an empty object
|
||||||
|
@ -27,7 +27,15 @@ MqttSettingsService::MqttSettingsService(AsyncWebServer* server, FS* fs, Securit
|
|||||||
server,
|
server,
|
||||||
MQTT_SETTINGS_SERVICE_PATH,
|
MQTT_SETTINGS_SERVICE_PATH,
|
||||||
securityManager),
|
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
|
#ifdef ESP32
|
||||||
WiFi.onEvent(
|
WiFi.onEvent(
|
||||||
std::bind(&MqttSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
|
std::bind(&MqttSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),
|
||||||
|
@ -121,19 +121,22 @@ class MqttSettingsService : public StatefulService<MqttSettings> {
|
|||||||
FSPersistence<MqttSettings> _fsPersistence;
|
FSPersistence<MqttSettings> _fsPersistence;
|
||||||
|
|
||||||
// Pointers to hold retained copies of the mqtt client connection strings.
|
// Pointers to hold retained copies of the mqtt client connection strings.
|
||||||
// Required as AsyncMqttClient holds refrences to the supplied connection strings.
|
// This is required as AsyncMqttClient holds refrences to the supplied connection strings.
|
||||||
char* _retainedHost = nullptr;
|
char* _retainedHost;
|
||||||
char* _retainedClientId = nullptr;
|
char* _retainedClientId;
|
||||||
char* _retainedUsername = nullptr;
|
char* _retainedUsername;
|
||||||
char* _retainedPassword = nullptr;
|
char* _retainedPassword;
|
||||||
|
|
||||||
AsyncMqttClient _mqttClient;
|
// variable to help manage connection
|
||||||
bool _reconfigureMqtt;
|
bool _reconfigureMqtt;
|
||||||
unsigned long _disconnectedAt;
|
unsigned long _disconnectedAt;
|
||||||
|
|
||||||
// connection status
|
// connection status
|
||||||
AsyncMqttClientDisconnectReason _disconnectReason;
|
AsyncMqttClientDisconnectReason _disconnectReason;
|
||||||
|
|
||||||
|
// the MQTT client instance
|
||||||
|
AsyncMqttClient _mqttClient;
|
||||||
|
|
||||||
#ifdef ESP32
|
#ifdef ESP32
|
||||||
void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
|
void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
|
||||||
void onStationModeDisconnected(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,
|
server,
|
||||||
SECURITY_SETTINGS_PATH,
|
SECURITY_SETTINGS_PATH,
|
||||||
this),
|
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);
|
addUpdateHandler([&](const String& originId) { configureJWTHandler(); }, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ class SecuritySettingsService : public StatefulService<SecuritySettings>, public
|
|||||||
private:
|
private:
|
||||||
HttpEndpoint<SecuritySettings> _httpEndpoint;
|
HttpEndpoint<SecuritySettings> _httpEndpoint;
|
||||||
FSPersistence<SecuritySettings> _fsPersistence;
|
FSPersistence<SecuritySettings> _fsPersistence;
|
||||||
ArduinoJsonJWT _jwtHandler = ArduinoJsonJWT(FACTORY_JWT_SECRET);
|
ArduinoJsonJWT _jwtHandler;
|
||||||
|
|
||||||
void configureJWTHandler();
|
void configureJWTHandler();
|
||||||
|
|
||||||
|
@ -7,7 +7,8 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit
|
|||||||
server,
|
server,
|
||||||
WIFI_SETTINGS_SERVICE_PATH,
|
WIFI_SETTINGS_SERVICE_PATH,
|
||||||
securityManager),
|
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.
|
// 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 needed, we save opmode=0 before disabling persistence so the device boots with WiFi disabled in the future.
|
||||||
if (WiFi.getMode() != WIFI_OFF) {
|
if (WiFi.getMode() != WIFI_OFF) {
|
||||||
|
Loading…
Reference in New Issue
Block a user