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_
#define DATASET_H_
#ifndef FRAMEWORK_DATAPOOLGLOB_DATASET_H_
#define FRAMEWORK_DATAPOOLGLOB_DATASET_H_
#include <framework/datapool/DataSetBase.h>
@ -93,4 +93,4 @@ private:
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
* of the LocalDataPoolManager.
*/
class OwnsLocalDataPoolIF {
class HasLocalDataPoolIF {
public:
virtual~ OwnsLocalDataPoolIF() {};
virtual~ HasLocalDataPoolIF() {};
static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_POOL_OWNER_IF;

View File

@ -7,7 +7,7 @@
#include <array>
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;
}

View File

@ -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 <framework/datapool/DataSetIF.h>
#include <framework/objectmanager/SystemObjectIF.h>
#include <framework/ipc/MutexIF.h>
#include <framework/housekeeping/HousekeepingMessage.h>
#include <framework/datapool/PoolEntry.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h>
#include <framework/datapoollocal/HasLocalDataPoolIF.h>
#include <framework/ipc/CommandMessage.h>
#include <framework/ipc/MessageQueueIF.h>
#include <framework/ipc/MutexHelper.h>
@ -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<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.
* Is also used to send messages. Can be set either in the constructor
@ -165,10 +208,10 @@ private:
template<class T> inline
ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId,
PoolEntry<T> **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_ */

View File

@ -5,7 +5,7 @@
#include <cmath>
#include <cstring>
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<OwnsLocalDataPoolIF>(
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
ownerId);
if(hkOwner == nullptr) {
sif::error << "LocalDataSet::LocalDataSet: Owner can't be nullptr!"

View File

@ -2,7 +2,7 @@
#define FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_
#include <framework/datapool/DataSetBase.h>
#include <framework/datapool/DataSetIF.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h>
#include <framework/datapoollocal/HasLocalDataPoolIF.h>
#include <framework/serialize/SerializeIF.h>
#include <vector>
@ -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);
/**

View File

@ -3,8 +3,8 @@
#include <framework/datapool/PoolVariableIF.h>
#include <framework/datapool/DataSetIF.h>
#include <framework/datapoollocal/HasLocalDataPoolIF.h>
#include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h>
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/serialize/SerializeAdapter.h>
@ -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);

View File

@ -7,7 +7,7 @@
template<typename T>
inline LocalPoolVar<T>::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<T>::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<OwnsLocalDataPoolIF>(poolOwner);
HasLocalDataPoolIF* hkOwner =
objectManager->get<HasLocalDataPoolIF>(poolOwner);
if(hkOwner == nullptr) {
sif::error << "LocalPoolVariable: The supplied pool owner did not implement"
"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.
* 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);

View File

@ -7,7 +7,7 @@
template<typename T, uint16_t vectorSize>
inline LocalPoolVector<T, vectorSize>::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<T, vectorSize>::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<OwnsLocalDataPoolIF>(poolOwner);
HasLocalDataPoolIF* hkOwner =
objectManager->get<HasLocalDataPoolIF>(poolOwner);
if(hkOwner == nullptr) {
sif::error << "LocalPoolVariable: The supplied pool owner did not implement"
"the correct interface HasHkPoolParametersIF!" << std::endl;

View File

@ -17,10 +17,9 @@
#include <framework/health/HealthHelper.h>
#include <framework/parameters/ParameterHelper.h>
#include <framework/datapool/HkSwitchHelper.h>
#include <framework/datapoollocal/HasLocalDataPoolIF.h>
#include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/devicehandlers/DeviceHandlerFailureIsolation.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h>
#include <map>
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:
/**