Browse Source

Merge pull request #61 from rjwats/fix-formatting

fix formatting issue
master
rjwats 5 years ago
committed by GitHub
parent
commit
5fa6a1218f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      lib/framework/SettingsService.h

24
lib/framework/SettingsService.h

@ -20,12 +20,11 @@
/*
* Abstraction of a service which stores it's settings as JSON in a file system.
*/
class SettingsService : public SettingsPersistence
{
class SettingsService : public SettingsPersistence {
public:
SettingsService(AsyncWebServer *server, FS *fs, char const *servicePath, char const *filePath) : SettingsPersistence(fs, filePath), _servicePath(servicePath)
{
SettingsService(AsyncWebServer* server, FS* fs, char const* servicePath, char const* filePath): SettingsPersistence(fs, filePath), _servicePath(servicePath) {
server->on(_servicePath, HTTP_GET, std::bind(&SettingsService::fetchConfig, this, std::placeholders::_1));
_updateHandler.setUri(servicePath);
@ -37,8 +36,7 @@ public:
virtual ~SettingsService() {}
void begin()
{
void begin() {
// read the initial data from the file system
readFromFS();
}
@ -47,8 +45,7 @@ protected:
char const* _servicePath;
AsyncJsonWebHandler _updateHandler;
virtual void fetchConfig(AsyncWebServerRequest *request)
{
virtual void fetchConfig(AsyncWebServerRequest *request) {
// handle the request
AsyncJsonResponse * response = new AsyncJsonResponse(false, MAX_SETTINGS_SIZE);
JsonObject jsonObject = response->getRoot();
@ -57,11 +54,9 @@ protected:
request->send(response);
}
virtual void updateConfig(AsyncWebServerRequest *request, JsonDocument &jsonDocument)
{
virtual void updateConfig(AsyncWebServerRequest *request, JsonDocument &jsonDocument) {
// handle the request
if (jsonDocument.is<JsonObject>())
{
if (jsonDocument.is<JsonObject>()){
JsonObject newConfig = jsonDocument.as<JsonObject>();
readFromJsonObject(newConfig);
writeToFS();
@ -72,15 +67,14 @@ protected:
writeToJsonObject(jsonObject);
response->setLength();
request->send(response);
}
else
{
} else {
request->send(400);
}
}
// implement to perform action when config has been updated
virtual void onConfigUpdated(){}
};
#endif // end SettingsService
Loading…
Cancel
Save