EpcTools
An event based multi-threaded C++ development framework.
Public Member Functions | Protected Member Functions | Friends | List of all members
EThreadEventWorker< TQueue, TMessage > Class Template Reference

Represents a worker thread that is part of a work group. More...

#include <etevent.h>

Inheritance diagram for EThreadEventWorker< TQueue, TMessage >:
EThreadBasic PFCP::ApplicationWorker

Public Member Functions

Int workerId () const
 
virtual Void onInit ()
 Called in the context of the thread prior to processing teh first event message. More...
 
virtual Void onQuit ()
 Called in the context of the thread when the EM_QUIT event is processed. More...
 
virtual Void onTimer (EThreadEventTimer *ptimer)
 Called in the context of the thread when th EM_TIMER event is processed. More...
 
ESemaphoreDatagetMsgSemaphore ()
 Returns the semaphore associated with this work groups' event queue. More...
 
Bool sendMessage (UInt message, Bool wait=True)
 Sends event message to this work group. More...
 
Bool sendMessage (UInt message, pVoid voidptr, Bool wait=True)
 Sends event message to this work group. More...
 
Bool sendMessage (const TMessage &msg, Bool wait=True)
 Sends event message to this work group. More...
 
- Public Member Functions inherited from EThreadBasic
 EThreadBasic ()
 Class constructor. More...
 
virtual ~EThreadBasic ()
 Class destructor. More...
 
Void init (pVoid arg, size_t stackSize=0)
 Initialize and start the thread. More...
 
Void join ()
 Waits for the thread to terminate. More...
 
Bool isInitialized ()
 Returns the thread initialization state. More...
 
RunState getRunState ()
 Returns the current thread run state. More...
 
Bool isWaitingToRun ()
 Determines if the thread is waiting to run. More...
 
Bool isRunning ()
 Determines if the thread is running. More...
 
Bool isDoneRunning ()
 Determines if the thread has finished running. More...
 
Int cancelWait ()
 Sends a cancellation request to the thread. More...
 
Void signal (Int sig)
 

Protected Member Functions

 EThreadEventWorker ()
 Default class constructor. More...
 
 ~EThreadEventWorker ()
 The class destructor. More...
 
virtual Void onMessageQueued (const TMessage &msg)
 Called when an event message is queued. More...
 
virtual Void init (TQueue &queue, Int workerid, pVoid arg, Dword stackSize=0)
 Initializes the thread object. More...
 
Void start ()
 Initializes the thread when it was suspended at init(). More...
 
Bool pumpMessage (TMessage &msg, Bool wait=true)
 Dispatches the next thread event message. More...
 
virtual Void pumpMessages ()
 Process event messages. More...
 
virtual Void defaultMessageHandler (TMessage &msg)
 The default event message handler. More...
 
pid_t getThreadId ()
 Retrieves the internal thread ID. More...
 

Friends

template<class T1 , class T2 , class T3 >
class EThreadEventWorkGroup
 

Additional Inherited Members

- Public Types inherited from EThreadBasic
enum  RunState { rsWaitingToRun, rsRunning, rsDoneRunning }
 EThreadBasic run states. More...
 
- Static Public Member Functions inherited from EThreadBasic
static Void sleep (Int milliseconds)
 Sleeps for the specified number of milliseconds. More...
 
static Void yield ()
 Relinquishes the CPU. More...
 
- Static Protected Member Functions inherited from EThreadBasic
static Void Initialize ()
 performs internal initialization *** DO NOT CALL *** More...
 
static Void UnInitialize ()
 performs internal de-initialization *** DO NOT CALL *** More...
 

Detailed Description

template<class TQueue, class TMessage>
class EThreadEventWorker< TQueue, TMessage >

Represents a worker thread that is part of a work group.

Constructor & Destructor Documentation

template<class TQueue, class TMessage>
EThreadEventWorker< TQueue, TMessage >::EThreadEventWorker ( )
inlineprotected

Default class constructor.

template<class TQueue, class TMessage>
EThreadEventWorker< TQueue, TMessage >::~EThreadEventWorker ( )
inlineprotected

The class destructor.

Member Function Documentation

template<class TQueue, class TMessage>
virtual Void EThreadEventWorker< TQueue, TMessage >::defaultMessageHandler ( TMessage &  msg)
inlineprotectedvirtual

The default event message handler.

Parameters
msgthe EThreadMessage event object

This method is called when no event handler has been defined in the class heirarchy for a specified thread event.

template<class TQueue, class TMessage>
ESemaphoreData& EThreadEventWorker< TQueue, TMessage >::getMsgSemaphore ( )
inline

Returns the semaphore associated with this work groups' event queue.

template<class TQueue, class TMessage>
pid_t EThreadEventWorker< TQueue, TMessage >::getThreadId ( )
inlineprotected

Retrieves the internal thread ID.

Returns
the internal thread ID
template<class TQueue, class TMessage>
virtual Void EThreadEventWorker< TQueue, TMessage >::init ( TQueue &  queue,
Int  workerid,
pVoid  arg,
Dword  stackSize = 0 
)
inlineprotectedvirtual

Initializes the thread object.

Parameters
queuea reference to the work group event queue.
workerididentifies the worker thread within the work group.
argan argument that will be passed through to the internal thread procedure. Currently not used.
stackSizethe stack size.
template<class TQueue, class TMessage>
virtual Void EThreadEventWorker< TQueue, TMessage >::onInit ( )
inlinevirtual

Called in the context of the thread prior to processing teh first event message.

Reimplemented in PFCP::ApplicationWorker.

template<class TQueue, class TMessage>
virtual Void EThreadEventWorker< TQueue, TMessage >::onMessageQueued ( const TMessage &  msg)
inlineprotectedvirtual

Called when an event message is queued.

Parameters
msgthe message object that has been queued.

This method is called in the context of the thread where sendMessage() is called after the message has been added to the thread's event queue.

template<class TQueue, class TMessage>
virtual Void EThreadEventWorker< TQueue, TMessage >::onQuit ( )
inlinevirtual

Called in the context of the thread when the EM_QUIT event is processed.

Reimplemented in PFCP::ApplicationWorker.

template<class TQueue, class TMessage>
virtual Void EThreadEventWorker< TQueue, TMessage >::onTimer ( EThreadEventTimer ptimer)
inlinevirtual

Called in the context of the thread when th EM_TIMER event is processed.

Parameters
ptimera pointer to the EThreadBase::Timer object that expired
template<class TQueue, class TMessage>
Bool EThreadEventWorker< TQueue, TMessage >::pumpMessage ( TMessage &  msg,
Bool  wait = true 
)
inlineprotected

Dispatches the next thread event message.

Parameters
msgthe EThreadMessage event object
waitwaits for the next EThreadMessage to be processed

This method retrieves the next event message from the threads event queue and processes the event by calling the first event handler as defined by the class heirarchy. If no event message is available and the wait parameter is true, then the thread will block waiting on the next event message to be sent to the thread. If there is no event handler defined in the class heirarchy for a particular event ID, the default event handler, defMessageHandler(), will be called.

template<class TQueue, class TMessage>
virtual Void EThreadEventWorker< TQueue, TMessage >::pumpMessages ( )
inlineprotectedvirtual

Process event messages.

Exceptions
EErrorcatches and re-throws any exception raised by pumpMessage

Any overridden version of pumpMessages() must call pumpMessage() to process each individual message.

template<class TQueue, class TMessage>
Bool EThreadEventWorker< TQueue, TMessage >::sendMessage ( UInt  message,
Bool  wait = True 
)
inline

Sends event message to this work group.

Parameters
messagethe message ID
waitwaits for the message to be sent

Sends (posts) an event message to the work group event queue. No additional data is posted with the event.

template<class TQueue, class TMessage>
Bool EThreadEventWorker< TQueue, TMessage >::sendMessage ( UInt  message,
pVoid  voidptr,
Bool  wait = True 
)
inline

Sends event message to this work group.

Parameters
messagethe message ID.
voidptra void pointer to be included with the message.
waitwaits for the message to be sent.

Sends (posts) an event message to the work group event queue. No additional data is posted with the event.

template<class TQueue, class TMessage>
Bool EThreadEventWorker< TQueue, TMessage >::sendMessage ( const TMessage &  msg,
Bool  wait = True 
)
inline

Sends event message to this work group.

Parameters
msgthe message object that has been queued.
waitwaits for the message to be sent

Sends (posts) the supplied event message to the work groups' event queue.

template<class TQueue, class TMessage>
Void EThreadEventWorker< TQueue, TMessage >::start ( )
inlineprotected

Initializes the thread when it was suspended at init().

template<class TQueue, class TMessage>
Int EThreadEventWorker< TQueue, TMessage >::workerId ( ) const
inline

Friends And Related Function Documentation

template<class TQueue, class TMessage>
template<class T1 , class T2 , class T3 >
friend class EThreadEventWorkGroup
friend

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