EEROS  0.4.1.0
API for the EEROS Real-Time Robotics Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Sequence.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_SEQUENCER_SEQUENCE_HPP_
2 #define ORG_EEROS_SEQUENCER_SEQUENCE_HPP_
3 
4 #include <string>
5 #include <map>
6 #include <functional>
7 #include <vector>
8 #include <mutex>
9 #include <condition_variable>
10 #include <atomic>
11 
12 #include <eeros/logger/Logger.hpp>
16 
17 namespace eeros {
18  namespace sequencer {
19 
20  // Base class
21  class SequenceBase {
22 
24 
25  public:
26  SequenceBase(std::string name, Sequencer* sequencer);
27 
28  virtual std::string getName() const;
29  virtual bool checkPreCondition();
30  virtual bool checkPostCondition();
31 
32  protected:
33  virtual void yield();
34 
35  virtual void init();
36  virtual void exit();
37 
39  std::string name;
41  };
42 
43  // Class template Sequence
44  template<typename Treturn = void, typename ... Targs>
45  class Sequence : public SequenceBase {
46 
47  public:
48  Sequence(std::string name, Sequencer* sequencer) : SequenceBase(name, sequencer) { }
49 
51  init();
52  yield();
53 
54  if(!checkPreCondition())
56 
57  yield();
58  Treturn res = run(args...);
59  yield();
60 
61  if(!checkPostCondition())
63 
64  yield();
65  exit();
66 
68  }
69 
70  protected:
71  virtual Treturn run(Targs... args) { }
72  };
73 
74  // Specializations for class template Sequence
75  template<typename ... Targs>
76  class Sequence<void, Targs...> : public SequenceBase {
77 
78  public:
79  Sequence(std::string name, Sequencer* sequencer) : SequenceBase(name, sequencer) { }
80 
81  SequenceResult<void> operator()(Targs ... args) {
82  init();
83  yield();
84 
85  if(!checkPreCondition())
87 
88  yield();
89  run(args...);
90  yield();
91 
92  if(!checkPostCondition())
94 
95  yield();
96  exit();
97 
99  }
100 
101  protected:
102  virtual void run(Targs... args) { }
103  };
104 
105  template<>
106  class Sequence<void> : public SequenceBase {
107 
108  public:
109  Sequence(std::string name, Sequencer* sequencer) : SequenceBase(name, sequencer) {
110  sequencer->addCmdSequence(this);
111  }
112 
114  init();
115  yield();
116 
117  if(!checkPreCondition())
119 
120  yield();
121  run();
122  yield();
123 
124  if(!checkPostCondition())
126 
127  yield();
128  exit();
129 
131  }
132 
133  protected:
134  virtual void run() { }
135  };
136  }; // namespace sequencer
137 }; // namespace eeros
138 
139 #endif // ORG_EEROS_SEQUENCER_SEQUENCE_HPP_
virtual Treturn run(Targs...args)
Definition: Sequence.hpp:71
virtual void init()
Definition: Sequence.cpp:24
SequenceBase(std::string name, Sequencer *sequencer)
Definition: Sequence.cpp:5
Definition: Sequence.hpp:45
virtual std::string getName() const
Definition: Sequence.cpp:7
virtual void addCmdSequence(Sequence< void > *seq)
Definition: Sequencer.cpp:152
Definition: SequenceResult.hpp:7
Definition: SequenceResult.hpp:27
Sequence(std::string name, Sequencer *sequencer)
Definition: Sequence.hpp:109
Sequence(std::string name, Sequencer *sequencer)
Definition: Sequence.hpp:48
eeros::logger::Logger< eeros::logger::LogWriter > log
Definition: Sequence.hpp:38
Definition: Sequence.hpp:21
Definition: SequenceResult.hpp:7
SequenceResult< Treturn > operator()(Targs...args)
Definition: Sequence.hpp:50
Sequence(std::string name, Sequencer *sequencer)
Definition: Sequence.hpp:79
SequenceResult< void > operator()()
Definition: Sequence.hpp:113
Definition: SequenceResult.hpp:7
Definition: SequenceResult.hpp:17
virtual void run()
Definition: Sequence.hpp:134
virtual bool checkPreCondition()
Definition: Sequence.cpp:11
Definition: Sequencer.hpp:26
Sequencer * sequencer
Definition: Sequence.hpp:40
virtual bool checkPostCondition()
Definition: Sequence.cpp:14
virtual void exit()
Definition: Sequence.cpp:26
std::string name
Definition: Sequence.hpp:39
SequenceResult< void > operator()(Targs...args)
Definition: Sequence.hpp:81
virtual void yield()
Definition: Sequence.cpp:18
virtual void run(Targs...args)
Definition: Sequence.hpp:102