fesa::Thread Class Reference

This class is a wrapper in order to manage threads according to the object oriented style. More...

#include <Thread.h>

Inheritance diagram for fesa::Thread:
fesa::AbstractEventSource fesa::FesaDeviceServer fesa::NotificationConsumer fesa::NotificationThread fesa::OnSubscriptionEventSource::SubscriptionThread fesa::PersistencyManager fesa::RTScheduler fesa::OnDemandEventSource fesa::OnSubscriptionEventSource fesa::TimerEventSource

List of all members.

Public Member Functions

 Thread ()
 Constructor.
virtual ~Thread ()
 Destructor.
void setDetachState (int32_t state)
 Modify the detach state of the thread.
virtual void start (bool blockingMode, const std::string &threadName)
 Create and run a thread.
virtual void stop ()
 Stop the thread.
int32_t join (void **status)
 Wait for the thread to terminate.
bool getIsRunning () const
 Check if the thread is running.
pthread_t getID () const
 Get the process ID.
int32_t getPriority () const
 Get the priority of the thread.
void setPriority (int32_t priority)
 Set the priority of the thread.

Static Public Member Functions

static void AdjustProcessPriority ()
 The process priority can only be adjusted in the main thread. It needs to be adjusted to the maximal thread priority since it sets the limit of the thread priorities of this process.
static std::string getThreadName (pthread_t threadId)
 Get the name of the thread by its id.
static void registerThreadIdName (pthread_t threadId, const std::string &threadName)
 Associate a thread id with a name.

Protected Member Functions

virtual void run ()=0
 this method has to be overridden to provide the logic for the thread. It has to contain the code that will be executed in the thread

Protected Attributes

bool isRunning_
 true if the thread is running
bool hasFinished_
 true if the thread has finished.
pthread_t tid_
 Id of this thread.

Static Private Member Functions

static void * startThread (void *arg)
 The method which will be called on creation of the thread. Static, in order to fit the expected type.

Private Attributes

pthread_attr_t attr_
 Attributes of this thread.
int32_t priority_
 Priority of this thread.
std::string name_

Detailed Description

This class is a wrapper in order to manage threads according to the object oriented style.

Definition at line 32 of file Thread.h.


Constructor & Destructor Documentation

fesa::Thread::Thread (  ) 

Constructor.

Exceptions:
FesaException 

Definition at line 110 of file Thread.cpp.

References attr_, FesaErrorInitializingThreadAttributes, fesa::NICE_SCHED_POLICY, and priority_.

fesa::Thread::~Thread (  )  [virtual]

Destructor.

Definition at line 123 of file Thread.cpp.


Member Function Documentation

void fesa::Thread::AdjustProcessPriority (  )  [static]

The process priority can only be adjusted in the main thread. It needs to be adjusted to the maximal thread priority since it sets the limit of the thread priorities of this process.

Exceptions:
FesaException 

Definition at line 241 of file Thread.cpp.

References fesa::AbstractEquipment::getDeviceDataFileName(), fesa::AbstractEquipment::getInstance(), fesa::AbstractEquipment::getProcessConfiguration(), fesa::ProcessConfiguration::isDefined(), fesa::NICE_SCHED_POLICY, fesa::PropertyTag::NO_RT_SCHEDULING, and fesa::RT_SCHED_POLICY.

pthread_t fesa::Thread::getID (  )  const [inline]
bool fesa::Thread::getIsRunning (  )  const [inline]

Check if the thread is running.

Returns:
true if the the thread is running

Definition at line 172 of file Thread.h.

References isRunning_.

int32_t fesa::Thread::getPriority (  )  const [inline]
std::string fesa::Thread::getThreadName ( pthread_t  threadId  )  [static]

Get the name of the thread by its id.

Parameters:
threadId The id of a thread
Returns:
The name of the thread

Definition at line 288 of file Thread.cpp.

int32_t fesa::Thread::join ( void **  status  ) 

Wait for the thread to terminate.

Parameters:
[out] status Status
Returns:
Exit code

Definition at line 223 of file Thread.cpp.

References tid_.

void fesa::Thread::registerThreadIdName ( pthread_t  threadId,
const std::string &  threadName 
) [static]

Associate a thread id with a name.

Parameters:
threadId The id of the thread
threadName The name of the thread

Definition at line 304 of file Thread.cpp.

Referenced by fesa::AbstractEventSource::AbstractEventSource(), fesa::FesaDeviceServer::get(), fesa::FesaDeviceServer::set(), and startThread().

virtual void fesa::Thread::run (  )  [protected, pure virtual]

this method has to be overridden to provide the logic for the thread. It has to contain the code that will be executed in the thread

Implemented in fesa::PersistencyManager, fesa::FesaDeviceServer, fesa::NotificationThread, fesa::AbstractEventSource, fesa::OnSubscriptionEventSource::SubscriptionThread, fesa::RTScheduler, and fesa::NotificationConsumer.

Referenced by startThread().

void fesa::Thread::setDetachState ( int32_t  state  )  [inline]

Modify the detach state of the thread.

Parameters:
state New thread state. See pthread_attr_setdetachstate() for info on what values are possible

Definition at line 162 of file Thread.h.

References attr_.

Referenced by fesa::NotificationConsumer::NotificationConsumer(), and fesa::RTScheduler::RTScheduler().

void fesa::Thread::setPriority ( int32_t  priority  ) 
void fesa::Thread::start ( bool  blockingMode,
const std::string &  threadName 
) [virtual]

Create and run a thread.

Parameters:
blockingMode If true, create a new thread and block the calling thread until the new thread finishes. If false, create a new thread and return
threadName The name of the thread that is being started
Exceptions:
FesaException 

Definition at line 129 of file Thread.cpp.

References attr_, FesaErrorCreatingThread, FesaErrorDestroyingThreadAttributes, FesaErrorSettingInheritScheduling, FesaErrorSettingSchedulingPolicy, FesaErrorSettingThreadAttributes, FesaErrorUndefinedPriority, hasFinished_, isRunning_, name_, priority_, startThread(), and tid_.

Referenced by fesa::OnSubscriptionEventSource::createSubscriptionThread(), fesa::NotificationThread::NotificationThread(), and fesa::AbstractServerController::start().

void * fesa::Thread::startThread ( void *  arg  )  [static, private]

The method which will be called on creation of the thread. Static, in order to fit the expected type.

Definition at line 89 of file Thread.cpp.

References FesaErrorSettingThreadAttributes, name_, priority_, registerThreadIdName(), run(), and tid_.

Referenced by start().

void fesa::Thread::stop (  )  [virtual]

Member Data Documentation

pthread_attr_t fesa::Thread::attr_ [private]

Attributes of this thread.

Definition at line 151 of file Thread.h.

Referenced by setDetachState(), start(), and Thread().

bool fesa::Thread::hasFinished_ [protected]
bool fesa::Thread::isRunning_ [protected]
std::string fesa::Thread::name_ [private]

Reimplemented in fesa::RTScheduler.

Definition at line 157 of file Thread.h.

Referenced by start(), and startThread().

int32_t fesa::Thread::priority_ [private]

Priority of this thread.

Definition at line 156 of file Thread.h.

Referenced by getPriority(), setPriority(), start(), startThread(), and Thread().

pthread_t fesa::Thread::tid_ [protected]

Id of this thread.

Definition at line 140 of file Thread.h.

Referenced by getID(), join(), start(), startThread(), and stop().


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

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1