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

Work group template definition. The work group contains the event queue that all of the associated worker threads will process. Worker threads can be added and removed at runtime as more or lessing processing capacity is requried. More...

#include <etevent.h>

Inheritance diagram for EThreadEventWorkGroup< TQueue, TMessage, TWorker >:
PFCP::ApplicationWorkGroup< TWorker >

Public Member Functions

 EThreadEventWorkGroup ()
 Default class constructor. More...
 
 ~EThreadEventWorkGroup ()
 The class destructor. More...
 
Bool isInitialized ()
 Retrieves indication if this work group object has been initialized. 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...
 
virtual Void init (Short appId, UShort workGroupId, Int minWorkers, Int maxWorkers=-1, Int queueSize=16384, pVoid arg=nullptr, Bool suspended=False, Dword stackSize=0)
 Initializes the thread object. More...
 
Void join ()
 Returns after successfully joining each worker thread. More...
 
Void quit ()
 Posts the quit message to all of the worker threads. More...
 
Void start ()
 Initializes the thread when it was suspended at init(). More...
 
Bool addWorker ()
 Creates a new worker thread if the current number of workers is less than the maximum configured. More...
 
Void initTimer (EThreadEventTimer &t)
 Intializes an EThreadEvent::Timer object and associates it with this work group. More...
 
ESemaphoreDatagetMsgSemaphore ()
 Returns the semaphore associated with this thread's event queue. More...
 

Protected Member Functions

virtual Void onMessageQueued (const TMessage &msg)
 Called when an event message is queued. More...
 
virtual Void onCreateWorker (TWorker &worker)
 Called when a new worker thread object is created. More...
 

Detailed Description

template<class TQueue, class TMessage, class TWorker>
class EThreadEventWorkGroup< TQueue, TMessage, TWorker >

Work group template definition. The work group contains the event queue that all of the associated worker threads will process. Worker threads can be added and removed at runtime as more or lessing processing capacity is requried.

Constructor & Destructor Documentation

template<class TQueue, class TMessage, class TWorker>
EThreadEventWorkGroup< TQueue, TMessage, TWorker >::EThreadEventWorkGroup ( )
inline

Default class constructor.

template<class TQueue, class TMessage, class TWorker>
EThreadEventWorkGroup< TQueue, TMessage, TWorker >::~EThreadEventWorkGroup ( )
inline

The class destructor.

Member Function Documentation

template<class TQueue, class TMessage, class TWorker>
Bool EThreadEventWorkGroup< TQueue, TMessage, TWorker >::addWorker ( )
inline

Creates a new worker thread if the current number of workers is less than the maximum configured.

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

Returns the semaphore associated with this thread's event queue.

template<class TQueue, class TMessage, class TWorker>
virtual Void EThreadEventWorkGroup< TQueue, TMessage, TWorker >::init ( Short  appId,
UShort  workGroupId,
Int  minWorkers,
Int  maxWorkers = -1,
Int  queueSize = 16384,
pVoid  arg = nullptr,
Bool  suspended = False,
Dword  stackSize = 0 
)
inlinevirtual

Initializes the thread object.

Parameters
appIdidentifies the application this thread is associated with.
workGroupIdthe ID for the work group.
minWorkersthe minimum number of workers for this work group.
maxWorkersthe maximum number of workers for this work group. Defaults to the minWorkers value.
queueSizethe maximum number of unprocessed entries in the event queue.
argan argument that will be passed through to the internal thread procedure. Currently not used.
suspendedif True, the thread is not initialized until start() is called.
stackSizethe stack size.
template<class TQueue, class TMessage, class TWorker>
Void EThreadEventWorkGroup< TQueue, TMessage, TWorker >::initTimer ( EThreadEventTimer t)
inline

Intializes an EThreadEvent::Timer object and associates it with this work group.

Parameters
tthe EThreadEvent::Timer object to initialize
template<class TQueue, class TMessage, class TWorker>
Bool EThreadEventWorkGroup< TQueue, TMessage, TWorker >::isInitialized ( )
inline

Retrieves indication if this work group object has been initialized.

Returns
True if initialized, otherwise False.
template<class TQueue, class TMessage, class TWorker>
Void EThreadEventWorkGroup< TQueue, TMessage, TWorker >::join ( )
inline

Returns after successfully joining each worker thread.

template<class TQueue, class TMessage, class TWorker>
virtual Void EThreadEventWorkGroup< TQueue, TMessage, TWorker >::onCreateWorker ( TWorker &  worker)
inlineprotectedvirtual

Called when a new worker thread object is created.

Parameters
workera reference to the worker thread object created.
template<class TQueue, class TMessage, class TWorker>
virtual Void EThreadEventWorkGroup< TQueue, TMessage, TWorker >::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, class TWorker>
Void EThreadEventWorkGroup< TQueue, TMessage, TWorker >::quit ( )
inline

Posts the quit message to all of the worker threads.

template<class TQueue, class TMessage, class TWorker>
Bool EThreadEventWorkGroup< TQueue, TMessage, TWorker >::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, class TWorker>
Bool EThreadEventWorkGroup< TQueue, TMessage, TWorker >::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, class TWorker>
Bool EThreadEventWorkGroup< TQueue, TMessage, TWorker >::sendMessage ( const TMessage &  msg,
Bool  wait = True 
)
inline

Sends event message to this work group.

Parameters
msgthe message thread message object to send.
waitwaits for the message to be sent

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

template<class TQueue, class TMessage, class TWorker>
Void EThreadEventWorkGroup< TQueue, TMessage, TWorker >::start ( )
inline

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


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