2016-06-15 23:48:41 +02:00
|
|
|
#include <framework/devicehandlers/HealthDevice.h>
|
2018-07-12 16:29:32 +02:00
|
|
|
#include <framework/ipc/QueueFactory.h>
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
HealthDevice::HealthDevice(object_id_t setObjectId,
|
|
|
|
MessageQueueId_t parentQueue) :
|
|
|
|
SystemObject(setObjectId), lastHealth(HEALTHY), parentQueue(
|
2018-07-12 16:29:32 +02:00
|
|
|
parentQueue), commandQueue(), healthHelper(this, setObjectId) {
|
2020-06-13 17:37:48 +02:00
|
|
|
commandQueue = QueueFactory::instance()->createMessageQueue(3, CommandMessage::MINIMUM_COMMAND_MESSAGE_SIZE);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HealthDevice::~HealthDevice() {
|
2018-07-12 16:29:32 +02:00
|
|
|
QueueFactory::instance()->deleteMessageQueue(commandQueue);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t HealthDevice::performOperation(uint8_t opCode) {
|
2020-06-24 00:24:15 +02:00
|
|
|
CommandMessage command;
|
2020-06-09 02:18:39 +02:00
|
|
|
ReturnValue_t result = commandQueue->receiveMessage(&command);
|
2016-06-15 23:48:41 +02:00
|
|
|
if (result == HasReturnvaluesIF::RETURN_OK) {
|
2020-06-09 02:18:39 +02:00
|
|
|
healthHelper.handleHealthCommand(&command);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t HealthDevice::initialize() {
|
|
|
|
ReturnValue_t result = SystemObject::initialize();
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if (parentQueue != 0) {
|
|
|
|
return healthHelper.initialize(parentQueue);
|
|
|
|
} else {
|
|
|
|
return healthHelper.initialize();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MessageQueueId_t HealthDevice::getCommandQueue() const {
|
2018-07-12 16:29:32 +02:00
|
|
|
return commandQueue->getId();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void HealthDevice::setParentQueue(MessageQueueId_t parentQueue) {
|
2020-06-25 18:09:32 +02:00
|
|
|
healthHelper.setParentQueue(parentQueue);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HealthDevice::hasHealthChanged() {
|
|
|
|
bool changed;
|
|
|
|
HealthState currentHealth = healthHelper.getHealth();
|
|
|
|
changed = currentHealth != lastHealth;
|
|
|
|
lastHealth = currentHealth;
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t HealthDevice::setHealth(HealthState health) {
|
|
|
|
healthHelper.setHealth(health);
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HasHealthIF::HealthState HealthDevice::getHealth() {
|
|
|
|
return healthHelper.getHealth();
|
|
|
|
}
|