Project stdui: "Simple Type Dialog User-Interface"

|
Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

control::cthread Class Reference

Base class of the multithread engine of the control API. More...

#include <cthread.hxx>

Inheritance diagram for control::cthread:

Inheritance graph
[legend]
List of all members.

Public Types

typedef sigc::signal< bool,
cthread * >::iterator 
notifyhandle

Public Member Functions

 cthread ()
 cthread (const std::string &nameid, const sigc::slot< bool > &exec_hook)
virtual ~cthread ()
cthread::notifyhandle notify_delegate (const sigc::slot< bool, cthread * > &_slot)
bool release_delegate (const cthread::notifyhandle &_handle)
bool run ()
 Initiates the start of the thread process by really creating the thread and then the hooked routine that runs in that thread.
bool exec_delegate (const sigc::slot< bool > &exec_hook)
 This method is used to register (or connect) a startup method to the cthread::run_ signal later if the constructor used to instanciate this cthread class was not the one that takes a sigc::slot argument, or used to add another slot to the run_ signal.
bool notify ()
bool exit ()
 Simply terminates the thread by calling pthread_exit() - but before doing so, this method emits the cthread::end_ signal to perform the connected routines.
bool end_delegate (const sigc::slot< void > &end_hook)
const std::string & name () const

Protected Attributes

std::string _name

Private Attributes

sigc::signal< bool, cthread * > notify_
 multi-purpose notificator signal.
pthread_t _pthID
 PThread thread handle id.
sigc::signal< bool > run_
sigc::signal< void > end_

Friends

void * thread_start_entry (void *)

Detailed Description

Base class of the multithread engine of the control API.

See also:
control::cmutex

control::ccontrol

Author:
Serge Lussier

Definition at line 37 of file cthread.hxx.


Member Typedef Documentation

typedef sigc::signal<bool, cthread*>::iterator control::cthread::notifyhandle
 

Definition at line 40 of file cthread.hxx.


Constructor & Destructor Documentation

control::cthread::cthread  ) 
 

Definition at line 37 of file cthread.cc.

00037                 : sigc::trackable()
00038 {
00039 }

control::cthread::cthread const std::string &  nameid,
const sigc::slot< bool > &  exec_hook
 

Definition at line 41 of file cthread.cc.

References _name, and run_.

00041                                                                         : trackable()
00042 {
00043    _name = nameid;
00044     run_.connect( exec_hook );
00045 }

control::cthread::~cthread  )  [virtual]
 

Definition at line 47 of file cthread.cc.

References _pthID, end_, name(), notify_, and run_.

00048 {
00049    std::cerr << __PRETTY_FUNCTION__ << std::endl << '{' << std::endl << name() << std::endl;
00050    run_.clear();
00051    end_.clear();
00052    notify_.clear();
00053    pthread_cancel(_pthID);
00054    std::cerr << "thread exited ?" << std::endl;
00055    std::cerr << std::endl << '}' << std::endl;
00056 }

Here is the call graph for this function:


Member Function Documentation

control::cthread::end_delegate const sigc::slot< void > &  end_hook  )  [inline]
 

Definition at line 73 of file cthread.hxx.

References end_.

00074     {
00075        end_.connect( end_hook );
00076        return true;
00077     }

bool control::cthread::exec_delegate const sigc::slot< bool > &  exec_hook  ) 
 

This method is used to register (or connect) a startup method to the cthread::run_ signal later if the constructor used to instanciate this cthread class was not the one that takes a sigc::slot argument, or used to add another slot to the run_ signal.

Definition at line 83 of file cthread.cc.

References run_.

00084 {
00085     run_.connect( exec_hook);
00086     return true;
00087 }

bool control::cthread::exit  ) 
 

Simply terminates the thread by calling pthread_exit() - but before doing so, this method emits the cthread::end_ signal to perform the connected routines.

Definition at line 94 of file cthread.cc.

References _pthID, and end_.

00095 {
00096    std::cerr << __PRETTY_FUNCTION__ << std::endl << '{' << std::endl << "." << std::endl;
00097    // signal the end of the thread just before aborting it!
00098    if(!end_.empty()) end_.emit();
00099     pthread_cancel(_pthID);
00100     std::cerr << std::endl << '}' << std::endl;
00101 
00102    return true;
00103 }

const std::string& control::cthread::name  )  const [inline]
 

Definition at line 81 of file cthread.hxx.

References _name.

Referenced by control::ccontrol::release(), control::ccontrol::start(), control::ccontrol::~ccontrol(), and ~cthread().

00082         {
00083            return _name;
00084         }

control::cthread::notify  )  [inline]
 

Definition at line 64 of file cthread.hxx.

References notify_.

00065     {
00066         return notify_.emit(this);
00067     }

control::cthread::notify_delegate const sigc::slot< bool, cthread * > &  _slot  )  [inline]
 

Definition at line 48 of file cthread.hxx.

References notify_.

00048 { return notify_.connect( _slot ); }

control::cthread::release_delegate const cthread::notifyhandle _handle  )  [inline]
 

Note:
After the call to this method, the handle is no more valid. Undefined results if used after the call.

Definition at line 53 of file cthread.hxx.

00053                                                                {
00054         if( _handle->empty() ) return false;
00055         _handle->disconnect();
00056         return true;
00057     }

bool control::cthread::run  ) 
 

Initiates the start of the thread process by really creating the thread and then the hooked routine that runs in that thread.

Note:
A method address hooked(or connected) to the cthread::run_ signal is reuired in order for this thread to work. The cthread class, as a wrapper to the pthread lib threads facility, initiates the thread with the generic static function (cthread.cc)::void *thread_start_entry(void* thread_inst) that actually emits the cthread::run_ signal which in turn calls any hooked functions. So if there are no "connected" slot(s) to the run_ signal, then the thread will simply pass-through the thread_start_entry function and terminates immediately.

Definition at line 70 of file cthread.cc.

References _pthID, and thread_start_entry.

Referenced by control::ccontrol::start().

00071 {
00072     int rc = pthread_create( &_pthID, 0l, thread_start_entry, (void*)this);
00073     if(rc) return false;
00074     return true;
00075 }


Friends And Related Function Documentation

void* thread_start_entry void *  thread_inst  )  [friend]
 

Real thread duties start here:

Todo:
implement thread end returns with end-state value...

Definition at line 26 of file cthread.cc.

Referenced by run().

00027 {
00028     cthread* inst = (cthread*) thread_inst;
00030     inst->run_.emit();
00031     // -------------------------------
00033     return 0l;
00034 }


Member Data Documentation

std::string control::cthread::_name [protected]
 

Definition at line 97 of file cthread.hxx.

Referenced by cthread(), and name().

pthread_t control::cthread::_pthID [private]
 

PThread thread handle id.

Definition at line 93 of file cthread.hxx.

Referenced by exit(), run(), and ~cthread().

sigc::signal<void> control::cthread::end_ [private]
 

Definition at line 95 of file cthread.hxx.

Referenced by end_delegate(), exit(), and ~cthread().

sigc::signal<bool, cthread*> control::cthread::notify_ [private]
 

multi-purpose notificator signal.

Definition at line 91 of file cthread.hxx.

Referenced by notify(), notify_delegate(), and ~cthread().

sigc::signal<bool> control::cthread::run_ [private]
 

Definition at line 94 of file cthread.hxx.

Referenced by cthread(), exec_delegate(), control::thread_start_entry(), and ~cthread().


The documentation for this class was generated from the following files:
API Documentation Generated by:  doxygen 1.4.0
About the author | Site started with trial version of DreamWeaver MX 2004 | Finalizing with  | Contact | ©2005, Serge Lussier ( Bretzel )