continued with local data pool manager

This commit is contained in:
Robin Müller 2020-07-09 00:59:10 +02:00
parent 64c290ffe4
commit ac9e6e1337
11 changed files with 97 additions and 53 deletions

View File

@ -1,5 +1,5 @@
#ifndef DATASET_H_ #ifndef FRAMEWORK_DATAPOOLGLOB_DATASET_H_
#define DATASET_H_ #define FRAMEWORK_DATAPOOLGLOB_DATASET_H_
#include <framework/datapool/DataSetBase.h> #include <framework/datapool/DataSetBase.h>
@ -93,4 +93,4 @@ private:
PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE]; PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE];
}; };
#endif /* DATASET_H_ */ #endif /* FRAMEWORK_DATAPOOLGLOB_DATASET_H_ */

View File

@ -36,9 +36,9 @@ using LocalDataPoolMapIter = LocalDataPool::iterator;
* pragmatic solution I found was to offer the client the full interface * pragmatic solution I found was to offer the client the full interface
* of the LocalDataPoolManager. * of the LocalDataPoolManager.
*/ */
class OwnsLocalDataPoolIF { class HasLocalDataPoolIF {
public: public:
virtual~ OwnsLocalDataPoolIF() {}; virtual~ HasLocalDataPoolIF() {};
static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_POOL_OWNER_IF; static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_POOL_OWNER_IF;

View File

@ -7,7 +7,7 @@
#include <array> #include <array>
LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner, LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner,
MessageQueueIF* queueToUse, bool appendValidityBuffer): MessageQueueIF* queueToUse, bool appendValidityBuffer):
appendValidityBuffer(appendValidityBuffer) { appendValidityBuffer(appendValidityBuffer) {
if(owner == nullptr) { if(owner == nullptr) {
@ -63,7 +63,7 @@ LocalDataPoolManager::~LocalDataPoolManager() {}
ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() { ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
if(not mapInitialized) { if(not mapInitialized) {
ReturnValue_t result = owner->initializePoolEntries(localDpMap); ReturnValue_t result = owner->initializePoolEntries(localPoolMap);
if(result == HasReturnvaluesIF::RETURN_OK) { if(result == HasReturnvaluesIF::RETURN_OK) {
mapInitialized = true; mapInitialized = true;
} }
@ -96,8 +96,8 @@ ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
ReturnValue_t LocalDataPoolManager::printPoolEntry( ReturnValue_t LocalDataPoolManager::printPoolEntry(
lp_id_t localPoolId) { lp_id_t localPoolId) {
auto poolIter = localDpMap.find(localPoolId); auto poolIter = localPoolMap.find(localPoolId);
if (poolIter == localDpMap.end()) { if (poolIter == localPoolMap.end()) {
sif::debug << "HousekeepingManager::fechPoolEntry:" sif::debug << "HousekeepingManager::fechPoolEntry:"
" Pool entry not found." << std::endl; " Pool entry not found." << std::endl;
return POOL_ENTRY_NOT_FOUND; return POOL_ENTRY_NOT_FOUND;
@ -110,7 +110,7 @@ MutexIF* LocalDataPoolManager::getMutexHandle() {
return mutex; return mutex;
} }
const OwnsLocalDataPoolIF* LocalDataPoolManager::getOwner() const { const HasLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
return owner; return owner;
} }
@ -213,4 +213,6 @@ ReturnValue_t LocalDataPoolManager::serializeHkPacketIntoStore(
return result; return result;
} }
ReturnValue_t LocalDataPoolManager::performHkOperation() {
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -1,12 +1,13 @@
#ifndef FRAMEWORK_HK_HOUSEKEEPINGHELPER_H_ #ifndef FRAMEWORK_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_
#define FRAMEWORK_HK_HOUSEKEEPINGHELPER_H_ #define FRAMEWORK_DATAPOOLLOCAL_LOCALDATAPOOLMANAGER_H_
#include <framework/datapool/DataSetIF.h> #include <framework/datapool/DataSetIF.h>
#include <framework/objectmanager/SystemObjectIF.h> #include <framework/objectmanager/SystemObjectIF.h>
#include <framework/ipc/MutexIF.h> #include <framework/ipc/MutexIF.h>
#include <framework/housekeeping/HousekeepingMessage.h> #include <framework/housekeeping/HousekeepingMessage.h>
#include <framework/datapool/PoolEntry.h> #include <framework/datapool/PoolEntry.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h> #include <framework/datapoollocal/HasLocalDataPoolIF.h>
#include <framework/ipc/CommandMessage.h> #include <framework/ipc/CommandMessage.h>
#include <framework/ipc/MessageQueueIF.h> #include <framework/ipc/MessageQueueIF.h>
#include <framework/ipc/MutexHelper.h> #include <framework/ipc/MutexHelper.h>
@ -20,7 +21,7 @@ class LocalDataSet;
* @details * @details
* The actual data pool structure is a member of this class. Any class which * 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 * 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, * Users of the data pool use the helper classes LocalDataSet,
* LocalPoolVariable and LocalPoolVector to access pool entries in * LocalPoolVariable and LocalPoolVector to access pool entries in
@ -57,16 +58,24 @@ public:
* @param queueToUse * @param queueToUse
* @param appendValidityBuffer * @param appendValidityBuffer
*/ */
LocalDataPoolManager(OwnsLocalDataPoolIF* owner, MessageQueueIF* queueToUse, LocalDataPoolManager(HasLocalDataPoolIF* owner, MessageQueueIF* queueToUse,
bool appendValidityBuffer = true); bool appendValidityBuffer = true);
virtual~ LocalDataPoolManager();
/** /**
* Initializes the map by calling the map initialization function of the * 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 * @param queueToUse
* @return * @return
*/ */
ReturnValue_t initialize(MessageQueueIF* queueToUse, ReturnValue_t initialize(MessageQueueIF* queueToUse,
object_id_t hkDestination); 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 function is used to set the default HK packet destination.
* This destination will usually only be set once. * This destination will usually only be set once.
@ -74,8 +83,6 @@ public:
*/ */
void setHkPacketDestination(MessageQueueId_t hkDestination); void setHkPacketDestination(MessageQueueId_t hkDestination);
virtual~ LocalDataPoolManager();
/** /**
* Generate a housekeeping packet with a given SID. * Generate a housekeeping packet with a given SID.
* @param sid * @param sid
@ -95,28 +102,64 @@ public:
*/ */
ReturnValue_t initializeHousekeepingPoolEntriesOnce(); ReturnValue_t initializeHousekeepingPoolEntriesOnce();
const OwnsLocalDataPoolIF* getOwner() const; const HasLocalDataPoolIF* getOwner() const;
ReturnValue_t printPoolEntry(lp_id_t localPoolId); 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 */ /* Copying forbidden */
LocalDataPoolManager(const LocalDataPoolManager &) = delete; LocalDataPoolManager(const LocalDataPoolManager &) = delete;
LocalDataPoolManager operator=(const LocalDataPoolManager&) = delete; LocalDataPoolManager operator=(const LocalDataPoolManager&) = delete;
private: private:
/** This is the map holding the actual data. Should only be initialized LocalDataPool localPoolMap;
* once ! */ /** Every housekeeping data manager has a mutex to protect access
bool mapInitialized = false; * to it's data pool. */
/** This specifies whether a validity buffer is appended at the end MutexIF* mutex = nullptr;
* of generated housekeeping packets. */ /** The class which actually owns the manager (and its datapool). */
bool appendValidityBuffer = true; 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<object_id_t, struct HkReceiver>;
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. * @brief Queue used for communication, for example commands.
* Is also used to send messages. Can be set either in the constructor * Is also used to send messages. Can be set either in the constructor
@ -165,10 +208,10 @@ private:
template<class T> inline template<class T> inline
ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId, ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId,
PoolEntry<T> **poolEntry) { PoolEntry<T> **poolEntry) {
auto poolIter = localDpMap.find(localPoolId); auto poolIter = localPoolMap.find(localPoolId);
if (poolIter == localDpMap.end()) { if (poolIter == localPoolMap.end()) {
sif::debug << "HousekeepingManager::fechPoolEntry:" sif::warning << "HousekeepingManager::fechPoolEntry: Pool entry "
" Pool entry not found." << std::endl; "not found." << std::endl;
return POOL_ENTRY_NOT_FOUND; 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_ */

View File

@ -5,7 +5,7 @@
#include <cmath> #include <cmath>
#include <cstring> #include <cstring>
LocalDataSet::LocalDataSet(OwnsLocalDataPoolIF *hkOwner, LocalDataSet::LocalDataSet(HasLocalDataPoolIF *hkOwner,
const size_t maxNumberOfVariables): const size_t maxNumberOfVariables):
DataSetBase(poolVarList.data(), maxNumberOfVariables) { DataSetBase(poolVarList.data(), maxNumberOfVariables) {
poolVarList.reserve(maxNumberOfVariables); poolVarList.reserve(maxNumberOfVariables);
@ -23,7 +23,7 @@ LocalDataSet::LocalDataSet(object_id_t ownerId,
DataSetBase(poolVarList.data(), maxNumberOfVariables) { DataSetBase(poolVarList.data(), maxNumberOfVariables) {
poolVarList.reserve(maxNumberOfVariables); poolVarList.reserve(maxNumberOfVariables);
poolVarList.resize(maxNumberOfVariables); poolVarList.resize(maxNumberOfVariables);
OwnsLocalDataPoolIF* hkOwner = objectManager->get<OwnsLocalDataPoolIF>( HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
ownerId); ownerId);
if(hkOwner == nullptr) { if(hkOwner == nullptr) {
sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!" sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!"

View File

@ -2,7 +2,7 @@
#define FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_ #define FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_
#include <framework/datapool/DataSetBase.h> #include <framework/datapool/DataSetBase.h>
#include <framework/datapool/DataSetIF.h> #include <framework/datapool/DataSetIF.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h> #include <framework/datapoollocal/HasLocalDataPoolIF.h>
#include <framework/serialize/SerializeIF.h> #include <framework/serialize/SerializeIF.h>
#include <vector> #include <vector>
@ -37,7 +37,7 @@ public:
* The constructor simply sets the fill_count to zero and sets * The constructor simply sets the fill_count to zero and sets
* the state to "uninitialized". * the state to "uninitialized".
*/ */
LocalDataSet(OwnsLocalDataPoolIF *hkOwner, LocalDataSet(HasLocalDataPoolIF *hkOwner,
const size_t maxNumberOfVariables); const size_t maxNumberOfVariables);
/** /**

View File

@ -3,8 +3,8 @@
#include <framework/datapool/PoolVariableIF.h> #include <framework/datapool/PoolVariableIF.h>
#include <framework/datapool/DataSetIF.h> #include <framework/datapool/DataSetIF.h>
#include <framework/datapoollocal/HasLocalDataPoolIF.h>
#include <framework/datapoollocal/LocalDataPoolManager.h> #include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h>
#include <framework/objectmanager/ObjectManagerIF.h> #include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/serialize/SerializeAdapter.h> #include <framework/serialize/SerializeAdapter.h>
@ -42,7 +42,7 @@ public:
* @param dataSet The data set in which the variable shall register itself. * @param dataSet The data set in which the variable shall register itself.
* If nullptr, the variable is not registered. * 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, pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE,
DataSetIF* dataSet = nullptr); DataSetIF* dataSet = nullptr);

View File

@ -7,7 +7,7 @@
template<typename T> template<typename T>
inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId, inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId,
OwnsLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode, HasLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode,
DataSetIF* dataSet): DataSetIF* dataSet):
localPoolId(poolId),readWriteMode(setReadWriteMode) { localPoolId(poolId),readWriteMode(setReadWriteMode) {
if(poolId == PoolVariableIF::NO_PARAMETER) { if(poolId == PoolVariableIF::NO_PARAMETER) {
@ -33,8 +33,8 @@ inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId, object_id_t poolOwner,
sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the " sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the "
"NO_PARAMETER value!" << std::endl; "NO_PARAMETER value!" << std::endl;
} }
OwnsLocalDataPoolIF* hkOwner = HasLocalDataPoolIF* hkOwner =
objectManager->get<OwnsLocalDataPoolIF>(poolOwner); objectManager->get<HasLocalDataPoolIF>(poolOwner);
if(hkOwner == nullptr) { if(hkOwner == nullptr) {
sif::error << "LocalPoolVariable: The supplied pool owner did not implement" sif::error << "LocalPoolVariable: The supplied pool owner did not implement"
"the correct interface HasHkPoolParametersIF!" << std::endl; "the correct interface HasHkPoolParametersIF!" << std::endl;

View File

@ -46,7 +46,7 @@ public:
* @param dataSet The data set in which the variable shall register itself. * @param dataSet The data set in which the variable shall register itself.
* If nullptr, the variable is not registered. * 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, pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE,
DataSetIF* dataSet = nullptr); DataSetIF* dataSet = nullptr);

View File

@ -7,7 +7,7 @@
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline LocalPoolVector<T, vectorSize>::LocalPoolVector(lp_id_t poolId, inline LocalPoolVector<T, vectorSize>::LocalPoolVector(lp_id_t poolId,
OwnsLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode, HasLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode,
DataSetIF* dataSet) : DataSetIF* dataSet) :
localPoolId(poolId), valid(false), readWriteMode(setReadWriteMode) { localPoolId(poolId), valid(false), readWriteMode(setReadWriteMode) {
if(poolId == PoolVariableIF::NO_PARAMETER) { if(poolId == PoolVariableIF::NO_PARAMETER) {
@ -29,8 +29,8 @@ inline LocalPoolVector<T, vectorSize>::LocalPoolVector(lp_id_t poolId,
sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the " sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the "
"NO_PARAMETER value!" << std::endl; "NO_PARAMETER value!" << std::endl;
} }
OwnsLocalDataPoolIF* hkOwner = HasLocalDataPoolIF* hkOwner =
objectManager->get<OwnsLocalDataPoolIF>(poolOwner); objectManager->get<HasLocalDataPoolIF>(poolOwner);
if(hkOwner == nullptr) { if(hkOwner == nullptr) {
sif::error << "LocalPoolVariable: The supplied pool owner did not implement" sif::error << "LocalPoolVariable: The supplied pool owner did not implement"
"the correct interface HasHkPoolParametersIF!" << std::endl; "the correct interface HasHkPoolParametersIF!" << std::endl;

View File

@ -17,10 +17,9 @@
#include <framework/health/HealthHelper.h> #include <framework/health/HealthHelper.h>
#include <framework/parameters/ParameterHelper.h> #include <framework/parameters/ParameterHelper.h>
#include <framework/datapool/HkSwitchHelper.h> #include <framework/datapool/HkSwitchHelper.h>
#include <framework/datapoollocal/HasLocalDataPoolIF.h>
#include <framework/datapoollocal/LocalDataPoolManager.h> #include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/devicehandlers/DeviceHandlerFailureIsolation.h> #include <framework/devicehandlers/DeviceHandlerFailureIsolation.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h>
#include <map> #include <map>
namespace Factory{ namespace Factory{
@ -88,7 +87,7 @@ class DeviceHandlerBase: public DeviceHandlerIF,
public HasHealthIF, public HasHealthIF,
public HasActionsIF, public HasActionsIF,
public ReceivesParameterMessagesIF, public ReceivesParameterMessagesIF,
public OwnsLocalDataPoolIF { public HasLocalDataPoolIF {
friend void (Factory::setStaticFrameworkObjectIds)(); friend void (Factory::setStaticFrameworkObjectIds)();
public: public:
/** /**