Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9f05cef554f5e8be695347eb3f94e7c5ad9ffb3b (plain) (blame)
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
RoomModel DynamicActorTest4 {
	
	import room.basic.types.int32
	import room.basic.types.string
	import room.basic.test.TestInstance

	ActorClass Appl {
		@TestInstance
		Structure {
			ActorRef cont: Container
		}
		Behavior {
		}
	}

	ActorClass Container {
		Structure {
			conjugated Port p0: PC
			Attribute caseId: int32
			optional ActorRef opt: Optional

			Binding p0 and opt.p0
		}
		Behavior {
			ctor '''caseId = etUnit_openAll("log", "DynamicActorTest4", "org.eclipse.etrice.generator.java.tests.DynamicActorTest4", "DynamicActorTest4_case");'''
			dtor '''etUnit_closeAll(caseId);'''

			// this method prints the passed message and then dumps the object tree consisting of actors and ports
			Operation dumpTree(msg: string) '''
				System.out.println(msg);
				System.out.println(((org.eclipse.etrice.runtime.java.messaging.RTObject)getRoot()).toStringRecursive());'''

			StateMachine {
				Transition init: initial -> CreateOptional {
				}
				Transition tr0: CreateOptional -> Done {
					triggers {
						<hello: p0>
					}
					action '''
						System.out.println(transitionData+"\n");
						opt.destroyOptionalActor();
						dumpTree("after deletion of Optional2");'''
				}
				State CreateOptional {
					entry '''
						opt.createOptionalActor("Optional", getThread());
						p0.sayHello();'''
				}
				State Done {
					entry '''etUnit_testFinished(caseId);'''
				}
			}
		}
	}

	// the class that is referenced as optional by the Container
	// It has an external end port and implements the behavior itself
	ActorClass Optional {
		Interface {
			Port p0: PC
		}
		Structure {
			external Port p0
		}
		Behavior {
			StateMachine {
				Transition init: initial -> Ready {
				}
				Transition tr0: Ready -> Ready {
					triggers {
						<sayHello: p0>
					}
					action '''p0.hello("this is AC1, instance "+getInstancePath());'''
				}
				State Ready
			}
		}
	}

	// a simple protocol that is used to demonstrate that actors are connected
	ProtocolClass PC {
		incoming {
			Message sayHello()
		}
		outgoing {
			Message hello(string)
		}
	}
}

Back to the top