Skip to content

Commit 368bfef

Browse files
authored
Merge pull request #68 from rjwats/clang-format
reformat with .clang-format based on google's spec with some minor ch…
2 parents 8fb805e + f4ae632 commit 368bfef

40 files changed

+919
-914
lines changed

.clang-format

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Language: Cpp
2+
BasedOnStyle: Google
3+
ColumnLimit: 120
4+
AllowShortBlocksOnASingleLine: false
5+
AllowShortFunctionsOnASingleLine: false
6+
AllowShortIfStatementsOnASingleLine: false
7+
AllowShortLoopsOnASingleLine: false
8+
BinPackArguments: false
9+
BinPackParameters: false
10+
BreakConstructorInitializers: AfterColon
11+
AllowAllParametersOfDeclarationOnNextLine: false
12+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
13+
ExperimentalAutoDetectBinPacking: false
14+
KeepEmptyLinesAtTheStartOfBlocks: false
15+
DerivePointerAlignment: false

lib/framework/APSettingsService.cpp

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

3-
APSettingsService::APSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) : AdminSettingsService(server, fs, securityManager, AP_SETTINGS_SERVICE_PATH, AP_SETTINGS_FILE) {}
3+
APSettingsService::APSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager) :
4+
AdminSettingsService(server, fs, securityManager, AP_SETTINGS_SERVICE_PATH, AP_SETTINGS_FILE) {
5+
}
46

5-
APSettingsService::~APSettingsService() {}
7+
APSettingsService::~APSettingsService() {
8+
}
69

710
void APSettingsService::begin() {
811
SettingsService::begin();
@@ -12,10 +15,10 @@ void APSettingsService::begin() {
1215
void APSettingsService::loop() {
1316
unsigned long currentMillis = millis();
1417
unsigned long manageElapsed = (unsigned long)(currentMillis - _lastManaged);
15-
if (manageElapsed >= MANAGE_NETWORK_DELAY){
18+
if (manageElapsed >= MANAGE_NETWORK_DELAY) {
1619
_lastManaged = currentMillis;
17-
manageAP();
18-
}
20+
manageAP();
21+
}
1922
handleDNS();
2023
}
2124

lib/framework/APSettingsService.h

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,39 +20,34 @@
2020
#define AP_SETTINGS_SERVICE_PATH "/rest/apSettings"
2121

2222
class APSettingsService : public AdminSettingsService {
23-
24-
public:
25-
26-
APSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
27-
~APSettingsService();
28-
29-
void begin();
30-
void loop();
31-
32-
protected:
33-
34-
void readFromJsonObject(JsonObject& root);
35-
void writeToJsonObject(JsonObject& root);
36-
void onConfigUpdated();
37-
38-
private:
39-
40-
// access point settings
41-
uint8_t _provisionMode;
42-
String _ssid;
43-
String _password;
44-
45-
// for the mangement delay loop
46-
unsigned long _lastManaged;
47-
48-
// for the captive portal
49-
DNSServer *_dnsServer;
50-
51-
void manageAP();
52-
void startAP();
53-
void stopAP() ;
54-
void handleDNS();
55-
23+
public:
24+
APSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager);
25+
~APSettingsService();
26+
27+
void begin();
28+
void loop();
29+
30+
protected:
31+
void readFromJsonObject(JsonObject& root);
32+
void writeToJsonObject(JsonObject& root);
33+
void onConfigUpdated();
34+
35+
private:
36+
// access point settings
37+
uint8_t _provisionMode;
38+
String _ssid;
39+
String _password;
40+
41+
// for the mangement delay loop
42+
unsigned long _lastManaged;
43+
44+
// for the captive portal
45+
DNSServer* _dnsServer;
46+
47+
void manageAP();
48+
void startAP();
49+
void stopAP();
50+
void handleDNS();
5651
};
5752

58-
#endif // end APSettingsConfig_h
53+
#endif // end APSettingsConfig_h

lib/framework/APStatus.cpp

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

33
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)
6-
);
4+
server->on(AP_STATUS_SERVICE_PATH,
5+
HTTP_GET,
6+
securityManager->wrapRequest(std::bind(&APStatus::apStatus, this, std::placeholders::_1),
7+
AuthenticationPredicates::IS_AUTHENTICATED));
78
}
89

9-
void APStatus::apStatus(AsyncWebServerRequest *request) {
10-
AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_AP_STATUS_SIZE);
10+
void APStatus::apStatus(AsyncWebServerRequest* request) {
11+
AsyncJsonResponse* response = new AsyncJsonResponse(false, MAX_AP_STATUS_SIZE);
1112
JsonObject root = response->getRoot();
1213

1314
WiFiMode_t currentWiFiMode = WiFi.getMode();
14-
root["active"] = (currentWiFiMode == WIFI_AP || currentWiFiMode == WIFI_AP_STA);
15+
root["active"] = (currentWiFiMode == WIFI_AP || currentWiFiMode == WIFI_AP_STA);
1516
root["ip_address"] = WiFi.softAPIP().toString();
1617
root["mac_address"] = WiFi.softAPmacAddress();
1718
root["station_num"] = WiFi.softAPgetStationNum();

lib/framework/APStatus.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,28 @@
22
#define APStatus_h
33

44
#if defined(ESP8266)
5-
#include <ESP8266WiFi.h>
6-
#include <ESPAsyncTCP.h>
5+
#include <ESP8266WiFi.h>
6+
#include <ESPAsyncTCP.h>
77
#elif defined(ESP_PLATFORM)
8-
#include <WiFi.h>
9-
#include <AsyncTCP.h>
8+
#include <AsyncTCP.h>
9+
#include <WiFi.h>
1010
#endif
1111

12-
#include <ESPAsyncWebServer.h>
1312
#include <ArduinoJson.h>
1413
#include <AsyncJson.h>
14+
#include <ESPAsyncWebServer.h>
1515
#include <IPAddress.h>
1616
#include <SecurityManager.h>
1717

1818
#define MAX_AP_STATUS_SIZE 1024
1919
#define AP_STATUS_SERVICE_PATH "/rest/apStatus"
2020

2121
class APStatus {
22+
public:
23+
APStatus(AsyncWebServer* server, SecurityManager* securityManager);
2224

23-
public:
24-
25-
APStatus(AsyncWebServer* server, SecurityManager* securityManager);
26-
27-
private:
28-
29-
void apStatus(AsyncWebServerRequest *request);
30-
25+
private:
26+
void apStatus(AsyncWebServerRequest* request);
3127
};
3228

33-
#endif // end APStatus_h
29+
#endif // end APStatus_h

lib/framework/AdminSettingsService.h

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,46 @@
44
#include <SettingsService.h>
55

66
class AdminSettingsService : public SettingsService {
7-
8-
public:
9-
AdminSettingsService(AsyncWebServer* server, FS* fs, SecurityManager* securityManager, char const* servicePath, char const* filePath):
10-
SettingsService(server, fs, servicePath, filePath), _securityManager(securityManager) {}
11-
12-
protected:
13-
// will validate the requests with the security manager
14-
SecurityManager* _securityManager;
15-
16-
void fetchConfig(AsyncWebServerRequest *request) {
17-
// verify the request against the predicate
18-
Authentication authentication = _securityManager->authenticateRequest(request);
19-
if (!getAuthenticationPredicate()(authentication)) {
20-
request->send(401);
21-
return;
22-
}
23-
// delegate to underlying implemetation
24-
SettingsService::fetchConfig(request);
25-
}
26-
27-
void updateConfig(AsyncWebServerRequest *request, JsonDocument &jsonDocument) {
28-
// verify the request against the predicate
29-
Authentication authentication = _securityManager->authenticateRequest(request);
30-
if (!getAuthenticationPredicate()(authentication)) {
31-
request->send(401);
32-
return;
33-
}
34-
// delegate to underlying implemetation
35-
SettingsService::updateConfig(request, jsonDocument);
7+
public:
8+
AdminSettingsService(AsyncWebServer* server,
9+
FS* fs,
10+
SecurityManager* securityManager,
11+
char const* servicePath,
12+
char const* filePath) :
13+
SettingsService(server, fs, servicePath, filePath),
14+
_securityManager(securityManager) {
15+
}
16+
17+
protected:
18+
// will validate the requests with the security manager
19+
SecurityManager* _securityManager;
20+
21+
void fetchConfig(AsyncWebServerRequest* request) {
22+
// verify the request against the predicate
23+
Authentication authentication = _securityManager->authenticateRequest(request);
24+
if (!getAuthenticationPredicate()(authentication)) {
25+
request->send(401);
26+
return;
3627
}
37-
38-
// override this to replace the default authentication predicate, IS_ADMIN
39-
AuthenticationPredicate getAuthenticationPredicate() {
40-
return AuthenticationPredicates::IS_ADMIN;
28+
// delegate to underlying implemetation
29+
SettingsService::fetchConfig(request);
30+
}
31+
32+
void updateConfig(AsyncWebServerRequest* request, JsonDocument& jsonDocument) {
33+
// verify the request against the predicate
34+
Authentication authentication = _securityManager->authenticateRequest(request);
35+
if (!getAuthenticationPredicate()(authentication)) {
36+
request->send(401);
37+
return;
4138
}
42-
39+
// delegate to underlying implemetation
40+
SettingsService::updateConfig(request, jsonDocument);
41+
}
42+
43+
// override this to replace the default authentication predicate, IS_ADMIN
44+
AuthenticationPredicate getAuthenticationPredicate() {
45+
return AuthenticationPredicates::IS_ADMIN;
46+
}
4347
};
4448

45-
#endif // end AdminSettingsService
49+
#endif // end AdminSettingsService

0 commit comments

Comments
 (0)