improved documentation signigicantly

This commit is contained in:
Robin Müller 2020-06-07 02:22:18 +02:00
parent d0b218c18e
commit fe5b50d885
12 changed files with 118 additions and 87 deletions

View File

@ -1,12 +1,12 @@
#ifndef POOLVARIABLEIF_H_
#define POOLVARIABLEIF_H_
#ifndef FRAMEWORK_DATAPOOL_POOLVARIABLEIF_H_
#define FRAMEWORK_DATAPOOL_POOLVARIABLEIF_H_
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/serialize/SerializeIF.h>
/**
* @brief This interface is used to control data pool variable representations.
* @brief This interface is used to control data pool
* variable representations.
* @details
* To securely handle data pool variables, all pool entries are locally
* managed by data pool variable access classes, which are called pool
@ -39,7 +39,8 @@ public:
*/
virtual ~PoolVariableIF() {}
/**
* @brief This method returns if the variable is write-only, read-write or read-only.
* @brief This method returns if the variable is write-only,
* read-write or read-only.
*/
virtual ReadWriteMode_t getReadWriteMode() const = 0;
/**
@ -47,7 +48,8 @@ public:
*/
virtual uint32_t getDataPoolId() const = 0;
/**
* @brief With this call, the valid information of the variable is returned.
* @brief With this call, the valid information of the
* variable is returned.
*/
virtual bool isValid() const = 0;
/**

View File

@ -1,12 +1,12 @@
#include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/datapoollocal/LocalDataSet.h>
#include <framework/housekeeping/HousekeepingManager.h>
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <framework/ipc/MutexFactory.h>
#include <framework/ipc/MutexHelper.h>
#include <array>
HousekeepingManager::HousekeepingManager(HasHkPoolParametersIF* owner) {
LocalDataPoolManager::LocalDataPoolManager(OwnsLocalDataPoolIF* owner) {
if(owner == nullptr) {
sif::error << "HkManager: Invalid supplied owner!" << std::endl;
std::exit(0);
@ -16,11 +16,12 @@ HousekeepingManager::HousekeepingManager(HasHkPoolParametersIF* owner) {
//owner->setMinimalHkSamplingFrequency();
}
HousekeepingManager::~HousekeepingManager() {}
LocalDataPoolManager::~LocalDataPoolManager() {}
ReturnValue_t HousekeepingManager::initializeHousekeepingPoolEntriesOnce() {
ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() {
if(not mapInitialized) {
ReturnValue_t result = owner->initializeHousekeepingPoolEntries(localDpMap);
ReturnValue_t result =
owner->initializeHousekeepingPoolEntries(localDpMap);
if(result == HasReturnvaluesIF::RETURN_OK) {
mapInitialized = true;
}
@ -30,24 +31,24 @@ ReturnValue_t HousekeepingManager::initializeHousekeepingPoolEntriesOnce() {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t HousekeepingManager::handleHousekeepingMessage(
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(
CommandMessage *message) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t HousekeepingManager::printPoolEntry(
ReturnValue_t LocalDataPoolManager::printPoolEntry(
lp_id_t localPoolId) {
auto poolIter = localDpMap.find(localPoolId);
if (poolIter == localDpMap.end()) {
sif::debug << "HousekeepingManager::fechPoolEntry:"
" Pool entry not found." << std::endl;
return HasHkPoolParametersIF::POOL_ENTRY_NOT_FOUND;
return OwnsLocalDataPoolIF::POOL_ENTRY_NOT_FOUND;
}
poolIter->second->print();
return HasReturnvaluesIF::RETURN_OK;
}
MutexIF* HousekeepingManager::getMutexHandle() {
MutexIF* LocalDataPoolManager::getMutexHandle() {
return mutex;
}
@ -56,7 +57,7 @@ MutexIF* HousekeepingManager::getMutexHandle() {
//
//}
void HousekeepingManager::generateHousekeepingPacket(sid_t sid) {
void LocalDataPoolManager::generateHousekeepingPacket(sid_t sid) {
LocalDataSet* dataSetToSerialize = dynamic_cast<LocalDataSet*>(
owner->getDataSetHandle(sid));
if(dataSetToSerialize == nullptr) {
@ -73,10 +74,10 @@ void HousekeepingManager::generateHousekeepingPacket(sid_t sid) {
}
void HousekeepingManager::setHkPacketQueue(MessageQueueIF *msgQueue) {
void LocalDataPoolManager::setHkPacketQueue(MessageQueueIF *msgQueue) {
this->hkPacketQueue = msgQueue;
}
const HasHkPoolParametersIF* HousekeepingManager::getOwner() const {
const OwnsLocalDataPoolIF* LocalDataPoolManager::getOwner() const {
return owner;
}

View File

@ -2,19 +2,35 @@
#define FRAMEWORK_HK_HOUSEKEEPINGHELPER_H_
#include <framework/datapool/DataSetIF.h>
#include <framework/objectmanager/SystemObjectIF.h>
#include <framework/housekeeping/HasHkPoolParametersIF.h>
#include <framework/ipc/MutexIF.h>
#include <framework/housekeeping/HousekeepingMessage.h>
#include <framework/datapool/PoolEntry.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h>
#include <framework/ipc/CommandMessage.h>
#include <framework/ipc/MessageQueueIF.h>
#include <framework/ipc/MutexHelper.h>
#include <map>
class HousekeepingManager {
/**
* @brief This class is the managing instance for local data pool.
* @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.
*
* Users of the data pool use the helper classes LocalDataSet,
* LocalPoolVariable and LocalPoolVector to access pool entries in
* a thread-safe and efficient way.
*
* The local data pools employ a blackboard logic: Only the most recent
* value is stored. The helper classes offer a read() and commit() interface
* through the PoolVariableIF which is used to read and update values.
* Each pool entry has a valid state too.
*
*/
class LocalDataPoolManager {
template<typename T>
friend class LocalPoolVar;
template<typename T, uint16_t vecSize>
@ -23,8 +39,8 @@ class HousekeepingManager {
public:
static constexpr float MINIMAL_SAMPLING_FREQUENCY = 0.2;
HousekeepingManager(HasHkPoolParametersIF* owner);
virtual~ HousekeepingManager();
LocalDataPoolManager(OwnsLocalDataPoolIF* owner);
virtual~ LocalDataPoolManager();
// propably will just call respective local data set functions.
@ -40,7 +56,7 @@ public:
ReturnValue_t initializeHousekeepingPoolEntriesOnce();
void setHkPacketQueue(MessageQueueIF* msgQueue);
const HasHkPoolParametersIF* getOwner() const;
const OwnsLocalDataPoolIF* getOwner() const;
ReturnValue_t printPoolEntry(lp_id_t localPoolId);
@ -48,14 +64,14 @@ private:
//! This is the map holding the actual data. Should only be initialized
//! once !
bool mapInitialized = false;
LocalDataPoolMap localDpMap;
LocalDataPool localDpMap;
//! 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).
HasHkPoolParametersIF* owner = nullptr;
OwnsLocalDataPoolIF* owner = nullptr;
//! Used for replies.
//! (maybe we dont need this, the sender can be retrieved from command
@ -85,27 +101,28 @@ private:
* supplied pointer.
* @return
*/
template <class T>
ReturnValue_t fetchPoolEntry(lp_id_t localPoolId, PoolEntry<T> **poolEntry);
void setMinimalSamplingFrequency(float frequencySeconds);
template <class T> ReturnValue_t fetchPoolEntry(lp_id_t localPoolId,
PoolEntry<T> **poolEntry);
void setMinimalSamplingFrequency(float frequencySeconds);
};
template<class T> inline
ReturnValue_t HousekeepingManager::fetchPoolEntry(lp_id_t localPoolId,
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;
return HasHkPoolParametersIF::POOL_ENTRY_NOT_FOUND;
return OwnsLocalDataPoolIF::POOL_ENTRY_NOT_FOUND;
}
*poolEntry = dynamic_cast< PoolEntry<T>* >(poolIter->second);
if(*poolEntry == nullptr) {
sif::debug << "HousekeepingManager::fetchPoolEntry:"
" Pool entry not found." << std::endl;
return HasHkPoolParametersIF::POOL_ENTRY_TYPE_CONFLICT;
return OwnsLocalDataPoolIF::POOL_ENTRY_TYPE_CONFLICT;
}
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -1,7 +1,7 @@
#include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/datapoollocal/LocalDataSet.h>
#include <framework/housekeeping/HousekeepingManager.h>
LocalDataSet::LocalDataSet(HasHkPoolParametersIF *hkOwner): DataSetBase() {
LocalDataSet::LocalDataSet(OwnsLocalDataPoolIF *hkOwner): DataSetBase() {
if(hkOwner != nullptr) {
hkManager = hkOwner->getHkManagerHandle();
}
@ -11,7 +11,7 @@ LocalDataSet::LocalDataSet(HasHkPoolParametersIF *hkOwner): DataSetBase() {
}
LocalDataSet::LocalDataSet(object_id_t ownerId): DataSetBase() {
HasHkPoolParametersIF* hkOwner = objectManager->get<HasHkPoolParametersIF>(
OwnsLocalDataPoolIF* hkOwner = objectManager->get<OwnsLocalDataPoolIF>(
ownerId);
if(hkOwner == nullptr) {
// config error, error output here.

View File

@ -2,10 +2,10 @@
#define FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_
#include <framework/datapool/DataSetBase.h>
#include <framework/datapool/DataSetIF.h>
#include <framework/housekeeping/HasHkPoolParametersIF.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h>
#include <framework/serialize/SerializeIF.h>
class HousekeepingManager;
class LocalDataPoolManager;
/**
* @brief The LocalDataSet class manages a set of locally checked out variables
@ -35,7 +35,7 @@ public:
* The constructor simply sets the fill_count to zero and sets
* the state to "uninitialized".
*/
LocalDataSet(HasHkPoolParametersIF* hkOwner);
LocalDataSet(OwnsLocalDataPoolIF* hkOwner);
/**
* @brief Constructor for users of local pool data. The passed pool
@ -78,7 +78,7 @@ private:
*/
ReturnValue_t unlockDataPool() override;
HousekeepingManager* hkManager;
LocalDataPoolManager* hkManager;
};
#endif /* FRAMEWORK_DATAPOOLLOCAL_LOCALDATASET_H_ */

View File

@ -3,11 +3,11 @@
#include <framework/datapool/PoolVariableIF.h>
#include <framework/datapool/DataSetIF.h>
#include <framework/housekeeping/HasHkPoolParametersIF.h>
#include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h>
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/serialize/SerializeAdapter.h>
#include <framework/housekeeping/HousekeepingManager.h>
/**
* @brief Local Pool Variable class which is used to access the local pools.
@ -29,9 +29,12 @@ public:
/**
* This constructor is used by the data creators to have pool variable
* instances which can also be stored in datasets.
* It does not fetch the current value from the data pool. This is performed
* by the read() operation (which is not thread-safe).
* Datasets can be used to access local pool entires in a thread-safe way.
*
* It does not fetch the current value from the data pool, which
* has to be done by calling the read() operation.
* Datasets can be used to access multiple local pool entries in an
* efficient way. A pointer to a dataset can be passed to register
* the pool variable in that dataset directly.
* @param poolId ID of the local pool entry.
* @param hkOwner Pointer of the owner. This will generally be the calling
* class itself which passes "this".
@ -39,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, HasHkPoolParametersIF* hkOwner,
LocalPoolVar(lp_id_t poolId, OwnsLocalDataPoolIF* hkOwner,
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE,
DataSetIF* dataSet = nullptr);
@ -47,12 +50,14 @@ public:
* This constructor is used by data users like controllers to have
* access to the local pool variables of data creators by supplying
* the respective creator object ID.
* It does not fetch the current value from the data pool. This is performed
* by the read() operation (which is not thread-safe).
* Datasets can be used to access local pool entires in a thread-safe way.
*
* It does not fetch the current value from the data pool, which
* has to be done by calling the read() operation.
* Datasets can be used to access multiple local pool entries in an
* efficient way. A pointer to a dataset can be passed to register
* the pool variable in that dataset directly.
* @param poolId ID of the local pool entry.
* @param hkOwner Pointer of the owner. This will generally be the calling
* class itself which passes "this".
* @param hkOwner object ID of the pool owner.
* @param setReadWriteMode Specify the read-write mode of the pool variable.
* @param dataSet The data set in which the variable shall register itself.
* If nullptr, the variable is not registered.
@ -99,7 +104,7 @@ public:
* at once to avoid the overhead of unnecessary lock und unlock operations.
*
*/
ReturnValue_t read(uint32_t lockTimeout = MutexIF::BLOCKING) override;
ReturnValue_t read(dur_millis_t lockTimeout = MutexIF::BLOCKING) override;
/**
* @brief The commit call copies the array values back to the data pool.
* @details
@ -109,7 +114,8 @@ public:
* It is recommended to use DataSets to read and commit multiple variables
* at once to avoid the overhead of unnecessary lock und unlock operations.
*/
ReturnValue_t commit(uint32_t lockTimeout = MutexIF::BLOCKING) override;
ReturnValue_t commit(dur_millis_t lockTimeout = MutexIF::BLOCKING) override;
protected:
/**
* @brief Like #read, but without a lock protection of the global pool.
@ -144,7 +150,7 @@ private:
bool valid = false;
//! Pointer to the class which manages the HK pool.
HousekeepingManager* hkManager;
LocalDataPoolManager* hkManager;
};
#include <framework/datapoollocal/LocalPoolVariable.tpp>

View File

@ -7,7 +7,7 @@
template<typename T>
inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId,
HasHkPoolParametersIF* hkOwner, pool_rwm_t setReadWriteMode,
OwnsLocalDataPoolIF* 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;
}
HasHkPoolParametersIF* hkOwner =
objectManager->get<HasHkPoolParametersIF>(poolOwner);
OwnsLocalDataPoolIF* hkOwner =
objectManager->get<OwnsLocalDataPoolIF>(poolOwner);
if(hkOwner == nullptr) {
sif::error << "LocalPoolVariable: The supplied pool owner did not implement"
"the correct interface HasHkPoolParametersIF!" << std::endl;
@ -47,7 +47,7 @@ inline LocalPoolVar<T>::LocalPoolVar(lp_id_t poolId, object_id_t poolOwner,
}
template<typename T>
inline ReturnValue_t LocalPoolVar<T>::read(millis_t lockTimeout) {
inline ReturnValue_t LocalPoolVar<T>::read(dur_millis_t lockTimeout) {
MutexHelper(hkManager->getMutexHandle(), lockTimeout);
return readWithoutLock();
}
@ -75,7 +75,7 @@ inline ReturnValue_t LocalPoolVar<T>::readWithoutLock() {
}
template<typename T>
inline ReturnValue_t LocalPoolVar<T>::commit(millis_t lockTimeout) {
inline ReturnValue_t LocalPoolVar<T>::commit(dur_millis_t lockTimeout) {
MutexHelper(hkManager->getMutexHandle(), lockTimeout);
return commitWithoutLock();
}

View File

@ -4,8 +4,8 @@
#include <framework/datapool/DataSetIF.h>
#include <framework/datapool/PoolEntry.h>
#include <framework/datapool/PoolVariableIF.h>
#include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/serialize/SerializeAdapter.h>
#include <framework/housekeeping/HousekeepingManager.h>
#include <framework/serviceinterface/ServiceInterfaceStream.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, HasHkPoolParametersIF* hkOwner,
LocalPoolVector(lp_id_t poolId, OwnsLocalDataPoolIF* hkOwner,
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE,
DataSetIF* dataSet = nullptr);
@ -179,7 +179,7 @@ private:
*/
ReadWriteMode_t readWriteMode;
//! @brief Pointer to the class which manages the HK pool.
HousekeepingManager* hkManager;
LocalDataPoolManager* hkManager;
// std::ostream is the type for object std::cout
template <typename U, uint16_t otherSize>

View File

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

View File

@ -5,33 +5,40 @@
#include <framework/housekeeping/HousekeepingMessage.h>
#include <map>
class HousekeepingManager;
class LocalDataPoolManager;
class DataSetIF;
/**
* @brief Type definition for local pool entries.
*/
using lp_id_t = uint32_t;
using LocalDataPoolMap = std::map<lp_id_t, PoolEntryIF*>;
using LocalDataPoolMapIter = LocalDataPoolMap::iterator;
using LocalDataPool = std::map<lp_id_t, PoolEntryIF*>;
using LocalDataPoolMapIter = LocalDataPool::iterator;
/**
* @brief This interface is implemented by classes which posses a local
* data pool (not the managing class)
* 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 HousekeepingManager
* member class which handles the retrieval of the local pool data.
* 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.
* specifying an interface rather difficult. The local data pool can be
* accessed by using the LocalPoolVariable, LocalPoolVector or LocalDataSet
* classes.
*
* This could be circumvented by using a wrapper/accessor function, but
* 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 housekeeping manager.
* of the LocalDataPoolManager.
*/
class HasHkPoolParametersIF {
class OwnsLocalDataPoolIF {
public:
virtual~ HasHkPoolParametersIF() {};
virtual~ OwnsLocalDataPoolIF() {};
static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING;
static constexpr ReturnValue_t POOL_ENTRY_NOT_FOUND = MAKE_RETURN_CODE(0XA0);
@ -39,9 +46,9 @@ public:
virtual MessageQueueId_t getCommandQueue() const = 0;
virtual ReturnValue_t initializeHousekeepingPoolEntries(
LocalDataPoolMap& localDataPoolMap) = 0;
LocalDataPool& localDataPoolMap) = 0;
//virtual float setMinimalHkSamplingFrequency() = 0;
virtual HousekeepingManager* getHkManagerHandle() = 0;
virtual LocalDataPoolManager* getHkManagerHandle() = 0;
virtual DataSetIF* getDataSetHandle(sid_t sid) = 0;
};

View File

@ -1347,11 +1347,11 @@ void DeviceHandlerBase::performOperationHook() {
}
ReturnValue_t DeviceHandlerBase::initializeHousekeepingPoolEntries(
LocalDataPoolMap &localDataPoolMap) {
LocalDataPool &localDataPoolMap) {
return RETURN_OK;
}
HousekeepingManager* DeviceHandlerBase::getHkManagerHandle() {
LocalDataPoolManager* DeviceHandlerBase::getHkManagerHandle() {
return &hkManager;
}

View File

@ -11,15 +11,13 @@
#include <framework/modes/HasModesIF.h>
#include <framework/power/PowerSwitchIF.h>
#include <framework/ipc/MessageQueueIF.h>
#include <framework/housekeeping/HasHkPoolParametersIF.h>
#include <framework/action/ActionHelper.h>
#include <framework/health/HealthHelper.h>
#include <framework/parameters/ParameterHelper.h>
#include <framework/datapool/HkSwitchHelper.h>
#include <framework/datapoollocal/LocalDataPoolManager.h>
#include <framework/devicehandlers/DeviceHandlerFailureIsolation.h>
#include <framework/housekeeping/HousekeepingManager.h>
#include <framework/datapoollocal/OwnsLocalDataPoolIF.h>
#include <map>
namespace Factory{
@ -87,7 +85,7 @@ class DeviceHandlerBase: public DeviceHandlerIF,
public HasHealthIF,
public HasActionsIF,
public ReceivesParameterMessagesIF,
public HasHkPoolParametersIF {
public OwnsLocalDataPoolIF {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
/**
@ -480,10 +478,10 @@ protected:
* @return
*/
virtual ReturnValue_t initializeHousekeepingPoolEntries(
LocalDataPoolMap& localDataPoolMap) override;
LocalDataPool& localDataPoolMap) override;
/** Get the HK manager object handle */
virtual HousekeepingManager* getHkManagerHandle() override;
virtual LocalDataPoolManager* getHkManagerHandle() override;
/**
* @brief Hook function for child handlers which is called once per
@ -609,7 +607,7 @@ protected:
/** Action helper for HasActionsIF */
ActionHelper actionHelper;
/** Housekeeping Manager */
HousekeepingManager hkManager;
LocalDataPoolManager hkManager;
/**
* @brief Information about commands