Skip to content

Commit f77428e

Browse files
committed
move initialization code to constructors as a simplfication
1 parent 29906a1 commit f77428e

30 files changed

+76
-151
lines changed

lib/framework/APSettingsService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <APSettingsService.h>
22

3-
APSettingsService::APSettingsService(FS* fs, SecurityManager* securityManager) : AdminSettingsService(fs, securityManager, AP_SETTINGS_SERVICE_PATH, AP_SETTINGS_FILE) {
3+
APSettingsService::APSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, AP_SETTINGS_SERVICE_PATH, AP_SETTINGS_FILE) {
44
onConfigUpdated();
55
}
66

lib/framework/APSettingsService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class APSettingsService : public AdminSettingsService {
2323

2424
public:
2525

26-
APSettingsService(FS* fs, SecurityManager* securityManager);
26+
APSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
2727
~APSettingsService();
2828

2929
void loop();

lib/framework/APStatus.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#include <APStatus.h>
22

3-
APStatus::APStatus(SecurityManager* securityManager) :_securityManager(securityManager) {}
4-
5-
void APStatus::init(AsyncWebServer *server){
6-
server->on(AP_STATUS_SERVICE_PATH, HTTP_GET,
7-
_securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED)
3+
APStatus::APStatus(AsyncWebServer* server, SecurityManager* securityManager) {
4+
server->on(AP_STATUS_SERVICE_PATH, HTTP_GET,
5+
securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, std::placeholders::_1), AuthenticationPredicates::IS_AUTHENTICATED)
86
);
97
}
108

lib/framework/APStatus.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,10 @@ class APStatus {
2222

2323
public:
2424

25-
APStatus(SecurityManager* securityManager);
26-
void init(AsyncWebServer *server);
25+
APStatus(AsyncWebServer* server, SecurityManager* securityManager);
2726

2827
private:
2928

30-
SecurityManager* _securityManager;
31-
3229
void apStatus(AsyncWebServerRequest *request);
3330

3431
};

lib/framework/AdminSettingsService.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
class AdminSettingsService : public SettingsService {
77

88
public:
9-
AdminSettingsService(FS* fs, SecurityManager* securityManager, char const* servicePath, char const* filePath):
10-
SettingsService(fs, servicePath, filePath), _securityManager(securityManager) {
11-
}
9+
AdminSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager, char const* servicePath, char const* filePath):
10+
SettingsService(server, fs, servicePath, filePath), _securityManager(securityManager) {}
1211

1312
protected:
1413
// will validate the requests with the security manager

lib/framework/AuthenticationService.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
#include <AuthenticationService.h>
22

3-
AuthenticationService::AuthenticationService(SecurityManager* securityManager) : _securityManager(securityManager) {
3+
AuthenticationService::AuthenticationService(AsyncWebServer* server, SecurityManager* securityManager) {
4+
server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, std::bind(&AuthenticationService::verifyAuthorization, this, std::placeholders::_1));
5+
46
_signInHandler.setUri(SIGN_IN_PATH);
57
_signInHandler.setMethod(HTTP_POST);
68
_signInHandler.setMaxContentLength(MAX_AUTHENTICATION_SIZE);
79
_signInHandler.onRequest(std::bind(&AuthenticationService::signIn, this, std::placeholders::_1, std::placeholders::_2));
10+
server->addHandler(&_signInHandler);
811
}
912

1013
AuthenticationService::~AuthenticationService() {}
1114

12-
void AuthenticationService::init(AsyncWebServer* server) {
13-
server->on(VERIFY_AUTHORIZATION_PATH, HTTP_GET, std::bind(&AuthenticationService::verifyAuthorization, this, std::placeholders::_1));
14-
server->addHandler(&_signInHandler);
15-
}
16-
1715
/**
1816
* Verifys that the request supplied a valid JWT.
1917
*/

lib/framework/AuthenticationService.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ class AuthenticationService {
1515

1616
public:
1717

18-
AuthenticationService(SecurityManager* securityManager);
18+
AuthenticationService(AsyncWebServer* server, SecurityManager* securityManager);
1919
~AuthenticationService();
2020

21-
void init(AsyncWebServer* server);
22-
2321
private:
24-
// server instance
25-
AsyncWebServer* _server;
22+
2623
SecurityManager* _securityManager;
2724
AsyncJsonWebHandler _signInHandler;
2825

lib/framework/ESP8266React.cpp

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,18 @@
11
#include <ESP8266React.h>
22

3-
ESP8266React::ESP8266React(FS* fs):
4-
_fs(fs),
5-
_securitySettingsService(_fs),
6-
_wifiSettingsService(_fs, &_securitySettingsService),
7-
_apSettingsService(_fs, &_securitySettingsService),
8-
_ntpSettingsService(_fs, &_securitySettingsService),
9-
_otaSettingsService(_fs, &_securitySettingsService),
10-
_authenticationService(&_securitySettingsService),
11-
_wifiScanner(&_securitySettingsService),
12-
_wifiStatus(&_securitySettingsService),
13-
_ntpStatus(&_securitySettingsService),
14-
_apStatus(&_securitySettingsService),
15-
_systemStatus(&_securitySettingsService) {
16-
}
17-
18-
void ESP8266React::init(AsyncWebServer* server) {
19-
// Start security settings service first
20-
_securitySettingsService.init(server);
21-
22-
// Core services
23-
_wifiSettingsService.init(server);
24-
_apSettingsService.init(server);
25-
_ntpSettingsService.init(server);
26-
_otaSettingsService.init(server);
27-
_authenticationService.init(server);
28-
29-
// Utility services
30-
_wifiScanner.init(server);
31-
_wifiStatus.init(server);
32-
_ntpStatus.init(server);
33-
_apStatus.init(server);
34-
_systemStatus.init(server);
35-
36-
37-
// Serving static resources from /www/
3+
ESP8266React::ESP8266React(AsyncWebServer* server, FS* fs):
4+
_securitySettingsService(server, fs),
5+
_wifiSettingsService(server, fs, &_securitySettingsService),
6+
_apSettingsService(server, fs, &_securitySettingsService),
7+
_ntpSettingsService(server, fs, &_securitySettingsService),
8+
_otaSettingsService(server, fs, &_securitySettingsService),
9+
_authenticationService(server, &_securitySettingsService),
10+
_wifiScanner(server, &_securitySettingsService),
11+
_wifiStatus(server, &_securitySettingsService),
12+
_ntpStatus(server, &_securitySettingsService),
13+
_apStatus(server, &_securitySettingsService),
14+
_systemStatus(server, &_securitySettingsService) {
15+
// Serve static resources from /www/
3816
server->serveStatic("/js/", SPIFFS, "/www/js/");
3917
server->serveStatic("/css/", SPIFFS, "/www/css/");
4018
server->serveStatic("/fonts/", SPIFFS, "/www/fonts/");

lib/framework/ESP8266React.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ class ESP8266React {
2929

3030
public:
3131

32-
ESP8266React(FS* fs);
33-
34-
void init(AsyncWebServer* server);
32+
ESP8266React(AsyncWebServer* server, FS* fs);
33+
3534
void loop();
3635

3736
SecurityManager* getSecurityManager(){
@@ -40,8 +39,6 @@ class ESP8266React {
4039

4140
private:
4241

43-
FS* _fs;
44-
4542
SecuritySettingsService _securitySettingsService;
4643

4744
WiFiSettingsService _wifiSettingsService;

lib/framework/NTPSettingsService.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <NTPSettingsService.h>
22

3-
NTPSettingsService::NTPSettingsService(FS* fs, SecurityManager* securityManager) : AdminSettingsService(fs, securityManager, NTP_SETTINGS_SERVICE_PATH, NTP_SETTINGS_FILE) {
3+
NTPSettingsService::NTPSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, NTP_SETTINGS_SERVICE_PATH, NTP_SETTINGS_FILE) {
44

55
#if defined(ESP8266)
66
_onStationModeDisconnectedHandler = WiFi.onStationModeDisconnected(std::bind(&NTPSettingsService::onStationModeDisconnected, this, std::placeholders::_1));

0 commit comments

Comments
 (0)