summaryrefslogtreecommitdiffstats
path: root/test/bindings/java/org/uscxml/examples/MonitorExample.java
blob: dc4cffacee0a6b6816c2d9f23a3ea86f2b21f571 (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
package org.uscxml.examples;

import org.uscxml.Interpreter;
import org.uscxml.InterpreterException;
import org.uscxml.InterpreterState;
import org.uscxml.StringVector;
import org.uscxml.helper.TestMonitor;


public class MonitorExample {
	
	public static void main(String[] args) {
		
		String uSCXMLLibPath = "/Users/sradomski/Documents/TK/Code/uscxml/build/cli/lib/libuscxmlNativeJava.jnilib"; 
		if (System.getenv().containsKey("USCXML_JAVA_LIB")) {
			uSCXMLLibPath = System.getenv("USCXML_JAVA_LIB");
		}
		
		System.load(uSCXMLLibPath);
		
		try {
			TestMonitor tm = new TestMonitor();
			Interpreter scxml = Interpreter.fromURL("https://raw.githubusercontent.com/tklab-tud/uscxml/master/test/w3c/null/test436.scxml");
			scxml.addMonitor(tm);
			InterpreterState state = InterpreterState.USCXML_UNDEF;
			while((state = scxml.step()) != InterpreterState.USCXML_FINISHED) {
				switch (state) {
				case USCXML_FINISHED:
				case USCXML_UNDEF:
				case USCXML_IDLE:
				case USCXML_INITIALIZED:
				case USCXML_INSTANTIATED:
					break;
				case USCXML_MICROSTEPPED:
				case USCXML_MACROSTEPPED:
					StringVector states = scxml.getConfiguration();
					for (int i = 0; i < states.size(); i++) {
						System.out.print(states.get(i) + " ");
					}
					System.out.println();
				case USCXML_CANCELLED:
					break;
				default:
					break;
				}
			}
			
		} catch (InterpreterException e) {
			e.printStackTrace();
			System.exit(-1);
		}
		System.exit(0);
	}

}