handling DatasetEntries
Some checks failed
fsfw/fsfw/pipeline/head There was a failure building this commit

This commit is contained in:
Ulrich Mohr 2023-07-18 15:07:21 +02:00
parent 4c0d9ae039
commit d328f3e190
3 changed files with 45 additions and 5 deletions

View File

@ -4,6 +4,7 @@
#include <fsfw/objectmanager/ObjectManager.h> #include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/returnvalues/returnvalue.h> #include <fsfw/returnvalues/returnvalue.h>
//TODO for non allocated: detect if initialized, and if not, call it
#include "HasDatapoolIF.h" #include "HasDatapoolIF.h"

View File

@ -20,7 +20,12 @@ class DatasetEntry : public Parameter<T>, public DatasetEntryIF {
: Parameter<T>(owner) : Parameter<T>(owner)
#endif #endif
{ {
owner->registerEntry(this); allocated = owner->registerEntry(this);
if (!allocated) {
return;
}
storedValue = new T();
storedValid = new bool
} }
public: public:
@ -32,19 +37,45 @@ class DatasetEntry : public Parameter<T>, public DatasetEntryIF {
static DatasetEntry createDatasetEntry(Dataset *owner) { return DatasetEntry(owner); } static DatasetEntry createDatasetEntry(Dataset *owner) { return DatasetEntry(owner); }
#endif #endif
~DatasetEntry() {
if (allocated) {
delete storedValue;
delete storedValid;
}
}
virtual void setValid(bool isValid) { valid = isValid; } virtual void setValid(bool isValid) { valid = isValid; }
virtual bool getValid() { return valid; } virtual bool getValid() { return valid; }
protected: protected:
virtual void commit() {} virtual void commit() {
virtual void read() {} *storedValue = value;
virtual void connect(DatasetEntryIF *entry) {} *storedValid = valid;
}
virtual void read() {
value = *storedValue;
valid = *storedValid;
}
virtual bool changed() { return false; } virtual void connect(DatasetEntryIF *entry) {
HousekeepingEntry<T> *theOther = dynamic_cast<HousekeepingEntry<T> *>(entry);
if (theOther == nullptr) {
// Configuration error
return;
}
this->storedValue = theOther->storedValue;
this->storedValid = theOther->storedValid;
}
virtual bool changed() { return ((value != *storedValue) || (valid != *storedValid)); }
private: private:
T value;
T *storedValue;
bool *storedValid;
bool valid; bool valid;
bool allocated;
}; };
#ifdef FSFW_INTROSPECTION #ifdef FSFW_INTROSPECTION

View File

@ -26,10 +26,18 @@ class DatasetEntryIF {
virtual void read() = 0; virtual void read() = 0;
virtual void connect(DatasetEntryIF* entry) = 0; virtual void connect(DatasetEntryIF* entry) = 0;
/**
* create actualValue
*/
virtual void allocate() = 0;
/** /**
* returns if value and actual value is different * returns if value and actual value is different
*/ */
virtual bool changed() = 0; virtual bool changed() = 0;
private:
}; };
#endif /* FSFW_DATAPOOL_POOLENTRYIF_H_ */ #endif /* FSFW_DATAPOOL_POOLENTRYIF_H_ */