2 #ifndef _YI_EVENT_DISPATCHER_H_ 3 #define _YI_EVENT_DISPATCHER_H_ 29 class CYISignalEmitEventHandler;
43 virtual void EventLoopStarted(
const std::shared_ptr<CYIEventDispatcher> &pDispatcher) = 0;
45 virtual void EventLoopExited(
const std::shared_ptr<CYIEventDispatcher> &pDispatcher) = 0;
69 typedef std::vector<std::shared_ptr<CYIEventHandlerProxy>> YI_EVENT_HANDLER_LIST;
70 typedef std::vector<std::shared_ptr<CYIEventFilterProxy>> YI_EVENT_FILTER_LIST;
71 typedef std::vector<IYIEventDispatcherListener *> YI_EVENT_DISPATCHER_LISTENER_LIST;
73 typedef std::vector<std::pair<CYIThreadHandle, std::shared_ptr<CYIEventDispatcher>>> YI_DISPATCHER_MAP;
92 bool Exit(
bool bJoin =
false,
bool bWaitUntilEmpty =
false);
97 void WaitUntilEventQueueRunning();
107 bool WaitUntilEventPosted(uint64_t uTimeoutMs = 0);
114 bool ProcessOneEvent();
121 bool ProcessAllEvents();
126 bool ProcessAllEvents(uint64_t uTimeoutUs);
247 bool SendEvent(std::unique_ptr<CYIEvent> pEvent);
270 bool SendEvent(std::unique_ptr<CYIEvent> pEvent,
CYIEventHandler *pDestination);
275 int32_t GetEventCount()
const;
287 void DiscardAllPosts();
303 static std::shared_ptr<CYIEventDispatcher> GetDispatcher(
const CYIThreadHandle &threadAffinity);
308 static const std::shared_ptr<CYIEventDispatcher> &GetDefaultDispatcher();
320 static const std::shared_ptr<CYIEventDispatcher> &GetDrawDispatcher();
325 static void SetDispatcher(
const CYIThreadHandle &threadAffinity,
const std::shared_ptr<CYIEventDispatcher> &pDispatcher);
335 static void SetDefaultDispatcher(
const std::shared_ptr<CYIEventDispatcher> &pDispatcher);
340 static void RemoveDefaultDispatcher();
345 static void SetDrawDispatcher(
const std::shared_ptr<CYIEventDispatcher> &pDispatcher);
350 static void RemoveDrawDispatcher();
373 bool PreFilter(
CYIEvent *pEvent,
const std::shared_ptr<CYIEventHandlerProxy> &pDestination);
374 bool PostFilter(
CYIEvent *pEvent,
const std::shared_ptr<CYIEventHandlerProxy> &pDestination);
375 bool DispatchEvent(
CYIEvent *pEvent,
const std::shared_ptr<CYIEventHandlerProxy> &pDestination);
376 bool ProcessEvent(
CYIEvent *pEvent,
const std::shared_ptr<CYIEventHandlerProxy> &pDestination);
378 void NotifyEventLoopStarted();
379 void NotifyEventLoopExited();
380 void NotifyEventDispatchStarted(
CYIEvent *pEvent);
381 void NotifyEventDispatchEnded(
CYIEvent *pEvent);
388 bool m_bEventQueueRunning;
390 CYISignalEmitEventHandler *m_pSignalEmitEventHandler;
394 YI_EVENT_HANDLER_LIST m_eventHandlerList;
395 YI_EVENT_FILTER_LIST m_eventFilterList;
396 YI_EVENT_DISPATCHER_LISTENER_LIST m_eventDispatcherListenerList;
397 YI_EVENT_QUEUE m_eventQueue;
407 static YI_DISPATCHER_MAP s_dispatcherMap;
408 static std::shared_ptr<CYIEventDispatcher> s_dispatcherDefault;
410 static std::shared_ptr<CYIEventDispatcher> s_dispatcherDraw;
419 template<
typename YI_TYPE>
432 YI_LOGD(
"YiDeleteLater",
"No event dispatcher. YiDeleteLater called while the application is shutting down, so deleting ptr immediately.");
bool RegisterEventFilter(CYIEventFilter *pFilter)
virtual void EventPostFilteredByHandler(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent, CYIEventFilter *pFilter, CYIEventHandler *pHandler)=0
Allows registering of event filters which can be used to perform processing on an event before and af...
Definition: YiEventHandler.h:25
Definition: YiMutex.h:110
Base class for events.
Definition: YiEvent.h:489
static std::shared_ptr< CYIEventDispatcher > GetDispatcher(const CYIThreadHandle &threadAffinity)
virtual ~IYIEventDispatcherListener()
Definition: YiEventDispatcher.h:41
#define YI_LOGD(tag, msg,...)
Definition: YiLoggerHelper.h:80
Definition: YiEvent.h:481
virtual void EventDispatchStarted(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent)=0
bool PreFilter(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent)
virtual void EventDispatchEnded(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent)=0
Proxy for a CYIEventFilter allowing safe destruction of the internal event filter objects...
Definition: YiEventFilterProxy.h:24
The base class for an object accessible from script source code.
Definition: YiScriptableObject.h:28
static const std::shared_ptr< CYIEventDispatcher > & GetDefaultDispatcher()
YI_EVENT_PRIORITY
Priority of the event in the event queue.
Definition: YiEvent.h:473
A container class which maintains a queue of items within defined YI_PRIORITY_QUEUE_PRIORITY prioriti...
Definition: YiPriorityQueue.h:44
virtual void EventHandled(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent, CYIEventHandler *pHandler)=0
Handles events where data deletion needs to be deferred.
Definition: YiDeferredDeletionEventHandler.h:17
static CYIThreadHandle GetCurrentThreadId()
friend class CYIEventDispatcher
Definition: YiEventHandler.h:27
Definition: YiReadWriteMutex.h:14
Definition: YiSignalHandler.h:174
virtual void EventLoopExited(const std::shared_ptr< CYIEventDispatcher > &pDispatcher)=0
virtual void EventLoopStarted(const std::shared_ptr< CYIEventDispatcher > &pDispatcher)=0
bool PostFilter(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent)
virtual void EventPreFilteredByDispatcher(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent, CYIEventFilter *pFilter)=0
Handles events where tasks are executed when the event is processed on an event queue.
Definition: YiTaskEventHandler.h:15
Stores, queues and dispatches events as well as sending notifications to IYIEventDispatcherListener o...
Definition: YiEventDispatcher.h:65
A class used to block a thread until a condition is met, as signaled by a different thread...
Definition: YiWaitCondition.h:64
Allows children that inherit from this class to implement processing before and after events are hand...
Definition: YiEventFilter.h:24
bool UnregisterEventFilter(CYIEventFilter *pFilter)
void YiDeleteLater(std::unique_ptr< YI_TYPE > pPtr)
Adds the given pointer to the deferred deletion queue.
Definition: YiEventDispatcher.h:420
IYIEventDispatcherListener()
Definition: YiEventDispatcher.h:40
Implementors of this Listener interface can register themselves with the CYIEventDispather and become...
Definition: YiEventDispatcher.h:36
Definition: YiThreadHandle.h:43
virtual void EventPreFilteredByHandler(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent, CYIEventFilter *pFilter, CYIEventHandler *pHandler)=0
Proxy for a CYIEventHandler allowing safe destruction of the internal event handler objects...
Definition: YiEventHandlerProxy.h:26
CYIEventHandler & operator=(const CYIEventHandler &)
virtual void EventPostFilteredByDispatcher(const std::shared_ptr< CYIEventDispatcher > &pDispatcher, CYIEvent *pEvent, CYIEventFilter *pFilter)=0
Event for handling deferred deletion of data of type YI_TYPE. SfinaeHelper type is used to control a ...
Definition: YiDeferredDeletionEvent.h:30
Definition: YiEvent.h:475