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

ctimer.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Serge Lussier   *
00003  *   serge.lussier@videotron.ca   *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 #include <ctimer.hxx>
00021 
00022 namespace control {
00023 
00024 ctimer::ctimer(const std::string& nameid, const sigc::slot< bool >& exec_hook): ccontrol(nameid, sigc::mem_fun<bool>(this, &ccontrol::noop) )
00025 {
00026    _state = ::control::pause;
00027    init();
00028 }
00029 
00030 
00031 ctimer::ctimer(): ccontrol()
00032 {
00033    init();
00034 }
00035 
00036 
00037 ctimer::~ctimer()
00038 {
00039 }
00040 
00041 
00042 
00043 
00044 
00048 bool ctimer::pause()
00049 {
00050    _state = ::control::pause;
00051    return true;
00052 }
00053 
00054 
00058 bool ctimer::start( unsigned long delay, bool once)
00059 {
00060    _duration = delay;
00061    _state = ::control::proceed;
00062    _single_shot = once;
00063    return ccontrol::start();
00064 }
00065 
00066 
00070 bool ctimer::resume()
00071 {
00072    _state = control::proceed;
00073    ccontrol::signal();
00074    return true;
00075 }
00076 
00077 
00081 void ctimer::stop()
00082 {
00083    _state = ::control::pause;
00084 }
00085 
00086 
00090 bool ctimer::controller_loop()
00091 {
00092    do{
00093       switch(_state){
00094          case ::control::proceed:
00095             usleep( _duration );
00096             cthread::notify();
00097             if( _single_shot) stop();
00098             break;
00099          case ::control::terminate:
00100             return false;
00101          case ::control::pause:
00102             do  wait(); while(_state == ::control::pause );
00103             break;
00104       }
00105    }while(_state != ::control::terminate );
00106    return true;
00107 }
00108 
00109 
00110 }

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 )