9 #ifndef INCLUDE_FUNAPI_SYSTEM_EVENT_H_ 10 #define INCLUDE_FUNAPI_SYSTEM_EVENT_H_ 12 #include <boost/any.hpp> 13 #include <boost/bind.hpp> 14 #include <boost/shared_ptr.hpp> 18 #include <google/protobuf/message.h> 31 FUNAPI_DLL_VISIBILITY
extern const EventTag kNullEventTag;
35 class FUNAPI_DLL_VISIBILITY
Event {
41 const Ptr<Session> &)> TimeoutHandler;
43 template <
typename EventT>
45 typedef Ptr<const EventT> result_type;
46 Ptr<const EventT> operator()(
const Ptr<const void> &t);
51 template <
typename EventT>
52 static void RegisterHandler(
56 template <
typename EventT>
57 static void RegisterHandler(
ChainAction (handler)(Ptr<const EventT>));
60 static void RegisterTimeoutHandler(
const TimeoutHandler &handler);
63 template <
typename EventT>
64 static bool Post(Ptr<EventT> event);
65 template <
typename EventT>
66 static bool Post(Ptr<EventT> event,
const EventTag &event_tag);
67 template <
typename EventT>
68 static bool Post(Ptr<EventT> event,
const string &event_name);
69 template <
typename EventT>
70 static bool Post(Ptr<EventT> event,
const string &event_name,
71 const EventTag &event_tag);
74 static bool Invoke(
const function<
void()> &func);
75 static bool Invoke(
const function<
void()> &func,
const EventTag &event_tag);
76 static bool Invoke(
const function<
void()> &func,
const string &event_name);
77 static bool Invoke(
const function<
void()> &func,
const string &event_name,
78 const EventTag &event_tag);
80 static void Resume(
const EventTag &event_tag);
87 typedef function<ChainAction (Ptr<const void>)> VoidedHandler;
89 static void RegisterHandler(
const std::type_info &,
const VoidedHandler &);
90 static bool Post(
const std::type_info &, Ptr<const void>);
91 static bool Post(
const std::type_info &,
93 const EventTag &event_tag);
94 static bool Post(
const std::type_info &, Ptr<const void>,
const string &);
95 static bool Post(
const std::type_info &,
98 const EventTag &event_tag);
102 FUNAPI_DLL_VISIBILITY
void ProcessNextEventAfterTimeout(
const EventTag &tag);
105 FUNAPI_DLL_VISIBILITY
const EventTag &GetCurrentEventTag();
108 FUNAPI_DLL_VISIBILITY
void SetEventName(
const string &name);
109 FUNAPI_DLL_VISIBILITY
const string &GetEventName();
110 FUNAPI_DLL_VISIBILITY DEPRECATED(
void DebugSetEventName(
const string &name));
111 FUNAPI_DLL_VISIBILITY DEPRECATED(
const string &DebugGetEventName());
114 FUNAPI_DLL_VISIBILITY WallClock::Duration GetEventQueueDelay();
117 template <
typename EventT>
119 const Ptr<const void> &t) {
120 return boost::static_pointer_cast<
const EventT,
const void>(t);
124 template <
typename EventT>
127 VoidedHandler f = VoidedHandler(
129 RegisterHandler(
typeid(EventT), f);
131 RegisterHandler(
typeid(EventT),
132 [h](Ptr<const void> p) {
133 const EventT *ep =
static_cast<const EventT*
>(p.get());
134 return h(Ptr<const EventT>(p, ep));
140 template <
typename EventT>
142 RegisterHandler(
typename EventT::Handler(handler));
146 template <
typename EventT>
148 return Post(
typeid(EventT), event);
152 template <
typename EventT>
153 bool Event::Post(Ptr<EventT> event,
const EventTag &event_tag) {
154 return Post(
typeid(EventT), event, event_tag);
158 template <
typename EventT>
159 bool Event::Post(Ptr<EventT> event,
const string &event_name) {
160 return Post(
typeid(EventT), event_name, event);
164 template <
typename EventT>
165 bool Event::Post(Ptr<EventT> event,
const string &event_name,
166 const EventTag &event_tag) {
167 return Post(
typeid(EventT), event, event_name, event_tag);
172 #endif // INCLUDE_FUNAPI_SYSTEM_EVENT_H_
Singleton class to access the Funapi's event subsystem.
Definition: event.h:35
Uuid EventId
Event Id.
Definition: event.h:27
boost::uuids::uuid Uuid
UUID type used throughout Funapi.
Definition: types.h:56
static bool Post(Ptr< EventT > event)
Posts an event so that listeners for the event can handle it.
Definition: event.h:147
static void RegisterHandler(const function< ChainAction(Ptr< const EventT >)> &h)
Listens to a particular event type.
Definition: event.h:125
Uuid EventTag
Event Tag.
Definition: event.h:30
ChainAction
Action types to specify behavior in chained operations (i.e.
Definition: types.h:67