Merge branch 'event/git-update' into mueller/master

This commit is contained in:
Robin Müller 2020-08-28 17:58:31 +02:00
commit 8596810fe2
18 changed files with 826 additions and 825 deletions

View File

@ -1,14 +1,14 @@
#include "../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);
}
}
#include "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);
}
}

View File

@ -1,45 +1,44 @@
#ifndef FRAMEWORK_EVENTS_EVENT_H_
#define FRAMEWORK_EVENTS_EVENT_H_
#include <cstdint>
#include "../events/fwSubsystemIdRanges.h"
//could be move to more suitable location
#include <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 /* FRAMEWORK_EVENTS_EVENT_H_ */
#ifndef EVENTOBJECT_EVENT_H_
#define EVENTOBJECT_EVENT_H_
#include <stdint.h>
#include "fwSubsystemIdRanges.h"
//could be move to more suitable location
#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_ */

View File

@ -1,166 +1,162 @@
#include "../events/EventManager.h"
#include "../events/EventMessage.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../ipc/QueueFactory.h"
#include "../ipc/MutexFactory.h"
const uint16_t EventManager::POOL_SIZES[N_POOLS] = {
sizeof(EventMatchTree::Node), sizeof(EventIdRangeMatcher),
sizeof(ReporterRangeMatcher) };
// If one checks registerListener calls, there are around 40 (to max 50)
// objects registering for certain events.
// Each listener requires 1 or 2 EventIdMatcher and 1 or 2 ReportRangeMatcher.
// So a good guess is 75 to a max of 100 pools required for each, which fits well.
// SHOULDDO: Shouldn't this be in the config folder and passed via ctor?
const uint16_t EventManager::N_ELEMENTS[N_POOLS] = { 240, 120, 120 };
EventManager::EventManager(object_id_t setObjectId) :
SystemObject(setObjectId),
factoryBackend(0, POOL_SIZES, N_ELEMENTS, false, true) {
mutex = MutexFactory::instance()->createMutex();
eventReportQueue = QueueFactory::instance()->createMessageQueue(
MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE);
}
EventManager::~EventManager() {
QueueFactory::instance()->deleteMessageQueue(eventReportQueue);
MutexFactory::instance()->deleteMutex(mutex);
}
MessageQueueId_t EventManager::getEventReportQueue() {
return eventReportQueue->getId();
}
ReturnValue_t EventManager::performOperation(uint8_t opCode) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
while (result == HasReturnvaluesIF::RETURN_OK) {
EventMessage message;
result = eventReportQueue->receiveMessage(&message);
if (result == HasReturnvaluesIF::RETURN_OK) {
#ifdef DEBUG
printEvent(&message);
#endif
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)) {
MessageQueueSenderIF::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;
}
#ifdef DEBUG
// forward declaration, should be implemented by mission
extern const char* translateObject(object_id_t object);
extern const char* translateEvents(Event event);
void EventManager::printEvent(EventMessage* message) {
const char *string = 0;
switch (message->getSeverity()) {
case SEVERITY::INFO:
#ifdef DEBUG_INFO_EVENT
string = translateObject(message->getReporter());
sif::info << "EVENT: ";
if (string != 0) {
sif::info << string;
} else {
sif::info << "0x" << std::hex << message->getReporter() << std::dec;
}
sif::info << " reported " << translateEvents(message->getEvent()) << " ("
<< std::dec << message->getEventId() << std::hex << ") P1: 0x"
<< message->getParameter1() << " P2: 0x"
<< message->getParameter2() << std::dec << std::endl;
#endif
break;
default:
string = translateObject(message->getReporter());
sif::debug << "EventManager: ";
if (string != 0) {
sif::debug << string;
}
else {
sif::debug << "0x" << std::hex << message->getReporter() << std::dec;
}
sif::debug << " reported " << translateEvents(message->getEvent())
<< " (" << std::dec << message->getEventId() << ") "
<< std::endl;
sif::debug << std::hex << "P1 Hex: 0x" << message->getParameter1()
<< ", P1 Dec: " << std::dec << message->getParameter1()
<< std::endl;
sif::debug << std::hex << "P2 Hex: 0x" << message->getParameter2()
<< ", P2 Dec: " << std::dec << message->getParameter2()
<< std::endl;
break;
}
}
#endif
void EventManager::lockMutex() {
mutex->lockMutex(MutexIF::BLOCKING);
}
void EventManager::unlockMutex() {
mutex->unlockMutex();
}
#include "EventManager.h"
#include "EventMessage.h"
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "../ipc/QueueFactory.h"
#include "../ipc/MutexFactory.h"
const uint16_t EventManager::POOL_SIZES[N_POOLS] = {
sizeof(EventMatchTree::Node), sizeof(EventIdRangeMatcher),
sizeof(ReporterRangeMatcher) };
// If one checks registerListener calls, there are around 40 (to max 50)
// objects registering for certain events.
// Each listener requires 1 or 2 EventIdMatcher and 1 or 2 ReportRangeMatcher.
// So a good guess is 75 to a max of 100 pools required for each, which fits well.
// SHOULDDO: Shouldn't this be in the config folder and passed via ctor?
const uint16_t EventManager::N_ELEMENTS[N_POOLS] = { 240, 120, 120 };
EventManager::EventManager(object_id_t setObjectId) :
SystemObject(setObjectId),
factoryBackend(0, POOL_SIZES, N_ELEMENTS, false, true) {
mutex = MutexFactory::instance()->createMutex();
eventReportQueue = QueueFactory::instance()->createMessageQueue(
MAX_EVENTS_PER_CYCLE, EventMessage::EVENT_MESSAGE_SIZE);
}
EventManager::~EventManager() {
QueueFactory::instance()->deleteMessageQueue(eventReportQueue);
MutexFactory::instance()->deleteMutex(mutex);
}
MessageQueueId_t EventManager::getEventReportQueue() {
return eventReportQueue->getId();
}
ReturnValue_t EventManager::performOperation(uint8_t opCode) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
while (result == HasReturnvaluesIF::RETURN_OK) {
EventMessage message;
result = eventReportQueue->receiveMessage(&message);
if (result == HasReturnvaluesIF::RETURN_OK) {
#ifdef DEBUG
printEvent(&message);
#endif
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)) {
MessageQueueSenderIF::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;
}
#ifdef DEBUG
void EventManager::printEvent(EventMessage* message) {
const char *string = 0;
switch (message->getSeverity()) {
case SEVERITY::INFO:
#ifdef DEBUG_INFO_EVENT
string = translateObject(message->getReporter());
sif::info << "EVENT: ";
if (string != 0) {
sif::info << string;
} else {
sif::info << "0x" << std::hex << message->getReporter() << std::dec;
}
sif::info << " reported " << translateEvents(message->getEvent()) << " ("
<< std::dec << message->getEventId() << std::hex << ") P1: 0x"
<< message->getParameter1() << " P2: 0x"
<< message->getParameter2() << std::dec << std::endl;
#endif
break;
default:
string = translateObject(message->getReporter());
sif::debug << "EventManager: ";
if (string != 0) {
sif::debug << string;
}
else {
sif::debug << "0x" << std::hex << message->getReporter() << std::dec;
}
sif::debug << " reported " << translateEvents(message->getEvent())
<< " (" << std::dec << message->getEventId() << ") "
<< std::endl;
sif::debug << std::hex << "P1 Hex: 0x" << message->getParameter1()
<< ", P1 Dec: " << std::dec << message->getParameter1()
<< std::endl;
sif::debug << std::hex << "P2 Hex: 0x" << message->getParameter2()
<< ", P2 Dec: " << std::dec << message->getParameter2()
<< std::endl;
break;
}
}
#endif
void EventManager::lockMutex() {
mutex->lockMutex(MutexIF::BLOCKING);
}
void EventManager::unlockMutex() {
mutex->unlockMutex();
}

View File

@ -1,61 +1,67 @@
#ifndef EVENTMANAGER_H_
#define EVENTMANAGER_H_
#include "../events/eventmatching/EventMatchTree.h"
#include "../events/EventManagerIF.h"
#include "../objectmanager/SystemObject.h"
#include "../storagemanager/LocalPool.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../ipc/MutexIF.h"
#include <map>
class EventManager: public EventManagerIF,
public ExecutableObjectIF,
public SystemObject {
public:
static const uint16_t MAX_EVENTS_PER_CYCLE = 80;
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(uint8_t opCode);
protected:
MessageQueueIF* eventReportQueue = nullptr;
std::map<MessageQueueId_t, EventMatchTree> listenerList;
MutexIF* mutex = nullptr;
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);
#ifdef DEBUG
void printEvent(EventMessage *message);
#endif
void lockMutex();
void unlockMutex();
};
#endif /* EVENTMANAGER_H_ */
#ifndef EVENTMANAGER_H_
#define EVENTMANAGER_H_
#include "eventmatching/EventMatchTree.h"
#include "EventManagerIF.h"
#include "../objectmanager/SystemObject.h"
#include "../storagemanager/LocalPool.h"
#include "../tasks/ExecutableObjectIF.h"
#include "../ipc/MessageQueueIF.h"
#include "../ipc/MutexIF.h"
#include <map>
#ifdef DEBUG
// forward declaration, should be implemented by mission
extern const char* translateObject(object_id_t object);
extern const char* translateEvents(Event event);
#endif
class EventManager: public EventManagerIF,
public ExecutableObjectIF,
public SystemObject {
public:
static const uint16_t MAX_EVENTS_PER_CYCLE = 80;
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(uint8_t opCode);
protected:
MessageQueueIF* eventReportQueue = nullptr;
std::map<MessageQueueId_t, EventMatchTree> listenerList;
MutexIF* mutex = nullptr;
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);
#ifdef DEBUG
void printEvent(EventMessage *message);
#endif
void lockMutex();
void unlockMutex();
};
#endif /* EVENTMANAGER_H_ */

View File

@ -1,52 +1,52 @@
#ifndef EVENTMANAGERIF_H_
#define EVENTMANAGERIF_H_
#include "../events/eventmatching/eventmatching.h"
#include "../events/EventMessage.h"
#include "../objectmanager/ObjectManagerIF.h"
#include "../ipc/MessageQueueSenderIF.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;
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();
}
}
MessageQueueSenderIF::sendMessage(eventmanagerQueue, message, sentFrom);
}
};
#endif /* EVENTMANAGERIF_H_ */
#ifndef EVENTMANAGERIF_H_
#define EVENTMANAGERIF_H_
#include "eventmatching/eventmatching.h"
#include "EventMessage.h"
#include "../objectmanager/ObjectManagerIF.h"
#include "../ipc/MessageQueueSenderIF.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;
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();
}
}
MessageQueueSenderIF::sendMessage(eventmanagerQueue, message, sentFrom);
}
};
#endif /* EVENTMANAGERIF_H_ */

View File

@ -1,114 +1,114 @@
#include "../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::setSeverity(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(&parameter, 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(&parameter, getData() + sizeof(Event) + sizeof(object_id_t), 4);
return parameter;
}
void EventMessage::setParameter1(uint32_t parameter) {
memcpy(getData() + sizeof(Event) + sizeof(object_id_t), &parameter, 4);
}
uint32_t EventMessage::getParameter2() {
uint32_t parameter;
memcpy(&parameter, 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, &parameter, 4);
}
void EventMessage::clearEventMessage() {
setEvent(INVALID_EVENT);
}
bool EventMessage::isClearedEventMessage() {
return getEvent() == INVALID_EVENT;
}
size_t EventMessage::getMinimumMessageSize() {
return EVENT_MESSAGE_SIZE;
}
#include "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::setSeverity(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(&parameter, 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(&parameter, getData() + sizeof(Event) + sizeof(object_id_t), 4);
return parameter;
}
void EventMessage::setParameter1(uint32_t parameter) {
memcpy(getData() + sizeof(Event) + sizeof(object_id_t), &parameter, 4);
}
uint32_t EventMessage::getParameter2() {
uint32_t parameter;
memcpy(&parameter, 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, &parameter, 4);
}
void EventMessage::clearEventMessage() {
setEvent(INVALID_EVENT);
}
bool EventMessage::isClearedEventMessage() {
return getEvent() == INVALID_EVENT;
}
size_t EventMessage::getMinimumMessageSize() {
return EVENT_MESSAGE_SIZE;
}

View File

@ -1,52 +1,52 @@
#ifndef EVENTMESSAGE_H_
#define EVENTMESSAGE_H_
#include "../events/Event.h"
#include "../ipc/MessageQueueMessage.h"
#include "../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.
//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 setSeverity(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_ */
#ifndef EVENTMESSAGE_H_
#define EVENTMESSAGE_H_
#include "Event.h"
#include "../ipc/MessageQueueMessage.h"
#include "../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.
//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 setSeverity(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_ */

View File

@ -1,19 +1,19 @@
#ifndef FRAMEWORK_EVENTS_EVENTREPORTINGPROXYIF_H_
#define FRAMEWORK_EVENTS_EVENTREPORTINGPROXYIF_H_
#include "../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_ */
#ifndef FRAMEWORK_EVENTS_EVENTREPORTINGPROXYIF_H_
#define FRAMEWORK_EVENTS_EVENTREPORTINGPROXYIF_H_
#include "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_ */

View File

@ -1,12 +1,12 @@
#include "../../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());
}
#include "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());
}

View File

@ -1,13 +1,13 @@
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTIDRANGEMATCHER_H_
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTIDRANGEMATCHER_H_
#include "../../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_ */
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTIDRANGEMATCHER_H_
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTIDRANGEMATCHER_H_
#include "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_ */

View File

@ -1,149 +1,149 @@
#include "../../events/eventmatching/EventIdRangeMatcher.h"
#include "../../events/eventmatching/EventMatchTree.h"
#include "../../events/eventmatching/ReporterRangeMatcher.h"
#include "../../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) {
//Need to make sure partially generated content is deleted, otherwise, that's a leak.
factory.destroy<INSERTION_T>(static_cast<INSERTION_T*>(newContent));
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) {
factory.destroy(position.element->value);
//If deletion fails, delete element anyway, nothing we can do.
//SHOULDO: Throw event, or write debug output.
return factory.destroy(position.element);
}
#include "EventIdRangeMatcher.h"
#include "EventMatchTree.h"
#include "ReporterRangeMatcher.h"
#include "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) {
//Need to make sure partially generated content is deleted, otherwise, that's a leak.
factory.destroy<INSERTION_T>(static_cast<INSERTION_T*>(newContent));
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) {
factory.destroy(position.element->value);
//If deletion fails, delete element anyway, nothing we can do.
//SHOULDO: Throw event, or write debug output.
return factory.destroy(position.element);
}

View File

@ -1,36 +1,36 @@
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTMATCHTREE_H_
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTMATCHTREE_H_
#include "../../container/PlacementFactory.h"
#include "../../events/EventMessage.h"
#include "../../globalfunctions/matching/MatchTree.h"
#include "../../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_ */
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTMATCHTREE_H_
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTMATCHTREE_H_
#include "../../container/PlacementFactory.h"
#include "../../events/EventMessage.h"
#include "../../globalfunctions/matching/MatchTree.h"
#include "../../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_ */

View File

@ -1,29 +1,29 @@
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTRANGEMATCHERBASE_H_
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTRANGEMATCHERBASE_H_
#include "../../events/EventMessage.h"
#include "../../globalfunctions/matching/RangeMatcher.h"
#include "../../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, size_t* size,
size_t maxSize, Endianness streamEndianness) const {
return rangeMatcher.serialize(buffer, size, maxSize, streamEndianness);
}
size_t getSerializedSize() const {
return rangeMatcher.getSerializedSize();
}
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) {
return rangeMatcher.deSerialize(buffer, size, streamEndianness);
}
protected:
RangeMatcher<T> rangeMatcher;
};
#endif /* FRAMEWORK_EVENTS_EVENTMATCHING_EVENTRANGEMATCHERBASE_H_ */
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_EVENTRANGEMATCHERBASE_H_
#define FRAMEWORK_EVENTS_EVENTMATCHING_EVENTRANGEMATCHERBASE_H_
#include "../../events/EventMessage.h"
#include "../../globalfunctions/matching/RangeMatcher.h"
#include "../../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, size_t* size,
size_t maxSize, Endianness streamEndianness) const {
return rangeMatcher.serialize(buffer, size, maxSize, streamEndianness);
}
size_t getSerializedSize() const {
return rangeMatcher.getSerializedSize();
}
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) {
return rangeMatcher.deSerialize(buffer, size, streamEndianness);
}
protected:
RangeMatcher<T> rangeMatcher;
};
#endif /* FRAMEWORK_EVENTS_EVENTMATCHING_EVENTRANGEMATCHERBASE_H_ */

View File

@ -1,13 +1,13 @@
#include "../../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());
}
#include "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());
}

View File

@ -1,13 +1,13 @@
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_REPORTERRANGEMATCHER_H_
#define FRAMEWORK_EVENTS_EVENTMATCHING_REPORTERRANGEMATCHER_H_
#include "../../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_ */
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_REPORTERRANGEMATCHER_H_
#define FRAMEWORK_EVENTS_EVENTMATCHING_REPORTERRANGEMATCHER_H_
#include "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_ */

View File

@ -1,14 +1,14 @@
#include "../../events/eventmatching/SeverityRangeMatcher.h"
#include "../../events/EventMessage.h"
#include "../../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());
}
#include "SeverityRangeMatcher.h"
#include "../../events/EventMessage.h"
#include "../../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());
}

View File

@ -1,13 +1,13 @@
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_SEVERITYRANGEMATCHER_H_
#define FRAMEWORK_EVENTS_EVENTMATCHING_SEVERITYRANGEMATCHER_H_
#include "../../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_ */
#ifndef FRAMEWORK_EVENTS_EVENTMATCHING_SEVERITYRANGEMATCHER_H_
#define FRAMEWORK_EVENTS_EVENTMATCHING_SEVERITYRANGEMATCHER_H_
#include "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_ */

View File

@ -1,10 +1,10 @@
#ifndef EVENTMATCHING_H_
#define EVENTMATCHING_H_
#include "../../events/eventmatching/EventIdRangeMatcher.h"
#include "../../events/eventmatching/EventMatchTree.h"
#include "../../events/eventmatching/ReporterRangeMatcher.h"
#include "../../events/eventmatching/SeverityRangeMatcher.h"
#endif /* EVENTMATCHING_H_ */
#ifndef EVENTMATCHING_H_
#define EVENTMATCHING_H_
#include "EventIdRangeMatcher.h"
#include "EventMatchTree.h"
#include "ReporterRangeMatcher.h"
#include "SeverityRangeMatcher.h"
#endif /* EVENTMATCHING_H_ */