YARP
Yet Another Robot Platform
execstate.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #ifndef YARP_MANAGER_Exec_State
10 #define YARP_MANAGER_Exec_State
11 
12 #include <yarp/manager/fsm.h>
13 #include <yarp/conf/api.h>
14 
15 
16 namespace yarp {
17 namespace manager {
18 
19 class Executable;
20 
21 
26 {
27 public:
28  virtual ~ITransition() = default;
29  virtual void kill() = 0;
30  virtual void moduleFailed() = 0;
31  virtual void refresh() {}
32  virtual void connectionFailed(void* which) {}
33  virtual void start() {}
34  virtual void stop() {}
35  virtual void startModule() {}
36  virtual void stopModule() {}
37  virtual void killModule() {}
38  virtual void connectAllPorts() {}
39  virtual void disconnectAllPorts() {}
40 };
41 
42 
44 {
45 public:
60 };
61 
62 
66 class Suspended : public ITransition, public FSM::StateBase
67 {
68 public:
69  Suspended(Executable* pExecutable, FSM::IEventSink* pEventSink);
70  ~Suspended() override;
71 
72 public:
73  void start() override;
74  void stop() override;
75  void kill() override;
76  void refresh() override;
77  void moduleFailed() override;
78 
79 public:
81 };
82 
83 
87 class Ready : public ITransition, public FSM::StateBase
88 {
89 public:
90  Ready(Executable* pExecutable, FSM::IEventSink* pEventSink);
91  ~Ready() override;
92 
93 public:
94  void kill() override;
95  void startModule() override;
96  void moduleFailed() override;
97 
98 private:
99  Executable* executable;
100  bool bAborted;
101  bool checkPriorityPorts();
102  bool checkResources(bool silent=true);
103  bool timeout(double base, double timeout);
104 };
105 
106 
107 
111 class Connecting : public ITransition, public FSM::StateBase
112 {
113 public:
114  Connecting(Executable* pExecutable, FSM::IEventSink* pEventSink);
115  ~Connecting() override;
116 
117 public:
118  void refresh() override;
119  void kill() override;
120  void connectAllPorts() override;
121  void moduleFailed() override;
122 
123 private:
124  Executable* executable;
125  bool checkNormalPorts();
126  bool bAborted;
127 };
128 
129 
130 
134 class Running : public ITransition, public FSM::StateBase
135 {
136 public:
137  Running(Executable* pExecutable, FSM::IEventSink* pEventSink);
138  ~Running() override;
139 
140 public:
141  void refresh() override;
142  void kill() override;
143  void start() override;
144  void stop() override;
145  void moduleFailed() override;
146  void connectionFailed(void* which) override;
147 
148 private:
149  Executable* executable;
150 };
151 
152 
156 class Dying : public ITransition, public FSM::StateBase
157 {
158 public:
159  Dying(Executable* pExecutable, FSM::IEventSink* pEventSink);
160  ~Dying() override;
161 
162 public:
163  void refresh() override;
164  void kill() override;
165  void moduleFailed() override;
166  void stopModule() override;
167  void killModule() override;
168  void disconnectAllPorts() override;
169 
170 private:
171  Executable* executable;
172 };
173 
174 
178 class Dead : public ITransition, public FSM::StateBase
179 {
180 public:
181  Dead(Executable* pExecutable, FSM::IEventSink* pEventSink);
182  ~Dead() override;
183 
184 public:
185  void start() override;
186  void stop() override;
187  void kill() override;
188  void refresh() override;
189  void moduleFailed() override;
190 
191 private:
192  Executable* executable;
193 };
194 
195 
200 {
201 public:
202  ExecMachine(Executable* pExecutable);
203  ~ExecMachine() override;
204 
205  void refresh();
206  void start();
207  void stop();
208  void kill();
209  void startModule();
210  void stopModule();
211  void killModule();
212  void connectAllPorts();
213  void disconnectAllPorts();
214  void moduleFailed();
215  void connectionFailed(void* which);
216 
217 protected:
218  void onTransition(FSM::StateBase* previous,
219  FSM::Event* event, FSM::StateBase* current) override;
220 
221 private:
222  Executable* executable;
223  Running* running;
224  Suspended* suspended;
225  Ready* ready;
226  Connecting* connecting;
227  Dead* dead;
228  Dying* dying;
229 };
230 
231 } // namespace yarp
232 } // namespace manager
233 
234 
235 #endif // __YARP_MANAGER_Exec_State__
yarp::manager::EventFactory::disconnectAllPortsEventOk
static FSM::Event * disconnectAllPortsEventOk
Definition: execstate.h:59
yarp::manager::Connecting::kill
void kill() override
Definition: execstate.cpp:322
yarp::manager::Running::kill
void kill() override
Definition: execstate.cpp:370
yarp::manager::Suspended::~Suspended
~Suspended() override
yarp::manager::Connecting
class Connecting
Definition: execstate.h:112
yarp::manager::Connecting::refresh
void refresh() override
Definition: execstate.cpp:312
yarp::manager::Connecting::connectAllPorts
void connectAllPorts() override
Definition: execstate.cpp:276
yarp::manager::Dead::Dead
Dead(Executable *pExecutable, FSM::IEventSink *pEventSink)
Class Dead.
Definition: execstate.cpp:496
yarp::manager::EventFactory::connectAllPortsEventOk
static FSM::Event * connectAllPortsEventOk
Definition: execstate.h:57
yarp::manager::EventFactory::stopEvent
static FSM::Event * stopEvent
Definition: execstate.h:47
yarp::manager::ExecMachine::startModule
void startModule()
Definition: execstate.cpp:648
FSM::Event
class IEventSink
Definition: fsm.h:32
yarp::manager::ExecMachine::~ExecMachine
~ExecMachine() override
Definition: execstate.cpp:606
yarp::manager::EventFactory::killModuleEventOk
static FSM::Event * killModuleEventOk
Definition: execstate.h:55
yarp::manager::ExecMachine::disconnectAllPorts
void disconnectAllPorts()
Definition: execstate.cpp:680
yarp::manager::EventFactory::recoverEvent
static FSM::Event * recoverEvent
Definition: execstate.h:50
yarp::manager::EventFactory::startModuleEventFailed
static FSM::Event * startModuleEventFailed
Definition: execstate.h:52
yarp::manager::EventFactory::startModuleEventOk
static FSM::Event * startModuleEventOk
Definition: execstate.h:51
yarp::manager::ITransition::~ITransition
virtual ~ITransition()=default
yarp::manager::EventFactory::stopModuleEventOk
static FSM::Event * stopModuleEventOk
Definition: execstate.h:53
yarp::manager::Suspended::stop
void stop() override
Definition: execstate.cpp:58
yarp::manager::Dead
class Dead
Definition: execstate.h:179
yarp::manager::Dying::disconnectAllPorts
void disconnectAllPorts() override
Definition: execstate.cpp:445
yarp::manager::EventFactory::connectAllPortsEventFailed
static FSM::Event * connectAllPortsEventFailed
Definition: execstate.h:58
yarp::manager::ITransition
all transitions are used in state machine
Definition: execstate.h:26
yarp::manager::Connecting::Connecting
Connecting(Executable *pExecutable, FSM::IEventSink *pEventSink)
Class Connecting.
Definition: execstate.cpp:254
yarp::manager::Running::moduleFailed
void moduleFailed() override
Definition: execstate.cpp:375
yarp::manager::EventFactory::stopModuleEventFailed
static FSM::Event * stopModuleEventFailed
Definition: execstate.h:54
yarp::manager::ITransition::killModule
virtual void killModule()
Definition: execstate.h:37
yarp::manager::Running::start
void start() override
Definition: execstate.cpp:359
yarp::manager::Running::Running
Running(Executable *pExecutable, FSM::IEventSink *pEventSink)
Class Running.
Definition: execstate.cpp:339
yarp::manager::Suspended::start
void start() override
Definition: execstate.cpp:53
yarp::manager::Ready::kill
void kill() override
Definition: execstate.cpp:242
yarp::manager::ExecMachine::moduleFailed
void moduleFailed()
Definition: execstate.cpp:688
yarp::manager::Running::refresh
void refresh() override
Definition: execstate.cpp:348
yarp::manager::ITransition::startModule
virtual void startModule()
Definition: execstate.h:35
yarp::manager::Suspended::moduleFailed
void moduleFailed() override
Definition: execstate.cpp:68
yarp::manager::ITransition::moduleFailed
virtual void moduleFailed()=0
yarp::manager::Dying::stopModule
void stopModule() override
Definition: execstate.cpp:399
yarp::manager::ITransition::stop
virtual void stop()
Definition: execstate.h:34
yarp::manager::Dying::kill
void kill() override
Definition: execstate.cpp:480
yarp::manager::Dead::moduleFailed
void moduleFailed() override
Definition: execstate.cpp:537
yarp::manager::ITransition::stopModule
virtual void stopModule()
Definition: execstate.h:36
yarp::manager::Dead::~Dead
~Dead() override
yarp::manager::ExecMachine::kill
void kill()
Definition: execstate.cpp:640
yarp::manager::Running
class Running
Definition: execstate.h:135
yarp::manager::ExecMachine::onTransition
void onTransition(FSM::StateBase *previous, FSM::Event *event, FSM::StateBase *current) override
Callback onTransition represents the change in the states.
Definition: execstate.cpp:705
yarp::manager::ExecMachine::stop
void stop()
Definition: execstate.cpp:632
yarp::manager::Suspended::executable
Executable * executable
Definition: execstate.h:80
yarp::manager::Ready::Ready
Ready(Executable *pExecutable, FSM::IEventSink *pEventSink)
Class Ready.
Definition: execstate.cpp:90
yarp::manager::Suspended::kill
void kill() override
Definition: execstate.cpp:63
yarp::manager::Dying::Dying
Dying(Executable *pExecutable, FSM::IEventSink *pEventSink)
Class Dying.
Definition: execstate.cpp:390
yarp::manager::Ready::startModule
void startModule() override
Definition: execstate.cpp:172
yarp::manager::EventFactory::failedEvent
static FSM::Event * failedEvent
Definition: execstate.h:49
yarp::manager::Suspended::Suspended
Suspended(Executable *pExecutable, FSM::IEventSink *pEventSink)
Class Suspended.
Definition: execstate.cpp:44
FSM::StateBase
Class StateBase.
Definition: fsm.h:80
yarp::manager::Dead::stop
void stop() override
Definition: execstate.cpp:510
yarp::manager::Ready::moduleFailed
void moduleFailed() override
Definition: execstate.cpp:248
yarp::manager::ITransition::disconnectAllPorts
virtual void disconnectAllPorts()
Definition: execstate.h:39
yarp::manager::Dead::kill
void kill() override
Definition: execstate.cpp:516
yarp::manager::Suspended::refresh
void refresh() override
Definition: execstate.cpp:73
FSM::StateMachineBase
Class StateMachineBase.
Definition: fsm.h:110
yarp::manager::ExecMachine::connectAllPorts
void connectAllPorts()
Definition: execstate.cpp:672
yarp::manager::EventFactory
Definition: execstate.h:44
yarp::manager::Running::connectionFailed
void connectionFailed(void *which) override
Definition: execstate.cpp:381
yarp::manager::ITransition::kill
virtual void kill()=0
yarp::manager::Dying::~Dying
~Dying() override
yarp::manager::Running::stop
void stop() override
Definition: execstate.cpp:365
yarp::manager::ExecMachine::killModule
void killModule()
Definition: execstate.cpp:664
fsm.h
yarp::manager::EventFactory::startEvent
static FSM::Event * startEvent
Initializing event factory.
Definition: execstate.h:46
yarp::manager::Dying
class Dying
Definition: execstate.h:157
FSM::IEventSink
class IEventSink
Definition: fsm.h:59
yarp::manager::ITransition::connectAllPorts
virtual void connectAllPorts()
Definition: execstate.h:38
yarp::manager::Dying::killModule
void killModule() override
Definition: execstate.cpp:424
yarp::manager::ExecMachine::refresh
void refresh()
Definition: execstate.cpp:616
yarp::manager::Suspended
class Suspended
Definition: execstate.h:67
yarp::manager::Running::~Running
~Running() override
yarp::manager::ITransition::start
virtual void start()
Definition: execstate.h:33
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::manager::EventFactory::killEvent
static FSM::Event * killEvent
Definition: execstate.h:48
yarp::manager::Dead::start
void start() override
Definition: execstate.cpp:505
yarp::manager::ExecMachine::start
void start()
Definition: execstate.cpp:624
yarp::manager::ExecMachine::ExecMachine
ExecMachine(Executable *pExecutable)
Class ExecMachine.
Definition: execstate.cpp:544
yarp::manager::Dying::moduleFailed
void moduleFailed() override
Definition: execstate.cpp:482
yarp::manager::EventFactory::killModuleEventFailed
static FSM::Event * killModuleEventFailed
Definition: execstate.h:56
yarp::manager::ITransition::connectionFailed
virtual void connectionFailed(void *which)
Definition: execstate.h:32
yarp::manager::ITransition::refresh
virtual void refresh()
Definition: execstate.h:31
yarp::manager::Dying::refresh
void refresh() override
Definition: execstate.cpp:469
yarp::manager::Connecting::~Connecting
~Connecting() override
yarp::manager::Connecting::moduleFailed
void moduleFailed() override
Definition: execstate.cpp:328
yarp::manager::Ready::~Ready
~Ready() override
yarp::manager::ExecMachine
Class ExecMachine.
Definition: execstate.h:200
api.h
yarp::manager::ExecMachine::stopModule
void stopModule()
Definition: execstate.cpp:656
yarp::manager::ExecMachine::connectionFailed
void connectionFailed(void *which)
Definition: execstate.cpp:696
yarp::manager::Executable
Class Executable.
Definition: executable.h:75
yarp::manager::Ready
class Ready
Definition: execstate.h:88
yarp::manager::Dead::refresh
void refresh() override
Definition: execstate.cpp:523