summaryrefslogtreecommitdiffstats
path: root/test/samples/w3c/Main.scxml
blob: 4c03631f5a8ce2d04f8b7545359d575e9d644bce (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<?xml version="1.0" encoding="utf-8"?>
<!-- A wrapper state that contains all other states in this file
- it represents the complete state machine -->
<scxml
       xmlns:xi="http://www.w3.org/2001/XInclude"
       version="1.0"
       initial="Main"
       datamodel="ecmascript">
  <state id="Main">
    <!-- its initial state is Test1 -->
    <initial>
      <transition target="Test1"/>
    </initial>

    <!-- Really simple state showing the basic syntax. -->
    <state id="Test1">
      <initial>
        <transition target="Test1Sub1"/>
      </initial>
      <!-- Runs before we go into the substate -->
      <onentry>
        <log expr="'Inside Test1'"/>
      </onentry>

      <!-- Here is our first substate -->
      <state id="Test1Sub1">
        <onentry>
          <log expr="'Inside Test1Sub1.'"/>
        </onentry>
        <onexit>
          <log expr="'Leaving Test1Sub1'"/>
        </onexit>
        <!-- Go to Sub2 on Event1 -->
        <transition event="Event1" target="Test1Sub2"/>
      </state>

      <!-- Here is the second substate
           It is final, so Test1 is done when we get here -->
      <final id="Test1Sub2"/>

      <!-- We get this event when we reach Test1Sub2. -->
      <transition event="Test1.done" target="Test2"/>

      <!-- We run this on the way out of Test1 -->
      <onexit>
        <log expr="'Leaving Test1...'"/>
      </onexit>
    </state>

    <state id="Test2">
      <initial>
        <transition target="Test2Sub1"/>
      </initial>

      <!-- This time we reference a state
           defined in an external file.   -->
       <xi:include href="Test2Sub1.xml" parse="text"/>

      <final id="Test2Sub2"/>

      <!-- Test2Sub2 is defined as final, so this
           event is generated when we reach it -->
      <transition event="done.state.Test2" next="Test3"/>
    </state>

    <state id="Test3">
      <initial>
        <transition target="Test3Sub1"/>
      </initial>

      <state id="Test3Sub1">
        <onentry>
          <log expr="'Inside Test3Sub1...'"/>
          <!-- Send our self an event in 5s -->
          <send event="'Timer'"  delay="'5s'"/>
        </onentry>
        <!-- Transition on to Test4.
             This will exit both us and our parent. -->
        <transition event="Timer" target="Test4"/>
        <onexit>
          <log expr="'Leaving Test3Sub1...'"/>
        </onexit>
      </state>

      <onexit>
        <log expr="'Leaving Test3...'"/>
      </onexit>
    </state>

    <state id="Test4">
      <onentry>
        <log expr="'Inside Test4...'"/>
      </onentry>
      <initial>
        <transition target="Test4Sub1"/>
      </initial>

      <state id="Test4Sub1">
        <onexit>
          <log expr="'Leaving Test4Sub1...'"/>
        </onexit>
        <!-- This transition causes the state to exit immediately
             after entering Test4Sub1.  The transition has no event
             or guard so it is always active -->
        <transition target="Test5"/>
      </state>
    </state>

    <state id="Test5">
      <onentry>
        <log expr="'Inside Test5...'"/>
      </onentry>
      <initial>
        <transition target="Test5P"/>
      </initial>

      <!-- Fire off parallel states.  In a more realistic example
      the parallel substates Test5PSub1 and Test5PSub2 would themselves
      have substates and would do some real work before transitioning to final substates -->
      <parallel id="Test5P">
        <state id="Test5PSub1" initial="Test5PSub1Final">
           <final id="Test5PSub1Final"/>
           </state>
        <state id="Test5PSub2" initial="Test5PSub2Final">
            <final id="Test5PSub2Final"/>
            </state>
        <onexit>
          <log expr="'all parallel states done'"/>
        </onexit>
      </parallel>

      <!-- The parallel states immediately transition to final substates,
      so this event is generated immediately.   -->
      <transition event="done.state.Test5P" target="Test6"/>
    </state>

    <!--
         - This state shows invocation of an external component.
         - We will use CCXML + VoiceXML actions as an example
         - as it is a good smoke test to show how it all
         - fits together.
         - Note: In a real app you would likely
         - split this over several states but we
         - are trying to keep it simple here.
    -->
    <state id="Test6"
           xmlns:ccxml="http://www.w3.org/2002/09/ccxml"
           xmlns:v3="http://www.w3.org/2005/07/vxml3">
      <datamodel>
        <data name="ccxmlid" expr="32459"/>
        <date name="v3id" expr="17620"/>
        <data name="dest" expr="'tel:+18315552020'"/>
        <data name="src" expr="'helloworld2.vxml'"/>
        <data name="id" expr="'HelloWorld'"/>
      </datamodel>

      <onentry>
        <!-- Use <send> a message to a CCXML Processor asking it to run createcall -->
        <send target="ccxmlid" type="basichttp" event="ccxml:createcall" namelist="dest"/>
      </onentry>

      <transition event="ccxml:connection.connected">
        <!-- Here as a platform-specific extension we use example V3
             Custom Action Elements instead of send. The implementation of this logic
             would be platform-dependent. -->
        <v3:form id="HelloWorld">
          <v3:block><v3:prompt>Hello World!</v3:prompt></v3:block>
        </v3:form>
      </transition>

      <transition event="v3:HelloWorld.done">
        <!-- Here we are using the low level <send>
             element to run a v3 form. Note that the event "v3:HelloWorld.done"
             is assumed either to be set/sent explicitly by the v3:form code or
             implicitly by some process outside of the v3:form -->
        <send target="v3id" type="basichttp" event="v3:formstart" namelist="src id"/>
      </transition>

      <transition event="v3:HelloWorld2.done">
        <!-- we use _event.data to access data in the event we're processing.
             Again we assume the v3:HelloWorld2.done is set/sent from outside
             this document -->
        <ccxml:disconnect connectionid="_event.data.connectionid"/>
      </transition>

      <transition event="ccxml:connection.disconnected" target="Done"/>

      <transition event="send.failed" target="Done">
        <!-- If we get an error event we move to the Done state that
             is a final state. -->
        <log expr="'Sending to and External component failed'"/>
      </transition>

      <onexit>
        <log expr="'Finished with external component'"/>
      </onexit>
    </state>

    <!-- This final state is an immediate child of Main
         -  when we get here, Main.done is generated. -->
    <final id="Done"/>
    <!-- End of Main > -->
  </state>
</scxml>