Today's the day. Renamed platform to framework.
This commit is contained in:
24
events/Event.cpp
Normal file
24
events/Event.cpp
Normal file
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Event.cpp
|
||||
*
|
||||
* Created on: 25.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
#include <framework/events/Event.h>
|
||||
namespace EVENT {
|
||||
EventId_t getEventId(Event event) {
|
||||
return (event & 0xFFFF);
|
||||
}
|
||||
|
||||
EventSeverity_t getSeverity(Event event) {
|
||||
return ((event >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
Event makeEvent(EventId_t eventId, EventSeverity_t eventSeverity) {
|
||||
return (eventSeverity << 16) + (eventId & 0xFFFF);
|
||||
}
|
||||
}
|
49
events/Event.h
Normal file
49
events/Event.h
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Event.h
|
||||
*
|
||||
* Created on: 18.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef EVENTOBJECT_EVENT_H_
|
||||
#define EVENTOBJECT_EVENT_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <config/tmtc/subsystemIdRanges.h>
|
||||
|
||||
typedef uint16_t EventId_t;
|
||||
typedef uint8_t EventSeverity_t;
|
||||
|
||||
#define MAKE_EVENT(id, severity) (((severity)<<16)+(SUBSYSTEM_ID*100)+(id))
|
||||
|
||||
typedef uint32_t Event;
|
||||
|
||||
namespace EVENT {
|
||||
EventId_t getEventId(Event event);
|
||||
|
||||
EventSeverity_t getSeverity(Event event);
|
||||
|
||||
Event makeEvent(EventId_t eventId, EventSeverity_t eventSeverity);
|
||||
|
||||
}
|
||||
namespace SEVERITY {
|
||||
static const EventSeverity_t INFO = 1;
|
||||
static const EventSeverity_t LOW = 2;
|
||||
static const EventSeverity_t MEDIUM = 3;
|
||||
static const EventSeverity_t HIGH = 4;
|
||||
}
|
||||
|
||||
//Unfortunately, this does not work nicely because of the inability to define static classes in headers.
|
||||
//struct Event {
|
||||
// Event(uint8_t domain, uint8_t counter, EventSeverity_t severity) :
|
||||
// id(domain*100+counter), severity(severity) {
|
||||
// }
|
||||
// EventId_t id;
|
||||
// EventSeverity_t severity;
|
||||
// static const EventSeverity_t INFO = 1;
|
||||
// static const EventSeverity_t LOW = 2;
|
||||
// static const EventSeverity_t MEDIUM = 3;
|
||||
// static const EventSeverity_t HIGH = 4;
|
||||
//};
|
||||
|
||||
#endif /* EVENTOBJECT_EVENT_H_ */
|
145
events/EventManager.cpp
Normal file
145
events/EventManager.cpp
Normal file
@ -0,0 +1,145 @@
|
||||
#include <config/objects/translateObjects.h>
|
||||
#include <config/events/translateEvents.h>
|
||||
|
||||
#include <framework/events/EventManager.h>
|
||||
#include <framework/events/EventMessage.h>
|
||||
#include <framework/serviceinterface/ServiceInterfaceStream.h>
|
||||
|
||||
const uint16_t EventManager::POOL_SIZES[N_POOLS] = {
|
||||
sizeof(EventMatchTree::Node), sizeof(EventIdRangeMatcher),
|
||||
sizeof(ReporterRangeMatcher) };
|
||||
//TODO: Rather arbitrary. Adjust!
|
||||
const uint16_t EventManager::N_ELEMENTS[N_POOLS] = { 240, 120, 120 };
|
||||
|
||||
EventManager::EventManager(object_id_t setObjectId) :
|
||||
SystemObject(setObjectId), eventReportQueue(MAX_EVENTS_PER_CYCLE,
|
||||
EventMessage::EVENT_MESSAGE_SIZE), mutex(NULL), factoryBackend(
|
||||
0, POOL_SIZES, N_ELEMENTS, false, true) {
|
||||
mutex = new MutexId_t;
|
||||
OSAL::createMutex(setObjectId + 1, (mutex));
|
||||
}
|
||||
|
||||
EventManager::~EventManager() {
|
||||
OSAL::deleteMutex(mutex);
|
||||
delete mutex;
|
||||
}
|
||||
|
||||
MessageQueueId_t EventManager::getEventReportQueue() {
|
||||
return eventReportQueue.getId();
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::performOperation() {
|
||||
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
|
||||
while (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
EventMessage message;
|
||||
result = eventReportQueue.receiveMessage(&message);
|
||||
if (result == HasReturnvaluesIF::RETURN_OK) {
|
||||
printEvent(&message);
|
||||
notifyListeners(&message);
|
||||
}
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
void EventManager::notifyListeners(EventMessage* message) {
|
||||
lockMutex();
|
||||
for (auto iter = listenerList.begin(); iter != listenerList.end(); ++iter) {
|
||||
if (iter->second.match(message)) {
|
||||
eventForwardingSender.sendMessage(iter->first, message,
|
||||
message->getSender());
|
||||
}
|
||||
}
|
||||
unlockMutex();
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::registerListener(MessageQueueId_t listener,
|
||||
bool forwardAllButSelected) {
|
||||
auto result = listenerList.insert(
|
||||
std::pair<MessageQueueId_t, EventMatchTree>(listener,
|
||||
EventMatchTree(&factoryBackend, forwardAllButSelected)));
|
||||
if (!result.second) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::subscribeToEvent(MessageQueueId_t listener,
|
||||
EventId_t event) {
|
||||
return subscribeToEventRange(listener, event);
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::subscribeToAllEventsFrom(MessageQueueId_t listener,
|
||||
object_id_t object) {
|
||||
return subscribeToEventRange(listener, 0, 0, true, object);
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::subscribeToEventRange(MessageQueueId_t listener,
|
||||
EventId_t idFrom, EventId_t idTo, bool idInverted,
|
||||
object_id_t reporterFrom, object_id_t reporterTo,
|
||||
bool reporterInverted) {
|
||||
auto iter = listenerList.find(listener);
|
||||
if (iter == listenerList.end()) {
|
||||
return LISTENER_NOT_FOUND;
|
||||
}
|
||||
lockMutex();
|
||||
ReturnValue_t result = iter->second.addMatch(idFrom, idTo, idInverted,
|
||||
reporterFrom, reporterTo, reporterInverted);
|
||||
unlockMutex();
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t EventManager::unsubscribeFromEventRange(MessageQueueId_t listener,
|
||||
EventId_t idFrom, EventId_t idTo, bool idInverted,
|
||||
object_id_t reporterFrom, object_id_t reporterTo,
|
||||
bool reporterInverted) {
|
||||
auto iter = listenerList.find(listener);
|
||||
if (iter == listenerList.end()) {
|
||||
return LISTENER_NOT_FOUND;
|
||||
}
|
||||
lockMutex();
|
||||
ReturnValue_t result = iter->second.removeMatch(idFrom, idTo, idInverted,
|
||||
reporterFrom, reporterTo, reporterInverted);
|
||||
unlockMutex();
|
||||
return result;
|
||||
}
|
||||
|
||||
void EventManager::printEvent(EventMessage* message) {
|
||||
const char *string = 0;
|
||||
switch (message->getSeverity()) {
|
||||
case SEVERITY::INFO:
|
||||
string = translateObject(message->getReporter());
|
||||
info << "EVENT: ";
|
||||
if (string != 0) {
|
||||
info << string;
|
||||
} else {
|
||||
info << "0x" << std::hex << message->getReporter() << std::dec;
|
||||
}
|
||||
info << " reported " << translateEvents(message->getEvent()) << " ("
|
||||
<< std::dec << message->getEventId() << std::hex << ") P1: 0x"
|
||||
<< message->getParameter1() << " P2: 0x"
|
||||
<< message->getParameter2() << std::dec << std::endl;
|
||||
break;
|
||||
default:
|
||||
string = translateObject(message->getReporter());
|
||||
error << "EVENT: ";
|
||||
if (string != 0) {
|
||||
error << string;
|
||||
} else {
|
||||
error << "0x" << std::hex << message->getReporter() << std::dec;
|
||||
}
|
||||
error << " reported " << translateEvents(message->getEvent()) << " ("
|
||||
<< std::dec << message->getEventId() << std::hex << ") P1: 0x"
|
||||
<< message->getParameter1() << " P2: 0x"
|
||||
<< message->getParameter2() << std::dec << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void EventManager::lockMutex() {
|
||||
OSAL::lockMutex(this->mutex, OSAL::NO_TIMEOUT);
|
||||
}
|
||||
|
||||
void EventManager::unlockMutex() {
|
||||
OSAL::unlockMutex(this->mutex);
|
||||
}
|
61
events/EventManager.h
Normal file
61
events/EventManager.h
Normal file
@ -0,0 +1,61 @@
|
||||
#ifndef EVENTMANAGER_H_
|
||||
#define EVENTMANAGER_H_
|
||||
|
||||
#include <framework/events/eventmatching/EventMatchTree.h>
|
||||
#include <framework/events/EventManagerIF.h>
|
||||
#include <framework/objectmanager/SystemObject.h>
|
||||
#include <framework/osal/OSAL.h>
|
||||
#include <framework/storagemanager/LocalPool.h>
|
||||
#include <framework/tasks/ExecutableObjectIF.h>
|
||||
#include <map>
|
||||
|
||||
class EventManager: public EventManagerIF,
|
||||
public ExecutableObjectIF,
|
||||
public SystemObject {
|
||||
public:
|
||||
static const uint16_t MAX_EVENTS_PER_CYCLE = 150;
|
||||
|
||||
EventManager(object_id_t setObjectId);
|
||||
virtual ~EventManager();
|
||||
|
||||
MessageQueueId_t getEventReportQueue();
|
||||
|
||||
ReturnValue_t registerListener(MessageQueueId_t listener, bool forwardAllButSelected = false);
|
||||
ReturnValue_t subscribeToEvent(MessageQueueId_t listener, EventId_t event);
|
||||
ReturnValue_t subscribeToAllEventsFrom(MessageQueueId_t listener,
|
||||
object_id_t object);
|
||||
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);
|
||||
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);
|
||||
ReturnValue_t performOperation();
|
||||
|
||||
protected:
|
||||
|
||||
MessageQueue eventReportQueue;
|
||||
|
||||
MessageQueueSender eventForwardingSender;
|
||||
|
||||
std::map<MessageQueueId_t, EventMatchTree> listenerList;
|
||||
|
||||
MutexId_t* mutex;
|
||||
|
||||
static const uint8_t N_POOLS = 3;
|
||||
LocalPool<N_POOLS> factoryBackend;
|
||||
static const uint16_t POOL_SIZES[N_POOLS];
|
||||
static const uint16_t N_ELEMENTS[N_POOLS];
|
||||
|
||||
void notifyListeners(EventMessage *message);
|
||||
|
||||
void printEvent(EventMessage *message);
|
||||
|
||||
void lockMutex();
|
||||
|
||||
void unlockMutex();
|
||||
};
|
||||
|
||||
#endif /* EVENTMANAGER_H_ */
|
53
events/EventManagerIF.h
Normal file
53
events/EventManagerIF.h
Normal file
@ -0,0 +1,53 @@
|
||||
#ifndef EVENTMANAGERIF_H_
|
||||
#define EVENTMANAGERIF_H_
|
||||
|
||||
#include <framework/events/eventmatching/eventmatching.h>
|
||||
#include <framework/events/EventMessage.h>
|
||||
#include <framework/ipc/MessageQueue.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
|
||||
class EventManagerIF {
|
||||
public:
|
||||
|
||||
static const uint8_t INTERFACE_ID = EVENT_MANAGER_IF;
|
||||
static const ReturnValue_t LISTENER_NOT_FOUND = MAKE_RETURN_CODE(1);
|
||||
virtual ~EventManagerIF() {
|
||||
}
|
||||
|
||||
virtual MessageQueueId_t getEventReportQueue() = 0;
|
||||
|
||||
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,
|
||||
uint32_t parameter1 = 0, uint32_t parameter2 = 0, MessageQueueId_t sentFrom = 0) {
|
||||
EventMessage message(event, reportingObject, parameter1, parameter2);
|
||||
triggerEvent(&message, sentFrom);
|
||||
}
|
||||
static void triggerEvent(EventMessage* message, MessageQueueId_t sentFrom = 0) {
|
||||
static MessageQueueId_t eventmanagerQueue = 0;
|
||||
if (eventmanagerQueue == 0) {
|
||||
EventManagerIF *eventmanager = objectManager->get<EventManagerIF>(
|
||||
objects::EVENT_MANAGER);
|
||||
if (eventmanager != NULL) {
|
||||
eventmanagerQueue = eventmanager->getEventReportQueue();
|
||||
}
|
||||
}
|
||||
MessageQueueSender sender(eventmanagerQueue);
|
||||
sender.sendToDefault(message, sentFrom);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif /* EVENTMANAGERIF_H_ */
|
114
events/EventMessage.cpp
Normal file
114
events/EventMessage.cpp
Normal file
@ -0,0 +1,114 @@
|
||||
#include <framework/events/EventMessage.h>
|
||||
#include <cstring>
|
||||
|
||||
EventMessage::EventMessage() {
|
||||
messageSize = EVENT_MESSAGE_SIZE;
|
||||
clearEventMessage();
|
||||
}
|
||||
|
||||
EventMessage::EventMessage(Event event, object_id_t reporter,
|
||||
uint32_t parameter1, uint32_t parameter2) {
|
||||
messageSize = EVENT_MESSAGE_SIZE;
|
||||
setMessageId(EVENT_MESSAGE);
|
||||
setEvent(event);
|
||||
setReporter(reporter);
|
||||
setParameter1(parameter1);
|
||||
setParameter2(parameter2);
|
||||
}
|
||||
|
||||
EventMessage::~EventMessage() {
|
||||
}
|
||||
|
||||
Event EventMessage::getEvent() {
|
||||
Event event;
|
||||
memcpy(&event, getData(), sizeof(Event));
|
||||
return (event & 0xFFFFFF);
|
||||
}
|
||||
|
||||
void EventMessage::setEvent(Event event) {
|
||||
Event tempEvent;
|
||||
memcpy(&tempEvent, getData(), sizeof(Event));
|
||||
tempEvent = (tempEvent & 0xFF000000) + (event & 0xFFFFFF);
|
||||
memcpy(getData(), &tempEvent, sizeof(Event));
|
||||
}
|
||||
|
||||
uint8_t EventMessage::getMessageId() {
|
||||
Event event;
|
||||
memcpy(&event, getData(), sizeof(Event));
|
||||
return (event & 0xFF000000) >> 24;
|
||||
}
|
||||
|
||||
void EventMessage::setMessageId(uint8_t id) {
|
||||
Event event;
|
||||
memcpy(&event, getData(), sizeof(Event));
|
||||
event = (event & 0x00FFFFFF) + (id << 24);
|
||||
memcpy(getData(), &event, sizeof(Event));
|
||||
}
|
||||
|
||||
EventSeverity_t EventMessage::getSeverity() {
|
||||
Event event;
|
||||
memcpy(&event, getData(), sizeof(Event));
|
||||
return EVENT::getSeverity(event);
|
||||
}
|
||||
|
||||
void EventMessage::setSeverety(EventSeverity_t severity) {
|
||||
Event event;
|
||||
memcpy(&event, getData(), sizeof(Event));
|
||||
event = (event & 0xFF00FFFF) + (severity << 16);
|
||||
memcpy(getData(), &event, sizeof(Event));
|
||||
}
|
||||
|
||||
EventId_t EventMessage::getEventId() {
|
||||
Event event;
|
||||
memcpy(&event, getData(), sizeof(Event));
|
||||
return EVENT::getEventId(event);
|
||||
}
|
||||
|
||||
void EventMessage::setEventId(EventId_t eventId) {
|
||||
Event event;
|
||||
memcpy(&event, getData(), sizeof(Event));
|
||||
event = (event & 0xFFFF0000) + eventId;
|
||||
memcpy(getData(), &event, sizeof(Event));
|
||||
}
|
||||
|
||||
object_id_t EventMessage::getReporter() {
|
||||
object_id_t parameter;
|
||||
memcpy(¶meter, getData() + sizeof(Event), sizeof(object_id_t));
|
||||
return parameter;
|
||||
}
|
||||
|
||||
void EventMessage::setReporter(object_id_t reporter) {
|
||||
memcpy(getData() + sizeof(Event), &reporter, sizeof(object_id_t));
|
||||
}
|
||||
|
||||
uint32_t EventMessage::getParameter1() {
|
||||
uint32_t parameter;
|
||||
memcpy(¶meter, getData() + sizeof(Event) + sizeof(object_id_t), 4);
|
||||
return parameter;
|
||||
}
|
||||
|
||||
void EventMessage::setParameter1(uint32_t parameter) {
|
||||
memcpy(getData() + sizeof(Event) + sizeof(object_id_t), ¶meter, 4);
|
||||
}
|
||||
|
||||
uint32_t EventMessage::getParameter2() {
|
||||
uint32_t parameter;
|
||||
memcpy(¶meter, getData() + sizeof(Event) + sizeof(object_id_t) + 4, 4);
|
||||
return parameter;
|
||||
}
|
||||
|
||||
void EventMessage::setParameter2(uint32_t parameter) {
|
||||
memcpy(getData() + sizeof(Event) + sizeof(object_id_t) + 4, ¶meter, 4);
|
||||
}
|
||||
|
||||
void EventMessage::clearEventMessage() {
|
||||
setEvent(INVALID_EVENT);
|
||||
}
|
||||
|
||||
bool EventMessage::isClearedEventMessage() {
|
||||
return getEvent() == INVALID_EVENT;
|
||||
}
|
||||
|
||||
size_t EventMessage::getMinimumMessageSize() {
|
||||
return EVENT_MESSAGE_SIZE;
|
||||
}
|
52
events/EventMessage.h
Normal file
52
events/EventMessage.h
Normal file
@ -0,0 +1,52 @@
|
||||
#ifndef EVENTMESSAGE_H_
|
||||
#define EVENTMESSAGE_H_
|
||||
|
||||
#include <framework/events/Event.h>
|
||||
#include <framework/ipc/MessageQueueMessage.h>
|
||||
#include <framework/objectmanager/ObjectManagerIF.h>
|
||||
|
||||
/**
|
||||
* Passing on events through IPC.
|
||||
* Event Id, severity and message type retrieval is a bit difficult.
|
||||
*/
|
||||
class EventMessage: public MessageQueueMessage {
|
||||
public:
|
||||
static const uint8_t EVENT_MESSAGE = 0; //!< Normal event
|
||||
static const uint8_t CONFIRMATION_REQUEST = 1; //!< Request to parent if event is caused by child or not.
|
||||
static const uint8_t YOUR_FAULT = 2; //!< The fault was caused by child, parent believes it's ok.
|
||||
static const uint8_t MY_FAULT = 3; //!< The fault was caused by the parent, child is ok.
|
||||
//TODO: Add other messageIDs here if necessary.
|
||||
static const uint8_t EVENT_MESSAGE_SIZE = HEADER_SIZE + sizeof(Event)
|
||||
+ 3 * sizeof(uint32_t);
|
||||
|
||||
EventMessage();
|
||||
// EventMessage(EventId_t event, EventSeverity_t severity,
|
||||
// object_id_t reporter, uint32_t parameter1, uint32_t parameter2 = 0);
|
||||
EventMessage(Event event, object_id_t reporter, uint32_t parameter1,
|
||||
uint32_t parameter2 = 0);
|
||||
virtual ~EventMessage();
|
||||
Event getEvent();
|
||||
void setEvent(Event event);
|
||||
uint8_t getMessageId();
|
||||
void setMessageId(uint8_t id);
|
||||
EventSeverity_t getSeverity();
|
||||
void setSeverety(EventSeverity_t severity);
|
||||
EventId_t getEventId();
|
||||
void setEventId(EventId_t event);
|
||||
object_id_t getReporter();
|
||||
void setReporter(object_id_t reporter);
|
||||
uint32_t getParameter1();
|
||||
void setParameter1(uint32_t parameter);
|
||||
uint32_t getParameter2();
|
||||
void setParameter2(uint32_t parameter);
|
||||
|
||||
void clearEventMessage();
|
||||
bool isClearedEventMessage();
|
||||
|
||||
protected:
|
||||
static const Event INVALID_EVENT = 0;
|
||||
virtual size_t getMinimumMessageSize();
|
||||
|
||||
};
|
||||
|
||||
#endif /* EVENTMESSAGE_H_ */
|
26
events/EventReportingProxyIF.h
Normal file
26
events/EventReportingProxyIF.h
Normal file
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* EventReportingProxyIF.h
|
||||
*
|
||||
* Created on: 19.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTREPORTINGPROXYIF_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTREPORTINGPROXYIF_H_
|
||||
|
||||
#include <framework/events/Event.h>
|
||||
|
||||
|
||||
class EventReportingProxyIF {
|
||||
public:
|
||||
virtual ~EventReportingProxyIF() {
|
||||
}
|
||||
|
||||
virtual void forwardEvent(Event event, uint32_t parameter1 = 0, uint32_t parameter2 = 0) const = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_EVENTS_EVENTREPORTINGPROXYIF_H_ */
|
19
events/eventmatching/EventIdRangeMatcher.cpp
Normal file
19
events/eventmatching/EventIdRangeMatcher.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* EventIdRangeMatcher.cpp
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/events/eventmatching/EventIdRangeMatcher.h>
|
||||
|
||||
EventIdRangeMatcher::EventIdRangeMatcher(EventId_t lower, EventId_t upper,
|
||||
bool inverted) : EventRangeMatcherBase<EventId_t>(lower, upper, inverted) {
|
||||
}
|
||||
|
||||
EventIdRangeMatcher::~EventIdRangeMatcher() {
|
||||
}
|
||||
|
||||
bool EventIdRangeMatcher::match(EventMessage* message) {
|
||||
return rangeMatcher.match(message->getEventId());
|
||||
}
|
20
events/eventmatching/EventIdRangeMatcher.h
Normal file
20
events/eventmatching/EventIdRangeMatcher.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* EventIdRangeMatcher.h
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTIDRANGEMATCHER_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTIDRANGEMATCHER_H_
|
||||
|
||||
#include <framework/events/eventmatching/EventRangeMatcherBase.h>
|
||||
|
||||
class EventIdRangeMatcher: public EventRangeMatcherBase<EventId_t> {
|
||||
public:
|
||||
EventIdRangeMatcher(EventId_t lower, EventId_t upper, bool inverted);
|
||||
~EventIdRangeMatcher();
|
||||
bool match(EventMessage* message);
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_EVENTS_EVENTMATCHING_EVENTIDRANGEMATCHER_H_ */
|
151
events/eventmatching/EventMatchTree.cpp
Normal file
151
events/eventmatching/EventMatchTree.cpp
Normal file
@ -0,0 +1,151 @@
|
||||
/*
|
||||
* EventMatchTree.cpp
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/events/eventmatching/EventIdRangeMatcher.h>
|
||||
#include <framework/events/eventmatching/EventMatchTree.h>
|
||||
#include <framework/events/eventmatching/ReporterRangeMatcher.h>
|
||||
#include <framework/events/eventmatching/SeverityRangeMatcher.h>
|
||||
|
||||
EventMatchTree::EventMatchTree(StorageManagerIF* storageBackend, bool invertedMatch) :
|
||||
MatchTree<EventMessage*>(end(), 1), factory(storageBackend), invertedMatch(invertedMatch) {
|
||||
}
|
||||
|
||||
EventMatchTree::~EventMatchTree() {
|
||||
}
|
||||
|
||||
bool EventMatchTree::match(EventMessage* number) {
|
||||
if (invertedMatch) {
|
||||
return !MatchTree<EventMessage*>::match(number);
|
||||
} else {
|
||||
return MatchTree<EventMessage*>::match(number);
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t EventMatchTree::addMatch(EventId_t idFrom,
|
||||
EventId_t idTo, bool idInverted, object_id_t reporterFrom,
|
||||
object_id_t reporterTo, bool reporterInverted) {
|
||||
if (idFrom == 0) {
|
||||
//Assuming all events shall be forwarded.
|
||||
idTo = 0;
|
||||
idInverted = true;
|
||||
}
|
||||
if (idTo == 0) {
|
||||
idTo = idFrom;
|
||||
}
|
||||
iterator lastTest;
|
||||
ReturnValue_t result = findOrInsertRangeMatcher<EventId_t, EventIdRangeMatcher>(
|
||||
begin(), idFrom, idTo, idInverted, &lastTest);
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
return result;
|
||||
}
|
||||
if (reporterFrom == 0) {
|
||||
//No need to add another AND branch
|
||||
return RETURN_OK;
|
||||
}
|
||||
if (reporterTo == 0) {
|
||||
reporterTo = reporterFrom;
|
||||
}
|
||||
return findOrInsertRangeMatcher<object_id_t, ReporterRangeMatcher>(
|
||||
lastTest.left(), reporterFrom, reporterTo, reporterInverted,
|
||||
&lastTest);
|
||||
}
|
||||
|
||||
ReturnValue_t EventMatchTree::removeMatch(EventId_t idFrom,
|
||||
EventId_t idTo, bool idInverted, object_id_t reporterFrom,
|
||||
object_id_t reporterTo, bool reporterInverted) {
|
||||
|
||||
iterator foundElement;
|
||||
|
||||
if (idFrom == 0) {
|
||||
//Assuming a "forward all events" request.
|
||||
idTo = 0;
|
||||
idInverted = true;
|
||||
}
|
||||
if (idTo == 0) {
|
||||
idTo = idFrom;
|
||||
}
|
||||
foundElement = findRangeMatcher<EventId_t, EventIdRangeMatcher>(
|
||||
begin(), idFrom, idTo, idInverted);
|
||||
if (foundElement == end()) {
|
||||
return NO_MATCH; //Can't tell if too detailed or just not found.
|
||||
}
|
||||
if (reporterFrom == 0) {
|
||||
if (foundElement.left() == end()) {
|
||||
return removeElementAndReconnectChildren(foundElement);
|
||||
} else {
|
||||
return TOO_GENERAL_REQUEST;
|
||||
}
|
||||
}
|
||||
if (reporterTo == 0) {
|
||||
reporterTo = reporterFrom;
|
||||
}
|
||||
foundElement = findRangeMatcher<object_id_t, ReporterRangeMatcher>(
|
||||
foundElement.left(), reporterFrom, reporterTo, reporterInverted);
|
||||
if (foundElement == end()) {
|
||||
return NO_MATCH;
|
||||
} else {
|
||||
return removeElementAndReconnectChildren(foundElement);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename VALUE_T, typename INSERTION_T>
|
||||
inline ReturnValue_t EventMatchTree::findOrInsertRangeMatcher(iterator start,
|
||||
VALUE_T idFrom, VALUE_T idTo, bool inverted, iterator* lastTest) {
|
||||
bool attachToBranch = AND;
|
||||
iterator iter = start;
|
||||
while (iter != end()) {
|
||||
INSERTION_T* matcher = static_cast<INSERTION_T*>(*iter);
|
||||
attachToBranch = OR;
|
||||
*lastTest = iter;
|
||||
if ((matcher->rangeMatcher.lowerBound == idFrom)
|
||||
&& (matcher->rangeMatcher.upperBound == idTo)
|
||||
&& (matcher->rangeMatcher.inverted == inverted)) {
|
||||
return RETURN_OK;
|
||||
} else {
|
||||
iter = iter.right();
|
||||
}
|
||||
}
|
||||
//Only reached if nothing was found.
|
||||
SerializeableMatcherIF<EventMessage*>* newContent = factory.generate<
|
||||
INSERTION_T>(idFrom, idTo, inverted);
|
||||
if (newContent == NULL) {
|
||||
return FULL;
|
||||
}
|
||||
Node* newNode = factory.generate<Node>(newContent);
|
||||
if (newNode == NULL) {
|
||||
return FULL;
|
||||
}
|
||||
*lastTest = insert(attachToBranch, *lastTest, newNode);
|
||||
if (*lastTest == end()) {
|
||||
//This actaully never fails, so creating a dedicated returncode seems an overshoot.
|
||||
return RETURN_FAILED;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
template<typename VALUE_T, typename INSERTION_T>
|
||||
EventMatchTree::iterator EventMatchTree::findRangeMatcher(iterator start,
|
||||
VALUE_T idFrom, VALUE_T idTo, bool inverted) {
|
||||
iterator iter = start;
|
||||
while (iter != end()) {
|
||||
INSERTION_T* matcher = static_cast<INSERTION_T*>(*iter);
|
||||
if ((matcher->rangeMatcher.lowerBound == idFrom)
|
||||
&& (matcher->rangeMatcher.upperBound == idTo)
|
||||
&& (matcher->rangeMatcher.inverted == inverted)) {
|
||||
break;
|
||||
} else {
|
||||
iter = iter.right(); //next OR element
|
||||
}
|
||||
}
|
||||
return iter;
|
||||
}
|
||||
|
||||
ReturnValue_t EventMatchTree::cleanUpElement(iterator position) {
|
||||
//TODO: What if first deletion fails?
|
||||
factory.destroy(position.element->value);
|
||||
return factory.destroy(position.element);
|
||||
}
|
43
events/eventmatching/EventMatchTree.h
Normal file
43
events/eventmatching/EventMatchTree.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* EventMatchTree.h
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTMATCHTREE_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTMATCHTREE_H_
|
||||
|
||||
#include <framework/container/PlacementFactory.h>
|
||||
#include <framework/events/EventMessage.h>
|
||||
#include <framework/globalfunctions/matching/MatchTree.h>
|
||||
#include <framework/returnvalues/HasReturnvaluesIF.h>
|
||||
class StorageManagerIF;
|
||||
|
||||
class EventMatchTree: public MatchTree<EventMessage*>, public HasReturnvaluesIF {
|
||||
public:
|
||||
EventMatchTree(StorageManagerIF* storageBackend, bool invertedMatch);
|
||||
virtual ~EventMatchTree();
|
||||
ReturnValue_t addMatch(EventId_t idFrom = 0, EventId_t idTo = 0, bool idInverted = false,
|
||||
object_id_t reporterFrom = 0, object_id_t reporterTo = 0,
|
||||
bool reporterInverted = false);
|
||||
ReturnValue_t removeMatch(EventId_t idFrom = 0, EventId_t idTo = 0, bool idInverted = false,
|
||||
object_id_t reporterFrom = 0, object_id_t reporterTo = 0,
|
||||
bool reporterInverted = false);
|
||||
bool match(EventMessage* number);
|
||||
protected:
|
||||
ReturnValue_t cleanUpElement(iterator position);
|
||||
private:
|
||||
PlacementFactory factory;
|
||||
bool invertedMatch;
|
||||
template<typename VALUE_T, typename INSERTION_T>
|
||||
ReturnValue_t findOrInsertRangeMatcher(iterator start, VALUE_T idFrom,
|
||||
VALUE_T idTo, bool inverted, iterator* lastTest);
|
||||
|
||||
template<typename VALUE_T, typename INSERTION_T>
|
||||
iterator findRangeMatcher(iterator start, VALUE_T idFrom, VALUE_T idTo,
|
||||
bool inverted);
|
||||
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_EVENTS_EVENTMATCHING_EVENTMATCHTREE_H_ */
|
36
events/eventmatching/EventRangeMatcherBase.h
Normal file
36
events/eventmatching/EventRangeMatcherBase.h
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* EventRangeMatcherBase.h
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTRANGEMATCHERBASE_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTRANGEMATCHERBASE_H_
|
||||
|
||||
#include <framework/events/EventMessage.h>
|
||||
#include <framework/globalfunctions/matching/RangeMatcher.h>
|
||||
#include <framework/globalfunctions/matching/SerializeableMatcherIF.h>
|
||||
|
||||
template <typename T>
|
||||
class EventRangeMatcherBase: public SerializeableMatcherIF<EventMessage*> {
|
||||
friend class EventMatchTree;
|
||||
public:
|
||||
EventRangeMatcherBase(T from, T till, bool inverted) : rangeMatcher(from, till, inverted) { }
|
||||
virtual ~EventRangeMatcherBase() { }
|
||||
ReturnValue_t serialize(uint8_t** buffer, uint32_t* size,
|
||||
const uint32_t max_size, bool bigEndian) const {
|
||||
return rangeMatcher.serialize(buffer, size, max_size, bigEndian);
|
||||
}
|
||||
uint32_t getSerializedSize() const {
|
||||
return rangeMatcher.getSerializedSize();
|
||||
}
|
||||
ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size,
|
||||
bool bigEndian) {
|
||||
return rangeMatcher.deSerialize(buffer, size, bigEndian);
|
||||
}
|
||||
protected:
|
||||
RangeMatcher<T> rangeMatcher;
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_EVENTS_EVENTMATCHING_EVENTRANGEMATCHERBASE_H_ */
|
20
events/eventmatching/ReporterRangeMatcher.cpp
Normal file
20
events/eventmatching/ReporterRangeMatcher.cpp
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* ReporterRangeMatcher.cpp
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/events/eventmatching/ReporterRangeMatcher.h>
|
||||
|
||||
ReporterRangeMatcher::ReporterRangeMatcher(object_id_t lower, object_id_t upper,
|
||||
bool inverted) : EventRangeMatcherBase<object_id_t>(lower, upper, inverted) {
|
||||
}
|
||||
|
||||
ReporterRangeMatcher::~ReporterRangeMatcher() {
|
||||
|
||||
}
|
||||
|
||||
bool ReporterRangeMatcher::match(EventMessage* message) {
|
||||
return rangeMatcher.match(message->getReporter());
|
||||
}
|
20
events/eventmatching/ReporterRangeMatcher.h
Normal file
20
events/eventmatching/ReporterRangeMatcher.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* ReporterRangeMatcher.h
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_REPORTERRANGEMATCHER_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTMATCHING_REPORTERRANGEMATCHER_H_
|
||||
|
||||
#include <framework/events/eventmatching/EventRangeMatcherBase.h>
|
||||
|
||||
class ReporterRangeMatcher: public EventRangeMatcherBase<object_id_t> {
|
||||
public:
|
||||
ReporterRangeMatcher(object_id_t lower, object_id_t upper, bool inverted);
|
||||
~ReporterRangeMatcher();
|
||||
bool match(EventMessage* message);
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_EVENTS_EVENTMATCHING_REPORTERRANGEMATCHER_H_ */
|
21
events/eventmatching/SeverityRangeMatcher.cpp
Normal file
21
events/eventmatching/SeverityRangeMatcher.cpp
Normal file
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* SeverityRangeMatcher.cpp
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#include <framework/events/eventmatching/SeverityRangeMatcher.h>
|
||||
#include <framework/events/EventMessage.h>
|
||||
#include <framework/serialize/SerializeAdapter.h>
|
||||
|
||||
SeverityRangeMatcher::SeverityRangeMatcher(EventSeverity_t from,
|
||||
EventSeverity_t till, bool inverted) : EventRangeMatcherBase<EventSeverity_t>(from, till, inverted) {
|
||||
}
|
||||
|
||||
SeverityRangeMatcher::~SeverityRangeMatcher() {
|
||||
}
|
||||
|
||||
bool SeverityRangeMatcher::match(EventMessage* message) {
|
||||
return rangeMatcher.match(message->getSeverity());
|
||||
}
|
20
events/eventmatching/SeverityRangeMatcher.h
Normal file
20
events/eventmatching/SeverityRangeMatcher.h
Normal file
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* SeverityRangeMatcher.h
|
||||
*
|
||||
* Created on: 27.08.2015
|
||||
* Author: baetz
|
||||
*/
|
||||
|
||||
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_SEVERITYRANGEMATCHER_H_
|
||||
#define FRAMEWORK_EVENTS_EVENTMATCHING_SEVERITYRANGEMATCHER_H_
|
||||
|
||||
#include <framework/events/eventmatching/EventRangeMatcherBase.h>
|
||||
|
||||
class SeverityRangeMatcher: public EventRangeMatcherBase<EventSeverity_t> {
|
||||
public:
|
||||
SeverityRangeMatcher(EventSeverity_t from, EventSeverity_t till, bool inverted);
|
||||
~SeverityRangeMatcher();
|
||||
bool match(EventMessage* message);
|
||||
};
|
||||
|
||||
#endif /* FRAMEWORK_EVENTS_EVENTMATCHING_SEVERITYRANGEMATCHER_H_ */
|
10
events/eventmatching/eventmatching.h
Normal file
10
events/eventmatching/eventmatching.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef EVENTMATCHING_H_
|
||||
#define EVENTMATCHING_H_
|
||||
|
||||
#include <framework/events/eventmatching/EventIdRangeMatcher.h>
|
||||
#include <framework/events/eventmatching/EventMatchTree.h>
|
||||
#include <framework/events/eventmatching/ReporterRangeMatcher.h>
|
||||
#include <framework/events/eventmatching/SeverityRangeMatcher.h>
|
||||
|
||||
|
||||
#endif /* EVENTMATCHING_H_ */
|
Reference in New Issue
Block a user