diff --git a/controller/ExtendedControllerBase.cpp b/controller/ExtendedControllerBase.cpp index 2b72a89d5..379f189c5 100644 --- a/controller/ExtendedControllerBase.cpp +++ b/controller/ExtendedControllerBase.cpp @@ -26,7 +26,7 @@ object_id_t ExtendedControllerBase::getObjectId() const { return SystemObject::getObjectId(); } -LocalDataPoolManager* ExtendedControllerBase::getHkManagerHandle() { +AccessPoolManagerIF* ExtendedControllerBase::getAccessorHandle() { return &localPoolManager; } @@ -106,10 +106,6 @@ MessageQueueId_t ExtendedControllerBase::getCommandQueue() const { return commandQueue->getId(); } -AccessLocalPoolIF* ExtendedControllerBase::getAccessorHandle() { - return &localPoolManager; -} - LocalPoolDataSetBase* ExtendedControllerBase::getDataSetHandle(sid_t sid) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "ExtendedControllerBase::getDataSetHandle: No child " diff --git a/controller/ExtendedControllerBase.h b/controller/ExtendedControllerBase.h index 47c180e64..ed1d71930 100644 --- a/controller/ExtendedControllerBase.h +++ b/controller/ExtendedControllerBase.h @@ -33,7 +33,7 @@ public: virtual ReturnValue_t initializeAfterTaskCreation() override; ProvidesDataPoolSubscriptionIF* getSubscriptionInterface() override; - AccessLocalPoolIF* getAccessorHandle() override; + AccessPoolManagerIF* getAccessorHandle() override; protected: LocalDataPoolManager localPoolManager; @@ -65,7 +65,6 @@ protected: virtual ReturnValue_t initializeLocalDataPool( LocalDataPool& localDataPoolMap, LocalDataPoolManager& poolManager) override; - virtual LocalDataPoolManager* getHkManagerHandle() override; virtual uint32_t getPeriodicOperationFrequency() const override; virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; }; diff --git a/datapoollocal/AccessLocalPoolF.h b/datapoollocal/AccessLocalPoolF.h index 51d2ec46b..88ccec936 100644 --- a/datapoollocal/AccessLocalPoolF.h +++ b/datapoollocal/AccessLocalPoolF.h @@ -1,31 +1,26 @@ #ifndef FSFW_DATAPOOLLOCAL_ACCESSLOCALPOOLF_H_ #define FSFW_DATAPOOLLOCAL_ACCESSLOCALPOOLF_H_ -#include -#include -#include +//#include "LocalDataPoolManager.h" #include -class AccessLocalPoolIF { -public: - virtual ~AccessLocalPoolIF() {}; +class LocalDataPoolManager; - virtual ReturnValue_t retrieveLocalPoolMutex(MutexIF* mutex) = 0; - virtual object_id_t getCreatorObjectId() const = 0; +class AccessPoolManagerIF { +public: + virtual ~AccessPoolManagerIF() {}; + + virtual MutexIF* getLocalPoolMutex() = 0; + + /** + * Can be used to get a handle to the local data pool manager. + * This function is protected because it should only be used by the + * class imlementing the interface. + */ + virtual LocalDataPoolManager* getHkManagerHandle() = 0; protected: - //virtual LocalDataPoolManager* getHkManagerHandle() = 0; }; -//template -//class AccessLocalPoolTypedIF { -//public: -// virtual ~AccessLocalPoolTypedIF() {}; -// -// virtual ReturnValue_t fetchPoolEntry(lp_id_t localPoolId, PoolEntry **poolEntry) = 0; -//}; - - - #endif /* FSFW_DATAPOOLLOCAL_ACCESSLOCALPOOLF_H_ */ diff --git a/datapoollocal/HasLocalDataPoolIF.h b/datapoollocal/HasLocalDataPoolIF.h index 967abd4a8..c0899203e 100644 --- a/datapoollocal/HasLocalDataPoolIF.h +++ b/datapoollocal/HasLocalDataPoolIF.h @@ -12,7 +12,6 @@ #include -class LocalDataPoolManager; class LocalPoolDataSetBase; class LocalPoolObjectBase; @@ -20,31 +19,26 @@ using LocalDataPool = std::map; using LocalDataPoolMapIter = LocalDataPool::iterator; /** - * @brief This interface is implemented by classes which posses a local - * data pool (not the managing class). It defines the relationship - * between the local data pool owner and the LocalDataPoolManager. + * @brief This interface is implemented by classes which posses a local data pool (not the + * managing class). It defines the relationship between the local data pool owner + * and the LocalDataPoolManager. * @details - * Any class implementing this interface shall also have a LocalDataPoolManager - * member class which contains the actual pool data structure - * and exposes the public interface for it. - * This is required because the pool entries are templates, which makes - * specifying an interface rather difficult. The local data pool can be - * accessed by using the LocalPoolVariable, LocalPoolVector or LocalDataSet - * classes. + * Any class implementing this interface shall also have a LocalDataPoolManager member class which + * contains the actual pool data structure and exposes the public interface for it. + * This is required because the pool entries are templates, which makes specifying an interface + * rather difficult. The local data pool can be accessed by using the LocalPoolVariable, + * LocalPoolVector or LocalDataSet classes. * * Architectural Note: - * This could be circumvented by using a wrapper/accessor function or - * implementing the templated function in this interface.. - * The first solution sounds better than the second but - * the LocalPoolVariable classes are templates as well, so this just shifts - * the problem somewhere else. Interfaces are nice, but the most - * pragmatic solution I found was to offer the client the full interface - * of the LocalDataPoolManager. + * This could be circumvented by using a wrapper/accessor function or implementing the templated + * function in this interface.. The first solution sounds better than the second but the + * LocalPoolVariable classes are templates as well, so this just shifts the problem somewhere else. + * Interfaces are nice, but the most pragmatic solution I found was to offer the client the full + * interface of the LocalDataPoolManager. */ class HasLocalDataPoolIF { - friend class LocalDataPoolManager; - friend class LocalPoolDataSetBase; - friend class LocalPoolObjectBase; + friend class HasLocalDpIFManagerAttorney; + friend class HasLocalDpIFUserAttorney; public: virtual~ HasLocalDataPoolIF() {}; @@ -55,6 +49,8 @@ public: static constexpr uint32_t INVALID_LPID = localpool::INVALID_LPID; + virtual object_id_t getObjectId() const = 0; + /** Command queue for housekeeping messages. */ virtual MessageQueueId_t getCommandQueue() const = 0; @@ -63,8 +59,7 @@ public: * The manager instance shall also be passed to this function. * It can be used to subscribe for periodic packets for for updates. */ - virtual ReturnValue_t initializeLocalDataPool( - LocalDataPool& localDataPoolMap, + virtual ReturnValue_t initializeLocalDataPool(LocalDataPool& localDataPoolMap, LocalDataPoolManager& poolManager) = 0; /** @@ -84,7 +79,7 @@ public: * the IPC store with this store ID. */ virtual void handleChangedDataset(sid_t sid, - store_address_t storeId = storeId::INVALID_STORE_ADDRESS) { + store_address_t storeId = storeId::INVALID_STORE_ADDRESS) { return; } @@ -112,27 +107,20 @@ public: virtual ReturnValue_t removeDataSet(sid_t sid) { return HasReturnvaluesIF::RETURN_FAILED; }; - virtual ReturnValue_t changeCollectionInterval(sid_t sid, - float newIntervalSeconds) { + virtual ReturnValue_t changeCollectionInterval(sid_t sid, float newIntervalSeconds) { return HasReturnvaluesIF::RETURN_FAILED; }; /** - * This function can be used by data pool consumers to retrieve a handle + * This function can be used by data pool consumers to retrieve a handle * which allows subscriptions to dataset and variable updates. * @return */ virtual ProvidesDataPoolSubscriptionIF* getSubscriptionInterface() = 0; - virtual AccessLocalPoolIF* getAccessorHandle() = 0; protected: - /** - * Can be used to get a handle to the local data pool manager. - * This function is protected because it should only be used by the - * class imlementing the interface. - */ - virtual LocalDataPoolManager* getHkManagerHandle() = 0; + virtual AccessPoolManagerIF* getAccessorHandle() = 0; /** * This function is used by the pool manager to get a valid dataset diff --git a/datapoollocal/HasLocalDataPoolIFAttorney.h b/datapoollocal/HasLocalDataPoolIFAttorney.h new file mode 100644 index 000000000..dd01e74ee --- /dev/null +++ b/datapoollocal/HasLocalDataPoolIFAttorney.h @@ -0,0 +1,38 @@ +#ifndef FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIFATTORNEY_H_ +#define FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIFATTORNEY_H_ + +#include + +class HasLocalDpIFUserAttorney { +private: + + static AccessPoolManagerIF* getAccessorHandle(HasLocalDataPoolIF* interface) { + return interface->getAccessorHandle(); + } + + friend class LocalPoolObjectBase; + friend class LocalPoolDataSetBase; + +}; + +class HasLocalDpIFManagerAttorney { + + static LocalPoolDataSetBase* getDataSetHandle(HasLocalDataPoolIF* interface, sid_t sid) { + return interface->getDataSetHandle(sid); + } + + static LocalPoolObjectBase* getPoolObjectHandle(HasLocalDataPoolIF* interface, + lp_id_t localPoolId) { + return interface->getPoolObjectHandle(localPoolId); + } + + static object_id_t getObjectId(HasLocalDataPoolIF* interface) { + return interface->getObjectId(); + } + + friend class LocalDataPoolManager; +}; + + + +#endif /* FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIFATTORNEY_H_ */ diff --git a/datapoollocal/LocalDataPoolManager.cpp b/datapoollocal/LocalDataPoolManager.cpp index 4aeb8677f..f471bea86 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/datapoollocal/LocalDataPoolManager.cpp @@ -1,6 +1,8 @@ #include "LocalDataPoolManager.h" #include "LocalPoolObjectBase.h" #include "LocalPoolDataSetBase.h" +#include "HasLocalDataPoolIFAttorney.h" +#include "LocalPoolDataSetAttorney.h" #include "../housekeeping/HousekeepingPacketUpdate.h" #include "../housekeeping/HousekeepingSetPacket.h" @@ -132,7 +134,7 @@ ReturnValue_t LocalDataPoolManager::handleHkUpdate(HkReceiver& receiver, // Update packets shall only be generated from datasets. return HasReturnvaluesIF::RETURN_FAILED; } - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, receiver.dataId.sid); if(dataSet->hasChanged()) { // prepare and send update notification @@ -151,7 +153,9 @@ ReturnValue_t LocalDataPoolManager::handleNotificationUpdate(HkReceiver& receive ReturnValue_t& status) { MarkChangedIF* toReset = nullptr; if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { - LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle(receiver.dataId.localPoolId); + LocalPoolObjectBase* poolObj = HasLocalDpIFManagerAttorney::getPoolObjectHandle(owner, + receiver.dataId.localPoolId); + //LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle(receiver.dataId.localPoolId); if(poolObj == nullptr) { printWarningOrError(fsfw::OutputTypes::OUT_WARNING, "handleNotificationUpdate", POOLOBJECT_NOT_FOUND); @@ -172,7 +176,8 @@ ReturnValue_t LocalDataPoolManager::handleNotificationUpdate(HkReceiver& receive } else { - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(receiver.dataId.sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, + receiver.dataId.sid); if(dataSet == nullptr) { printWarningOrError(fsfw::OutputTypes::OUT_WARNING, "handleNotificationUpdate", DATASET_NOT_FOUND); @@ -203,7 +208,7 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot( MarkChangedIF* toReset = nullptr; // check whether data has changed and send messages in case it has. if(receiver.dataType == DataType::LOCAL_POOL_VARIABLE) { - LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle( + LocalPoolObjectBase* poolObj = HasLocalDpIFManagerAttorney::getPoolObjectHandle(owner, receiver.dataId.localPoolId); if(poolObj == nullptr) { printWarningOrError(fsfw::OutputTypes::OUT_WARNING, @@ -221,7 +226,7 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot( CCSDSTime::CDS_short cds; CCSDSTime::convertToCcsds(&cds, &now); HousekeepingPacketUpdate updatePacket(reinterpret_cast(&cds), - sizeof(cds), owner->getPoolObjectHandle( + sizeof(cds), HasLocalDpIFManagerAttorney::getPoolObjectHandle(owner, receiver.dataId.localPoolId)); store_address_t storeId; @@ -241,7 +246,7 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot( toReset = poolObj; } else { - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, receiver.dataId.sid); if(dataSet == nullptr) { printWarningOrError(fsfw::OutputTypes::OUT_WARNING, @@ -259,7 +264,8 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot( CCSDSTime::CDS_short cds; CCSDSTime::convertToCcsds(&cds, &now); HousekeepingPacketUpdate updatePacket(reinterpret_cast(&cds), - sizeof(cds), owner->getDataSetHandle(receiver.dataId.sid)); + sizeof(cds), HasLocalDpIFManagerAttorney::getDataSetHandle(owner, + receiver.dataId.sid)); store_address_t storeId; ReturnValue_t result = addUpdateToStore(updatePacket, storeId); @@ -363,11 +369,12 @@ ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, hkReceiver.dataType = DataType::DATA_SET; hkReceiver.destinationQueue = hkReceiverObject->getHkQueue(); - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); + //LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); if(dataSet != nullptr) { - dataSet->setReportingEnabled(enableReporting); - dataSet->setDiagnostic(isDiagnostics); - dataSet->initializePeriodicHelper(collectionInterval, + LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, enableReporting); + LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics); + LocalPoolDataSetAttorney::initializePeriodicHelper(*dataSet, collectionInterval, owner->getPeriodicOperationFrequency(), isDiagnostics); } @@ -393,10 +400,11 @@ ReturnValue_t LocalDataPoolManager::subscribeForUpdatePackets(sid_t sid, hkReceiver.dataType = DataType::DATA_SET; hkReceiver.destinationQueue = hkReceiverObject->getHkQueue(); - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); + //LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); if(dataSet != nullptr) { - dataSet->setReportingEnabled(true); - dataSet->setDiagnostic(isDiagnostics); + LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, true); + LocalPoolDataSetAttorney::setDiagnostic(*dataSet, isDiagnostics); } hkReceiversMap.push_back(hkReceiver); @@ -410,7 +418,7 @@ ReturnValue_t LocalDataPoolManager::subscribeForSetUpdateMessages( MessageQueueId_t targetQueueId, bool generateSnapshot) { struct HkReceiver hkReceiver; hkReceiver.dataType = DataType::DATA_SET; - hkReceiver.dataId.sid = sid_t(this->getCreatorObjectId(), setId); + hkReceiver.dataId.sid = sid_t(owner->getObjectId(), setId); hkReceiver.destinationQueue = targetQueueId; hkReceiver.objectId = destinationObject; if(generateSnapshot) { @@ -534,13 +542,14 @@ ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage( case(HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT): case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT): { - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); + LocalPoolDataSetBase* dataSet =HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); + //LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); if(command == HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT - and dataSet->isDiagnostics()) { + and LocalPoolDataSetAttorney::isDiagnostics(*dataSet)) { return WRONG_HK_PACKET_TYPE; } else if(command == HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT - and not dataSet->isDiagnostics()) { + and not LocalPoolDataSetAttorney::isDiagnostics(*dataSet)) { return WRONG_HK_PACKET_TYPE; } return generateHousekeepingPacket(HousekeepingMessage::getSid(message), @@ -629,7 +638,7 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid, // and now we set a HK message and send it the HK packet destination. CommandMessage hkMessage; - if(dataSet->isDiagnostics()) { + if(LocalPoolDataSetAttorney::isDiagnostics(*dataSet)) { HousekeepingMessage::setHkDiagnosticsReply(&hkMessage, sid, storeId); } else { @@ -683,7 +692,8 @@ void LocalDataPoolManager::setNonDiagnosticIntervalFactor( void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver& receiver) { sid_t sid = receiver.dataId.sid; - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); + //LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); if(dataSet == nullptr) { printWarningOrError(fsfw::OutputTypes::OUT_WARNING, "performPeriodicHkGeneration", @@ -691,16 +701,19 @@ void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver& receiver) { return; } - if(not dataSet->getReportingEnabled()) { + if(not LocalPoolDataSetAttorney::getReportingEnabled(*dataSet)) { return; } - if(dataSet->periodicHelper == nullptr) { + PeriodicHousekeepingHelper* periodicHelper = + LocalPoolDataSetAttorney::getPeriodicHelper(*dataSet); + + if(periodicHelper == nullptr) { // Configuration error. return; } - if(not dataSet->periodicHelper->checkOpNecessary()) { + if(periodicHelper->checkOpNecessary()) { return; } @@ -721,43 +734,49 @@ void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver& receiver) { ReturnValue_t LocalDataPoolManager::togglePeriodicGeneration(sid_t sid, bool enable, bool isDiagnostics) { - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); - if((dataSet->isDiagnostics() and not isDiagnostics) or - (not dataSet->isDiagnostics() and isDiagnostics)) { + //LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); + if((LocalPoolDataSetAttorney::isDiagnostics(*dataSet) and not isDiagnostics) or + (not LocalPoolDataSetAttorney::isDiagnostics(*dataSet) and isDiagnostics)) { return WRONG_HK_PACKET_TYPE; } - if((dataSet->getReportingEnabled() and enable) or - (not dataSet->getReportingEnabled() and not enable)) { + if((LocalPoolDataSetAttorney::getReportingEnabled(*dataSet) and enable) or + (not LocalPoolDataSetAttorney::getReportingEnabled(*dataSet) and not enable)) { return REPORTING_STATUS_UNCHANGED; } - dataSet->setReportingEnabled(enable); + LocalPoolDataSetAttorney::setReportingEnabled(*dataSet, enable); return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t LocalDataPoolManager::changeCollectionInterval(sid_t sid, float newCollectionInterval, bool isDiagnostics) { - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); - bool targetIsDiagnostics = dataSet->isDiagnostics(); + //LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); + bool targetIsDiagnostics = LocalPoolDataSetAttorney::isDiagnostics(*dataSet); if((targetIsDiagnostics and not isDiagnostics) or (not targetIsDiagnostics and isDiagnostics)) { return WRONG_HK_PACKET_TYPE; } - if(dataSet->periodicHelper == nullptr) { + PeriodicHousekeepingHelper* periodicHelper = + LocalPoolDataSetAttorney::getPeriodicHelper(*dataSet); + + if(periodicHelper == nullptr) { // config error return PERIODIC_HELPER_INVALID; } - dataSet->periodicHelper->changeCollectionInterval(newCollectionInterval); + periodicHelper->changeCollectionInterval(newCollectionInterval); return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid, bool isDiagnostics) { // Get and check dataset first. - LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); + //LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(sid); + LocalPoolDataSetBase* dataSet = HasLocalDpIFManagerAttorney::getDataSetHandle(owner, sid); if(dataSet == nullptr) { printWarningOrError(fsfw::OutputTypes::OUT_WARNING, "performPeriodicHkGeneration", @@ -766,16 +785,16 @@ ReturnValue_t LocalDataPoolManager::generateSetStructurePacket(sid_t sid, } - bool targetIsDiagnostics = dataSet->isDiagnostics(); + bool targetIsDiagnostics = LocalPoolDataSetAttorney::isDiagnostics(*dataSet); if((targetIsDiagnostics and not isDiagnostics) or (not targetIsDiagnostics and isDiagnostics)) { return WRONG_HK_PACKET_TYPE; } bool valid = dataSet->isValid(); - bool reportingEnabled = dataSet->getReportingEnabled(); - float collectionInterval = - dataSet->periodicHelper->getCollectionIntervalInSeconds(); + bool reportingEnabled = LocalPoolDataSetAttorney::getReportingEnabled(*dataSet); + float collectionInterval = LocalPoolDataSetAttorney::getPeriodicHelper(*dataSet)-> + getCollectionIntervalInSeconds(); // Generate set packet which can be serialized. HousekeepingSetPacket setPacket(sid, @@ -822,16 +841,13 @@ void LocalDataPoolManager::clearReceiversList() { HkReceivers().swap(hkReceiversMap); } -ReturnValue_t LocalDataPoolManager::retrieveLocalPoolMutex(MutexIF *mutex) { - if(this->mutex == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; - } - mutex = this->mutex; - return HasReturnvaluesIF::RETURN_OK; +MutexIF* LocalDataPoolManager::getLocalPoolMutex() { + return this->mutex; } object_id_t LocalDataPoolManager::getCreatorObjectId() const { - return owner->getAccessorHandle()->getCreatorObjectId(); + return owner->getObjectId(); + //return owner->getObjectId(); } void LocalDataPoolManager::printWarningOrError(fsfw::OutputTypes outputType, @@ -869,7 +885,7 @@ void LocalDataPoolManager::printWarningOrError(fsfw::OutputTypes outputType, #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "LocalDataPoolManager::" << functionName << ": Object ID " << std::setw(8) << std::setfill('0') - << std::hex << this->getCreatorObjectId() << " | " << errorPrint + << std::hex << owner->getObjectId() << " | " << errorPrint << std::dec << std::setfill(' ') << std::endl; #else fsfw::printWarning("LocalDataPoolManager::%s: Object ID 0x%08x | %s\n", @@ -880,7 +896,7 @@ void LocalDataPoolManager::printWarningOrError(fsfw::OutputTypes outputType, #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "LocalDataPoolManager::" << functionName << ": Object ID " << std::setw(8) << std::setfill('0') - << std::hex << this->getCreatorObjectId() << " | " << errorPrint + << std::hex << owner->getObjectId() << " | " << errorPrint << std::dec << std::setfill(' ') << std::endl; #else fsfw::printError("LocalDataPoolManager::%s: Object ID 0x%08x | %s\n", @@ -888,3 +904,7 @@ void LocalDataPoolManager::printWarningOrError(fsfw::OutputTypes outputType, #endif } } + +LocalDataPoolManager* LocalDataPoolManager::getHkManagerHandle() { + return this; +} diff --git a/datapoollocal/LocalDataPoolManager.h b/datapoollocal/LocalDataPoolManager.h index 3544c9446..f94f0ec1b 100644 --- a/datapoollocal/LocalDataPoolManager.h +++ b/datapoollocal/LocalDataPoolManager.h @@ -51,11 +51,11 @@ class HousekeepingPacketUpdate; * @author R. Mueller */ class LocalDataPoolManager: public ProvidesDataPoolSubscriptionIF, - public AccessLocalPoolIF { - template friend class LocalPoolVariable; - template friend class LocalPoolVector; - //friend class LocalPoolDataSetBase; + public AccessPoolManagerIF { friend void (Factory::setStaticFrameworkObjectIds)(); + //! Some classes using the pool manager directly need to access class internals of the + //! manager. The attorney provides granular control of access to these internals. + friend class LocalDpManagerAttorney; public: static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER; @@ -177,7 +177,7 @@ public: MessageQueueId_t targetQueueId, bool generateSnapshot) override; - ReturnValue_t retrieveLocalPoolMutex(MutexIF* mutex) override; + MutexIF* getLocalPoolMutex() override; /** * Non-Diagnostics packets usually have a lower minimum sampling frequency @@ -263,7 +263,9 @@ public: */ void clearReceiversList(); - object_id_t getCreatorObjectId() const override; + object_id_t getCreatorObjectId() const; + + virtual LocalDataPoolManager* getHkManagerHandle() override; private: LocalDataPool localPoolMap; //! Every housekeeping data manager has a mutex to protect access diff --git a/datapoollocal/LocalDpManagerAttorney.h b/datapoollocal/LocalDpManagerAttorney.h new file mode 100644 index 000000000..1d72f607f --- /dev/null +++ b/datapoollocal/LocalDpManagerAttorney.h @@ -0,0 +1,32 @@ +#ifndef FSFW_DATAPOOLLOCAL_LOCALDPMANAGERATTORNEY_H_ +#define FSFW_DATAPOOLLOCAL_LOCALDPMANAGERATTORNEY_H_ + +#include + +/** + * @brief This is a helper class implements the Attorney-Client idiom for access to + * LocalDataPoolManager internals + * @details + * This helper class provides better control over which classes are allowed to access + * LocalDataPoolManager internals in a granular and encapsulated way when compared to + * other methods like direct friend declarations. It allows these classes to use + * an explicit subset of the pool manager private/protected functions. + * See: https://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Friendship_and_the_Attorney-Client + */ +class LocalDpManagerAttorney { +private: + template static ReturnValue_t fetchPoolEntry(LocalDataPoolManager& manager, + lp_id_t localPoolId, PoolEntry **poolEntry) { + return manager.fetchPoolEntry(localPoolId, poolEntry); + } + + static MutexIF* getMutexHandle(LocalDataPoolManager& manager) { + return manager.getMutexHandle(); + } + + + template friend class LocalPoolVariable; + template friend class LocalPoolVector; +}; + +#endif /* FSFW_DATAPOOLLOCAL_LOCALDPMANAGERATTORNEY_H_ */ diff --git a/datapoollocal/LocalPoolDataSetAttorney.h b/datapoollocal/LocalPoolDataSetAttorney.h new file mode 100644 index 000000000..36358db41 --- /dev/null +++ b/datapoollocal/LocalPoolDataSetAttorney.h @@ -0,0 +1,40 @@ +#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETATTORNEY_H_ +#define FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETATTORNEY_H_ + +#include + +class LocalPoolDataSetAttorney { +private: + static void setDiagnostic(LocalPoolDataSetBase& set, bool diagnostics) { + set.setDiagnostic(diagnostics); + } + + static bool isDiagnostics(LocalPoolDataSetBase& set) { + return set.isDiagnostics(); + } + + static void initializePeriodicHelper(LocalPoolDataSetBase& set, float collectionInterval, + uint32_t minimumPeriodicIntervalMs, + bool isDiagnostics, uint8_t nonDiagIntervalFactor = 5) { + set.initializePeriodicHelper(collectionInterval, minimumPeriodicIntervalMs, isDiagnostics, + nonDiagIntervalFactor); + } + + static void setReportingEnabled(LocalPoolDataSetBase& set, bool enabled) { + set.setReportingEnabled(enabled); + } + + static bool getReportingEnabled(LocalPoolDataSetBase& set) { + return set.getReportingEnabled(); + } + + static PeriodicHousekeepingHelper* getPeriodicHelper(LocalPoolDataSetBase& set) { + return set.periodicHelper; + } + + friend class LocalDataPoolManager; +}; + + + +#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETATTORNEY_H_ */ diff --git a/datapoollocal/LocalPoolDataSetBase.cpp b/datapoollocal/LocalPoolDataSetBase.cpp index c4bed0a41..9bed85830 100644 --- a/datapoollocal/LocalPoolDataSetBase.cpp +++ b/datapoollocal/LocalPoolDataSetBase.cpp @@ -1,4 +1,5 @@ #include "LocalPoolDataSetBase.h" +#include "HasLocalDataPoolIFAttorney.h" #include "../serviceinterface/ServiceInterface.h" #include "../datapoollocal/LocalDataPoolManager.h" @@ -23,14 +24,14 @@ LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner, #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ return; } - localPoolAccessor = hkOwner->getAccessorHandle(); + AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner); - if(localPoolAccessor != nullptr) { - localPoolAccessor->retrieveLocalPoolMutex(mutexIfSingleDataCreator); - //mutexIfSingleDataCreator = hkManager->getAc(); + if(poolManager != nullptr) { + poolManager = accessor->getHkManagerHandle(); + mutexIfSingleDataCreator = accessor->getLocalPoolMutex(); } - this->sid.objectId = localPoolAccessor->getCreatorObjectId(); + this->sid.objectId = hkOwner->getObjectId(); this->sid.ownerSetId = setId; // Data creators get a periodic helper for periodic HK data generation. @@ -43,10 +44,10 @@ LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray, const size_t maxNumberOfVariables): PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { - AccessLocalPoolIF* hkOwner = objectManager->get( + AccessPoolManagerIF* hkOwner = objectManager->get( sid.objectId); if(hkOwner != nullptr) { - ReturnValue_t result = hkOwner->retrieveLocalPoolMutex(mutexIfSingleDataCreator); + mutexIfSingleDataCreator = hkOwner->getLocalPoolMutex(); } //if(hkManager != nullptr) { @@ -310,8 +311,8 @@ void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) { } object_id_t LocalPoolDataSetBase::getCreatorObjectId() { - if(localPoolAccessor != nullptr) { - return localPoolAccessor->getCreatorObjectId(); + if(poolManager != nullptr) { + return poolManager->getCreatorObjectId(); } return objects::NO_OBJECT; } diff --git a/datapoollocal/LocalPoolDataSetBase.h b/datapoollocal/LocalPoolDataSetBase.h index 442d93c83..f815ac441 100644 --- a/datapoollocal/LocalPoolDataSetBase.h +++ b/datapoollocal/LocalPoolDataSetBase.h @@ -42,7 +42,8 @@ class PeriodicHousekeepingHelper; */ class LocalPoolDataSetBase: public PoolDataSetBase, public MarkChangedIF { - friend class LocalDataPoolManager; + //friend class LocalDataPoolManager; + friend class LocalPoolDataSetAttorney; friend class PeriodicHousekeepingHelper; public: /** @@ -217,7 +218,7 @@ protected: bool bitGetter(const uint8_t* byte, uint8_t position) const; PeriodicHousekeepingHelper* periodicHelper = nullptr; - AccessLocalPoolIF* localPoolAccessor = nullptr; + LocalDataPoolManager* poolManager = nullptr; }; diff --git a/datapoollocal/LocalPoolObjectBase.cpp b/datapoollocal/LocalPoolObjectBase.cpp index c74380cf6..e7abf9df8 100644 --- a/datapoollocal/LocalPoolObjectBase.cpp +++ b/datapoollocal/LocalPoolObjectBase.cpp @@ -1,4 +1,5 @@ #include "LocalPoolObjectBase.h" +#include "HasLocalDataPoolIFAttorney.h" LocalPoolObjectBase::LocalPoolObjectBase(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet, pool_rwm_t setReadWriteMode): @@ -16,7 +17,9 @@ LocalPoolObjectBase::LocalPoolObjectBase(lp_id_t poolId, HasLocalDataPoolIF* hkO #endif return; } - hkManager = hkOwner->getHkManagerHandle(); + AccessPoolManagerIF* poolManAccessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner); + hkManager = poolManAccessor->getHkManagerHandle(); + //HasLohkOwner->getHkManagerHandle(); if (dataSet != nullptr) { dataSet->registerVariable(this); } @@ -41,7 +44,10 @@ LocalPoolObjectBase::LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId, #endif return; } - hkManager = hkOwner->getHkManagerHandle(); + //hkManager = hkOwner->getHkManagerHandle(); + AccessPoolManagerIF* poolManAccessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner); + //hkManager = HasLocalDpIFUserAttorney::getHkManagerHandle(hkOwner); + hkManager = poolManAccessor->getHkManagerHandle(); if(dataSet != nullptr) { dataSet->registerVariable(this); } diff --git a/datapoollocal/LocalPoolVariable.h b/datapoollocal/LocalPoolVariable.h index eac915160..e66c565c8 100644 --- a/datapoollocal/LocalPoolVariable.h +++ b/datapoollocal/LocalPoolVariable.h @@ -1,11 +1,11 @@ #ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ #define FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_H_ +#include #include "LocalPoolObjectBase.h" #include "HasLocalDataPoolIF.h" #include "LocalDataPoolManager.h" #include "AccessLocalPoolF.h" - #include "../datapool/PoolVariableIF.h" #include "../datapool/DataSetIF.h" #include "../serviceinterface/ServiceInterface.h" diff --git a/datapoollocal/LocalPoolVariable.tpp b/datapoollocal/LocalPoolVariable.tpp index e55ea2a0f..6fd34171a 100644 --- a/datapoollocal/LocalPoolVariable.tpp +++ b/datapoollocal/LocalPoolVariable.tpp @@ -26,7 +26,7 @@ inline LocalPoolVariable::LocalPoolVariable(gp_id_t globalPoolId, template inline ReturnValue_t LocalPoolVariable::read( MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { - MutexHelper(hkManager->getMutexHandle(), timeoutType, timeoutMs); + MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs); return readWithoutLock(); } @@ -41,7 +41,9 @@ inline ReturnValue_t LocalPoolVariable::readWithoutLock() { } PoolEntry* poolEntry = nullptr; - ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); + ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId, + &poolEntry); + //ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); if(result != RETURN_OK) { object_id_t ownerObjectId = hkManager->getCreatorObjectId(); reportReadCommitError("LocalPoolVariable", result, @@ -73,7 +75,7 @@ inline ReturnValue_t LocalPoolVariable::commit(bool setValid, template inline ReturnValue_t LocalPoolVariable::commit( MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { - MutexHelper(hkManager->getMutexHandle(), timeoutType, timeoutMs); + MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs); return commitWithoutLock(); } @@ -88,7 +90,9 @@ inline ReturnValue_t LocalPoolVariable::commitWithoutLock() { } PoolEntry* poolEntry = nullptr; - ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); + //ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); + ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId, + &poolEntry); if(result != RETURN_OK) { object_id_t ownerObjectId = hkManager->getCreatorObjectId(); reportReadCommitError("LocalPoolVariable", result, diff --git a/datapoollocal/LocalPoolVector.h b/datapoollocal/LocalPoolVector.h index a28fe327a..3f26b9f51 100644 --- a/datapoollocal/LocalPoolVector.h +++ b/datapoollocal/LocalPoolVector.h @@ -1,6 +1,7 @@ #ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ #define FSFW_DATAPOOLLOCAL_LOCALPOOLVECTOR_H_ +#include #include "LocalPoolObjectBase.h" #include "../datapool/DataSetIF.h" #include "../datapool/PoolEntry.h" diff --git a/datapoollocal/LocalPoolVector.tpp b/datapoollocal/LocalPoolVector.tpp index 24421b0b6..6476b1e17 100644 --- a/datapoollocal/LocalPoolVector.tpp +++ b/datapoollocal/LocalPoolVector.tpp @@ -26,7 +26,7 @@ inline LocalPoolVector::LocalPoolVector(gp_id_t globalPoolId, template inline ReturnValue_t LocalPoolVector::read( MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { - MutexHelper(hkManager->getMutexHandle(), timeoutType, timeoutMs); + MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs); return readWithoutLock(); } template @@ -40,7 +40,8 @@ inline ReturnValue_t LocalPoolVector::readWithoutLock() { } PoolEntry* poolEntry = nullptr; - ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); + ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId, + &poolEntry); memset(this->value, 0, vectorSize * sizeof(T)); if(result != RETURN_OK) { @@ -64,7 +65,7 @@ inline ReturnValue_t LocalPoolVector::commit(bool valid, template inline ReturnValue_t LocalPoolVector::commit( MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { - MutexHelper(hkManager->getMutexHandle(), timeoutType, timeoutMs); + MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs); return commitWithoutLock(); } @@ -78,7 +79,8 @@ inline ReturnValue_t LocalPoolVector::commitWithoutLock() { return PoolVariableIF::INVALID_READ_WRITE_MODE; } PoolEntry* poolEntry = nullptr; - ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); + ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId, + &poolEntry); if(result != RETURN_OK) { object_id_t targetObjectId = hkManager->getCreatorObjectId(); reportReadCommitError("LocalPoolVector", result, false, targetObjectId, diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 2492535a4..ef0219e8c 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -1432,11 +1432,6 @@ ReturnValue_t DeviceHandlerBase::initializeLocalDataPool( return RETURN_OK; } -LocalDataPoolManager* DeviceHandlerBase::getHkManagerHandle() { - return &hkManager; -} - - ReturnValue_t DeviceHandlerBase::initializeAfterTaskCreation() { // In this function, the task handle should be valid if the task // was implemented correctly. We still check to be 1000 % sure :-) @@ -1488,7 +1483,7 @@ void DeviceHandlerBase::setNormalDatapoolEntriesInvalid() { } } -AccessLocalPoolIF* DeviceHandlerBase::getAccessorHandle() { +AccessPoolManagerIF* DeviceHandlerBase::getAccessorHandle() { return &hkManager; } diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index f3f208a60..7abc67058 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -519,11 +519,11 @@ protected: /** Get the HK manager object handle */ - LocalDataPoolManager* getHkManagerHandle() override; + //LocalDataPoolManager* getHkManagerHandle() override; ProvidesDataPoolSubscriptionIF* getSubscriptionInterface() override; - AccessLocalPoolIF* getAccessorHandle() override; + AccessPoolManagerIF* getAccessorHandle() override; /** * @brief Hook function for child handlers which is called once per diff --git a/devicehandlers/DeviceHandlerThermalSet.h b/devicehandlers/DeviceHandlerThermalSet.h index 0fabd3b30..239012e26 100644 --- a/devicehandlers/DeviceHandlerThermalSet.h +++ b/devicehandlers/DeviceHandlerThermalSet.h @@ -15,7 +15,7 @@ public: DeviceHandlerIF::DEFAULT_THERMAL_STATE_POOL_ID, lp_id_t heaterRequestId = DeviceHandlerIF::DEFAULT_THERMAL_HEATING_REQUEST_POOL_ID): - DeviceHandlerThermalSet(hkOwner->getAccessorHandle()->getCreatorObjectId(), setId, + DeviceHandlerThermalSet(hkOwner->getObjectId(), setId, thermalStateId, heaterRequestId) {} DeviceHandlerThermalSet(object_id_t deviceHandler, uint32_t setId = diff --git a/internalError/InternalErrorReporter.cpp b/internalError/InternalErrorReporter.cpp index 0817c0809..3a05b3509 100644 --- a/internalError/InternalErrorReporter.cpp +++ b/internalError/InternalErrorReporter.cpp @@ -134,7 +134,7 @@ uint32_t InternalErrorReporter::getStoreHits() { return value; } -AccessLocalPoolIF* InternalErrorReporter::getAccessorHandle() { +AccessPoolManagerIF* InternalErrorReporter::getAccessorHandle() { return &poolManager; } @@ -166,10 +166,6 @@ ReturnValue_t InternalErrorReporter::initializeLocalDataPool( return HasReturnvaluesIF::RETURN_OK; } -LocalDataPoolManager* InternalErrorReporter::getHkManagerHandle() { - return &poolManager; -} - dur_millis_t InternalErrorReporter::getPeriodicOperationFrequency() const { return this->executingTask->getPeriodMs(); } diff --git a/internalError/InternalErrorReporter.h b/internalError/InternalErrorReporter.h index 5bd5785a6..0cb6be593 100644 --- a/internalError/InternalErrorReporter.h +++ b/internalError/InternalErrorReporter.h @@ -43,11 +43,10 @@ public: virtual ReturnValue_t initializeLocalDataPool( LocalDataPool& localDataPoolMap, LocalDataPoolManager& poolManager) override; - virtual LocalDataPoolManager* getHkManagerHandle() override; virtual dur_millis_t getPeriodicOperationFrequency() const override; virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; ProvidesDataPoolSubscriptionIF* getSubscriptionInterface() override; - AccessLocalPoolIF* getAccessorHandle() override; + AccessPoolManagerIF* getAccessorHandle() override; virtual ReturnValue_t initialize() override; virtual ReturnValue_t initializeAfterTaskCreation() override;