Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Rentz-Reichert2017-11-06 05:37:41 -0500
committerHenrik Rentz-Reichert2017-11-07 01:58:06 -0500
commit48d51b2b32f759e255f0cca154d2757c95d15e19 (patch)
treef1455e17e092e88c01feac4b6cf7f5ec2d2896ff /plugins/org.eclipse.etrice.generator.cpp
parentb09856b29bfcaea08e9e57b14da3744c0a201867 (diff)
downloadorg.eclipse.etrice-48d51b2b32f759e255f0cca154d2757c95d15e19.tar.gz
org.eclipse.etrice-48d51b2b32f759e255f0cca154d2757c95d15e19.tar.xz
org.eclipse.etrice-48d51b2b32f759e255f0cca154d2757c95d15e19.zip
Bug 511330 - [core.genmodel.fsm] introduce simplified generator model
for state machines * manually merged newfsmgen to newfsmgen_finalize because no rebase was possible due to structural changes * rebased on master * switch to Oxygen and Xtend 2.12 Change-Id: If9a8c7421f07fb8e8fa824b7bc6761b9142b7eaf
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.cpp')
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/.classpath4
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/.settings/org.eclipse.jdt.core.prefs7
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend11
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend10
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend4
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend2
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend58
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Validator.java2
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.java1094
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.java525
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java581
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java623
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/NodeGen.java854
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.java1543
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.java182
16 files changed, 5467 insertions, 36 deletions
diff --git a/plugins/org.eclipse.etrice.generator.cpp/.classpath b/plugins/org.eclipse.etrice.generator.cpp/.classpath
index ef5811bf8..87e8cd659 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/.classpath
+++ b/plugins/org.eclipse.etrice.generator.cpp/.classpath
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
- <classpathentry kind="src" path="xtend-gen"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="xtend-gen"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/plugins/org.eclipse.etrice.generator.cpp/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.etrice.generator.cpp/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 000000000..0c68a61dc
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,7 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/plugins/org.eclipse.etrice.generator.cpp/META-INF/MANIFEST.MF b/plugins/org.eclipse.etrice.generator.cpp/META-INF/MANIFEST.MF
index c985f7177..01cec3227 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.etrice.generator.cpp/META-INF/MANIFEST.MF
@@ -14,7 +14,8 @@ Require-Bundle: org.eclipse.etrice.core.genmodel;bundle-version="1.1.1",
org.eclipse.etrice.generator.doc;bundle-version="1.1.1",
org.eclipse.xtend.lib;bundle-version="2.6.0",
org.eclipse.xtext.generator;bundle-version="2.6.0",
- org.eclipse.xtext.util;bundle-version="2.6.0"
+ org.eclipse.xtext.util;bundle-version="2.6.0",
+ org.eclipse.etrice.core.genmodel.fsm
Import-Package: org.apache.log4j
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: org.eclipse.etrice.generator.cpp,
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend
index 6ff717e2d..2791ee88a 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend
@@ -19,6 +19,7 @@ import org.eclipse.etrice.core.fsm.fSM.ComponentCommunicationType
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.genmodel.etricegen.WiredActorClass
+import org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions
import org.eclipse.etrice.core.room.ActorClass
import org.eclipse.etrice.generator.cpp.Main
import org.eclipse.etrice.generator.fsm.base.FileSystemHelpers
@@ -158,16 +159,16 @@ class ActorClassGen extends GenericActorClassGenerator {
virtual void destroy();
«IF ac.hasNonEmptyStateMachine»
- «xpac.genStateMachineConstants»
+ «xpac.graphContainer.genStateMachineConstants»
- «xpac.genStateMachineMethods(false)»
+ «xpac.graphContainer.genStateMachineMethods(false)»
«IF ac.commType == ComponentCommunicationType::DATA_DRIVEN»
void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* generic_data);
«ENDIF»
«IF ac.commType == ComponentCommunicationType::ASYNCHRONOUS || ac.commType == ComponentCommunicationType::DATA_DRIVEN»
virtual void receive(const etRuntime::Message* msg);
«ENDIF»
- «ELSEIF xpac.stateMachine.empty»
+ «ELSEIF FsmGenExtensions.isEmpty(xpac.graphContainer.graph)»
««« no state machine in the super classes
//--------------------- no state machine
virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data);
@@ -347,7 +348,7 @@ class ActorClassGen extends GenericActorClassGenerator {
«operationsImplementation(ac.operations, ac.name)»
«IF ac.hasNonEmptyStateMachine»
- «xpac.genStateMachineMethods(true)»
+ «xpac.graphContainer.genStateMachineMethods(true)»
«IF ac.commType == ComponentCommunicationType::DATA_DRIVEN»
void «ac.name»::receiveEvent(InterfaceItemBase* ifitem, int evt, void* generic_data) {
handleSystemEvent(ifitem, evt, generic_data);
@@ -362,7 +363,7 @@ class ActorClassGen extends GenericActorClassGenerator {
«ENDIF»
}
«ENDIF»
- «ELSEIF xpac.stateMachine.empty»
+ «ELSEIF FsmGenExtensions.isEmpty(xpac.graphContainer.graph)»
««« no state machine in the super classes
//--------------------- no state machine
void «ac.name»::receiveEvent(InterfaceItemBase* ifitem, int evt, void* data) {
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend
index c788cd293..45ffd82ba 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend
@@ -24,7 +24,7 @@ import java.util.List
import org.eclipse.emf.ecore.EObject
import org.eclipse.etrice.core.etphys.eTPhys.NodeRef
import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
-import org.eclipse.etrice.core.genmodel.fsm.fsmgen.IDiagnostician
+import org.eclipse.etrice.core.genmodel.fsm.IDiagnostician
import org.eclipse.etrice.core.room.ActorClass
import org.eclipse.etrice.core.room.DataType
import org.eclipse.etrice.core.room.EnumLiteral
@@ -50,7 +50,7 @@ class CppExtensions implements ILanguageExtension {
@Inject extension RoomExtensions
override String getTypedDataDefinition(EObject msg) {
- generateArglistAndTypedData((msg as Message).data).get(1)
+ generateArglistAndTypedData((msg as Message).data).get(TypedDataKind.DECLARATION_AND_INITIALIZATION.ordinal)
}
def String getCppHeaderFileName(RoomClass rc) { rc.name + ".h" }
@@ -219,9 +219,9 @@ class CppExtensions implements ILanguageExtension {
}
var deRef = if(!data.refType.ref) '*' else ''
- val typedData = '''«typeExpr» «data.name» = «deRef»(static_cast<«castExpr»>(generic_data__et));''' + NEWLINE
- val dataArg = ''', «data.name»'''
- val typedArgList = ''', «typeExpr» «data.name»'''
+ val dataArg = ''', «GENERIC_DATA_NAME»'''
+ val typedData = '''«typeExpr» «GENERIC_DATA_NAME» = «deRef»(static_cast<«castExpr»>(generic_data__et));''' + NEWLINE
+ val typedArgList = ''', «typeExpr» «GENERIC_DATA_NAME»'''
return #[dataArg, typedData, typedArgList]
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
index 105f639fc..c629ccef3 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend
@@ -16,13 +16,13 @@ import com.google.inject.Inject
import com.google.inject.Singleton
import java.util.List
import org.eclipse.etrice.core.genmodel.etricegen.Root
-import org.eclipse.etrice.core.genmodel.fsm.base.ILogger
+import org.eclipse.etrice.core.genmodel.fsm.ILogger
import org.eclipse.etrice.core.room.Attribute
import org.eclipse.etrice.core.room.ComplexType
import org.eclipse.etrice.core.room.DataClass
+import org.eclipse.etrice.core.room.util.RoomHelpers
import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-import org.eclipse.etrice.core.room.util.RoomHelpers
@Singleton
class DataClassGen {
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend
index 38f0da881..16f5e98f1 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend
@@ -16,7 +16,7 @@ import com.google.inject.Inject
import com.google.inject.Singleton
import java.util.List
import org.eclipse.etrice.core.genmodel.etricegen.Root
-import org.eclipse.etrice.core.genmodel.fsm.base.ILogger
+import org.eclipse.etrice.core.genmodel.fsm.ILogger
import org.eclipse.etrice.core.room.CommunicationType
import org.eclipse.etrice.core.room.InterfaceItem
import org.eclipse.etrice.core.room.Message
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend
index 514cd75db..5af70d5a6 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend
@@ -13,29 +13,26 @@
package org.eclipse.etrice.generator.cpp.gen
-import com.google.inject.Inject
import com.google.inject.Singleton
-import org.eclipse.etrice.core.genmodel.fsm.fsmgen.ExpandedModelComponent
+import java.util.Comparator
+import org.eclipse.etrice.core.fsm.fSM.State
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node
import org.eclipse.etrice.generator.cpp.Main
import org.eclipse.etrice.generator.generic.GenericStateMachineGenerator
-import org.eclipse.etrice.generator.generic.RoomExtensions
+
+import static extension org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions.*
@Singleton
class StateMachineGen extends GenericStateMachineGenerator {
- @Inject extension RoomExtensions
-
- override genExtra(ExpandedModelComponent xpac, boolean generateImplementation) {
- val states = newArrayList
- var ac = xpac.modelComponent
- val clsName = xpac.modelComponent.componentName
+ val nodeComparator = new NodeComparator
+
+ override genExtra(GraphContainer gc, boolean generateImplementation) {
+ var ac = gc.component
+ val clsName = ac.componentName
+ val orderedStateNodes = gc.graph.allStateNodes.toList.sortWith(nodeComparator)
-// it is crucial that we obey the order that is used for state IDs
-// that means we have to collect base classes first and each base class list with leaf states last
- while (ac!=null) {
- states.addAll(0, ac.allBaseStates.leafStatesLast)
- ac = ac.base
- }
if(generateImplementation)
'''
«IF Main::settings.generateMSCInstrumentation || Main::settings.generateWithVerboseOutput»
@@ -43,12 +40,12 @@ class StateMachineGen extends GenericStateMachineGenerator {
const String «clsName»::s_stateStrings[] = {
"<no state>",
"<top>",
- «FOR state : states SEPARATOR ","»
- "«state.genStatePathName»"
+ «FOR state : orderedStateNodes SEPARATOR ","»
+ "«(state.stateGraphNode as State).genStatePathName»"
«ENDFOR»
};
«ENDIF»
- const int «clsName»::s_numberOfStates = «2+states.size»;
+ const int «clsName»::s_numberOfStates = «2+orderedStateNodes.size»;
void «clsName»::setState(int new_state) {
«IF Main::settings.generateMSCInstrumentation»
@@ -69,7 +66,7 @@ class StateMachineGen extends GenericStateMachineGenerator {
«ENDIF»
static const int s_numberOfStates;
- int history[«2+states.size»];
+ int history[«2+orderedStateNodes.size»];
void setState(int new_state);
'''
@@ -83,4 +80,27 @@ class StateMachineGen extends GenericStateMachineGenerator {
"etBool"
}
+ private static class NodeComparator implements Comparator<Node> {
+
+ // it is crucial that we obey the order that is used for state IDs
+ // that means we have to collect base classes first and each base class list with leaf states last
+ override int compare(Node o1, Node o2) {
+ if (o1.inheritanceLevel==o2.inheritanceLevel) {
+ if (o1.isLeaf && o2.isLeaf) {
+ return 0
+ }
+ if (o1.isLeaf) {
+ return 1
+ }
+ if (o2.isLeaf) {
+ return -1
+ }
+ return 0
+ }
+ else {
+ return Integer.compare(o1.inheritanceLevel, o1.inheritanceLevel)
+ }
+ }
+
+ }
}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Validator.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Validator.java
index e813049dd..3d065a596 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Validator.java
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Validator.java
@@ -13,7 +13,7 @@
package org.eclipse.etrice.generator.cpp.gen;
import org.eclipse.etrice.core.genmodel.etricegen.Root;
-import org.eclipse.etrice.core.genmodel.fsm.base.ILogger;
+import org.eclipse.etrice.core.genmodel.fsm.ILogger;
import com.google.inject.Inject;
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.java
new file mode 100644
index 000000000..39e1004cb
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.java
@@ -0,0 +1,1094 @@
+/**
+ * Copyright (c) 2011 Draeger Medical GmbH (http://www.draeger.com).
+ * 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:
+ * Peter Karlitschek (initial contribution)
+ */
+package org.eclipse.etrice.generator.cpp.gen;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.fsm.fSM.ComponentCommunicationType;
+import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass;
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.core.genmodel.etricegen.Wire;
+import org.eclipse.etrice.core.genmodel.etricegen.WiredActorClass;
+import org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.ActorRef;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.ProtocolClass;
+import org.eclipse.etrice.core.room.SAP;
+import org.eclipse.etrice.core.room.SPP;
+import org.eclipse.etrice.core.room.ServiceImplementation;
+import org.eclipse.etrice.generator.cpp.Main;
+import org.eclipse.etrice.generator.cpp.gen.CppExtensions;
+import org.eclipse.etrice.generator.cpp.gen.Initialization;
+import org.eclipse.etrice.generator.cpp.gen.StateMachineGen;
+import org.eclipse.etrice.generator.fsm.base.FileSystemHelpers;
+import org.eclipse.etrice.generator.fsm.base.IGeneratorFileIo;
+import org.eclipse.etrice.generator.generic.GenericActorClassGenerator;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ListExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class ActorClassGen extends GenericActorClassGenerator {
+ @Inject
+ protected IGeneratorFileIo fileIO;
+
+ @Inject
+ @Extension
+ protected CppExtensions _cppExtensions;
+
+ @Inject
+ @Extension
+ protected RoomExtensions _roomExtensions;
+
+ @Inject
+ @Extension
+ protected ProcedureHelpers _procedureHelpers;
+
+ @Inject
+ protected Initialization initHelper;
+
+ @Inject
+ @Extension
+ protected StateMachineGen _stateMachineGen;
+
+ @Inject
+ @Extension
+ protected FileSystemHelpers _fileSystemHelpers;
+
+ public void doGenerate(final Root root) {
+ final Map<ActorClass, WiredActorClass> ac2wired = CollectionLiterals.<ActorClass, WiredActorClass>newHashMap();
+ final Consumer<WiredActorClass> _function = (WiredActorClass it) -> {
+ ac2wired.put(it.getActorClass(), it);
+ };
+ Iterables.<WiredActorClass>filter(root.getWiredInstances(), WiredActorClass.class).forEach(_function);
+ final Function1<ActorClass, Boolean> _function_1 = (ActorClass it) -> {
+ return Boolean.valueOf(this._fileSystemHelpers.isValidGenerationLocation(it));
+ };
+ final Function1<ActorClass, ExpandedActorClass> _function_2 = (ActorClass it) -> {
+ return root.getExpandedActorClass(it);
+ };
+ Iterable<ExpandedActorClass> _map = IterableExtensions.<ActorClass, ExpandedActorClass>map(IterableExtensions.<ActorClass>filter(root.getActorClasses(), _function_1), _function_2);
+ for (final ExpandedActorClass xpac : _map) {
+ {
+ final WiredActorClass wired = ac2wired.get(xpac.getActorClass());
+ final boolean manualBehavior = this._roomHelpers.isBehaviorAnnotationPresent(xpac.getActorClass(), "BehaviorManual");
+ String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(xpac.getActorClass());
+ String _path = this._roomExtensions.getPath(xpac.getActorClass());
+ final String path = (_generationTargetPath + _path);
+ String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(xpac.getActorClass());
+ String _path_1 = this._roomExtensions.getPath(xpac.getActorClass());
+ final String infopath = (_generationInfoPath + _path_1);
+ String _xifexpression = null;
+ if (manualBehavior) {
+ _xifexpression = "Abstract";
+ } else {
+ _xifexpression = "";
+ }
+ String file = _xifexpression;
+ String _cppHeaderFileName = this._cppExtensions.getCppHeaderFileName(xpac.getActorClass());
+ String _plus = (file + _cppHeaderFileName);
+ this.fileIO.generateFile("generating ActorClass declaration", path, infopath, _plus, this.generateHeaderFile(root, xpac, wired, manualBehavior));
+ String _cppSourceFileName = this._cppExtensions.getCppSourceFileName(xpac.getActorClass());
+ String _plus_1 = (file + _cppSourceFileName);
+ this.fileIO.generateFile("generating ActorClass implementation", path, infopath, _plus_1, this.generateSourceFile(root, xpac, wired, manualBehavior));
+ }
+ }
+ }
+
+ protected CharSequence generateHeaderFile(final Root root, final ExpandedActorClass xpac, final WiredActorClass wired, final boolean manualBehavior) {
+ CharSequence _xblockexpression = null;
+ {
+ final ActorClass ac = xpac.getActorClass();
+ String _xifexpression = null;
+ if (manualBehavior) {
+ String _name = ac.getName();
+ _xifexpression = ("Abstract" + _name);
+ } else {
+ _xifexpression = ac.getName();
+ }
+ final String clsname = _xifexpression;
+ String _elvis = null;
+ ActorClass _actorBase = ac.getActorBase();
+ String _name_1 = null;
+ if (_actorBase!=null) {
+ _name_1=_actorBase.getName();
+ }
+ if (_name_1 != null) {
+ _elvis = _name_1;
+ } else {
+ _elvis = "etRuntime::ActorClassBase";
+ }
+ final String rtBaseClassName = _elvis;
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @author generated by eTrice");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* Header File of ActorClass ");
+ _builder.append(clsname, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ CharSequence _generateIncludeGuardBegin = this._cppExtensions.generateIncludeGuardBegin(ac, "");
+ _builder.append(_generateIncludeGuardBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"common/etDatatypesCpp.hpp\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/IRTObject.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/PortBase.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/ReplicatedActorClassBase.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/InterfaceItemBase.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/SubSystemClassBase.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/Address.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/IMessageReceiver.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/debugging/DebuggingService.h\"");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ EList<ProtocolClass> _referencedProtocolClasses = root.getReferencedProtocolClasses(ac);
+ for(final ProtocolClass pc : _referencedProtocolClasses) {
+ _builder.append("#include \"");
+ String _path = this._roomExtensions.getPath(pc);
+ _builder.append(_path);
+ String _name_2 = pc.getName();
+ _builder.append(_name_2);
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ {
+ EList<DataClass> _referencedDataClasses = root.getReferencedDataClasses(ac);
+ for(final DataClass dc : _referencedDataClasses) {
+ _builder.append("#include \"");
+ String _path_1 = this._roomExtensions.getPath(dc);
+ _builder.append(_path_1);
+ String _name_3 = dc.getName();
+ _builder.append(_name_3);
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ {
+ ActorClass _actorBase_1 = ac.getActorBase();
+ boolean _equals = Objects.equal(_actorBase_1, null);
+ if (_equals) {
+ _builder.append("#include \"common/modelbase/ActorClassBase.h\"");
+ _builder.newLine();
+ } else {
+ _builder.append("#include \"");
+ String _path_2 = this._roomExtensions.getPath(ac.getActorBase());
+ _builder.append(_path_2);
+ String _name_4 = ac.getActorBase().getName();
+ _builder.append(_name_4);
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ {
+ EList<ActorRef> _actorRefs = ac.getActorRefs();
+ for(final ActorRef ar : _actorRefs) {
+ _builder.append("#include \"");
+ String _actorIncludePath = this._cppExtensions.getActorIncludePath(ar.getType());
+ _builder.append(_actorIncludePath);
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ CharSequence _userCode = this._procedureHelpers.userCode(ac.getUserCode1());
+ _builder.append(_userCode);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("using namespace etRuntime;");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceBegin = this._cppExtensions.generateNamespaceBegin(ac);
+ _builder.append(_generateNamespaceBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("class ");
+ _builder.append(clsname);
+ _builder.append(" : public ");
+ _builder.append(rtBaseClassName);
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("protected:");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("//--------------------- ports");
+ _builder.newLine();
+ {
+ List<Port> _endPorts = this._roomHelpers.getEndPorts(ac);
+ for(final Port ep : _endPorts) {
+ _builder.append("\t\t");
+ String _portClassName = this._roomExtensions.getPortClassName(ep);
+ _builder.append(_portClassName, "\t\t");
+ _builder.append(" ");
+ String _name_5 = ep.getName();
+ _builder.append(_name_5, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("//--------------------- sub actors");
+ _builder.newLine();
+ {
+ EList<ActorRef> _actorRefs_1 = ac.getActorRefs();
+ for(final ActorRef sub : _actorRefs_1) {
+ {
+ int _multiplicity = sub.getMultiplicity();
+ boolean _greaterThan = (_multiplicity > 1);
+ if (_greaterThan) {
+ _builder.append("\t\t");
+ _builder.append("Replicated");
+ String _implementationClassName = this._cppExtensions.getImplementationClassName(sub.getType());
+ _builder.append(_implementationClassName, "\t\t");
+ _builder.append(" ");
+ String _name_6 = sub.getName();
+ _builder.append(_name_6, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t\t");
+ String _implementationClassName_1 = this._cppExtensions.getImplementationClassName(sub.getType());
+ _builder.append(_implementationClassName_1, "\t\t");
+ _builder.append(" ");
+ String _name_7 = sub.getName();
+ _builder.append(_name_7, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("//--------------------- saps");
+ _builder.newLine();
+ {
+ EList<SAP> _serviceAccessPoints = ac.getServiceAccessPoints();
+ for(final SAP sap : _serviceAccessPoints) {
+ _builder.append("\t\t");
+ String _portClassName_1 = this._roomExtensions.getPortClassName(sap);
+ _builder.append(_portClassName_1, "\t\t");
+ _builder.append(" ");
+ String _name_8 = sap.getName();
+ _builder.append(_name_8, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("//--------------------- services");
+ _builder.newLine();
+ {
+ EList<ServiceImplementation> _serviceImplementations = ac.getServiceImplementations();
+ for(final ServiceImplementation svc : _serviceImplementations) {
+ _builder.append("\t\t");
+ String _portClassName_2 = this._roomExtensions.getPortClassName(svc);
+ _builder.append(_portClassName_2, "\t\t");
+ _builder.append(" ");
+ String _name_9 = svc.getSpp().getName();
+ _builder.append(_name_9, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("//--------------------- interface item IDs");
+ _builder.newLine();
+ _builder.append("\t\t");
+ String _genInterfaceItemConstants = this.genInterfaceItemConstants(xpac);
+ _builder.append(_genInterfaceItemConstants, "\t\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t\t");
+ CharSequence _attributes = this._procedureHelpers.attributes(ac.getAttributes());
+ _builder.append(_attributes, "\t\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t\t");
+ CharSequence _operationsDeclaration = this._procedureHelpers.operationsDeclaration(ac.getOperations(), ac.getName());
+ _builder.append(_operationsDeclaration, "\t\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public:");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("//--------------------- construction");
+ _builder.newLine();
+ _builder.append("\t\t");
+ String _name_10 = ac.getName();
+ _builder.append(_name_10, "\t\t");
+ _builder.append("(etRuntime::IRTObject* parent, const String& name);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("void initialize(void);");
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation) {
+ _builder.append("\t\t");
+ _builder.append("void setProbesActive(bool recursive, bool active);");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("//--------------------- port getters");
+ _builder.newLine();
+ _builder.append("\t\t");
+ final Function1<Port, CharSequence> _function = (Port it) -> {
+ String _portClassName_3 = this._roomExtensions.getPortClassName(it);
+ String _plus = (_portClassName_3 + "&");
+ return this._procedureHelpers.getterImplementation(_plus, it.getName(), clsname);
+ };
+ String _join = IterableExtensions.join(ListExtensions.<Port, CharSequence>map(this._roomHelpers.getEndPorts(ac), _function), this._roomExtensions.NEWLINE);
+ _builder.append(_join, "\t\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t\t");
+ final Function1<SAP, CharSequence> _function_1 = (SAP it) -> {
+ String _portClassName_3 = this._roomExtensions.getPortClassName(it);
+ String _plus = (_portClassName_3 + "&");
+ return this._procedureHelpers.getterImplementation(_plus, it.getName(), clsname);
+ };
+ String _join_1 = IterableExtensions.join(ListExtensions.<SAP, CharSequence>map(ac.getServiceAccessPoints(), _function_1), this._roomExtensions.NEWLINE);
+ _builder.append(_join_1, "\t\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t\t");
+ final Function1<ServiceImplementation, CharSequence> _function_2 = (ServiceImplementation it) -> {
+ String _portClassName_3 = this._roomExtensions.getPortClassName(it);
+ String _plus = (_portClassName_3 + "&");
+ return this._procedureHelpers.getterImplementation(_plus, it.getSpp().getName(), clsname);
+ };
+ String _join_2 = IterableExtensions.join(ListExtensions.<ServiceImplementation, CharSequence>map(ac.getServiceImplementations(), _function_2), this._roomExtensions.NEWLINE);
+ _builder.append(_join_2, "\t\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("//--------------------- lifecycle functions");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("virtual void destroy();");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ boolean _hasNonEmptyStateMachine = this._roomHelpers.hasNonEmptyStateMachine(ac);
+ if (_hasNonEmptyStateMachine) {
+ _builder.append("\t\t");
+ CharSequence _genStateMachineConstants = this._stateMachineGen.genStateMachineConstants(xpac.getGraphContainer());
+ _builder.append(_genStateMachineConstants, "\t\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t\t");
+ CharSequence _genStateMachineMethods = this._stateMachineGen.genStateMachineMethods(xpac.getGraphContainer(), false);
+ _builder.append(_genStateMachineMethods, "\t\t");
+ _builder.newLineIfNotEmpty();
+ {
+ ComponentCommunicationType _commType = ac.getCommType();
+ boolean _equals_1 = Objects.equal(_commType, ComponentCommunicationType.DATA_DRIVEN);
+ if (_equals_1) {
+ _builder.append("\t\t");
+ _builder.append("void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* generic_data);");
+ _builder.newLine();
+ }
+ }
+ {
+ if ((Objects.equal(ac.getCommType(), ComponentCommunicationType.ASYNCHRONOUS) || Objects.equal(ac.getCommType(), ComponentCommunicationType.DATA_DRIVEN))) {
+ _builder.append("\t\t");
+ _builder.append("virtual void receive(const etRuntime::Message* msg);");
+ _builder.newLine();
+ }
+ }
+ } else {
+ boolean _isEmpty = FsmGenExtensions.isEmpty(xpac.getGraphContainer().getGraph());
+ if (_isEmpty) {
+ _builder.append("\t\t");
+ _builder.append("//--------------------- no state machine");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data);");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("virtual void executeInitTransition() {}");
+ _builder.newLine();
+ }
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t\t");
+ CharSequence _userCode_1 = this._procedureHelpers.userCode(ac.getUserCode2());
+ _builder.append(_userCode_1, "\t\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("class Replicated");
+ _builder.append(clsname);
+ _builder.append(" : public ReplicatedActorClassBase {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("public:");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("Replicated");
+ _builder.append(clsname, "\t");
+ _builder.append("(IRTObject* parent, const String& name) :");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("ReplicatedActorClassBase(parent, name) {}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("protected:");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("ActorClassBase* createActor(IRTObject* parent, const String& name) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("return new ");
+ _builder.append(clsname, "\t\t");
+ _builder.append("(parent, name);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceEnd = this._cppExtensions.generateNamespaceEnd(ac);
+ _builder.append(_generateNamespaceEnd);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ CharSequence _generateIncludeGuardEnd = this._cppExtensions.generateIncludeGuardEnd(ac, "");
+ _builder.append(_generateIncludeGuardEnd);
+ _builder.newLineIfNotEmpty();
+ _xblockexpression = _builder;
+ }
+ return _xblockexpression;
+ }
+
+ private CharSequence generateConstructorInitalizerList(final ActorClass ac) {
+ CharSequence _xblockexpression = null;
+ {
+ @Extension
+ final Initialization initHelper = this.initHelper;
+ ArrayList<CharSequence> initList = CollectionLiterals.<CharSequence>newArrayList();
+ StringConcatenation _builder = new StringConcatenation();
+ String _elvis = null;
+ ActorClass _actorBase = ac.getActorBase();
+ String _name = null;
+ if (_actorBase!=null) {
+ _name=_actorBase.getName();
+ }
+ if (_name != null) {
+ _elvis = _name;
+ } else {
+ _elvis = "ActorClassBase";
+ }
+ _builder.append(_elvis);
+ _builder.append("(parent, name)");
+ initList.add(_builder.toString());
+ final Function1<Port, String> _function = (Port it) -> {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ String _name_1 = it.getName();
+ _builder_1.append(_name_1);
+ _builder_1.append("(this, \"");
+ String _name_2 = it.getName();
+ _builder_1.append(_name_2);
+ _builder_1.append("\", IFITEM_");
+ String _name_3 = it.getName();
+ _builder_1.append(_name_3);
+ _builder_1.append(")");
+ return _builder_1.toString();
+ };
+ List<String> _map = ListExtensions.<Port, String>map(this._roomHelpers.getEndPorts(ac), _function);
+ Iterables.<CharSequence>addAll(initList, _map);
+ final Function1<ActorRef, String> _function_1 = (ActorRef it) -> {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ String _name_1 = it.getName();
+ _builder_1.append(_name_1);
+ _builder_1.append("(this, \"");
+ String _name_2 = it.getName();
+ _builder_1.append(_name_2);
+ _builder_1.append("\")");
+ return _builder_1.toString();
+ };
+ List<String> _map_1 = ListExtensions.<ActorRef, String>map(ac.getActorRefs(), _function_1);
+ Iterables.<CharSequence>addAll(initList, _map_1);
+ final Function1<SAP, String> _function_2 = (SAP it) -> {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ String _name_1 = it.getName();
+ _builder_1.append(_name_1);
+ _builder_1.append("(this, \"");
+ String _name_2 = it.getName();
+ _builder_1.append(_name_2);
+ _builder_1.append("\", IFITEM_");
+ String _name_3 = it.getName();
+ _builder_1.append(_name_3);
+ _builder_1.append(")");
+ return _builder_1.toString();
+ };
+ List<String> _map_2 = ListExtensions.<SAP, String>map(ac.getServiceAccessPoints(), _function_2);
+ Iterables.<CharSequence>addAll(initList, _map_2);
+ final Function1<ServiceImplementation, String> _function_3 = (ServiceImplementation it) -> {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ String _name_1 = it.getSpp().getName();
+ _builder_1.append(_name_1);
+ _builder_1.append("(this, \"");
+ String _name_2 = it.getSpp().getName();
+ _builder_1.append(_name_2);
+ _builder_1.append("\", IFITEM_");
+ String _name_3 = it.getSpp().getName();
+ _builder_1.append(_name_3);
+ _builder_1.append(")");
+ return _builder_1.toString();
+ };
+ List<String> _map_3 = ListExtensions.<ServiceImplementation, String>map(ac.getServiceImplementations(), _function_3);
+ Iterables.<CharSequence>addAll(initList, _map_3);
+ final Function1<Attribute, String> _function_4 = (Attribute it) -> {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ String _name_1 = it.getName();
+ _builder_1.append(_name_1);
+ _builder_1.append("(");
+ String _initializerListValue = initHelper.getInitializerListValue(it);
+ _builder_1.append(_initializerListValue);
+ _builder_1.append(")");
+ return _builder_1.toString();
+ };
+ List<String> _map_4 = ListExtensions.<Attribute, String>map(ac.getAttributes(), _function_4);
+ Iterables.<CharSequence>addAll(initList, _map_4);
+ _xblockexpression = initHelper.generateCtorInitializerList(initList);
+ }
+ return _xblockexpression;
+ }
+
+ protected CharSequence generateSourceFile(final Root root, final ExpandedActorClass xpac, final WiredActorClass wired, final boolean manualBehavior) {
+ CharSequence _xblockexpression = null;
+ {
+ final ActorClass ac = xpac.getActorClass();
+ String _xifexpression = null;
+ if (manualBehavior) {
+ String _name = ac.getName();
+ _xifexpression = ("Abstract" + _name);
+ } else {
+ _xifexpression = ac.getName();
+ }
+ final String clsname = _xifexpression;
+ String _elvis = null;
+ ActorClass _actorBase = ac.getActorBase();
+ String _name_1 = null;
+ if (_actorBase!=null) {
+ _name_1=_actorBase.getName();
+ }
+ if (_name_1 != null) {
+ _elvis = _name_1;
+ } else {
+ _elvis = "ActorClassBase";
+ }
+ final String rtBaseClassName = _elvis;
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @author generated by eTrice");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* Source File of ActorClass ");
+ String _name_2 = ac.getName();
+ _builder.append(_name_2, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("#include \"");
+ String _cppHeaderFileName = this._cppExtensions.getCppHeaderFileName(ac);
+ _builder.append(_cppHeaderFileName);
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/RTObject.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/RTServices.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/debugging/DebuggingService.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/debugging/MSCFunctionObject.h\"");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("using namespace etRuntime;");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceBegin = this._cppExtensions.generateNamespaceBegin(ac);
+ _builder.append(_generateNamespaceBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ CharSequence _userCode = this._procedureHelpers.userCode(ac.getUserCode3());
+ _builder.append(_userCode);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append(clsname);
+ _builder.append("::");
+ _builder.append(clsname);
+ _builder.append("(etRuntime::IRTObject* parent, const String& name)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ CharSequence _generateConstructorInitalizerList = this.generateConstructorInitalizerList(ac);
+ _builder.append(_generateConstructorInitalizerList, "\t\t");
+ _builder.newLineIfNotEmpty();
+ _builder.append("{");
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation) {
+ _builder.append("\t");
+ _builder.append("MSCFunctionObject mscFunctionObject(getInstancePathName(), \"Constructor\");");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ {
+ boolean _hasNonEmptyStateMachine = this._roomHelpers.hasNonEmptyStateMachine(ac);
+ if (_hasNonEmptyStateMachine) {
+ _builder.append("\t");
+ _builder.append("for (int i = 0; i < s_numberOfStates; i++) {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("history[i] = NO_STATE;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("setClassName(\"");
+ String _name_3 = ac.getName();
+ _builder.append(_name_3, "\t");
+ _builder.append("\");");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// sub actors");
+ _builder.newLine();
+ {
+ EList<ActorRef> _actorRefs = ac.getActorRefs();
+ for(final ActorRef sub : _actorRefs) {
+ {
+ int _multiplicity = sub.getMultiplicity();
+ boolean _greaterThan = (_multiplicity > 1);
+ if (_greaterThan) {
+ _builder.append("\t");
+ String _name_4 = sub.getName();
+ _builder.append(_name_4, "\t");
+ _builder.append(".createSubActors(");
+ int _multiplicity_1 = sub.getMultiplicity();
+ _builder.append(_multiplicity_1, "\t");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _genExtraInitializers = this.initHelper.genExtraInitializers(ac.getAttributes());
+ _builder.append(_genExtraInitializers, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _userStructorBody = this._procedureHelpers.userStructorBody(ac, true);
+ _builder.append(_userStructorBody, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_5 = ac.getName();
+ _builder.append(_name_5);
+ _builder.append("::initialize() {");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _isGenerateMSCInstrumentation_1 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_1) {
+ _builder.append("\t");
+ _builder.append("MSCFunctionObject mscFunctionObject(getInstancePathName(), \"initialize()\");");
+ _builder.newLine();
+ {
+ EList<ActorRef> _actorRefs_1 = ac.getActorRefs();
+ for(final ActorRef sub_1 : _actorRefs_1) {
+ {
+ int _multiplicity_2 = sub_1.getMultiplicity();
+ boolean _greaterThan_1 = (_multiplicity_2 > 1);
+ if (_greaterThan_1) {
+ _builder.append("\t");
+ _builder.append("for (int i=0; i<");
+ int _multiplicity_3 = sub_1.getMultiplicity();
+ _builder.append(_multiplicity_3, "\t");
+ _builder.append("; ++i) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addMessageActorCreate(*this, ");
+ String _name_6 = sub_1.getName();
+ _builder.append(_name_6, "\t\t");
+ _builder.append(".getSubActor(i)->getName());");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ } else {
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addMessageActorCreate(*this, \"");
+ String _name_7 = sub_1.getName();
+ _builder.append(_name_7, "\t");
+ _builder.append("\");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("ActorClassBase::initialize();");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.newLine();
+ {
+ EList<ActorRef> _actorRefs_2 = ac.getActorRefs();
+ for(final ActorRef sub_2 : _actorRefs_2) {
+ _builder.append("\t");
+ String _name_8 = sub_2.getName();
+ _builder.append(_name_8, "\t");
+ _builder.append(".initialize();");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// wiring");
+ _builder.newLine();
+ {
+ EList<Wire> _wires = wired.getWires();
+ for(final Wire wire : _wires) {
+ _builder.append("\t");
+ String _xifexpression_1 = null;
+ boolean _isDataDriven = wire.isDataDriven();
+ if (_isDataDriven) {
+ _xifexpression_1 = "DataPortBase";
+ } else {
+ _xifexpression_1 = "InterfaceItemBase";
+ }
+ _builder.append(_xifexpression_1, "\t");
+ _builder.append("::connect(this, \"");
+ String _join = IterableExtensions.join(wire.getPath1(), "/");
+ _builder.append(_join, "\t");
+ _builder.append("\", \"");
+ String _join_1 = IterableExtensions.join(wire.getPath2(), "/");
+ _builder.append(_join_1, "\t");
+ _builder.append("\");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ {
+ if ((Objects.equal(ac.getCommType(), ComponentCommunicationType.ASYNCHRONOUS) || Objects.equal(ac.getCommType(), ComponentCommunicationType.DATA_DRIVEN))) {
+ _builder.append("\t");
+ _builder.append("// activate polling for data-driven communication");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("RTServices::getInstance().getMsgSvcCtrl().getMsgSvc(getThread())->addPollingMessageReceiver(*this);");
+ _builder.newLine();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation_2 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_2) {
+ _builder.append("void ");
+ String _name_9 = ac.getName();
+ _builder.append(_name_9);
+ _builder.append("::setProbesActive(bool recursive, bool active) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addPortInstance(m_RTSystemPort);");
+ _builder.newLine();
+ {
+ int _size = ac.getActorRefs().size();
+ boolean _greaterThan_2 = (_size > 0);
+ if (_greaterThan_2) {
+ _builder.append("\t");
+ _builder.append("if(recursive) {");
+ _builder.newLine();
+ {
+ EList<ActorRef> _actorRefs_3 = ac.getActorRefs();
+ for(final ActorRef sub_3 : _actorRefs_3) {
+ _builder.append("\t");
+ _builder.append("\t");
+ String _name_10 = sub_3.getName();
+ _builder.append(_name_10, "\t\t");
+ _builder.append(".setProbesActive(recursive, active);");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ {
+ List<Port> _endPorts = this._roomHelpers.getEndPorts(ac);
+ for(final Port ep : _endPorts) {
+ {
+ boolean _isDataDriven_1 = this._roomHelpers.isDataDriven(ep);
+ boolean _not = (!_isDataDriven_1);
+ if (_not) {
+ {
+ boolean _isReplicated = ep.isReplicated();
+ if (_isReplicated) {
+ _builder.append("\t");
+ _builder.append("for(int i = 0; i < ");
+ String _name_11 = ep.getName();
+ _builder.append(_name_11, "\t");
+ _builder.append(".getNInterfaceItems(); i++)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addPortInstance(*(");
+ String _name_12 = ep.getName();
+ _builder.append(_name_12, "\t\t");
+ _builder.append(".getInterfaceItem(i)));");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addPortInstance(");
+ String _name_13 = ep.getName();
+ _builder.append(_name_13, "\t");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ }
+ }
+ {
+ EList<SAP> _serviceAccessPoints = ac.getServiceAccessPoints();
+ for(final SAP sap : _serviceAccessPoints) {
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addPortInstance(");
+ String _name_14 = sap.getName();
+ _builder.append(_name_14, "\t");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ {
+ EList<SPP> _serviceProvisionPoints = ac.getServiceProvisionPoints();
+ for(final SPP spp : _serviceProvisionPoints) {
+ _builder.append("\t");
+ _builder.append("for(int i = 0; i < ");
+ String _name_15 = spp.getName();
+ _builder.append(_name_15, "\t");
+ _builder.append(".getNInterfaceItems(); i++)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t\t");
+ _builder.append("DebuggingService::getInstance().addPortInstance(*(");
+ String _name_16 = spp.getName();
+ _builder.append(_name_16, "\t\t\t");
+ _builder.append(".getInterfaceItem(i)));");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_17 = ac.getName();
+ _builder.append(_name_17);
+ _builder.append("::destroy(){");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _isGenerateMSCInstrumentation_3 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_3) {
+ _builder.append("\t");
+ _builder.append("MSCFunctionObject mscFunctionObject(getInstancePathName(), \"destroy()\");");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ String _userStructorBody_1 = this._procedureHelpers.userStructorBody(ac, false);
+ _builder.append(_userStructorBody_1, "\t");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _isGenerateMSCInstrumentation_4 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_4) {
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addMessageActorDestroy(*this);");
+ _builder.newLine();
+ }
+ }
+ {
+ if ((Objects.equal(ac.getCommType(), ComponentCommunicationType.ASYNCHRONOUS) || Objects.equal(ac.getCommType(), ComponentCommunicationType.DATA_DRIVEN))) {
+ _builder.append("\t");
+ _builder.append("RTServices::getInstance().getMsgSvcCtrl().getMsgSvc(getThread())->removePollingMessageReceiver(*this);");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append(rtBaseClassName, "\t");
+ _builder.append("::destroy();");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ CharSequence _operationsImplementation = this._procedureHelpers.operationsImplementation(ac.getOperations(), ac.getName());
+ _builder.append(_operationsImplementation);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ {
+ boolean _hasNonEmptyStateMachine_1 = this._roomHelpers.hasNonEmptyStateMachine(ac);
+ if (_hasNonEmptyStateMachine_1) {
+ CharSequence _genStateMachineMethods = this._stateMachineGen.genStateMachineMethods(xpac.getGraphContainer(), true);
+ _builder.append(_genStateMachineMethods);
+ _builder.newLineIfNotEmpty();
+ {
+ ComponentCommunicationType _commType = ac.getCommType();
+ boolean _equals = Objects.equal(_commType, ComponentCommunicationType.DATA_DRIVEN);
+ if (_equals) {
+ _builder.append("void ");
+ String _name_18 = ac.getName();
+ _builder.append(_name_18);
+ _builder.append("::receiveEvent(InterfaceItemBase* ifitem, int evt, void* generic_data) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("handleSystemEvent(ifitem, evt, generic_data);");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ {
+ if ((Objects.equal(ac.getCommType(), ComponentCommunicationType.ASYNCHRONOUS) || Objects.equal(ac.getCommType(), ComponentCommunicationType.DATA_DRIVEN))) {
+ _builder.append("void ");
+ String _name_19 = ac.getName();
+ _builder.append(_name_19);
+ _builder.append("::receive(const Message* msg) {");
+ _builder.newLineIfNotEmpty();
+ {
+ ComponentCommunicationType _commType_1 = ac.getCommType();
+ boolean _equals_1 = Objects.equal(_commType_1, ComponentCommunicationType.ASYNCHRONOUS);
+ if (_equals_1) {
+ _builder.append("\t");
+ _builder.append("receiveEvent(0, -1, 0);");
+ _builder.newLine();
+ } else {
+ _builder.append("\t");
+ _builder.append("receiveEventInternal();");
+ _builder.newLine();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ } else {
+ boolean _isEmpty = FsmGenExtensions.isEmpty(xpac.getGraphContainer().getGraph());
+ if (_isEmpty) {
+ _builder.append("//--------------------- no state machine");
+ _builder.newLine();
+ _builder.append("void ");
+ String _name_20 = ac.getName();
+ _builder.append(_name_20);
+ _builder.append("::receiveEvent(InterfaceItemBase* ifitem, int evt, void* data) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("handleSystemEvent(ifitem, evt, data);");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ _builder.newLine();
+ String _generateNamespaceEnd = this._cppExtensions.generateNamespaceEnd(ac);
+ _builder.append(_generateNamespaceEnd);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _xblockexpression = _builder;
+ }
+ return _xblockexpression;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.java
new file mode 100644
index 000000000..d29b527d7
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.java
@@ -0,0 +1,525 @@
+/**
+ * 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
+ * Peter Karlitschek
+ */
+package org.eclipse.etrice.generator.cpp.gen;
+
+import com.google.common.base.Objects;
+import com.google.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance;
+import org.eclipse.etrice.core.genmodel.etricegen.InstanceBase;
+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.DataClass;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.EnumerationType;
+import org.eclipse.etrice.core.room.ExternalType;
+import org.eclipse.etrice.core.room.PortClass;
+import org.eclipse.etrice.core.room.PrimitiveType;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.generator.base.IDataConfiguration;
+import org.eclipse.etrice.generator.cpp.gen.CppExtensions;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.generic.TypeHelpers;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.Conversions;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.StringExtensions;
+
+@SuppressWarnings("all")
+public class ConfigGenAddon {
+ @Inject
+ @Extension
+ private CppExtensions stdExt;
+
+ @Inject
+ @Extension
+ private TypeHelpers typeHelpers;
+
+ @Inject
+ @Extension
+ private ProcedureHelpers helpers;
+
+ @Inject
+ private IDataConfiguration dataConfigExt;
+
+ @Inject
+ @Extension
+ private RoomHelpers _roomHelpers;
+
+ @Inject
+ @Extension
+ private RoomExtensions _roomExtensions;
+
+ public CharSequence genActorInstanceConfig(final ActorInstance ai, final String aiVariableName) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ List<Attribute> _allAttributes = this._roomHelpers.getAllAttributes(ai.getActorClass());
+ for(final Attribute a : _allAttributes) {
+ String _applyInstanceConfig = this.applyInstanceConfig(ai, aiVariableName, this._roomExtensions.<Attribute>union(new ArrayList<Attribute>(), a));
+ _builder.append(_applyInstanceConfig);
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ {
+ EList<InterfaceItemInstance> _orderedIfItemInstances = ai.getOrderedIfItemInstances();
+ for(final InterfaceItemInstance pi : _orderedIfItemInstances) {
+ PortClass _portClass = this._roomHelpers.getPortClass(pi.getInterfaceItem());
+ EList<Attribute> _attributes = null;
+ if (_portClass!=null) {
+ _attributes=_portClass.getAttributes();
+ }
+ EList<Attribute> attribs = _attributes;
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _notEquals = (!Objects.equal(attribs, null));
+ if (_notEquals) {
+ {
+ for(final Attribute a_1 : attribs) {
+ CharSequence _invokeGetter = this.helpers.invokeGetter(pi.getName(), null);
+ String _plus = ((aiVariableName + ".") + _invokeGetter);
+ String _applyInstanceConfig_1 = this.applyInstanceConfig(pi, _plus, this._roomExtensions.<Attribute>union(new ArrayList<Attribute>(), a_1));
+ _builder.append(_applyInstanceConfig_1);
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ }
+ }
+ return _builder;
+ }
+
+ private String applyInstanceConfig(final InstanceBase instance, final String invokes, final List<Attribute> path) {
+ String _xblockexpression = null;
+ {
+ Attribute a = IterableExtensions.<Attribute>last(path);
+ DataType aType = a.getType().getType();
+ String _xifexpression = null;
+ boolean _isPrimitive = this.typeHelpers.isPrimitive(aType);
+ if (_isPrimitive) {
+ String _xblockexpression_1 = null;
+ {
+ String value = this.typeHelpers.getAttrInstanceConfigValue(path, instance);
+ String _xifexpression_1 = null;
+ boolean _equals = Objects.equal(value, null);
+ if (_equals) {
+ StringConcatenation _builder = new StringConcatenation();
+ _xifexpression_1 = _builder.toString();
+ } else {
+ String _xifexpression_2 = null;
+ if (((a.getSize() == 0) || this.typeHelpers.isCharacterType(aType))) {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append(invokes);
+ _builder_1.append(".");
+ CharSequence _invokeSetter = this.helpers.invokeSetter(a.getName(), null, this.stdExt.toValueLiteral(((PrimitiveType) aType), value));
+ _builder_1.append(_invokeSetter);
+ _builder_1.append(";");
+ _xifexpression_2 = _builder_1.toString();
+ } else {
+ String _xifexpression_3 = null;
+ int _size = a.getSize();
+ int _size_1 = ((List<String>)Conversions.doWrapArray(value.split(","))).size();
+ boolean _equals_1 = (_size == _size_1);
+ if (_equals_1) {
+ String _xblockexpression_2 = null;
+ {
+ StringConcatenation _builder_2 = new StringConcatenation();
+ _builder_2.append("{ ");
+ {
+ String[] _split = value.split(",");
+ boolean _hasElements = false;
+ for(final String s : _split) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder_2.appendImmediate(", ", "");
+ }
+ String _valueLiteral = this.stdExt.toValueLiteral(((PrimitiveType) aType), s.trim());
+ _builder_2.append(_valueLiteral);
+ }
+ }
+ _builder_2.append(" }");
+ String arrayExpr = _builder_2.toString();
+ StringConcatenation _builder_3 = new StringConcatenation();
+ _builder_3.append(invokes);
+ _builder_3.append(".");
+ StringConcatenation _builder_4 = new StringConcatenation();
+ _builder_4.append("new ");
+ String _typeName = this.typeHelpers.typeName(aType);
+ _builder_4.append(_typeName);
+ _builder_4.append("[] ");
+ _builder_4.append(arrayExpr);
+ CharSequence _invokeSetter_1 = this.helpers.invokeSetter(a.getName(), null, _builder_4.toString());
+ _builder_3.append(_invokeSetter_1);
+ _builder_3.append(";");
+ _xblockexpression_2 = _builder_3.toString();
+ }
+ _xifexpression_3 = _xblockexpression_2;
+ } else {
+ StringConcatenation _builder_2 = new StringConcatenation();
+ _builder_2.append("{");
+ _builder_2.newLine();
+ _builder_2.append("\t");
+ String _typeName = this.typeHelpers.typeName(aType);
+ _builder_2.append(_typeName, "\t");
+ _builder_2.append("[] array = ");
+ _builder_2.append(invokes, "\t");
+ _builder_2.append(".");
+ CharSequence _invokeGetter = this.helpers.invokeGetter(a.getName(), null);
+ _builder_2.append(_invokeGetter, "\t");
+ _builder_2.append(";");
+ _builder_2.newLineIfNotEmpty();
+ _builder_2.append("\t");
+ _builder_2.append("for (int i=0;i<");
+ int _size_2 = a.getSize();
+ _builder_2.append(_size_2, "\t");
+ _builder_2.append(";i++){");
+ _builder_2.newLineIfNotEmpty();
+ _builder_2.append("\t\t");
+ _builder_2.append("array[i] = ");
+ String _valueLiteral = this.stdExt.toValueLiteral(((PrimitiveType) aType), value);
+ _builder_2.append(_valueLiteral, "\t\t");
+ _builder_2.append(";");
+ _builder_2.newLineIfNotEmpty();
+ _builder_2.append("}");
+ _xifexpression_3 = _builder_2.toString();
+ }
+ _xifexpression_2 = _xifexpression_3;
+ }
+ _xifexpression_1 = _xifexpression_2;
+ }
+ _xblockexpression_1 = _xifexpression_1;
+ }
+ _xifexpression = _xblockexpression_1;
+ } else {
+ String _xifexpression_1 = null;
+ boolean _isDataClass = this.typeHelpers.isDataClass(aType);
+ if (_isDataClass) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ EList<Attribute> _attributes = ((DataClass) aType).getAttributes();
+ for(final Attribute e : _attributes) {
+ CharSequence _invokeGetter = this.helpers.invokeGetter(a.getName(), null);
+ String _plus = ((invokes + ".") + _invokeGetter);
+ String _applyInstanceConfig = this.applyInstanceConfig(instance, _plus, this._roomExtensions.<Attribute>union(path, e));
+ _builder.append(_applyInstanceConfig);
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _xifexpression_1 = _builder.toString();
+ }
+ _xifexpression = _xifexpression_1;
+ }
+ _xblockexpression = _xifexpression;
+ }
+ return _xblockexpression;
+ }
+
+ public CharSequence genDynConfigGetterSetter(final ActorClass ac) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ List<Attribute> _dynConfigReadAttributes = this.dataConfigExt.getDynConfigReadAttributes(ac);
+ for(final Attribute a : _dynConfigReadAttributes) {
+ _builder.append("public ");
+ String _typeName = this.typeHelpers.typeName(a.getType().getType());
+ _builder.append(_typeName);
+ {
+ int _size = a.getSize();
+ boolean _greaterThan = (_size > 0);
+ if (_greaterThan) {
+ _builder.append("[]");
+ }
+ }
+ _builder.append(" get");
+ String _firstUpper = StringExtensions.toFirstUpper(a.getName());
+ _builder.append(_firstUpper);
+ _builder.append("(){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("if(lock_");
+ String _name = a.getName();
+ _builder.append(_name, "\t");
+ _builder.append(" == null)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("return ");
+ String _name_1 = a.getName();
+ _builder.append(_name_1, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("else");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("synchronized(lock_");
+ String _name_2 = a.getName();
+ _builder.append(_name_2, "\t\t");
+ _builder.append("){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("return ");
+ String _name_3 = a.getName();
+ _builder.append(_name_3, "\t\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("public void set");
+ String _firstUpper_1 = StringExtensions.toFirstUpper(a.getName());
+ _builder.append(_firstUpper_1);
+ _builder.append("(");
+ String _typeName_1 = this.typeHelpers.typeName(a.getType().getType());
+ _builder.append(_typeName_1);
+ {
+ int _size_1 = a.getSize();
+ boolean _greaterThan_1 = (_size_1 > 0);
+ if (_greaterThan_1) {
+ _builder.append("[]");
+ }
+ }
+ _builder.append(" ");
+ String _name_4 = a.getName();
+ _builder.append(_name_4);
+ _builder.append("){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("if(lock_");
+ String _name_5 = a.getName();
+ _builder.append(_name_5, "\t");
+ _builder.append(" == null)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("this.");
+ String _name_6 = a.getName();
+ _builder.append(_name_6, "\t\t");
+ _builder.append(" = ");
+ String _name_7 = a.getName();
+ _builder.append(_name_7, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("else");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("synchronized(lock_");
+ String _name_8 = a.getName();
+ _builder.append(_name_8, "\t\t");
+ _builder.append("){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t\t");
+ _builder.append("this.");
+ String _name_9 = a.getName();
+ _builder.append(_name_9, "\t\t\t");
+ _builder.append(" = ");
+ String _name_10 = a.getName();
+ _builder.append(_name_10, "\t\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("public DynConfigLock get");
+ String _firstUpper_2 = StringExtensions.toFirstUpper(a.getName());
+ _builder.append(_firstUpper_2);
+ _builder.append("Lock(){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("return lock_");
+ String _name_11 = a.getName();
+ _builder.append(_name_11, "\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}\t");
+ _builder.newLine();
+ }
+ }
+ {
+ List<Attribute> _dynConfigWriteAttributes = this.dataConfigExt.getDynConfigWriteAttributes(ac);
+ for(final Attribute a_1 : _dynConfigWriteAttributes) {
+ _builder.append("public void setAndWrite");
+ String _firstUpper_3 = StringExtensions.toFirstUpper(a_1.getName());
+ _builder.append(_firstUpper_3);
+ _builder.append("(");
+ String _typeName_2 = this.typeHelpers.typeName(a_1.getType().getType());
+ _builder.append(_typeName_2);
+ {
+ int _size_2 = a_1.getSize();
+ boolean _greaterThan_2 = (_size_2 > 0);
+ if (_greaterThan_2) {
+ _builder.append("[]");
+ }
+ }
+ _builder.append(" ");
+ String _name_12 = a_1.getName();
+ _builder.append(_name_12);
+ _builder.append("){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("set");
+ String _firstUpper_4 = StringExtensions.toFirstUpper(a_1.getName());
+ _builder.append(_firstUpper_4, "\t\t");
+ _builder.append("(");
+ String _name_13 = a_1.getName();
+ _builder.append(_name_13, "\t\t");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("variableService.write(this.getInstancePath()+\"/");
+ String _name_14 = a_1.getName();
+ _builder.append(_name_14, "\t\t");
+ _builder.append("\", ");
+ String _name_15 = a_1.getName();
+ _builder.append(_name_15, "\t\t");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ return _builder;
+ }
+
+ public String genMinMaxConstants(final ActorClass ac) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ EList<Attribute> _attributes = ac.getAttributes();
+ for(final Attribute a : _attributes) {
+ String _genMinMaxConstantsRec = this.genMinMaxConstantsRec(ac, a.getName(), this._roomExtensions.<Attribute>union(new ArrayList<Attribute>(), a));
+ _builder.append(_genMinMaxConstantsRec);
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ String result = _builder.toString();
+ int _length = result.length();
+ boolean _notEquals = (_length != 0);
+ if (_notEquals) {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("//--------------------- Attribute Specifications");
+ String _plus = (result + _builder_1);
+ result = _plus;
+ }
+ return result;
+ }
+
+ private String genMinMaxConstantsRec(final ActorClass ac, final String varNamePath, final List<Attribute> path) {
+ String _xblockexpression = null;
+ {
+ String temp = ((String) null);
+ String _xifexpression = null;
+ boolean _isDataClass = this.typeHelpers.isDataClass(IterableExtensions.<Attribute>last(path).getType().getType());
+ if (_isDataClass) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ DataType _type = IterableExtensions.<Attribute>last(path).getType().getType();
+ List<Attribute> _allAttributes = this._roomHelpers.getAllAttributes(((DataClass) _type));
+ for(final Attribute e : _allAttributes) {
+ String _name = e.getName();
+ String _plus = ((varNamePath + "_") + _name);
+ String _genMinMaxConstantsRec = this.genMinMaxConstantsRec(ac, _plus, this._roomExtensions.<Attribute>union(path, e));
+ _builder.append(_genMinMaxConstantsRec);
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _xifexpression = _builder.toString();
+ } else {
+ String _xifexpression_1 = null;
+ DataType _type_1 = IterableExtensions.<Attribute>last(path).getType().getType();
+ if ((_type_1 instanceof ExternalType)) {
+ _xifexpression_1 = null;
+ } else {
+ String _xifexpression_2 = null;
+ DataType _type_2 = IterableExtensions.<Attribute>last(path).getType().getType();
+ if ((_type_2 instanceof EnumerationType)) {
+ _xifexpression_2 = null;
+ } else {
+ String _xblockexpression_1 = null;
+ {
+ DataType _type_3 = IterableExtensions.<Attribute>last(path).getType().getType();
+ PrimitiveType aType = ((PrimitiveType) _type_3);
+ StringConcatenation _builder_1 = new StringConcatenation();
+ {
+ boolean _notEquals = (!Objects.equal((temp = this.dataConfigExt.getAttrClassConfigMinValue(ac, path)), null));
+ if (_notEquals) {
+ _builder_1.append("public static ");
+ String _minMaxType = this.getMinMaxType(aType);
+ _builder_1.append(_minMaxType);
+ _builder_1.append(" MIN_");
+ _builder_1.append(varNamePath);
+ _builder_1.append(" = ");
+ String _valueLiteral = this.stdExt.toValueLiteral(aType, temp);
+ _builder_1.append(_valueLiteral);
+ _builder_1.append(";");
+ _builder_1.newLineIfNotEmpty();
+ }
+ }
+ {
+ boolean _notEquals_1 = (!Objects.equal((temp = this.dataConfigExt.getAttrClassConfigMaxValue(ac, path)), null));
+ if (_notEquals_1) {
+ _builder_1.append("public static ");
+ String _minMaxType_1 = this.getMinMaxType(aType);
+ _builder_1.append(_minMaxType_1);
+ _builder_1.append(" MAX_");
+ _builder_1.append(varNamePath);
+ _builder_1.append(" = ");
+ String _valueLiteral_1 = this.stdExt.toValueLiteral(aType, temp);
+ _builder_1.append(_valueLiteral_1);
+ _builder_1.append(";");
+ _builder_1.newLineIfNotEmpty();
+ }
+ }
+ _xblockexpression_1 = _builder_1.toString();
+ }
+ _xifexpression_2 = _xblockexpression_1;
+ }
+ _xifexpression_1 = _xifexpression_2;
+ }
+ _xifexpression = _xifexpression_1;
+ }
+ _xblockexpression = _xifexpression;
+ }
+ return _xblockexpression;
+ }
+
+ private String getMinMaxType(final PrimitiveType type) {
+ String _switchResult = null;
+ String _typeName = this.typeHelpers.typeName(type);
+ if (_typeName != null) {
+ switch (_typeName) {
+ case "byte":
+ _switchResult = "int";
+ break;
+ case "short":
+ _switchResult = "int";
+ break;
+ case "float":
+ _switchResult = "double";
+ break;
+ default:
+ _switchResult = this.typeHelpers.typeName(type);
+ break;
+ }
+ } else {
+ _switchResult = this.typeHelpers.typeName(type);
+ }
+ return _switchResult;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java
new file mode 100644
index 000000000..079407806
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java
@@ -0,0 +1,581 @@
+/**
+ * Copyright (c) 2010 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Thomas Schuetz and Henrik Rentz-Reichert (initial contribution)
+ * Peter Karlitschek
+ */
+package org.eclipse.etrice.generator.cpp.gen;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.Collections;
+import java.util.List;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.etrice.core.common.base.KeyValue;
+import org.eclipse.etrice.core.etphys.eTPhys.NodeRef;
+import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance;
+import org.eclipse.etrice.core.genmodel.fsm.IDiagnostician;
+import org.eclipse.etrice.core.room.ActorClass;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.EnumLiteral;
+import org.eclipse.etrice.core.room.EnumerationType;
+import org.eclipse.etrice.core.room.ExternalType;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.PrimitiveType;
+import org.eclipse.etrice.core.room.RefableType;
+import org.eclipse.etrice.core.room.RoomClass;
+import org.eclipse.etrice.core.room.VarDecl;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.generator.fsm.generic.ILanguageExtensionBase;
+import org.eclipse.etrice.generator.generic.ILanguageExtension;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.generic.TypeHelpers;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.util.Pair;
+import org.eclipse.xtext.util.Strings;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Conversions;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class CppExtensions implements ILanguageExtension {
+ @Inject
+ private IDiagnostician diagnostician;
+
+ @Inject
+ @Extension
+ private TypeHelpers _typeHelpers;
+
+ @Inject
+ @Extension
+ private RoomHelpers _roomHelpers;
+
+ @Inject
+ @Extension
+ private RoomExtensions _roomExtensions;
+
+ @Override
+ public String getTypedDataDefinition(final EObject msg) {
+ return this.generateArglistAndTypedData(((Message) msg).getData())[ILanguageExtensionBase.TypedDataKind.DECLARATION_AND_INITIALIZATION.ordinal()];
+ }
+
+ public String getCppHeaderFileName(final RoomClass rc) {
+ String _name = rc.getName();
+ return (_name + ".h");
+ }
+
+ public String getCppSourceFileName(final RoomClass rc) {
+ String _name = rc.getName();
+ return (_name + ".cpp");
+ }
+
+ public String getCppClassName(final NodeRef nr, final SubSystemInstance ssi) {
+ String _name = nr.getName();
+ String _plus = ("Node_" + _name);
+ String _plus_1 = (_plus + "_");
+ String _name_1 = ssi.getName();
+ return (_plus_1 + _name_1);
+ }
+
+ public String getCppHeaderFileName(final NodeRef nr, final SubSystemInstance ssi) {
+ String _cppClassName = this.getCppClassName(nr, ssi);
+ return (_cppClassName + ".h");
+ }
+
+ public String getCppSourceFileName(final NodeRef nr, final SubSystemInstance ssi) {
+ String _cppClassName = this.getCppClassName(nr, ssi);
+ return (_cppClassName + ".cpp");
+ }
+
+ @Override
+ public String accessLevelPrivate() {
+ return "";
+ }
+
+ @Override
+ public String accessLevelProtected() {
+ return "";
+ }
+
+ @Override
+ public String accessLevelPublic() {
+ return "";
+ }
+
+ @Override
+ public String memberAccess() {
+ return "this->";
+ }
+
+ @Override
+ public String selfPointer(final String classname, final boolean hasArgs) {
+ return "";
+ }
+
+ @Override
+ public String selfPointer(final boolean hasArgs) {
+ return "";
+ }
+
+ @Override
+ public String scopeSeparator() {
+ return "::";
+ }
+
+ @Override
+ public String operationScope(final String classname, final boolean isDeclaration) {
+ String _xifexpression = null;
+ if (isDeclaration) {
+ _xifexpression = "";
+ } else {
+ _xifexpression = (classname + "::");
+ }
+ return _xifexpression;
+ }
+
+ @Override
+ public String memberInDeclaration(final String namespace, final String member) {
+ return member;
+ }
+
+ @Override
+ public String memberInUse(final String namespace, final String member) {
+ return ((namespace + ".") + member);
+ }
+
+ @Override
+ public boolean usesInheritance() {
+ return true;
+ }
+
+ @Override
+ public boolean usesPointers() {
+ return true;
+ }
+
+ @Override
+ public String genEnumeration(final String name, final List<Pair<String, String>> entries) {
+ String _xblockexpression = null;
+ {
+ boolean _isEmpty = entries.isEmpty();
+ if (_isEmpty) {
+ return "";
+ }
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("typedef enum {");
+ _builder.newLine();
+ {
+ boolean _hasElements = false;
+ for(final Pair<String, String> entry : entries) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(",", "\t");
+ }
+ _builder.append("\t");
+ String _first = entry.getFirst();
+ _builder.append(_first, "\t");
+ _builder.append(" = ");
+ String _second = entry.getSecond();
+ _builder.append(_second, "\t");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("} ");
+ _builder.append(name);
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _xblockexpression = _builder.toString();
+ }
+ return _xblockexpression;
+ }
+
+ @Override
+ public String booleanConstant(final boolean b) {
+ return Boolean.valueOf(b).toString();
+ }
+
+ @Override
+ public String pointerLiteral() {
+ return "*";
+ }
+
+ @Override
+ public String nullPointer() {
+ return "0";
+ }
+
+ @Override
+ public String voidPointer() {
+ return "void*";
+ }
+
+ @Override
+ public String arrayType(final String type, final int size, final boolean isRef) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("StaticArray<");
+ _builder.append(type);
+ {
+ if (isRef) {
+ _builder.append("*");
+ }
+ }
+ _builder.append(", ");
+ _builder.append(size);
+ _builder.append(">");
+ return _builder.toString();
+ }
+
+ @Override
+ public String arrayDeclaration(final String type, final int size, final boolean isRef, final String name) {
+ String _arrayType = this.arrayType(type, size, isRef);
+ String _plus = (_arrayType + " ");
+ return (_plus + name);
+ }
+
+ public String getIncludeGuardString(final RoomClass roomClass, final String appendSegments) {
+ String[] _split = this._roomExtensions.getPackage(roomClass).split("\\.");
+ String _name = roomClass.getName();
+ Iterable<String> _plus = Iterables.<String>concat(((Iterable<? extends String>)Conversions.doWrapArray(_split)), Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList(_name)));
+ String[] _split_1 = appendSegments.split("\\.");
+ final Function1<String, Boolean> _function = (String it) -> {
+ boolean _isEmpty = it.isEmpty();
+ return Boolean.valueOf((!_isEmpty));
+ };
+ String _upperCase = IterableExtensions.join(IterableExtensions.<String>filter(Iterables.<String>concat(_plus, ((Iterable<? extends String>)Conversions.doWrapArray(_split_1))), _function), "_").toUpperCase();
+ String _plus_1 = ("_" + _upperCase);
+ return (_plus_1 + "_H_");
+ }
+
+ public CharSequence generateIncludeGuardBegin(final RoomClass roomClass, final String appendSegments) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("#ifndef ");
+ String _includeGuardString = this.getIncludeGuardString(roomClass, appendSegments);
+ _builder.append(_includeGuardString);
+ _builder.newLineIfNotEmpty();
+ _builder.append("#define ");
+ String _includeGuardString_1 = this.getIncludeGuardString(roomClass, appendSegments);
+ _builder.append(_includeGuardString_1);
+ _builder.newLineIfNotEmpty();
+ return _builder;
+ }
+
+ public CharSequence generateIncludeGuardEnd(final RoomClass roomClass, final String appendSegments) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("#endif /* ");
+ String _includeGuardString = this.getIncludeGuardString(roomClass, appendSegments);
+ _builder.append(_includeGuardString);
+ _builder.append(" */");
+ return _builder;
+ }
+
+ public String generateNamespaceBegin(final RoomClass roomClass) {
+ return "";
+ }
+
+ public String generateNamespaceEnd(final RoomClass roomClass) {
+ return "";
+ }
+
+ @Override
+ public String superCall(final String baseClassName, final String method, final String arguments) {
+ return (((((baseClassName + "::") + method) + "(") + arguments) + ");");
+ }
+
+ @Override
+ public String toValueLiteral(final PrimitiveType type, final String value) {
+ throw new UnsupportedOperationException("TODO Config for Cpp");
+ }
+
+ @Override
+ public String toEnumLiteral(final EnumerationType type, final String value) {
+ throw new UnsupportedOperationException("TODO Config for Cpp");
+ }
+
+ @Override
+ public String defaultValue(final DataType dt) {
+ String _switchResult = null;
+ final DataType it = dt;
+ boolean _matched = false;
+ if (it instanceof PrimitiveType) {
+ _matched=true;
+ _switchResult = ((PrimitiveType)it).getDefaultValueLiteral();
+ }
+ if (!_matched) {
+ if (it instanceof EnumerationType) {
+ _matched=true;
+ String _xblockexpression = null;
+ {
+ this.diagnostician.error("Enumeration not supported", dt, null);
+ _xblockexpression = "/* TODO */";
+ }
+ _switchResult = _xblockexpression;
+ }
+ }
+ if (!_matched) {
+ if (it instanceof ExternalType) {
+ _matched=true;
+ _switchResult = ((ExternalType)it).getDefaultValueLiteral();
+ }
+ }
+ return _switchResult;
+ }
+
+ public String getDefaultValue(final EnumerationType type) {
+ String _xifexpression = null;
+ boolean _isEmpty = type.getLiterals().isEmpty();
+ if (_isEmpty) {
+ _xifexpression = "";
+ } else {
+ _xifexpression = this.getCastedValue(type.getLiterals().get(0));
+ }
+ return _xifexpression;
+ }
+
+ @Override
+ public String initializationWithDefaultValues(final DataType dt, final int size) {
+ String _xblockexpression = null;
+ {
+ final String dv = this.defaultValue(dt);
+ String _xifexpression = null;
+ if ((size > 1)) {
+ String _xblockexpression_1 = null;
+ {
+ String res = "{";
+ int i = 0;
+ while ((i < size)) {
+ {
+ res = (res + dv);
+ i = (i + 1);
+ if ((i < size)) {
+ res = (res + ",");
+ }
+ }
+ }
+ _xblockexpression_1 = (res + "}");
+ }
+ _xifexpression = _xblockexpression_1;
+ } else {
+ _xifexpression = dv;
+ }
+ _xblockexpression = _xifexpression;
+ }
+ return _xblockexpression;
+ }
+
+ @Override
+ public String[] generateArglistAndTypedData(final EObject d) {
+ if ((Objects.equal(d, null) || (!(d instanceof VarDecl)))) {
+ return ((String[])Conversions.unwrapArray(CollectionLiterals.<String>newArrayList("", "", ""), String.class));
+ }
+ final VarDecl data = ((VarDecl) d);
+ String _switchResult = null;
+ DataType _type = data.getRefType().getType();
+ final DataType it = _type;
+ boolean _matched = false;
+ if (it instanceof PrimitiveType) {
+ boolean _isEmpty = Strings.isEmpty(((PrimitiveType)it).getCastName());
+ boolean _not = (!_isEmpty);
+ if (_not) {
+ _matched=true;
+ _switchResult = ((PrimitiveType)it).getCastName();
+ }
+ }
+ if (!_matched) {
+ if (it instanceof EnumerationType) {
+ _matched=true;
+ _switchResult = this.getCastType(((EnumerationType)it));
+ }
+ }
+ if (!_matched) {
+ _switchResult = this._typeHelpers.typeName(it);
+ }
+ final String castExpr = (_switchResult + "*");
+ String _typeName = this._typeHelpers.typeName(data.getRefType().getType());
+ String _switchResult_1 = null;
+ RefableType _refType = data.getRefType();
+ final RefableType it_1 = _refType;
+ boolean _matched_1 = false;
+ boolean _isRef = it_1.isRef();
+ if (_isRef) {
+ _matched_1=true;
+ _switchResult_1 = "*";
+ }
+ if (!_matched_1) {
+ boolean _isPrimitive = this._typeHelpers.isPrimitive(it_1.getType());
+ if (_isPrimitive) {
+ _matched_1=true;
+ _switchResult_1 = "";
+ }
+ }
+ if (!_matched_1) {
+ _switchResult_1 = "&";
+ }
+ final String typeExpr = (_typeName + _switchResult_1);
+ String _xifexpression = null;
+ boolean _isRef_1 = data.getRefType().isRef();
+ boolean _not = (!_isRef_1);
+ if (_not) {
+ _xifexpression = "*";
+ } else {
+ _xifexpression = "";
+ }
+ String deRef = _xifexpression;
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append(", ");
+ _builder.append(ILanguageExtension.GENERIC_DATA_NAME);
+ final String dataArg = _builder.toString();
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append(typeExpr);
+ _builder_1.append(" ");
+ _builder_1.append(ILanguageExtension.GENERIC_DATA_NAME);
+ _builder_1.append(" = ");
+ _builder_1.append(deRef);
+ _builder_1.append("(static_cast<");
+ _builder_1.append(castExpr);
+ _builder_1.append(">(generic_data__et));");
+ final String typedData = (_builder_1.toString() + this._roomExtensions.NEWLINE);
+ StringConcatenation _builder_2 = new StringConcatenation();
+ _builder_2.append(", ");
+ _builder_2.append(typeExpr);
+ _builder_2.append(" ");
+ _builder_2.append(ILanguageExtension.GENERIC_DATA_NAME);
+ final String typedArgList = _builder_2.toString();
+ return new String[] { dataArg, typedData, typedArgList };
+ }
+
+ @Override
+ public String getTargetType(final EnumerationType type) {
+ String _xifexpression = null;
+ PrimitiveType _primitiveType = type.getPrimitiveType();
+ boolean _notEquals = (!Objects.equal(_primitiveType, null));
+ if (_notEquals) {
+ _xifexpression = type.getPrimitiveType().getTargetName();
+ } else {
+ _xifexpression = type.getName();
+ }
+ return _xifexpression;
+ }
+
+ @Override
+ public String getCastedValue(final EnumLiteral literal) {
+ String _xblockexpression = null;
+ {
+ EObject _eContainer = literal.eContainer();
+ final EnumerationType type = ((EnumerationType) _eContainer);
+ final String cast = this.getTargetType(type);
+ String _xifexpression = null;
+ PrimitiveType _primitiveType = type.getPrimitiveType();
+ boolean _notEquals = (!Objects.equal(_primitiveType, null));
+ if (_notEquals) {
+ _xifexpression = Long.toString(literal.getLiteralValue());
+ } else {
+ String _string = Long.toString(literal.getLiteralValue());
+ String _plus = ((("((" + cast) + ")") + _string);
+ _xifexpression = (_plus + ")");
+ }
+ _xblockexpression = _xifexpression;
+ }
+ return _xblockexpression;
+ }
+
+ @Override
+ public String getCastType(final EnumerationType type) {
+ String _xifexpression = null;
+ PrimitiveType _primitiveType = type.getPrimitiveType();
+ boolean _notEquals = (!Objects.equal(_primitiveType, null));
+ if (_notEquals) {
+ _xifexpression = type.getPrimitiveType().getCastName();
+ } else {
+ _xifexpression = type.getName();
+ }
+ return _xifexpression;
+ }
+
+ @Override
+ public String makeOverridable() {
+ return "virtual ";
+ }
+
+ /**
+ * check if there is an ImplementationSubclass annotation and return its fully qualified name or the actor class name
+ */
+ public String getImplementationClassName(final ActorClass ac) {
+ String _xblockexpression = null;
+ {
+ final List<KeyValue> attributes = this._roomHelpers.getAttributes(ac, "ImplementationSubclass");
+ String _xifexpression = null;
+ boolean _isEmpty = attributes.isEmpty();
+ if (_isEmpty) {
+ _xifexpression = ac.getName();
+ } else {
+ final Function1<KeyValue, Boolean> _function = (KeyValue it) -> {
+ String _key = it.getKey();
+ return Boolean.valueOf(Objects.equal(_key, "fqnClassName"));
+ };
+ _xifexpression = this._roomHelpers.literalToString(IterableExtensions.<KeyValue>head(IterableExtensions.<KeyValue>filter(attributes, _function)).getValue());
+ }
+ _xblockexpression = _xifexpression;
+ }
+ return _xblockexpression;
+ }
+
+ /**
+ * check if there is an ImplementationSubclass annotation. If it also has an includePath use it.
+ * If there is not includePath, use the class name as base file name.
+ * If there is no annotation use the default path.
+ */
+ public String getActorIncludePath(final ActorClass ac) {
+ String _xblockexpression = null;
+ {
+ final List<KeyValue> attributes = this._roomHelpers.getAttributes(ac, "ImplementationSubclass");
+ String _xifexpression = null;
+ boolean _isEmpty = attributes.isEmpty();
+ if (_isEmpty) {
+ String _path = this._roomExtensions.getPath(ac);
+ String _name = ac.getName();
+ String _plus = (_path + _name);
+ _xifexpression = (_plus + ".h");
+ } else {
+ String _xblockexpression_1 = null;
+ {
+ final Function1<KeyValue, Boolean> _function = (KeyValue it) -> {
+ String _key = it.getKey();
+ return Boolean.valueOf(Objects.equal(_key, "includePath"));
+ };
+ final Iterable<KeyValue> path = IterableExtensions.<KeyValue>filter(attributes, _function);
+ String _xifexpression_1 = null;
+ boolean _isEmpty_1 = IterableExtensions.isEmpty(path);
+ if (_isEmpty_1) {
+ String _xblockexpression_2 = null;
+ {
+ final Function1<KeyValue, Boolean> _function_1 = (KeyValue it) -> {
+ String _key = it.getKey();
+ return Boolean.valueOf(Objects.equal(_key, "fqnClassName"));
+ };
+ final String baseName = IterableExtensions.<String>last(((Iterable<String>)Conversions.doWrapArray(this._roomHelpers.literalToString(IterableExtensions.<KeyValue>head(IterableExtensions.<KeyValue>filter(attributes, _function_1)).getValue()).split("::"))));
+ _xblockexpression_2 = (baseName + ".h");
+ }
+ _xifexpression_1 = _xblockexpression_2;
+ } else {
+ _xifexpression_1 = this._roomHelpers.literalToString(IterableExtensions.<KeyValue>head(path).getValue());
+ }
+ _xblockexpression_1 = _xifexpression_1;
+ }
+ _xifexpression = _xblockexpression_1;
+ }
+ _xblockexpression = _xifexpression;
+ }
+ return _xblockexpression;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java
new file mode 100644
index 000000000..eb5cf13b8
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java
@@ -0,0 +1,623 @@
+/**
+ * Copyright (c) 2011 Draeger Medical GmbH (http://www.draeger.com).
+ * 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:
+ * Peter Karlitschek (initial contribution)
+ */
+package org.eclipse.etrice.generator.cpp.gen;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.core.genmodel.fsm.ILogger;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.ComplexType;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.DataType;
+import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.util.RoomHelpers;
+import org.eclipse.etrice.generator.cpp.gen.CppExtensions;
+import org.eclipse.etrice.generator.cpp.gen.CppProcedureHelpers;
+import org.eclipse.etrice.generator.cpp.gen.Initialization;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ListExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class DataClassGen {
+ @Inject
+ @Extension
+ private JavaIoFileSystemAccess fileAccess;
+
+ @Inject
+ @Extension
+ private CppExtensions stdExt;
+
+ @Inject
+ @Extension
+ private RoomExtensions roomExt;
+
+ @Inject
+ @Extension
+ private CppProcedureHelpers helpers;
+
+ @Inject
+ private Initialization initHelper;
+
+ @Inject
+ @Extension
+ private RoomHelpers _roomHelpers;
+
+ @Inject
+ private ILogger logger;
+
+ public void doGenerate(final Root root) {
+ this.logger.logInfo("generating code");
+ EList<DataClass> _dataClasses = root.getDataClasses();
+ for (final DataClass dc : _dataClasses) {
+ {
+ String _generationTargetPath = this.roomExt.getGenerationTargetPath(dc);
+ String _path = this.roomExt.getPath(dc);
+ String path = (_generationTargetPath + _path);
+ String _cppHeaderFileName = this.stdExt.getCppHeaderFileName(dc);
+ String _plus = ("generating DataClass header \'" + _cppHeaderFileName);
+ String _plus_1 = (_plus + "\' in \'");
+ String _plus_2 = (_plus_1 + path);
+ String _plus_3 = (_plus_2 + "\'");
+ this.logger.logInfo(_plus_3);
+ this.fileAccess.setOutputPath(path);
+ this.fileAccess.generateFile(this.stdExt.getCppHeaderFileName(dc), this.generateHeaderFile(root, dc));
+ String _cppSourceFileName = this.stdExt.getCppSourceFileName(dc);
+ String _plus_4 = ("generating DataClass source \'" + _cppSourceFileName);
+ String _plus_5 = (_plus_4 + "\' in \'");
+ String _plus_6 = (_plus_5 + path);
+ String _plus_7 = (_plus_6 + "\'");
+ this.logger.logInfo(_plus_7);
+ this.fileAccess.setOutputPath(path);
+ this.fileAccess.generateFile(this.stdExt.getCppSourceFileName(dc), this.generateSourceFile(root, dc));
+ }
+ }
+ }
+
+ public CharSequence generateHeaderFile(final Root root, final DataClass dc) {
+ StringConcatenation _builder = new StringConcatenation();
+ CharSequence _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(dc, "");
+ _builder.append(_generateIncludeGuardBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"common/etDatatypesCpp.hpp\"");
+ _builder.newLine();
+ {
+ DataClass _base = dc.getBase();
+ boolean _notEquals = (!Objects.equal(_base, null));
+ if (_notEquals) {
+ _builder.append("#include \"");
+ String _path = this.roomExt.getPath(dc.getBase());
+ _builder.append(_path);
+ String _name = dc.getBase().getName();
+ _builder.append(_name);
+ _builder.append(".h\"");
+ }
+ }
+ _builder.newLineIfNotEmpty();
+ {
+ EList<DataClass> _referencedDataClasses = root.getReferencedDataClasses(dc);
+ for(final DataClass classes : _referencedDataClasses) {
+ _builder.append("#include \"");
+ String _path_1 = this.roomExt.getPath(classes);
+ _builder.append(_path_1);
+ String _name_1 = classes.getName();
+ _builder.append(_name_1);
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ {
+ EList<RoomModel> _referencedModels = root.getReferencedModels(dc);
+ for(final RoomModel model : _referencedModels) {
+ {
+ EList<DataClass> _dataClasses = model.getDataClasses();
+ for(final DataClass classes_1 : _dataClasses) {
+ _builder.append("#include \"");
+ String _path_2 = this.roomExt.getPath(classes_1);
+ _builder.append(_path_2);
+ String _name_2 = classes_1.getName();
+ _builder.append(_name_2);
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ CharSequence _userCode = this.helpers.userCode(dc.getUserCode1());
+ _builder.append(_userCode);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("using namespace etRuntime; // TODO JH remove");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceBegin = this.stdExt.generateNamespaceBegin(dc);
+ _builder.append(_generateNamespaceBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("class ");
+ String _name_3 = dc.getName();
+ _builder.append(_name_3);
+ {
+ DataClass _base_1 = dc.getBase();
+ boolean _notEquals_1 = (!Objects.equal(_base_1, null));
+ if (_notEquals_1) {
+ _builder.append(" : public ");
+ String _name_4 = dc.getBase().getName();
+ _builder.append(_name_4);
+ }
+ }
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("public:");
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _userCode_1 = this.helpers.userCode(dc.getUserCode2());
+ _builder.append(_userCode_1, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _attributes = this.helpers.attributes(dc.getAttributes());
+ _builder.append(_attributes, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _attributeSettersGettersImplementation = this.helpers.attributeSettersGettersImplementation(dc.getAttributes(), dc.getName());
+ _builder.append(_attributeSettersGettersImplementation, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _operationsDeclaration = this.helpers.operationsDeclaration(dc.getOperations(), dc.getName());
+ _builder.append(_operationsDeclaration, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// default constructor, copy constructor and assignment operator");
+ _builder.newLine();
+ _builder.append("\t");
+ String _name_5 = dc.getName();
+ _builder.append(_name_5, "\t");
+ _builder.append("();");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _name_6 = dc.getName();
+ _builder.append(_name_6, "\t");
+ _builder.append("(const ");
+ String _name_7 = dc.getName();
+ _builder.append(_name_7, "\t");
+ _builder.append("& rhs);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("// constructor using fields");
+ _builder.newLine();
+ _builder.append("\t");
+ {
+ boolean _isEmpty = this._roomHelpers.getAllAttributes(dc).isEmpty();
+ boolean _not = (!_isEmpty);
+ if (_not) {
+ String _name_8 = dc.getName();
+ _builder.append(_name_8, "\t");
+ _builder.append("(");
+ String _constArgList = this.helpers.constArgList(this._roomHelpers.getAllAttributes(dc));
+ _builder.append(_constArgList, "\t");
+ _builder.append(");");
+ }
+ }
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ String _name_9 = dc.getName();
+ _builder.append(_name_9, "\t");
+ _builder.append("& operator=(const ");
+ String _name_10 = dc.getName();
+ _builder.append(_name_10, "\t");
+ _builder.append("& rhs);");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceEnd = this.stdExt.generateNamespaceEnd(dc);
+ _builder.append(_generateNamespaceEnd);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ CharSequence _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(dc, "");
+ _builder.append(_generateIncludeGuardEnd);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ return _builder;
+ }
+
+ public CharSequence generateSourceFile(final Root root, final DataClass dc) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @author generated by eTrice");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* Source File of DataClass ");
+ String _name = dc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("#include \"");
+ String _cppHeaderFileName = this.stdExt.getCppHeaderFileName(dc);
+ _builder.append(_cppHeaderFileName);
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"etUnit/etUnit.h\"");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceBegin = this.stdExt.generateNamespaceBegin(dc);
+ _builder.append(_generateNamespaceBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ CharSequence _userCode = this.helpers.userCode(dc.getUserCode3());
+ _builder.append(_userCode);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("// default constructor");
+ _builder.newLine();
+ String _name_1 = dc.getName();
+ _builder.append(_name_1);
+ _builder.append("::");
+ String _name_2 = dc.getName();
+ _builder.append(_name_2);
+ _builder.append("()");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ CharSequence _generateDefaultInitalizerList = this.generateDefaultInitalizerList(dc);
+ _builder.append(_generateDefaultInitalizerList, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _genExtraInitializers = this.initHelper.genExtraInitializers(dc.getAttributes());
+ _builder.append(_genExtraInitializers, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _userStructorBody = this.helpers.userStructorBody(dc, true);
+ _builder.append(_userStructorBody, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("// copy constructor");
+ _builder.newLine();
+ String _name_3 = dc.getName();
+ _builder.append(_name_3);
+ _builder.append("::");
+ String _name_4 = dc.getName();
+ _builder.append(_name_4);
+ _builder.append("(const ");
+ String _name_5 = dc.getName();
+ _builder.append(_name_5);
+ _builder.append("& rhs)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ CharSequence _generateCopyInitalizerList = this.generateCopyInitalizerList(dc);
+ _builder.append(_generateCopyInitalizerList, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("// constructor using fields");
+ _builder.newLine();
+ _builder.append("// TODO");
+ _builder.newLine();
+ {
+ boolean _isEmpty = this._roomHelpers.getAllAttributes(dc).isEmpty();
+ boolean _not = (!_isEmpty);
+ if (_not) {
+ String _name_6 = dc.getName();
+ _builder.append(_name_6);
+ _builder.append("::");
+ String _name_7 = dc.getName();
+ _builder.append(_name_7);
+ _builder.append("(");
+ String _constArgList = this.helpers.constArgList(this._roomHelpers.getAllAttributes(dc));
+ _builder.append(_constArgList);
+ _builder.append(")");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ CharSequence _generateFieldInitializerList = this.generateFieldInitializerList(dc);
+ _builder.append(_generateFieldInitializerList, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ _builder.append("// assignment operator");
+ _builder.newLine();
+ String _name_8 = dc.getName();
+ _builder.append(_name_8);
+ _builder.append("& ");
+ String _name_9 = dc.getName();
+ _builder.append(_name_9);
+ _builder.append("::operator=(const ");
+ String _name_10 = dc.getName();
+ _builder.append(_name_10);
+ _builder.append("& rhs)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("if (this == &rhs) { return *this; };");
+ _builder.newLine();
+ _builder.append("\t");
+ {
+ DataClass _base = dc.getBase();
+ boolean _notEquals = (!Objects.equal(_base, null));
+ if (_notEquals) {
+ String _name_11 = dc.getBase().getName();
+ _builder.append(_name_11, "\t");
+ _builder.append("::operator=(rhs);");
+ }
+ }
+ _builder.newLineIfNotEmpty();
+ {
+ EList<Attribute> _attributes = dc.getAttributes();
+ for(final Attribute attr : _attributes) {
+ _builder.append("\t");
+ _builder.append("this->");
+ String _name_12 = attr.getName();
+ _builder.append(_name_12, "\t");
+ _builder.append(" = rhs.");
+ String _name_13 = attr.getName();
+ _builder.append(_name_13, "\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("return *this;");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ CharSequence _operationsImplementation = this.helpers.operationsImplementation(dc.getOperations(), dc.getName());
+ _builder.append(_operationsImplementation);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ String _generateNamespaceEnd = this.stdExt.generateNamespaceEnd(dc);
+ _builder.append(_generateNamespaceEnd);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ return _builder;
+ }
+
+ private CharSequence generateDefaultInitalizerList(final DataClass dataClass) {
+ CharSequence _xblockexpression = null;
+ {
+ @Extension
+ final Initialization initHelper = this.initHelper;
+ ArrayList<CharSequence> initList = CollectionLiterals.<CharSequence>newArrayList();
+ DataClass _base = dataClass.getBase();
+ boolean _notEquals = (!Objects.equal(_base, null));
+ if (_notEquals) {
+ String _name = dataClass.getBase().getName();
+ String _plus = (_name + "()");
+ initList.add(_plus);
+ }
+ final Function1<Attribute, String> _function = (Attribute it) -> {
+ StringConcatenation _builder = new StringConcatenation();
+ String _name_1 = it.getName();
+ _builder.append(_name_1);
+ _builder.append("(");
+ String _initializerListValue = initHelper.getInitializerListValue(it);
+ _builder.append(_initializerListValue);
+ _builder.append(")");
+ return _builder.toString();
+ };
+ List<String> _map = ListExtensions.<Attribute, String>map(dataClass.getAttributes(), _function);
+ Iterables.<CharSequence>addAll(initList, _map);
+ _xblockexpression = initHelper.generateCtorInitializerList(initList);
+ }
+ return _xblockexpression;
+ }
+
+ private CharSequence generateCopyInitalizerList(final DataClass dataClass) {
+ CharSequence _xblockexpression = null;
+ {
+ @Extension
+ final Initialization initHelper = this.initHelper;
+ ArrayList<CharSequence> initList = CollectionLiterals.<CharSequence>newArrayList();
+ DataClass _base = dataClass.getBase();
+ boolean _notEquals = (!Objects.equal(_base, null));
+ if (_notEquals) {
+ String _name = dataClass.getBase().getName();
+ String _plus = (_name + "(rhs)");
+ initList.add(_plus);
+ }
+ final Function1<Attribute, String> _function = (Attribute it) -> {
+ StringConcatenation _builder = new StringConcatenation();
+ String _name_1 = it.getName();
+ _builder.append(_name_1);
+ _builder.append("(rhs.");
+ String _name_2 = it.getName();
+ _builder.append(_name_2);
+ _builder.append(")");
+ return _builder.toString();
+ };
+ List<String> _map = ListExtensions.<Attribute, String>map(dataClass.getAttributes(), _function);
+ Iterables.<CharSequence>addAll(initList, _map);
+ _xblockexpression = initHelper.generateCtorInitializerList(initList);
+ }
+ return _xblockexpression;
+ }
+
+ private CharSequence generateFieldInitializerList(final DataClass dataClass) {
+ CharSequence _xblockexpression = null;
+ {
+ @Extension
+ final Initialization initHelper = this.initHelper;
+ ArrayList<CharSequence> initList = CollectionLiterals.<CharSequence>newArrayList();
+ DataClass _base = dataClass.getBase();
+ boolean _notEquals = (!Objects.equal(_base, null));
+ if (_notEquals) {
+ StringConcatenation _builder = new StringConcatenation();
+ String _name = dataClass.getBase().getName();
+ _builder.append(_name);
+ _builder.append("(");
+ final Function1<Attribute, String> _function = (Attribute it) -> {
+ return it.getName();
+ };
+ String _join = IterableExtensions.join(ListExtensions.<Attribute, String>map(this._roomHelpers.getAllAttributes(dataClass.getBase()), _function), ", ");
+ _builder.append(_join);
+ _builder.append(")");
+ initList.add(_builder.toString());
+ }
+ final Function1<Attribute, String> _function_1 = (Attribute it) -> {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ String _name_1 = it.getName();
+ _builder_1.append(_name_1);
+ _builder_1.append("(");
+ String _name_2 = it.getName();
+ _builder_1.append(_name_2);
+ _builder_1.append(")");
+ return _builder_1.toString();
+ };
+ List<String> _map = ListExtensions.<Attribute, String>map(dataClass.getAttributes(), _function_1);
+ Iterables.<CharSequence>addAll(initList, _map);
+ _xblockexpression = initHelper.generateCtorInitializerList(initList);
+ }
+ return _xblockexpression;
+ }
+
+ public String deepCopy(final DataClass _dc) {
+ String result = "";
+ DataClass dc = _dc;
+ while ((!Objects.equal(dc, null))) {
+ {
+ String _string = this.deepCopy(dc.getAttributes()).toString();
+ String _plus = (_string + result);
+ result = _plus;
+ dc = dc.getBase();
+ }
+ }
+ return result;
+ }
+
+ public CharSequence deepCopy(final List<Attribute> attributes) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ for(final Attribute a : attributes) {
+ {
+ DataType _type = a.getType().getType();
+ if ((_type instanceof ComplexType)) {
+ _builder.append("if (");
+ String _name = a.getName();
+ _builder.append(_name);
+ _builder.append("!=null) {");
+ _builder.newLineIfNotEmpty();
+ {
+ int _size = a.getSize();
+ boolean _equals = (_size == 0);
+ if (_equals) {
+ _builder.append("\t");
+ _builder.append("copy.");
+ String _name_1 = a.getName();
+ _builder.append(_name_1, "\t");
+ _builder.append(" = ");
+ String _name_2 = a.getName();
+ _builder.append(_name_2, "\t");
+ _builder.append(".deepCopy();");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t");
+ _builder.append("for (int i=0;i<");
+ String _name_3 = a.getName();
+ _builder.append(_name_3, "\t");
+ _builder.append(".length;i++){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("copy.");
+ String _name_4 = a.getName();
+ _builder.append(_name_4, "\t\t");
+ _builder.append("[i] = ");
+ String _name_5 = a.getName();
+ _builder.append(_name_5, "\t\t");
+ _builder.append("[i].deepCopy();");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ } else {
+ {
+ int _size_1 = a.getSize();
+ boolean _equals_1 = (_size_1 == 0);
+ if (_equals_1) {
+ _builder.append("copy.");
+ String _name_6 = a.getName();
+ _builder.append(_name_6);
+ _builder.append(" = ");
+ String _name_7 = a.getName();
+ _builder.append(_name_7);
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("for (int i=0;i<");
+ String _name_8 = a.getName();
+ _builder.append(_name_8);
+ _builder.append(".length;i++){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("copy.");
+ String _name_9 = a.getName();
+ _builder.append(_name_9, "\t");
+ _builder.append("[i] = ");
+ String _name_10 = a.getName();
+ _builder.append(_name_10, "\t");
+ _builder.append("[i];");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ }
+ }
+ return _builder;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/NodeGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/NodeGen.java
new file mode 100644
index 000000000..8f75401a9
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/NodeGen.java
@@ -0,0 +1,854 @@
+/**
+ * Copyright (c) 2011 Draeger Medical GmbH (http://www.draeger.com).
+ * 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:
+ * Peter Karlitschek (initial contribution)
+ */
+package org.eclipse.etrice.generator.cpp.gen;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.Consumer;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.common.converter.TimeConverter;
+import org.eclipse.etrice.core.etmap.util.ETMapUtil;
+import org.eclipse.etrice.core.etphys.eTPhys.ExecMode;
+import org.eclipse.etrice.core.etphys.eTPhys.NodeRef;
+import org.eclipse.etrice.core.etphys.eTPhys.PhysicalThread;
+import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance;
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.core.genmodel.etricegen.StructureInstance;
+import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance;
+import org.eclipse.etrice.core.genmodel.etricegen.Wire;
+import org.eclipse.etrice.core.genmodel.etricegen.WiredSubSystemClass;
+import org.eclipse.etrice.core.room.ActorRef;
+import org.eclipse.etrice.core.room.RoomModel;
+import org.eclipse.etrice.core.room.SubSystemClass;
+import org.eclipse.etrice.generator.cpp.Main;
+import org.eclipse.etrice.generator.cpp.gen.CppExtensions;
+import org.eclipse.etrice.generator.cpp.gen.Initialization;
+import org.eclipse.etrice.generator.fsm.base.FileSystemHelpers;
+import org.eclipse.etrice.generator.fsm.base.IGeneratorFileIo;
+import org.eclipse.etrice.generator.fsm.base.Indexed;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ListExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class NodeGen {
+ @Inject
+ @Extension
+ private CppExtensions _cppExtensions;
+
+ @Inject
+ @Extension
+ private RoomExtensions _roomExtensions;
+
+ @Inject
+ @Extension
+ private ProcedureHelpers _procedureHelpers;
+
+ @Inject
+ @Extension
+ private FileSystemHelpers _fileSystemHelpers;
+
+ @Inject
+ private IGeneratorFileIo fileIO;
+
+ @Inject
+ private Initialization initHelper;
+
+ public void doGenerate(final Root root) {
+ final Map<SubSystemClass, WiredSubSystemClass> sscc2wired = CollectionLiterals.<SubSystemClass, WiredSubSystemClass>newHashMap();
+ final Consumer<WiredSubSystemClass> _function = (WiredSubSystemClass it) -> {
+ sscc2wired.put(it.getSubSystemClass(), it);
+ };
+ Iterables.<WiredSubSystemClass>filter(root.getWiredInstances(), WiredSubSystemClass.class).forEach(_function);
+ Collection<NodeRef> _nodeRefs = ETMapUtil.getNodeRefs();
+ for (final NodeRef nr : _nodeRefs) {
+ List<String> _subSystemInstancePaths = ETMapUtil.getSubSystemInstancePaths(nr);
+ for (final String instpath : _subSystemInstancePaths) {
+ {
+ StructureInstance _instance = root.getInstance(instpath);
+ final SubSystemInstance ssi = ((SubSystemInstance) _instance);
+ if (((!Objects.equal(ssi, null)) && this._fileSystemHelpers.isValidGenerationLocation(ssi.getSubSystemClass()))) {
+ final WiredSubSystemClass wired = sscc2wired.get(ssi.getSubSystemClass());
+ String _generationTargetPath = this._roomExtensions.getGenerationTargetPath(ssi.getSubSystemClass());
+ String _path = this._roomExtensions.getPath(ssi.getSubSystemClass());
+ final String path = (_generationTargetPath + _path);
+ String _generationInfoPath = this._roomExtensions.getGenerationInfoPath(ssi.getSubSystemClass());
+ String _path_1 = this._roomExtensions.getPath(ssi.getSubSystemClass());
+ final String infopath = (_generationInfoPath + _path_1);
+ final Set<PhysicalThread> usedThreads = ETMapUtil.getUsedThreads(nr, ssi);
+ this.fileIO.generateFile("generating Node declaration", path, infopath, this._cppExtensions.getCppHeaderFileName(nr, ssi), this.generateHeaderFile(root, ssi, wired, usedThreads));
+ this.fileIO.generateFile("generating Node implementation", path, infopath, this._cppExtensions.getCppSourceFileName(nr, ssi), this.generateSourceFile(root, ssi, wired, usedThreads));
+ }
+ }
+ }
+ }
+ }
+
+ public CharSequence generateHeaderFile(final Root root, final SubSystemInstance comp, final WiredSubSystemClass wired, final Collection<PhysicalThread> usedThreads) {
+ CharSequence _xblockexpression = null;
+ {
+ final SubSystemClass cc = comp.getSubSystemClass();
+ final EList<RoomModel> models = root.getReferencedModels(cc);
+ final NodeRef nr = ETMapUtil.getNodeRef(comp);
+ final String clsname = this._cppExtensions.getCppClassName(nr, comp);
+ final Function1<PhysicalThread, Boolean> _function = (PhysicalThread t) -> {
+ return Boolean.valueOf(usedThreads.contains(t));
+ };
+ final Iterable<PhysicalThread> threads = IterableExtensions.<PhysicalThread>filter(nr.getType().getThreads(), _function);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @author generated by eTrice");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* Header File of SubSystemClass ");
+ _builder.append(clsname, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ CharSequence _generateIncludeGuardBegin = this._cppExtensions.generateIncludeGuardBegin(cc, "");
+ _builder.append(_generateIncludeGuardBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/IMessageService.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/SubSystemClassBase.h\"");
+ _builder.newLine();
+ {
+ EList<ActorInstance> _actorInstances = comp.getActorInstances();
+ for(final ActorInstance ai : _actorInstances) {
+ _builder.append("#include \"");
+ String _actorIncludePath = this._cppExtensions.getActorIncludePath(ai.getActorClass());
+ _builder.append(_actorIncludePath);
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ CharSequence _userCode = this._procedureHelpers.userCode(cc.getUserCode1());
+ _builder.append(_userCode);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ String _generateNamespaceBegin = this._cppExtensions.generateNamespaceBegin(cc);
+ _builder.append(_generateNamespaceBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("class ");
+ _builder.append(clsname);
+ _builder.append(" : public etRuntime::SubSystemClassBase{");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _userCode_1 = this._procedureHelpers.userCode(cc.getUserCode2());
+ _builder.append(_userCode_1, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public:");
+ _builder.newLine();
+ {
+ Iterable<Indexed<PhysicalThread>> _indexed = Indexed.<PhysicalThread>indexed(threads);
+ for(final Indexed<PhysicalThread> thread : _indexed) {
+ _builder.append("\t\t");
+ _builder.append("static const int ");
+ String _threadId = this.getThreadId(thread.getValue());
+ _builder.append(_threadId, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t\t");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// sub actors");
+ _builder.newLine();
+ {
+ EList<ActorRef> _actorRefs = cc.getActorRefs();
+ for(final ActorRef sub : _actorRefs) {
+ {
+ int _multiplicity = sub.getMultiplicity();
+ boolean _greaterThan = (_multiplicity > 1);
+ if (_greaterThan) {
+ _builder.append("\t\t");
+ _builder.append("Replicated");
+ String _implementationClassName = this._cppExtensions.getImplementationClassName(sub.getType());
+ _builder.append(_implementationClassName, "\t\t");
+ _builder.append(" ");
+ String _name = sub.getName();
+ _builder.append(_name, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t\t");
+ String _implementationClassName_1 = this._cppExtensions.getImplementationClassName(sub.getType());
+ _builder.append(_implementationClassName_1, "\t\t");
+ _builder.append(" ");
+ String _name_1 = sub.getName();
+ _builder.append(_name_1, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append(clsname, "\t\t");
+ _builder.append("(IRTObject* parent, const String& name);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("~");
+ _builder.append(clsname, "\t\t");
+ _builder.append("();");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data);");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("virtual void instantiateMessageServices();");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("virtual void mapThreads(void);");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("virtual void initialize(void);");
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation) {
+ _builder.append("\t\t");
+ _builder.append("virtual void setProbesActive(bool recursive, bool active);");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("virtual void init();");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation_1 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_1) {
+ _builder.append("\t\t");
+ _builder.append("etBool hasGeneratedMSCInstrumentation() const { return true; }");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("virtual void destroy();");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("private:");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// MessageServices");
+ _builder.newLine();
+ {
+ for(final PhysicalThread thread_1 : threads) {
+ _builder.append("\t\t");
+ _builder.append("IMessageService* msgSvc_");
+ String _name_2 = thread_1.getName();
+ _builder.append(_name_2, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append(clsname, "\t\t");
+ _builder.append("();");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append(clsname, "\t\t");
+ _builder.append("(");
+ _builder.append(clsname, "\t\t");
+ _builder.append(" const&);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append(clsname, "\t\t");
+ _builder.append("& operator=(");
+ _builder.append(clsname, "\t\t");
+ _builder.append(" const&);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("};");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceEnd = this._cppExtensions.generateNamespaceEnd(cc);
+ _builder.append(_generateNamespaceEnd);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ CharSequence _generateIncludeGuardEnd = this._cppExtensions.generateIncludeGuardEnd(cc, "");
+ _builder.append(_generateIncludeGuardEnd);
+ _builder.newLineIfNotEmpty();
+ _xblockexpression = _builder;
+ }
+ return _xblockexpression;
+ }
+
+ private String getThreadId(final PhysicalThread thread) {
+ String _upperCase = thread.getName().toUpperCase();
+ return ("THREAD_" + _upperCase);
+ }
+
+ private CharSequence generateConstructorInitalizerList(final SubSystemClass cc) {
+ CharSequence _xblockexpression = null;
+ {
+ @Extension
+ final Initialization initHelper = this.initHelper;
+ ArrayList<CharSequence> initList = CollectionLiterals.<CharSequence>newArrayList();
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("SubSystemClassBase(parent, name)");
+ initList.add(_builder.toString());
+ final Function1<ActorRef, String> _function = (ActorRef it) -> {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ String _name = it.getName();
+ _builder_1.append(_name);
+ _builder_1.append("(this, \"");
+ String _name_1 = it.getName();
+ _builder_1.append(_name_1);
+ _builder_1.append("\")");
+ return _builder_1.toString();
+ };
+ List<String> _map = ListExtensions.<ActorRef, String>map(cc.getActorRefs(), _function);
+ Iterables.<CharSequence>addAll(initList, _map);
+ _xblockexpression = initHelper.generateCtorInitializerList(initList);
+ }
+ return _xblockexpression;
+ }
+
+ public CharSequence generateSourceFile(final Root root, final SubSystemInstance comp, final WiredSubSystemClass wired, final Collection<PhysicalThread> usedThreads) {
+ CharSequence _xblockexpression = null;
+ {
+ final SubSystemClass cc = comp.getSubSystemClass();
+ final EList<RoomModel> models = root.getReferencedModels(cc);
+ final NodeRef nr = ETMapUtil.getNodeRef(comp);
+ final String clsname = this._cppExtensions.getCppClassName(nr, comp);
+ final Function1<PhysicalThread, Boolean> _function = (PhysicalThread t) -> {
+ return Boolean.valueOf(usedThreads.contains(t));
+ };
+ final Iterable<PhysicalThread> threads = IterableExtensions.<PhysicalThread>filter(nr.getType().getThreads(), _function);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @author generated by eTrice");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* Source File of SubsystemClass ");
+ _builder.append(clsname, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("#include \"");
+ String _cppHeaderFileName = this._cppExtensions.getCppHeaderFileName(nr, comp);
+ _builder.append(_cppHeaderFileName);
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"common/debugging/DebuggingService.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/debugging/MSCFunctionObject.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/IMessageService.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/MessageService.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/MessageServiceController.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/RTServices.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/StaticMessageMemory.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/InterfaceItemBase.h\"");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("using namespace etRuntime;");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceBegin = this._cppExtensions.generateNamespaceBegin(cc);
+ _builder.append(_generateNamespaceBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ {
+ Iterable<Indexed<PhysicalThread>> _indexed = Indexed.<PhysicalThread>indexed(threads);
+ for(final Indexed<PhysicalThread> thread : _indexed) {
+ _builder.append("const int ");
+ _builder.append(clsname);
+ _builder.append("::");
+ String _threadId = this.getThreadId(thread.getValue());
+ _builder.append(_threadId);
+ _builder.append(" = ");
+ int _index0 = thread.getIndex0();
+ _builder.append(_index0);
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append(clsname);
+ _builder.append("::");
+ _builder.append(clsname);
+ _builder.append("(IRTObject* parent, const String& name)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ CharSequence _generateConstructorInitalizerList = this.generateConstructorInitalizerList(cc);
+ _builder.append(_generateConstructorInitalizerList, "\t\t");
+ _builder.newLineIfNotEmpty();
+ {
+ for(final PhysicalThread thread_1 : threads) {
+ _builder.append("\t\t");
+ _builder.append(", msgSvc_");
+ String _name = thread_1.getName();
+ _builder.append(_name, "\t\t");
+ _builder.append("(NULL)");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("{");
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation) {
+ _builder.append("\t");
+ _builder.append("MSCFunctionObject mscFunctionObject(getInstancePathName(), \"Constructor\");");
+ _builder.newLine();
+ }
+ }
+ {
+ EList<ActorRef> _actorRefs = cc.getActorRefs();
+ for(final ActorRef sub : _actorRefs) {
+ {
+ int _multiplicity = sub.getMultiplicity();
+ boolean _greaterThan = (_multiplicity > 1);
+ if (_greaterThan) {
+ _builder.append("\t");
+ String _name_1 = sub.getName();
+ _builder.append(_name_1, "\t");
+ _builder.append(".createSubActors(");
+ int _multiplicity_1 = sub.getMultiplicity();
+ _builder.append(_multiplicity_1, "\t");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append(clsname);
+ _builder.append("::~");
+ _builder.append(clsname);
+ _builder.append("() {");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _isGenerateMSCInstrumentation_1 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_1) {
+ _builder.append("\t");
+ _builder.append("MSCFunctionObject mscFunctionObject(getInstancePathName(), \"Destructor\");");
+ _builder.newLine();
+ }
+ }
+ {
+ for(final PhysicalThread thread_2 : threads) {
+ _builder.append("\t");
+ _builder.append("delete msgSvc_");
+ String _name_2 = thread_2.getName();
+ _builder.append(_name_2, "\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("void ");
+ _builder.append(clsname);
+ _builder.append("::receiveEvent(InterfaceItemBase* ifitem, int evt, void* data){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("void ");
+ _builder.append(clsname);
+ _builder.append("::instantiateMessageServices(){");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation_2 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_2) {
+ _builder.append("\t");
+ _builder.append("MSCFunctionObject mscFunctionObject(getInstancePathName(), \"instantiateMessageServices()\");");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("IMessageMemory* msgMemory;");
+ _builder.newLine();
+ {
+ final Function1<PhysicalThread, Long> _function_1 = (PhysicalThread it) -> {
+ long _prio = it.getPrio();
+ return Long.valueOf((-_prio));
+ };
+ List<PhysicalThread> _sortBy = IterableExtensions.<PhysicalThread, Long>sortBy(threads, _function_1);
+ for(final PhysicalThread thread_3 : _sortBy) {
+ _builder.append("\t");
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("msgMemory = new StaticMessageMemory(this, \"MessageMemory_");
+ String _name_3 = thread_3.getName();
+ _builder.append(_name_3, "\t\t");
+ _builder.append("\", ");
+ int _msgblocksize = thread_3.getMsgblocksize();
+ _builder.append(_msgblocksize, "\t\t");
+ _builder.append(", ");
+ int _msgpoolsize = thread_3.getMsgpoolsize();
+ _builder.append(_msgpoolsize, "\t\t");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ {
+ if ((Objects.equal(thread_3.getExecmode(), ExecMode.POLLED) || Objects.equal(thread_3.getExecmode(), ExecMode.MIXED))) {
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("etTime interval;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("interval.sec = ");
+ long _split = TimeConverter.split(thread_3.getTime(), TimeConverter.SEC, true);
+ _builder.append(_split, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("interval.nSec = ");
+ long _split_1 = TimeConverter.split(thread_3.getTime(), TimeConverter.MILLI_SEC, false);
+ _builder.append(_split_1, "\t\t");
+ _builder.append("L;");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("msgSvc_");
+ String _name_4 = thread_3.getName();
+ _builder.append(_name_4, "\t\t");
+ _builder.append(" = new MessageService(this, IMessageService::");
+ String _name_5 = thread_3.getExecmode().getName();
+ _builder.append(_name_5, "\t\t");
+ _builder.append(", interval, 0, ");
+ String _threadId_1 = this.getThreadId(thread_3);
+ _builder.append(_threadId_1, "\t\t");
+ _builder.append(", \"MessageService_");
+ String _name_6 = thread_3.getName();
+ _builder.append(_name_6, "\t\t");
+ _builder.append("\", msgMemory, ");
+ long _prio = thread_3.getPrio();
+ _builder.append(_prio, "\t\t");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ } else {
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("msgSvc_");
+ String _name_7 = thread_3.getName();
+ _builder.append(_name_7, "\t\t");
+ _builder.append(" = new MessageService(this, IMessageService::");
+ String _name_8 = thread_3.getExecmode().getName();
+ _builder.append(_name_8, "\t\t");
+ _builder.append(", 0, ");
+ String _threadId_2 = this.getThreadId(thread_3);
+ _builder.append(_threadId_2, "\t\t");
+ _builder.append(", \"MessageService_");
+ String _name_9 = thread_3.getName();
+ _builder.append(_name_9, "\t\t");
+ _builder.append("\", msgMemory, ");
+ long _prio_1 = thread_3.getPrio();
+ _builder.append(_prio_1, "\t\t");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("RTServices::getInstance().getMsgSvcCtrl().addMsgSvc(*msgSvc_");
+ String _name_10 = thread_3.getName();
+ _builder.append(_name_10, "\t\t");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("void ");
+ _builder.append(clsname);
+ _builder.append("::mapThreads() {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("// thread mappings");
+ _builder.newLine();
+ {
+ EList<ActorInstance> _allContainedInstances = comp.getAllContainedInstances();
+ for(final ActorInstance ai : _allContainedInstances) {
+ _builder.append("\t");
+ final ETMapUtil.MappedThread mapped = ETMapUtil.getMappedThread(ai);
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _not = (!(mapped.isImplicit() || mapped.isAsParent()));
+ if (_not) {
+ _builder.append("\t");
+ _builder.append("addPathToThread(\"");
+ String _path = ai.getPath();
+ _builder.append(_path, "\t");
+ _builder.append("\", ");
+ String _threadId_3 = this.getThreadId(mapped.getThread());
+ _builder.append(_threadId_3, "\t");
+ _builder.append(");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("void ");
+ _builder.append(clsname);
+ _builder.append("::initialize() {");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _isGenerateMSCInstrumentation_3 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_3) {
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().getSyncLogger().addVisibleComment(\"starting initialization\");");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("MSCFunctionObject mscFunctionObject(getInstancePathName(), \"initialize()\");");
+ _builder.newLine();
+ {
+ EList<ActorRef> _actorRefs_1 = cc.getActorRefs();
+ for(final ActorRef sub_1 : _actorRefs_1) {
+ {
+ int _multiplicity_2 = sub_1.getMultiplicity();
+ boolean _greaterThan_1 = (_multiplicity_2 > 1);
+ if (_greaterThan_1) {
+ _builder.append("\t");
+ _builder.append("for (int i=0; i<");
+ int _multiplicity_3 = sub_1.getMultiplicity();
+ _builder.append(_multiplicity_3, "\t");
+ _builder.append("; ++i) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addMessageActorCreate(*this, ");
+ String _name_11 = sub_1.getName();
+ _builder.append(_name_11, "\t\t");
+ _builder.append(".getSubActor(i)->getName());");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ } else {
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addMessageActorCreate(*this, \"");
+ String _name_12 = sub_1.getName();
+ _builder.append(_name_12, "\t");
+ _builder.append("\");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// wiring");
+ _builder.newLine();
+ {
+ EList<Wire> _wires = wired.getWires();
+ for(final Wire wire : _wires) {
+ _builder.append("\t");
+ String _xifexpression = null;
+ boolean _isDataDriven = wire.isDataDriven();
+ if (_isDataDriven) {
+ _xifexpression = "DataPortBase";
+ } else {
+ _xifexpression = "InterfaceItemBase";
+ }
+ _builder.append(_xifexpression, "\t");
+ _builder.append("::connect(this, \"");
+ String _join = IterableExtensions.join(wire.getPath1(), "/");
+ _builder.append(_join, "\t");
+ _builder.append("\", \"");
+ String _join_1 = IterableExtensions.join(wire.getPath2(), "/");
+ _builder.append(_join_1, "\t");
+ _builder.append("\");");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// call initialize of sub actors");
+ _builder.newLine();
+ {
+ EList<ActorRef> _actorRefs_2 = cc.getActorRefs();
+ for(final ActorRef sub_2 : _actorRefs_2) {
+ _builder.append("\t");
+ String _name_13 = sub_2.getName();
+ _builder.append(_name_13, "\t");
+ _builder.append(".initialize();");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation_4 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_4) {
+ _builder.append("void ");
+ _builder.append(clsname);
+ _builder.append("::setProbesActive(bool recursive, bool active) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("for(int i = 0; i < m_RTSystemPort.getNInterfaceItems(); i++)");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("DebuggingService::getInstance().addPortInstance(*(m_RTSystemPort.getInterfaceItem(i)));");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("if(recursive) {");
+ _builder.newLine();
+ {
+ EList<ActorRef> _actorRefs_3 = cc.getActorRefs();
+ for(final ActorRef sub_3 : _actorRefs_3) {
+ _builder.append("\t\t");
+ String _name_14 = sub_3.getName();
+ _builder.append(_name_14, "\t\t");
+ _builder.append(".setProbesActive(recursive, active);");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ _builder.append("void ");
+ _builder.append(clsname);
+ _builder.append("::init(){");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("SubSystemClassBase::init();");
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation_5 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_5) {
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addVisibleComment(\"done sub system initialization\");");
+ _builder.newLine();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation_6 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_6) {
+ _builder.newLine();
+ _builder.append("void ");
+ _builder.append(clsname);
+ _builder.append("::destroy() {");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _isGenerateMSCInstrumentation_7 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_7) {
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().getSyncLogger().addVisibleComment(\"starting destruction\");");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("MSCFunctionObject mscFunctionObject(getInstancePathName(), \"destroy()\");");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addVisibleComment(\"begin sub system destruction\");");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("SubSystemClassBase::destroy();");
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation_8 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_8) {
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addVisibleComment(\"done sub system destruction\");");
+ _builder.newLine();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ String _generateNamespaceEnd = this._cppExtensions.generateNamespaceEnd(cc);
+ _builder.append(_generateNamespaceEnd);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _xblockexpression = _builder;
+ }
+ return _xblockexpression;
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.java
new file mode 100644
index 000000000..6fef1fe28
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.java
@@ -0,0 +1,1543 @@
+/**
+ * Copyright (c) 2011 Draeger Medical GmbH (http://www.draeger.com).
+ * 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:
+ * Peter Karlitschek (initial contribution)
+ */
+package org.eclipse.etrice.generator.cpp.gen;
+
+import com.google.common.base.Objects;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import java.util.List;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.core.genmodel.fsm.ILogger;
+import org.eclipse.etrice.core.room.Attribute;
+import org.eclipse.etrice.core.room.CommunicationType;
+import org.eclipse.etrice.core.room.DataClass;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.core.room.MessageHandler;
+import org.eclipse.etrice.core.room.Port;
+import org.eclipse.etrice.core.room.PortClass;
+import org.eclipse.etrice.core.room.ProtocolClass;
+import org.eclipse.etrice.core.room.SAP;
+import org.eclipse.etrice.core.room.SPP;
+import org.eclipse.etrice.core.room.VarDecl;
+import org.eclipse.etrice.generator.cpp.Main;
+import org.eclipse.etrice.generator.cpp.gen.CppExtensions;
+import org.eclipse.etrice.generator.cpp.gen.Initialization;
+import org.eclipse.etrice.generator.fsm.base.FileSystemHelpers;
+import org.eclipse.etrice.generator.fsm.base.IGeneratorFileIo;
+import org.eclipse.etrice.generator.generic.GenericProtocolClassGenerator;
+import org.eclipse.etrice.generator.generic.ProcedureHelpers;
+import org.eclipse.etrice.generator.generic.RoomExtensions;
+import org.eclipse.etrice.generator.generic.TypeHelpers;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.CollectionLiterals;
+import org.eclipse.xtext.xbase.lib.Extension;
+import org.eclipse.xtext.xbase.lib.Functions.Function1;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.ListExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class ProtocolClassGen extends GenericProtocolClassGenerator {
+ @Inject
+ private IGeneratorFileIo fileIO;
+
+ @Inject
+ @Extension
+ private CppExtensions stdExt;
+
+ @Inject
+ @Extension
+ private RoomExtensions roomExt;
+
+ @Inject
+ @Extension
+ private ProcedureHelpers helpers;
+
+ @Inject
+ @Extension
+ private TypeHelpers _typeHelpers;
+
+ @Inject
+ @Extension
+ private FileSystemHelpers _fileSystemHelpers;
+
+ @Inject
+ private Initialization initHelper;
+
+ @Inject
+ private ILogger logger;
+
+ public void doGenerate(final Root root) {
+ final Function1<ProtocolClass, Boolean> _function = (ProtocolClass cl) -> {
+ return Boolean.valueOf(this._fileSystemHelpers.isValidGenerationLocation(cl));
+ };
+ Iterable<ProtocolClass> _filter = IterableExtensions.<ProtocolClass>filter(root.getProtocolClasses(), _function);
+ for (final ProtocolClass pc : _filter) {
+ {
+ String _generationTargetPath = this.roomExt.getGenerationTargetPath(pc);
+ String _path = this.roomExt.getPath(pc);
+ final String path = (_generationTargetPath + _path);
+ String _generationInfoPath = this.roomExt.getGenerationInfoPath(pc);
+ String _path_1 = this.roomExt.getPath(pc);
+ final String infopath = (_generationInfoPath + _path_1);
+ CommunicationType _commType = pc.getCommType();
+ if (_commType != null) {
+ switch (_commType) {
+ case EVENT_DRIVEN:
+ this.fileIO.generateFile("generating ProtocolClass declaration", path, infopath, this.stdExt.getCppHeaderFileName(pc), this.generateHeaderFile(root, pc));
+ this.fileIO.generateFile("generating ProtocolClass implementation", path, infopath, this.stdExt.getCppSourceFileName(pc), this.generateSourceFile(root, pc));
+ break;
+ case DATA_DRIVEN:
+ this.fileIO.generateFile("generating ProtocolClass declaration", path, infopath, this.stdExt.getCppHeaderFileName(pc), this.generateDataDrivenHeaderFile(root, pc));
+ this.fileIO.generateFile("generating ProtocolClass implementation", path, infopath, this.stdExt.getCppSourceFileName(pc), this.generateDataDrivenSourceFile(root, pc));
+ break;
+ case SYNCHRONOUS:
+ this.logger.logError("synchronous protocols not supported yet", pc);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ protected CharSequence generateHeaderFile(final Root root, final ProtocolClass pc) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @author generated by eTrice");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* Header File of ProtocolClass ");
+ String _name = pc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ CharSequence _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(pc, "");
+ _builder.append(_generateIncludeGuardBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/InterfaceItemBase.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/PortBase.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/ReplicatedInterfaceItemBase.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/ReplicatedPortBase.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/etDatatypesCpp.hpp\"");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ EList<DataClass> _referencedDataClasses = root.getReferencedDataClasses(pc);
+ for(final DataClass dataClass : _referencedDataClasses) {
+ _builder.append("#include \"");
+ String _path = this.roomExt.getPath(dataClass);
+ _builder.append(_path);
+ String _name_1 = dataClass.getName();
+ _builder.append(_name_1);
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ CharSequence _userCode = this.helpers.userCode(pc.getUserCode1());
+ _builder.append(_userCode);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ String _generateNamespaceBegin = this.stdExt.generateNamespaceBegin(pc);
+ _builder.append(_generateNamespaceBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("class ");
+ String _name_2 = pc.getName();
+ _builder.append(_name_2);
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("public:");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("/* message IDs */");
+ _builder.newLine();
+ _builder.append("\t\t");
+ String _genMessageIDs = this.genMessageIDs(pc);
+ _builder.append(_genMessageIDs, "\t\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t\t");
+ CharSequence _userCode_1 = this.helpers.userCode(pc, 2);
+ _builder.append(_userCode_1, "\t\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("static bool isValidEvtID(int evtId) {");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("return ((MSG_MIN < evtId) && (evtId < MSG_MAX));");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("static bool isValidOutgoingEvtID(int evtId) {");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("return ((MSG_MIN < evtId) && (evtId < ");
+ {
+ int _size = pc.getIncomingMessages().size();
+ boolean _equals = (_size == 0);
+ if (_equals) {
+ _builder.append("MSG_MAX");
+ } else {
+ _builder.append("IN_");
+ String _name_3 = pc.getIncomingMessages().get(0).getName();
+ _builder.append(_name_3, "\t\t\t");
+ }
+ }
+ _builder.append("));");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("static bool isValidIncomingEvtID(int evtId) {");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("return ((");
+ {
+ int _size_1 = pc.getIncomingMessages().size();
+ boolean _equals_1 = (_size_1 == 0);
+ if (_equals_1) {
+ _builder.append("MSG_MAX");
+ } else {
+ _builder.append("IN_");
+ String _name_4 = pc.getIncomingMessages().get(0).getName();
+ _builder.append(_name_4, "\t\t\t");
+ }
+ }
+ _builder.append(" <= evtId) && (evtId < MSG_MAX));");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("static const etRuntime::String& getMessageString(int msg_id);");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("private:");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("static const etRuntime::String s_messageStrings[];");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _builder.newLine();
+ CharSequence _portClassDeclaration = this.portClassDeclaration(pc, false);
+ _builder.append(_portClassDeclaration);
+ _builder.newLineIfNotEmpty();
+ CharSequence _portClassDeclaration_1 = this.portClassDeclaration(pc, true);
+ _builder.append(_portClassDeclaration_1);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ String _generateNamespaceEnd = this.stdExt.generateNamespaceEnd(pc);
+ _builder.append(_generateNamespaceEnd);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ CharSequence _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(pc, "");
+ _builder.append(_generateIncludeGuardEnd);
+ _builder.newLineIfNotEmpty();
+ return _builder;
+ }
+
+ protected CharSequence portClassDeclaration(final ProtocolClass pc, final boolean conj) {
+ CharSequence _xblockexpression = null;
+ {
+ PortClass pclass = this.roomExt.getPortClass(pc, conj);
+ String portClassName = this.roomExt.getPortClassName(pc, conj);
+ String replPortClassName = this.roomExt.getPortClassName(pc, conj, true);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("//------------------------------------------------------------------------------------------------------------");
+ _builder.newLine();
+ _builder.append("// ");
+ {
+ if (conj) {
+ _builder.append("conjugated ");
+ }
+ }
+ _builder.append("port class");
+ _builder.newLineIfNotEmpty();
+ _builder.append("//------------------------------------------------------------------------------------------------------------");
+ _builder.newLine();
+ _builder.append("class ");
+ _builder.append(portClassName);
+ _builder.append(" : public etRuntime::PortBase {");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _notEquals = (!Objects.equal(pclass, null));
+ if (_notEquals) {
+ _builder.append("\t");
+ CharSequence _userCode = this.helpers.userCode(pclass.getUserCode());
+ _builder.append(_userCode, "\t");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append(" ");
+ _builder.append("public:");
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append(portClassName, "\t ");
+ _builder.append("(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t ");
+ _builder.append(portClassName, "\t ");
+ _builder.append("(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId, int idx);");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation) {
+ _builder.append("\t");
+ _builder.append("virtual void destroy();");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("virtual void receive(const etRuntime::Message* m);");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ boolean _notEquals_1 = (!Objects.equal(pclass, null));
+ if (_notEquals_1) {
+ _builder.append("\t");
+ CharSequence _attributes = this.helpers.attributes(pclass.getAttributes());
+ _builder.append(_attributes, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ CharSequence _operationsDeclaration = this.helpers.operationsDeclaration(pclass.getOperations(), portClassName);
+ _builder.append(_operationsDeclaration, "\t");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t ");
+ _builder.append("// sent messages");
+ _builder.newLine();
+ {
+ List<Message> _allMessages = this._roomHelpers.getAllMessages(pc, conj);
+ for(final Message m : _allMessages) {
+ _builder.append("\t");
+ CharSequence _messageSignature = this.messageSignature(m, false);
+ _builder.append(_messageSignature, "\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ CharSequence _messageSignature_1 = this.messageSignature(m, true);
+ _builder.append(_messageSignature_1, "\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("};");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("//------------------------------------------------------------------------------------------------------------");
+ _builder.newLine();
+ _builder.append("// ");
+ {
+ if (conj) {
+ _builder.append("conjugated ");
+ }
+ }
+ _builder.append("replicated port class");
+ _builder.newLineIfNotEmpty();
+ _builder.append("//------------------------------------------------------------------------------------------------------------");
+ _builder.newLine();
+ _builder.append("class ");
+ _builder.append(replPortClassName);
+ _builder.append(" : public etRuntime::ReplicatedPortBase {");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("public:");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append(replPortClassName, "\t\t");
+ _builder.append("(etRuntime::IInterfaceItemOwner* actor, const etRuntime::String& name, int localId);");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("int getReplication() const { return getNInterfaceItems(); }");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("int getIndexOf(const etRuntime::InterfaceItemBase& ifitem) const { return ifitem.getIdx(); }");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append(portClassName, "\t\t");
+ _builder.append("& get(int idx) const { return *dynamic_cast<");
+ _builder.append(portClassName, "\t\t");
+ _builder.append("*>(getInterfaceItem(idx)); }");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ {
+ if (conj) {
+ _builder.append("\t\t");
+ _builder.append("// incoming messages");
+ _builder.newLine();
+ {
+ List<Message> _allIncomingMessages = this._roomHelpers.getAllIncomingMessages(pc);
+ for(final Message m_1 : _allIncomingMessages) {
+ _builder.append("\t\t");
+ CharSequence _messageSignature_2 = this.messageSignature(m_1, false);
+ _builder.append(_messageSignature_2, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ } else {
+ _builder.append("\t\t");
+ _builder.append("// outgoing messages");
+ _builder.newLine();
+ {
+ List<Message> _allOutgoingMessages = this._roomHelpers.getAllOutgoingMessages(pc);
+ for(final Message m_2 : _allOutgoingMessages) {
+ _builder.append("\t\t");
+ CharSequence _messageSignature_3 = this.messageSignature(m_2, false);
+ _builder.append(_messageSignature_3, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ }
+ }
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("protected:");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("virtual etRuntime::InterfaceItemBase* createInterfaceItem(etRuntime::IInterfaceItemOwner* rcv, const etRuntime::String& name, int lid, int idx) {");
+ _builder.newLine();
+ _builder.append("\t\t\t");
+ _builder.append("return new ");
+ _builder.append(portClassName, "\t\t\t");
+ _builder.append("(rcv, name, lid, idx);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _xblockexpression = _builder;
+ }
+ return _xblockexpression;
+ }
+
+ protected CharSequence generateSourceFile(final Root root, final ProtocolClass pc) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @author generated by eTrice");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* Source File of ProtocolClass ");
+ String _name = pc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("#include \"");
+ String _cppHeaderFileName = this.stdExt.getCppHeaderFileName(pc);
+ _builder.append(_cppHeaderFileName);
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"common/debugging/DebuggingService.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/debugging/MSCFunctionObject.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/AbstractMessageReceiver.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/Address.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/messaging/Message.h\"");
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/IEventReceiver.h\"");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("using namespace etRuntime;");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceBegin = this.stdExt.generateNamespaceBegin(pc);
+ _builder.append(_generateNamespaceBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ CharSequence _userCode = this.helpers.userCode(pc, 3);
+ _builder.append(_userCode);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("/* message names as strings for debugging (generate MSC) */");
+ _builder.newLine();
+ _builder.append("const String ");
+ String _name_1 = pc.getName();
+ _builder.append(_name_1);
+ _builder.append("::s_messageStrings[] = {\"MIN\", ");
+ {
+ List<Message> _allOutgoingMessages = this._roomHelpers.getAllOutgoingMessages(pc);
+ for(final Message m : _allOutgoingMessages) {
+ _builder.append("\"");
+ String _name_2 = m.getName();
+ _builder.append(_name_2);
+ _builder.append("\",");
+ }
+ }
+ _builder.append(" ");
+ {
+ List<Message> _allIncomingMessages = this._roomHelpers.getAllIncomingMessages(pc);
+ for(final Message m_1 : _allIncomingMessages) {
+ _builder.append("\"");
+ String _name_3 = m_1.getName();
+ _builder.append(_name_3);
+ _builder.append("\",");
+ }
+ }
+ _builder.append("\"MAX\"};");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("const String& ");
+ String _name_4 = pc.getName();
+ _builder.append(_name_4);
+ _builder.append("::getMessageString(int msg_id) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("if ((MSG_MIN < msg_id ) && ( msg_id < MSG_MAX )) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("return s_messageStrings[msg_id];");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("} else {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("// id out of range");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("static const String errorMsg = \"Message ID out of range\";");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("return errorMsg;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ CharSequence _portClassImplementation = this.portClassImplementation(pc, false);
+ _builder.append(_portClassImplementation);
+ _builder.newLineIfNotEmpty();
+ CharSequence _portClassImplementation_1 = this.portClassImplementation(pc, true);
+ _builder.append(_portClassImplementation_1);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ String _generateNamespaceEnd = this.stdExt.generateNamespaceEnd(pc);
+ _builder.append(_generateNamespaceEnd);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ return _builder;
+ }
+
+ protected CharSequence portClassImplementation(final ProtocolClass pc, final boolean conj) {
+ CharSequence _xblockexpression = null;
+ {
+ PortClass pclass = this.roomExt.getPortClass(pc, conj);
+ String portClassName = this.roomExt.getPortClassName(pc, conj);
+ String replPortClassName = this.roomExt.getPortClassName(pc, conj, true);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("//------------------------------------------------------------------------------------------------------------");
+ _builder.newLine();
+ _builder.append("// ");
+ {
+ if (conj) {
+ _builder.append("conjugated ");
+ }
+ }
+ _builder.append("port class");
+ _builder.newLineIfNotEmpty();
+ _builder.append("//------------------------------------------------------------------------------------------------------------");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append(portClassName);
+ _builder.append("::");
+ _builder.append(portClassName);
+ _builder.append("(IInterfaceItemOwner* actor, const String& name, int localId)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ CharSequence _generateConstructorInitalizerList = this.generateConstructorInitalizerList(pclass, "0");
+ _builder.append(_generateConstructorInitalizerList, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append(portClassName);
+ _builder.append("::");
+ _builder.append(portClassName);
+ _builder.append("(IInterfaceItemOwner* actor, const String& name, int localId, int idx)");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ CharSequence _generateConstructorInitalizerList_1 = this.generateConstructorInitalizerList(pclass, "idx");
+ _builder.append(_generateConstructorInitalizerList_1, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("\t");
+ {
+ boolean _notEquals = (!Objects.equal(pclass, null));
+ if (_notEquals) {
+ CharSequence _genExtraInitializers = this.initHelper.genExtraInitializers(pclass.getAttributes());
+ _builder.append(_genExtraInitializers, "\t");
+ }
+ }
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation) {
+ _builder.newLine();
+ _builder.append("void ");
+ _builder.append(portClassName);
+ _builder.append("::destroy() {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().removePortInstance(*this);");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("PortBase::destroy();");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ _builder.append("void ");
+ _builder.append(portClassName);
+ _builder.append("::receive(const Message* msg) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("// TODO JH further");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("if (! ");
+ String _name = pc.getName();
+ _builder.append(_name, "\t");
+ _builder.append("::");
+ {
+ if (conj) {
+ _builder.append("isValidOutgoingEvtID");
+ } else {
+ _builder.append("isValidIncomingEvtID");
+ }
+ }
+ _builder.append("(msg->getEvtId())) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("//std::cout << \"unknown\" << std::endl;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ boolean _isGenerateMSCInstrumentation_1 = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation_1) {
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), ");
+ String _name_1 = pc.getName();
+ _builder.append(_name_1, "\t");
+ _builder.append("::getMessageString(msg->getEvtId()).c_str());");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ {
+ boolean _handlesReceive = this.roomExt.handlesReceive(pc, conj);
+ if (_handlesReceive) {
+ _builder.append("\t");
+ _builder.append("switch (msg->getEvtId()) {");
+ _builder.newLine();
+ {
+ List<MessageHandler> _receiveHandlers = this.roomExt.getReceiveHandlers(pc, conj);
+ for(final MessageHandler hdlr : _receiveHandlers) {
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("case ");
+ String _name_2 = pc.getName();
+ _builder.append(_name_2, "\t\t");
+ _builder.append("::");
+ String _codeName = this.roomExt.getCodeName(hdlr.getMsg());
+ _builder.append(_codeName, "\t\t");
+ _builder.append(":");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("{");
+ _builder.newLine();
+ {
+ EList<String> _lines = hdlr.getDetailCode().getLines();
+ for(final String command : _lines) {
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("\t\t");
+ _builder.append(command, "\t\t\t\t");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("break;");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("default:");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("getActor()->receiveEvent(this, msg->getEvtId(),\tmsg->getData());");
+ _builder.newLine();
+ {
+ boolean _handlesReceive_1 = this.roomExt.handlesReceive(pc, conj);
+ if (_handlesReceive_1) {
+ _builder.append("\t");
+ _builder.append("\t\t");
+ _builder.append("break;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ boolean _notEquals_1 = (!Objects.equal(pclass, null));
+ if (_notEquals_1) {
+ CharSequence _operationsImplementation = this.helpers.operationsImplementation(pclass.getOperations(), portClassName);
+ _builder.append(_operationsImplementation);
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("// sent messages");
+ _builder.newLine();
+ {
+ List<Message> _allMessages = this._roomHelpers.getAllMessages(pc, conj);
+ for(final Message m : _allMessages) {
+ CharSequence _sendMessage = this.sendMessage(m, pc.getName(), portClassName, conj);
+ _builder.append(_sendMessage);
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("//------------------------------------------------------------------------------------------------------------");
+ _builder.newLine();
+ _builder.append("// ");
+ {
+ if (conj) {
+ _builder.append("conjugated ");
+ }
+ }
+ _builder.append("replicated port class");
+ _builder.newLineIfNotEmpty();
+ _builder.append("//------------------------------------------------------------------------------------------------------------");
+ _builder.newLine();
+ _builder.append(replPortClassName);
+ _builder.append("::");
+ _builder.append(replPortClassName);
+ _builder.append("(IInterfaceItemOwner* actor, const String& name, int localId) :");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("ReplicatedPortBase(actor, name, localId)");
+ _builder.newLine();
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ {
+ if (conj) {
+ _builder.append("// incoming messages");
+ _builder.newLine();
+ {
+ List<Message> _allIncomingMessages = this._roomHelpers.getAllIncomingMessages(pc);
+ for(final Message m_1 : _allIncomingMessages) {
+ CharSequence _messageSignatureDefinition = this.messageSignatureDefinition(m_1, replPortClassName, false);
+ _builder.append(_messageSignatureDefinition);
+ _builder.append("{");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("for (Vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("(dynamic_cast<");
+ _builder.append(portClassName, "\t\t");
+ _builder.append("*>(*it))->");
+ CharSequence _messageCall = this.messageCall(m_1, false);
+ _builder.append(_messageCall, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ } else {
+ _builder.append("// outgoing messages");
+ _builder.newLine();
+ {
+ List<Message> _allOutgoingMessages = this._roomHelpers.getAllOutgoingMessages(pc);
+ for(final Message m_2 : _allOutgoingMessages) {
+ CharSequence _messageSignatureDefinition_1 = this.messageSignatureDefinition(m_2, replPortClassName, false);
+ _builder.append(_messageSignatureDefinition_1);
+ _builder.append("{");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("for (Vector<etRuntime::InterfaceItemBase*>::iterator it = getItems().begin(); it != getItems().end(); ++it) {");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("(dynamic_cast<");
+ _builder.append(portClassName, "\t\t");
+ _builder.append("*>(*it))->");
+ CharSequence _messageCall_1 = this.messageCall(m_2, false);
+ _builder.append(_messageCall_1, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ }
+ }
+ _xblockexpression = _builder;
+ }
+ return _xblockexpression;
+ }
+
+ private CharSequence generateConstructorInitalizerList(final PortClass pc, final String index) {
+ CharSequence _xblockexpression = null;
+ {
+ @Extension
+ final Initialization initHelper = this.initHelper;
+ final List<CharSequence> initList = CollectionLiterals.<CharSequence>newArrayList();
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("PortBase(actor, name, localId, ");
+ _builder.append(index);
+ _builder.append(")");
+ initList.add(_builder.toString());
+ boolean _notEquals = (!Objects.equal(pc, null));
+ if (_notEquals) {
+ final Function1<Attribute, String> _function = (Attribute it) -> {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ String _name = it.getName();
+ _builder_1.append(_name);
+ _builder_1.append("(");
+ String _initializerListValue = initHelper.getInitializerListValue(it);
+ _builder_1.append(_initializerListValue);
+ _builder_1.append(")");
+ return _builder_1.toString();
+ };
+ List<String> _map = ListExtensions.<Attribute, String>map(pc.getAttributes(), _function);
+ Iterables.<CharSequence>addAll(initList, _map);
+ }
+ _xblockexpression = initHelper.generateCtorInitializerList(initList);
+ }
+ return _xblockexpression;
+ }
+
+ protected CharSequence messageCall(final Message m, final boolean impl) {
+ StringConcatenation _builder = new StringConcatenation();
+ String _name = m.getName();
+ _builder.append(_name);
+ {
+ if (impl) {
+ _builder.append("_impl");
+ }
+ }
+ _builder.append("(");
+ {
+ VarDecl _data = m.getData();
+ boolean _notEquals = (!Objects.equal(_data, null));
+ if (_notEquals) {
+ _builder.append(" ");
+ String _name_1 = m.getData().getName();
+ _builder.append(_name_1);
+ }
+ }
+ _builder.append(")");
+ return _builder;
+ }
+
+ protected CharSequence messageSignature(final Message m, final boolean impl) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ if ((m.isPriv() || impl)) {
+ _builder.append("private:");
+ } else {
+ _builder.append("public:");
+ }
+ }
+ _builder.append(" void ");
+ String _name = m.getName();
+ _builder.append(_name);
+ {
+ if (impl) {
+ _builder.append("_impl");
+ }
+ }
+ _builder.append("(");
+ {
+ VarDecl _data = m.getData();
+ boolean _notEquals = (!Objects.equal(_data, null));
+ if (_notEquals) {
+ String _signatureString = this.helpers.signatureString(m.getData().getRefType());
+ _builder.append(_signatureString);
+ _builder.append(" ");
+ String _name_1 = m.getData().getName();
+ _builder.append(_name_1);
+ }
+ }
+ _builder.append(")");
+ return _builder;
+ }
+
+ protected CharSequence messageSignatureDefinition(final Message m, final String classPrefix, final boolean impl) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("void ");
+ _builder.append(classPrefix);
+ _builder.append("::");
+ String _name = m.getName();
+ _builder.append(_name);
+ {
+ if (impl) {
+ _builder.append("_impl");
+ }
+ }
+ _builder.append("(");
+ {
+ VarDecl _data = m.getData();
+ boolean _notEquals = (!Objects.equal(_data, null));
+ if (_notEquals) {
+ String _signatureString = this.helpers.signatureString(m.getData().getRefType());
+ _builder.append(_signatureString);
+ _builder.append(" ");
+ String _name_1 = m.getData().getName();
+ _builder.append(_name_1);
+ }
+ }
+ _builder.append(")");
+ return _builder;
+ }
+
+ protected CharSequence sendMessage(final Message m, final String portClassName, final String classPrefix, final boolean conj) {
+ CharSequence _xblockexpression = null;
+ {
+ String _xifexpression = null;
+ if (conj) {
+ _xifexpression = "IN";
+ } else {
+ _xifexpression = "OUT";
+ }
+ String dir = _xifexpression;
+ MessageHandler hdlr = this.roomExt.getSendHandler(m, conj);
+ String _xifexpression_1 = null;
+ VarDecl _data = m.getData();
+ boolean _notEquals = (!Objects.equal(_data, null));
+ if (_notEquals) {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append(", ");
+ String _name = m.getData().getName();
+ _builder.append(_name);
+ _xifexpression_1 = _builder.toString();
+ }
+ final String dataArg = _xifexpression_1;
+ String _xifexpression_2 = null;
+ if (((!Objects.equal(m.getData(), null)) && (!m.getData().getRefType().isRef()))) {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ _builder_1.append("DataMessage<");
+ String _typeName = this._typeHelpers.typeName(m.getData().getRefType().getType());
+ _builder_1.append(_typeName);
+ _builder_1.append(">");
+ _xifexpression_2 = _builder_1.toString();
+ } else {
+ StringConcatenation _builder_2 = new StringConcatenation();
+ _builder_2.append("Message");
+ _xifexpression_2 = _builder_2.toString();
+ }
+ final String messageType = _xifexpression_2;
+ StringConcatenation _builder_3 = new StringConcatenation();
+ _builder_3.append("new (buffer) ");
+ _builder_3.append(messageType);
+ _builder_3.append("(getPeerAddress(), ");
+ _builder_3.append(portClassName);
+ _builder_3.append("::");
+ _builder_3.append(dir);
+ _builder_3.append("_");
+ String _name_1 = m.getName();
+ _builder_3.append(_name_1);
+ String _elvis = null;
+ if (dataArg != null) {
+ _elvis = dataArg;
+ } else {
+ _elvis = "";
+ }
+ _builder_3.append(_elvis);
+ _builder_3.append(")");
+ final String message = _builder_3.toString();
+ StringConcatenation _builder_4 = new StringConcatenation();
+ CharSequence _messageSignatureDefinition = this.messageSignatureDefinition(m, classPrefix, false);
+ _builder_4.append(_messageSignatureDefinition);
+ _builder_4.append(" {");
+ _builder_4.newLineIfNotEmpty();
+ {
+ boolean _notEquals_1 = (!Objects.equal(hdlr, null));
+ if (_notEquals_1) {
+ _builder_4.append("\t");
+ {
+ EList<String> _lines = hdlr.getDetailCode().getLines();
+ for(final String command : _lines) {
+ _builder_4.append("\t");
+ _builder_4.append(command, "\t");
+ _builder_4.newLineIfNotEmpty();
+ }
+ }
+ } else {
+ _builder_4.append("\t");
+ CharSequence _messageCall = this.messageCall(m, true);
+ _builder_4.append(_messageCall, "\t");
+ _builder_4.append(";");
+ _builder_4.newLineIfNotEmpty();
+ }
+ }
+ _builder_4.append("}");
+ _builder_4.newLine();
+ _builder_4.newLine();
+ CharSequence _messageSignatureDefinition_1 = this.messageSignatureDefinition(m, classPrefix, true);
+ _builder_4.append(_messageSignatureDefinition_1);
+ _builder_4.append(" {");
+ _builder_4.newLineIfNotEmpty();
+ {
+ boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation) {
+ _builder_4.append("\t");
+ _builder_4.append("DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),");
+ _builder_4.newLine();
+ _builder_4.append("\t");
+ _builder_4.append("\t");
+ _builder_4.append(portClassName, "\t\t");
+ _builder_4.append("::getMessageString(");
+ _builder_4.append(portClassName, "\t\t");
+ _builder_4.append("::");
+ _builder_4.append(dir, "\t\t");
+ _builder_4.append("_");
+ String _name_2 = m.getName();
+ _builder_4.append(_name_2, "\t\t");
+ _builder_4.append(").c_str());");
+ _builder_4.newLineIfNotEmpty();
+ }
+ }
+ _builder_4.append("\t");
+ _builder_4.append("if (getPeerAddress().isValid()) {");
+ _builder_4.newLine();
+ _builder_4.append("\t\t");
+ _builder_4.append("Message* buffer = dynamic_cast<IMessageService*>(getPeerMsgReceiver())->getMessageBuffer(sizeof(");
+ _builder_4.append(messageType, "\t\t");
+ _builder_4.append("));");
+ _builder_4.newLineIfNotEmpty();
+ _builder_4.append("\t\t");
+ _builder_4.append("if (buffer) {");
+ _builder_4.newLine();
+ _builder_4.append("\t\t\t");
+ _builder_4.append("getPeerMsgReceiver()->receive(");
+ _builder_4.append(message, "\t\t\t");
+ _builder_4.append(");");
+ _builder_4.newLineIfNotEmpty();
+ _builder_4.append("\t\t");
+ _builder_4.append("}");
+ _builder_4.newLine();
+ _builder_4.append("\t");
+ _builder_4.append("}");
+ _builder_4.newLine();
+ _builder_4.append("}");
+ _builder_4.newLine();
+ _xblockexpression = _builder_4;
+ }
+ return _xblockexpression;
+ }
+
+ protected CharSequence generateDataDrivenHeaderFile(final Root root, final ProtocolClass pc) {
+ CharSequence _xblockexpression = null;
+ {
+ final Function1<Message, Boolean> _function = (Message m) -> {
+ VarDecl _data = m.getData();
+ return Boolean.valueOf((!Objects.equal(_data, null)));
+ };
+ final Iterable<Message> sentMsgs = IterableExtensions.<Message>filter(this._roomHelpers.getAllIncomingMessages(pc), _function);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @author generated by eTrice");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* Header File of ProtocolClass ");
+ String _name = pc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ CharSequence _generateIncludeGuardBegin = this.stdExt.generateIncludeGuardBegin(pc, "");
+ _builder.append(_generateIncludeGuardBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("#include \"common/etDatatypesCpp.hpp\"");
+ _builder.newLine();
+ _builder.append("#include \"common/modelbase/DataPort.h\"");
+ _builder.newLine();
+ {
+ EList<DataClass> _referencedDataClasses = root.getReferencedDataClasses(pc);
+ for(final DataClass dataClass : _referencedDataClasses) {
+ _builder.append("#include \"");
+ String _path = this.roomExt.getPath(dataClass);
+ _builder.append(_path);
+ String _name_1 = dataClass.getName();
+ _builder.append(_name_1);
+ _builder.append(".h\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ CharSequence _userCode = this.helpers.userCode(pc.getUserCode1());
+ _builder.append(_userCode);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ String _generateNamespaceBegin = this.stdExt.generateNamespaceBegin(pc);
+ _builder.append(_generateNamespaceBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("class ");
+ String _name_2 = pc.getName();
+ _builder.append(_name_2);
+ _builder.append(" {");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ CharSequence _userCode_1 = this.helpers.userCode(pc.getUserCode2());
+ _builder.append(_userCode_1, "\t");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("// send port holds data");
+ _builder.newLine();
+ _builder.append("class ");
+ String _portClassName = this.roomExt.getPortClassName(pc, true);
+ _builder.append(_portClassName);
+ _builder.append(" : public etRuntime::DataSendPort {");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("public:");
+ _builder.newLine();
+ _builder.append("\t");
+ String _portClassName_1 = this.roomExt.getPortClassName(pc, true);
+ _builder.append(_portClassName_1, "\t");
+ _builder.append("(etRuntime::IRTObject* parent, const etRuntime::String& name, int localId);");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// getters and setters");
+ _builder.newLine();
+ {
+ for(final Message msg : sentMsgs) {
+ _builder.append("\t");
+ _builder.append("void ");
+ String _name_3 = msg.getName();
+ _builder.append(_name_3, "\t");
+ _builder.append("(");
+ String _typeName = this._typeHelpers.typeName(msg.getData().getRefType().getType());
+ _builder.append(_typeName, "\t");
+ _builder.append(" ");
+ String _name_4 = msg.getName();
+ _builder.append(_name_4, "\t");
+ _builder.append(") {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("m_");
+ String _name_5 = msg.getName();
+ _builder.append(_name_5, "\t\t");
+ _builder.append(" = ");
+ String _name_6 = msg.getName();
+ _builder.append(_name_6, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ _builder.append("\t");
+ String _typeName_1 = this._typeHelpers.typeName(msg.getData().getRefType().getType());
+ _builder.append(_typeName_1, "\t");
+ _builder.append(" ");
+ String _name_7 = msg.getName();
+ _builder.append(_name_7, "\t");
+ _builder.append("() const {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("return m_");
+ String _name_8 = msg.getName();
+ _builder.append(_name_8, "\t\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ _builder.append("private:");
+ _builder.newLine();
+ {
+ for(final Message msg_1 : sentMsgs) {
+ _builder.append("\t");
+ String _typeName_2 = this._typeHelpers.typeName(msg_1.getData().getRefType().getType());
+ _builder.append(_typeName_2, "\t");
+ _builder.append(" m_");
+ String _name_9 = msg_1.getName();
+ _builder.append(_name_9, "\t");
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("};");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("// receive port accesses send port");
+ _builder.newLine();
+ _builder.append("class ");
+ String _portClassName_2 = this.roomExt.getPortClassName(pc, false);
+ _builder.append(_portClassName_2);
+ _builder.append(" : public etRuntime::DataReceivePort {");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("public:");
+ _builder.newLine();
+ _builder.append("\t");
+ String _portClassName_3 = this.roomExt.getPortClassName(pc, false);
+ _builder.append(_portClassName_3, "\t");
+ _builder.append("(etRuntime::IRTObject* parent, const etRuntime::String& name, int localId);");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("// getters");
+ _builder.newLine();
+ {
+ for(final Message msg_2 : sentMsgs) {
+ _builder.append("\t");
+ String _typeName_3 = this._typeHelpers.typeName(msg_2.getData().getRefType().getType());
+ _builder.append(_typeName_3, "\t");
+ _builder.append(" ");
+ String _name_10 = msg_2.getName();
+ _builder.append(_name_10, "\t");
+ _builder.append("() const;");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.newLine();
+ _builder.append("protected:");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("virtual void connect(etRuntime::DataSendPort* dataSendPort);");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("private:");
+ _builder.newLine();
+ _builder.append("\t");
+ String _portClassName_4 = this.roomExt.getPortClassName(pc, true);
+ _builder.append(_portClassName_4, "\t");
+ _builder.append("* m_peer;");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("};");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceEnd = this.stdExt.generateNamespaceEnd(pc);
+ _builder.append(_generateNamespaceEnd);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ CharSequence _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(pc, "");
+ _builder.append(_generateIncludeGuardEnd);
+ _builder.newLineIfNotEmpty();
+ _xblockexpression = _builder;
+ }
+ return _xblockexpression;
+ }
+
+ protected CharSequence generateDataDrivenSourceFile(final Root root, final ProtocolClass pc) {
+ CharSequence _xblockexpression = null;
+ {
+ final Function1<Message, Boolean> _function = (Message m) -> {
+ VarDecl _data = m.getData();
+ return Boolean.valueOf((!Objects.equal(_data, null)));
+ };
+ final Iterable<Message> sentMsgs = IterableExtensions.<Message>filter(this._roomHelpers.getAllIncomingMessages(pc), _function);
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("/**");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* @author generated by eTrice");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("* Source File of ProtocolClass ");
+ String _name = pc.getName();
+ _builder.append(_name, " ");
+ _builder.newLineIfNotEmpty();
+ _builder.append(" ");
+ _builder.append("*");
+ _builder.newLine();
+ _builder.append(" ");
+ _builder.append("*/");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("#include \"");
+ String _cppHeaderFileName = this.stdExt.getCppHeaderFileName(pc);
+ _builder.append(_cppHeaderFileName);
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("using namespace etRuntime;");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceBegin = this.stdExt.generateNamespaceBegin(pc);
+ _builder.append(_generateNamespaceBegin);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ CharSequence _userCode = this.helpers.userCode(pc.getUserCode3());
+ _builder.append(_userCode);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("// send port holds data");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("// constructor");
+ _builder.newLine();
+ String _portClassName = this.roomExt.getPortClassName(pc, true);
+ _builder.append(_portClassName);
+ _builder.append("::");
+ String _portClassName_1 = this.roomExt.getPortClassName(pc, true);
+ _builder.append(_portClassName_1);
+ _builder.append("(IRTObject* parent, const String& name, int localId) :");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("DataSendPort(parent, name, localId)");
+ _builder.newLine();
+ _builder.append("{");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("// receive port accesses send port");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("// constructor");
+ _builder.newLine();
+ String _portClassName_2 = this.roomExt.getPortClassName(pc, false);
+ _builder.append(_portClassName_2);
+ _builder.append("::");
+ String _portClassName_3 = this.roomExt.getPortClassName(pc, false);
+ _builder.append(_portClassName_3);
+ _builder.append("(IRTObject* parent, const String& name, int localId) :");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t\t");
+ _builder.append("DataReceivePort(parent, name, localId),");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("m_peer(0)");
+ _builder.newLine();
+ _builder.append("{");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ _builder.append("// getters");
+ _builder.newLine();
+ {
+ for(final Message msg : sentMsgs) {
+ String _typeName = this._typeHelpers.typeName(msg.getData().getRefType().getType());
+ _builder.append(_typeName);
+ _builder.append(" ");
+ String _portClassName_4 = this.roomExt.getPortClassName(pc, false);
+ _builder.append(_portClassName_4);
+ _builder.append("::");
+ String _name_1 = msg.getName();
+ _builder.append(_name_1);
+ _builder.append("() const {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("// TODO needs default value");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("//if (m_peer == 0)");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("/*\treturn ");
+ String _defaultValue = this.stdExt.defaultValue(msg.getData().getRefType().getType());
+ _builder.append(_defaultValue, "\t");
+ _builder.append("; */");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("return m_peer->");
+ String _name_2 = msg.getName();
+ _builder.append(_name_2, "\t");
+ _builder.append("();");
+ _builder.newLineIfNotEmpty();
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.newLine();
+ _builder.append("void ");
+ String _portClassName_5 = this.roomExt.getPortClassName(pc, false);
+ _builder.append(_portClassName_5);
+ _builder.append("::connect(DataSendPort* dataSendPort) {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ String _portClassName_6 = this.roomExt.getPortClassName(pc, true);
+ _builder.append(_portClassName_6, "\t");
+ _builder.append("* peer = dynamic_cast<");
+ String _portClassName_7 = this.roomExt.getPortClassName(pc, true);
+ _builder.append(_portClassName_7, "\t");
+ _builder.append("*>(dataSendPort);");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("if (peer != 0)");
+ _builder.newLine();
+ _builder.append("\t\t");
+ _builder.append("m_peer = peer;");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _builder.newLine();
+ String _generateNamespaceEnd = this.stdExt.generateNamespaceEnd(pc);
+ _builder.append(_generateNamespaceEnd);
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _xblockexpression = _builder;
+ }
+ return _xblockexpression;
+ }
+
+ @Override
+ public String getMessageID(final Message msg, final InterfaceItem item) {
+ if ((item instanceof Port)) {
+ Port p = ((Port) item);
+ String _xifexpression = null;
+ boolean _isConjugated = p.isConjugated();
+ if (_isConjugated) {
+ _xifexpression = "OUT_";
+ } else {
+ _xifexpression = "IN_";
+ }
+ String direction = _xifexpression;
+ String _name = p.getProtocol().getName();
+ String _name_1 = msg.getName();
+ String _plus = (direction + _name_1);
+ return this.enumInUse(_name, _plus);
+ } else {
+ if ((item instanceof SAP)) {
+ SAP sap = ((SAP) item);
+ String _name_2 = sap.getProtocol().getName();
+ String _name_3 = msg.getName();
+ String _plus_1 = ("OUT_" + _name_3);
+ return this.enumInUse(_name_2, _plus_1);
+ } else {
+ if ((item instanceof SPP)) {
+ SPP spp = ((SPP) item);
+ String _name_4 = spp.getProtocol().getName();
+ String _name_5 = msg.getName();
+ String _plus_2 = ("IN_" + _name_5);
+ return this.enumInUse(_name_4, _plus_2);
+ }
+ }
+ }
+ return "unknown interface item";
+ }
+
+ protected String enumInUse(final String namespace, final String member) {
+ return ((namespace + "::") + member);
+ }
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.java
new file mode 100644
index 000000000..c751e2cb7
--- /dev/null
+++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.java
@@ -0,0 +1,182 @@
+/**
+ * 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 v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * CONTRIBUTORS:
+ * Henrik Rentz-Reichert (initial contribution)
+ * Peter Karlitschek
+ */
+package org.eclipse.etrice.generator.cpp.gen;
+
+import com.google.inject.Singleton;
+import java.util.Comparator;
+import java.util.List;
+import org.eclipse.etrice.core.fsm.fSM.ModelComponent;
+import org.eclipse.etrice.core.fsm.fSM.State;
+import org.eclipse.etrice.core.fsm.fSM.StateGraphNode;
+import org.eclipse.etrice.core.genmodel.fsm.FsmGenExtensions;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.GraphContainer;
+import org.eclipse.etrice.core.genmodel.fsm.fsmgen.Node;
+import org.eclipse.etrice.generator.cpp.Main;
+import org.eclipse.etrice.generator.generic.GenericStateMachineGenerator;
+import org.eclipse.xtend2.lib.StringConcatenation;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xbase.lib.IteratorExtensions;
+
+@Singleton
+@SuppressWarnings("all")
+public class StateMachineGen extends GenericStateMachineGenerator {
+ private static class NodeComparator implements Comparator<Node> {
+ @Override
+ public int compare(final Node o1, final Node o2) {
+ int _inheritanceLevel = o1.getInheritanceLevel();
+ int _inheritanceLevel_1 = o2.getInheritanceLevel();
+ boolean _equals = (_inheritanceLevel == _inheritanceLevel_1);
+ if (_equals) {
+ if ((FsmGenExtensions.isLeaf(o1) && FsmGenExtensions.isLeaf(o2))) {
+ return 0;
+ }
+ boolean _isLeaf = FsmGenExtensions.isLeaf(o1);
+ if (_isLeaf) {
+ return 1;
+ }
+ boolean _isLeaf_1 = FsmGenExtensions.isLeaf(o2);
+ if (_isLeaf_1) {
+ return (-1);
+ }
+ return 0;
+ } else {
+ return Integer.compare(o1.getInheritanceLevel(), o1.getInheritanceLevel());
+ }
+ }
+ }
+
+ private final StateMachineGen.NodeComparator nodeComparator = new StateMachineGen.NodeComparator();
+
+ @Override
+ public CharSequence genExtra(final GraphContainer gc, final boolean generateImplementation) {
+ CharSequence _xblockexpression = null;
+ {
+ ModelComponent ac = gc.getComponent();
+ final String clsName = ac.getComponentName();
+ final List<Node> orderedStateNodes = IterableExtensions.<Node>sortWith(IteratorExtensions.<Node>toList(FsmGenExtensions.getAllStateNodes(gc.getGraph())), this.nodeComparator);
+ CharSequence _xifexpression = null;
+ if (generateImplementation) {
+ StringConcatenation _builder = new StringConcatenation();
+ {
+ if ((Main.getSettings().isGenerateMSCInstrumentation() || Main.getSettings().isGenerateWithVerboseOutput())) {
+ _builder.append("// state names");
+ _builder.newLine();
+ _builder.append("const String ");
+ _builder.append(clsName);
+ _builder.append("::s_stateStrings[] = {");
+ _builder.newLineIfNotEmpty();
+ _builder.append("\t");
+ _builder.append("\"<no state>\",");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\"<top>\",");
+ _builder.newLine();
+ {
+ boolean _hasElements = false;
+ for(final Node state : orderedStateNodes) {
+ if (!_hasElements) {
+ _hasElements = true;
+ } else {
+ _builder.appendImmediate(",", "\t");
+ }
+ _builder.append("\t");
+ _builder.append("\"");
+ StateGraphNode _stateGraphNode = state.getStateGraphNode();
+ String _genStatePathName = this._codegenHelpers.getGenStatePathName(((State) _stateGraphNode));
+ _builder.append(_genStatePathName, "\t");
+ _builder.append("\"");
+ _builder.newLineIfNotEmpty();
+ }
+ }
+ _builder.append("};");
+ _builder.newLine();
+ }
+ }
+ _builder.append("const int ");
+ _builder.append(clsName);
+ _builder.append("::s_numberOfStates = ");
+ int _size = orderedStateNodes.size();
+ int _plus = (2 + _size);
+ _builder.append(_plus);
+ _builder.append(";");
+ _builder.newLineIfNotEmpty();
+ _builder.newLine();
+ _builder.append("void ");
+ _builder.append(clsName);
+ _builder.append("::setState(int new_state) {");
+ _builder.newLineIfNotEmpty();
+ {
+ boolean _isGenerateMSCInstrumentation = Main.getSettings().isGenerateMSCInstrumentation();
+ if (_isGenerateMSCInstrumentation) {
+ _builder.append("\t");
+ _builder.append("DebuggingService::getInstance().addActorState(*this, s_stateStrings[new_state].c_str());");
+ _builder.newLine();
+ }
+ }
+ {
+ boolean _isGenerateWithVerboseOutput = Main.getSettings().isGenerateWithVerboseOutput();
+ if (_isGenerateWithVerboseOutput) {
+ _builder.append("\t");
+ _builder.append("if (s_stateStrings[new_state] != \"Idle\") {");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("\t");
+ _builder.append("std::cout << getInstancePath().c_str() << \" -> \" << s_stateStrings[new_state].c_str() << std::endl;");
+ _builder.newLine();
+ _builder.append("\t");
+ _builder.append("}");
+ _builder.newLine();
+ }
+ }
+ _builder.append("\t");
+ _builder.append("m_state = new_state;");
+ _builder.newLine();
+ _builder.append("}");
+ _builder.newLine();
+ _xifexpression = _builder;
+ } else {
+ StringConcatenation _builder_1 = new StringConcatenation();
+ {
+ if ((Main.getSettings().isGenerateMSCInstrumentation() || Main.getSettings().isGenerateWithVerboseOutput())) {
+ _builder_1.append("static const String s_stateStrings[];");
+ _builder_1.newLine();
+ }
+ }
+ _builder_1.append("static const int s_numberOfStates;");
+ _builder_1.newLine();
+ _builder_1.newLine();
+ _builder_1.append("int history[");
+ int _size_1 = orderedStateNodes.size();
+ int _plus_1 = (2 + _size_1);
+ _builder_1.append(_plus_1);
+ _builder_1.append("];");
+ _builder_1.newLineIfNotEmpty();
+ _builder_1.newLine();
+ _builder_1.append("void setState(int new_state);");
+ _builder_1.newLine();
+ _xifexpression = _builder_1;
+ }
+ _xblockexpression = _xifexpression;
+ }
+ return _xblockexpression;
+ }
+
+ @Override
+ public String stateType() {
+ return "etInt16";
+ }
+
+ @Override
+ public String boolType() {
+ return "etBool";
+ }
+}

Back to the top