Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Schuetz2013-07-12 08:40:15 +0000
committerThomas Schuetz2013-07-12 08:40:15 +0000
commit12cda553738ca88662624b6f47066b5564549648 (patch)
treebfa65b6c38aa566a5f1cc98395da6546a6c6e282 /plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice
parent3447749b1a453735ac54fc09ea7680acdbb19b69 (diff)
parentd65e1d1bdd43feadb43261b85aac2d8aef5e089c (diff)
downloadorg.eclipse.etrice-12cda553738ca88662624b6f47066b5564549648.tar.gz
org.eclipse.etrice-12cda553738ca88662624b6f47066b5564549648.tar.xz
org.eclipse.etrice-12cda553738ca88662624b6f47066b5564549648.zip
Merge remote-tracking branch 'origin/master'
Conflicts: plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.modellib.c.zip plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.modellib.java.zip plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.runtime.c.zip plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.tutorials.c.zip plugins/org.eclipse.etrice.ui.runtime/contents/org.eclipse.etrice.tutorials.java.zip Change-Id: I98e2df3ab57d6e7e8f27e5b0aee7eaa189bfbc33
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice')
-rw-r--r--plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend368
-rw-r--r--plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/util/DataConfigurationHelper.java400
2 files changed, 384 insertions, 384 deletions
diff --git a/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend b/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend
index 3530e3e02..d382794ca 100644
--- a/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend
+++ b/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/DataConfiguration.xtend
@@ -1,184 +1,184 @@
-/*******************************************************************************
- * 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 com.google.inject.Inject
-import java.util.ArrayList
-import java.util.List
-import org.eclipse.emf.ecore.EObject
-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.ConfigModel
-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.genmodel.etricegen.SubSystemInstance
-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.base.IResourceURIAcceptor
-import org.eclipse.etrice.generator.config.util.DataConfigurationHelper
-import org.eclipse.xtext.scoping.impl.ImportUriResolver
-import org.eclipse.emf.common.EMFPlugin
-
-class DataConfiguration implements IDataConfiguration {
-
- @Inject
- protected ILogger logger;
-
- @Inject
- protected ImportUriResolver uriResolver;
-
- override doSetup() {
- if (!EMFPlugin::IS_ECLIPSE_RUNNING)
- 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)?.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
- 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+"/"+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 = DataConfigurationHelper::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 = DataConfigurationHelper::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(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(SubSystemInstance cc){
- DataConfigurationHelper::subSystemConfigMap.get(cc.path)
- }
-
- 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
- }
-
- override void addReferencedModels(IResourceURIAcceptor acceptor, EObject root) {
- if (root instanceof ConfigModel) {
- for (imp : (root as ConfigModel).imports) {
- val importURI = uriResolver.resolve(imp)
- acceptor.addResourceURI(importURI);
- }
- }
- }
-
-}
+/*******************************************************************************
+ * 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 com.google.inject.Inject
+import java.util.ArrayList
+import java.util.List
+import org.eclipse.emf.ecore.EObject
+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.ConfigModel
+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.genmodel.etricegen.SubSystemInstance
+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.base.IResourceURIAcceptor
+import org.eclipse.etrice.generator.config.util.DataConfigurationHelper
+import org.eclipse.xtext.scoping.impl.ImportUriResolver
+import org.eclipse.emf.common.EMFPlugin
+
+class DataConfiguration implements IDataConfiguration {
+
+ @Inject
+ protected ILogger logger;
+
+ @Inject
+ protected ImportUriResolver uriResolver;
+
+ override doSetup() {
+ if (!EMFPlugin::IS_ECLIPSE_RUNNING)
+ 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)?.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
+ 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+"/"+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 = DataConfigurationHelper::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 = DataConfigurationHelper::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(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(SubSystemInstance cc){
+ DataConfigurationHelper::subSystemConfigMap.get(cc.path)
+ }
+
+ 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
+ }
+
+ override void addReferencedModels(IResourceURIAcceptor acceptor, EObject root) {
+ if (root instanceof ConfigModel) {
+ for (imp : (root as ConfigModel).imports) {
+ val importURI = uriResolver.resolve(imp)
+ acceptor.addResourceURI(importURI);
+ }
+ }
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/util/DataConfigurationHelper.java b/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/util/DataConfigurationHelper.java
index eddcee088..2364a4bf0 100644
--- a/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/util/DataConfigurationHelper.java
+++ b/plugins/org.eclipse.etrice.generator.config/src/org/eclipse/etrice/generator/config/util/DataConfigurationHelper.java
@@ -1,200 +1,200 @@
-/*******************************************************************************
- * 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.util;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.emf.ecore.resource.ResourceSet;
-import org.eclipse.etrice.core.config.ActorClassConfig;
-import org.eclipse.etrice.core.config.ActorInstanceConfig;
-import org.eclipse.etrice.core.config.AttrClassConfig;
-import org.eclipse.etrice.core.config.AttrInstanceConfig;
-import org.eclipse.etrice.core.config.ConfigModel;
-import org.eclipse.etrice.core.config.PortInstanceConfig;
-import org.eclipse.etrice.core.config.ProtocolClassConfig;
-import org.eclipse.etrice.core.config.SubSystemConfig;
-import org.eclipse.etrice.core.config.util.ConfigUtil;
-import org.eclipse.etrice.core.genmodel.base.ILogger;
-import org.eclipse.etrice.core.room.ActorClass;
-import org.eclipse.etrice.core.room.Attribute;
-import org.eclipse.etrice.core.room.DataClass;
-import org.eclipse.etrice.core.room.ProtocolClass;
-
-public class DataConfigurationHelper {
-
- // static
- public static Map<String, AttrClassConfig> actorClassAttrMap = new HashMap<String, AttrClassConfig>();
- public static Map<String, AttrClassConfig> protocolClassAttrMap = new HashMap<String, AttrClassConfig>();
- public static Map<String, AttrInstanceConfig> actorInstanceAttrMap = new HashMap<String, AttrInstanceConfig>();
-
- // dynamic
- public static Map<String, SubSystemConfig> subSystemConfigMap = new HashMap<String, SubSystemConfig>();
- public static Map<String, List<AttrInstanceConfig>> dynActorInstanceAttrMap = new HashMap<String, List<AttrInstanceConfig>>();
- public static Map<ActorClass, List<AttrInstanceConfig>> dynActorClassAttrMap = new HashMap<ActorClass, List<AttrInstanceConfig>>();
-
- public static boolean setConfigModels(ResourceSet rs, ILogger logger) {
- actorClassAttrMap.clear();
- protocolClassAttrMap.clear();
- actorInstanceAttrMap.clear();
- subSystemConfigMap.clear();
- dynActorInstanceAttrMap.clear();
- dynActorClassAttrMap.clear();
-
- boolean error = false;
-
- List<ConfigModel> configs = new ArrayList<ConfigModel>();
- for (Resource res : rs.getResources()) {
- EObject object = res.getContents().get(0);
- if (object instanceof ConfigModel)
- configs.add((ConfigModel) object);
- }
-
- if (!configs.isEmpty())
- logger.logInfo("-- loading configurations");
-
- Set<ActorClass> actorClasses = new HashSet<ActorClass>();
- Set<ProtocolClass> protocolClasses = new HashSet<ProtocolClass>();
- Set<String> actorInstances = new HashSet<String>();
- for (ConfigModel config : configs) {
- for (ActorClassConfig classConfig : config.getActorClassConfigs()) {
- if (actorClasses.contains(classConfig.getActor())) {
- logger.logError("Multiple configurations for actor class "
- + classConfig.getActor().getName() + " found", null);
- error = true;
- } else {
- actorClasses.add(classConfig.getActor());
- collectConfigs(classConfig, actorClassAttrMap);
- }
- }
- for (ProtocolClassConfig protocolConfig : config
- .getProtocolClassConfigs()) {
- if (protocolClasses.contains(protocolConfig.getProtocol())) {
- logger.logError(
- "Multiple configurations for protocol class "
- + protocolConfig.getProtocol().getName()
- + " found", null);
- error = true;
- } else {
- protocolClasses.add(protocolConfig.getProtocol());
- collectConfigs(protocolConfig, protocolClassAttrMap);
- }
- }
- for (ActorInstanceConfig instanceConfig : config
- .getActorInstanceConfigs()) {
- String path = ConfigUtil.getPath(instanceConfig);
- if (actorInstances.contains(path)) {
- logger.logError(
- "Multiple configurations for actor instance "
- + path + " found", null);
- } else {
- actorInstances.add(path);
- collectConfigs(instanceConfig, path, actorInstanceAttrMap);
- }
- }
- for (SubSystemConfig ssConfig : config.getSubSystemConfigs()) {
- String path = ConfigUtil.getPath(ssConfig);
- if (subSystemConfigMap.containsKey(path)) {
- logger.logError("Multiple configurations for subSystem"
- + path + " found", null);
- error = true;
- } else
- subSystemConfigMap.put(path, ssConfig);
- }
- }
-
- return !error;
- }
-
- private static void collectConfigs(ActorInstanceConfig actorConfig,
- String path, Map<String, AttrInstanceConfig> map) {
- for (AttrInstanceConfig c : actorConfig.getAttributes()) {
- collectConfigs(c, path + "/" + c.getAttribute().getName(), map);
-
- if (c.isDynConfig()) {
- List<AttrInstanceConfig> list = dynActorInstanceAttrMap
- .get(path);
- if (list == null)
- list = new ArrayList<AttrInstanceConfig>();
- list.add(c);
- dynActorInstanceAttrMap.put(path, list);
-
- ActorClass ac = ConfigUtil.getLastActorRef(
- actorConfig.getSubSystem().getType(),
- actorConfig.getPath()).getType();
- if ((list = dynActorClassAttrMap.get(ac)) == null)
- list = new ArrayList<AttrInstanceConfig>();
- list.add(c);
- dynActorClassAttrMap.put(ac, list);
- }
- }
- for (PortInstanceConfig c : actorConfig.getPorts()) {
- for (AttrInstanceConfig a : c.getAttributes())
- collectConfigs(a, path + "/" + c.getItem().getName() + "/"
- + a.getAttribute().getName(), map);
- }
- }
-
- private static void collectConfigs(ProtocolClassConfig protocolConfig,
- Map<String, AttrClassConfig> map) {
- String path = "/" + protocolConfig.getProtocol().getName();
- if (protocolConfig.getRegular() != null)
- for (AttrClassConfig c : protocolConfig.getRegular()
- .getAttributes())
- collectConfigs(c, path + "/regular/"
- + c.getAttribute().getName(), map);
- if (protocolConfig.getConjugated() != null)
- for (AttrClassConfig c : protocolConfig.getConjugated()
- .getAttributes())
- collectConfigs(c, path + "/conjugated/"
- + c.getAttribute().getName(), map);
- }
-
- private static void collectConfigs(ActorClassConfig actorConfig,
- Map<String, AttrClassConfig> map) {
- String path = "/" + actorConfig.getActor().getName();
- for (AttrClassConfig c : actorConfig.getAttributes())
- collectConfigs(c, path + "/" + c.getAttribute().getName(), map);
- }
-
- private static void collectConfigs(AttrClassConfig config, String path,
- Map<String, AttrClassConfig> map) {
- Attribute a = config.getAttribute();
- if (a.getRefType().getType() instanceof DataClass)
- for (AttrClassConfig c : config.getAttributes())
- collectConfigs(c, path + "/" + c.getAttribute().getName(), map);
- map.put(path, config);
- }
-
- private static void collectConfigs(AttrInstanceConfig config, String path,
- Map<String, AttrInstanceConfig> map) {
- Attribute a = config.getAttribute();
- if (a.getRefType().getType() instanceof DataClass)
- for (AttrInstanceConfig c : config.getAttributes())
- collectConfigs(c, path + "/" + c.getAttribute().getName(), map);
- map.put(path, config);
- }
-
- public static String toStringPath(Iterable<String> path, String pathDelim) {
- StringBuilder b = new StringBuilder();
- for (String p : path)
- b.append(pathDelim + p);
-
- return b.toString();
- }
-}
+/*******************************************************************************
+ * 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.util;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.resource.Resource;
+import org.eclipse.emf.ecore.resource.ResourceSet;
+import org.eclipse.etrice.core.config.ActorClassConfig;
+import org.eclipse.etrice.core.config.ActorInstanceConfig;
+import org.eclipse.etrice.core.config.AttrClassConfig;
+import org.eclipse.etrice.core.config.AttrInstanceConfig;
+import org.eclipse.etrice.core.config.ConfigModel;
+import org.eclipse.etrice.core.config.PortInstanceConfig;
+import org.eclipse.etrice.core.config.ProtocolClassConfig;
+import org.eclipse.etrice.core.config.SubSystemConfig;
+import org.eclipse.etrice.core.config.util.ConfigUtil;
+import org.eclipse.etrice.core.genmodel.base.ILogger;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.ProtocolClass;
+
+public class DataConfigurationHelper {
+
+ // static
+ public static Map<String, AttrClassConfig> actorClassAttrMap = new HashMap<String, AttrClassConfig>();
+ public static Map<String, AttrClassConfig> protocolClassAttrMap = new HashMap<String, AttrClassConfig>();
+ public static Map<String, AttrInstanceConfig> actorInstanceAttrMap = new HashMap<String, AttrInstanceConfig>();
+
+ // dynamic
+ public static Map<String, SubSystemConfig> subSystemConfigMap = new HashMap<String, SubSystemConfig>();
+ public static Map<String, List<AttrInstanceConfig>> dynActorInstanceAttrMap = new HashMap<String, List<AttrInstanceConfig>>();
+ public static Map<ActorClass, List<AttrInstanceConfig>> dynActorClassAttrMap = new HashMap<ActorClass, List<AttrInstanceConfig>>();
+
+ public static boolean setConfigModels(ResourceSet rs, ILogger logger) {
+ actorClassAttrMap.clear();
+ protocolClassAttrMap.clear();
+ actorInstanceAttrMap.clear();
+ subSystemConfigMap.clear();
+ dynActorInstanceAttrMap.clear();
+ dynActorClassAttrMap.clear();
+
+ boolean error = false;
+
+ List<ConfigModel> configs = new ArrayList<ConfigModel>();
+ for (Resource res : rs.getResources()) {
+ EObject object = res.getContents().get(0);
+ if (object instanceof ConfigModel)
+ configs.add((ConfigModel) object);
+ }
+
+ if (!configs.isEmpty())
+ logger.logInfo("-- loading configurations");
+
+ Set<ActorClass> actorClasses = new HashSet<ActorClass>();
+ Set<ProtocolClass> protocolClasses = new HashSet<ProtocolClass>();
+ Set<String> actorInstances = new HashSet<String>();
+ for (ConfigModel config : configs) {
+ for (ActorClassConfig classConfig : config.getActorClassConfigs()) {
+ if (actorClasses.contains(classConfig.getActor())) {
+ logger.logError("Multiple configurations for actor class "
+ + classConfig.getActor().getName() + " found", null);
+ error = true;
+ } else {
+ actorClasses.add(classConfig.getActor());
+ collectConfigs(classConfig, actorClassAttrMap);
+ }
+ }
+ for (ProtocolClassConfig protocolConfig : config
+ .getProtocolClassConfigs()) {
+ if (protocolClasses.contains(protocolConfig.getProtocol())) {
+ logger.logError(
+ "Multiple configurations for protocol class "
+ + protocolConfig.getProtocol().getName()
+ + " found", null);
+ error = true;
+ } else {
+ protocolClasses.add(protocolConfig.getProtocol());
+ collectConfigs(protocolConfig, protocolClassAttrMap);
+ }
+ }
+ for (ActorInstanceConfig instanceConfig : config
+ .getActorInstanceConfigs()) {
+ String path = ConfigUtil.getPath(instanceConfig);
+ if (actorInstances.contains(path)) {
+ logger.logError(
+ "Multiple configurations for actor instance "
+ + path + " found", null);
+ } else {
+ actorInstances.add(path);
+ collectConfigs(instanceConfig, path, actorInstanceAttrMap);
+ }
+ }
+ for (SubSystemConfig ssConfig : config.getSubSystemConfigs()) {
+ String path = ConfigUtil.getPath(ssConfig);
+ if (subSystemConfigMap.containsKey(path)) {
+ logger.logError("Multiple configurations for subSystem"
+ + path + " found", null);
+ error = true;
+ } else
+ subSystemConfigMap.put(path, ssConfig);
+ }
+ }
+
+ return !error;
+ }
+
+ private static void collectConfigs(ActorInstanceConfig actorConfig,
+ String path, Map<String, AttrInstanceConfig> map) {
+ for (AttrInstanceConfig c : actorConfig.getAttributes()) {
+ collectConfigs(c, path + "/" + c.getAttribute().getName(), map);
+
+ if (c.isDynConfig()) {
+ List<AttrInstanceConfig> list = dynActorInstanceAttrMap
+ .get(path);
+ if (list == null)
+ list = new ArrayList<AttrInstanceConfig>();
+ list.add(c);
+ dynActorInstanceAttrMap.put(path, list);
+
+ ActorClass ac = ConfigUtil.getLastActorRef(
+ actorConfig.getSubSystem().getType(),
+ actorConfig.getPath()).getType();
+ if ((list = dynActorClassAttrMap.get(ac)) == null)
+ list = new ArrayList<AttrInstanceConfig>();
+ list.add(c);
+ dynActorClassAttrMap.put(ac, list);
+ }
+ }
+ for (PortInstanceConfig c : actorConfig.getPorts()) {
+ for (AttrInstanceConfig a : c.getAttributes())
+ collectConfigs(a, path + "/" + c.getItem().getName() + "/"
+ + a.getAttribute().getName(), map);
+ }
+ }
+
+ private static void collectConfigs(ProtocolClassConfig protocolConfig,
+ Map<String, AttrClassConfig> map) {
+ String path = "/" + protocolConfig.getProtocol().getName();
+ if (protocolConfig.getRegular() != null)
+ for (AttrClassConfig c : protocolConfig.getRegular()
+ .getAttributes())
+ collectConfigs(c, path + "/regular/"
+ + c.getAttribute().getName(), map);
+ if (protocolConfig.getConjugated() != null)
+ for (AttrClassConfig c : protocolConfig.getConjugated()
+ .getAttributes())
+ collectConfigs(c, path + "/conjugated/"
+ + c.getAttribute().getName(), map);
+ }
+
+ private static void collectConfigs(ActorClassConfig actorConfig,
+ Map<String, AttrClassConfig> map) {
+ String path = "/" + actorConfig.getActor().getName();
+ for (AttrClassConfig c : actorConfig.getAttributes())
+ collectConfigs(c, path + "/" + c.getAttribute().getName(), map);
+ }
+
+ private static void collectConfigs(AttrClassConfig config, String path,
+ Map<String, AttrClassConfig> map) {
+ Attribute a = config.getAttribute();
+ if (a.getRefType().getType() instanceof DataClass)
+ for (AttrClassConfig c : config.getAttributes())
+ collectConfigs(c, path + "/" + c.getAttribute().getName(), map);
+ map.put(path, config);
+ }
+
+ private static void collectConfigs(AttrInstanceConfig config, String path,
+ Map<String, AttrInstanceConfig> map) {
+ Attribute a = config.getAttribute();
+ if (a.getRefType().getType() instanceof DataClass)
+ for (AttrInstanceConfig c : config.getAttributes())
+ collectConfigs(c, path + "/" + c.getAttribute().getName(), map);
+ map.put(path, config);
+ }
+
+ public static String toStringPath(Iterable<String> path, String pathDelim) {
+ StringBuilder b = new StringBuilder();
+ for (String p : path)
+ b.append(pathDelim + p);
+
+ return b.toString();
+ }
+}

Back to the top