diff --git a/datapool/PoolVariableIF.h b/datapool/PoolVariableIF.h index dead6844a..dbb9db15c 100644 --- a/datapool/PoolVariableIF.h +++ b/datapool/PoolVariableIF.h @@ -46,6 +46,8 @@ public: * read-write or read-only. */ virtual ReadWriteMode_t getReadWriteMode() const = 0; + virtual void setReadWriteMode(ReadWriteMode_t newMode) = 0; + /** * @brief This operation shall return the data pool id of the variable. */ @@ -59,7 +61,6 @@ public: * @brief With this call, the valid information of the variable is set. */ virtual void setValid(bool validity) = 0; - }; using pool_rwm_t = PoolVariableIF::ReadWriteMode_t; diff --git a/datapoollocal/LocalPoolDataSetBase.cpp b/datapoollocal/LocalPoolDataSetBase.cpp index d043d18f5..daa54fb33 100644 --- a/datapoollocal/LocalPoolDataSetBase.cpp +++ b/datapoollocal/LocalPoolDataSetBase.cpp @@ -288,7 +288,7 @@ bool LocalPoolDataSetBase::isValid() const { void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) { if(setEntriesRecursively) { for(size_t idx = 0; idx < this->getFillCount(); idx++) { - registeredVariables[idx] -> setValid(valid); + registeredVariables[idx]->setValid(valid); } } this->valid = valid; @@ -301,3 +301,8 @@ object_id_t LocalPoolDataSetBase::getCreatorObjectId() { return objects::NO_OBJECT; } +void LocalPoolDataSetBase::setAllVariablesReadOnly() { + for(size_t idx = 0; idx < this->getFillCount(); idx++) { + registeredVariables[idx]->setReadWriteMode(pool_rwm_t::VAR_READ); + } +} diff --git a/datapoollocal/LocalPoolDataSetBase.h b/datapoollocal/LocalPoolDataSetBase.h index 9501f7821..404509ae5 100644 --- a/datapoollocal/LocalPoolDataSetBase.h +++ b/datapoollocal/LocalPoolDataSetBase.h @@ -109,6 +109,12 @@ public: LocalPoolDataSetBase(const LocalPoolDataSetBase& otherSet) = delete; const LocalPoolDataSetBase& operator=(const LocalPoolDataSetBase& otherSet) = delete; + /** + * Helper functions used to set all currently contained variables to read-only. + * It is recommended to call this in set constructors intended to be used + * by data consumers to prevent accidentally changing pool data. + */ + void setAllVariablesReadOnly(); void setValidityBufferGeneration(bool withValidityBuffer); sid_t getSid() const; diff --git a/doc/README-localpools.md b/doc/README-localpools.md index 8dd83385e..57a41aa14 100644 --- a/doc/README-localpools.md +++ b/doc/README-localpools.md @@ -1,3 +1,29 @@ ## Local Data Pools +The local data pools can be used to store data like sensor values so they can be used +by other software objects like controllers as well. If a class should have a local pool which +can be used by other software objects as well, following steps have to be performed: +1. Create a `LocalDataPoolManager` member class +2. Implement the `HasLocalDataPoolIF` + +The local data pool manager is also able to process housekeeping service requests in form +of messages, generate periodic housekeeping packet, generate notification and snapshots of changed +variables and datasets and process notifications and snapshots coming from other objects. +Two important framework classes already perform the two steps shown above so the steps required +are altered slightly. + +### Storing and Accessing pool data + +The pool manager is responsible for thread-safe access of the pool data, but the actual +access to the pool data is done via proxy classes like pool variable classes or dataset classes. +Generally, a user will create a dataset class which in turn groups all cohesive pool variables. + +The user can then use this set class to `read` the variables and `commit` changed variables +back into the pool. + +### Using the local data pools of the `DeviceHandlerBase` + +It is very common to store data generated by devices like a sensor into a pool which can +then be used by other objects. Therefore, the `DeviceHandlerBase` already has a +local pool. The