#include <ccontrol.hxx>
Inheritance diagram for control::ccontrol:


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_ |
Definition at line 42 of file ccontrol.hxx.
|
|
Definition at line 44 of file ccontrol.hxx. |
|
|
Default empty ccontrol construtor.
Definition at line 32 of file ccontrol.cc.
|
|
||||||||||||
|
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 }
|
|
|
The destructor disconnects all the delegates and release its mutex. It does not terminate the thread.
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:

|
|
Definition at line 56 of file ccontrol.hxx. References proceed_. 00056 { proceed_.connect(_work); }
|
|
|
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:

|
|
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 }
|
|
|
Definition at line 66 of file ccontrol.hxx. 00066 { return true; }
|
|
|
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:

|
|
This method is used to awake this thread to perform its work.
Definition at line 110 of file ccontrol.cc. 00111 {
00112 if( _cond ) return;
00113 _cond = true;
00114 //lock();
00115 pthread_cond_signal(_cv );
00116 //unlock();
00117 }
|
|
|
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:

|
|
Definition at line 63 of file ccontrol.hxx. References _state. Referenced by wait(). 00063 { return _state; }
|
|
|
Definition at line 122 of file ccontrol.cc. 00123 {
00124 _state = ::control::terminate;
00125 if(!_cond ){
00126 _cond=true;
00127 ccontrol::signal();
00128 }
00129
00130 }
|
|
|
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.
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:

|
|
Definition at line 69 of file ccontrol.hxx. Referenced by ccontrol(), signal(), terminate(), and wait(). |
|
|
Definition at line 70 of file ccontrol.hxx. |
|
|
Definition at line 74 of file ccontrol.hxx. Referenced by controller_loop(), start(), state(), terminate(), and wait(). |
|
|
Definition at line 71 of file ccontrol.hxx. Referenced by ccontrol(), connect(), wait(), and ~ccontrol(). |
1.4.0