Ceylan::System::Thread Class Reference

Basic abstract class for threaded objects. More...

#include <CeylanThread.h>

Inheritance diagram for Ceylan::System::Thread:

Inheritance graph
[legend]
Collaboration diagram for Ceylan::System::Thread:

Collaboration graph
[legend]

List of all members.

Classes

class  ThreadException
 Raised when POSIX returns thread errors, mainly in creation. More...
class  Waiter

Public Types

enum  TextOutputFormat { rawText, html }
 Defines what text output formats for TextDisplayable instances are available. More...

Public Member Functions

 Thread ()
 Constructs an anonymous thread.
 Thread (const std::string &name)
 Constructs a named Thread object.
virtual ~Thread () throw ()
 Basic destructor.
virtual void run ()
 Start point method.
virtual void start ()=0
 The start point for the newly created thread.
virtual void askToStop ()
SystemSpecificThreadIdentifier & id () const
 Returns this Thread's unique id.
bool isClean () const
 Returns this thread's clean state.
bool isRunning () const
 Tells whether the thread is running.
bool hasTerminated () const
 Tells whether the thread has terminated its run.
bool stopDemanded () const
 Tells whether the thread has been asked to stop.
void waitUntilOver ()
virtual const std::string toString (Ceylan::VerbosityLevels level=Ceylan::high) const
 Returns a user-friendly description of the state of this object.
const std::string & getName () const
 Returns the name string.

Static Public Member Functions

static ThreadCount GetNumberOfThreads ()
 Returns the number of Thread objects currently existing.
static void Sleep (System::Second seconds, System::Microsecond microseconds=0)
 Makes the calling thread sleep during specified time.
static void Run (Thread &thread)
 Runs specified thread.
static const std::string ToString (std::list< TextDisplayable * > displayables, Ceylan::VerbosityLevels level=Ceylan::high)
 Returns a user-friendly description of this list of pointers to text displayable instances.
static TextOutputFormat GetOutputFormat ()
 Returns the current overall text format to be used by TextDisplayable instances.
static void SetOutputFormat (TextOutputFormat newOutputFormat)
 Sets the current overall text format to be used by TextDisplayable instances.

Protected Member Functions

void cancel ()
virtual void cleanup ()
 This method is called after the run.
void setRunning (bool newRunningStatus)
 Sets the running status.
virtual void threadCreationFailed (int error)
 Called whenever the thread creation fails.

Static Protected Attributes

static TextOutputFormat _OutputFormat = rawText
 The text format to be used currently by TextDisplayable instances.

Private Member Functions

 Thread (const Thread &source)
 Copy constructor made private to ensure that it will never be called.
Threadoperator= (const Thread &source)
 Assignment operator made private to ensure that it will never be called.

Private Attributes

SystemSpecificThreadIdentifier * _id
 This thread's unique system-specific identifier.
SystemSpecificThreadAttribute * _attr
 This thread's system-specific attribute.
Ceylan::System::Synchronized
< bool > 
_terminated
 Tells whether this thread has terminated, i.e.
Ceylan::System::Synchronized
< bool > 
_clean
 Tells whether this thread is clean, i.e.
Ceylan::System::Synchronized
< bool > 
_running
 Tells whether this thread is currently running.
Ceylan::System::Synchronized
< bool > 
_mustStop
 Tells whether this thread must stop, i.e.

Static Private Attributes

static Synchronized
< ThreadCount > * 
_Number = 0
 Number of the currently existing thread instances.


Detailed Description

Basic abstract class for threaded objects.

Note:
No thread object will be created unless the multithreading feature is supported: Thread constructors will otherwise throw FeatureNotAvailableException instances.
See also:
Feature::isMultithreadingSupported

Runnable, Synchronized, POSIX threads.

Definition at line 70 of file CeylanThread.h.


Member Enumeration Documentation

Defines what text output formats for TextDisplayable instances are available.

Enumerator:
rawText 
html 

Definition at line 124 of file CeylanTextDisplayable.h.


Constructor & Destructor Documentation

Thread::Thread (  ) 

Constructs an anonymous thread.

Exceptions:
FeatureNotAvailableException if the multithreading feature is not available.

Definition at line 203 of file CeylanThread.cc.

References _attr, and _id.

Thread::Thread ( const std::string &  name  )  [explicit]

Constructs a named Thread object.

Exceptions:
FeatureNotAvailableException if the multithreading feature is not available.

Definition at line 234 of file CeylanThread.cc.

References _attr, and _id.

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

Basic destructor.

Definition at line 265 of file CeylanThread.cc.

References _attr, _id, _Number, cancel(), Ceylan::System::Runnable::getName(), and isRunning().

Ceylan::System::Thread::Thread ( const Thread source  )  [private]

Copy constructor made private to ensure that it will never be called.

The compiler should complain whenever this undefined constructor is called, implicitly or not.


Member Function Documentation

void Thread::askToStop (  )  [virtual]

void Thread::cancel (  )  [protected]

void Thread::cleanup (  )  [protected, virtual]

This method is called after the run.

It is executed by the launching thread.

Definition at line 765 of file CeylanThread.cc.

References _clean, and generalUtils::true.

Referenced by Run().

const string & Runnable::getName (  )  const [inherited]

Returns the name string.

Definition at line 75 of file CeylanRunnable.cc.

References Ceylan::System::Runnable::_name.

Referenced by askToStop(), cancel(), Run(), run(), waitUntilOver(), and ~Thread().

Ceylan::System::ThreadCount Thread::GetNumberOfThreads (  )  [static]

Returns the number of Thread objects currently existing.

Definition at line 485 of file CeylanThread.cc.

References _Number.

TextDisplayable::TextOutputFormat TextDisplayable::GetOutputFormat (  )  [static, inherited]

bool Thread::hasTerminated (  )  const

Tells whether the thread has terminated its run.

Definition at line 386 of file CeylanThread.cc.

References _terminated.

Thread::SystemSpecificThreadIdentifier & Thread::id (  )  const

Returns this Thread's unique id.

Definition at line 359 of file CeylanThread.cc.

References _id.

bool Thread::isClean (  )  const

Returns this thread's clean state.

Definition at line 368 of file CeylanThread.cc.

References _clean, and Ceylan::System::Synchronized< bool >::getValue().

bool Thread::isRunning (  )  const

Tells whether the thread is running.

Definition at line 377 of file CeylanThread.cc.

References _running, and Ceylan::System::Synchronized< bool >::getValue().

Referenced by ~Thread().

Thread& Ceylan::System::Thread::operator= ( const Thread source  )  [private]

Assignment operator made private to ensure that it will never be called.

The compiler should complain whenever this undefined operator is called, implicitly or not.

void Thread::Run ( Thread thread  )  [static]

Runs specified thread.

Note:
Does nothing if the multithreading feature is not available.

Definition at line 521 of file CeylanThread.cc.

References cleanup(), Ceylan::System::Runnable::getName(), setRunning(), and start().

Referenced by run().

void Thread::run (  )  [virtual]

Start point method.

Exceptions:
RunnableException if the runnable could not be run.

Implements Ceylan::System::Runnable.

Definition at line 305 of file CeylanThread.cc.

References _id, Ceylan::System::Runnable::getName(), Run(), and threadCreationFailed().

void TextDisplayable::SetOutputFormat ( TextOutputFormat  newOutputFormat  )  [static, inherited]

Sets the current overall text format to be used by TextDisplayable instances.

Parameters:
newOutputFormat the new output format.

Definition at line 72 of file CeylanTextDisplayable.cc.

References Ceylan::TextDisplayable::_OutputFormat.

Referenced by Ceylan::Log::LogHolder::LogHolder().

void Thread::setRunning ( bool  newRunningStatus  )  [protected]

Sets the running status.

Definition at line 778 of file CeylanThread.cc.

References _running, and Ceylan::toString().

Referenced by Run().

void Thread::Sleep ( System::Second  seconds,
System::Microsecond  microseconds = 0 
) [static]

Makes the calling thread sleep during specified time.

Parameters:
seconds the number of seconds to wait.
microseconds the number of microseconds to wait, must be less than one second, it is only the remainder of the total wanted duration.
Exceptions:
ThreadException if the sleep failed.

Definition at line 497 of file CeylanThread.cc.

References Ceylan::System::basicSleep(), dataUtils::e, Ceylan::Exception::toString(), and Ceylan::toString().

Referenced by Ceylan::System::InputStream::Select().

virtual void Ceylan::System::Thread::start (  )  [pure virtual]

The start point for the newly created thread.

Referenced by Run().

bool Thread::stopDemanded (  )  const

Tells whether the thread has been asked to stop.

Definition at line 395 of file CeylanThread.cc.

References _mustStop.

void Thread::threadCreationFailed ( int  error  )  [protected, virtual]

Called whenever the thread creation fails.

Definition at line 792 of file CeylanThread.cc.

References Ceylan::System::explainError().

Referenced by run().

const std::string TextDisplayable::ToString ( std::list< TextDisplayable * >  displayables,
Ceylan::VerbosityLevels  level = Ceylan::high 
) [static, inherited]

Returns a user-friendly description of this list of pointers to text displayable instances.

Parameters:
displayables a list of pointers to TextDisplayable instances/
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
toString, Ceylan::VerbosityLevels

Definition at line 45 of file CeylanTextDisplayable.cc.

References Ceylan::formatStringList().

const string Thread::toString ( Ceylan::VerbosityLevels  level = Ceylan::high  )  const [virtual]

Returns a user-friendly description of the state of this object.

Parameters:
level the requested verbosity level.
Note:
Text output format is determined from overall settings.
See also:
TextDisplayable

Implements Ceylan::System::Runnable.

Definition at line 425 of file CeylanThread.cc.

References _clean, _id, _mustStop, _Number, _running, _terminated, Ceylan::formatStringList(), Ceylan::low, and Ceylan::medium.

void Thread::waitUntilOver (  ) 

Definition at line 404 of file CeylanThread.cc.

References _id, and Ceylan::System::Runnable::getName().


Member Data Documentation

SystemSpecificThreadAttribute* Ceylan::System::Thread::_attr [private]

This thread's system-specific attribute.

Definition at line 586 of file CeylanThread.h.

Referenced by Thread(), and ~Thread().

Tells whether this thread is clean, i.e.

if its cleanup method has already been called.

Definition at line 627 of file CeylanThread.h.

Referenced by cleanup(), isClean(), and toString().

SystemSpecificThreadIdentifier* Ceylan::System::Thread::_id [private]

This thread's unique system-specific identifier.

Definition at line 581 of file CeylanThread.h.

Referenced by cancel(), id(), run(), Thread(), toString(), waitUntilOver(), and ~Thread().

Tells whether this thread must stop, i.e.

wheter it has been requested to do so.

Definition at line 644 of file CeylanThread.h.

Referenced by askToStop(), stopDemanded(), and toString().

Synchronized< ThreadCount > * Thread::_Number = 0 [static, private]

Number of the currently existing thread instances.

Definition at line 654 of file CeylanThread.h.

Referenced by GetNumberOfThreads(), toString(), and ~Thread().

TextDisplayable::TextOutputFormat TextDisplayable::_OutputFormat = rawText [static, protected, inherited]

The text format to be used currently by TextDisplayable instances.

Note:
Defaults to raw text.

Definition at line 158 of file CeylanTextDisplayable.h.

Referenced by Ceylan::TextDisplayable::GetOutputFormat(), and Ceylan::TextDisplayable::SetOutputFormat().

Tells whether this thread is currently running.

Definition at line 635 of file CeylanThread.h.

Referenced by cancel(), isRunning(), setRunning(), and toString().

Tells whether this thread has terminated, i.e.

if its cancel method has already been called.

Definition at line 618 of file CeylanThread.h.

Referenced by cancel(), hasTerminated(), and toString().


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

Generated on Thu Jun 4 20:41:11 2009 for Ceylan by  doxygen 1.5.8