diff options
author | Frank Lippert | 2013-02-12 18:57:45 +0000 |
---|---|---|
committer | Frank Lippert | 2013-02-12 18:57:45 +0000 |
commit | c4f2ef6a17fa698ce646c0f49b6cc9fb31901d4a (patch) | |
tree | a4bcf9ae6d35a626c3f3d1ff2baf50086ecad5aa /plugins/org.eclipse.etrice.generator.java | |
parent | 67bebf77c3453a6a212e34f086701316aea3e8a3 (diff) | |
download | org.eclipse.etrice-c4f2ef6a17fa698ce646c0f49b6cc9fb31901d4a.tar.gz org.eclipse.etrice-c4f2ef6a17fa698ce646c0f49b6cc9fb31901d4a.tar.xz org.eclipse.etrice-c4f2ef6a17fa698ce646c0f49b6cc9fb31901d4a.zip |
added changes from master
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.java')
6 files changed, 399 insertions, 399 deletions
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend index e6418cdf0..594f4df99 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ActorClassGen.xtend @@ -19,8 +19,8 @@ import org.eclipse.etrice.core.genmodel.base.ILogger import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-import static extension org.eclipse.etrice.core.room.util.RoomHelpers.* -import org.eclipse.etrice.generator.base.AbstractGenerator +import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
+import org.eclipse.etrice.generator.base.AbstractGenerator
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.generator.generic.ProcedureHelpers
import org.eclipse.etrice.generator.generic.GenericActorClassGenerator
@@ -28,12 +28,12 @@ import org.eclipse.etrice.generator.base.IDataConfiguration @Singleton
class ActorClassGen extends GenericActorClassGenerator {
- +
@Inject JavaIoFileSystemAccess fileAccess
@Inject extension JavaExtensions
@Inject extension RoomExtensions
@Inject IDataConfiguration dataConfigExt
- @Inject ConfigGenAddon configGenAddon + @Inject ConfigGenAddon configGenAddon
@Inject extension ProcedureHelpers
@Inject extension Initialization
@@ -112,7 +112,7 @@ class ActorClassGen extends GenericActorClassGenerator { «FOR a : dataConfigExt.getDynConfigReadAttributes(ac)»
private DynConfigLock lock_«a.name»;
«ENDFOR»
- «ac.operationsImplementation» + «ac.operationsImplementation»
//--------------------- construction
public «ac.name»(IRTObject parent, String name, Address[][] port_addr, Address[][] peer_addr){
@@ -164,7 +164,7 @@ class ActorClassGen extends GenericActorClassGenerator { «attributeSettersGettersImplementation(ac.attributes.minus(dataConfigExt.getDynConfigReadAttributes(ac)), ac.name)»
«configGenAddon.genDynConfigGetterSetter(ac)»
- +
//--------------------- port getters
«FOR ep : ac.getEndPorts()»
«ep.portClassName.getterImplementation(ep.name, ac.name)»
@@ -214,4 +214,4 @@ class ActorClassGen extends GenericActorClassGenerator { '''
}
-} +}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.xtend index f128e3e86..c78a85fe2 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ConfigGenAddon.xtend @@ -1,15 +1,15 @@ -/******************************************************************************* - * 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 - * - *******************************************************************************/ - +/*******************************************************************************
+ * 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.java.gen
import com.google.inject.Inject
@@ -25,130 +25,130 @@ import org.eclipse.etrice.core.room.util.RoomHelpers import org.eclipse.etrice.generator.base.IDataConfiguration
import org.eclipse.etrice.generator.generic.ProcedureHelpers
import org.eclipse.etrice.generator.generic.RoomExtensions
-import org.eclipse.etrice.generator.generic.TypeHelpers -import org.eclipse.etrice.core.room.ExternalType - -class ConfigGenAddon { - - @Inject extension JavaExtensions stdExt - @Inject extension TypeHelpers typeHelpers - @Inject extension ProcedureHelpers helpers - @Inject IDataConfiguration dataConfigExt - @Inject extension RoomExtensions - @Inject Initialization initGen - - // For SubSystemClassGen - - def public genActorInstanceConfig(ActorInstance ai, String aiVariableName){''' - «FOR a : ai.actorClass.allAttributes» - «applyInstanceConfig(ai, aiVariableName, new ArrayList<Attribute>().union(a))» - «ENDFOR» - «FOR pi : ai.orderedIfItemInstances» - «var attribs = RoomHelpers::getPortClass(pi.interfaceItem)?.attributes» - «IF attribs != null» - «FOR a : attribs» - «applyInstanceConfig(pi, aiVariableName+"."+invokeGetter(pi.name, null), new ArrayList<Attribute>().union(a))» - «ENDFOR» - «ENDIF» - «ENDFOR» - ''' - } - - def private applyInstanceConfig(InstanceBase instance, String invokes, List<Attribute> path){ - var a = path.last - var aType = a.refType.type - switch aType { - PrimitiveType: { - var value = typeHelpers.getAttrInstanceConfigValue(path, instance) - if(value != null) - initGen.genAttributeInitializer(a, toValueLiteral(aType, value), invokes) - } - DataClass: - ''' - «FOR e : (aType as DataClass).allAttributes» - «applyInstanceConfig(instance, invokes+"."+a.name.invokeGetter(null), path.union(e))» - «ENDFOR» - ''' - } - } - - // For ActorClassGen - - def public genDynConfigGetterSetter(ActorClass ac){''' - «FOR a : dataConfigExt.getDynConfigReadAttributes(ac)» - public «a.refType.type.typeName»«IF a.size>0»[]«ENDIF» get«a.name.toFirstUpper»(){ - if(lock_«a.name» == null) - return «a.name»; - else - synchronized(lock_«a.name»){ - return «a.name»; - } - } - public void set«a.name.toFirstUpper»(«a.refType.type.typeName»«IF a.size>0»[]«ENDIF» «a.name»){ - if(lock_«a.name» == null) - this.«a.name» = «a.name»; - else - synchronized(lock_«a.name»){ - this.«a.name» = «a.name»; - } - } - public DynConfigLock get«a.name.toFirstUpper»Lock(){ - return lock_«a.name»; - } - «ENDFOR» - «FOR a : dataConfigExt.getDynConfigWriteAttributes(ac)» - public void setAndWrite«a.name.toFirstUpper»(«a.refType.type.typeName»«IF a.size>0»[]«ENDIF» «a.name»){ - set«a.name.toFirstUpper»(«a.name»); - variableService.write(this.getInstancePath()+"/«a.name»", «a.name»); - } - «ENDFOR» - '''} - - def public genMinMaxConstants(ActorClass ac){ - var result = ''' - «FOR a : ac.allAttributes» - «genMinMaxConstantsRec(ac, a.name, new ArrayList<Attribute>().union(a))» - «ENDFOR» - ''' - if(result.length != 0) - result = result+'''//--------------------- Attribute Specifications''' - return result - } - - def private genMinMaxConstantsRec(ActorClass ac, String varNamePath, List<Attribute> path){ - var aType = path.last.refType.type - switch aType { - DataClass: - ''' - «FOR e : (aType as DataClass).allAttributes» - «genMinMaxConstantsRec(ac, varNamePath+"_"+e.name, path.union(e))» - «ENDFOR» - ''' - PrimitiveType:{ - var temp = null as String - ''' - «IF (temp = dataConfigExt.getAttrClassConfigMinValue(ac, path)) != null» - public static «aType.minMaxType» MIN_«varNamePath» = «aType.toValueLiteral(temp)»; - «ENDIF» - «IF (temp = dataConfigExt.getAttrClassConfigMaxValue(ac, path)) != null» - public static «aType.minMaxType» MAX_«varNamePath» = «aType.toValueLiteral(temp)»; - «ENDIF» - ''' - } - } - } - - def private getMinMaxType(PrimitiveType type){ - return switch(type.typeName){ - case "byte": - "int" - case "short": - "int" - case "float": - "double" - default: - type.typeName - } - } - -} +import org.eclipse.etrice.generator.generic.TypeHelpers
+import org.eclipse.etrice.core.room.ExternalType
+
+class ConfigGenAddon {
+
+ @Inject extension JavaExtensions stdExt
+ @Inject extension TypeHelpers typeHelpers
+ @Inject extension ProcedureHelpers helpers
+ @Inject IDataConfiguration dataConfigExt
+ @Inject extension RoomExtensions
+ @Inject Initialization initGen
+
+ // For SubSystemClassGen
+
+ def public genActorInstanceConfig(ActorInstance ai, String aiVariableName){'''
+ «FOR a : ai.actorClass.allAttributes»
+ «applyInstanceConfig(ai, aiVariableName, new ArrayList<Attribute>().union(a))»
+ «ENDFOR»
+ «FOR pi : ai.orderedIfItemInstances»
+ «var attribs = RoomHelpers::getPortClass(pi.interfaceItem)?.attributes»
+ «IF attribs != null»
+ «FOR a : attribs»
+ «applyInstanceConfig(pi, aiVariableName+"."+invokeGetter(pi.name, null), new ArrayList<Attribute>().union(a))»
+ «ENDFOR»
+ «ENDIF»
+ «ENDFOR»
+ '''
+ }
+
+ def private applyInstanceConfig(InstanceBase instance, String invokes, List<Attribute> path){
+ var a = path.last
+ var aType = a.refType.type
+ switch aType {
+ PrimitiveType: {
+ var value = typeHelpers.getAttrInstanceConfigValue(path, instance)
+ if(value != null)
+ initGen.genAttributeInitializer(a, toValueLiteral(aType, value), invokes)
+ }
+ DataClass:
+ '''
+ «FOR e : (aType as DataClass).allAttributes»
+ «applyInstanceConfig(instance, invokes+"."+a.name.invokeGetter(null), path.union(e))»
+ «ENDFOR»
+ '''
+ }
+ }
+
+ // For ActorClassGen
+
+ def public genDynConfigGetterSetter(ActorClass ac){'''
+ «FOR a : dataConfigExt.getDynConfigReadAttributes(ac)»
+ public «a.refType.type.typeName»«IF a.size>0»[]«ENDIF» get«a.name.toFirstUpper»(){
+ if(lock_«a.name» == null)
+ return «a.name»;
+ else
+ synchronized(lock_«a.name»){
+ return «a.name»;
+ }
+ }
+ public void set«a.name.toFirstUpper»(«a.refType.type.typeName»«IF a.size>0»[]«ENDIF» «a.name»){
+ if(lock_«a.name» == null)
+ this.«a.name» = «a.name»;
+ else
+ synchronized(lock_«a.name»){
+ this.«a.name» = «a.name»;
+ }
+ }
+ public DynConfigLock get«a.name.toFirstUpper»Lock(){
+ return lock_«a.name»;
+ }
+ «ENDFOR»
+ «FOR a : dataConfigExt.getDynConfigWriteAttributes(ac)»
+ public void setAndWrite«a.name.toFirstUpper»(«a.refType.type.typeName»«IF a.size>0»[]«ENDIF» «a.name»){
+ set«a.name.toFirstUpper»(«a.name»);
+ variableService.write(this.getInstancePath()+"/«a.name»", «a.name»);
+ }
+ «ENDFOR»
+ '''}
+
+ def public genMinMaxConstants(ActorClass ac){
+ var result = '''
+ «FOR a : ac.allAttributes»
+ «genMinMaxConstantsRec(ac, a.name, new ArrayList<Attribute>().union(a))»
+ «ENDFOR»
+ '''
+ if(result.length != 0)
+ result = result+'''//--------------------- Attribute Specifications'''
+ return result
+ }
+
+ def private genMinMaxConstantsRec(ActorClass ac, String varNamePath, List<Attribute> path){
+ var aType = path.last.refType.type
+ switch aType {
+ DataClass:
+ '''
+ «FOR e : (aType as DataClass).allAttributes»
+ «genMinMaxConstantsRec(ac, varNamePath+"_"+e.name, path.union(e))»
+ «ENDFOR»
+ '''
+ PrimitiveType:{
+ var temp = null as String
+ '''
+ «IF (temp = dataConfigExt.getAttrClassConfigMinValue(ac, path)) != null»
+ public static «aType.minMaxType» MIN_«varNamePath» = «aType.toValueLiteral(temp)»;
+ «ENDIF»
+ «IF (temp = dataConfigExt.getAttrClassConfigMaxValue(ac, path)) != null»
+ public static «aType.minMaxType» MAX_«varNamePath» = «aType.toValueLiteral(temp)»;
+ «ENDIF»
+ '''
+ }
+ }
+ }
+
+ def private getMinMaxType(PrimitiveType type){
+ return switch(type.typeName){
+ case "byte":
+ "int"
+ case "short":
+ "int"
+ case "float":
+ "double"
+ default:
+ type.typeName
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend index 681f76942..abb6c71d6 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/DataClassGen.xtend @@ -174,4 +174,4 @@ class DataClassGen { «ENDFOR»
'''
}
-} +}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend index 64e6a247f..61528cfff 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/ProtocolClassGen.xtend @@ -275,4 +275,4 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { «ENDIF»
'''
}
-} +}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/SubSystemClassGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/SubSystemClassGen.xtend index 340e08bfc..53ac5d6cb 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/SubSystemClassGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/SubSystemClassGen.xtend @@ -27,14 +27,14 @@ import org.eclipse.etrice.core.room.LogicalThread @Singleton
class SubSystemClassGen {
- +
@Inject JavaIoFileSystemAccess fileAccess
@Inject extension JavaExtensions
@Inject extension RoomExtensions
@Inject IDataConfiguration dataConfigExt
@Inject ConfigGenAddon configGenAddon
@Inject extension ProcedureHelpers
- +
@Inject VariableServiceGen varService
@Inject ILogger logger
@@ -239,4 +239,4 @@ class SubSystemClassGen { def private getThreadId(LogicalThread thread) {
"THREAD_"+thread.name.toUpperCase
}
-} +}
diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/VariableServiceGen.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/VariableServiceGen.xtend index 718d10c19..1fb9f9996 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/VariableServiceGen.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/VariableServiceGen.xtend @@ -1,15 +1,15 @@ -/******************************************************************************* - * 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 - * - *******************************************************************************/ - +/*******************************************************************************
+ * 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.java.gen
import com.google.inject.Inject
@@ -30,239 +30,239 @@ import org.eclipse.etrice.generator.base.IDataConfiguration import org.eclipse.etrice.generator.generic.ProcedureHelpers
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.generator.generic.TypeHelpers
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess -import org.eclipse.etrice.core.room.ActorClass -import java.util.Collection - -@Singleton -class VariableServiceGen { - - @Inject extension JavaIoFileSystemAccess fileAccess - @Inject extension JavaExtensions stdExt - @Inject extension RoomExtensions roomExt - @Inject IDataConfiguration configExt - @Inject extension ProcedureHelpers helpers - @Inject extension TypeHelpers - @Inject ILogger logger - - def doGenerate(Root root, SubSystemInstance ssi) { - var path = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath - var file = ssi.subSystemClass.name+"VariableService.java" - logger.logInfo("generating VariableService implementation: '"+file+"' in '"+path+"'") - fileAccess.setOutputPath(path) - fileAccess.generateFile(file, root.generate(ssi)) - } - - def private generate(Root root, SubSystemInstance comp) { - var cc = comp.subSystemClass - val aisAttrMap = new HashMap<ActorInstance, List<Attribute>> - comp.allContainedInstances.forEach(ai | if(!configExt.getDynConfigReadAttributes(ai).empty)aisAttrMap.put(ai, configExt.getDynConfigReadAttributes(ai))) - ''' - - package «comp.subSystemClass.getPackage()»; - - import java.util.Arrays; - import java.util.HashMap; - import java.util.Map; - import org.eclipse.etrice.runtime.java.config.VariableService; - «configExt.getUserCode1(comp)» - «FOR model : aisAttrMap.keySet.roomModels» - import «model.name».*; - «ENDFOR» - - - public class «cc.name+"VariableService"» extends VariableService{ - - private «comp.subSystemClass.name» subSystem; - - // Actor instances - «FOR ai : aisAttrMap.keySet» - private «ai.actorClass.name» «ai.varName»; - «ENDFOR» - - public «cc.name+"VariableService"»(«cc.name» subSystem) { - super(«configExt.getUserCode2(comp)»); - this.subSystem = subSystem; - } - - @Override - protected void initInstances(){ - «FOR ai : aisAttrMap.keySet» - «ai.varName» = («ai.actorClass.name»)subSystem.getInstance("«ai.path»"); - «ENDFOR» - } - - - @Override - protected void setAttributeValues(Map<String, Object> values) { - Object object; - String id = null; - - «FOR ai : aisAttrMap.keySet» - «FOR a : aisAttrMap.get(ai)» - try{ - boolean changed = false; - «genSetAttributeValues1(new ArrayList<Attribute>.union(a), ai)» - if(changed) - synchronized(«ai.varName».«invokeGetter(a.name+"Lock", null)»){ - if(«ai.varName».«invokeGetter(a.name+"Lock", null)».isUpdate()){ - «genSetAttributeValues2(new ArrayList<Attribute>.union(a), ai)» - } - } - }catch(IllegalArgumentException e){ - error(id, e); - } - «ENDFOR» - «ENDFOR» - } - - @Override - protected Map<String, Object> getAttributeValues(){ - Map<String, Object> values = new HashMap<String, Object>(); - «FOR ai : aisAttrMap.keySet» - «FOR a : aisAttrMap.get(ai)» - «genGetAttributeValues(new ArrayList<Attribute>.union(a), ai)» - «ENDFOR» - «ENDFOR» - - return values; - } - - @Override - public void writeDataClass(String id, Object dcObject, Map<String, Object> writeMap) { - «var dataClasses = aisAttrMap.keySet.dynConfigDataClasses» - «FOR dc : dataClasses» - if(dcObject.getClass().equals(«dc.typeName».class)) - writeDataClass(id, («dc.typeName») dcObject, writeTasks); - «ENDFOR» - } - - // DataClasses write operations - - «FOR dc : getAllDataClasses(dataClasses)» - private void writeDataClass(String id, «dc.typeName» object, Map<String, Object> map){ - «FOR a : dc.allAttributes» - «IF a.refType.type.primitive» - map.put(id+"/«a.name»", «IF a.size>0»toObjectArray(«ENDIF»object.«invokeGetter(a.name, null)»«IF a.size>0»)«ENDIF»); - «ELSE» - writeDataClass(id+"/«a.name»", object.«invokeGetter(a.name, null)», map); - «ENDIF» - «ENDFOR» - } - «ENDFOR» - - @Override - protected int getPollingTimerUser(){ - return «configExt.getPollingTimerUser(comp)»; - } - - } - '''} - - def private genMinMaxCheck(List<Attribute> path, ActorClass ac){ - var a = path.last - var aVarName = path.toAbsolutePath("_") - var min = configExt.getAttrClassConfigMinValue(ac, path) != null - var max = configExt.getAttrClassConfigMaxValue(ac, path) != null - if(min || max) - ''' - «IF a.size>0»for(«a.refType.type.typeName» e : «aVarName») - «ENDIF»checkMinMax(«IF a.size>0»e«ELSE»«aVarName»«ENDIF», «IF min»«ac.name».MIN«aVarName»«ELSE»null«ENDIF», «IF max»«ac.name».MAX«aVarName»«ELSE»null«ENDIF»); - ''' - } - - def private getDynConfigDataClasses(Iterable<ActorInstance> ais){ - val result = new HashSet<DataClass> - ais.forEach(ai | configExt.getDynConfigReadAttributes(ai). - forEach(a | if(a.refType.type.dataClass)result.add(a.refType.type as DataClass) - )) - return result - } - - def private getAllDataClasses(Iterable<DataClass> dcs){ - val result = new HashSet<DataClass> - result.addAll(dcs) - val visit = new LinkedList<DataClass> - visit.addAll(dcs) - while(!visit.empty){ - var dc = visit.pop - dc.allAttributes.forEach(a | if(a.refType.type.dataClass)visit.add(a.refType.type as DataClass)) - } - return result - } - - def private getRoomModels(Collection<ActorInstance> ais){ - val models = new HashSet<RoomModel> - ais.forEach(ai | models.add(ai.actorClass.eContainer as RoomModel)) - return models - } - - def private toAbsolutePath(List<Attribute> path, String pathDelim){ - '''«FOR p : path»«pathDelim»«p.name»«ENDFOR»'''.toString - } - - def private getVarName(ActorInstance ai){ - '''«FOR p : ai.path.split('/').drop(2) SEPARATOR '_'»«p»«ENDFOR»''' - } - - def private genGetAttributeValues(List<Attribute> path, ActorInstance ai){ - var a = path.last - if(a.refType.type.primitive){''' - values.put("«ai.path»«path.toAbsolutePath('/')»", «IF a.size>0»toObjectArray(«ENDIF»«ai.varName».«path.invokeGetters(null)»«IF a.size>0»)«ENDIF»); - ''' - } else if(a.refType.type.dataClass){ - var dataClass = (a.refType.type as DataClass) - ''' - «FOR at : dataClass.allAttributes» - «genGetAttributeValues(path.union(at), ai)» - «ENDFOR» - ''' - } - } - - def private genSetAttributeValues1(List<Attribute> path, ActorInstance ai){ - var a = path.last - var aVarName = path.toAbsolutePath("_") - if(a.refType.type.primitive){''' - id = "«ai.path»«path.toAbsolutePath("/")»"; - «IF a.size==0»«a.refType.type.typeName.toWrapper»«ELSE»«a.refType.type.typeName»[]«ENDIF» «aVarName» = null; - object = values.get(id); - if(object != null){ - «aVarName» = ensure«a.refType.type.typeName.toFirstUpper»«IF a.size>0»Array«ENDIF»(object«IF a.size>0», «a.size»«ENDIF»); - «genMinMaxCheck(path, ai.actorClass)» - if(!«IF a.size==0»«aVarName».equals(«ELSE»Arrays.equals(«aVarName», «ENDIF»(«IF a.size==0»«a.refType.type.typeName.toWrapper»«ELSE»«a.refType.type.typeName»[]«ENDIF»)getDiffMap().get(id))) - changed = true; - } else - warning(id, "is missing"); - ''' - } else if(a.refType.type.dataClass){ - var dataClass = (a.refType.type as DataClass) - ''' - «FOR at : dataClass.allAttributes» - «genSetAttributeValues1(path.union(at), ai)» - «ENDFOR» - ''' - } - } - - def private genSetAttributeValues2(List<Attribute> path, ActorInstance ai){ - var a = path.last - var aVarName = path.toAbsolutePath("_") - if(a.refType.type.primitive){ - var getters = if(path.size>1)path.take(path.size-1).invokeGetters(null)+"." else "" - ''' - if(«aVarName» != null){ - «ai.varName».«getters»«invokeSetter(a.name, null, aVarName)»; - getDiffMap().put("«ai.path»«path.toAbsolutePath("/")»", «aVarName»); - } - ''' - } else if(a.refType.type.dataClass){ - var dataClass = (a.refType.type as DataClass) - ''' - «FOR at : dataClass.allAttributes» - «genSetAttributeValues2(path.union(at), ai)» - «ENDFOR» - ''' - } - } -} +import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+import org.eclipse.etrice.core.room.ActorClass
+import java.util.Collection
+
+@Singleton
+class VariableServiceGen {
+
+ @Inject extension JavaIoFileSystemAccess fileAccess
+ @Inject extension JavaExtensions stdExt
+ @Inject extension RoomExtensions roomExt
+ @Inject IDataConfiguration configExt
+ @Inject extension ProcedureHelpers helpers
+ @Inject extension TypeHelpers
+ @Inject ILogger logger
+
+ def doGenerate(Root root, SubSystemInstance ssi) {
+ var path = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath
+ var file = ssi.subSystemClass.name+"VariableService.java"
+ logger.logInfo("generating VariableService implementation: '"+file+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(file, root.generate(ssi))
+ }
+
+ def private generate(Root root, SubSystemInstance comp) {
+ var cc = comp.subSystemClass
+ val aisAttrMap = new HashMap<ActorInstance, List<Attribute>>
+ comp.allContainedInstances.forEach(ai | if(!configExt.getDynConfigReadAttributes(ai).empty)aisAttrMap.put(ai, configExt.getDynConfigReadAttributes(ai)))
+ '''
+
+ package «comp.subSystemClass.getPackage()»;
+
+ import java.util.Arrays;
+ import java.util.HashMap;
+ import java.util.Map;
+ import org.eclipse.etrice.runtime.java.config.VariableService;
+ «configExt.getUserCode1(comp)»
+ «FOR model : aisAttrMap.keySet.roomModels»
+ import «model.name».*;
+ «ENDFOR»
+
+
+ public class «cc.name+"VariableService"» extends VariableService{
+
+ private «comp.subSystemClass.name» subSystem;
+
+ // Actor instances
+ «FOR ai : aisAttrMap.keySet»
+ private «ai.actorClass.name» «ai.varName»;
+ «ENDFOR»
+
+ public «cc.name+"VariableService"»(«cc.name» subSystem) {
+ super(«configExt.getUserCode2(comp)»);
+ this.subSystem = subSystem;
+ }
+
+ @Override
+ protected void initInstances(){
+ «FOR ai : aisAttrMap.keySet»
+ «ai.varName» = («ai.actorClass.name»)subSystem.getInstance("«ai.path»");
+ «ENDFOR»
+ }
+
+
+ @Override
+ protected void setAttributeValues(Map<String, Object> values) {
+ Object object;
+ String id = null;
+
+ «FOR ai : aisAttrMap.keySet»
+ «FOR a : aisAttrMap.get(ai)»
+ try{
+ boolean changed = false;
+ «genSetAttributeValues1(new ArrayList<Attribute>.union(a), ai)»
+ if(changed)
+ synchronized(«ai.varName».«invokeGetter(a.name+"Lock", null)»){
+ if(«ai.varName».«invokeGetter(a.name+"Lock", null)».isUpdate()){
+ «genSetAttributeValues2(new ArrayList<Attribute>.union(a), ai)»
+ }
+ }
+ }catch(IllegalArgumentException e){
+ error(id, e);
+ }
+ «ENDFOR»
+ «ENDFOR»
+ }
+
+ @Override
+ protected Map<String, Object> getAttributeValues(){
+ Map<String, Object> values = new HashMap<String, Object>();
+ «FOR ai : aisAttrMap.keySet»
+ «FOR a : aisAttrMap.get(ai)»
+ «genGetAttributeValues(new ArrayList<Attribute>.union(a), ai)»
+ «ENDFOR»
+ «ENDFOR»
+
+ return values;
+ }
+
+ @Override
+ public void writeDataClass(String id, Object dcObject, Map<String, Object> writeMap) {
+ «var dataClasses = aisAttrMap.keySet.dynConfigDataClasses»
+ «FOR dc : dataClasses»
+ if(dcObject.getClass().equals(«dc.typeName».class))
+ writeDataClass(id, («dc.typeName») dcObject, writeTasks);
+ «ENDFOR»
+ }
+
+ // DataClasses write operations
+
+ «FOR dc : getAllDataClasses(dataClasses)»
+ private void writeDataClass(String id, «dc.typeName» object, Map<String, Object> map){
+ «FOR a : dc.allAttributes»
+ «IF a.refType.type.primitive»
+ map.put(id+"/«a.name»", «IF a.size>0»toObjectArray(«ENDIF»object.«invokeGetter(a.name, null)»«IF a.size>0»)«ENDIF»);
+ «ELSE»
+ writeDataClass(id+"/«a.name»", object.«invokeGetter(a.name, null)», map);
+ «ENDIF»
+ «ENDFOR»
+ }
+ «ENDFOR»
+
+ @Override
+ protected int getPollingTimerUser(){
+ return «configExt.getPollingTimerUser(comp)»;
+ }
+
+ }
+ '''}
+
+ def private genMinMaxCheck(List<Attribute> path, ActorClass ac){
+ var a = path.last
+ var aVarName = path.toAbsolutePath("_")
+ var min = configExt.getAttrClassConfigMinValue(ac, path) != null
+ var max = configExt.getAttrClassConfigMaxValue(ac, path) != null
+ if(min || max)
+ '''
+ «IF a.size>0»for(«a.refType.type.typeName» e : «aVarName»)
+ «ENDIF»checkMinMax(«IF a.size>0»e«ELSE»«aVarName»«ENDIF», «IF min»«ac.name».MIN«aVarName»«ELSE»null«ENDIF», «IF max»«ac.name».MAX«aVarName»«ELSE»null«ENDIF»);
+ '''
+ }
+
+ def private getDynConfigDataClasses(Iterable<ActorInstance> ais){
+ val result = new HashSet<DataClass>
+ ais.forEach(ai | configExt.getDynConfigReadAttributes(ai).
+ forEach(a | if(a.refType.type.dataClass)result.add(a.refType.type as DataClass)
+ ))
+ return result
+ }
+
+ def private getAllDataClasses(Iterable<DataClass> dcs){
+ val result = new HashSet<DataClass>
+ result.addAll(dcs)
+ val visit = new LinkedList<DataClass>
+ visit.addAll(dcs)
+ while(!visit.empty){
+ var dc = visit.pop
+ dc.allAttributes.forEach(a | if(a.refType.type.dataClass)visit.add(a.refType.type as DataClass))
+ }
+ return result
+ }
+
+ def private getRoomModels(Collection<ActorInstance> ais){
+ val models = new HashSet<RoomModel>
+ ais.forEach(ai | models.add(ai.actorClass.eContainer as RoomModel))
+ return models
+ }
+
+ def private toAbsolutePath(List<Attribute> path, String pathDelim){
+ '''«FOR p : path»«pathDelim»«p.name»«ENDFOR»'''.toString
+ }
+
+ def private getVarName(ActorInstance ai){
+ '''«FOR p : ai.path.split('/').drop(2) SEPARATOR '_'»«p»«ENDFOR»'''
+ }
+
+ def private genGetAttributeValues(List<Attribute> path, ActorInstance ai){
+ var a = path.last
+ if(a.refType.type.primitive){'''
+ values.put("«ai.path»«path.toAbsolutePath('/')»", «IF a.size>0»toObjectArray(«ENDIF»«ai.varName».«path.invokeGetters(null)»«IF a.size>0»)«ENDIF»);
+ '''
+ } else if(a.refType.type.dataClass){
+ var dataClass = (a.refType.type as DataClass)
+ '''
+ «FOR at : dataClass.allAttributes»
+ «genGetAttributeValues(path.union(at), ai)»
+ «ENDFOR»
+ '''
+ }
+ }
+
+ def private genSetAttributeValues1(List<Attribute> path, ActorInstance ai){
+ var a = path.last
+ var aVarName = path.toAbsolutePath("_")
+ if(a.refType.type.primitive){'''
+ id = "«ai.path»«path.toAbsolutePath("/")»";
+ «IF a.size==0»«a.refType.type.typeName.toWrapper»«ELSE»«a.refType.type.typeName»[]«ENDIF» «aVarName» = null;
+ object = values.get(id);
+ if(object != null){
+ «aVarName» = ensure«a.refType.type.typeName.toFirstUpper»«IF a.size>0»Array«ENDIF»(object«IF a.size>0», «a.size»«ENDIF»);
+ «genMinMaxCheck(path, ai.actorClass)»
+ if(!«IF a.size==0»«aVarName».equals(«ELSE»Arrays.equals(«aVarName», «ENDIF»(«IF a.size==0»«a.refType.type.typeName.toWrapper»«ELSE»«a.refType.type.typeName»[]«ENDIF»)getDiffMap().get(id)))
+ changed = true;
+ } else
+ warning(id, "is missing");
+ '''
+ } else if(a.refType.type.dataClass){
+ var dataClass = (a.refType.type as DataClass)
+ '''
+ «FOR at : dataClass.allAttributes»
+ «genSetAttributeValues1(path.union(at), ai)»
+ «ENDFOR»
+ '''
+ }
+ }
+
+ def private genSetAttributeValues2(List<Attribute> path, ActorInstance ai){
+ var a = path.last
+ var aVarName = path.toAbsolutePath("_")
+ if(a.refType.type.primitive){
+ var getters = if(path.size>1)path.take(path.size-1).invokeGetters(null)+"." else ""
+ '''
+ if(«aVarName» != null){
+ «ai.varName».«getters»«invokeSetter(a.name, null, aVarName)»;
+ getDiffMap().put("«ai.path»«path.toAbsolutePath("/")»", «aVarName»);
+ }
+ '''
+ } else if(a.refType.type.dataClass){
+ var dataClass = (a.refType.type as DataClass)
+ '''
+ «FOR at : dataClass.allAttributes»
+ «genSetAttributeValues2(path.union(at), ai)»
+ «ENDFOR»
+ '''
+ }
+ }
+}
|