PeriodicThread.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Mon Jun 10 14:43:13 CEST 2002  PeriodicThread.hpp
00003 
00004                         PeriodicThread.hpp -  description
00005                            -------------------
00006     begin                : Mon June 10 2002
00007     copyright            : (C) 2002 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 #ifndef ORO_PERIODIC_THREAD_HPP
00039 #define ORO_PERIODIC_THREAD_HPP
00040 
00041 // Our own package config headers.
00042 #include "../rtt-config.h"
00043 #include "fosi.h"
00044 
00045 #include "RunnableInterface.hpp"
00046 #include "ThreadInterface.hpp"
00047 
00048 #include <string>
00049 
00050 namespace RTT
00051 {
00052     class RTT_API DigitalOutInterface;
00053 
00054     namespace OS {
00065     class RTT_API PeriodicThread
00066         : public OS::ThreadInterface
00067     {
00068         friend void* periodicThread( void* t );
00069 
00070     public:
00071 
00081         PeriodicThread(int priority,const std::string & name, double period, OS::RunnableInterface* r=0);
00082 
00093         PeriodicThread(int scheduler, int priority,const std::string & name, double period, OS::RunnableInterface* r=0);
00094 
00095         virtual ~PeriodicThread();
00096 
00097         virtual bool run( OS::RunnableInterface* r);
00098 
00099         virtual bool start();
00100 
00101         virtual bool stop();
00102 
00103         bool setPeriod( Seconds s );
00104 
00105         bool setPeriod( secs s, nsecs ns );
00106 
00107         void getPeriod( secs& s, nsecs& ns ) const;
00108 
00109         virtual Seconds getPeriod() const;
00110 
00111         virtual nsecs getPeriodNS() const;
00112 
00113         virtual bool isRunning() const;
00114 
00115         virtual bool isActive() const;
00116 
00117         virtual const char* getName() const;
00118 
00119         virtual RTOS_TASK * getTask(){return &rtos_task;};
00120 
00121         virtual bool setScheduler(int sched_type);
00122         virtual int getScheduler() const;
00123 
00127         bool setPeriod(  TIME_SPEC p );
00128 
00129         virtual bool setPriority(int priority);
00130 
00131         virtual int getPriority() const;
00132 
00133         virtual void yield();
00134 
00135         void setMaxOverrun( int m );
00136         int getMaxOverrun() const;
00137 
00143         void terminate();
00144 
00145         void emergencyStop();
00146      protected:
00147 
00148         virtual void continuousStepping(bool yes_no);
00155         virtual bool setToStop();
00156 
00157         virtual void step();
00158 
00159         virtual bool initialize();
00160 
00161         virtual void finalize();
00162      private:
00163 
00164         void setup(int _priority, const std::string& name);
00165 
00169         void configure();
00170 
00177         RTOS_TASK rtos_task;
00178 
00182         int msched_type;
00183 
00188         bool active, running;
00189 
00190         bool prepareForExit;
00191 
00192         bool wait_for_step;
00193 
00194         rt_sem_t sem;
00195         rt_sem_t confDone;
00199         OS::RunnableInterface* runComp;
00200 
00201         int maxOverRun;
00202 
00203         // Only used for passing on the period
00204         NANO_TIME period;
00205 
00206 #ifdef OROPKG_OS_THREAD_SCOPE
00207     // Pointer to Threadscope device
00208         DigitalOutInterface * d;
00209 #endif
00210     };
00211 
00212 }}
00213 
00214 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3