101 lines
2.9 KiB
C++
101 lines
2.9 KiB
C++
/*
|
|
* File: EventService.h
|
|
* Author: jgaebler
|
|
*
|
|
* Created on February 27, 2014, 4:45 PM
|
|
*/
|
|
#pragma once
|
|
|
|
#ifndef EVENTSERVICE_H
|
|
#define EVENTSERVICE_H
|
|
|
|
#include "common/MoversightService.h"
|
|
#include "common/container/ObjectList.h"
|
|
#include "common/container/SubscriptionMap.h"
|
|
|
|
namespace ubeeme {
|
|
namespace moversight {
|
|
|
|
class Moversight;
|
|
|
|
/**
|
|
* @brief Provides an event handling service for the moversight protocol.
|
|
* @author Robert Noack
|
|
* @author Jan Gäbler
|
|
* @class EventService
|
|
* @ingroup Moversight
|
|
*/
|
|
class EventService : public MoversightService {
|
|
friend class Moversight;
|
|
friend class Dispatcher;
|
|
public:
|
|
EventService(Dispatcher & m);
|
|
EventService(const EventService& orig);
|
|
virtual ~EventService();
|
|
|
|
EventService & operator=(const EventService & other);
|
|
|
|
virtual void initialise();
|
|
virtual void finalise();
|
|
|
|
template<typename ObjType>
|
|
void subscribe(ObjectListener * ol);
|
|
|
|
void signal( DeliverableObject* e, ObjectListener* recipient = NULL);
|
|
|
|
template<typename ObjType>
|
|
void unsubscribe(ObjectListener * ol);
|
|
void unsubscribeAll(ObjectListener * ol);
|
|
|
|
protected:
|
|
|
|
virtual void process();
|
|
|
|
private:
|
|
|
|
void subscribe(ObjectListener * ol, std::string type);
|
|
void unsubscribe(ObjectListener * ol, std::string type);
|
|
|
|
ObjectList pendingObjects;
|
|
SubscriptionMap subscriptions;
|
|
|
|
};
|
|
|
|
/**
|
|
* @brief Subscribe for a certain type of object.
|
|
*
|
|
* This will add <ObjType> as a key value to <subscriptions>, if not
|
|
* already present. <ms> will be inserted in the object's subscriber list.
|
|
* To subscribe to multiple objects, you have to call <subscribe()>
|
|
* subsequently.
|
|
*
|
|
* @tparam ObjType Type of object to subscribe to.
|
|
* @param ms The Moversight service which is subscribing to the object.
|
|
*/
|
|
template<typename ObjType>
|
|
void
|
|
EventService::subscribe(ObjectListener * ol) {
|
|
subscribe(ol, typeid (ObjType*).name());
|
|
}
|
|
|
|
/**
|
|
* @brief Unsubscribe from a certain type of object.
|
|
*
|
|
* The service will be removed from the object's list of subscribers.
|
|
* To unsubscribe from multiple objects you have to use subsequent calls
|
|
* to <unsubscribe()>.
|
|
*
|
|
* @tparam ObjType Type of object to unsubscribe from.
|
|
* @param ms The Moversight service to unsubscribe.
|
|
*/
|
|
template<typename ObjType>
|
|
void
|
|
EventService::unsubscribe(ObjectListener * ol) {
|
|
unsubscribe(ol, typeid (ObjType*).name());
|
|
}
|
|
|
|
}
|
|
}
|
|
#endif /* EVENTSERVICE_H */
|
|
|