Orocos Real-Time Toolkit  2.9.0
TaskCore.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: FMTC do nov 2 13:06:07 CET 2006 TaskCore.hpp
3 
4  TaskCore.hpp - description
5  -------------------
6  begin : do november 02 2006
7  copyright : (C) 2006 FMTC
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * This library is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU General Public *
13  * License as published by the Free Software Foundation; *
14  * version 2 of the License. *
15  * *
16  * As a special exception, you may use this file as part of a free *
17  * software library without restriction. Specifically, if other files *
18  * instantiate templates or use macros or inline functions from this *
19  * file, or you compile this file and link it with other files to *
20  * produce an executable, this file does not by itself cause the *
21  * resulting executable to be covered by the GNU General Public *
22  * License. This exception does not however invalidate any other *
23  * reasons why the executable file might be covered by the GNU General *
24  * Public License. *
25  * *
26  * This library is distributed in the hope that it will be useful, *
27  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
28  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
29  * Lesser General Public License for more details. *
30  * *
31  * You should have received a copy of the GNU General Public *
32  * License along with this library; if not, write to the Free Software *
33  * Foundation, Inc., 59 Temple Place, *
34  * Suite 330, Boston, MA 02111-1307 USA *
35  * *
36  ***************************************************************************/
37 
38 
39 #ifndef ORO_TASK_CORE_HPP
40 #define ORO_TASK_CORE_HPP
41 
42 #include <string>
43 #include "../rtt-fwd.hpp"
44 #include "../rtt-config.h"
45 #include "../Time.hpp"
46 
47 namespace RTT
48 { namespace base {
49 
55  {
56  public:
99  enum TaskState {
100  Init
101  ,PreOperational
102  ,FatalError
103  ,Exception
104  ,Stopped
105  ,Running
106  ,RunTimeError
107  };
108 
116  TaskCore( TaskState initial_state = Stopped );
117 
118  virtual ~TaskCore();
119 
128  virtual TaskState getTaskState() const;
129 
143  virtual TaskState getTargetState() const;
144 
158  virtual bool configure();
159 
167  virtual bool activate();
168 
178  virtual bool start();
179 
186  virtual bool stop();
187 
193  virtual bool cleanup();
194 
199  virtual bool isConfigured() const;
200 
206  virtual bool isActive() const;
207 
214  virtual bool isRunning() const;
215 
226  virtual Seconds getPeriod() const;
227 
234  virtual bool setPeriod(Seconds s);
235 
240  virtual unsigned getCpuAffinity() const;
241 
247  virtual bool setCpuAffinity(unsigned cpu);
248 
254  virtual bool inFatalError() const;
255 
259  virtual bool inException() const;
260 
264  virtual bool inRunTimeError() const;
265 
272  virtual bool update();
273 
280  virtual bool trigger();
281 
288  virtual void error();
289 
297  virtual bool recover();
298 
306  const ExecutionEngine* engine() const
307  {
308  return ee;
309  }
310 
315  {
316  return ee;
317  }
318 
324  unsigned int getCycleCounter() const { return mCycleCounter; }
328  unsigned int getTriggerCounter() const { return mTriggerCounter; }
332  unsigned int getIOCounter() const { return mIOCounter; }
336  unsigned int getTimeOutCounter() const { return mTimeOutCounter; }
337 
338  protected:
349  virtual bool configureHook();
350 
356  virtual void cleanupHook();
357 
367  virtual bool startHook();
368 
380  virtual void updateHook();
381 
390  virtual bool breakUpdateHook();
391 
399  virtual void errorHook();
400 
408  virtual void exceptionHook();
409 
410 
416  virtual void stopHook();
417 
424  virtual void fatal();
425 
434  virtual void exception();
435 
436  // Required to set mTaskState to Running, Stopped or Exception.
437  // As an alternative, one could query the EE.
438  friend class ::RTT::ExecutionEngine;
439 
445 
447 
448  private:
453  TaskState const mInitialState;
458  TaskState mTargetState;
459 
460  // non copyable
461  TaskCore( TaskCore& );
462 
463  friend class TaskContext;
464 
465  protected:
470 
476  unsigned int mCycleCounter;
480  unsigned int mIOCounter;
484  unsigned int mTimeOutCounter;
488  unsigned int mTriggerCounter;
489  };
490 }}
491 
492 #endif
double Seconds
Seconds are stored as a double precision float.
Definition: Time.hpp:53
The minimal Orocos task.
Definition: TaskCore.hpp:54
ExecutionEngine * engine()
Get a pointer to the ExecutionEngine of this Task.
Definition: TaskCore.hpp:314
TaskState mTaskState
Definition: TaskCore.hpp:446
#define RTT_API
Definition: rtt-config.h:97
unsigned int mCycleCounter
For each update cycle, this counter increments by one.
Definition: TaskCore.hpp:476
unsigned int mIOCounter
Number of cycles that were caused by IOReady triggers.
Definition: TaskCore.hpp:480
An execution engine serialises (executes one after the other) the execution of all commands...
unsigned int getCycleCounter() const
For each update cycle, this counter increments by one.
Definition: TaskCore.hpp:324
unsigned int mTimeOutCounter
Number of cycles that were caused by TimeOut triggers.
Definition: TaskCore.hpp:484
bool mTriggerOnStart
Set to false in order to not trigger() when calling start().
Definition: TaskCore.hpp:469
TaskState
Describes the different states a component can have.
Definition: TaskCore.hpp:99
unsigned int getTimeOutCounter() const
Number of cycles that were caused by TimeOut triggers.
Definition: TaskCore.hpp:336
The TaskContext is the C++ representation of an Orocos component.
Definition: TaskContext.hpp:93
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
Definition: Activity.cpp:52
ExecutionEngine * ee
The execution engine which calls update() and processes our commands, events etc. ...
Definition: TaskCore.hpp:444
unsigned int getIOCounter() const
Number of cycles that were caused by IOReady triggers.
Definition: TaskCore.hpp:332
unsigned int getTriggerCounter() const
Number of cycles that were caused by Trigger triggers.
Definition: TaskCore.hpp:328
unsigned int mTriggerCounter
Number of cycles that were caused by Trigger triggers.
Definition: TaskCore.hpp:488
const ExecutionEngine * engine() const
Get a const pointer to the ExecutionEngine of this Task.
Definition: TaskCore.hpp:306