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

base class for EThreadPrivate and EThreadPublic More...

#include <etevent.h>

Inheritance diagram for EThreadEvent< TQueue, TMessage >:
EThreadBasic _EThreadEventBase ESocket::Thread< TQueue, TMessage >

Public Member Functions

 EThreadEvent ()
 Default class constructor. More...
 
 ~EThreadEvent ()
 Rhe class destructor. More...
 
Bool sendMessage (UInt message, Bool wait=True)
 Sends event message to this thread. More...
 
Bool sendMessage (UInt message, pVoid voidptr, Bool wait=True)
 Sends event message to this thread. More...
 
Bool sendMessage (const TMessage &msg, Bool wait=True)
 Sends event message to this thread. More...
 
virtual Void init (Short appId, UShort threadId, pVoid arg, Int queueSize=16384, Bool suspended=False, Dword stackSize=0)
 Initializes the thread object. More...
 
Void quit ()
 Posts the quit message to this thread. More...
 
Void start ()
 Initializes the thread when it was suspended at init(). More...
 
Void suspend ()
 Suspends a running thread. More...
 
Void resume ()
 Resumes a suspended thread. More...
 
virtual Void onInit ()
 Called in the context of the thread when the EM_INIT event is processed. More...
 
virtual Void onQuit ()
 Called in the context of the thread when the EM_QUIT event is processed. More...
 
virtual Void onSuspend ()
 Called in the context of the thread when th EM_SUSPEND event is processed. More...
 
virtual Void onTimer (EThreadEventTimer *ptimer)
 Called in the context of the thread when th EM_TIMER event is processed. More...
 
Void initTimer (EThreadEventTimer &t)
 Intializes an EThreadEvent::Timer object and associates with this thread. More...
 
ESemaphoreDatagetMsgSemaphore ()
 Returns the semaphore associated with this thread's event queue. 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

virtual Void messageQueued ()
 Called when an event message is queued. 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...
 

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 EThreadEvent< TQueue, TMessage >

base class for EThreadPrivate and EThreadPublic

The EThreadBase class provides event dispatching and timer management functionality that are part of EThreadPrivate and EThreadPublic. the EThreadPrivate and EThreadPublic classes. This functionality includes event dispatching

Constructor & Destructor Documentation

◆ EThreadEvent()

template<class TQueue, class TMessage>
EThreadEvent< TQueue, TMessage >::EThreadEvent ( )
inline

Default class constructor.

◆ ~EThreadEvent()

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

Rhe class destructor.

Member Function Documentation

◆ defaultMessageHandler()

template<class TQueue, class TMessage>
virtual Void EThreadEvent< 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.

◆ getMsgSemaphore()

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

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

◆ getThreadId()

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

Retrieves the internal thread ID.

Returns
the internal thread ID

◆ init()

template<class TQueue, class TMessage>
virtual Void EThreadEvent< TQueue, TMessage >::init ( Short  appId,
UShort  threadId,
pVoid  arg,
Int  queueSize = 16384,
Bool  suspended = False,
Dword  stackSize = 0 
)
inlinevirtual

Initializes the thread object.

Parameters
appIdidentifies the application this thread is associated with.
threadIdidentifies the thread within this application.
argan argument that will be passed through to the internal thread procedure. Currently not used.
queueSizethe maximum number of unprocessed entries in the event queue.
suspendedif True, the thread is started in a suspended state.
stackSizethe stack size.

◆ initTimer()

template<class TQueue, class TMessage>
Void EThreadEvent< TQueue, TMessage >::initTimer ( EThreadEventTimer t)
inline

Intializes an EThreadEvent::Timer object and associates with this thread.

Parameters
tthe EThreadEvent::Timer object to initialize

◆ messageQueued()

template<class TQueue, class TMessage>
virtual Void EThreadEvent< TQueue, TMessage >::messageQueued ( )
inlineprotectedvirtual

Called when an event message is 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.

◆ onInit()

template<class TQueue, class TMessage>
virtual Void EThreadEvent< TQueue, TMessage >::onInit ( )
inlinevirtual

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

◆ onQuit()

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

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

◆ onSuspend()

template<class TQueue, class TMessage>
virtual Void EThreadEvent< TQueue, TMessage >::onSuspend ( )
inlinevirtual

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

◆ onTimer()

template<class TQueue, class TMessage>
virtual Void EThreadEvent< 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

◆ pumpMessage()

template<class TQueue, class TMessage>
Bool EThreadEvent< 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.

◆ pumpMessages()

template<class TQueue, class TMessage>
virtual Void EThreadEvent< 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.

◆ quit()

template<class TQueue, class TMessage>
Void EThreadEvent< TQueue, TMessage >::quit ( )
inline

Posts the quit message to this thread.

◆ resume()

template<class TQueue, class TMessage>
Void EThreadEvent< TQueue, TMessage >::resume ( )
inline

Resumes a suspended thread.

◆ sendMessage() [1/3]

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

Sends event message to this thread.

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

Sends (posts) the supplied event message to this thread's event queue.

◆ sendMessage() [2/3]

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

Sends event message to this thread.

Parameters
messagethe message ID
waitwaits for the message to be sent

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

◆ sendMessage() [3/3]

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

Sends event message to this thread.

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 this threads event queue. No additional data is posted with the event.

◆ start()

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

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

◆ suspend()

template<class TQueue, class TMessage>
Void EThreadEvent< TQueue, TMessage >::suspend ( )
inline

Suspends a running thread.

Suspends a running thread by posting the EM_SUSPEND message to the threads event queue. The thread will call the onSuspend() method when the EM_SUSPEND event is processed. The thread will not process any more thread messages until the resume() method is called.


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