Orocos Real-Time Toolkit  2.5.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     protected:
00193         void waitForMessagesInternal( boost::function<bool(void)> const& pred);
00194 
00207         void waitAndProcessMessages(boost::function<bool(void)> const& pred);
00208 
00221         void waitAndProcessFunctions(boost::function<bool(void)> const& pred);
00222 
00226         base::TaskCore*     taskc;
00227 
00231         internal::MWSRQueue<base::DisposableInterface*>* mqueue;
00232 
00233         std::vector<base::TaskCore*> children;
00234 
00238         internal::MWSRQueue<base::ExecutableInterface*>* f_queue;
00239 
00240         os::Mutex msg_lock;
00241         os::Condition msg_cond;
00242 
00243         void processMessages();
00244         void processFunctions();
00245         void processChildren();
00246 
00247         virtual bool initialize();
00248 
00253         virtual void step();
00254 
00255         virtual bool breakLoop();
00256 
00257         virtual void finalize();
00258 
00259         virtual bool hasWork();
00260 
00261     };
00262 
00263 }
00264 #endif