rad 6.2.0
Loading...
Searching...
No Matches
Executor.h
Go to the documentation of this file.
1
10/*
11 * scampl4cpp/engine
12 *
13 * Copyright by European Southern Observatory, 2012
14 * All rights reserved
15 *
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
20 *
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
25 *
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
29 * 02111-1307 USA.
30 */
31
32#ifndef SCXML4CPP_EXECUTOR_H
33#define SCXML4CPP_EXECUTOR_H
34
35#ifndef __cplusplus
36#error This is a C++ include file and cannot be used from plain C
37#endif
38
39#ifndef SCXML4CPP_STATECOMPARATOR_H
41#endif
42
43#ifndef SCXML4CPP_EVENTQUEUE_H
45#endif
46
47#ifndef SCXML4CPP_HELPER_H
48#include "scxml4cpp/Helper.h"
49#endif
50
51#include <queue>
52#include <list>
53#include <string>
54
55namespace scxml4cpp {
56
57class StateMachine;
58class State;
59class Transition;
60class Event;
61class EventQueue;
62class Context;
63class EventListener;
64class StatusListener;
65
73class Executor {
74 public:
83
91 Executor(StateMachine& stateMachine, Context* context, EventQueue& events);
92
96 ~Executor();
97
106 std::string formatStatus(const bool usefullyqualified = false);
107
111 std::string formatModel();
112
116 std::list<State*> getStatus();
117
123 void printStatus(const bool usefullyqualified = false);
124
130 void setContext(Context* context);
131
138
143
149 void addEventListener(EventListener* eventListener);
150
156 void removeEventListener(EventListener* eventListener);
157
162
168 void addStatusListener(StatusListener* statusListener);
169
175 void removeStatusListener(StatusListener* statusListener);
176
181
186 void startSM();
187
192 void stopSM();
193
197 void start();
198
202 void stop();
203
208 void run();
209
218 void postEvent(Event* e);
219
224 void processEvent();
225
232 void processEvent(Event* e);
233
237 bool isRunning();
238
242 bool isFinal();
243
244 private:
245 StateMachine& mStateMachine;
246
247 /*
248 * use std::list<State*> instead of std::set<State*>
249 * to preserve the insertion order.
250 *
251 * Note that std::set<> is ordered container and the default order
252 * is given by comparing the State* pointers. The values of the pointers
253 * depends on the memory allocation algorithm. Most of the times but NOT
254 * always new pointers have larger values.
255 *
256 * By using std::list we lose the check of already exiting elements
257 * in the container. However this check has only linear complexity.
258 * Better adding the check and keep the order, than keeping the check
259 * and have to sort again after.
260 */
261 std::list<State*> mCurrentStatus;
262 std::list<State*> mPreviousStatus;
263 std::list<State*> mStatesToInvoke;
264
265 std::queue<Event*> mInternalEvents;
266 EventQueue& mExternalEvents;
267 bool mContinue; // is interpreted started
268 bool mFinal; // is top level final state reached
269 StateComparator mStateComparator;
270 Context* mContext;
271 Helper mHelper;
272 EventHandlingPolicy mEventHandlingPolicy;
273 std::list<EventListener*> mEventListeners;
274 std::list<StatusListener*> mStatusListeners;
275
276 void addUniqueStateToList(State* s, std::list<State*>& l);
277
278 //void addStateToInvoke(State* s);
279 void addStateToCurrentStatus(State* s);
280
281 StateComparator& getStateComparator();
282 void processInternalEvents();
283 void exitInterpreter();
284 std::list<Transition*> selectEventlessTransitions();
285 std::list<Transition*> selectTransitions(Event* e);
286 void microstep(std::list<Transition*>& enabledTransitions);
287 void exitStates(std::list<Transition*>& enabledTransitions);
288 void executeTransitionContent(std::list<Transition*>& enabledTransitions);
289 void enterStates(std::list<Transition*>& enabledTransitions);
290 void addStatesToEnter(State* s, State* root, std::list<State*>& statesToEnter,
291 std::list<State*>& statesForDefaultEntry);
292
293 void notifyEventListeners(Event* e);
294 void notifyStatusListeners(std::list<State*>& status);
295
296 Executor(const Executor&);
297 Executor& operator=(const Executor&);
298};
299
300} // namespace scxml4cpp
301
302#endif // SCXML4CPP_EXECUTOR_H
EventQueue header.
Helper header.
StateComparator header.
Definition Context.h:58
Definition EventListener.h:57
Definition EventQueue.h:55
Definition Event.h:66
Definition Executor.h:73
std::string formatModel()
Definition Executor.cpp:140
void startSM()
Definition Executor.cpp:155
std::list< State * > getStatus()
Definition Executor.cpp:145
bool isRunning()
Definition Executor.cpp:299
void setEventHandlingPolicy(const EventHandlingPolicy policy)
Definition Executor.cpp:78
void removeAllStatusListener()
Definition Executor.cpp:125
void postEvent(Event *e)
Definition Executor.cpp:309
void processEvent()
Definition Executor.cpp:322
void stopSM()
Definition Executor.cpp:291
void setContext(Context *context)
Definition Executor.cpp:72
void removeAllEventListener()
Definition Executor.cpp:104
EventHandlingPolicy
Definition Executor.h:78
@ SILENT
Definition Executor.h:79
@ REJECT
Event is silently rejected if transition is not enabled.
Definition Executor.h:80
@ DEFFERRED
Event is rejected with notification, if transition is not enabled.
Definition Executor.h:81
void start()
Definition Executor.cpp:268
void removeStatusListener(StatusListener *statusListener)
Definition Executor.cpp:117
void stop()
Definition Executor.cpp:275
std::string formatStatus(const bool usefullyqualified=false)
Definition Executor.cpp:135
void printStatus(const bool usefullyqualified=false)
Definition Executor.cpp:150
void addStatusListener(StatusListener *statusListener)
Definition Executor.cpp:109
bool isFinal()
Definition Executor.cpp:304
EventHandlingPolicy getEventHandlingPolicy()
Definition Executor.cpp:83
void removeEventListener(EventListener *eventListener)
Definition Executor.cpp:96
void run()
Definition Executor.cpp:258
void addEventListener(EventListener *eventListener)
Definition Executor.cpp:88
~Executor()
Definition Executor.cpp:70
Definition Helper.h:57
Definition StateComparator.h:53
Definition StateMachine.h:64
Definition State.h:60
Definition StatusListener.h:60
Definition Action.cpp:36
Definition testCoroActivity.cpp:16
boost::asio::io_context::executor_type Executor
Definition testExecutorActivity.cpp:14