diff --git a/datapoollocal/LocalDataPoolManager.cpp b/datapoollocal/LocalDataPoolManager.cpp index 4f124e7f..45ad7647 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/datapoollocal/LocalDataPoolManager.cpp @@ -88,9 +88,8 @@ ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() { } ReturnValue_t LocalDataPoolManager::performHkOperation() { + ReturnValue_t status = HasReturnvaluesIF::RETURN_OK; for(auto& receiver: hkReceiversMap) { - //HkReceiver* receiver = &hkReceiversIter.second; - switch(receiver.reportingType) { case(ReportingType::PERIODIC): { if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { @@ -100,8 +99,46 @@ ReturnValue_t LocalDataPoolManager::performHkOperation() { performPeriodicHkGeneration(receiver); break; } + case(ReportingType::UPDATE_HK): { + if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { + // Periodic packets shall only be generated from datasets. + continue; + } + LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( + receiver.dataId.sid); + if(dataSet->hasChanged()) { + // prepare and send update notification + ReturnValue_t result = generateHousekeepingPacket( + receiver.dataId.sid, dataSet, true); + if(result != HasReturnvaluesIF::RETURN_OK) { + status = result; + } + } + break; + } + case(ReportingType::UPDATE_NOTIFICATION): { + if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { + } + else { + LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( + receiver.dataId.sid); + if(dataSet->hasChanged()) { + // prepare and send update notification + } + } + break; + } case(ReportingType::UPDATE_SNAPSHOT): { // check whether data has changed and send messages in case it has. + if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { + } + else { + LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( + receiver.dataId.sid); + if(dataSet->hasChanged()) { + // prepare and send update snapshot. + } + } break; } default: @@ -109,7 +146,7 @@ ReturnValue_t LocalDataPoolManager::performHkOperation() { return HasReturnvaluesIF::RETURN_FAILED; } } - return HasReturnvaluesIF::RETURN_OK; + return status; } ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, @@ -368,8 +405,7 @@ ReturnValue_t LocalDataPoolManager::changeCollectionInterval(sid_t sid, ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid, bool isDiagnostics) { // Get and check dataset first. - LocalPoolDataSetBase* dataSet = dynamic_cast( - owner->getDataSetHandle(sid)); + LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); if(dataSet == nullptr) { sif::warning << "HousekeepingManager::generateHousekeepingPacket:" << " Set ID not found" << std::endl; diff --git a/datapoollocal/LocalPoolDataSetBase.cpp b/datapoollocal/LocalPoolDataSetBase.cpp index da0a86b2..e9adaa5a 100644 --- a/datapoollocal/LocalPoolDataSetBase.cpp +++ b/datapoollocal/LocalPoolDataSetBase.cpp @@ -226,7 +226,7 @@ void LocalPoolDataSetBase::setChanged(bool changed) { this->changed = changed; } -bool LocalPoolDataSetBase::isChanged() const { +bool LocalPoolDataSetBase::hasChanged() const { return changed; } diff --git a/datapoollocal/LocalPoolDataSetBase.h b/datapoollocal/LocalPoolDataSetBase.h index d00af992..2774f507 100644 --- a/datapoollocal/LocalPoolDataSetBase.h +++ b/datapoollocal/LocalPoolDataSetBase.h @@ -117,7 +117,7 @@ public: bool isValid() const override; void setChanged(bool changed); - bool isChanged() const; + bool hasChanged() const; protected: sid_t sid; diff --git a/datapoollocal/LocalPoolObjectBase.cpp b/datapoollocal/LocalPoolObjectBase.cpp new file mode 100644 index 00000000..b6302e7e --- /dev/null +++ b/datapoollocal/LocalPoolObjectBase.cpp @@ -0,0 +1,67 @@ +#include "LocalPoolObjectBase.h" + +LocalPoolObjectBase::LocalPoolObjectBase(lp_id_t poolId, + HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet, + pool_rwm_t setReadWriteMode) { + if(poolId == PoolVariableIF::NO_PARAMETER) { + sif::warning << "LocalPoolVar::LocalPoolVar: 0 passed as pool ID, " + << "which is the NO_PARAMETER value!" << std::endl; + } + if(hkOwner == nullptr) { + sif::error << "LocalPoolVar::LocalPoolVar: The supplied pool " + << "owner is a invalid!" << std::endl; + return; + } + hkManager = hkOwner->getHkManagerHandle(); + if (dataSet != nullptr) { + dataSet->registerVariable(this); + } +} + +LocalPoolObjectBase::LocalPoolObjectBase(lp_id_t poolId, object_id_t poolOwner, + DataSetIF *dataSet, pool_rwm_t setReadWriteMode) { + if(poolId == PoolVariableIF::NO_PARAMETER) { + sif::warning << "LocalPoolVar::LocalPoolVar: 0 passed as pool ID, " + << "which is the NO_PARAMETER value!" << std::endl; + } + HasLocalDataPoolIF* hkOwner = + objectManager->get(poolOwner); + if(hkOwner == nullptr) { + sif::error << "LocalPoolVariable: The supplied pool owner did not " + << "implement the correct interface" + << " HasLocalDataPoolIF!" << std::endl; + return; + } + hkManager = hkOwner->getHkManagerHandle(); + if(dataSet != nullptr) { + dataSet->registerVariable(this); + } +} + +pool_rwm_t LocalPoolObjectBase::getReadWriteMode() const { + return readWriteMode; +} + +bool LocalPoolObjectBase::isValid() const { + return valid; +} + +void LocalPoolObjectBase::setValid(bool valid) { + this->valid = valid; +} + +lp_id_t LocalPoolObjectBase::getDataPoolId() const { + return localPoolId; +} + +void LocalPoolObjectBase::setDataPoolId(lp_id_t poolId) { + this->localPoolId = poolId; +} + +void LocalPoolObjectBase::setChanged(bool changed) { + this->changed = changed; +} + +bool LocalPoolObjectBase::hasChanged() const { + return changed; +} diff --git a/datapoollocal/LocalPoolObjectBase.h b/datapoollocal/LocalPoolObjectBase.h new file mode 100644 index 00000000..8445b764 --- /dev/null +++ b/datapoollocal/LocalPoolObjectBase.h @@ -0,0 +1,58 @@ +#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ +#define FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ + +#include "../datapoollocal/LocalDataPoolManager.h" +#include "../datapool/PoolVariableIF.h" + +class LocalPoolObjectBase: public PoolVariableIF, HasReturnvaluesIF { +public: + LocalPoolObjectBase(lp_id_t poolId, + HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet, + pool_rwm_t setReadWriteMode); + + LocalPoolObjectBase(lp_id_t poolId, object_id_t poolOwner, + DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); + + pool_rwm_t getReadWriteMode() const; + + bool isValid() const override; + void setValid(bool valid) override; + + void setChanged(bool changed); + bool hasChanged() const; + + lp_id_t getDataPoolId() const override; + void setDataPoolId(lp_id_t poolId); + +protected: + /** + * @brief To access the correct data pool entry on read and commit calls, + * the data pool id is stored. + */ + uint32_t localPoolId = PoolVariableIF::NO_PARAMETER; + /** + * @brief The valid information as it was stored in the data pool + * is copied to this attribute. + */ + bool valid = false; + + /** + * @brief A local pool variable can be marked as changed. + */ + bool changed = false; + + /** + * @brief The information whether the class is read-write or + * read-only is stored here. + */ + ReadWriteMode_t readWriteMode = pool_rwm_t::VAR_READ_WRITE; + + //! @brief Pointer to the class which manages the HK pool. + LocalDataPoolManager* hkManager; + +}; + + + +#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ */ diff --git a/datapoollocal/LocalPoolVariable.h b/datapoollocal/LocalPoolVariable.h index ec5c8cd1..e9d94178 100644 --- a/datapoollocal/LocalPoolVariable.h +++ b/datapoollocal/LocalPoolVariable.h @@ -1,6 +1,7 @@ #ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ #define FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ +#include "LocalPoolObjectBase.h" #include "HasLocalDataPoolIF.h" #include "LocalDataPoolManager.h" @@ -21,7 +22,7 @@ * @ingroup data_pool */ template -class LocalPoolVar: public PoolVariableIF, HasReturnvaluesIF { +class LocalPoolVar: public LocalPoolObjectBase { public: //! Default ctor is forbidden. LocalPoolVar() = delete; @@ -76,15 +77,6 @@ public: */ T value = 0; - pool_rwm_t getReadWriteMode() const override; - - lp_id_t getDataPoolId() const override; - void setDataPoolId(lp_id_t poolId); - - bool isValid() const override; - void setValid(bool validity) override; - uint8_t getValid() const; - ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, SerializeIF::Endianness streamEndianness) const override; virtual size_t getSerializedSize() const override; @@ -145,15 +137,6 @@ protected: const LocalPoolVar &var); private: - //! @brief Pool ID of pool entry inside the used local pool. - lp_id_t localPoolId = PoolVariableIF::NO_PARAMETER; - //! @brief Read-write mode of the pool variable - pool_rwm_t readWriteMode = pool_rwm_t::VAR_READ_WRITE; - //! @brief Specifies whether the entry is valid or invalid. - bool valid = false; - - //! Pointer to the class which manages the HK pool. - LocalDataPoolManager* hkManager; }; #include "LocalPoolVariable.tpp" diff --git a/datapoollocal/LocalPoolVariable.tpp b/datapoollocal/LocalPoolVariable.tpp index b0bdd7b9..3320aa5a 100644 --- a/datapoollocal/LocalPoolVariable.tpp +++ b/datapoollocal/LocalPoolVariable.tpp @@ -9,43 +9,12 @@ template inline LocalPoolVar::LocalPoolVar(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet, pool_rwm_t setReadWriteMode): - localPoolId(poolId), readWriteMode(setReadWriteMode) { - if(poolId == PoolVariableIF::NO_PARAMETER) { - sif::warning << "LocalPoolVar::LocalPoolVar: 0 passed as pool ID, " - << "which is the NO_PARAMETER value!" << std::endl; - } - if(hkOwner == nullptr) { - sif::error << "LocalPoolVar::LocalPoolVar: The supplied pool " - << "owner is a invalid!" << std::endl; - return; - } - hkManager = hkOwner->getHkManagerHandle(); - if(dataSet != nullptr) { - dataSet->registerVariable(this); - } -} + LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {} template inline LocalPoolVar::LocalPoolVar(lp_id_t poolId, object_id_t poolOwner, DataSetIF *dataSet, pool_rwm_t setReadWriteMode): - localPoolId(poolId), readWriteMode(setReadWriteMode) { - if(poolId == PoolVariableIF::NO_PARAMETER) { - sif::warning << "LocalPoolVar::LocalPoolVar: 0 passed as pool ID, " - << "which is the NO_PARAMETER value!" << std::endl; - } - HasLocalDataPoolIF* hkOwner = - objectManager->get(poolOwner); - if(hkOwner == nullptr) { - sif::error << "LocalPoolVariable: The supplied pool owner did not " - << "implement the correct interface " - << "HasLocalDataPoolIF!" << std::endl; - return; - } - hkManager = hkOwner->getHkManagerHandle(); - if(dataSet != nullptr) { - dataSet->registerVariable(this); - } -} + LocalPoolObjectBase(poolId, poolOwner, dataSet, setReadWriteMode) {} template inline ReturnValue_t LocalPoolVar::read(dur_millis_t lockTimeout) { @@ -111,36 +80,6 @@ inline LocalPoolVar & LocalPoolVar::operator =(T newValue) { } -template -inline pool_rwm_t LocalPoolVar::getReadWriteMode() const { - return readWriteMode; -} - -template -inline lp_id_t LocalPoolVar::getDataPoolId() const { - return localPoolId; -} - -template -inline void LocalPoolVar::setDataPoolId(lp_id_t poolId) { - this->localPoolId = poolId; -} - -template -inline bool LocalPoolVar::isValid() const { - return valid; -} - -template -inline void LocalPoolVar::setValid(bool validity) { - this->valid = validity; -} - -template -inline uint8_t LocalPoolVar::getValid() const { - return valid; -} - template inline ReturnValue_t LocalPoolVar::serialize(uint8_t** buffer, size_t* size, const size_t max_size, SerializeIF::Endianness streamEndianness) const { diff --git a/datapoollocal/LocalPoolVector.h b/datapoollocal/LocalPoolVector.h index 57c4b90b..a7ebd3fe 100644 --- a/datapoollocal/LocalPoolVector.h +++ b/datapoollocal/LocalPoolVector.h @@ -1,6 +1,7 @@ #ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ #define FRAMEWORK_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ +#include "LocalPoolObjectBase.h" #include "../datapool/DataSetIF.h" #include "../datapool/PoolEntry.h" #include "../datapool/PoolVariableIF.h" @@ -30,7 +31,7 @@ * @ingroup data_pool */ template -class LocalPoolVector: public PoolVariableIF, public HasReturnvaluesIF { +class LocalPoolVector: public LocalPoolObjectBase { public: LocalPoolVector() = delete; /** @@ -48,8 +49,7 @@ public: */ LocalPoolVector(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet = nullptr, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE - ); + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); /** * This constructor is used by data users like controllers to have @@ -67,8 +67,7 @@ public: */ LocalPoolVector(lp_id_t poolId, object_id_t poolOwner, DataSetIF* dataSet = nullptr, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE - ); + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); /** * @brief This is the local copy of the data pool entry. @@ -91,27 +90,6 @@ public: return vectorSize; } - uint32_t getDataPoolId() const override; - /** - * @brief This operation sets the data pool ID of the variable. - * @details - * The method is necessary to set id's of data pool member variables - * with bad initialization. - */ - void setDataPoolId(uint32_t poolId); - - /** - * This method returns if the variable is write-only, read-write or read-only. - */ - pool_rwm_t getReadWriteMode() const; - - /** - * @brief With this call, the valid information of the variable is returned. - */ - bool isValid() const override; - void setValid(bool valid) override; - uint8_t getValid() const; - T& operator [](int i); const T &operator [](int i) const; @@ -168,23 +146,7 @@ protected: ReturnValue_t commitWithoutLock() override; private: - /** - * @brief To access the correct data pool entry on read and commit calls, - * the data pool id is stored. - */ - uint32_t localPoolId; - /** - * @brief The valid information as it was stored in the data pool - * is copied to this attribute. - */ - bool valid; - /** - * @brief The information whether the class is read-write or - * read-only is stored here. - */ - ReadWriteMode_t readWriteMode; - //! @brief Pointer to the class which manages the HK pool. - LocalDataPoolManager* hkManager; + // std::ostream is the type for object std::cout template diff --git a/datapoollocal/LocalPoolVector.tpp b/datapoollocal/LocalPoolVector.tpp index 2aa6fbb5..34720b97 100644 --- a/datapoollocal/LocalPoolVector.tpp +++ b/datapoollocal/LocalPoolVector.tpp @@ -9,39 +9,12 @@ template inline LocalPoolVector::LocalPoolVector(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet, pool_rwm_t setReadWriteMode): - localPoolId(poolId), valid(false), readWriteMode(setReadWriteMode) { - if(poolId == PoolVariableIF::NO_PARAMETER) { - sif::warning << "LocalPoolVector: PoolVariableIF::NO_PARAMETER passed " - << "as pool ID, which is the NO_PARAMETER value!" << std::endl; - } - std::memset(this->value, 0, vectorSize * sizeof(T)); - hkManager = hkOwner->getHkManagerHandle(); - if (dataSet != nullptr) { - dataSet->registerVariable(this); - } -} + LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {} template inline LocalPoolVector::LocalPoolVector(lp_id_t poolId, object_id_t poolOwner, DataSetIF *dataSet, pool_rwm_t setReadWriteMode): - readWriteMode(setReadWriteMode) { - if(poolId == PoolVariableIF::NO_PARAMETER) { - sif::warning << "LocalPoolVector: PoolVariableIF::NO_PARAMETER passed " - << "as pool ID, which is the NO_PARAMETER value!" << std::endl; - } - HasLocalDataPoolIF* hkOwner = - objectManager->get(poolOwner); - if(hkOwner == nullptr) { - sif::error << "LocalPoolVariable: The supplied pool owner did not " - << "implement the correct interface HasHkPoolParametersIF!" - << std::endl; - return; - } - hkManager = hkOwner->getHkManagerHandle(); - if(dataSet != nullptr) { - dataSet->registerVariable(this); - } -} + LocalPoolObjectBase(poolId, poolOwner, dataSet, setReadWriteMode) {} template inline ReturnValue_t LocalPoolVector::read(uint32_t lockTimeout) { @@ -161,37 +134,6 @@ inline ReturnValue_t LocalPoolVector::deSerialize( return result; } -template -inline pool_rwm_t LocalPoolVector::getReadWriteMode() const { - return this->readWriteMode; -} - - -template -inline uint32_t LocalPoolVector::getDataPoolId() const { - return localPoolId; -} - -template -inline void LocalPoolVector::setDataPoolId(uint32_t poolId) { - this->localPoolId = poolId; -} - -template -inline void LocalPoolVector::setValid(bool valid) { - this->valid = valid; -} - -template -inline uint8_t LocalPoolVector::getValid() const { - return valid; -} - -template -inline bool LocalPoolVector::isValid() const { - return valid; -} - template inline std::ostream& operator<< (std::ostream &out, const LocalPoolVector &var) {