fsfw/events/EventManagerIF.h

72 lines
2.6 KiB
C
Raw Permalink Normal View History

2021-01-19 14:37:52 +01:00
#ifndef FSFW_EVENTS_EVENTMANAGERIF_H_
#define FSFW_EVENTS_EVENTMANAGERIF_H_
2020-08-13 20:53:35 +02:00
#include "EventMessage.h"
2020-12-14 20:22:59 +01:00
#include "eventmatching/eventmatching.h"
2021-06-05 19:52:38 +02:00
#include "../objectmanager/ObjectManager.h"
2020-08-13 20:53:35 +02:00
#include "../ipc/MessageQueueSenderIF.h"
2020-12-14 20:22:59 +01:00
#include "../ipc/MessageQueueIF.h"
2021-01-19 14:37:52 +01:00
#include "../serviceinterface/ServiceInterface.h"
class EventManagerIF {
public:
static const uint8_t INTERFACE_ID = CLASS_ID::EVENT_MANAGER_IF;
static const ReturnValue_t LISTENER_NOT_FOUND = MAKE_RETURN_CODE(1);
virtual ~EventManagerIF() {
}
virtual MessageQueueId_t getEventReportQueue() = 0;
2020-12-14 20:22:59 +01:00
virtual ReturnValue_t registerListener(MessageQueueId_t listener,
bool forwardAllButSelected = false) = 0;
virtual ReturnValue_t subscribeToEvent(MessageQueueId_t listener,
EventId_t event) = 0;
virtual ReturnValue_t subscribeToAllEventsFrom(MessageQueueId_t listener,
object_id_t object) = 0;
virtual ReturnValue_t subscribeToEventRange(MessageQueueId_t listener,
EventId_t idFrom = 0, EventId_t idTo = 0, bool idInverted = false,
object_id_t reporterFrom = 0, object_id_t reporterTo = 0,
bool reporterInverted = false) = 0;
virtual ReturnValue_t unsubscribeFromEventRange(MessageQueueId_t listener,
EventId_t idFrom = 0, EventId_t idTo = 0, bool idInverted = false,
object_id_t reporterFrom = 0, object_id_t reporterTo = 0,
bool reporterInverted = false) = 0;
static void triggerEvent(object_id_t reportingObject, Event event,
2020-12-14 20:22:59 +01:00
uint32_t parameter1 = 0, uint32_t parameter2 = 0,
MessageQueueId_t sentFrom = 0) {
EventMessage message(event, reportingObject, parameter1, parameter2);
triggerEvent(&message, sentFrom);
}
2020-12-14 20:22:59 +01:00
static void triggerEvent(EventMessage* message,
MessageQueueId_t sentFrom = 0) {
if (eventmanagerQueue == MessageQueueIF::NO_QUEUE) {
2021-06-05 19:52:38 +02:00
EventManagerIF *eventmanager = ObjectManager::instance()->get<EventManagerIF>(
objects::EVENT_MANAGER);
2020-12-14 20:22:59 +01:00
if (eventmanager == nullptr) {
2021-01-19 14:37:52 +01:00
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "EventManagerIF::triggerEvent: EventManager invalid or not found!"
<< std::endl;
#else
sif::printWarning("EventManagerIF::triggerEvent: "
"EventManager invalid or not found!");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_VERBOSE_LEVEL >= 1 */
2020-12-14 20:22:59 +01:00
return;
}
2020-12-14 20:22:59 +01:00
eventmanagerQueue = eventmanager->getEventReportQueue();
}
MessageQueueSenderIF::sendMessage(eventmanagerQueue, message, sentFrom);
}
2021-01-19 14:37:52 +01:00
private:
//! Initialized by EventManager (C++11 does not allow header-only static member initialization).
static MessageQueueId_t eventmanagerQueue;
};
2021-01-19 14:37:52 +01:00
#endif /* FSFW_EVENTS_EVENTMANAGERIF_H_ */