39 #ifndef ORO_CALL_FUNCTION_HPP 40 #define ORO_CALL_FUNCTION_HPP 42 #include "../base/ActionInterface.hpp" 43 #include "../base/DisposableInterface.hpp" 44 #include "../internal/DataSources.hpp" 46 #include "../internal/DataSource.hpp" 47 #include "../ExecutionEngine.hpp" 48 #include "../Logger.hpp" 49 #include <boost/shared_ptr.hpp> 50 #include <boost/bind.hpp> 53 {
namespace scripting {
54 using namespace detail;
67 boost::shared_ptr<ProgramInterface> _foo;
75 bool checkIfDoneOrYielded() {
76 return (!maccept || _foo->inError() || _foo->isStopped());
85 if ( _foo->inError() ) {
87 }
else if ( _foo->isStopped() ) {
103 boost::shared_ptr<ProgramInterface> foo,
107 mrunner(p), mcaller(caller),
108 _foo( foo ), maccept(false)
133 if (!minit->execute())
return false;
134 _foo->loaded(mrunner);
136 if ( _foo->needsStart() )
139 if ( mrunner->
isSelf() ) {
148 this->executeAndDispose();
149 if ( checkIfDone() )
return true;
150 log(
Warning) <<
"Execution of function '" << _foo->getName() <<
" did not finish in one cycle " 151 "and paused in line " << _foo->getLineNumber() <<
", e.g. because of a yield statement." << nlog()
152 <<
"As it was called from the executing thread, execution will continue immediately to avoid a dead-lock." << nlog()
153 <<
"This behavior might be unexpected and can cause busy-wait loops." << endlog();
166 maccept = mrunner->
process(
this );
167 if ( !maccept )
return false;
170 mrunner->
waitForMessages(boost::bind(&CallFunction::checkIfDoneOrYielded,
this) );
171 }
while( !checkIfDone() );
180 maccept = mrunner->
process(
this );
181 if ( !maccept )
return false;
184 mrunner->
waitForMessages(boost::bind(&CallFunction::checkIfDoneOrYielded,
this) );
185 if ( checkIfDone() )
return true;
194 if ( !maccept )
return false;
197 mrunner->
waitForMessages(boost::bind(&CallFunction::checkIfDone,
this) );
198 if ( checkIfDone() )
return true;
215 if ( _foo->execute() == false ) {
237 minit->readArguments();
242 return new CallFunction( minit->clone(), _foo, mrunner, mcaller);
247 boost::shared_ptr<ProgramInterface> fcpy( _foo->copy(alreadyCloned) );
248 return new CallFunction( minit->copy(alreadyCloned), fcpy , mrunner, mcaller );
base::ActionInterface * clone() const
The Clone Software Pattern.
virtual void dispose()
Just free this object without executing it.
bool isSelf() const
Check if the thread that processes messages send to this engine is the same as the calling thread...
virtual bool execute()
Enqueue the function in the target engine (mrunner) and wait until it is finished or in error state...
void waitForMessages(const boost::function< bool(void)> &pred)
Call this if you wish to block on a message arriving in the Execution Engine.
#define RTT_SCRIPTING_API
An execution engine serialises (executes one after the other) the execution of all commands...
virtual void executeAndDispose()
Message callback that executes the function until it finishes or yields.
CallFunction(base::ActionInterface *init_com, boost::shared_ptr< ProgramInterface > foo, ExecutionEngine *p, ExecutionEngine *caller)
Create a Command to send a function to a ExecutionEngine.
virtual bool valid() const
Inspect if this action was executed and valid.
virtual void readArguments()
This is invoked some time before execute() at a time when the action may read its function arguments...
Based on the software pattern 'command', this interface allows execution of action objects...
base::ActionInterface * copy(std::map< const base::DataSourceBase *, base::DataSourceBase * > &alreadyCloned) const
When copying an Orocos program, we want identical internal::DataSource's to be mapped to identical Da...
An object that is executable and is freed after execution.
virtual void reset()
Reset this action.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
An action which calls a FunctionFraph for execution in a ExecutionEngine.
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().