Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 4cf04e79a2f46ebf9fa4bef3ccea96e32a0d5130 (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
/*******************************************************************************
 * 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 v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * CONTRIBUTORS:
 * 		Juergen Haug
 * 
 *******************************************************************************/

package org.eclipse.etrice.generator.config

import java.util.ArrayList
import java.util.List
import org.eclipse.emf.ecore.resource.ResourceSet
import org.eclipse.etrice.core.ConfigStandaloneSetup
import org.eclipse.etrice.core.config.BooleanLiteral
import org.eclipse.etrice.core.config.IntLiteral
import org.eclipse.etrice.core.config.Literal
import org.eclipse.etrice.core.config.LiteralArray
import org.eclipse.etrice.core.config.RealLiteral
import org.eclipse.etrice.core.config.StringLiteral
import org.eclipse.etrice.core.genmodel.base.ILogger
import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance
import org.eclipse.etrice.core.genmodel.etricegen.InterfaceItemInstance
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.core.room.SubSystemClass
import org.eclipse.etrice.generator.base.IDataConfiguration
import org.eclipse.etrice.generator.config.util.DataConfigurationHelper

class DataConfiguration implements IDataConfiguration {
	

	override doSetup() {
		ConfigStandaloneSetup::doSetup()
	}
	
	override setResources(ResourceSet resource, ILogger logger) {
		DataConfigurationHelper::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)?.min?.toStringExpr
	}
	
	override getAttrClassConfigMinValue(ActorClass actor, List<Attribute> path) {
		actor.getAttrClassConfig(path)?.max?.toStringExpr
	}
	
	def private getAttrClassConfig(ActorClass actor, List<Attribute> path){
		var id = '''/«actor.name»/«path.toStringPath»'''.toString
		DataConfigurationHelper::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
		DataConfigurationHelper::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
		DataConfigurationHelper::actorInstanceAttrMap.get(id)?.value?.toStringExpr
	}
	
	override getAttrInstanceConfigValue(InterfaceItemInstance item, List<Attribute> path) {
		DataConfigurationHelper::actorInstanceAttrMap.get(item.path)?.value?.toStringExpr
	}
	// dynamic
	
	override getPollingTimerUser(SubSystemClass subsystem) {
		 subsystem.config?.dynConfig?.polling
	}
	
	override getUserCode1(SubSystemClass 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(SubSystemClass subsystem) {
		var dynConfig = subsystem.config?.dynConfig
		return 
			if(dynConfig?.filePath != null)
				'''new ConfigSourceFile("«dynConfig.filePath»")'''
			else 
				dynConfig?.userCode2
	}
	
	override getDynConfigReadAttributes(String actorInstance) {
		val result = new ArrayList<Attribute>
		var configs = DataConfigurationHelper::dynActorInstanceAttrMap.get(actorInstance)
		configs?.forEach(c | if(c.readOnly)result.add(c.attribute))
		
		return result
	}
	
	override getDynConfigWriteAttributes(String actorInstance) {
		val result = new ArrayList<Attribute>
		var configs = DataConfigurationHelper::dynActorInstanceAttrMap.get(actorInstance)
		configs?.forEach(c | if(!c.readOnly)result.add(c.attribute))
		
		return result
	}
	
	
	override hasVariableService(SubSystemClass subsystem) {
		subsystem.config?.dynConfig != null
	}
	
	def private toStringExpr(LiteralArray literal){
		'''«FOR l : literal.literals SEPARATOR ','»«l.toStringExpr»«ENDFOR»'''.toString
	}
	
	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(SubSystemClass cc){
		DataConfigurationHelper::subSystemConfigMap.get(cc)
	}	

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

	
}

Back to the top