Event queue. More...
#include <CEventQueue.h>
Inherits IEventQueue.
Classes | |
class | CTimer |
Public Member Functions | |
virtual void | adoptBuffer (IEventQueueBuffer *) |
Set the buffer. | |
virtual bool | getEvent (CEvent &event, double timeout=-1.0) |
Remove event from queue. | |
virtual bool | dispatchEvent (const CEvent &event) |
Dispatch an event. | |
virtual void | addEvent (const CEvent &event) |
Add event to queue. | |
virtual CEventQueueTimer * | newTimer (double duration, void *target) |
Create a recurring timer. | |
virtual CEventQueueTimer * | newOneShotTimer (double duration, void *target) |
Create a one-shot timer. | |
virtual void | deleteTimer (CEventQueueTimer *) |
Destroy a timer. | |
virtual void | adoptHandler (CEvent::Type type, void *target, IEventJob *handler) |
Register an event handler for an event type. | |
virtual void | removeHandler (CEvent::Type type, void *target) |
Unregister an event handler for an event type. | |
virtual void | removeHandlers (void *target) |
Unregister all event handlers for an event target. | |
virtual CEvent::Type | registerType (const char *name) |
Creates a new event type. | |
virtual CEvent::Type | registerTypeOnce (CEvent::Type &type, const char *name) |
Creates a new event type. | |
virtual bool | isEmpty () const |
Test if queue is empty. | |
virtual IEventJob * | getHandler (CEvent::Type type, void *target) const |
Get an event handler. | |
virtual const char * | getTypeName (CEvent::Type type) |
Get name for event. |
Event queue.
An event queue that implements the platform independent parts and delegates the platform dependent parts to a subclass.
Definition at line 31 of file CEventQueue.h.
void CEventQueue::addEvent | ( | const CEvent & | event | ) | [virtual] |
Add event to queue.
Adds event
to the end of the queue.
Implements IEventQueue.
Definition at line 197 of file CEventQueue.cpp.
References IEventQueueBuffer::addEvent(), CEvent::deleteData(), dispatchEvent(), CEvent::getFlags(), CEvent::getType(), CEvent::kDeliverImmediately, CEvent::kSystem, CEvent::kTimer, and CEvent::kUnknown.
void CEventQueue::adoptBuffer | ( | IEventQueueBuffer * | ) | [virtual] |
Set the buffer.
Replace the current event queue buffer. Any queued events are discarded. The queue takes ownership of the buffer.
Implements IEventQueue.
Definition at line 103 of file CEventQueue.cpp.
References CEvent::deleteData().
void CEventQueue::adoptHandler | ( | CEvent::Type | type, | |
void * | target, | |||
IEventJob * | handler | |||
) | [virtual] |
Register an event handler for an event type.
Registers an event handler for type
and target
. The handler
is adopted. Any existing handler for the type,target pair is deleted. dispatchEvent()
will invoke handler
for any event for target
of type type
. If no such handler exists it will use the handler for target
and type kUnknown
if it exists.
Implements IEventQueue.
Definition at line 286 of file CEventQueue.cpp.
void CEventQueue::deleteTimer | ( | CEventQueueTimer * | ) | [virtual] |
Destroy a timer.
Destroys a previously created timer. The timer is removed from the queue and will not generate event, even if the timer has expired.
Implements IEventQueue.
Definition at line 268 of file CEventQueue.cpp.
References CPriorityQueue< T, Container, Compare >::begin(), IEventQueueBuffer::deleteTimer(), CPriorityQueue< T, Container, Compare >::end(), and CPriorityQueue< T, Container, Compare >::erase().
bool CEventQueue::dispatchEvent | ( | const CEvent & | event | ) | [virtual] |
Dispatch an event.
Looks up the dispatcher for the event's target and invokes it. Returns true iff a dispatcher exists for the target.
Implements IEventQueue.
Definition at line 182 of file CEventQueue.cpp.
References getHandler(), CEvent::getType(), CEvent::kUnknown, and IEventJob::run().
Referenced by addEvent().
bool CEventQueue::getEvent | ( | CEvent & | event, | |
double | timeout = -1.0 | |||
) | [virtual] |
Remove event from queue.
Returns the next event on the queue into event
. If no event is available then blocks for up to timeout
seconds, or forever if timeout
is negative. Returns true iff an event was available.
Implements IEventQueue.
Definition at line 123 of file CEventQueue.cpp.
References IEventQueueBuffer::getEvent(), CStopwatch::getTime(), IEventQueueBuffer::isEmpty(), IEventQueueBuffer::kNone, IEventQueueBuffer::kSystem, IEventQueueBuffer::kUser, and IEventQueueBuffer::waitForEvent().
IEventJob * CEventQueue::getHandler | ( | CEvent::Type | type, | |
void * | target | |||
) | const [virtual] |
Get an event handler.
Finds and returns the event handler for the type
, target
pair if it exists, otherwise it returns NULL.
Implements IEventQueue.
Definition at line 345 of file CEventQueue.cpp.
Referenced by dispatchEvent().
const char * CEventQueue::getTypeName | ( | CEvent::Type | type | ) | [virtual] |
Get name for event.
Returns the name for the event type
. This is primarily for debugging.
Implements IEventQueue.
Definition at line 76 of file CEventQueue.cpp.
References CEvent::kQuit, CEvent::kSystem, CEvent::kTimer, and CEvent::kUnknown.
bool CEventQueue::isEmpty | ( | ) | const [virtual] |
Test if queue is empty.
Returns true iff the queue has no events in it, including timer events.
Implements IEventQueue.
Definition at line 339 of file CEventQueue.cpp.
References IEventQueueBuffer::isEmpty().
CEventQueueTimer * CEventQueue::newOneShotTimer | ( | double | duration, | |
void * | target | |||
) | [virtual] |
Create a one-shot timer.
Creates and returns a one-shot timer. An event is returned when the timer expires and the timer is removed from further handling. When a timer event is returned the data points to a CTimerEvent
. The c_count member of the CTimerEvent
is always 1. The client must pass the returned timer to deleteTimer()
(whether or not the timer has expired) to release the timer. The returned timer event uses the given target
. If target
is NULL it uses the returned timer as the target.
Implements IEventQueue.
Definition at line 249 of file CEventQueue.cpp.
References CStopwatch::getTime(), IEventQueueBuffer::newTimer(), and CPriorityQueue< T, Container, Compare >::push().
CEventQueueTimer * CEventQueue::newTimer | ( | double | duration, | |
void * | target | |||
) | [virtual] |
Create a recurring timer.
Creates and returns a timer. An event is returned after duration
seconds and the timer is reset to countdown again. When a timer event is returned the data points to a CTimerEvent
. The client must pass the returned timer to deleteTimer()
(whether or not the timer has expired) to release the timer. The returned timer event uses the given target
. If target
is NULL it uses the returned timer as the target.
Events for a single timer don't accumulate in the queue, even if the client reading events can't keep up. Instead, the m_count
member of the CTimerEvent
indicates how many events for the timer would have been put on the queue since the last event for the timer was removed (or since the timer was added).
Implements IEventQueue.
Definition at line 230 of file CEventQueue.cpp.
References CStopwatch::getTime(), IEventQueueBuffer::newTimer(), and CPriorityQueue< T, Container, Compare >::push().
CEvent::Type CEventQueue::registerType | ( | const char * | name | ) | [virtual] |
Creates a new event type.
Returns a unique event type id.
Implements IEventQueue.
Definition at line 55 of file CEventQueue.cpp.
CEvent::Type CEventQueue::registerTypeOnce | ( | CEvent::Type & | type, | |
const char * | name | |||
) | [virtual] |
Creates a new event type.
If type
contains kUnknown
then it is set to a unique event type id otherwise it is left alone. The final value of type
is returned.
Implements IEventQueue.
Definition at line 64 of file CEventQueue.cpp.
References CEvent::kUnknown.
void CEventQueue::removeHandler | ( | CEvent::Type | type, | |
void * | target | |||
) | [virtual] |
Unregister an event handler for an event type.
Unregisters an event handler for the type
, target
pair and deletes it.
Implements IEventQueue.
Definition at line 295 of file CEventQueue.cpp.
void CEventQueue::removeHandlers | ( | void * | target | ) | [virtual] |
Unregister all event handlers for an event target.
Unregisters all event handlers for the target
and deletes them.
Implements IEventQueue.
Definition at line 314 of file CEventQueue.cpp.