All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
HSEP::Thread Class Referenceabstract

Base class to create thread aware classes. More...

#include <Thread.h>

+ Inheritance diagram for HSEP::Thread:
+ Collaboration diagram for HSEP::Thread:

Public Member Functions

 Thread (const char *pType)
 
virtual ~Thread ()
 
const char * namePtr () const
 
bool dispatch ()
 Lets the thread to start working.
 
int join ()
 Wait until the internal thread's memory structures are finished.
 
void finish ()
 Advise the thread for not continuing executing the perform method.
 
bool finishRequested () const
 Indicates if a finish was executed on this thread.
 
void relocate (string pDestination)
 Moves the thread to the specified destination.
 
- Public Member Functions inherited from HSEP::HSEPObject
string & lastErrorRef ()
 Returns a reference to the last stored error message.
 
ErrorCode lastCode ()
 Returns the last stored code.
 
bool valid ()
 Permits to know if the object has a valid internal state.
 
string & typeRef ()
 Permits to know the type of this particular object.
 

Protected Member Functions

 Thread (const char *pType, string &pReceivedState)
 This is the protected constructor will be used by the distributed rebuilder.
 
virtual bool prepare ()=0
 Provides a placeholder for the class to initialize internal data.
 
virtual int perform ()=0
 Performs the internal processing cycle for the thread.
 
virtual void dispose ()=0
 If the prepare and perform method where successful, the dispose must deinitialize everything was initialized during the prepare method.
 
virtual void d_packState (string &pStateData)
 Permits to package the thread contents to be send to another process or computer to continue working.
 
virtual bool d_sendToDestination (string &pStateData)
 Sends the thread state to the destination.
 
virtual void d_restoreState (string &pSource)
 Rebuilds the internal state for the thread.
 
- Protected Member Functions inherited from HSEP::HSEPObject
 HSEPObject (const char *pType)
 Constructor, providing the base for the state controlling instance.
 
virtual ~HSEPObject ()
 
void setLastError (string &pErrorMsgRef)
 Assigns an error message text to the last executed operation.
 
void setLastError (const string &pErrorMsgRef)
 Assigns an error message text to the last executed operation.
 
void setLastError (const char *pErrorMsg)
 Assigns an error message text to the last executed operation.
 
void setValid ()
 Defines that the object has a valid state.
 
void setInvalid ()
 Defines that the object has an invalid state.
 
void setLastCode (const ErrorCode pErrorCode)
 Defines the internal result code for the object.
 

Protected Attributes

Mutex aMutex
 

Detailed Description

Base class to create thread aware classes.

The descendant classes must implement the prepare, perform and dispose methods, that would offer the following type of functionality:

In the independent thread functionality

if (prepare) {
while not finished {
exitCode = perform
}
}

Where the thread must be accountable as finished

exitCode = join
... do something with exitCode, as the thread was finished

All the internal threading processing is hidden for the class user.

Definition at line 63 of file Thread.h.

Constructor & Destructor Documentation

HSEP::Thread::Thread ( const char *  pType)
inline

Definition at line 88 of file Thread.h.

References THREADNAME_LEN.

virtual HSEP::Thread::~Thread ( )
inlinevirtual

Definition at line 94 of file Thread.h.

HSEP::Thread::Thread ( const char *  pType,
string &  pReceivedState 
)
inlineprotected

This is the protected constructor will be used by the distributed rebuilder.

Parameters
pType
pReceivedState

Definition at line 158 of file Thread.h.

References THREADNAME_LEN.

Member Function Documentation

virtual void HSEP::Thread::d_packState ( string &  pStateData)
inlineprotectedvirtual

Permits to package the thread contents to be send to another process or computer to continue working.

Parameters
pStateDatawhere the data will be stored

Definition at line 209 of file Thread.h.

virtual void HSEP::Thread::d_restoreState ( string &  pSource)
inlineprotectedvirtual

Rebuilds the internal state for the thread.

Parameters
pSource

Definition at line 227 of file Thread.h.

virtual bool HSEP::Thread::d_sendToDestination ( string &  pStateData)
inlineprotectedvirtual

Sends the thread state to the destination.

Parameters
pStateData
Returns
true when the data was acknowledge as being received and the thread will live in the other environment.

Definition at line 219 of file Thread.h.

bool HSEP::Thread::dispatch ( )

Lets the thread to start working.

If the operating system doesn't have enough resources, the dispatch attempts to start the thread 10 times with 10 milliseconds time between attempt. After that, if all the attempts fail, returns false.

Returns
true when the thread was able to start
false when the operating system was not able to start the thread

Definition at line 72 of file Thread.cpp.

References NON_DISPATCHED.

Referenced by HSEP::Service::Service().

+ Here is the caller graph for this function:

virtual void HSEP::Thread::dispose ( )
protectedpure virtual

If the prepare and perform method where successful, the dispose must deinitialize everything was initialized during the prepare method.

Implemented in HSEP::LThread, and HSEP::ServiceThread.

void HSEP::Thread::finish ( )
inline

Advise the thread for not continuing executing the perform method.

Definition at line 122 of file Thread.h.

bool HSEP::Thread::finishRequested ( ) const
inline

Indicates if a finish was executed on this thread.

Returns
true if the finish was executed.
false if the finish was not executed.

Definition at line 132 of file Thread.h.

int HSEP::Thread::join ( )

Wait until the internal thread's memory structures are finished.

Returns
the last numeric code sent by the internal performed method.

Definition at line 119 of file Thread.cpp.

const char* HSEP::Thread::namePtr ( ) const
inline

Definition at line 96 of file Thread.h.

virtual int HSEP::Thread::perform ( )
protectedpure virtual

Performs the internal processing cycle for the thread.

Only works if the prepare method was successful.

Returns
a numeric code that only can be recovered externally on the join method.

Implemented in HSEP::LThread.

virtual bool HSEP::Thread::prepare ( )
protectedpure virtual

Provides a placeholder for the class to initialize internal data.

Returns
true when the initialization was successful.
false when an error that must avoid the thread to run happened.

Implemented in HSEP::LThread, and HSEP::ServiceThread.

void HSEP::Thread::relocate ( string  pDestination)

Moves the thread to the specified destination.

In this version, the relocation of threads have no effect. This is an advanced functionality to be developed in future versions to create completely mutable distributed programs that can distribute "part" of their functionality to other programs and/or other computers.

Parameters
pDestination

Definition at line 127 of file Thread.cpp.

Member Data Documentation

Mutex HSEP::Thread::aMutex
mutableprotected

Definition at line 168 of file Thread.h.

Referenced by HSEP::ServiceThread::log().


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