00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
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