From ac9e6e1337acc8a5f68811be1f5da30c69a3e52e Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 9 Jul 2020 00:59:10 +0200 Subject: [PATCH] continued with local data pool manager --- datapoolglob/GlobalDataSet.h | 6 +- ...LocalDataPoolIF.h => HasLocalDataPoolIF.h} | 4 +- datapoollocal/LocalDataPoolManager.cpp | 14 +-- datapoollocal/LocalDataPoolManager.h | 95 ++++++++++++++----- datapoollocal/LocalDataSet.cpp | 4 +- datapoollocal/LocalDataSet.h | 4 +- datapoollocal/LocalPoolVariable.h | 4 +- datapoollocal/LocalPoolVariable.tpp | 6 +- datapoollocal/LocalPoolVector.h | 2 +- datapoollocal/LocalPoolVector.tpp | 6 +- devicehandlers/DeviceHandlerBase.h | 5 +- 11 files changed, 97 insertions(+), 53 deletions(-) rename datapoollocal/{OwnsLocalDataPoolIF.h => HasLocalDataPoolIF.h} (97%) diff --git a/datapoolglob/GlobalDataSet.h b/datapoolglob/GlobalDataSet.h index 519b08c0..d237cc1b 100644 --- a/datapoolglob/GlobalDataSet.h +++ b/datapoolglob/GlobalDataSet.h @@ -1,5 +1,5 @@ -#ifndef DATASET_H_ -#define DATASET_H_ +#ifndef FRAMEWORK_DATAPOOLGLOB_DATASET_H_ +#define FRAMEWORK_DATAPOOLGLOB_DATASET_H_ #include @@ -93,4 +93,4 @@ private: PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE]; }; -#endif /* DATASET_H_ */ +#endif /* FRAMEWORK_DATAPOOLGLOB_DATASET_H_ */ diff --git a/datapoollocal/OwnsLocalDataPoolIF.h b/datapoollocal/HasLocalDataPoolIF.h similarity index 97% rename from datapoollocal/OwnsLocalDataPoolIF.h rename to datapoollocal/HasLocalDataPoolIF.h index 6fc10889..0095f894 100644 --- a/datapoollocal/OwnsLocalDataPoolIF.h +++ b/datapoollocal/HasLocalDataPoolIF.h @@ -36,9 +36,9 @@ using LocalDataPoolMapIter = LocalDataPool::iterator; * pragmatic solution I found was to offer the client the full interface * of the LocalDataPoolManager. */ -class OwnsLocalDataPoolIF { +class HasLocalDataPoolIF { public: - virtual~ OwnsLocalDataPoolIF() {}; + virtual~ HasLocalDataPoolIF() {}; static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_POOL_OWNER_IF; diff --git a/datapoollocal/LocalDataPoolManager.cpp b/datapoollocal/LocalDataPoolManager.cpp index 9c70c74f..02016abf 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/datapoollocal/LocalDataPoolManager.cpp @@ -7,7 +7,7 @@ #include -LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner, +LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQueueIF* queueToUse, bool appendValidityBuffer): appendValidityBuffer(appendValidityBuffer) { if(owner == nullptr) { @@ -63,7 +63,7 @@ LocalDataPoolManager::~LocalDataPoolManager() {} ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() { if(not mapInitialized) { - ReturnValue_t result = owner->initializePoolEntries(localDpMap); + ReturnValue_t result = owner->initializePoolEntries(localPoolMap); if(result == HasReturnvaluesIF::RETURN_OK) { mapInitialized = true; } @@ -96,8 +96,8 @@ ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage( ReturnValue_t LocalDataPoolManager::printPoolEntry( lp_id_t localPoolId) { - auto poolIter = localDpMap.find(localPoolId); - if (poolIter == localDpMap.end()) { + auto poolIter = localPoolMap.find(localPoolId); + if (poolIter == localPoolMap.end()) { sif::debug << "HousekeepingManager::fechPoolEntry:" " Pool entry not found." << std::endl; return POOL_ENTRY_NOT_FOUND; @@ -110,7 +110,7 @@ MutexIF* LocalDataPoolManager::getMutexHandle() { return mutex; } -const OwnsLocalDataPoolIF* LocalDataPoolManager::getOwner() const { +const HasLocalDataPoolIF* LocalDataPoolManager::getOwner() const { return owner; } @@ -213,4 +213,6 @@ ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore( return result; } - +ReturnValue_t LocalDataPoolManager::performHkOperation() { + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/datapoollocal/LocalDataPoolManager.h b/datapoollocal/LocalDataPoolManager.h index 3841b99c..847c309c 100644 --- a/datapoollocal/LocalDataPoolManager.h +++ b/datapoollocal/LocalDataPoolManager.h @@ -1,12 +1,13 @@ -#ifndef FRAMEWORK_HK_HOUSEKEEPINGHELPER_H_ -#define FRAMEWORK_HK_HOUSEKEEPINGHELPER_H_ +#ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_ +#define FRAMEWORK_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_ + #include #include #include #include #include -#include +#include #include #include #include @@ -20,7 +21,7 @@ class LocalDataSet; * @details * The actual data pool structure is a member of this class. Any class which * has a local data pool shall have this class as a member and implement - * the OwnsLocalDataPoolIF. + * the HasLocalDataPoolIF. * * Users of the data pool use the helper classes LocalDataSet, * LocalPoolVariable and LocalPoolVector to access pool entries in @@ -57,16 +58,24 @@ public: * @param queueToUse * @param appendValidityBuffer */ - LocalDataPoolManager(OwnsLocalDataPoolIF* owner, MessageQueueIF* queueToUse, + LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQueueIF* queueToUse, bool appendValidityBuffer = true); + virtual~ LocalDataPoolManager(); + /** * Initializes the map by calling the map initialization function of the - * owner abd assigns the queue to use. + * owner and assigns the queue to use. * @param queueToUse * @return */ ReturnValue_t initialize(MessageQueueIF* queueToUse, object_id_t hkDestination); + /** + * This should be called in the periodic handler of the owner. + * It performs all the periodic functionalities of the data pool manager. + * @return + */ + ReturnValue_t performHkOperation(); /** * This function is used to set the default HK packet destination. * This destination will usually only be set once. @@ -74,8 +83,6 @@ public: */ void setHkPacketDestination(MessageQueueId_t hkDestination); - virtual~ LocalDataPoolManager(); - /** * Generate a housekeeping packet with a given SID. * @param sid @@ -95,28 +102,64 @@ public: */ ReturnValue_t initializeHousekeepingPoolEntriesOnce(); - const OwnsLocalDataPoolIF* getOwner() const; + const HasLocalDataPoolIF* getOwner() const; ReturnValue_t printPoolEntry(lp_id_t localPoolId); + /** + * Different types of housekeeping reporting are possible. + * 1. PERIODIC: HK packets are generated in fixed intervals + * 2. UPDATED: HK packets are generated if a value was updated + * 3. REQUESTED: HK packets are only generated if explicitely requested + */ + enum class ReportingType: uint8_t { + PERIODIC, + ON_UPDATE, + REQUESTED + }; + /* Copying forbidden */ LocalDataPoolManager(const LocalDataPoolManager &) = delete; LocalDataPoolManager operator=(const LocalDataPoolManager&) = delete; + private: - /** This is the map holding the actual data. Should only be initialized - * once ! */ - bool mapInitialized = false; - /** This specifies whether a validity buffer is appended at the end - * of generated housekeeping packets. */ - bool appendValidityBuffer = true; + LocalDataPool localPoolMap; + /** Every housekeeping data manager has a mutex to protect access + * to it's data pool. */ + MutexIF* mutex = nullptr; + /** The class which actually owns the manager (and its datapool). */ + HasLocalDataPoolIF* owner = nullptr; - LocalDataPool localDpMap; + /** + * The data pool manager will keep an internal map of HK receivers. + */ + struct HkReceiver { + LocalDataSet* dataSet = nullptr; + MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE; + ReportingType reportingType = ReportingType::PERIODIC; + bool reportingStatus = true; + /** Different members of this union will be used depending on reporting + * type */ + union hkParameter { + /** This parameter will be used for the PERIODIC type */ + dur_seconds_t collectionInterval = 0; + /** This parameter will be used for the ON_UPDATE type */ + bool hkDataChanged; + }; + }; + + /** Using a multimap as the same object might request multiple datasets */ + using HkReceiversMap = std::multimap; + + HkReceiversMap hkReceiversMap; + + /** This is the map holding the actual data. Should only be initialized + * once ! */ + bool mapInitialized = false; + /** This specifies whether a validity buffer is appended at the end + * of generated housekeeping packets. */ + bool appendValidityBuffer = true; - /** Every housekeeping data manager has a mutex to protect access - * to it's data pool. */ - MutexIF * mutex = nullptr; - /** The class which actually owns the manager (and its datapool). */ - OwnsLocalDataPoolIF* owner = nullptr; /** * @brief Queue used for communication, for example commands. * Is also used to send messages. Can be set either in the constructor @@ -165,10 +208,10 @@ private: template inline ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId, PoolEntry **poolEntry) { - auto poolIter = localDpMap.find(localPoolId); - if (poolIter == localDpMap.end()) { - sif::debug << "HousekeepingManager::fechPoolEntry:" - " Pool entry not found." << std::endl; + auto poolIter = localPoolMap.find(localPoolId); + if (poolIter == localPoolMap.end()) { + sif::warning << "HousekeepingManager::fechPoolEntry: Pool entry " + "not found." << std::endl; return POOL_ENTRY_NOT_FOUND; } @@ -182,4 +225,4 @@ ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId, } -#endif /* FRAMEWORK_HK_HOUSEKEEPINGHELPER_H_ */ +#endif /* FRAMEWORK_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_ */ diff --git a/datapoollocal/LocalDataSet.cpp b/datapoollocal/LocalDataSet.cpp index 272a1b6f..2a42cd38 100644 --- a/datapoollocal/LocalDataSet.cpp +++ b/datapoollocal/LocalDataSet.cpp @@ -5,7 +5,7 @@ #include #include -LocalDataSet::LocalDataSet(OwnsLocalDataPoolIF *hkOwner, +LocalDataSet::LocalDataSet(HasLocalDataPoolIF *hkOwner, const size_t maxNumberOfVariables): DataSetBase(poolVarList.data(), maxNumberOfVariables) { poolVarList.reserve(maxNumberOfVariables); @@ -23,7 +23,7 @@ LocalDataSet::LocalDataSet(object_id_t ownerId, DataSetBase(poolVarList.data(), maxNumberOfVariables) { poolVarList.reserve(maxNumberOfVariables); poolVarList.resize(maxNumberOfVariables); - OwnsLocalDataPoolIF* hkOwner = objectManager->get( + HasLocalDataPoolIF* hkOwner = objectManager->get( ownerId); if(hkOwner == nullptr) { sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!" diff --git a/datapoollocal/LocalDataSet.h b/datapoollocal/LocalDataSet.h index 20c647ca..2c70de82 100644 --- a/datapoollocal/LocalDataSet.h +++ b/datapoollocal/LocalDataSet.h @@ -2,7 +2,7 @@ #define FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_ #include #include -#include +#include #include #include @@ -37,7 +37,7 @@ public: * The constructor simply sets the fill_count to zero and sets * the state to "uninitialized". */ - LocalDataSet(OwnsLocalDataPoolIF *hkOwner, + LocalDataSet(HasLocalDataPoolIF *hkOwner, const size_t maxNumberOfVariables); /** diff --git a/datapoollocal/LocalPoolVariable.h b/datapoollocal/LocalPoolVariable.h index 98782b8d..73d691d7 100644 --- a/datapoollocal/LocalPoolVariable.h +++ b/datapoollocal/LocalPoolVariable.h @@ -3,8 +3,8 @@ #include #include +#include #include -#include #include #include @@ -42,7 +42,7 @@ public: * @param dataSet The data set in which the variable shall register itself. * If nullptr, the variable is not registered. */ - LocalPoolVar(lp_id_t poolId, OwnsLocalDataPoolIF* hkOwner, + LocalPoolVar(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE, DataSetIF* dataSet = nullptr); diff --git a/datapoollocal/LocalPoolVariable.tpp b/datapoollocal/LocalPoolVariable.tpp index 7f9fbf13..0b96bb4f 100644 --- a/datapoollocal/LocalPoolVariable.tpp +++ b/datapoollocal/LocalPoolVariable.tpp @@ -7,7 +7,7 @@ template inline LocalPoolVar::LocalPoolVar(lp_id_t poolId, - OwnsLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode, + HasLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode, DataSetIF* dataSet): localPoolId(poolId),readWriteMode(setReadWriteMode) { if(poolId == PoolVariableIF::NO_PARAMETER) { @@ -33,8 +33,8 @@ inline LocalPoolVar::LocalPoolVar(lp_id_t poolId, object_id_t poolOwner, sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the " "NO_PARAMETER value!" << std::endl; } - OwnsLocalDataPoolIF* hkOwner = - objectManager->get(poolOwner); + HasLocalDataPoolIF* hkOwner = + objectManager->get(poolOwner); if(hkOwner == nullptr) { sif::error << "LocalPoolVariable: The supplied pool owner did not implement" "the correct interface HasHkPoolParametersIF!" << std::endl; diff --git a/datapoollocal/LocalPoolVector.h b/datapoollocal/LocalPoolVector.h index f6532894..3083646f 100644 --- a/datapoollocal/LocalPoolVector.h +++ b/datapoollocal/LocalPoolVector.h @@ -46,7 +46,7 @@ public: * @param dataSet The data set in which the variable shall register itself. * If nullptr, the variable is not registered. */ - LocalPoolVector(lp_id_t poolId, OwnsLocalDataPoolIF* hkOwner, + LocalPoolVector(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE, DataSetIF* dataSet = nullptr); diff --git a/datapoollocal/LocalPoolVector.tpp b/datapoollocal/LocalPoolVector.tpp index 872c49ec..b7f2fe19 100644 --- a/datapoollocal/LocalPoolVector.tpp +++ b/datapoollocal/LocalPoolVector.tpp @@ -7,7 +7,7 @@ template inline LocalPoolVector::LocalPoolVector(lp_id_t poolId, - OwnsLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode, + HasLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode, DataSetIF* dataSet) : localPoolId(poolId), valid(false), readWriteMode(setReadWriteMode) { if(poolId == PoolVariableIF::NO_PARAMETER) { @@ -29,8 +29,8 @@ inline LocalPoolVector::LocalPoolVector(lp_id_t poolId, sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the " "NO_PARAMETER value!" << std::endl; } - OwnsLocalDataPoolIF* hkOwner = - objectManager->get(poolOwner); + HasLocalDataPoolIF* hkOwner = + objectManager->get(poolOwner); if(hkOwner == nullptr) { sif::error << "LocalPoolVariable: The supplied pool owner did not implement" "the correct interface HasHkPoolParametersIF!" << std::endl; diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 3fdab9ed..ce7f7b9f 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -17,10 +17,9 @@ #include #include #include +#include #include #include -#include - #include namespace Factory{ @@ -88,7 +87,7 @@ class DeviceHandlerBase: public DeviceHandlerIF, public HasHealthIF, public HasActionsIF, public ReceivesParameterMessagesIF, - public OwnsLocalDataPoolIF { + public HasLocalDataPoolIF { friend void (Factory::setStaticFrameworkObjectIds)(); public: /**