StartStopManager.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jan 19 14:11:19 CET 2004  StartStopManager.hpp 
00003 
00004                         StartStopManager.hpp -  description
00005                            -------------------
00006     begin                : Mon January 19 2004
00007     copyright            : (C) 2004 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.ac.be
00009  
00010  ***************************************************************************
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU General Public                   *
00013  *   License as published by the Free Software Foundation;                 *
00014  *   version 2 of the License.                                             *
00015  *                                                                         *
00016  *   As a special exception, you may use this file as part of a free       *
00017  *   software library without restriction.  Specifically, if other files   *
00018  *   instantiate templates or use macros or inline functions from this     *
00019  *   file, or you compile this file and link it with other files to        *
00020  *   produce an executable, this file does not by itself cause the         *
00021  *   resulting executable to be covered by the GNU General Public          *
00022  *   License.  This exception does not however invalidate any other        *
00023  *   reasons why the executable file might be covered by the GNU General   *
00024  *   Public License.                                                       *
00025  *                                                                         *
00026  *   This library is distributed in the hope that it will be useful,       *
00027  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00028  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00029  *   Lesser General Public License for more details.                       *
00030  *                                                                         *
00031  *   You should have received a copy of the GNU General Public             *
00032  *   License along with this library; if not, write to the Free Software   *
00033  *   Foundation, Inc., 59 Temple Place,                                    *
00034  *   Suite 330, Boston, MA  02111-1307  USA                                *
00035  *                                                                         *
00036  ***************************************************************************/ 
00037  
00038  
00039 #ifndef STARTSTOPMANAGER_HPP
00040 #define STARTSTOPMANAGER_HPP
00041 
00042 #include "../Time.hpp"
00043 #include <boost/function.hpp>
00044 #include <boost/bind.hpp>
00045 #include <vector>
00046 #include <algorithm>
00047 #include "../rtt-config.h"
00048 
00049 namespace RTT
00050 { namespace os {
00061     class RTT_API StartStopManager
00062     {
00063         static StartStopManager* mt;
00064 
00065     public:
00066         static StartStopManager* Instance();
00067 
00068         static void Release();
00069 
00070         typedef int (*start_fun)(void);
00071         typedef boost::function<void (void)> stop_fun;
00072 
00076         void startFunction( start_fun t );
00077 
00081         void stopFunction( stop_fun t );
00082 
00088         bool start();
00089 
00093         void stop();
00094 
00095     private:
00096 
00097         StartStopManager();
00098 
00099         ~StartStopManager();
00100 
00101         void res_collector( start_fun f )
00102         {
00103             if ( f && f() != 0 )
00104                 res = false;
00105         }
00106 
00107         static void caller( stop_fun f)
00108         {
00109           if (f)
00110             f();
00111         }
00112 
00113         bool res;
00114             
00115         std::vector<start_fun> startv;
00116         std::vector<stop_fun> stopv;
00117     };
00118 
00119 
00124     struct InitFunction
00125     {
00126         InitFunction( int (*f)(void) ) 
00127         {
00128             StartStopManager::Instance()->startFunction(f);
00129         }
00130     };
00131 
00136     struct CleanupFunction
00137     {
00138         CleanupFunction( void (*f)(void) )
00139         {
00140             StartStopManager::Instance()->stopFunction(f);
00141         }
00142     };
00143 
00144 
00145 
00146 
00147 }}
00148 
00149 #endif


rtt
Author(s): RTT Developers
autogenerated on Wed Aug 26 2015 16:16:18