handling DatasetEntries
This commit is contained in:
parent
4c0d9ae039
commit
d328f3e190
@ -4,6 +4,7 @@
|
||||
#include <fsfw/objectmanager/ObjectManager.h>
|
||||
#include <fsfw/returnvalues/returnvalue.h>
|
||||
|
||||
//TODO for non allocated: detect if initialized, and if not, call it
|
||||
|
||||
#include "HasDatapoolIF.h"
|
||||
|
||||
|
@ -20,7 +20,12 @@ class DatasetEntry : public Parameter<T>, public DatasetEntryIF {
|
||||
: Parameter<T>(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<T>, 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<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:
|
||||
T value;
|
||||
T *storedValue;
|
||||
bool *storedValid;
|
||||
bool valid;
|
||||
bool allocated;
|
||||
};
|
||||
|
||||
#ifdef FSFW_INTROSPECTION
|
||||
|
@ -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_ */
|
||||
|
Loading…
x
Reference in New Issue
Block a user