Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dc0b9cd944d38c9a47118645c8803b2adda067d5 (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
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
«REM»
/*******************************************************************************
 * Copyright (c) 2010 protos software gmbh (http://www.protos.de).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * CONTRIBUTORS:
 * 		Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/
«ENDREM»
«IMPORT room»;
«IMPORT etricegen»;

«EXTENSION org::eclipse::etrice::generator::extensions::Extensions»
«EXTENSION extensions::Extensions»
«EXTENSION org::eclipse::xtend::util::stdlib::io»

«DEFINE subSystemClass FOR Root»

«FOREACH this.subSystemInstances AS comp»

«LET comp.subSystemClass AS cc»

«("generating "+getPath(cc)+cc.name+"_controller.java").info()»
«FILE getPath(cc)+cc.name+".java"»
package «getPackage(cc)»;

import org.eclipse.etrice.runtime.java.messaging.MessageService;
import org.eclipse.etrice.runtime.java.messaging.RTServices;
import org.eclipse.etrice.runtime.java.messaging.Address;
import org.eclipse.etrice.runtime.java.messaging.IRTObject;
import org.eclipse.etrice.runtime.java.messaging.RTSystemServicesProtocol.*;
import org.eclipse.etrice.runtime.java.modelbase.ActorClassBase;
import org.eclipse.etrice.runtime.java.modelbase.SubSystemClassBase;
import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;

«LET this.getReferencedModels(cc) AS models»
«FOREACH models AS model»import «model.name».*;«ENDFOREACH»
«ENDLET»


«EXPAND ProcedureHelpers::UserCode FOR cc.userCode1»

public class «comp.name» extends SubSystemClassBase{

	«EXPAND ProcedureHelpers::UserCode FOR cc.userCode2»
	
	public «comp.name»(IRTObject parent, String name) {
		super(parent, name);
	}
	
	@Override
	public void receiveEvent(InterfaceItemBase ifitem, int evt, Object data){
	}
	
	@Override	
	public void instantiateMessageServices(){
	
		RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, new Address(0, 0, 0),"MessageService_Main"));
		«FOREACH comp.subSystemClass.threads AS thread ITERATOR tid»
			RTServices.getInstance().getMsgSvcCtrl().addMsgSvc(new MessageService(this, new Address(0, «tid.counter1», 0),"MessageService_«thread.name»", «thread.prio»));
		«ENDFOREACH»
		}

	@Override
	public void instantiateActors(){
		// all addresses
		// Addresses for the Subsystem Systemport
		«FOREACH comp.allContainedInstances AS ai ITERATOR i»Address addr_item_SystemPort_«i.counter0»=new Address(0,0,«comp.objCounter.getAndIncrementCount()»);
		«ENDFOREACH»
		
		«FOREACH comp.allContainedInstances AS ai»
		// actor instance «ai.path» itself => Systemport Address
		// TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport)
		Address addr_item_«ai.path.getPathName()»= new Address(0,«ai.threadId»,«ai.objId»);
		// interface items of «ai.path»«FOREACH ai.orderedIfItemInstances AS pi»
				«IF ServiceImplInstance.isInstance(pi) || pi.peers.size>1»«FOREACH pi.peers AS peer ITERATOR i»Address addr_item_«pi.path.getPathName()»_«i.counter0» = new Address(0,«pi.threadId»,«pi.objId+i.counter0»);
					«ENDFOREACH»
				«ELSE»Address addr_item_«pi.path.getPathName()» = new Address(0,«ai.threadId»,«pi.objId»);
				«ENDIF»
			«ENDFOREACH»
		«ENDFOREACH»

		// instantiate all actor instances
		instances = new ActorClassBase[«comp.allContainedInstances.size»];
		«FOREACH comp.allContainedInstances AS ai ITERATOR k»instances[«comp.allContainedInstances.indexOf(ai)»] = new «ai.actorClass.name»(
				«IF SubSystemInstance.isInstance(ai.eContainer)»this«ELSE»instances[«comp.allContainedInstances.indexOf(ai.eContainer)»]«ENDIF»,
				"«ai.name»",
				// own interface item addresses
				new Address[][] {{addr_item_«ai.path.getPathName()»},«FOREACH ai.orderedIfItemInstances AS pi SEPARATOR ","»{«IF ServiceImplInstance.isInstance(pi) || pi.peers.size>1»«FOREACH pi.peers AS peer ITERATOR i SEPARATOR ","»addr_item_«pi.path.getPathName()»_«i.counter0»«ENDFOREACH»
					«ELSE»addr_item_«pi.path.getPathName()»
					«ENDIF»}
				«ENDFOREACH»},
				// peer interface item addresses
				new Address[][] {{addr_item_SystemPort_«k.counter0»},«FOREACH ai.orderedIfItemInstances AS pi SEPARATOR ","»{«IF !ServiceImplInstance.isInstance(pi) && pi.peers.isEmpty»null«ELSE»«FOREACH pi.peers AS pp SEPARATOR ","»«IF ServiceImplInstance.isInstance(pp) || pp.peers.size>1»addr_item_«pp.path.getPathName()»_«pp.peers.indexOf(pi)»
					«ELSE»addr_item_«pp.path.getPathName()»
					«ENDIF»
					«ENDFOREACH»«ENDIF»}
				«ENDFOREACH»}
			); 
		«ENDFOREACH»

		// create the subsystem system port	
		RTSystemPort = new RTSystemServicesProtocolConjPortRepl(this, "RTSystemPort",
				0, //local ID
				new Address[]{ // own addresses
				«FOREACH comp.allContainedInstances AS ai ITERATOR i SEPARATOR ","»addr_item_SystemPort_«i.counter0»
				«ENDFOREACH»},
				new Address[]{  // peer addresses
				«FOREACH comp.allContainedInstances AS ai SEPARATOR ","»addr_item_«ai.path.getPathName()»
				«ENDFOREACH»});
				
	}
};
«ENDFILE»

«ENDLET»
«ENDFOREACH»
«ENDDEFINE»

Back to the top