health update

This commit is contained in:
Robin Müller 2020-10-10 17:49:50 +02:00
parent 837a18135e
commit bc0402faf7
3 changed files with 31 additions and 25 deletions

View File

@ -35,17 +35,14 @@ public:
virtual MessageQueueId_t getCommandQueue() const = 0; virtual MessageQueueId_t getCommandQueue() const = 0;
/** /**
* set the Health State * @brief Set the Health State
*
* The parent will be informed, if the Health changes * The parent will be informed, if the Health changes
*
* @param health * @param health
*/ */
virtual ReturnValue_t setHealth(HealthState health) = 0; virtual ReturnValue_t setHealth(HealthState health) = 0;
/** /**
* get Health State * @brief Get Health State
*
* @return Health State of the object * @return Health State of the object
*/ */
virtual HasHealthIF::HealthState getHealth() = 0; virtual HasHealthIF::HealthState getHealth() = 0;

View File

@ -12,13 +12,15 @@
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
/** /**
* Helper class for Objects that implement HasHealthIF * @brief Helper class for Objects that implement HasHealthIF
* @details
* It takes care of registering with the Health Table as well as handling
* health commands (including replying to the sender) and updating
* the Health Table.
* *
* It takes care of registering with the Health Table as well as handling health commands * If a parent is set in the ctor, the parent will be informed with a
* (including replying to the sender) and updating the Health Table. * @c HEALTH_INFO message about changes in the health state.
* * Note that a @c HEALTH_INFO is only generated if the Health
* If a parent is set in the ctor, the parent will be informed with a @c HEALTH_INFO message
* about changes in the health state. Note that a @c HEALTH_INFO is only generated if the Health
* changes, not for all @c HEALTH_SET commands received. * changes, not for all @c HEALTH_SET commands received.
* *
* It does NOT handle @c HEALTH_INFO messages * It does NOT handle @c HEALTH_INFO messages
@ -27,10 +29,9 @@ class HealthHelper {
public: public:
/** /**
* ctor
*
* @param owner * @param owner
* @param objectId the object Id to use when communication with the HealthTable * @param objectId The object Id to use when communication with
* the HealthTable
*/ */
HealthHelper(HasHealthIF* owner, object_id_t objectId); HealthHelper(HasHealthIF* owner, object_id_t objectId);
@ -57,7 +58,8 @@ public:
* @param message * @param message
* @return * @return
* -@c RETURN_OK if the message was handled * -@c RETURN_OK if the message was handled
* -@c RETURN_FAILED if the message could not be handled (ie it was not a @c HEALTH_SET or @c HEALTH_READ message) * -@c RETURN_FAILED if the message could not be handled
* (ie it was not a @c HEALTH_SET or @c HEALTH_READ message)
*/ */
ReturnValue_t handleHealthCommand(CommandMessage *message); ReturnValue_t handleHealthCommand(CommandMessage *message);
@ -78,15 +80,18 @@ public:
HasHealthIF::HealthState getHealth(); HasHealthIF::HealthState getHealth();
/** /**
* @param parentQueue the Queue id of the parent object. Set to 0 if no parent present * @param parentQueue The queue ID of the parent object.
* Set to 0 if no parent present
*/ */
void setParentQueue(MessageQueueId_t parentQueue); void setParentQueue(MessageQueueId_t parentQueue);
/** /**
* *
* @param parentQueue the Queue id of the parent object. Set to 0 if no parent present * @param parentQueue The queue ID of the parent object.
* Set to 0 if no parent present
* @return * @return
* -@c RETURN_OK if the Health Table was found and the object could be registered * -@c RETURN_OK if the Health Table was found and the object
* could be registered
* -@c RETURN_FAILED else * -@c RETURN_FAILED else
*/ */
ReturnValue_t initialize(MessageQueueId_t parentQueue ); ReturnValue_t initialize(MessageQueueId_t parentQueue );
@ -110,8 +115,11 @@ private:
HasHealthIF* owner; HasHealthIF* owner;
/** /**
* if the #parentQueue is not NULL, a @c HEALTH_INFO message will be sent to this queue * if the #parentQueue is not NULL, a @c HEALTH_INFO message
* @param health the health is passed as parameter so that the number of calls to the health table can be minimized * will be sent to this queue
* @param health
* The health is passed as parameter so that the number of
* calls to the health table can be minimized
* @param oldHealth information of the previous health state. * @param oldHealth information of the previous health state.
*/ */
void informParent(HasHealthIF::HealthState health, void informParent(HasHealthIF::HealthState health,

View File

@ -6,8 +6,6 @@
#include "../ipc/MutexIF.h" #include "../ipc/MutexIF.h"
#include <map> #include <map>
typedef std::map<object_id_t, HasHealthIF::HealthState> HealthMap;
using HealthEntry = std::pair<object_id_t, HasHealthIF::HealthState>;
class HealthTable: public HealthTableIF, public SystemObject { class HealthTable: public HealthTableIF, public SystemObject {
public: public:
@ -28,6 +26,9 @@ public:
virtual HasHealthIF::HealthState getHealth(object_id_t) override; virtual HasHealthIF::HealthState getHealth(object_id_t) override;
protected: protected:
using HealthMap = std::map<object_id_t, HasHealthIF::HealthState>;
using HealthEntry = std::pair<object_id_t, HasHealthIF::HealthState>;
MutexIF* mutex; MutexIF* mutex;
HealthMap healthMap; HealthMap healthMap;