Classes | Public Member Functions

CEventQueue Class Reference

Event queue. More...

#include <CEventQueue.h>

Inherits IEventQueue.

List of all members.

Classes

class  CTimer

Public Member Functions

virtual void loop ()
 Loop the event queue until quit.
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 CEventQueueTimernewTimer (double duration, void *target)
 Create a recurring timer.
virtual CEventQueueTimernewOneShotTimer (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 IEventJobgetHandler (CEvent::Type type, void *target) const
 Get an event handler.
virtual const char * getTypeName (CEvent::Type type)
 Get name for event.
virtual CEvent::Type getRegisteredType (const CString &name) const
 Get an event type by name.

Detailed Description

Event queue.

An event queue that implements the platform independent parts and delegates the platform dependent parts to a subclass.

Definition at line 35 of file CEventQueue.h.


Member Function Documentation

void CEventQueue::addEvent ( const CEvent event  )  [virtual]

Add event to queue.

Adds event to the end of the queue.

Implements IEventQueue.

Definition at line 223 of file CEventQueue.cpp.

References IEventQueueBuffer::addEvent(), CEvent::deleteData(), dispatchEvent(), CEvent::getFlags(), CEvent::getType(), 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 121 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 312 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 294 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 208 of file CEventQueue.cpp.

References getHandler(), CEvent::getType(), CEvent::kUnknown, and IEventJob::run().

Referenced by addEvent(), and loop().

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 149 of file CEventQueue.cpp.

References IEventQueueBuffer::getEvent(), CStopwatch::getTime(), IEventQueueBuffer::isEmpty(), IEventQueueBuffer::kNone, IEventQueueBuffer::kSystem, IEventQueueBuffer::kUser, and IEventQueueBuffer::waitForEvent().

Referenced by loop().

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 371 of file CEventQueue.cpp.

Referenced by dispatchEvent().

CEvent::Type CEventQueue::getRegisteredType ( const CString &  name  )  const [virtual]

Get an event type by name.

Returns the registered type for an event for a given name.

Implements IEventQueue.

Definition at line 482 of file CEventQueue.cpp.

References CEvent::kUnknown.

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 94 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 365 of file CEventQueue.cpp.

References IEventQueueBuffer::isEmpty().

void CEventQueue::loop (  )  [virtual]

Loop the event queue until quit.

Dequeues and dispatches events until the kQuit event is found.

Implements IEventQueue.

Definition at line 59 of file CEventQueue.cpp.

References CEvent::deleteData(), dispatchEvent(), getEvent(), and CEvent::getType().

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 275 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 256 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 71 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 81 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 321 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 340 of file CEventQueue.cpp.


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