Orocos Real-Time Toolkit  2.6.0
ExecutionEngine.hpp
00001 /***************************************************************************
00002   tag: Peter Soetens  Wed Jan 18 14:11:40 CET 2006  ExecutionEngine.hpp
00003 
00004                         ExecutionEngine.hpp -  description
00005                            -------------------
00006     begin                : Wed January 18 2006
00007     copyright            : (C) 2006 Peter Soetens
00008     email                : peter.soetens@mech.kuleuven.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 ORO_EXECUTION_ENGINE_HPP
00040 #define ORO_EXECUTION_ENGINE_HPP
00041 
00042 #include "os/Mutex.hpp"
00043 #include "os/MutexLock.hpp"
00044 #include "os/Condition.hpp"
00045 #include "base/RunnableInterface.hpp"
00046 #include "base/ActivityInterface.hpp"
00047 #include "base/DisposableInterface.hpp"
00048 #include "base/ExecutableInterface.hpp"
00049 #include "internal/List.hpp"
00050 #include <vector>
00051 #include <boost/function.hpp>
00052 
00053 #include "rtt-config.h"
00054 #include "internal/rtt-internal-fwd.hpp"
00055 
00056 namespace RTT
00057 {
00058 
00077     class RTT_API ExecutionEngine
00078         : public base::RunnableInterface
00079     {
00080     public:
00087         ExecutionEngine( base::TaskCore* owner = 0);
00088 
00089         ~ExecutionEngine();
00090 
00094         base::TaskCore* getParent();
00095 
00099         virtual void addChild(base::TaskCore* tc);
00100 
00104         virtual void removeChild(base::TaskCore* tc);
00105 
00109         base::TaskCore* getTaskCore() const { return taskc; }
00110 
00122         virtual bool process(base::DisposableInterface* c);
00123 
00132         virtual bool runFunction(base::ExecutableInterface* f);
00133 
00139         virtual bool removeFunction(base::ExecutableInterface* f);
00140 
00146         virtual bool removeSelfFunction(base::ExecutableInterface* f);
00147 
00157         void waitForMessages(const boost::function<bool(void)>& pred);
00158 
00168         void waitForFunctions(const boost::function<bool(void)>& pred);
00169 
00178         bool stopTask(base::TaskCore* task);
00179 
00180 
00184         void setExceptionTask();
00185     protected:
00199         void waitForMessagesInternal( boost::function<bool(void)> const& pred);
00200 
00213         void waitAndProcessMessages(boost::function<bool(void)> const& pred);
00214 
00227         void waitAndProcessFunctions(boost::function<bool(void)> const& pred);
00228 
00232         base::TaskCore*     taskc;
00233 
00237         internal::MWSRQueue<base::DisposableInterface*>* mqueue;
00238 
00239         std::vector<base::TaskCore*> children;
00240 
00244         internal::MWSRQueue<base::ExecutableInterface*>* f_queue;
00245 
00246         os::Mutex msg_lock;
00247         os::Condition msg_cond;
00248 
00249         void processMessages();
00250         void processFunctions();
00251         void processChildren();
00252 
00253         virtual bool initialize();
00254 
00259         virtual void step();
00260 
00261         virtual bool breakLoop();
00262 
00263         virtual void finalize();
00264 
00265         virtual bool hasWork();
00266 
00267     };
00268 
00269 }
00270 #endif