GlobalObjects
Loading...
Searching...
No Matches
EuAPThread Class Referenceabstract

Abstract superclass for threads. More...

#include <EuAPThread.h>

Inheritance diagram for EuAPThread:

Public Types

enum  EuPTHREAD_STATUS { EuPTHREAD_AT_THE_START , EuPTHREAD_WORKING , EuPTHREAD_PAUSING , EuPTHREAD_FINISHED }
 

Public Member Functions

 EuAPThread ()
 
virtual ~EuAPThread ()
 
virtual int cancel ()
 
virtual int join ()
 
virtual int start ()=0
 
EuAPThread::EuPTHREAD_STATUS status () const
 
void testCancel ()
 

Protected Member Functions

virtual void cleanUp ()
 
virtual void work ()=0
 

Static Protected Member Functions

static void _cleanUp (void *pParam)
 

Protected Attributes

EuPTHREAD_STATUS m_eThreadStatus
 
std::string m_strDebugInfo
 
pthread_t m_Thread
 

Private Member Functions

 EuAPThread (const EuAPThread &)
 
EuAPThreadoperator= (const EuAPThread &)
 

Detailed Description

Abstract superclass for threads.

The work of the thread is done in the method EuAPThread::work(), which must be implemented by subclasses.

Note
Based on 32 bit POSIX threads.
Author
Helmut Jakoby

Member Enumeration Documentation

◆ EuPTHREAD_STATUS

To be able to control a thread, it is helpful to know the work status.

Enumerator
EuPTHREAD_AT_THE_START 

The thread has not yet worked.

EuPTHREAD_WORKING 

The thread is working.

EuPTHREAD_PAUSING 

The thread skips the work.

EuPTHREAD_FINISHED 

The thread is finished with its work.

Constructor & Destructor Documentation

◆ EuAPThread() [1/2]

EuAPThread::EuAPThread ( )

Standard constructor.

◆ ~EuAPThread()

virtual EuAPThread::~EuAPThread ( )
virtual

Destructor.

Exceptions
eut::ErrorNExceptionIf the thread is already started and not yet finished, an exception is thrown.

◆ EuAPThread() [2/2]

EuAPThread::EuAPThread ( const EuAPThread & )
private

The copy constructor is not available.

Member Function Documentation

◆ _cleanUp()

static void EuAPThread::_cleanUp ( void * pParam)
staticprotected

This method is passed in subclasses in method threadWork to function pthread_cleanup_push, which expects a function (this one) and a void parameter to 'pass' (in this case the respective derived EuAPThread).

So when the pthread ends, this method is called with the respective thread as pParam (is the derived EuAPThread).

This static method in turn calls the dynamic method cleanUp of the derived EuAPThread (passed in pParam), which can perform the necessary cleanup work.

Parameters
[in]pParamThe respective derived EuAPThread.

◆ cancel()

virtual int EuAPThread::cancel ( )
virtual

Terminates the thread.

This method must be called before the destructor because other virtual methods may be called. This method can therefore not be placed in the destructor!

Returns
A return value < 0 indicates an error or info.
Note
This method waits (via pthread_join(...)) until the thread is finished.

Reimplemented in EuEndlessPThread.

◆ cleanUp()

virtual void EuAPThread::cleanUp ( )
protectedvirtual

If necessary cleanup work has to be performed, this method can be overwritten in the respective subclasses; it is called automatically.

Here m_eThreadStatus is set to EuPTHREAD_FINISHED.

Attention
In the overridden methods in subclasses this method should be called to set the status.

◆ join()

virtual int EuAPThread::join ( )
virtual

Is waiting until the thread is finished.

Returns
A return value < 0 indicates an error.

◆ operator=()

EuAPThread & EuAPThread::operator= ( const EuAPThread & )
private

The assignment operator is not available.

◆ start()

virtual int EuAPThread::start ( )
pure virtual

Starts the thread.

Must be overwritten in subclasses, otherwise nothing happens.

Returns
A return value < 0 should indicate an error.

Implemented in EuEndlessPThread.

◆ status()

EuAPThread::EuPTHREAD_STATUS EuAPThread::status ( ) const

Returns the status of the thread.

Returns
The status.

◆ testCancel()

void EuAPThread::testCancel ( )

Checks whether the thread should be terminated (pthread_testcancel()).

◆ work()

virtual void EuAPThread::work ( )
protectedpure virtual

This method is executed by the thread and must be overwritten in subclasses.

The method testCancel() should be inserted there to ensure that the thread is terminated.

Member Data Documentation

◆ m_eThreadStatus

EuPTHREAD_STATUS EuAPThread::m_eThreadStatus
protected

The working status.

◆ m_strDebugInfo

std::string EuAPThread::m_strDebugInfo
protected

Here you can write something in for DEBUG purposes.

◆ m_Thread

pthread_t EuAPThread::m_Thread
protected

The 'real' pthread.


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