diff --git a/datapool/PoolDataSetBase.cpp b/datapool/PoolDataSetBase.cpp index 010697854..7d50a40af 100644 --- a/datapool/PoolDataSetBase.cpp +++ b/datapool/PoolDataSetBase.cpp @@ -1,5 +1,6 @@ #include "PoolDataSetBase.h" #include "../serviceinterface/ServiceInterfaceStream.h" +#include PoolDataSetBase::PoolDataSetBase(PoolVariableIF** registeredVariablesArray, const size_t maxFillCount): @@ -228,3 +229,20 @@ void PoolDataSetBase::setReadCommitProtectionBehaviour( this->timeoutTypeForSingleVars = timeoutType; this->mutexTimeoutForSingleVars = mutexTimeout; } + +/* We really should supply the container as a template argument instead of writing sth like this */ +//PoolDataSetBase::PoolDataSetBase(const PoolDataSetBase &otherSet): +// fillCount(otherSet.fillCount), state(otherSet.state), +// maxFillCount(otherSet.maxFillCount), +// protectEveryReadCommitCall(otherSet.protectEveryReadCommitCall), +// timeoutTypeForSingleVars(otherSet.timeoutTypeForSingleVars), +// mutexTimeoutForSingleVars(otherSet.mutexTimeoutForSingleVars) { +// if(registeredVariables != nullptr and otherSet.registeredVariables != nullptr) { +// std::memcpy(reinterpret_cast(*(this->registeredVariables)), +// reinterpret_cast(*(otherSet.registeredVariables)), +// fillCount * sizeof(PoolVariableIF*)); +// } +//} +// +//const PoolDataSetBase& PoolDataSetBase::operator=(const PoolDataSetBase &otherSet) { +//} diff --git a/datapool/PoolDataSetBase.h b/datapool/PoolDataSetBase.h index 756541469..ab8954557 100644 --- a/datapool/PoolDataSetBase.h +++ b/datapool/PoolDataSetBase.h @@ -39,8 +39,12 @@ public: * supply a pointer to this dataset to PoolVariable * initializations to register pool variables. */ - PoolDataSetBase(PoolVariableIF** registeredVariablesArray, - const size_t maxFillCount); + PoolDataSetBase(PoolVariableIF** registeredVariablesArray, const size_t maxFillCount); + + /* Forbidden for now */ + PoolDataSetBase(const PoolDataSetBase& otherSet) = delete; + const PoolDataSetBase& operator=(const PoolDataSetBase& otherSet) = delete; + virtual~ PoolDataSetBase(); /** @@ -63,8 +67,7 @@ public: * - @c SET_WAS_ALREADY_READ if read() is called twice without calling * commit() in between */ - virtual ReturnValue_t read( - MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, + virtual ReturnValue_t read(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, uint32_t lockTimeout = 20) override; /** * @brief The commit call initializes writing back the registered variables. @@ -84,8 +87,7 @@ public: * - @c COMMITING_WITHOUT_READING if set was not read yet and * contains non write-only variables */ - virtual ReturnValue_t commit( - MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, + virtual ReturnValue_t commit(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, uint32_t lockTimeout = 20) override; /** diff --git a/datapoollocal/LocalPoolDataSetBase.cpp b/datapoollocal/LocalPoolDataSetBase.cpp index 00293645b..d1d95d8a8 100644 --- a/datapoollocal/LocalPoolDataSetBase.cpp +++ b/datapoollocal/LocalPoolDataSetBase.cpp @@ -67,9 +67,19 @@ LocalPoolDataSetBase::LocalPoolDataSetBase( LocalPoolDataSetBase::~LocalPoolDataSetBase() { + /* We only delete objects which were created in the class constructor */ if(periodicHelper != nullptr) { delete periodicHelper; } + /* In case set was read but not comitted, we commit all variables with an invalid state */ + if(state == States::STATE_SET_WAS_READ) { + for (uint16_t count = 0; count < fillCount; count++) { + if(registeredVariables[count] != nullptr) { + registeredVariables[count]->setValid(false); + registeredVariables[count]->commit(MutexIF::TimeoutType::WAITING, 20); + } + } + } } ReturnValue_t LocalPoolDataSetBase::lockDataPool( diff --git a/datapoollocal/LocalPoolDataSetBase.h b/datapoollocal/LocalPoolDataSetBase.h index cc41b0eb2..ca9074311 100644 --- a/datapoollocal/LocalPoolDataSetBase.h +++ b/datapoollocal/LocalPoolDataSetBase.h @@ -97,12 +97,18 @@ public: * @brief The destructor automatically manages writing the valid * information of variables. * @details - * In case the data set was read out, but not committed(indicated by state), + * In case the data set was read out, but not committed (indicated by state), * the destructor parses all variables that are still registered to the set. * For each, the valid flag in the data pool is set to "invalid". */ ~LocalPoolDataSetBase(); + /* The copy constructor and assingment constructor are forbidden for now. + The use-cases are limited and the first step would be to implement them properly for the + base class */ + LocalPoolDataSetBase(const LocalPoolDataSetBase& otherSet) = delete; + const LocalPoolDataSetBase& operator=(const LocalPoolDataSetBase& otherSet) = delete; + void setValidityBufferGeneration(bool withValidityBuffer); sid_t getSid() const; @@ -153,6 +159,7 @@ public: bool hasChanged() const override; object_id_t getCreatorObjectId(); + protected: sid_t sid; //! This mutex is used if the data is created by one object only.