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::ccontrol Class Reference

base controler class. The controler class is a subset of cmutex and cthread and its execution is associated with a pthread_cond variable. More...

#include <ccontrol.hxx>

Inheritance diagram for control::ccontrol:

Inheritance graph
[legend]
Collaboration diagram for control::ccontrol:

Collaboration graph
[legend]
List of all members.

Public Types

typedef sigc::slot< bool > worker_delegate

Public Member Functions

 ccontrol ()
 Default empty ccontrol construtor.
 ccontrol (const std::string &nameid, const control::ccontrol::worker_delegate &worker)
 control contructor which initializes the name and the delegate method in the contructor.
virtual ~ccontrol ()
 The destructor disconnects all the delegates and release its mutex. It does not terminate the thread.
int wait ()
 The wait method sleeps on the pthread_cond_wait until the ccontrol::signal() method is called to awake this thread. This method also emits the proceed_ signal to call any hooked routines to perfoms the work.
void signal ()
 This method is used to awake this thread to perform its work.
void connect (const sigc::slot< bool > &_work)
virtual bool start ()
 This method may be called to make more sense than the default cthread::run() method for code clarity. So it does call cthread::run() method.
virtual bool init ()
 Initialize the control's data such pthread's structures before starting itself.
int state ()
void terminate ()
void release ()
bool noop ()

Protected Member Functions

virtual bool controller_loop ()

Protected Attributes

int _state

Private Attributes

bool _cond
pthread_cond_t * _cv
sigc::signal< bool > proceed_

Detailed Description

base controler class. The controler class is a subset of cmutex and cthread and its execution is associated with a pthread_cond variable.

Author:
Serge Lussier

Definition at line 42 of file ccontrol.hxx.


Member Typedef Documentation

typedef sigc::slot<bool> control::ccontrol::worker_delegate
 

Definition at line 44 of file ccontrol.hxx.


Constructor & Destructor Documentation

control::ccontrol::ccontrol  ) 
 

Default empty ccontrol construtor.

Definition at line 32 of file ccontrol.cc.

00032                   :cthread(), cmutex(),_cond(false)
00033 {
00034 }

control::ccontrol::ccontrol const std::string &  nameid,
const control::ccontrol::worker_delegate worker
 

control contructor which initializes the name and the delegate method in the contructor.

Definition at line 40 of file ccontrol.cc.

References _cond, and proceed_.

00040                                                                                         : cmutex(),
00041    cthread(nameid, sigc::mem_fun(this, &ccontrol::controller_loop)){
00042       proceed_.connect( worker );
00043       _cond=false;
00044 }

control::ccontrol::~ccontrol  )  [virtual]
 

The destructor disconnects all the delegates and release its mutex. It does not terminate the thread.

See also:
cthread for thread termination.

Definition at line 52 of file ccontrol.cc.

References control::cthread::name(), proceed_, and release().

00053 {
00054    std::cerr << __PRETTY_FUNCTION__ <<  std::endl << '{' << std::endl << "." << std::endl;
00055    std::cerr << name() << std::endl;
00056    proceed_.clear();
00057    std::cerr << "releasing condition variable..." << std::endl;
00058    release();
00059    std::cerr << '}' << std::endl;
00060 }

Here is the call graph for this function:


Member Function Documentation

control::ccontrol::connect const sigc::slot< bool > &  _work  )  [inline]
 

Definition at line 56 of file ccontrol.hxx.

References proceed_.

00056 { proceed_.connect(_work); }

bool control::ccontrol::controller_loop  )  [protected, virtual]
 

Reimplemented in control::ctimer.

Definition at line 191 of file ccontrol.cc.

References _state, and wait().

00192 {
00193    do ; while(this->wait() != control::terminate);
00194    return control::terminate == _state;
00195 }

Here is the call graph for this function:

bool control::ccontrol::init  )  [virtual]
 

Initialize the control's data such pthread's structures before starting itself.

Reimplemented from control::cmutex.

Definition at line 152 of file ccontrol.cc.

References _cv.

Referenced by control::ctimer::ctimer().

00153 {
00154    cmutex::init();
00155    _cv = new pthread_cond_t;
00156    pthread_cond_init(_cv, 0l);
00157 
00158    return true;
00159 
00160 }

bool control::ccontrol::noop  )  [inline]
 

Definition at line 66 of file ccontrol.hxx.

00066 { return true; }

void control::ccontrol::release  ) 
 

Definition at line 166 of file ccontrol.cc.

References _cv, control::cthread::name(), and control::cmutex::unlock().

Referenced by wait(), and ~ccontrol().

00167 {
00168    std::cerr << __PRETTY_FUNCTION__ << std::endl << '{' << std::endl << "." << std::endl;
00169    std::cerr << name() << std::endl;
00170    if(_mutex) unlock();
00171    if(_cv) {
00172      int ER =  pthread_cond_destroy(_cv);
00173      if(ER){
00174         std::cerr << " -- error trying to release condition variable..." << std::endl;
00175      }
00176       delete _cv;
00177       _cv=0l;
00178    }
00179    if(_mutex){
00180       delete _mutex;
00181       _mutex = 0l;
00182    }
00183    std::cerr << "terminating inner thread instance..." << std::endl;
00184    cthread::exit();
00185    std::cerr << std::endl << '}' << std::endl;
00186 }

Here is the call graph for this function:

void control::ccontrol::signal  ) 
 

This method is used to awake this thread to perform its work.

Definition at line 110 of file ccontrol.cc.

References _cond, and _cv.

00111 {
00112    if( _cond ) return;
00113    _cond = true;
00114    //lock();
00115    pthread_cond_signal(_cv );
00116    //unlock();
00117 }

bool control::ccontrol::start  )  [virtual]
 

This method may be called to make more sense than the default cthread::run() method for code clarity. So it does call cthread::run() method.

Definition at line 138 of file ccontrol.cc.

References _state, control::cthread::name(), and control::cthread::run().

00139 {
00140    std::cerr << __PRETTY_FUNCTION__ << std::endl << '{' << std::endl << "." << std::endl;
00141    std::cerr << name() << std::endl;
00142    _state = control::proceed;
00143    std::cerr << std::endl << '}' << std::endl;
00144    return run();
00145 }

Here is the call graph for this function:

control::ccontrol::state  )  [inline]
 

Definition at line 63 of file ccontrol.hxx.

References _state.

Referenced by wait().

00063 { return _state; }

void control::ccontrol::terminate  ) 
 

Definition at line 122 of file ccontrol.cc.

References _cond, and _state.

00123 {
00124    _state = ::control::terminate;
00125    if(!_cond ){
00126       _cond=true;
00127       ccontrol::signal();
00128    }
00129 
00130 }

int control::ccontrol::wait  ) 
 

The wait method sleeps on the pthread_cond_wait until the ccontrol::signal() method is called to awake this thread. This method also emits the proceed_ signal to call any hooked routines to perfoms the work.

Returns:
(int) the state's value of this control :
Note:
control::terminate if one of the hooked routine has determined that this control is done. control::pause if this control must be paused until the resume method is called. -- not yet implemented. control::proceed is the default return state that tells this control to continue its duty...

Les commentaires sont en anglais, vue que le francais n'est pas une langue rependue en informatique.... It is mandatory that ccontrol::terminate() must be called from outside of the control's thread execution for terminating a control at anytime. Directly deleting or cancelling the controler's thread process results in undef behaviour if the controler's thread is in waiting condition. Thus, calling ccontrol::terminate ensure that it puts the controler in termination state and does what is needed to ensure that the thread cancellation is made inside the controler's own thread process and all other resources are released. Typical usage:

    //create the instance of a controler:
             control::ccontrol *_control = new control::ccontrol("controler's nameid description", sigc::mem_fun(&obj, &objclass::method);
             _control->init(); // the contructor doesn't call init.
             _control->start();
   // ... later:
             _control->terminate();

Definition at line 86 of file ccontrol.cc.

References _cond, _cv, _state, control::cmutex::lock(), control::cmutex::mutexhandle(), proceed_, release(), and state().

Referenced by control::ctimer::controller_loop(), and controller_loop().

00087 {
00088    //lock();
00089    int CV_ERR =0;
00090    while( ! _cond ){
00091       lock();
00092       CV_ERR = pthread_cond_wait( _cv, mutexhandle() );
00094    }
00095    //unlock(); // pas besoin de debloquer le mutex...
00096    if( _state == control::proceed ) proceed_();
00097    if( _state == control::terminate){
00098       release();
00099       return control::terminate;
00100    }
00101    //
00102    _cond = false;
00103    return state();
00104 }

Here is the call graph for this function:


Member Data Documentation

bool control::ccontrol::_cond [private]
 

Definition at line 69 of file ccontrol.hxx.

Referenced by ccontrol(), signal(), terminate(), and wait().

pthread_cond_t* control::ccontrol::_cv [private]
 

Definition at line 70 of file ccontrol.hxx.

Referenced by init(), release(), signal(), and wait().

int control::ccontrol::_state [protected]
 

Definition at line 74 of file ccontrol.hxx.

Referenced by controller_loop(), start(), state(), terminate(), and wait().

sigc::signal<bool> control::ccontrol::proceed_ [private]
 

Definition at line 71 of file ccontrol.hxx.

Referenced by ccontrol(), connect(), wait(), and ~ccontrol().


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 )