Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4e63c010fc0832c2ab7d857eea197176292adb67 (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
/*******************************************************************************
 * Copyright (c) 2011 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 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * CONTRIBUTORS:
 * 		Henrik Rentz-Reichert (initial contribution)
 * 
 *******************************************************************************/

package org.eclipse.etrice.generator.java.gen

import com.google.inject.Inject
import com.google.inject.Singleton
import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.room.ActorClass
import org.eclipse.etrice.generator.fsm.base.FileSystemHelpers
import org.eclipse.etrice.generator.base.io.IGeneratorFileIO
import org.eclipse.etrice.generator.generic.GenericActorClassGenerator
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.generator.java.Main
import org.eclipse.etrice.generator.java.setup.GeneratorOptionsHelper

@Singleton
class OptionalActorInterfaceGen extends GenericActorClassGenerator {

	@Inject IGeneratorFileIO fileIO
	@Inject extension JavaExtensions
	@Inject extension RoomExtensions
	@Inject extension FileSystemHelpers
	@Inject protected extension GeneratorOptionsHelper
	
	def doGenerate(Root root) {
		for (ac: root.optionalActorClasses.filter(cl|cl.isValidGenerationLocation)) {
			val path = ac.generationTargetPath+ac.path
			val infopath = ac.generationInfoPath+ac.path
			var file = ac.getJavaInterfaceFileName(false)
			fileIO.generateFile("generating ActorClass Interface implementation", path, infopath, file, root.generate(ac, false))

			file = ac.getJavaInterfaceFileName(true)
			fileIO.generateFile("generating ActorClass Interface implementation", path, infopath, file, root.generate(ac, true))
		}
	}
	
	def generate(Root root, ActorClass ac, boolean replicated) {
		val baseClass = if (replicated) "ReplicatedOptionalActorInterfaceBase" else "ScalarOptionalActorInterfaceBase"
		'''
			package «ac.getPackage»;
			
			«IF Main::settings.generateMSCInstrumentation»
				import org.eclipse.etrice.runtime.java.debugging.DebuggingService;
			«ENDIF»
			import org.eclipse.etrice.runtime.java.modelbase.IEventReceiver;
			import org.eclipse.etrice.runtime.java.modelbase.InterfaceItemBroker;
			import org.eclipse.etrice.runtime.java.modelbase.«baseClass»;
			
			class «ac.getJavaInterfaceName(replicated)» extends «baseClass» {
				//--------------------- brokers for ports on the interface
				«FOR ep : ac.allInterfacePorts»
					protected InterfaceItemBroker «ep.name» = null;
				«ENDFOR»

				//--------------------- interface item IDs
				«ac.genInterfaceItemConstantsForOptionalActor»
				
				//--------------------- construction
				public «ac.getJavaInterfaceName(replicated)» (IEventReceiver parent, String name) {
					super(parent, name, "«ac.name»");
					
					«FOR ep : ac.allInterfacePorts»
						«IF ep.replicated»
							«ep.name» = new ReplicatedInterfaceItemBroker(this, "«ep.name»", «ep.ifItemId»);
						«ELSE»
							«ep.name» = new InterfaceItemBroker(this, "«ep.name»", «ep.ifItemId»);
						«ENDIF»
					«ENDFOR»
				}
				«IF Main::settings.generateMSCInstrumentation»
					
					@Override
					protected void logCreation(String actorClass, String name) {
						DebuggingService.getInstance().addMessageActorCreate(this, actorClass, name);
					}
					
					@Override
					protected void logDeletion(String name) {
						DebuggingService.getInstance().addMessageActorDestroy(this, name);
					}
				«ENDIF»
			}
		'''
	}	
}

Back to the top