summaryrefslogtreecommitdiffstats
path: root/test/uscxml/test-invoke-communication-invoker.scxml
blob: 98d089d2c8da23b37db5f8e90c1d9a89e2753aea (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
<scxml>
	<!-- invoke and communicate on entry - will fail -->
	<state id="send.onentry">
		<invoke type="scxml" id="send.onentry.invoker">
			<content>
				<scxml>
					<state>
						<transition event="finish" target="done" />
					</state>
					<final id="done"/>
				</scxml>
			</content>
		</invoke>
		
		<onentry>
			<!-- This will fail as invoker is not yet instantiated -->
			<send target="#_send.onentry.invoker" event="finish"/>
		</onentry>
		
		<transition event="done.invoke.send.onentry.invoker" target="send.onentry.pass" />
		<transition event="error.communication" target="send.onentry.fail" />
	</state>

	<state id="send.onentry.pass">
		<transition target="external.event" />
	</state>
	<state id="send.onentry.fail">
		<transition target="external.event" />
	</state>
	
	
	<!-- Invoke and send an event to the external queue which will trigger communication -->
	<state id="external.event">
		<invoke type="scxml" id="external.event.invoker">
			<content>
				<scxml>
					<state>
						<transition event="finish" target="done" />
					</state>
					<final id="done"/>
				</scxml>
			</content>
		</invoke>
		
		<onentry>
			<send event="send.to.invoker"/>
		</onentry>
		<transition type="internal" event="send.to.invoker">
			<!-- This will succeed as invoker was instantiated -->
			<send target="#_external.event.invoker" event="finish"/>
		</transition>
		
		<transition event="done.invoke.external.event.invoker" target="external.event.pass" />
		<transition event="error.communication" target="external.event.fail" />
		
	</state>
	
	<state id="external.event.pass">
		<transition target="delayed.event" />
	</state>
	<state id="external.event.fail">
		<transition target="delayed.event" />
	</state>
	
	<!-- invoke and communicate delayed on entry - will succeed -->
	<state id="delayed.event">
		<invoke type="scxml" id="delayed.event.invoker">
			<content>
				<scxml>
					<state>
						<transition event="finish" target="done" />
					</state>
					<final id="done"/>
				</scxml>
			</content>
		</invoke>
		
		<onentry>
			<!-- This will succeed as the invoker will be instantiated in 1ms (invoking is synchronous) -->
			<send target="#_delayed.event.invoker" event="finish" delay="1ms"/>
		</onentry>
		
		<transition event="done.invoke.delayed.event.invoker" target="delayed.event.pass" />
		<transition event="error.communication" target="delayed.event.fail" />
	</state>

	<state id="delayed.event.pass">
		<transition target="callback.event" />		
	</state>
	<state id="delayed.event.fail">
		<transition target="callback.event" />
	</state>

	<!-- invoke with callback event (out of spec, but so useful!) -->
	<state id="callback.event">
		<invoke type="scxml" id="callback.event.invoker" callback="init">
			<content>
				<scxml>
					<state>
						<transition event="finish" target="done" />
					</state>
					<final id="done"/>
				</scxml>
			</content>
		</invoke>
		
		<transition event="init.callback.event.invoker">
			<send target="#_callback.event.invoker" event="finish" />
		</transition>
		
		<transition event="done.invoke.callback.event.invoker" target="callback.event.pass" />
		<transition event="error.communication" target="callback.event.fail" />
	</state>

	<final id="callback.event.pass" />
	<final id="callback.event.fail" />
	
</scxml>