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 DigitalOutInterface;
00053 
00054     namespace OS {
00065     class 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 
00102         virtual bool start();
00106         virtual bool stop();
00111         bool setPeriod( Seconds s );
00116         bool setPeriod( secs s, nsecs ns );
00121         void getPeriod( secs& s, nsecs& ns ) const;
00122 
00126         virtual Seconds getPeriod() const;
00127 
00131         virtual nsecs getPeriodNS() const;
00132 
00136         virtual bool isRunning() const;
00137 
00141         virtual const char* getName() const;
00142 
00147         virtual RTOS_TASK * getTask(){return &rtos_task;};
00148 
00149         virtual bool setScheduler(int sched_type);
00150         virtual int getScheduler() const;
00151 
00155         bool setPeriod(  TIME_SPEC p );
00156 
00157         virtual bool setPriority(int priority);
00158 
00159         virtual int getPriority() const;
00160 
00161         virtual void yield();
00162 
00163         void setMaxOverrun( int m );
00164         int getMaxOverrun() const;
00170         void terminate();
00171 
00172         void emergencyStop();
00173      protected:
00174 
00175         virtual void continuousStepping(bool yes_no);
00182         virtual bool setToStop();
00183 
00184         virtual void step();
00185     
00186         virtual bool initialize();
00187 
00188         virtual void finalize();
00189      private:
00190 
00191         void setup(int _priority, const std::string& name);
00192 
00196         void configure();
00197 
00204         RTOS_TASK rtos_task;
00205 
00209         int msched_type;
00210 
00215         bool running;
00216 
00217         bool prepareForExit;
00218 
00219         bool wait_for_step;
00220 
00221         rt_sem_t sem;
00222         rt_sem_t confDone;
00226         OS::RunnableInterface* runComp;
00227 
00228         int maxOverRun;
00229 
00230         // Only used for passing on the period
00231         NANO_TIME period;
00232 
00233 #ifdef OROPKG_OS_THREAD_SCOPE
00234     // Pointer to Threadscope device
00235         DigitalOutInterface * d;
00236 #endif    
00237     };
00238 
00239 }}
00240 
00241 #endif

Generated on Tue Aug 25 14:17:22 2009 for Orocos Real-Time Toolkit by  doxygen 1.5.8