You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.9 KiB
71 lines
1.9 KiB
#include "basicEventHeap.h"
|
|
|
|
#define LOG( X ) m_pLog->Log( "basicEventHeap", this, X )
|
|
#define LOG_ERROR( X ) m_pLog->Log( "basicEventHeap", this, _LOG_ERROR, X )
|
|
|
|
basicEventHeap* basicEventHeap::_instance = 0;
|
|
|
|
/**
|
|
* Returns the single instance of the object.
|
|
*/
|
|
basicEventHeap* basicEventHeap::getInstance() {
|
|
// check if the instance has been created yet
|
|
if (0 == _instance) {
|
|
// if not, then create it
|
|
_instance = new basicEventHeap;
|
|
}
|
|
// return the single instance
|
|
return _instance;
|
|
};
|
|
|
|
void basicEventHeap::addHandler( basicEventHandler *handler ){
|
|
if( m_pRing != NULL ) m_pRing->add( handler );
|
|
};
|
|
|
|
void basicEventHeap::removeHandler( basicEventHandler *handler ){
|
|
if( m_pRing != NULL && handler != NULL ) m_pRing->removePtr( handler );
|
|
};
|
|
|
|
void basicEventHeap::m_fThreadProc( void ){
|
|
basicEventHandler *mpHandler;
|
|
basicEvent *mpEvent;
|
|
EventHandlerIterator *mpIterator;
|
|
m_bThreadStatus = TH_WORKING;
|
|
while( m_bThreadStatus < TH_ENDED ){
|
|
if( m_bThreadStatus == TH_SLIPS ){
|
|
SLEEP( 10 );
|
|
};
|
|
if( m_bThreadStatus == TH_WORKING ){
|
|
mpEvent = NULL;
|
|
m_pDispatchingMutex->lock();
|
|
if (!m_vEventQueue.empty()){
|
|
mpEvent = m_vEventQueue.front();
|
|
m_vEventQueue.pop();
|
|
};
|
|
m_pDispatchingMutex->unlock();
|
|
if( mpEvent!= NULL ){
|
|
m_pHandlerMutex->lock();
|
|
mpIterator = m_pRing->begin();
|
|
while( mpIterator != NULL ){
|
|
mpHandler = m_pRing->getAtCursor( mpIterator );
|
|
if( mpHandler != NULL ) {
|
|
mpHandler->dispatchEvent( mpEvent );
|
|
};
|
|
mpIterator = mpIterator->next;
|
|
};
|
|
m_pHandlerMutex->unlock();
|
|
utilizeBasicEvent( mpEvent );
|
|
} else SLEEP(3);
|
|
};
|
|
};
|
|
};
|
|
|
|
void basicEventHeap::broadcast( basicEvent *Evt ){
|
|
m_pDispatchingMutex->lock();
|
|
m_vEventQueue.push( Evt );
|
|
m_pDispatchingMutex->unlock();
|
|
};
|
|
|
|
#undef LOG
|
|
#undef LOG_ERROR
|
|
|