summaryrefslogtreecommitdiffstats
path: root/test/uscxml/test-invoke-communication.scxml
blob: 8d277efd9d71c4fd3bd8ab67db6285d583095fc2 (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
<scxml>
	<!-- invoke and communicate on entry - will fail -->
	<state id="send.onentry">
		<invoke type="scxml" 
						id="send.onentry.invoker"
						src="test-invoke-communication-invoker.scxml" />
		
		<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" 
						src="test-invoke-communication-invoker.scxml" />
		
		<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"  
						src="test-invoke-communication-invoker.scxml" />
		
		<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" 
						src="test-invoke-communication-invoker.scxml" />
		
		<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>