41 #include "../ExecutionEngine.hpp" 47 using namespace detail;
53 ,mTaskState(initial_state)
54 ,mInitialState(initial_state)
55 ,mTargetState(initial_state)
62 ,mInitialState(initial_state)
63 ,mTargetState(initial_state)
92 if ( !this->
engine()->getActivity() )
99 if ( !this->
engine()->getActivity() )
111 log(
Error) <<
"in configure(): state has been changed inside the configureHook" << endlog();
112 log(
Error) <<
" but configureHook returned true. Bailing out." << endlog();
124 )
CATCH(std::exception
const& e,
125 log(
Error) <<
"in configure(): switching to exception state because of unhandled exception" << endlog();
126 log(
Error) <<
" " << e.what() << endlog();
129 log(
Error) <<
"in configure(): switching to exception state because of unhandled exception" << endlog();
144 )
CATCH(std::exception
const& e,
145 log(
Error) <<
"in cleanup(): switching to exception state because of unhandled exception" << endlog();
146 log(
Error) <<
" " << e.what() << endlog();
149 log(
Error) <<
"in cleanup(): switching to exception state because of unhandled exception" << endlog();
158 if (
engine()->getActivity() )
181 )
CATCH(std::exception
const& e,
182 log(
RTT::Error) <<
"stopHook(), cleanupHook() and/or exceptionHook() raised " << e.what() <<
", going into Fatal" << endlog();
185 log(
Error) <<
"stopHook(), cleanupHook() and/or exceptionHook() raised an exception, going into Fatal" << endlog();
209 log(
Error) <<
"in start(): state has been changed inside the startHook" << endlog();
210 log(
Error) <<
" but startHook returned true. Bailing out." << endlog();
221 )
CATCH(std::exception
const& e,
222 log(
Error) <<
"in start(): switching to exception state because of unhandled exception" << endlog();
223 log(
Error) <<
" " << e.what() << endlog();
226 log(
Error) <<
"in start(): switching to exception state because of unhandled exception" << endlog();
238 if (
engine()->stopTask(
this) ) {
246 )
CATCH(std::exception
const& e,
247 log(
Error) <<
"in stop(): switching to exception state because of unhandled exception" << endlog();
248 log(
Error) <<
" " << e.what() << endlog();
251 log(
Error) <<
"in stop(): switching to exception state because of unhandled exception" << endlog();
323 void TaskCore::prepareUpdateHook() {
ActivityInterface * getActivity() const
Query for the task this interface is run in.
virtual bool setPeriod(Seconds s)=0
Set the periodicity of this activity in Seconds.
double Seconds
Seconds are stored as a double precision float.
virtual bool trigger()=0
Trigger that work has to be done.
#define TRY(C)
Contains static global configuration variables and cached entries.
The state indicating the component encountered a C++ exception.
virtual bool trigger()
Invoke this method to trigger the thread of this TaskContext to execute its ExecutionEngine and the u...
virtual bool configureHook()
Implement this method such that it contains the code which will be executed when configure() is calle...
virtual void updateHook()
Function where the user must insert his 'application' code.
virtual bool recover()
Call this method in a RunTimeError or Exception state to indicate that the run-time error conditions ...
virtual TaskState getTargetState() const
Returns the state this TaskCore is going to, or in case no transition is taking place, returns getTaskState().
virtual bool startHook()
Implement this method such that it contains the code which will be executed when start() is called...
virtual bool isActive() const =0
Query if the activity is started.
The state indicating that a run-time error has occured [red] and needs attention. ...
virtual bool isConfigured() const
Inspect if the component is configured, i.e.
virtual bool activate()
This method starts the ExecutionEngine of this component in case it was not running.
virtual bool setCpuAffinity(unsigned cpu)
Sets the cpu affinity of this component.
virtual void stopHook()
Implement this method such that it contains the code which will be executed when stop() is called...
virtual bool isRunning() const
Inspect if the component is in the Running or RunTimeError state.
virtual bool configure()
This method instructs the component to (re-)read configuration data and try to enter the Stopped stat...
virtual unsigned getCpuAffinity() const =0
Get the cpu affinity of this activity.
The state indicating additional configuration is required.
An execution engine serialises (executes one after the other) the execution of all commands...
virtual void error()
Call this method in a Running state to indicate a run-time error condition.
virtual Seconds getPeriod() const
Get the configured execution period of this component.
virtual bool inException() const
Inspect if the component is in the Exception state.
virtual bool inFatalError() const
Inspect if the component is in the FatalError state.
virtual void errorHook()
Implement this method to contain code that must be executed in the RunTimeError state, instead of updateHook().
virtual bool update()
Invoke this method to execute the ExecutionEngine and the update() method.
virtual bool setCpuAffinity(unsigned cpu)=0
Set the cpu affinity of this activity.
The state indicating the component encountered a fatal error and is unable to execute.
virtual void exceptionHook()
Implement this method to contain code that must be executed when transitioning to the Exception state...
virtual void fatal()
Call this method from any place to indicate that this component encountered a fatal error...
virtual void exception()
Call this method to indicate a run-time exception happend.
TaskState
Describes the different states a component can have.
base::TaskCore * getParent()
The base::TaskCore which created this ExecutionEngine.
virtual bool execute()=0
Execute this activity such that it executes a step or loop of the RunnableInterface.
virtual Seconds getPeriod() const =0
Get the periodicity of this activity in Seconds.
virtual bool breakUpdateHook()
Implement this function if your code might block for long times inside the updateHook() function...
virtual TaskState getTaskState() const
Returns the current state of the TaskCore.
virtual bool isActive() const
Inspect if the component's ExecutionEngine is processing requests.
virtual void cleanupHook()
Implement this method such that it contains the code which will be executed when cleanup() is called...
virtual bool inRunTimeError() const
Inspect if the component is in the RunTimeError state.
virtual void addChild(base::TaskCore *tc)
Add a base::TaskCore to execute.
The state indicating the component is running [green].
void setExecutionEngine(ExecutionEngine *engine)
Use this method to re-set the execution engine of this task core.
virtual unsigned getCpuAffinity() const
Get the configured cpu affinity of this component.
virtual bool start()=0
Start the activity.
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
The state indicating the component is ready to run.
virtual bool stop()
This method stops the execution of updateHook() of this component.
ExecutionEngine * ee
The execution engine which calls update() and processes our commands, events etc. ...
virtual bool setPeriod(Seconds s)
Sets the period of this component.
const ExecutionEngine * engine() const
Get a const pointer to the ExecutionEngine of this Task.
virtual bool cleanup()
This method instructs a stopped component to enter the pre-operational state again.
virtual void removeChild(base::TaskCore *tc)
Remove a base::TaskCore from execution.
TaskCore(TaskState initial_state=Stopped)
Create a TaskCore.
virtual bool start()
This method starts the execution of the updateHook() with each trigger or period. ...
virtual bool stop()=0
Stop the activity This will stop the activity by removing it from the 'run-queue' of a thread or call...