Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: dc01fa902d489bb30066545786773f732dd69746 (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
package org.eclipse.etrice.generator.java.gen

import com.google.inject.Inject
import java.util.HashMap
import org.eclipse.etrice.core.genmodel.etricegen.OptionalActorInstance
import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.genmodel.etricegen.WiredActorClass
import org.eclipse.etrice.core.room.ActorClass
import org.eclipse.etrice.core.room.CommunicationType
import org.eclipse.etrice.core.room.util.RoomHelpers
import org.eclipse.etrice.generator.base.io.IGeneratorFileIO
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.generator.fsm.base.FileSystemHelpers

class OptionalActorFactoryGen {

	@Inject IGeneratorFileIO fileIO
	@Inject extension RoomHelpers
	@Inject extension JavaExtensions
	@Inject extension RoomExtensions
	@Inject extension FileSystemHelpers
	
	def doGenerate(Root root) {
		val HashMap<ActorClass, WiredActorClass> ac2wired = new HashMap<ActorClass, WiredActorClass>
		root.wiredInstances.filter(w|w instanceof WiredActorClass).forEach[w|ac2wired.put((w as WiredActorClass).actorClass, w as WiredActorClass)]
		for (oi: root.optionalInstances.filter(cl|cl.actorClass.isValidGenerationLocation)) {
			val ac = oi.actorClass
			val wired = ac2wired.get(ac)
			val path = ac.path
			val file = ac.getJavaFactoryFileName
			fileIO.generateFile("generating ActorClass Interface implementation", path + file, root.generate(oi, wired))
		}
	}
	
	def generate(Root root, OptionalActorInstance oi, WiredActorClass wired) {
		val ac = oi.actorClass
		val clsname = ac.javaFactoryName
		'''
			package «ac.package»;
			
			import «ac.package».«ac.name»;
			import org.eclipse.etrice.runtime.java.modelbase.OptionalActorInterfaceBase;
			import org.eclipse.etrice.runtime.java.modelbase.IOptionalActorFactory;
			import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBase;
			
			public class «clsname» implements IOptionalActorFactory {
				
				public «ac.name» create(OptionalActorInterfaceBase ai, String name) {
					// instantiate sub tree
					«ac.name» actor = new «ac.name»(ai, name);
					
					// wiring
					«FOR port: getAllEndPorts(ac).filter(p|isExternal(p))»
						«if (isDataDriven(port)) "DataPortBase" else "InterfaceItemBase"».connect(ai, "«port.name»", name+"/«port.name»");
					«ENDFOR»
					«FOR open: wired.openBindings»
						«if (isDataDriven(open.port)) "DataPortBase" else "InterfaceItemBase"».connect(ai, "«open.port.name»", name+"/«open.path.join('/')»");
					«ENDFOR»
					«FOR req: wired.requiredServices»
						«if (req.protocol.commType==CommunicationType::DATA_DRIVEN) "DataPortBase" else "InterfaceItemBase"».connect(ai, "«req.protocol.fullyQualifiedName»", name+"/«req.path.join('/')»");
					«ENDFOR»
					
					return actor;
				}
			}
		'''
	}
}

Back to the top