SingleThread.hpp

00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Apr 22 20:40:53 CEST 2004  SingleThread.hpp
00003 
00004                         SingleThread.hpp -  description
00005                            -------------------
00006     begin                : Thu April 22 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 SINGLE_THREAD_HPP
00040 #define SINGLE_THREAD_HPP
00041 
00042 // Our own package config headers.
00043 #include "../rtt-config.h"
00044 #include "fosi.h"
00045 
00046 #include "RunnableInterface.hpp"
00047 #include "ThreadInterface.hpp"
00048 #include "Mutex.hpp"
00049 
00050 #include <string>
00051 
00052 namespace RTT
00053 {
00054     class RTT_API DigitalOutInterface;
00055 
00056     namespace OS {
00084     class RTT_API SingleThread
00085         : public OS::ThreadInterface
00086     {
00087         friend void* singleThread_f( void* t );
00088     public:
00097         SingleThread(int priority, const std::string& name, OS::RunnableInterface* r=0);
00098 
00108         SingleThread(int scheduler, int priority, const std::string& name, OS::RunnableInterface* r=0);
00109 
00110         virtual ~SingleThread();
00111 
00112         virtual bool run( OS::RunnableInterface* r);
00113 
00124         virtual bool start();
00125 
00137         virtual bool stop();
00138 
00142         virtual bool isRunning() const;
00143 
00147         virtual bool isActive() const;
00148 
00152         virtual const char* getName() const;
00157         virtual RTOS_TASK * getTask(){return &(this->rtos_task);};
00158 
00159         virtual bool setScheduler(int sched_type);
00160         virtual int getScheduler() const;
00161 
00162         virtual Seconds getPeriod() const { return 0.0; }
00163         virtual bool setPeriod(Seconds period) { return false; }
00164         virtual nsecs getPeriodNS() const { return 0; }
00165 
00166         virtual bool setPriority(int priority);
00167 
00168         virtual int getPriority() const;
00169 
00170         virtual void yield();
00171 
00172     protected:
00173 
00174         virtual bool breakLoop();
00175 
00176         virtual void loop();
00177 
00178         virtual bool initialize();
00179 
00180         virtual void finalize();
00181 
00182     private:
00183         void setup(int _priority, const std::string& name);
00184 
00188         int msched_type;
00189 
00194         bool active;
00195 
00199         bool prepareForExit;
00200 
00204         bool inloop;
00205 
00209         bool runloop;
00210 
00214         RTOS_TASK rtos_task;
00215 
00219         rt_sem_t sem;
00220 
00225         rt_sem_t confDone;
00226 
00230         OS::RunnableInterface* runComp;
00231 
00235         MutexRecursive breaker;
00236 
00237 #ifdef OROPKG_OS_THREAD_SCOPE
00238     // Pointer to Threadscope device
00239         DigitalOutInterface * d;
00240 #endif
00241     };
00242 
00243 }}
00244 
00245 #endif
Generated on Thu Dec 23 13:22:38 2010 for Orocos Real-Time Toolkit by  doxygen 1.6.3