diff --git a/src/fsfw/datapool/Dataset.cpp b/src/fsfw/datapool/Dataset.cpp index c14c78966..725332ff6 100644 --- a/src/fsfw/datapool/Dataset.cpp +++ b/src/fsfw/datapool/Dataset.cpp @@ -4,6 +4,7 @@ #include #include +//TODO for non allocated: detect if initialized, and if not, call it #include "HasDatapoolIF.h" diff --git a/src/fsfw/datapool/DatasetEntry.h b/src/fsfw/datapool/DatasetEntry.h index 07d267aa3..f42e1df58 100644 --- a/src/fsfw/datapool/DatasetEntry.h +++ b/src/fsfw/datapool/DatasetEntry.h @@ -20,7 +20,12 @@ class DatasetEntry : public Parameter, public DatasetEntryIF { : Parameter(owner) #endif { - owner->registerEntry(this); + allocated = owner->registerEntry(this); + if (!allocated) { + return; + } + storedValue = new T(); + storedValid = new bool } public: @@ -32,19 +37,45 @@ class DatasetEntry : public Parameter, public DatasetEntryIF { static DatasetEntry createDatasetEntry(Dataset *owner) { return DatasetEntry(owner); } #endif + ~DatasetEntry() { + if (allocated) { + delete storedValue; + delete storedValid; + } + } + virtual void setValid(bool isValid) { valid = isValid; } virtual bool getValid() { return valid; } protected: - virtual void commit() {} - virtual void read() {} - virtual void connect(DatasetEntryIF *entry) {} + virtual void commit() { + *storedValue = value; + *storedValid = valid; + } + virtual void read() { + value = *storedValue; + valid = *storedValid; + } - virtual bool changed() { return false; } + virtual void connect(DatasetEntryIF *entry) { + HousekeepingEntry *theOther = dynamic_cast *>(entry); + if (theOther == nullptr) { + // Configuration error + return; + } + this->storedValue = theOther->storedValue; + this->storedValid = theOther->storedValid; + } + + virtual bool changed() { return ((value != *storedValue) || (valid != *storedValid)); } private: + T value; + T *storedValue; + bool *storedValid; bool valid; + bool allocated; }; #ifdef FSFW_INTROSPECTION diff --git a/src/fsfw/datapool/DatasetEntryIF.h b/src/fsfw/datapool/DatasetEntryIF.h index 903792378..93b6502bf 100644 --- a/src/fsfw/datapool/DatasetEntryIF.h +++ b/src/fsfw/datapool/DatasetEntryIF.h @@ -26,10 +26,18 @@ class DatasetEntryIF { virtual void read() = 0; virtual void connect(DatasetEntryIF* entry) = 0; + /** + * create actualValue + */ + virtual void allocate() = 0; + /** * returns if value and actual value is different */ virtual bool changed() = 0; + +private: + }; #endif /* FSFW_DATAPOOL_POOLENTRYIF_H_ */