diff --git a/firmware/src/domain/core/PersistentElement.h b/firmware/src/domain/core/PersistentElement.h new file mode 100644 index 0000000..8a2f47d --- /dev/null +++ b/firmware/src/domain/core/PersistentElement.h @@ -0,0 +1,15 @@ +#ifndef ESP32_PERSISTENTELEMENT_H +#define ESP32_PERSISTENTELEMENT_H + +/** + * PersistentElements can be stored with the PersistentService + */ +class PersistentElement { +private: + int tableRow; +public: + int getTableRow() { return this->tableRow; } + void setTableRow(int tableRow) { this->tableRow = tableRow; } +}; + +#endif //ESP32_PERSISTENTELEMENT_H diff --git a/firmware/src/domain/core/PersistentService.h b/firmware/src/domain/core/PersistentService.h new file mode 100644 index 0000000..532fae1 --- /dev/null +++ b/firmware/src/domain/core/PersistentService.h @@ -0,0 +1,24 @@ +#ifndef ESP32_PERSISTSERVICE_H +#define ESP32_PERSISTSERVICE_H + +#include +#include "PersistentElement.h" + +/** + * This service is used to access and save elements in the storage. + * Each non abstract class will managed in his own class. Abstract types are read only (sorted by type if read as list) + */ +class PersistentService { +private: + +public: + virtual void save(PersistentElement elementToSave)= 0; + virtual void remove(PersistentElement elementToSave)= 0; + virtual void remove(std::string type, int id)= 0; + virtual PersistentElement get(std::string type)= 0; + virtual PersistentElement get(std::string type, int id)= 0; + + virtual void rearangeStorage()=0; +}; + +#endif //ESP32_PERSISTSERVICE_H diff --git a/firmware/src/domain/valoplus/adressableRgbLed.h b/firmware/src/domain/valoplus/AdressableRgbLed.h similarity index 84% rename from firmware/src/domain/valoplus/adressableRgbLed.h rename to firmware/src/domain/valoplus/AdressableRgbLed.h index 1826790..66d7c27 100644 --- a/firmware/src/domain/valoplus/adressableRgbLed.h +++ b/firmware/src/domain/valoplus/AdressableRgbLed.h @@ -1,11 +1,11 @@ #ifndef TEST_ADRESSABLERGBLED_H #define TEST_ADRESSABLERGBLED_H -#include +#include #include -#include +#include -class AdressableRgbLed : ChannelElement { +class AdressableRgbLed : public ChannelElement { private: std::string name; StateAdressableRgbLed stateAdressableRgbLed; diff --git a/firmware/src/domain/valoplus/adressableRgbLedJsonService.h b/firmware/src/domain/valoplus/AdressableRgbLedJsonService.h similarity index 87% rename from firmware/src/domain/valoplus/adressableRgbLedJsonService.h rename to firmware/src/domain/valoplus/AdressableRgbLedJsonService.h index 182562f..232cf06 100644 --- a/firmware/src/domain/valoplus/adressableRgbLedJsonService.h +++ b/firmware/src/domain/valoplus/AdressableRgbLedJsonService.h @@ -3,7 +3,7 @@ #include #include -#include +#include class AdressableRgbLedJsonService { private: @@ -21,9 +21,9 @@ class AdressableRgbLedJsonService { JsonObject& links = root.createNestedObject("_links"); JsonObject& self1 = links.createNestedObject("self"); - self1.set("href", "/adressableRgbLeds/" + obj.getId()); + self1.set("href", "/adressableRgbLeds/" + obj.getTableRow()); JsonObject& self2 = links.createNestedObject("adressableRgbLed"); - self2.set("href", "/adressableRgbLeds/" + obj.getId()); + self2.set("href", "/adressableRgbLeds/" + obj.getTableRow()); char buffer[root.measureLength()]; root.printTo(buffer, sizeof(buffer)); diff --git a/firmware/src/domain/valoplus/channelElement.h b/firmware/src/domain/valoplus/ChannelElement.h similarity index 54% rename from firmware/src/domain/valoplus/channelElement.h rename to firmware/src/domain/valoplus/ChannelElement.h index 6236ace..79d4a9d 100644 --- a/firmware/src/domain/valoplus/channelElement.h +++ b/firmware/src/domain/valoplus/ChannelElement.h @@ -1,9 +1,9 @@ #ifndef TEST_CHANNELELEMENT_H #define TEST_CHANNELELEMENT_H -#include +#include -class ChannelElement : ControllableElement { +class ChannelElement : public ControllableElement { private: public: diff --git a/firmware/src/domain/valoplus/controllableElement.h b/firmware/src/domain/valoplus/ControllableElement.h similarity index 70% rename from firmware/src/domain/valoplus/controllableElement.h rename to firmware/src/domain/valoplus/ControllableElement.h index 8f8b45c..5349930 100644 --- a/firmware/src/domain/valoplus/controllableElement.h +++ b/firmware/src/domain/valoplus/ControllableElement.h @@ -1,9 +1,10 @@ #ifndef TEST_CONTROLLABLEELEMENT_H #define TEST_CONTROLLABLEELEMENT_H +#include #include -class ControllableElement { +class ControllableElement : public PersistentElement { private: public: diff --git a/firmware/src/domain/valoplus/device.h b/firmware/src/domain/valoplus/Device.h similarity index 80% rename from firmware/src/domain/valoplus/device.h rename to firmware/src/domain/valoplus/Device.h index bdd9ca8..3046b45 100644 --- a/firmware/src/domain/valoplus/device.h +++ b/firmware/src/domain/valoplus/Device.h @@ -1,12 +1,12 @@ #ifndef TEST_DEVICE_H #define TEST_DEVICE_H -#include +#include #include -#include #include +#include -class Device : ControllableElement { +class Device : public ControllableElement { private: public: diff --git a/firmware/src/domain/valoplus/group.h b/firmware/src/domain/valoplus/Group.h similarity index 83% rename from firmware/src/domain/valoplus/group.h rename to firmware/src/domain/valoplus/Group.h index 4dc97f2..2805dd5 100644 --- a/firmware/src/domain/valoplus/group.h +++ b/firmware/src/domain/valoplus/Group.h @@ -1,11 +1,11 @@ #ifndef TEST_GROUP_H #define TEST_GROUP_H +#include #include -#include #include -class Group : ControllableElement { +class Group : public ControllableElement { private: std::string name; std::vector members; diff --git a/firmware/src/domain/valoplus/groupJsonService.h b/firmware/src/domain/valoplus/GroupJsonService.h similarity index 86% rename from firmware/src/domain/valoplus/groupJsonService.h rename to firmware/src/domain/valoplus/GroupJsonService.h index c2327d2..f5f7d2b 100644 --- a/firmware/src/domain/valoplus/groupJsonService.h +++ b/firmware/src/domain/valoplus/GroupJsonService.h @@ -3,7 +3,7 @@ #include #include -#include +#include class GroupJsonService { private: @@ -19,9 +19,9 @@ class GroupJsonService { JsonObject& links = root.createNestedObject("_links"); JsonObject& self1 = links.createNestedObject("self"); - self1.set("href", "/groups/" + obj.getId()); + self1.set("href", "/groups/" + obj.getTableRow()); JsonObject& self2 = links.createNestedObject("group"); - self2.set("href", "/groups/" + obj.getId()); + self2.set("href", "/groups/" + obj.getTableRow()); char buffer[root.measureLength()]; root.printTo(buffer, sizeof(buffer)); diff --git a/firmware/src/domain/valoplus/master.h b/firmware/src/domain/valoplus/Master.h similarity index 91% rename from firmware/src/domain/valoplus/master.h rename to firmware/src/domain/valoplus/Master.h index d58be17..9606952 100644 --- a/firmware/src/domain/valoplus/master.h +++ b/firmware/src/domain/valoplus/Master.h @@ -1,12 +1,12 @@ #ifndef TEST_MASTER_H #define TEST_MASTER_H -#include #include -#include +#include #include +#include -class Master : Device { +class Master : public Device { private: std::string name; std::string ip; diff --git a/firmware/src/domain/valoplus/masterJsonService.h b/firmware/src/domain/valoplus/MasterJsonService.h similarity index 90% rename from firmware/src/domain/valoplus/masterJsonService.h rename to firmware/src/domain/valoplus/MasterJsonService.h index 4b9072f..db7a4e2 100644 --- a/firmware/src/domain/valoplus/masterJsonService.h +++ b/firmware/src/domain/valoplus/MasterJsonService.h @@ -3,7 +3,7 @@ #include #include -#include +#include class MasterJsonService { private: @@ -24,9 +24,9 @@ class MasterJsonService { JsonObject& links = root.createNestedObject("_links"); JsonObject& self1 = links.createNestedObject("self"); - self1.set("href", "/masters/" + obj.getId()); + self1.set("href", "/masters/" + obj.getTableRow()); JsonObject& self2 = links.createNestedObject("master"); - self2.set("href", "/masters/" + obj.getId()); + self2.set("href", "/masters/" + obj.getTableRow()); char buffer[root.measureLength()]; root.printTo(buffer, sizeof(buffer)); diff --git a/firmware/src/domain/valoplus/rgbLed.h b/firmware/src/domain/valoplus/RgbLed.h similarity index 89% rename from firmware/src/domain/valoplus/rgbLed.h rename to firmware/src/domain/valoplus/RgbLed.h index 32f4894..2171a1c 100644 --- a/firmware/src/domain/valoplus/rgbLed.h +++ b/firmware/src/domain/valoplus/RgbLed.h @@ -1,10 +1,10 @@ #ifndef TEST_RGBLED_H #define TEST_RGBLED_H -#include #include +#include -class RgbLed : ChannelElement { +class RgbLed : public ChannelElement { private: std::string name; int channelIdRed; diff --git a/firmware/src/domain/valoplus/rgbLedJsonService.h b/firmware/src/domain/valoplus/RgbLedJsonService.h similarity index 89% rename from firmware/src/domain/valoplus/rgbLedJsonService.h rename to firmware/src/domain/valoplus/RgbLedJsonService.h index 64f08bc..1c64d97 100644 --- a/firmware/src/domain/valoplus/rgbLedJsonService.h +++ b/firmware/src/domain/valoplus/RgbLedJsonService.h @@ -3,7 +3,7 @@ #include #include -#include +#include class RgbLedJsonService { private: @@ -21,9 +21,9 @@ class RgbLedJsonService { JsonObject& links = root.createNestedObject("_links"); JsonObject& self1 = links.createNestedObject("self"); - self1.set("href", "/rgbLeds/" + obj.getId()); + self1.set("href", "/rgbLeds/" + obj.getTableRow()); JsonObject& self2 = links.createNestedObject("rgbLed"); - self2.set("href", "/rgbLeds/" + obj.getId()); + self2.set("href", "/rgbLeds/" + obj.getTableRow()); char buffer[root.measureLength()]; root.printTo(buffer, sizeof(buffer)); diff --git a/firmware/src/domain/valoplus/singleColorLed.h b/firmware/src/domain/valoplus/SingleColorLed.h similarity index 81% rename from firmware/src/domain/valoplus/singleColorLed.h rename to firmware/src/domain/valoplus/SingleColorLed.h index d32ef6a..fc611af 100644 --- a/firmware/src/domain/valoplus/singleColorLed.h +++ b/firmware/src/domain/valoplus/SingleColorLed.h @@ -1,10 +1,10 @@ #ifndef TEST_SINGLECOLORLED_H #define TEST_SINGLECOLORLED_H -#include #include +#include -class SingleColorLed : ChannelElement { +class SingleColorLed : public ChannelElement { private: std::string name; int channelId; diff --git a/firmware/src/domain/valoplus/singleColorLedJsonService.h b/firmware/src/domain/valoplus/SingleColorLedJsonService.h similarity index 85% rename from firmware/src/domain/valoplus/singleColorLedJsonService.h rename to firmware/src/domain/valoplus/SingleColorLedJsonService.h index 341f093..2702061 100644 --- a/firmware/src/domain/valoplus/singleColorLedJsonService.h +++ b/firmware/src/domain/valoplus/SingleColorLedJsonService.h @@ -3,7 +3,7 @@ #include #include -#include +#include class SingleColorLedJsonService { private: @@ -19,9 +19,9 @@ class SingleColorLedJsonService { JsonObject& links = root.createNestedObject("_links"); JsonObject& self1 = links.createNestedObject("self"); - self1.set("href", "/singleColorLeds/" + obj.getId()); + self1.set("href", "/singleColorLeds/" + obj.getTableRow()); JsonObject& self2 = links.createNestedObject("singleColorLed"); - self2.set("href", "/singleColorLeds/" + obj.getId()); + self2.set("href", "/singleColorLeds/" + obj.getTableRow()); char buffer[root.measureLength()]; root.printTo(buffer, sizeof(buffer)); diff --git a/firmware/src/domain/valoplus/slave.h b/firmware/src/domain/valoplus/Slave.h similarity index 89% rename from firmware/src/domain/valoplus/slave.h rename to firmware/src/domain/valoplus/Slave.h index 7caf60f..e4a489f 100644 --- a/firmware/src/domain/valoplus/slave.h +++ b/firmware/src/domain/valoplus/Slave.h @@ -1,12 +1,12 @@ #ifndef TEST_SLAVE_H #define TEST_SLAVE_H -#include #include -#include +#include #include +#include -class Slave : Device { +class Slave : public Device { private: std::string name; std::string ip; diff --git a/firmware/src/domain/valoplus/slaveJsonService.h b/firmware/src/domain/valoplus/SlaveJsonService.h similarity index 89% rename from firmware/src/domain/valoplus/slaveJsonService.h rename to firmware/src/domain/valoplus/SlaveJsonService.h index e4caebe..942d975 100644 --- a/firmware/src/domain/valoplus/slaveJsonService.h +++ b/firmware/src/domain/valoplus/SlaveJsonService.h @@ -3,7 +3,7 @@ #include #include -#include +#include class SlaveJsonService { private: @@ -23,9 +23,9 @@ class SlaveJsonService { JsonObject& links = root.createNestedObject("_links"); JsonObject& self1 = links.createNestedObject("self"); - self1.set("href", "/slaves/" + obj.getId()); + self1.set("href", "/slaves/" + obj.getTableRow()); JsonObject& self2 = links.createNestedObject("slave"); - self2.set("href", "/slaves/" + obj.getId()); + self2.set("href", "/slaves/" + obj.getTableRow()); char buffer[root.measureLength()]; root.printTo(buffer, sizeof(buffer)); diff --git a/firmware/src/domain/valoplus/state.h b/firmware/src/domain/valoplus/State.h similarity index 66% rename from firmware/src/domain/valoplus/state.h rename to firmware/src/domain/valoplus/State.h index 7658d4b..0acfdf7 100644 --- a/firmware/src/domain/valoplus/state.h +++ b/firmware/src/domain/valoplus/State.h @@ -1,8 +1,9 @@ #ifndef TEST_STATE_H #define TEST_STATE_H +#include -class State { +class State : public PersistentElement { private: public: diff --git a/firmware/src/domain/valoplus/stateAdressableRgbLed.h b/firmware/src/domain/valoplus/StateAdressableRgbLed.h similarity index 83% rename from firmware/src/domain/valoplus/stateAdressableRgbLed.h rename to firmware/src/domain/valoplus/StateAdressableRgbLed.h index 4e62553..d1c753b 100644 --- a/firmware/src/domain/valoplus/stateAdressableRgbLed.h +++ b/firmware/src/domain/valoplus/StateAdressableRgbLed.h @@ -1,9 +1,9 @@ #ifndef TEST_STATEADRESSABLERGBLED_H #define TEST_STATEADRESSABLERGBLED_H -#include +#include -class StateAdressableRgbLed : State { +class StateAdressableRgbLed : public State { private: bool active; int brightness; diff --git a/firmware/src/domain/valoplus/stateAdressableRgbLedJsonService.h b/firmware/src/domain/valoplus/StateAdressableRgbLedJsonService.h similarity index 85% rename from firmware/src/domain/valoplus/stateAdressableRgbLedJsonService.h rename to firmware/src/domain/valoplus/StateAdressableRgbLedJsonService.h index b98ee9a..d4c9b48 100644 --- a/firmware/src/domain/valoplus/stateAdressableRgbLedJsonService.h +++ b/firmware/src/domain/valoplus/StateAdressableRgbLedJsonService.h @@ -3,7 +3,7 @@ #include #include -#include +#include class StateAdressableRgbLedJsonService { private: @@ -19,9 +19,9 @@ class StateAdressableRgbLedJsonService { JsonObject& links = root.createNestedObject("_links"); JsonObject& self1 = links.createNestedObject("self"); - self1.set("href", "/stateAdressableRgbLeds/" + obj.getId()); + self1.set("href", "/stateAdressableRgbLeds/" + obj.getTableRow()); JsonObject& self2 = links.createNestedObject("stateAdressableRgbLed"); - self2.set("href", "/stateAdressableRgbLeds/" + obj.getId()); + self2.set("href", "/stateAdressableRgbLeds/" + obj.getTableRow()); char buffer[root.measureLength()]; root.printTo(buffer, sizeof(buffer));