50 #include <boost/bind.hpp> 53 #define ORONUM_EE_MQUEUE_SIZE 100 65 using namespace detail;
66 using namespace boost;
81 std::vector<TaskCore*> copy =
children;
82 for (std::vector<TaskCore*>::iterator it = copy.begin(); it != copy.end();++it){
83 (*it)->setExecutionEngine( 0 );
88 while (
f_queue->dequeue( foo ) )
92 while (
mqueue->dequeue( dis ) )
108 vector<TaskCore*>::iterator it = find (
children.begin(),
children.end(), tc );
119 while (
f_queue->dequeue(foo) ) {
121 if ( foo->
execute() == false ){
139 bool result =
f_queue->enqueue( f );
152 : mf(f),mee(ee), found(false) {}
158 virtual bool isError()
const {
return false; }
214 return !
mqueue->isEmpty();
223 while (
mqueue->dequeue(com) ) {
251 bool result =
mqueue->enqueue( c );
290 if (slave_activity && slave_activity->
getMaster()) {
359 taskc->prepareUpdateHook();
361 )
CATCH(std::exception
const& e,
362 log(
Error) <<
"in updateHook(): switching to exception state because of unhandled exception" << endlog();
363 log(
Error) <<
" " << e.what() << endlog();
366 log(
Error) <<
"in updateHook(): switching to exception state because of unhandled exception" << endlog();
374 )
CATCH(std::exception
const& e,
375 log(
Error) <<
"in errorHook(): switching to exception state because of unhandled exception" << endlog();
376 log(
Error) <<
" " << e.what() << endlog();
379 log(
Error) <<
"in errorHook(): switching to exception state because of unhandled exception" << endlog();
387 for (std::vector<TaskCore*>::iterator it =
children.begin(); it !=
children.end();++it) {
390 (*it)->prepareUpdateHook();
392 )
CATCH(std::exception
const& e,
393 log(
Error) <<
"in updateHook(): switching to exception state because of unhandled exception" << endlog();
394 log(
Error) <<
" " << e.what() << endlog();
397 log(
Error) <<
"in updateHook(): switching to exception state because of unhandled exception" << endlog();
404 )
CATCH(std::exception
const& e,
405 log(
Error) <<
"in errorHook(): switching to exception state because of unhandled exception" << endlog();
406 log(
Error) <<
" " << e.what() << endlog();
409 log(
Error) <<
"in errorHook(): switching to exception state because of unhandled exception" << endlog();
421 for (std::vector<TaskCore*>::iterator it =
children.begin(); it !=
children.end();++it) {
422 ok = (*it)->breakUpdateHook() && ok;
446 name =
"GlobalEngine";
447 log(
Error) <<
"in "<<name<<
": unhandled exception in sent operation." << endlog();
ActivityInterface * getActivity() const
Query for the task this interface is run in.
virtual void setActivity(ActivityInterface *task)
Set the task this interface is run in.
virtual bool trigger()=0
Trigger that work has to be done.
#define TRY(C)
Contains static global configuration variables and cached entries.
virtual void step()
Executes (in that order) Messages, Functions and updateHook() functions of this TaskContext and its c...
void loaded(ExecutionEngine *ee)
Called by the ExecutionEngine ee to tell this object it is being loaded.
virtual bool removeFunction(base::ExecutableInterface *f)
Remove a running function added with runFunction.
virtual bool hasWork()
This method is for 'intelligent' activity implementations that wish to see if it is required to call ...
void setMaster(ExecutionEngine *master)
Set the master ExecutionEngine.
virtual void dispose()
Just free this object without executing it.
bool isLoaded()
Returns true if this object is loaded in an ExecutionEngine.
ExecutionEngine * mmaster
A master ExecutionEngine which should process our messages.
virtual void updateHook()
Function where the user must insert his 'application' code.
void waitForMessages(const boost::function< bool(void)> &pred)
Call this if you wish to block on a message arriving in the Execution Engine.
virtual bool isActive() const =0
Query if the activity is started.
RemoveMsg(ExecutableInterface *f, ExecutionEngine *ee)
The state indicating that a run-time error has occured [red] and needs attention. ...
virtual bool removeSelfFunction(base::ExecutableInterface *f)
Self-removal for a running function added with runFunction.
void waitForFunctions(const boost::function< bool(void)> &pred)
Call this if you wish to block on a function completing in the Execution Engine.
virtual void finalize()
The method that will be called after the last periodical execution of step() ( or non periodical exec...
virtual bool isRunning() const =0
Query if the activity is initialized and executing.
internal::MWSRQueue< base::ExecutableInterface * > * f_queue
Stores all functions we're executing.
void waitForMessagesInternal(boost::function< bool(void)> const &pred)
Call this if you wish to block on a message arriving in the Execution Engine.
An execution engine serialises (executes one after the other) the execution of all commands...
internal::MWSRQueue< base::DisposableInterface * > * mqueue
Our Message queue.
virtual void executeAndDispose()=0
Execute functionality and free this object.
virtual bool isError() const
virtual void errorHook()
Implement this method to contain code that must be executed in the RunTimeError state, instead of updateHook().
Interface to start/stop and query a Activity.
bool stopTask(base::TaskCore *task)
Stops executing the updateHook of task.
virtual bool initialize()
The method that will be called before the first periodical execution of step() ( or non periodical ex...
The state indicating the component encountered a fatal error and is unable to execute.
virtual bool execute()=0
Executes a piece of functionality.
virtual void exception()
Call this method to indicate a run-time exception happend.
void unloaded()
Called by the ExecutionEngine ee to tell this object it is being unloaded.
void waitAndProcessFunctions(boost::function< bool(void)> const &pred)
Call this if you wish to block on a function completing in the Execution Engine and execute it...
base::TaskCore * getParent()
The base::TaskCore which created this ExecutionEngine.
std::vector< base::TaskCore * > children
virtual bool breakUpdateHook()
Implement this function if your code might block for long times inside the updateHook() function...
An object that is executable and is freed after execution.
void waitAndProcessMessages(boost::function< bool(void)> const &pred)
Call this if you wish to block on a message arriving in the Execution Engine and execute it...
This object represents the default Multi-Writer, Single-Reader queue implementation used by Orocos ob...
virtual void addChild(base::TaskCore *tc)
Add a base::TaskCore to execute.
void setExceptionTask()
Set the 'owner' task in the exception state.
The state indicating the component is running [green].
Notify the Logger in which 'module' the message occured.
The TaskContext is the C++ representation of an Orocos component.
virtual bool start()=0
Start the activity.
base::TaskCore * taskc
The parent or 'owner' of this ExecutionEngine, may be null.
virtual void setActivity(base::ActivityInterface *task)
Overwritten version of RTT::base::RunnableInterface::setActivity().
Objects that implement this interface are to be executed in the ExecutionEngine.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
#define ORONUM_EE_MQUEUE_SIZE
virtual bool process(base::DisposableInterface *c)
Queue and execute (process) a given message.
virtual bool runFunction(base::ExecutableInterface *f)
Run a given function in step() or loop().
virtual void executeAndDispose()
Execute functionality and free this object.
ExecutionEngine(base::TaskCore *owner=0)
Create an execution engine with a internal::CommandProcessor, scripting::ProgramProcessor and StateMa...
virtual const std::string & getName() const
Returns the name of this TaskContext.
virtual RunnableInterface * getRunner() const
Returns a pointer to the RunnableInterface instance.
void broadcast()
Wake all threads that are blocking in wait() or wait_until().
virtual void removeChild(base::TaskCore *tc)
Remove a base::TaskCore from execution.
virtual bool breakLoop()
This method is called by the framework to break out of the loop() method.
MutexLock is a scope based Monitor, protecting critical sections with a Mutex object through locking ...
bool wait(Mutex &m)
Wait forever until a condition occurs.
virtual void dispose()=0
Just free this object without executing it.