PikeAero::CEventQueue Class Reference

#include <ceventqueue.h>

Collaboration diagram for PikeAero::CEventQueue:

Collaboration graph
[legend]

Static Public Member Functions

static CMachine::ubit32 deliveryCount ()
static void dequeue ()
 dispatch some events in the current task's time slice
static CMachine::ubit32 dequeueCount ()
static void enqueue (CEvent *e)
 enqueue an event for later dispatch. CEventQueue has event ownership and will delete it.
static CMachine::ubit32 enqueueCount ()
static void initialize ()
static void installListener (CObject *object, CEvent::Type type)
 install an event listener
static CMachine::ubit32 maxInQueue ()
static void removeListener (CObject *object, CEvent::Type type)
 remove an event listener
static void resetDeliveryCount ()
static void resetDequeueCount ()
static void resetEnqueueCount ()
static void resetMaxInQueue ()

Static Protected Member Functions

static void dispatch (CEvent *e)
 dispatch a particular event, CEventQueue has event ownership and will delete the event after dispatch

Static Private Attributes

static CMachine::ubit32 mDeliveryCount
static CMachine::ubit32 mDequeueCount
static CMachine::ubit32 mEnqueueCount
static CObjectQueuemEventQueue = NULL
static CObjectList ** mListenerMap = NULL
static CMachine::ubit32 mMaxInQueue

Detailed Description

Implements queueing and dispatching events.

Author:
Michael Sharkey <mike@pikeaero.com>

Definition at line 35 of file ceventqueue.h.


Member Function Documentation

static CMachine::ubit32 PikeAero::CEventQueue::deliveryCount (  )  [inline, static]

Definition at line 55 of file ceventqueue.h.

References mDeliveryCount.

Referenced by PikeAero::CTaskAggregator::perSecond().

00055 {return mDeliveryCount;}

Here is the caller graph for this function:

void PikeAero::CEventQueue::dequeue (  )  [static]

dispatch some events in the current task's time slice

Definition at line 70 of file ceventqueue.cpp.

References PikeAero::CObjectList::count(), PikeAero::CObjectQueue::dequeue(), dispatch(), mDequeueCount, mEventQueue, mMaxInQueue, and PikeAero::CMachine::resetWatchDog().

Referenced by PikeAero::CTaskSupervisor::run().

00071 {
00072     CMachine::bit32 count = mEventQueue->count();
00073     mMaxInQueue = (mMaxInQueue >= count) ? mMaxInQueue : count;
00074 
00075     while ( mEventQueue->count() )
00076     {
00077         CEvent* e = static_cast<CEvent*>(mEventQueue->dequeue());
00078         CMachine::resetWatchDog();
00079         ++mDequeueCount;
00080         dispatch( e );
00081     }
00082 }

Here is the call graph for this function:

Here is the caller graph for this function:

static CMachine::ubit32 PikeAero::CEventQueue::dequeueCount (  )  [inline, static]

Definition at line 52 of file ceventqueue.h.

References mDequeueCount.

Referenced by PikeAero::CTaskAggregator::perSecond().

00052 {return mDequeueCount;}

Here is the caller graph for this function:

void PikeAero::CEventQueue::dispatch ( CEvent e  )  [static, protected]

dispatch a particular event, CEventQueue has event ownership and will delete the event after dispatch

Event handler must not take ownership of the event object, but must make a copy if nessesary

then we delete the event object

Definition at line 111 of file ceventqueue.cpp.

References PikeAero::CObjectList::at(), PikeAero::CObjectList::count(), PikeAero::CObject::event(), mDeliveryCount, mListenerMap, and PikeAero::CMachine::resetWatchDog().

Referenced by dequeue().

00112 {
00113     CEvent::Type type = ((CEvent*)e)->type();
00114     CObjectList* list = static_cast<CObjectList*>(mListenerMap[type]);
00115     for ( CMachine::ubit32 n=0; n < list->count(); n++ )
00116     {
00117         /** Event handler must not take ownership of the event object, but must make a copy if nessesary */
00118         list->at(n)->event(e);
00119         ++mDeliveryCount;
00120         CMachine::resetWatchDog();
00121     }
00122     /** then we delete the event object */
00123     delete e;
00124 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CEventQueue::enqueue ( CEvent e  )  [static]

enqueue an event for later dispatch. CEventQueue has event ownership and will delete it.

public interface to atomic methods

Only enqueue the event if somebody is listening to it's type...

jump the queue - LIFO mode

TODO - load testing required. test threshold where flooding hi priority events begins to starve the queue.

normal/low priority - FIFO mode.

Definition at line 85 of file ceventqueue.cpp.

References PikeAero::CObjectList::append(), PikeAero::CObjectList::count(), PikeAero::CObjectList::insert(), mEnqueueCount, mEventQueue, mListenerMap, PikeAero::CEvent::PriorityHigh, and PikeAero::CEvent::type().

Referenced by PikeAero::CObject::dispatch().

00086 {
00087     /** Only enqueue the event if somebody is listening to it's type... */
00088     CObjectList* list = static_cast<CObjectList*>(mListenerMap[e->type()]);
00089     if ( list->count() > 0 )
00090     {
00091         ++mEnqueueCount;
00092         if ( ((CEvent*)e)->priority() == CEvent::PriorityHigh )
00093         {
00094             /** jump the queue - LIFO mode */
00095             /** TODO - load testing required. test threshold where flooding hi priority events begins to starve the queue. */
00096             mEventQueue->insert(e,0);
00097         }
00098         else
00099         {
00100             /** normal/low priority - FIFO mode. */
00101             mEventQueue->append(e);
00102         }
00103     }
00104     else
00105     {
00106         delete e;
00107     }
00108 }

Here is the call graph for this function:

Here is the caller graph for this function:

static CMachine::ubit32 PikeAero::CEventQueue::enqueueCount (  )  [inline, static]

Definition at line 49 of file ceventqueue.h.

References mEnqueueCount.

Referenced by PikeAero::CTaskAggregator::perSecond().

00049 {return mEnqueueCount;}

Here is the caller graph for this function:

void PikeAero::CEventQueue::initialize (  )  [static]

perform CEventQueue initialization

initialize the event queue

initialize the listeners - allocate a table to the size of the maximum event type enumerator

instantiate an object list for each event type

Definition at line 37 of file ceventqueue.cpp.

References PikeAero::CMemHeap::malloc(), PikeAero::CEvent::Maximum, mDeliveryCount, mDequeueCount, mEnqueueCount, mEventQueue, mListenerMap, and mMaxInQueue.

Referenced by main().

00038 {
00039     mMaxInQueue = 0;
00040     mEnqueueCount = 0;
00041     mDequeueCount = 0;
00042     mDeliveryCount = 0;
00043 
00044     /** initialize the event queue */
00045     mEventQueue = new CObjectQueue();
00046     /** initialize the listeners - allocate a table to the size of the maximum event type enumerator */
00047     mListenerMap=static_cast<CObjectList**>(CMemHeap::malloc( sizeof(CObjectList*) * CEvent::Maximum ));
00048     for ( int n=0; n < (int)CEvent::Maximum; n++ )
00049     {
00050         /** instantiate an object list for each event type */
00051         mListenerMap[n] = new CObjectList();
00052     }
00053 }

Here is the call graph for this function:

Here is the caller graph for this function:

void PikeAero::CEventQueue::installListener ( CObject object,
CEvent::Type  type 
) [static]

install an event listener

TODO - need a mutex here?

Definition at line 56 of file ceventqueue.cpp.

References PikeAero::CObjectList::append(), and mListenerMap.

Referenced by PikeAero::CCommunicationPacket::CCommunicationPacket(), PikeAero::CTaskFuelPressureMonitor::start(), PikeAero::CTaskFuelInjection::start(), PikeAero::CTaskConsoleBase::start(), PikeAero::CTaskAnalogInputADC::start(), and PikeAero::CTaskAggregator::start().

00057 {
00058     /** TODO - need a mutex here? */
00059     mListenerMap[type]->append( object );
00060 }

Here is the call graph for this function:

Here is the caller graph for this function:

static CMachine::ubit32 PikeAero::CEventQueue::maxInQueue (  )  [inline, static]

Definition at line 46 of file ceventqueue.h.

References mMaxInQueue.

Referenced by PikeAero::CTaskAggregator::perSecond().

00046 {return mMaxInQueue;}

Here is the caller graph for this function:

void PikeAero::CEventQueue::removeListener ( CObject object,
CEvent::Type  type 
) [static]

remove an event listener

TODO - need a mutex here?

Definition at line 63 of file ceventqueue.cpp.

References mListenerMap, and PikeAero::CObjectList::remove().

Referenced by PikeAero::CTaskSupervisor::stop(), PikeAero::CTaskFuelInjection::stop(), PikeAero::CTaskConsoleBase::stop(), PikeAero::CTaskAggregator::stop(), PikeAero::CCommunicationPacket::~CCommunicationPacket(), PikeAero::CTaskAnalogInputADC::~CTaskAnalogInputADC(), and PikeAero::CTaskFuelPressureMonitor::~CTaskFuelPressureMonitor().

00064 {
00065     /** TODO - need a mutex here? */
00066     mListenerMap[type]->remove( object );
00067 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void PikeAero::CEventQueue::resetDeliveryCount (  )  [inline, static]

Definition at line 56 of file ceventqueue.h.

References mDeliveryCount.

Referenced by PikeAero::CTaskAggregator::perSecond().

00056 {mDeliveryCount=0;}

Here is the caller graph for this function:

static void PikeAero::CEventQueue::resetDequeueCount (  )  [inline, static]

Definition at line 53 of file ceventqueue.h.

References mDequeueCount.

Referenced by PikeAero::CTaskAggregator::perSecond().

00053 {mDequeueCount=0;}

Here is the caller graph for this function:

static void PikeAero::CEventQueue::resetEnqueueCount (  )  [inline, static]

Definition at line 50 of file ceventqueue.h.

References mEnqueueCount.

Referenced by PikeAero::CTaskAggregator::perSecond().

00050 {mEnqueueCount=0;}

Here is the caller graph for this function:

static void PikeAero::CEventQueue::resetMaxInQueue (  )  [inline, static]

Definition at line 47 of file ceventqueue.h.

References mMaxInQueue.

Referenced by PikeAero::CTaskAggregator::perSecond().

00047 {mMaxInQueue=0;}

Here is the caller graph for this function:


Field Documentation

Definition at line 65 of file ceventqueue.h.

Referenced by deliveryCount(), dispatch(), initialize(), and resetDeliveryCount().

Definition at line 64 of file ceventqueue.h.

Referenced by dequeue(), dequeueCount(), initialize(), and resetDequeueCount().

Definition at line 63 of file ceventqueue.h.

Referenced by enqueue(), enqueueCount(), initialize(), and resetEnqueueCount().

Definition at line 66 of file ceventqueue.h.

Referenced by dequeue(), enqueue(), and initialize().

CObjectList ** PikeAero::CEventQueue::mListenerMap = NULL [static, private]

Definition at line 67 of file ceventqueue.h.

Referenced by dispatch(), enqueue(), initialize(), installListener(), and removeListener().

Definition at line 62 of file ceventqueue.h.

Referenced by dequeue(), initialize(), maxInQueue(), and resetMaxInQueue().


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

Generated on Sun Oct 25 14:00:03 2009 for stingray3 by  doxygen 1.5.8