Merge pull request 'health helper update' (#184) from KSat/fsfw:mueller/HealthHelperIdFix into master

Reviewed-on: fsfw/fsfw#184
This commit is contained in:
Steffen Gaisser 2020-09-15 15:45:56 +02:00
commit 42bfedd36c
2 changed files with 39 additions and 28 deletions

View File

@ -1,9 +1,8 @@
#include "HealthHelper.h"
#include "../ipc/MessageQueueSenderIF.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
HealthHelper::HealthHelper(HasHealthIF* owner, object_id_t objectId) :
healthTable(NULL), eventSender(NULL), objectId(objectId), parentQueue(
0), owner(owner) {
objectId(objectId), owner(owner) {
}
HealthHelper::~HealthHelper() {
@ -40,9 +39,19 @@ void HealthHelper::setParentQueue(MessageQueueId_t parentQueue) {
ReturnValue_t HealthHelper::initialize() {
healthTable = objectManager->get<HealthTableIF>(objects::HEALTH_TABLE);
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,
HasHealthIF::HEALTHY);
if (result != HasReturnvaluesIF::RETURN_OK) {
@ -62,22 +71,22 @@ void HealthHelper::setHealth(HasHealthIF::HealthState health) {
void HealthHelper::informParent(HasHealthIF::HealthState health,
HasHealthIF::HealthState oldHealth) {
if (parentQueue == 0) {
if (parentQueue == MessageQueueIF::NO_QUEUE) {
return;
}
CommandMessage message;
HealthMessage::setHealthMessage(&message, HealthMessage::HEALTH_INFO,
CommandMessage information;
HealthMessage::setHealthMessage(&information, HealthMessage::HEALTH_INFO,
health, oldHealth);
if (MessageQueueSenderIF::sendMessage(parentQueue, &message,
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
if (MessageQueueSenderIF::sendMessage(parentQueue, &information,
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
sif::debug << "HealthHelper::informParent: sending health reply failed."
<< std::endl;
}
}
void HealthHelper::handleSetHealthCommand(CommandMessage* message) {
ReturnValue_t result = owner->setHealth(HealthMessage::getHealth(message));
if (message->getSender() == 0) {
void HealthHelper::handleSetHealthCommand(CommandMessage* command) {
ReturnValue_t result = owner->setHealth(HealthMessage::getHealth(command));
if (command->getSender() == MessageQueueIF::NO_QUEUE) {
return;
}
CommandMessage reply;
@ -85,12 +94,12 @@ void HealthHelper::handleSetHealthCommand(CommandMessage* message) {
HealthMessage::setHealthMessage(&reply,
HealthMessage::REPLY_HEALTH_SET);
} else {
reply.setReplyRejected(result, message->getCommand());
reply.setReplyRejected(result, command->getCommand());
}
if (MessageQueueSenderIF::sendMessage(message->getSender(), &reply,
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
sif::debug
<< "HealthHelper::handleHealthCommand: sending health reply failed."
<< std::endl;
if (MessageQueueSenderIF::sendMessage(command->getSender(), &reply,
owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) {
sif::debug << "HealthHelper::handleHealthCommand: sending health "
"reply failed." << std::endl;
}
}

View File

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