summaryrefslogtreecommitdiffstats
path: root/src/uscxml/interpreter/MicroStepImpl.h
blob: 71c03b5831b737cd98820419a161a42270922382 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
 *  @file
 *  @author     2016 Stefan Radomski (stefan.radomski@cs.tu-darmstadt.de)
 *  @copyright  Simplified BSD
 *
 *  @cond
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the FreeBSD license as published by the FreeBSD
 *  project.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 *  You should have received a copy of the FreeBSD license along with this
 *  program. If not, see <http://www.opensource.org/licenses/bsd-license>.
 *  @endcond
 */

#ifndef MICROSTEPIMPL_H_98233709
#define MICROSTEPIMPL_H_98233709

#include <memory>
#include <mutex>
#include <list>
#include <map>
#include <string>

#include "uscxml/Common.h"
#include "uscxml/messages/Event.h"
#include "uscxml/interpreter/InterpreterMonitor.h"
#include "uscxml/util/DOM.h"
#include <xercesc/dom/DOM.hpp>

namespace uscxml {

enum InterpreterState {


	USCXML_FINISHED       = -2,  ///< machine reached a final configuration and is done
	USCXML_INTERRUPTED    = -1,  ///< machine received the empty event on the external queue
	USCXML_UNDEF          = 0,   ///< not an actual state
	USCXML_IDLE           = 1,   ///< stable configuration and queues empty
	USCXML_INITIALIZED    = 2,   ///< DOM is setup and all external components instantiated
	USCXML_INSTANTIATED   = 3,   ///< nothing really, just instantiated
	USCXML_MICROSTEPPED   = 4,   ///< processed one transition set
	USCXML_MACROSTEPPED   = 5,   ///< processed all transition sets and reached a stable configuration
	USCXML_CANCELLED      = 6,   ///< machine was cancelled, step once more to finalize
};

class USCXML_API MicroStepCallbacks {
public:
	/** Event Queues / Matching */
	virtual Event dequeueInternal() = 0;
	virtual Event dequeueExternal(bool blocking) = 0;
	virtual bool isMatched(const Event& event, const std::string& eventDesc) = 0;
	virtual void raiseDoneEvent(xercesc::DOMElement* state, xercesc::DOMElement* doneData) = 0;

	/** Datamodel */
	virtual bool isTrue(const std::string& expr) = 0;
	virtual void initData(xercesc::DOMElement* element) = 0;

	/** Executable Content */
	virtual void process(xercesc::DOMElement* block) = 0;

	/** Invocations */
	virtual void invoke(xercesc::DOMElement* invoke) = 0;
	virtual void uninvoke(xercesc::DOMElement* invoke) = 0;

	/** Monitoring */
	virtual InterpreterMonitor* getMonitor() = 0;
};

class USCXML_API MicroStepImpl {
public:
	enum Binding {
		EARLY = 0,
		LATE = 1
	};

	MicroStepImpl(MicroStepCallbacks* callbacks) : _callbacks(callbacks) {}

	virtual InterpreterState step(bool blocking) = 0;
	virtual void reset() = 0; ///< Reset state machine
	virtual bool isInState(const std::string& stateId) = 0;
	virtual std::list<xercesc::DOMElement*> getConfiguration() = 0;

	virtual void init(xercesc::DOMElement* scxml) = 0;
	virtual void markAsCancelled() = 0;

protected:
	MicroStepCallbacks* _callbacks;

};

class USCXML_API MicroStep {
public:
	PIMPL_OPERATORS(MicroStep)

	virtual InterpreterState step(bool blocking) {
		return _impl->step(blocking);
	}
	virtual void reset() {
		return _impl->reset();
	}
	virtual bool isInState(const std::string& stateId) {
		return _impl->isInState(stateId);
	}

	std::list<xercesc::DOMElement*> getConfiguration() {
		return _impl->getConfiguration();
	}

	virtual void init(xercesc::DOMElement* scxml) {
		_impl->init(scxml);
	}

	virtual void markAsCancelled() {
		_impl->markAsCancelled();
	}
protected:
	std::shared_ptr<MicroStepImpl> _impl;
};

}

#endif /* end of include guard: MICROSTEPIMPL_H_98233709 */