health helper update

This commit is contained in:
Robin Müller 2020-09-04 15:19:33 +02:00
parent b3d08cd40b
commit 62eb327df6
2 changed files with 39 additions and 28 deletions

View File

@ -1,9 +1,8 @@
#include "HealthHelper.h" #include "HealthHelper.h"
#include "../ipc/MessageQueueSenderIF.h"
#include "../serviceinterface/ServiceInterfaceStream.h" #include "../serviceinterface/ServiceInterfaceStream.h"
HealthHelper::HealthHelper(HasHealthIF* owner, object_id_t objectId) : HealthHelper::HealthHelper(HasHealthIF* owner, object_id_t objectId) :
healthTable(NULL), eventSender(NULL), objectId(objectId), parentQueue( objectId(objectId), owner(owner) {
0), owner(owner) {
} }
HealthHelper::~HealthHelper() { HealthHelper::~HealthHelper() {
@ -40,9 +39,19 @@ void HealthHelper::setParentQueue(MessageQueueId_t parentQueue) {
ReturnValue_t HealthHelper::initialize() { ReturnValue_t HealthHelper::initialize() {
healthTable = objectManager->get<HealthTableIF>(objects::HEALTH_TABLE); healthTable = objectManager->get<HealthTableIF>(objects::HEALTH_TABLE);
eventSender = objectManager->get<EventReportingProxyIF>(objectId); eventSender = objectManager->get<EventReportingProxyIF>(objectId);
if ((healthTable == NULL) || eventSender == NULL) {
return HasReturnvaluesIF::RETURN_FAILED; if (healthTable == nullptr) {
sif::error << "HealthHelper::initialize: Health table object needs"
"to be created in factory." << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
} }
if(eventSender == nullptr) {
sif::error << "HealthHelper::initialize: Owner has to implement "
"ReportingProxyIF." << std::endl;
return ObjectManagerIF::CHILD_INIT_FAILED;
}
ReturnValue_t result = healthTable->registerObject(objectId, ReturnValue_t result = healthTable->registerObject(objectId,
HasHealthIF::HEALTHY); HasHealthIF::HEALTHY);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
@ -62,22 +71,22 @@ void HealthHelper::setHealth(HasHealthIF::HealthState health) {
void HealthHelper::informParent(HasHealthIF::HealthState health, void HealthHelper::informParent(HasHealthIF::HealthState health,
HasHealthIF::HealthState oldHealth) { HasHealthIF::HealthState oldHealth) {
if (parentQueue == 0) { if (parentQueue == MessageQueueMessageIF::NO_QUEUE) {
return; return;
} }
CommandMessage message; CommandMessage information;
HealthMessage::setHealthMessage(&message, HealthMessage::HEALTH_INFO, HealthMessage::setHealthMessage(&information, HealthMessage::HEALTH_INFO,
health, oldHealth); health, oldHealth);
if (MessageQueueSenderIF::sendMessage(parentQueue, &message, if (MessageQueueSenderIF::sendMessage(parentQueue, &information,
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) { owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
sif::debug << "HealthHelper::informParent: sending health reply failed." sif::debug << "HealthHelper::informParent: sending health reply failed."
<< std::endl; << std::endl;
} }
} }
void HealthHelper::handleSetHealthCommand(CommandMessage* message) { void HealthHelper::handleSetHealthCommand(CommandMessage* command) {
ReturnValue_t result = owner->setHealth(HealthMessage::getHealth(message)); ReturnValue_t result = owner->setHealth(HealthMessage::getHealth(command));
if (message->getSender() == 0) { if (command->getSender() == MessageQueueMessageIF::NO_QUEUE) {
return; return;
} }
CommandMessage reply; CommandMessage reply;
@ -85,12 +94,12 @@ void HealthHelper::handleSetHealthCommand(CommandMessage* message) {
HealthMessage::setHealthMessage(&reply, HealthMessage::setHealthMessage(&reply,
HealthMessage::REPLY_HEALTH_SET); HealthMessage::REPLY_HEALTH_SET);
} else { } else {
reply.setReplyRejected(result, message->getCommand()); reply.setReplyRejected(result, command->getCommand());
} }
if (MessageQueueSenderIF::sendMessage(message->getSender(), &reply, if (MessageQueueSenderIF::sendMessage(command->getSender(), &reply,
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) { owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
sif::debug sif::debug << "HealthHelper::handleHealthCommand: sending health "
<< "HealthHelper::handleHealthCommand: sending health reply failed." "reply failed." << std::endl;
<< std::endl;
} }
} }

View File

@ -1,11 +1,13 @@
#ifndef HEALTHHELPER_H_ #ifndef FSFW_HEALTH_HEALTHHELPER_H_
#define HEALTHHELPER_H_ #define FSFW_HEALTH_HEALTHHELPER_H_
#include "../events/EventManagerIF.h"
#include "../events/EventReportingProxyIF.h"
#include "HasHealthIF.h" #include "HasHealthIF.h"
#include "HealthMessage.h" #include "HealthMessage.h"
#include "HealthTableIF.h" #include "HealthTableIF.h"
#include "../events/EventManagerIF.h"
#include "../events/EventReportingProxyIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../objectmanager/ObjectManagerIF.h" #include "../objectmanager/ObjectManagerIF.h"
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
@ -27,8 +29,8 @@ public:
/** /**
* ctor * ctor
* *
* @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
* @param useAsFrom id to use as from id when sending replies, can be set to 0
*/ */
HealthHelper(HasHealthIF* owner, object_id_t objectId); HealthHelper(HasHealthIF* owner, object_id_t objectId);
@ -39,12 +41,12 @@ public:
* *
* only valid after initialize() has been called * only valid after initialize() has been called
*/ */
HealthTableIF *healthTable; HealthTableIF *healthTable = nullptr;
/** /**
* Proxy to forward events. * Proxy to forward events.
*/ */
EventReportingProxyIF* eventSender; EventReportingProxyIF* eventSender = nullptr;
/** /**
* Try to handle the message. * Try to handle the message.
@ -100,7 +102,7 @@ private:
/** /**
* The Queue of the parent * The Queue of the parent
*/ */
MessageQueueId_t parentQueue; MessageQueueId_t parentQueue = MessageQueueIF::NO_QUEUE;
/** /**
* The one using the healthHelper. * The one using the healthHelper.
@ -117,4 +119,4 @@ private:
void handleSetHealthCommand(CommandMessage *message); void handleSetHealthCommand(CommandMessage *message);
}; };
#endif /* HEALTHHELPER_H_ */ #endif /* FSFW_HEALTH_HEALTHHELPER_H_ */