From 037bd83af9cd7f05680323e1ae856b73b31eb007 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 11 Jan 2021 21:31:03 +0100 Subject: [PATCH] trying new interface --- controller/ExtendedControllerBase.cpp | 5 ++ controller/ExtendedControllerBase.h | 2 + datapoollocal/AccessLocalDataPoolIF.h | 17 ++++ datapoollocal/HasLocalDataPoolIF.h | 81 +++++++++++-------- datapoollocal/LocalDataPoolManager.h | 2 +- datapoollocal/LocalPoolDataSetBase.cpp | 2 +- datapoollocal/LocalPoolDataSetBase.h | 8 +- datapoollocal/LocalPoolObjectBase.h | 2 +- .../ProvidesDataPoolSubscriptionIF.h | 7 +- devicehandlers/DeviceHandlerBase.cpp | 4 + devicehandlers/DeviceHandlerBase.h | 4 +- internalError/InternalErrorReporter.cpp | 5 ++ internalError/InternalErrorReporter.h | 1 + 13 files changed, 100 insertions(+), 40 deletions(-) create mode 100644 datapoollocal/AccessLocalDataPoolIF.h diff --git a/controller/ExtendedControllerBase.cpp b/controller/ExtendedControllerBase.cpp index 017acafe..101ac558 100644 --- a/controller/ExtendedControllerBase.cpp +++ b/controller/ExtendedControllerBase.cpp @@ -113,3 +113,8 @@ LocalPoolDataSetBase* ExtendedControllerBase::getDataSetHandle(sid_t sid) { #endif return nullptr; } + +ProvidesDataPoolSubscriptionIF* ExtendedControllerBase::getSubsciptionInterface( + ) { + return &localPoolManager; +} diff --git a/controller/ExtendedControllerBase.h b/controller/ExtendedControllerBase.h index 02c5728e..ec8d149d 100644 --- a/controller/ExtendedControllerBase.h +++ b/controller/ExtendedControllerBase.h @@ -32,6 +32,8 @@ public: virtual ReturnValue_t performOperation(uint8_t opCode) override; virtual ReturnValue_t initializeAfterTaskCreation() override; + ProvidesDataPoolSubscriptionIF* getSubsciptionInterface() override; + protected: LocalDataPoolManager localPoolManager; ActionHelper actionHelper; diff --git a/datapoollocal/AccessLocalDataPoolIF.h b/datapoollocal/AccessLocalDataPoolIF.h new file mode 100644 index 00000000..d204a088 --- /dev/null +++ b/datapoollocal/AccessLocalDataPoolIF.h @@ -0,0 +1,17 @@ +#ifndef FSFW_DATAPOOLLOCAL_ACCESSLOCALDATAPOOLIF_H_ +#define FSFW_DATAPOOLLOCAL_ACCESSLOCALDATAPOOLIF_H_ + +#include + + +class AccessLocalDataPoolIF { +public: + virtual ~AccessLocalDataPoolIF() {}; + +protected: + virtual LocalDataPoolManager* getHkManagerHandle() = 0; + +}; + + +#endif /* FSFW_DATAPOOLLOCAL_ACCESSLOCALDATAPOOLIF_H_ */ diff --git a/datapoollocal/HasLocalDataPoolIF.h b/datapoollocal/HasLocalDataPoolIF.h index 55b98c45..5b296d97 100644 --- a/datapoollocal/HasLocalDataPoolIF.h +++ b/datapoollocal/HasLocalDataPoolIF.h @@ -1,6 +1,7 @@ #ifndef FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_ #define FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_ +#include "ProvidesDataPoolSubscriptionIF.h" #include "locPoolDefinitions.h" #include "../datapool/PoolEntryIF.h" @@ -40,8 +41,9 @@ using LocalDataPoolMapIter = LocalDataPool::iterator; * of the LocalDataPoolManager. */ class HasLocalDataPoolIF { - friend class LocalPoolDataSetBase; - friend class LocalPoolObjectBase; + friend class LocalDataPoolManager; + //friend class LocalPoolDataSetBase; + //friend class LocalPoolObjectBase; public: virtual~ HasLocalDataPoolIF() {}; @@ -73,36 +75,10 @@ public: */ virtual uint32_t getPeriodicOperationFrequency() const = 0; - /** - * This function is used by the pool manager to get a valid dataset - * from a SID - * @param sid Corresponding structure ID - * @return - */ - virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) = 0; - - /** - * Similar to the function above, but used to get a local pool variable - * handle. This is only needed for update notifications, so it is not - * defined as abstract. - * @param localPoolId - * @return - */ - virtual LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "HasLocalDataPoolIF::getPoolObjectHandle: Not overriden" - << ". Returning nullptr!" << std::endl; -#else - fsfw::printWarning("HasLocalDataPoolIF::getPoolObjectHandle: " - "Not overriden. Returning nullptr!\n"); -#endif - return nullptr; - } - /** * @brief This function will be called by the manager if an update * notification is received. - * @details + * @details HasLocalDataPoolIF * Can be overriden by the child class to handle changed datasets. * @param sid * @param storeId If a snapshot was requested, data will be located inside @@ -127,8 +103,10 @@ public: return; } - /* These function can be implemented by pool owner, as they are required - * by the housekeeping message interface */ + /** + * These function can be implemented by pool owner, if they are required + * and used by the housekeeping message interface. + * */ virtual ReturnValue_t addDataSet(sid_t sid) { return HasReturnvaluesIF::RETURN_FAILED; }; @@ -140,11 +118,50 @@ public: return HasReturnvaluesIF::RETURN_FAILED; }; + /** + * This function can be used by data pool consumers to retrieve a handle + * which allows subscriptions to dataset and variable updates. + * @return + */ virtual ProvidesDataPoolSubscriptionIF* getSubsciptionInterface() = 0; protected: - /** Can be used to get a handle to the local data pool manager. */ + /** + * 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; + + /** + * This function is used by the pool manager to get a valid dataset + * from a SID. This function is protected to prevent users from + * using raw data set pointers which could not be thread-safe. Users + * should use the #ProvidesDataPoolSubscriptionIF. + * @param sid Corresponding structure ID + * @return + */ + virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) = 0; + + /** + * Similar to the function above, but used to get a local pool variable + * handle. This is only needed for update notifications, so it is not + * defined as abstract. This function is protected to prevent users from + * using raw pool variable pointers which could not be thread-safe. + * Users should use the #ProvidesDataPoolSubscriptionIF. + * @param localPoolId + * @return + */ + virtual LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "HasLocalDataPoolIF::getPoolObjectHandle: Not overriden" + << ". Returning nullptr!" << std::endl; +#else + fsfw::printWarning("HasLocalDataPoolIF::getPoolObjectHandle: " + "Not overriden. Returning nullptr!\n"); +#endif + return nullptr; + } }; #endif /* FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_ */ diff --git a/datapoollocal/LocalDataPoolManager.h b/datapoollocal/LocalDataPoolManager.h index d0a1181f..7a4e376c 100644 --- a/datapoollocal/LocalDataPoolManager.h +++ b/datapoollocal/LocalDataPoolManager.h @@ -1,7 +1,7 @@ #ifndef FSFW_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_ #define FSFW_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_ -#include +#include "ProvidesDataPoolSubscriptionIF.h" #include "HasLocalDataPoolIF.h" #include "../serviceinterface/ServiceInterface.h" diff --git a/datapoollocal/LocalPoolDataSetBase.cpp b/datapoollocal/LocalPoolDataSetBase.cpp index 8a39823e..9fc3f924 100644 --- a/datapoollocal/LocalPoolDataSetBase.cpp +++ b/datapoollocal/LocalPoolDataSetBase.cpp @@ -8,7 +8,7 @@ #include #include -LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner, +LocalPoolDataSetBase::LocalPoolDataSetBase(AccessLocalDataPoolIF *hkOwner, uint32_t setId, PoolVariableIF** registeredVariablesArray, const size_t maxNumberOfVariables, bool periodicHandling): PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { diff --git a/datapoollocal/LocalPoolDataSetBase.h b/datapoollocal/LocalPoolDataSetBase.h index 77a22f14..58b65880 100644 --- a/datapoollocal/LocalPoolDataSetBase.h +++ b/datapoollocal/LocalPoolDataSetBase.h @@ -3,6 +3,7 @@ #include "HasLocalDataPoolIF.h" #include "MarkChangedIF.h" +#include "AccessLocalDataPoolIF.h" #include "../datapool/DataSetIF.h" #include "../datapool/PoolDataSetBase.h" @@ -42,7 +43,8 @@ class PeriodicHousekeepingHelper; * @ingroup data_pool */ class LocalPoolDataSetBase: public PoolDataSetBase, - public MarkChangedIF { + public MarkChangedIF, + public AccessLocalDataPoolIF { friend class LocalDataPoolManager; friend class PeriodicHousekeepingHelper; public: @@ -52,7 +54,7 @@ public: * This constructor also initializes the components required for * periodic handling. */ - LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner, + LocalPoolDataSetBase(AccessLocalDataPoolIF *hkOwner, uint32_t setId, PoolVariableIF** registeredVariablesArray, const size_t maxNumberOfVariables, bool periodicHandling = true); @@ -218,7 +220,7 @@ protected: bool bitGetter(const uint8_t* byte, uint8_t position) const; PeriodicHousekeepingHelper* periodicHelper = nullptr; - LocalDataPoolManager* hkManager = nullptr; + AccessLocalDataPoolIF* hkManager = nullptr; }; diff --git a/datapoollocal/LocalPoolObjectBase.h b/datapoollocal/LocalPoolObjectBase.h index 25ca594d..e7414131 100644 --- a/datapoollocal/LocalPoolObjectBase.h +++ b/datapoollocal/LocalPoolObjectBase.h @@ -54,7 +54,7 @@ protected: ReadWriteMode_t readWriteMode = pool_rwm_t::VAR_READ_WRITE; //! @brief Pointer to the class which manages the HK pool. - LocalDataPoolManager* hkManager; + LocalDataPoolManager* hkManager = nullptr; void reportReadCommitError(const char* variableType, ReturnValue_t error, bool read, object_id_t objectId, lp_id_t lpId); diff --git a/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/datapoollocal/ProvidesDataPoolSubscriptionIF.h index 6f96d518..7f0cc754 100644 --- a/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -1,10 +1,13 @@ +#ifndef FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ +#define FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ + #include #include #include -class ProvidesDataPoolSubscriptionIF{ +class ProvidesDataPoolSubscriptionIF { public: virtual ~ProvidesDataPoolSubscriptionIF(){}; @@ -77,3 +80,5 @@ public: bool generateSnapshot) = 0; }; + +#endif /* FSFW_DATAPOOLLOCAL_PROVIDESDATAPOOLSUBSCRIPTION_H_ */ diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 4fa7b09c..de45c7d4 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -1532,3 +1532,7 @@ void DeviceHandlerBase::printWarningOrError(fsfw::OutputTypes errorType, } } + +ProvidesDataPoolSubscriptionIF* DeviceHandlerBase::getSubsciptionInterface() { + return &hkManager; +} diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 4c745b4f..556c23a2 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -518,7 +518,9 @@ protected: LocalDataPoolManager& poolManager) override; /** Get the HK manager object handle */ - virtual LocalDataPoolManager* getHkManagerHandle() override; + LocalDataPoolManager* getHkManagerHandle() override; + + ProvidesDataPoolSubscriptionIF* getSubsciptionInterface() override; /** * @brief Hook function for child handlers which is called once per diff --git a/internalError/InternalErrorReporter.cpp b/internalError/InternalErrorReporter.cpp index 6842da8e..16c6412b 100644 --- a/internalError/InternalErrorReporter.cpp +++ b/internalError/InternalErrorReporter.cpp @@ -195,3 +195,8 @@ void InternalErrorReporter::setMutexTimeout(MutexIF::TimeoutType timeoutType, this->timeoutType = timeoutType; this->timeoutMs = timeoutMs; } + +ProvidesDataPoolSubscriptionIF* InternalErrorReporter::getSubsciptionInterface( + ) { + return &poolManager; +} diff --git a/internalError/InternalErrorReporter.h b/internalError/InternalErrorReporter.h index c85057d6..1fcf733f 100644 --- a/internalError/InternalErrorReporter.h +++ b/internalError/InternalErrorReporter.h @@ -46,6 +46,7 @@ public: virtual LocalDataPoolManager* getHkManagerHandle() override; virtual dur_millis_t getPeriodicOperationFrequency() const override; virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) override; + ProvidesDataPoolSubscriptionIF* getSubsciptionInterface() override; virtual ReturnValue_t initialize() override; virtual ReturnValue_t initializeAfterTaskCreation() override;