Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 01a36c9ef10156799b4ceeb3e1a4411807eff1bd (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*******************************************************************************
 * Copyright (c) 2012 Juergen Haug
 * 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:
 * 		Juergen Haug
 * 
 *******************************************************************************/
package org.eclipse.etrice.generator.config

import com.google.inject.Inject
import java.util.ArrayList
import java.util.HashSet
import java.util.List
import org.eclipse.emf.common.EMFPlugin
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.etrice.core.ConfigStandaloneSetup
import org.eclipse.etrice.core.common.base.BooleanLiteral
import org.eclipse.etrice.core.common.base.IntLiteral
import org.eclipse.etrice.core.common.base.Literal
import org.eclipse.etrice.core.common.base.RealLiteral
import org.eclipse.etrice.core.common.base.StringLiteral
import org.eclipse.etrice.core.config.ConfigValue
import org.eclipse.etrice.core.config.ConfigValueArray
import org.eclipse.etrice.core.config.EnumConfigValue
import org.eclipse.etrice.core.config.LiteralConfigValue
import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance
import org.eclipse.etrice.core.genmodel.etricegen.InterfaceItemInstance
import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
import org.eclipse.etrice.generator.base.logging.ILogger
import org.eclipse.etrice.core.room.ActorClass
import org.eclipse.etrice.core.room.Attribute
import org.eclipse.etrice.core.room.ProtocolClass
import org.eclipse.etrice.generator.base.IDataConfiguration
import org.eclipse.etrice.generator.config.util.DataConfigurationHelper
import org.eclipse.xtext.scoping.impl.ImportUriResolver

class DataConfiguration implements IDataConfiguration {

	@Inject
	protected extension DataConfigurationHelper
	
	@Inject
	protected ILogger logger;

	@Inject
	protected ImportUriResolver uriResolver;

	override doSetup() {
		if (!EMFPlugin::IS_ECLIPSE_RUNNING)
			ConfigStandaloneSetup::doSetup()

	}

	override setResources(ResourceSet resource, ILogger logger) {
		setConfigModels(resource, logger)
	}

	// static
	override getAttrClassConfigValue(ActorClass actor, List<Attribute> path) {
		actor.getAttrClassConfig(path)?.value?.toStringExpr
	}

	override getAttrClassConfigMaxValue(ActorClass actor, List<Attribute> path) {
		actor.getAttrClassConfig(path)?.max?.toStringExpr
	}

	override getAttrClassConfigMinValue(ActorClass actor, List<Attribute> path) {
		actor.getAttrClassConfig(path)?.min?.toStringExpr
	}

	def private getAttrClassConfig(ActorClass actor, List<Attribute> path) {
		var id = '''/«actor.name»/«path.toStringPath»'''.toString
		actorClassAttrMap.get(id)
	}

	override getAttrClassConfigValue(ProtocolClass pc, boolean regular, List<Attribute> path) {
		var id = '''/«pc.name»/«IF regular»regular«ELSE»conjugated«ENDIF»/«path.toStringPath»'''.toString
		protocolClassAttrMap.get(id)?.value?.toStringExpr
	}

	def private toStringPath(List<Attribute> path) {
		'''«FOR a : path SEPARATOR '/'»«a.name»«ENDFOR»'''.toString
	}

	override getAttrInstanceConfigValue(ActorInstance ai, List<Attribute> path) {
		var id = ai.path + "/" + path.toStringPath
		actorInstanceAttrMap.get(id)?.value?.toStringExpr
	}

	override getAttrInstanceConfigValue(InterfaceItemInstance item, List<Attribute> path) {
		actorInstanceAttrMap.get(item.path + "/" + path.toStringPath)?.value?.toStringExpr
	}

	// dynamic
	override getPollingTimerUser(SubSystemInstance subsystem) {
		val dynConf = subsystem.config?.dynConfig
		if (dynConf === null)
			0
		else
			dynConf.polling
	}

	override getUserCode1(SubSystemInstance subsystem) {
		var dynConfig = subsystem.config?.dynConfig
		return if (dynConfig?.filePath !== null)
			"import org.eclipse.etrice.runtime.java.config.ConfigSourceFile;" // TODO JH make lang independent
		else
			dynConfig?.userCode1
	}

	override getUserCode2(SubSystemInstance subsystem) {
		var dynConfig = subsystem.config?.dynConfig
		return if (dynConfig?.filePath !== null) '''new ConfigSourceFile("«dynConfig.filePath»")''' else
			dynConfig?.userCode2
	}

	override getDynConfigReadAttributes(ActorInstance ai) {
		val result = new ArrayList<Attribute>
		var configs = dynActorInstanceAttrMap.get(ai.path)
		configs?.forEach(c|if(c.readOnly) result.add(c.attribute))

		return result
	}

	override getDynConfigWriteAttributes(ActorInstance ai) {
		val result = new ArrayList<Attribute>
		var configs = dynActorInstanceAttrMap.get(ai.path)
		configs?.forEach(c|if(!c.readOnly) result.add(c.attribute))

		return result
	}

	override hasVariableService(SubSystemInstance subsystem) {
		subsystem.config?.dynConfig !== null
	}

	def private toStringExpr(ConfigValueArray literal) {
		'''«FOR l : literal.values SEPARATOR ','»«l.toStringExpr»«ENDFOR»'''.toString
	}

	def private toStringExpr(ConfigValue configValue) {
		switch (configValue) {
			LiteralConfigValue: configValue.value.toStringExpr
			EnumConfigValue: configValue.value.fullName
		}
	}

	def private toStringExpr(Literal literal) {
		switch (literal) {
			BooleanLiteral: literal.isTrue.toString
			IntLiteral: literal.value.toString
			RealLiteral: literal.value.toString
			StringLiteral: literal.value.toString
		}
	}

	def private getConfig(SubSystemInstance cc) {
		subSystemConfigMap.get(cc.path)
	}

	override getDynConfigReadAttributes(ActorClass actor) {
		val result = new HashSet<Attribute>
		val configs = dynActorClassAttrMap.get(actor)
		configs?.forEach(c|if(c.readOnly) result.add(c.attribute))
		return result.toList
	}

	override getDynConfigWriteAttributes(ActorClass actor) {
		val result = new HashSet<Attribute>
		val configs = dynActorClassAttrMap.get(actor)
		configs?.forEach(c|if(!c.readOnly) result.add(c.attribute))
		return result.toList
	}

}

Back to the top