You.i Engine
CYIEventDispatcher Class Reference

Detailed Description

Stores, queues and dispatches events as well as sending notifications to IYIEventDispatcherListener objects regarding different actions being taken on the events.

#include <event/YiEventDispatcher.h>

Inheritance diagram for CYIEventDispatcher:

Public Member Functions

 CYIEventDispatcher ()
 
virtual ~CYIEventDispatcher ()
 
bool Start ()
 
bool Exit (bool bJoin=false, bool bWaitUntilEmpty=false)
 
void WaitUntilEventQueueRunning ()
 
bool WaitUntilEventPosted (uint64_t uTimeoutMs=0)
 
bool ProcessOneEvent ()
 
bool ProcessAllEvents ()
 
bool ProcessAllEvents (uint64_t uTimeoutUs)
 
bool RegisterEventHandler (CYIEventHandler *pEventHandler)
 
bool UnregisterEventHandler (CYIEventHandler *pEventHandler)
 
bool RegisterEventFilter (CYIEventFilter *pEventFilter)
 
bool UnregisterEventFilter (CYIEventFilter *pEventFilter)
 
bool RegisterEventDispatcherListener (IYIEventDispatcherListener *pEventDispatcherListener)
 
bool UnregisterEventDispatcherListener (IYIEventDispatcherListener *pEventDispatcherListener)
 
bool PostEvent (std::unique_ptr< CYIEvent > pEvent, YI_EVENT_PRIORITY priority=YI_EVENT_PRIORITY_DEFAULT, bool bBump=false)
 
bool PostEvent (std::unique_ptr< CYIEvent > pEvent, CYIEventHandler *pDestination, YI_EVENT_PRIORITY priority=YI_EVENT_PRIORITY_DEFAULT, bool bBump=false)
 
bool PostUniqueEvent (std::unique_ptr< CYIEvent > pEvent, YI_EVENT_PRIORITY priority=YI_EVENT_PRIORITY_DEFAULT)
 
bool PostUniqueEvent (std::unique_ptr< CYIEvent > pEvent, CYIEventHandler *pDestination, YI_EVENT_PRIORITY priority=YI_EVENT_PRIORITY_DEFAULT)
 
bool SendEvent (std::unique_ptr< CYIEvent > pEvent)
 
bool SendEvent (std::unique_ptr< CYIEvent > pEvent, CYIEventHandler *pDestination)
 
int32_t GetEventCount () const
 
void Shutdown ()
 
void DiscardAllPosts ()
 
void DiscardPosts (CYIEventHandler *pDestination)
 
void DiscardPostsIf (bool(*predicate)(const std::shared_ptr< CYIEventDispatcher > &, CYIEvent *, CYIEventHandler *, YI_EVENT_PRIORITY))
 
CYIEventHandlerGetSignalEmitEventHandler ()
 
CYIEventHandlerGetDeferredDeletionEventHandler ()
 
CYIEventHandlerGetTaskEventHandler ()
 
- Public Member Functions inherited from CYISignalHandler
 CYISignalHandler ()
 
 CYISignalHandler (const CYISignalHandler &rSignalHandler)
 
virtual ~CYISignalHandler ()
 
CYISignalHandleroperator= (const CYISignalHandler &rSignalHandler)
 
void MoveToThread (CYIThread *pThread)
 This function allows the user to override the default thread affinity to any CYIThread that may or may not be running. More...
 
CYIThreadHandle GetThreadAffinity () const
 
void SetThreadAffinity (const CYIThreadHandle &rThreadAffinity)
 
virtual bool IsConnected () const
 
virtual bool IsConnected (const CYISignalBase &rSignal) const
 
void Disconnect (CYISignalBase &rSignal)
 
void DisconnectFromAllSignals ()
 
- Public Member Functions inherited from CYIThread::Listener
 Listener ()
 
virtual ~Listener ()
 
virtual void OnThreadStarted (CYIThread *)
 
virtual void OnThreadTerminated (CYIThread *)
 
virtual void OnThreadFinished (CYIThread *)
 
- Public Member Functions inherited from CYIScriptableObject
 CYIScriptableObject ()
 
 CYIScriptableObject (const CYIScriptableObject &other)
 
CYIScriptableObjectoperator= (const CYIScriptableObject &other)
 
virtual ~CYIScriptableObject ()
 
CYIBindingImplementationGetBindingImplementation () const
 
void SetBindingImplementation (CYIBindingImplementation *pBindingImplementation)
 
virtual const CYIRuntimeTypeInfoGetRuntimeTypeInfoForScriptObject () const
 

Static Public Member Functions

static std::shared_ptr< CYIEventDispatcherGetDispatcher (const CYIThreadHandle &threadAffinity)
 
static const std::shared_ptr< CYIEventDispatcher > & GetDefaultDispatcher ()
 
static const CYIThreadHandleGetDefaultDispatcherThreadAffinity ()
 
static const std::shared_ptr< CYIEventDispatcher > & GetDrawDispatcher ()
 
static void SetDispatcher (const CYIThreadHandle &threadAffinity, const std::shared_ptr< CYIEventDispatcher > &pDispatcher)
 
static void RemoveDispatcher (const CYIThreadHandle &threadAffinity)
 
static void SetDefaultDispatcher (const std::shared_ptr< CYIEventDispatcher > &pDispatcher)
 
static void RemoveDefaultDispatcher ()
 
static void SetDrawDispatcher (const std::shared_ptr< CYIEventDispatcher > &pDispatcher)
 
static void RemoveDrawDispatcher ()
 

Friends

class CYIEventHandler
 

Constructor & Destructor Documentation

CYIEventDispatcher::CYIEventDispatcher ( )
virtual CYIEventDispatcher::~CYIEventDispatcher ( )
virtual

Member Function Documentation

void CYIEventDispatcher::DiscardAllPosts ( )

Clears the event queue and deletes each item.

void CYIEventDispatcher::DiscardPosts ( CYIEventHandler pDestination)

Deletes each item in the queue that belongs to pDestination.

void CYIEventDispatcher::DiscardPostsIf ( bool(*)(const std::shared_ptr< CYIEventDispatcher > &, CYIEvent *, CYIEventHandler *, YI_EVENT_PRIORITY predicate)

Deletes each item in the queue if the predicate for that event returns true.

bool CYIEventDispatcher::Exit ( bool  bJoin = false,
bool  bWaitUntilEmpty = false 
)

Stops the event queue.

If bJoin is true, wait for the thread to exit.

If bWaitUntilEmpty is true, wait for the queue to be empty before stopping.

static const std::shared_ptr<CYIEventDispatcher>& CYIEventDispatcher::GetDefaultDispatcher ( )
static

Returns the default CYIEventDispatcher.

static const CYIThreadHandle& CYIEventDispatcher::GetDefaultDispatcherThreadAffinity ( )
static

Returns the CYIThreadHandle of the default dispatcher.

CYIEventHandler* CYIEventDispatcher::GetDeferredDeletionEventHandler ( )

Returns the current CYIDeferredDeletionEventHandler.

static std::shared_ptr<CYIEventDispatcher> CYIEventDispatcher::GetDispatcher ( const CYIThreadHandle threadAffinity)
static

Returns the CYIEventDispatcher belonging to threadAffinity.

static const std::shared_ptr<CYIEventDispatcher>& CYIEventDispatcher::GetDrawDispatcher ( )
static

Returns the current draw dispatcher for drawing hardware-mirrored assets.

See also
CYIAssetHardware
int32_t CYIEventDispatcher::GetEventCount ( ) const

Returns the number of events in the queue.

CYIEventHandler* CYIEventDispatcher::GetSignalEmitEventHandler ( )

Returns the current CYISignalEmitEventHandler.

CYIEventHandler* CYIEventDispatcher::GetTaskEventHandler ( )

Returns the current CYITaskEventHandler.

bool CYIEventDispatcher::PostEvent ( std::unique_ptr< CYIEvent pEvent,
YI_EVENT_PRIORITY  priority = YI_EVENT_PRIORITY_DEFAULT,
bool  bBump = false 
)

Adds the event to the event queue with YI_EVENT_PRIORITY priority.

If bBump is true, then push it to the top of the queue. Otherwise queue it normally.

bool CYIEventDispatcher::PostEvent ( std::unique_ptr< CYIEvent pEvent,
CYIEventHandler pDestination,
YI_EVENT_PRIORITY  priority = YI_EVENT_PRIORITY_DEFAULT,
bool  bBump = false 
)

Adds both pEvent and pDestination to the event queue.

bool CYIEventDispatcher::PostUniqueEvent ( std::unique_ptr< CYIEvent pEvent,
YI_EVENT_PRIORITY  priority = YI_EVENT_PRIORITY_DEFAULT 
)

Adds the event to the event queue with the YI_EVENT_PRIORITY priority and deletes all previous instances of the event type.

bool CYIEventDispatcher::PostUniqueEvent ( std::unique_ptr< CYIEvent pEvent,
CYIEventHandler pDestination,
YI_EVENT_PRIORITY  priority = YI_EVENT_PRIORITY_DEFAULT 
)

Adds the event to the event queue with the YI_EVENT_PRIORITY priority and deletes all previous instances of the event type.

If pDestination is specified, then it gets stored in the queue along with the pEvent.

bool CYIEventDispatcher::ProcessAllEvents ( )

Processes all events in the queue.

Returns true if there are items in the queue and the processing action is successful and false otherwise.

bool CYIEventDispatcher::ProcessAllEvents ( uint64_t  uTimeoutUs)

Similar to ProcessAllEvents() but it adds the uTimeoutUs parameter which will limit the time processing the events.

bool CYIEventDispatcher::ProcessOneEvent ( )

Processes the first event in the queue if the queue is not empty.

Returns true if there are items in the queue and the processing action is successful and false otherwise.

bool CYIEventDispatcher::RegisterEventDispatcherListener ( IYIEventDispatcherListener pEventDispatcherListener)

Adds pEventDispatcherListener to the list of event dispatch listeners.

Warning
Registering an event dispatcher listener inside of any of the listener's methods is unsupported and will cause deadlock.
bool CYIEventDispatcher::RegisterEventFilter ( CYIEventFilter pEventFilter)

Adds pEventFilter to the list of event filters.

Note
The event dispatcher does not take ownership of pEventFilter.
Warning
Registering an event filter inside of the following methods is unsupported and will cause deadlock:
static void CYIEventDispatcher::RemoveDefaultDispatcher ( )
static

Clears the default event dispatcher.

static void CYIEventDispatcher::RemoveDispatcher ( const CYIThreadHandle threadAffinity)
static

Removes the event dispatcher which belongs to threadAffinity.

static void CYIEventDispatcher::RemoveDrawDispatcher ( )
static

Clears the default draw event dispatcher.

bool CYIEventDispatcher::SendEvent ( std::unique_ptr< CYIEvent pEvent,
CYIEventHandler pDestination 
)

Immediately dispatches the event.

If pDestination is specified, then it gets dispatched along with the pEvent.

Warning
Calling this variation of send event inside of the following methods is only supported if pDestination is non-null.

The event may be posted instead.

See also
PostEvent
static void CYIEventDispatcher::SetDefaultDispatcher ( const std::shared_ptr< CYIEventDispatcher > &  pDispatcher)
static

Sets the default event dispatcher to pDispatcher.

static void CYIEventDispatcher::SetDispatcher ( const CYIThreadHandle threadAffinity,
const std::shared_ptr< CYIEventDispatcher > &  pDispatcher 
)
static

Sets the event dispatcher belonging to threadAffinity to pDispatcher.

static void CYIEventDispatcher::SetDrawDispatcher ( const std::shared_ptr< CYIEventDispatcher > &  pDispatcher)
static

Sets the default draw event dispatcher to pDispatcher.

void CYIEventDispatcher::Shutdown ( )

Clears the events from the dispatcher.

Note
Console platforms (i.e Xbox, Playstation) restrictions require events to be purged from the queue without processing. In all other cases, all events are immediately processed.
bool CYIEventDispatcher::Start ( )

Starts the event loop and event queue.

bool CYIEventDispatcher::UnregisterEventDispatcherListener ( IYIEventDispatcherListener pEventDispatcherListener)

Removes pEventDispatcherListener from the list of event dispatch listeners.

Warning
Unregistering an event dispatcher listener inside of any of the listener's methods is unsupported and will cause deadlock.
bool CYIEventDispatcher::UnregisterEventFilter ( CYIEventFilter pEventFilter)

Removes pEventFilter from the list of event filters.

Warning
Unregistering an event filter inside of the following methods is unsupported and will cause deadlock:
bool CYIEventDispatcher::WaitUntilEventPosted ( uint64_t  uTimeoutMs = 0)

Blocks until an event has been posted to the queue or times out after uTimeoutMs milliseconds.

The default value 0, represents no timeout. Returns true if the wait timed out.

See also
PostEvent
PostUniqueEvent
void CYIEventDispatcher::WaitUntilEventQueueRunning ( )

If the event queue is not running, blocks here until the event queue starts up.

Friends And Related Function Documentation

friend class CYIEventHandler
friend

The documentation for this class was generated from the following file: