health table init now mandatory, better

diagnostic output for uninit health table or invalid health helper owner
This commit is contained in:
Robin Müller 2020-07-16 12:38:21 +02:00
parent 47b3a428c6
commit aaafed7b28
3 changed files with 21 additions and 34 deletions

View File

@ -164,12 +164,8 @@ ReturnValue_t DeviceHandlerBase::initialize() {
}
result = healthHelper.initialize();
if (result == RETURN_OK) {
healthHelperActive = true;
}
else {
sif::warning << "DeviceHandlerBase::initialize: Health Helper "
"initialization failure." << std::endl;
if (result != RETURN_OK) {
return result;
}
result = modeHelper.initialize();
@ -246,11 +242,9 @@ void DeviceHandlerBase::readCommandQueue() {
return;
}
if(healthHelperActive) {
result = healthHelper.handleHealthCommand(&command);
if (result == RETURN_OK) {
return;
}
result = healthHelper.handleHealthCommand(&command);
if (result == RETURN_OK) {
return;
}
result = modeHelper.handleModeCommand(&command);
@ -1028,9 +1022,7 @@ void DeviceHandlerBase::getMode(Mode_t* mode, Submode_t* submode) {
}
void DeviceHandlerBase::setToExternalControl() {
if(healthHelperActive) {
healthHelper.setHealth(EXTERNAL_CONTROL);
}
healthHelper.setHealth(EXTERNAL_CONTROL);
}
void DeviceHandlerBase::announceMode(bool recursive) {
@ -1050,25 +1042,12 @@ void DeviceHandlerBase::missedReply(DeviceCommandId_t id) {
}
HasHealthIF::HealthState DeviceHandlerBase::getHealth() {
if(healthHelperActive) {
return healthHelper.getHealth();
}
else {
sif::warning << "DeviceHandlerBase::getHealth: Health helper not active"
<< std::endl;
return HasHealthIF::HEALTHY;
}
return healthHelper.getHealth();
}
ReturnValue_t DeviceHandlerBase::setHealth(HealthState health) {
if(healthHelperActive) {
healthHelper.setHealth(health);
}
else {
sif::warning << "DeviceHandlerBase::getHealth: Health helper not active"
<< std::endl;
}
return HasReturnvaluesIF::RETURN_OK;
healthHelper.setHealth(health);
return HasReturnvaluesIF::RETURN_OK;
}
void DeviceHandlerBase::checkSwitchState() {

View File

@ -609,7 +609,6 @@ protected:
/** Health helper for HasHealthIF */
HealthHelper healthHelper;
bool healthHelperActive = false;
/** Mode helper for HasModesIF */
ModeHelper modeHelper;
/** Parameter helper for ReceivesParameterMessagesIF */

View File

@ -39,10 +39,19 @@ void HealthHelper::setParentQeueue(MessageQueueId_t parentQueue) {
ReturnValue_t HealthHelper::initialize() {
healthTable = objectManager->get<HealthTableIF>(objects::HEALTH_TABLE);
eventSender = objectManager->get<EventReportingProxyIF>(objectId);
// TODO: Better returnvalues
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) {