Skip to content

Commit 4fa491e

Browse files
authored
adopt explicit initialization - with the exception of trivial classes (rjwats#122)
1 parent db0d98d commit 4fa491e

8 files changed

+31
-16
lines changed

lib/framework/APSettingsService.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ APSettingsService::APSettingsService(AsyncWebServer* server, FS* fs, SecurityMan
88
AP_SETTINGS_SERVICE_PATH,
99
securityManager),
1010
_fsPersistence(APSettings::serialize, APSettings::deserialize, this, fs, AP_SETTINGS_FILE),
11-
_dnsServer(nullptr) {
11+
_dnsServer(nullptr),
12+
_lastManaged(0) {
1213
addUpdateHandler([&](const String& originId) { reconfigureAP(); }, false);
1314
}
1415

lib/framework/APSettingsService.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ class APSettingsService : public StatefulService<APSettings> {
6868
HttpEndpoint<APSettings> _httpEndpoint;
6969
FSPersistence<APSettings> _fsPersistence;
7070

71-
// for the mangement delay loop
72-
unsigned long _lastManaged;
73-
7471
// for the captive portal
7572
DNSServer* _dnsServer;
7673

74+
// for the mangement delay loop
75+
unsigned long _lastManaged;
76+
7777
void reconfigureAP();
7878
void manageAP();
7979
void startAP();

lib/framework/FSPersistence.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ class FSPersistence {
2020
_jsonDeserializer(jsonDeserializer),
2121
_statefulService(statefulService),
2222
_fs(fs),
23-
_filePath(filePath) {
23+
_filePath(filePath),
24+
_updateHandlerId(0) {
2425
enableUpdateHandler();
2526
}
2627

@@ -85,7 +86,7 @@ class FSPersistence {
8586
StatefulService<T>* _statefulService;
8687
FS* _fs;
8788
char const* _filePath;
88-
update_handler_id_t _updateHandlerId = 0;
89+
update_handler_id_t _updateHandlerId;
8990

9091
protected:
9192
// We assume the deserializer supplies sensible defaults if an empty object

lib/framework/MqttSettingsService.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ MqttSettingsService::MqttSettingsService(AsyncWebServer* server, FS* fs, Securit
2727
server,
2828
MQTT_SETTINGS_SERVICE_PATH,
2929
securityManager),
30-
_fsPersistence(MqttSettings::serialize, MqttSettings::deserialize, this, fs, MQTT_SETTINGS_FILE) {
30+
_fsPersistence(MqttSettings::serialize, MqttSettings::deserialize, this, fs, MQTT_SETTINGS_FILE),
31+
_retainedHost(nullptr),
32+
_retainedClientId(nullptr),
33+
_retainedUsername(nullptr),
34+
_retainedPassword(nullptr),
35+
_reconfigureMqtt(false),
36+
_disconnectedAt(0),
37+
_disconnectReason(AsyncMqttClientDisconnectReason::TCP_DISCONNECTED),
38+
_mqttClient() {
3139
#ifdef ESP32
3240
WiFi.onEvent(
3341
std::bind(&MqttSettingsService::onStationModeDisconnected, this, std::placeholders::_1, std::placeholders::_2),

lib/framework/MqttSettingsService.h

+9-6
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,22 @@ class MqttSettingsService : public StatefulService<MqttSettings> {
121121
FSPersistence<MqttSettings> _fsPersistence;
122122

123123
// Pointers to hold retained copies of the mqtt client connection strings.
124-
// Required as AsyncMqttClient holds refrences to the supplied connection strings.
125-
char* _retainedHost = nullptr;
126-
char* _retainedClientId = nullptr;
127-
char* _retainedUsername = nullptr;
128-
char* _retainedPassword = nullptr;
124+
// This is required as AsyncMqttClient holds refrences to the supplied connection strings.
125+
char* _retainedHost;
126+
char* _retainedClientId;
127+
char* _retainedUsername;
128+
char* _retainedPassword;
129129

130-
AsyncMqttClient _mqttClient;
130+
// variable to help manage connection
131131
bool _reconfigureMqtt;
132132
unsigned long _disconnectedAt;
133133

134134
// connection status
135135
AsyncMqttClientDisconnectReason _disconnectReason;
136136

137+
// the MQTT client instance
138+
AsyncMqttClient _mqttClient;
139+
137140
#ifdef ESP32
138141
void onStationModeGotIP(WiFiEvent_t event, WiFiEventInfo_t info);
139142
void onStationModeDisconnected(WiFiEvent_t event, WiFiEventInfo_t info);

lib/framework/SecuritySettingsService.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ SecuritySettingsService::SecuritySettingsService(AsyncWebServer* server, FS* fs)
77
server,
88
SECURITY_SETTINGS_PATH,
99
this),
10-
_fsPersistence(SecuritySettings::serialize, SecuritySettings::deserialize, this, fs, SECURITY_SETTINGS_FILE) {
10+
_fsPersistence(SecuritySettings::serialize, SecuritySettings::deserialize, this, fs, SECURITY_SETTINGS_FILE),
11+
_jwtHandler(FACTORY_JWT_SECRET) {
1112
addUpdateHandler([&](const String& originId) { configureJWTHandler(); }, false);
1213
}
1314

lib/framework/SecuritySettingsService.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class SecuritySettingsService : public StatefulService<SecuritySettings>, public
7777
private:
7878
HttpEndpoint<SecuritySettings> _httpEndpoint;
7979
FSPersistence<SecuritySettings> _fsPersistence;
80-
ArduinoJsonJWT _jwtHandler = ArduinoJsonJWT(FACTORY_JWT_SECRET);
80+
ArduinoJsonJWT _jwtHandler;
8181

8282
void configureJWTHandler();
8383

lib/framework/WiFiSettingsService.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ WiFiSettingsService::WiFiSettingsService(AsyncWebServer* server, FS* fs, Securit
77
server,
88
WIFI_SETTINGS_SERVICE_PATH,
99
securityManager),
10-
_fsPersistence(WiFiSettings::serialize, WiFiSettings::deserialize, this, fs, WIFI_SETTINGS_FILE) {
10+
_fsPersistence(WiFiSettings::serialize, WiFiSettings::deserialize, this, fs, WIFI_SETTINGS_FILE),
11+
_lastConnectionAttempt(0) {
1112
// We want the device to come up in opmode=0 (WIFI_OFF), when erasing the flash this is not the default.
1213
// If needed, we save opmode=0 before disabling persistence so the device boots with WiFi disabled in the future.
1314
if (WiFi.getMode() != WIFI_OFF) {

0 commit comments

Comments
 (0)