2020-08-13 20:53:35 +02:00
|
|
|
#include "../events/EventManagerIF.h"
|
|
|
|
#include "FailureIsolationBase.h"
|
|
|
|
#include "../health/HasHealthIF.h"
|
|
|
|
#include "../health/HealthMessage.h"
|
|
|
|
#include "../ipc/QueueFactory.h"
|
|
|
|
#include "../objectmanager/ObjectManagerIF.h"
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2020-08-08 13:28:59 +02:00
|
|
|
FailureIsolationBase::FailureIsolationBase(object_id_t owner,
|
|
|
|
object_id_t parent, uint8_t messageDepth, uint8_t parameterDomainBase) :
|
|
|
|
ownerId(owner), faultTreeParent(parent),
|
|
|
|
parameterDomainBase(parameterDomainBase) {
|
|
|
|
eventQueue = QueueFactory::instance()->createMessageQueue(messageDepth,
|
|
|
|
EventMessage::EVENT_MESSAGE_SIZE);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
FailureIsolationBase::~FailureIsolationBase() {
|
|
|
|
QueueFactory::instance()->deleteMessageQueue(eventQueue);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t FailureIsolationBase::initialize() {
|
2016-06-15 23:48:41 +02:00
|
|
|
EventManagerIF* manager = objectManager->get<EventManagerIF>(
|
|
|
|
objects::EVENT_MANAGER);
|
2020-08-08 13:28:59 +02:00
|
|
|
if (manager == nullptr) {
|
|
|
|
sif::error << "FailureIsolationBase::initialize: Event Manager has not"
|
|
|
|
" been initialized!" << std::endl;
|
2016-06-15 23:48:41 +02:00
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t result = manager->registerListener(eventQueue->getId());
|
2016-06-15 23:48:41 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-08-08 13:28:59 +02:00
|
|
|
if (ownerId != objects::NO_OBJECT) {
|
2018-07-12 16:29:32 +02:00
|
|
|
result = manager->subscribeToAllEventsFrom(eventQueue->getId(), ownerId);
|
2016-06-15 23:48:41 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
owner = objectManager->get<HasHealthIF>(ownerId);
|
2020-08-08 13:28:59 +02:00
|
|
|
if (owner == nullptr) {
|
|
|
|
sif::error << "FailureIsolationBase::intialize: Owner object "
|
|
|
|
"invalid. Make sure it implements HasHealthIF" << std::endl;
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
}
|
2020-08-08 13:28:59 +02:00
|
|
|
if (faultTreeParent != objects::NO_OBJECT) {
|
2016-06-15 23:48:41 +02:00
|
|
|
ConfirmsFailuresIF* parentIF = objectManager->get<ConfirmsFailuresIF>(
|
|
|
|
faultTreeParent);
|
2020-08-08 13:28:59 +02:00
|
|
|
if (parentIF == nullptr) {
|
|
|
|
sif::error << "FailureIsolationBase::intialize: Parent object"
|
|
|
|
<< "invalid." << std::endl;
|
|
|
|
sif::error << "Make sure it implements ConfirmsFailuresIF."
|
|
|
|
<< std::endl;
|
|
|
|
return ObjectManagerIF::CHILD_INIT_FAILED;
|
2016-06-15 23:48:41 +02:00
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
eventQueue->setDefaultDestination(parentIF->getEventReceptionQueue());
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
return RETURN_OK;
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
void FailureIsolationBase::checkForFailures() {
|
2016-06-15 23:48:41 +02:00
|
|
|
EventMessage event;
|
2018-07-12 16:29:32 +02:00
|
|
|
for (ReturnValue_t result = eventQueue->receiveMessage(&event);
|
|
|
|
result == RETURN_OK; result = eventQueue->receiveMessage(&event)) {
|
|
|
|
if (event.getSender() == eventQueue->getId()) {
|
2016-06-15 23:48:41 +02:00
|
|
|
//We already got this event, because we sent it.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (event.getMessageId()) {
|
|
|
|
case EventMessage::EVENT_MESSAGE:
|
|
|
|
if (isFdirDisabledForSeverity(event.getSeverity())) {
|
|
|
|
//We do not handle events when disabled.
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
eventReceived(&event);
|
|
|
|
break;
|
|
|
|
case EventMessage::CONFIRMATION_REQUEST:
|
|
|
|
doConfirmFault(&event);
|
|
|
|
break;
|
|
|
|
case EventMessage::YOUR_FAULT:
|
|
|
|
eventConfirmed(&event);
|
|
|
|
break;
|
|
|
|
case EventMessage::MY_FAULT:
|
|
|
|
wasParentsFault(&event);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
decrementFaultCounters();
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
void FailureIsolationBase::setOwnerHealth(HasHealthIF::HealthState health) {
|
2016-06-15 23:48:41 +02:00
|
|
|
if (owner != NULL) {
|
|
|
|
owner->setHealth(health);
|
|
|
|
}
|
|
|
|
//else: owner has no health.
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
MessageQueueId_t FailureIsolationBase::getEventReceptionQueue() {
|
|
|
|
return eventQueue->getId();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t FailureIsolationBase::sendConfirmationRequest(EventMessage* event,
|
2016-06-15 23:48:41 +02:00
|
|
|
MessageQueueId_t destination) {
|
|
|
|
event->setMessageId(EventMessage::CONFIRMATION_REQUEST);
|
2020-08-08 13:28:59 +02:00
|
|
|
if (destination != MessageQueueIF::NO_QUEUE) {
|
2018-07-12 16:29:32 +02:00
|
|
|
return eventQueue->sendMessage(destination, event);
|
2020-08-08 13:28:59 +02:00
|
|
|
} else if (faultTreeParent != objects::NO_OBJECT) {
|
2018-07-12 16:29:32 +02:00
|
|
|
return eventQueue->sendToDefault(event);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
void FailureIsolationBase::eventConfirmed(EventMessage* event) {
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
void FailureIsolationBase::wasParentsFault(EventMessage* event) {
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
void FailureIsolationBase::doConfirmFault(EventMessage* event) {
|
2016-06-15 23:48:41 +02:00
|
|
|
ReturnValue_t result = confirmFault(event);
|
|
|
|
if (result == YOUR_FAULT) {
|
|
|
|
event->setMessageId(EventMessage::YOUR_FAULT);
|
2018-07-12 16:29:32 +02:00
|
|
|
eventQueue->reply(event);
|
2016-06-15 23:48:41 +02:00
|
|
|
} else if (result == MY_FAULT) {
|
|
|
|
event->setMessageId(EventMessage::MY_FAULT);
|
2018-07-12 16:29:32 +02:00
|
|
|
eventQueue->reply(event);
|
2016-06-15 23:48:41 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t FailureIsolationBase::confirmFault(EventMessage* event) {
|
2016-06-15 23:48:41 +02:00
|
|
|
return YOUR_FAULT;
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
void FailureIsolationBase::triggerEvent(Event event, uint32_t parameter1,
|
2016-06-15 23:48:41 +02:00
|
|
|
uint32_t parameter2) {
|
|
|
|
//With this mechanism, all events are disabled for a certain device.
|
|
|
|
//That's not so good for visibility.
|
|
|
|
if (isFdirDisabledForSeverity(EVENT::getSeverity(event))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
EventMessage message(event, ownerId, parameter1, parameter2);
|
2018-07-12 16:29:32 +02:00
|
|
|
EventManagerIF::triggerEvent(&message, eventQueue->getId());
|
2016-06-15 23:48:41 +02:00
|
|
|
eventReceived(&message);
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
bool FailureIsolationBase::isFdirDisabledForSeverity(EventSeverity_t severity) {
|
2016-06-15 23:48:41 +02:00
|
|
|
if ((owner != NULL) && (severity != SEVERITY::INFO)) {
|
|
|
|
if (owner->getHealth() == HasHealthIF::EXTERNAL_CONTROL) {
|
|
|
|
//External control disables handling of fault messages.
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
void FailureIsolationBase::throwFdirEvent(Event event, uint32_t parameter1,
|
2016-06-15 23:48:41 +02:00
|
|
|
uint32_t parameter2) {
|
|
|
|
EventMessage message(event, ownerId, parameter1, parameter2);
|
2018-07-12 16:29:32 +02:00
|
|
|
EventManagerIF::triggerEvent(&message, eventQueue->getId());
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|