Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen')
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend550
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend32
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend450
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.java120
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/DataClassGen.xtend562
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Initialization.xtend206
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend104
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend886
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend178
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.xtend602
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.xtend184
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Validator.java98
12 files changed, 1986 insertions, 1986 deletions
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 570580bfb..6472d9f60 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
@@ -1,275 +1,275 @@
-/*******************************************************************************
- * 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.inject.Inject
-import com.google.inject.Singleton
-import java.util.ArrayList
-import org.eclipse.etrice.core.genmodel.base.ILogger
-import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
-import org.eclipse.etrice.core.genmodel.etricegen.Root
-import org.eclipse.etrice.core.room.ActorClass
-import org.eclipse.etrice.generator.base.AbstractGenerator
-import org.eclipse.etrice.generator.generic.GenericActorClassGenerator
-import org.eclipse.etrice.generator.generic.ProcedureHelpers
-import org.eclipse.etrice.generator.generic.RoomExtensions
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-import org.eclipse.etrice.generator.cpp.GeneratorOptions
-import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
-import org.eclipse.etrice.core.room.ActorCommunicationType
-
-/**
- * @author Peter Karlitschek
- *
- */
-@Singleton
-class ActorClassGen extends GenericActorClassGenerator {
-
- @Inject JavaIoFileSystemAccess fileAccess
- @Inject extension CppExtensions
- @Inject extension RoomExtensions
- @Inject extension Initialization
- @Inject extension ProcedureHelpers
- @Inject extension StateMachineGen
- @Inject ILogger logger
-
- def doGenerate(Root root) {
- for (xpac: root.xpActorClasses) {
- var path = xpac.actorClass.generationTargetPath+xpac.actorClass.getPath
-
- logger.logInfo("generating ActorClass header '"+xpac.actorClass.getCppHeaderFileName+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(xpac.actorClass.getCppHeaderFileName, root.generateHeaderFile(xpac, xpac.actorClass))
-
- logger.logInfo("generating ActorClass source '"+xpac.actorClass.getCppSourceFileName+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(xpac.actorClass.getCppSourceFileName, root.generateSourceFile(xpac, xpac.actorClass))
- }
- }
-
- def private generateHeaderFile(Root root, ExpandedActorClass xpac, ActorClass ac) {
-// val ctor = ac.operations.filter(op|op.constructor).head
-// val dtor = ac.operations.filter(op|op.destructor).head
-
- '''
- /**
- * @author generated by eTrice
- *
- * Header File of ActorClass «ac.name»
- *
- */
-
- «generateIncludeGuardBegin(ac.name)»
-
- #include "platforms/generic/etDatatypes.h"
- #include "common/messaging/IRTObject.h"
- #include "common/modelbase/PortBase.h"
- #include "common/modelbase/InterfaceItemBase.h"
- #include "common/modelbase/ActorClassBase.h"
- #include "common/modelbase/SubSystemClassBase.h"
- #include "common/messaging/Address.h"
- #include "common/messaging/IMessageReceiver.h"
- #include "common/debugging/DebuggingService.h"
- «IF GeneratorOptions::useEtUnit»
- extern "C" {
- #include "etUnit.h"
- }
- «ENDIF»
- #include <string>
- #include <vector>
-
- «FOR model : root.getReferencedModels(ac)»
-««« #include "«model.name».h"
- «ENDFOR»
-
- «FOR pc : root.getReferencedProtocolClasses(ac)»
- #include "«pc.path»«pc.name».h"
- «ENDFOR»
- «FOR dc : root.getReferencedDataClasses(ac)»
- #include "«dc.path»«dc.name».h"
- «ENDFOR»
-
-
- «ac.userCode(1)»
-
-
- class «ac.name» : public «IF ac.base!=null»«ac.base.name»«ELSE»etRuntime::ActorClassBase«ENDIF» {
-
-
- protected:
- //--------------------- ports
- «ac.endPorts.map(port | '''«port.portClassName» «port.name»;''').join("\n")»
- //--------------------- saps
- «ac.strSAPs.map(sap | '''«sap.portClassName» «sap.name»;''').join("\n")»
- //--------------------- services
- «ac.serviceImplementations.map(svc | '''«svc.portClassName» «svc.spp.name»;''').join("\n")»
-
- //--------------------- interface item IDs
- «xpac.genInterfaceItemConstants»
-
- «ac.attributes.attributes»
-
- «ac.operationsImplementation»
-
- public:
- //--------------------- construction
- «ac.name»(etRuntime::IRTObject* parent, std::string name, const std::vector<std::vector<etRuntime::Address> >& port_addr,
- const std::vector<std::vector<etRuntime::Address> >& peer_addr);
-
-««« TODO: check whether attribute setters/getters are necessary at all, if yes own cpp implementation is needed for *,[],& variables
-««« «attributeSettersGettersImplementation(ac.attributes, ac.name)»
- //--------------------- port getters
- «FOR ep : ac.getEndPorts()»
- «ep.portClassName.getterImplementation(ep.name, ac.name)»
- «ENDFOR»
- «FOR sap : ac.strSAPs»
- «sap.portClassName.getterImplementation(sap.name, ac.name)»
- «ENDFOR»
- «FOR svc : ac.serviceImplementations»
- «svc.portClassName.getterImplementation(svc.spp.name, ac.name)»
- «ENDFOR»
-
- //--------------------- lifecycle functions
- virtual void init();
- virtual void start();
- «IF !ac.overridesStop()»
- virtual void stop();
- «ENDIF»
- virtual void destroy();
- «IF ac.hasNonEmptyStateMachine»
- «xpac.genStateMachineMethodDeclarations()»
- «ELSEIF !xpac.hasStateMachine()»
- public:
- //--------------------- no state machine
- virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data);
- virtual void executeInitTransition();
- «ENDIF»
-
- «ac.userCode(2)»
-
- };
-
-
- «generateIncludeGuardEnd(ac.name)»
- '''
- }
- def private generateConstructorInitalizerList(ActorClass ac) {
- var initializerList = new ArrayList<CharSequence>();
- if (ac.base==null) {
- initializerList.add('''ActorClassBase( parent, name, port_addr[0][0], peer_addr[0][0])''')
- }
- else {
- initializerList.add('''«ac.base.name»(*this, parent, name, port_addr, peer_addr)''')
- }
- // own ports
- for ( ep : ac.getEndPorts() ) {
- initializerList.add('''«ep.name»(*this, this, "«ep.name»", IFITEM_«ep.name», «IF ep.multiplicity==1»0, «ENDIF»port_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF», peer_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF»)''');
- }
- // own saps
- for ( sap : ac.strSAPs ) {
- initializerList.add('''«sap.name»(*this, this, "«sap.name»", IFITEM_«sap.name», 0, port_addr[IFITEM_«sap.name»][0], peer_addr[IFITEM_«sap.name»][0])''');
- }
- // own service implementations
- for (svc : ac.serviceImplementations) {
- initializerList.add('''«svc.spp.name»(*this, this, "«svc.spp.name»", IFITEM_«svc.spp.name», port_addr[IFITEM_«svc.spp.name»], peer_addr[IFITEM_«svc.spp.name»])''');
- }
- for (attrib: ac.attributes) {
- initializerList.add(attrib.attributeInitialization(false))
- }
- return
- '''
- «initializerList.join(',\n')»
- '''
- }
-
-
- def private generateSourceFile(Root root, ExpandedActorClass xpac, ActorClass ac) {
- val ctor = ac.operations.filter(op|op.constructor).head
- val dtor = ac.operations.filter(op|op.destructor).head
- val async = xpac.actorClass.commType==ActorCommunicationType::ASYNCHRONOUS
-
- '''
- /**
- * @author generated by eTrice
- *
- * Source File of ActorClass «ac.name»
- *
- */
-
- #include "«ac.getCppHeaderFileName»"
- #include "common/debugging/DebuggingService.h"
- #include <iostream>
-
- using namespace etRuntime;
-
-
- «ac.name»::«ac.name»(etRuntime::IRTObject* parent, std::string name, const std::vector<std::vector<etRuntime::Address> >& port_addr,
- const std::vector<std::vector<etRuntime::Address> >& peer_addr)
- : «ac.generateConstructorInitalizerList»
- {
- «IF ac.hasNonEmptyStateMachine»
- history = new int[s_numberOfStates];
- for (int i = 0; i < s_numberOfStates; i++) {
- history[i] = NO_STATE;
- }
- «ENDIF»
- setClassName("«ac.name»");
- «ac.attributes.attributeInitialization(false)»
-
- «IF async»
- getMsgsvc()->addAsyncActor(*this);
- «ENDIF»
- «IF ctor!=null»
- // user defined constructor body
- «AbstractGenerator::getInstance().getTranslatedCode(ctor.detailCode)»
- «ENDIF»
- }
-
- void «ac.name»::init(){
- initUser();
- }
-
- void «ac.name»::start(){
- startUser();
- }
-
- «IF !ac.overridesStop()»
- void «ac.name»::stop(){
- stopUser();
- }
- «ENDIF»
-
- void «ac.name»::destroy(){
- «IF dtor!=null»
-
- // user defined destructor body
- «AbstractGenerator::getInstance().getTranslatedCode(dtor.detailCode)»
- «ENDIF»
- }
-
- «IF ac.hasNonEmptyStateMachine»
- «xpac.genStateMachine(false)»
- «ELSEIF !xpac.hasStateMachine()»
- //--------------------- no state machine
- void «ac.name»::receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data) {
- handleSystemEvent(ifitem, evt, data);
- }
-
- void «ac.name»::executeInitTransition(){
- }
- «ENDIF»
- '''
- }
-
-
-}
+/*******************************************************************************
+ * 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.inject.Inject
+import com.google.inject.Singleton
+import java.util.ArrayList
+import org.eclipse.etrice.core.genmodel.base.ILogger
+import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
+import org.eclipse.etrice.core.genmodel.etricegen.Root
+import org.eclipse.etrice.core.room.ActorClass
+import org.eclipse.etrice.generator.base.AbstractGenerator
+import org.eclipse.etrice.generator.generic.GenericActorClassGenerator
+import org.eclipse.etrice.generator.generic.ProcedureHelpers
+import org.eclipse.etrice.generator.generic.RoomExtensions
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+import org.eclipse.etrice.generator.cpp.GeneratorOptions
+import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
+import org.eclipse.etrice.core.room.ActorCommunicationType
+
+/**
+ * @author Peter Karlitschek
+ *
+ */
+@Singleton
+class ActorClassGen extends GenericActorClassGenerator {
+
+ @Inject JavaIoFileSystemAccess fileAccess
+ @Inject extension CppExtensions
+ @Inject extension RoomExtensions
+ @Inject extension Initialization
+ @Inject extension ProcedureHelpers
+ @Inject extension StateMachineGen
+ @Inject ILogger logger
+
+ def doGenerate(Root root) {
+ for (xpac: root.xpActorClasses) {
+ var path = xpac.actorClass.generationTargetPath+xpac.actorClass.getPath
+
+ logger.logInfo("generating ActorClass header '"+xpac.actorClass.getCppHeaderFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(xpac.actorClass.getCppHeaderFileName, root.generateHeaderFile(xpac, xpac.actorClass))
+
+ logger.logInfo("generating ActorClass source '"+xpac.actorClass.getCppSourceFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(xpac.actorClass.getCppSourceFileName, root.generateSourceFile(xpac, xpac.actorClass))
+ }
+ }
+
+ def private generateHeaderFile(Root root, ExpandedActorClass xpac, ActorClass ac) {
+// val ctor = ac.operations.filter(op|op.constructor).head
+// val dtor = ac.operations.filter(op|op.destructor).head
+
+ '''
+ /**
+ * @author generated by eTrice
+ *
+ * Header File of ActorClass «ac.name»
+ *
+ */
+
+ «generateIncludeGuardBegin(ac.name)»
+
+ #include "platforms/generic/etDatatypes.h"
+ #include "common/messaging/IRTObject.h"
+ #include "common/modelbase/PortBase.h"
+ #include "common/modelbase/InterfaceItemBase.h"
+ #include "common/modelbase/ActorClassBase.h"
+ #include "common/modelbase/SubSystemClassBase.h"
+ #include "common/messaging/Address.h"
+ #include "common/messaging/IMessageReceiver.h"
+ #include "common/debugging/DebuggingService.h"
+ «IF GeneratorOptions::useEtUnit»
+ extern "C" {
+ #include "etUnit.h"
+ }
+ «ENDIF»
+ #include <string>
+ #include <vector>
+
+ «FOR model : root.getReferencedModels(ac)»
+««« #include "«model.name».h"
+ «ENDFOR»
+
+ «FOR pc : root.getReferencedProtocolClasses(ac)»
+ #include "«pc.path»«pc.name».h"
+ «ENDFOR»
+ «FOR dc : root.getReferencedDataClasses(ac)»
+ #include "«dc.path»«dc.name».h"
+ «ENDFOR»
+
+
+ «ac.userCode(1)»
+
+
+ class «ac.name» : public «IF ac.base!=null»«ac.base.name»«ELSE»etRuntime::ActorClassBase«ENDIF» {
+
+
+ protected:
+ //--------------------- ports
+ «ac.endPorts.map(port | '''«port.portClassName» «port.name»;''').join("\n")»
+ //--------------------- saps
+ «ac.strSAPs.map(sap | '''«sap.portClassName» «sap.name»;''').join("\n")»
+ //--------------------- services
+ «ac.serviceImplementations.map(svc | '''«svc.portClassName» «svc.spp.name»;''').join("\n")»
+
+ //--------------------- interface item IDs
+ «xpac.genInterfaceItemConstants»
+
+ «ac.attributes.attributes»
+
+ «ac.operationsImplementation»
+
+ public:
+ //--------------------- construction
+ «ac.name»(etRuntime::IRTObject* parent, std::string name, const std::vector<std::vector<etRuntime::Address> >& port_addr,
+ const std::vector<std::vector<etRuntime::Address> >& peer_addr);
+
+««« TODO: check whether attribute setters/getters are necessary at all, if yes own cpp implementation is needed for *,[],& variables
+««« «attributeSettersGettersImplementation(ac.attributes, ac.name)»
+ //--------------------- port getters
+ «FOR ep : ac.getEndPorts()»
+ «ep.portClassName.getterImplementation(ep.name, ac.name)»
+ «ENDFOR»
+ «FOR sap : ac.strSAPs»
+ «sap.portClassName.getterImplementation(sap.name, ac.name)»
+ «ENDFOR»
+ «FOR svc : ac.serviceImplementations»
+ «svc.portClassName.getterImplementation(svc.spp.name, ac.name)»
+ «ENDFOR»
+
+ //--------------------- lifecycle functions
+ virtual void init();
+ virtual void start();
+ «IF !ac.overridesStop()»
+ virtual void stop();
+ «ENDIF»
+ virtual void destroy();
+ «IF ac.hasNonEmptyStateMachine»
+ «xpac.genStateMachineMethodDeclarations()»
+ «ELSEIF !xpac.hasStateMachine()»
+ public:
+ //--------------------- no state machine
+ virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data);
+ virtual void executeInitTransition();
+ «ENDIF»
+
+ «ac.userCode(2)»
+
+ };
+
+
+ «generateIncludeGuardEnd(ac.name)»
+ '''
+ }
+ def private generateConstructorInitalizerList(ActorClass ac) {
+ var initializerList = new ArrayList<CharSequence>();
+ if (ac.base==null) {
+ initializerList.add('''ActorClassBase( parent, name, port_addr[0][0], peer_addr[0][0])''')
+ }
+ else {
+ initializerList.add('''«ac.base.name»(*this, parent, name, port_addr, peer_addr)''')
+ }
+ // own ports
+ for ( ep : ac.getEndPorts() ) {
+ initializerList.add('''«ep.name»(*this, this, "«ep.name»", IFITEM_«ep.name», «IF ep.multiplicity==1»0, «ENDIF»port_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF», peer_addr[IFITEM_«ep.name»]«IF ep.multiplicity==1»[0]«ENDIF»)''');
+ }
+ // own saps
+ for ( sap : ac.strSAPs ) {
+ initializerList.add('''«sap.name»(*this, this, "«sap.name»", IFITEM_«sap.name», 0, port_addr[IFITEM_«sap.name»][0], peer_addr[IFITEM_«sap.name»][0])''');
+ }
+ // own service implementations
+ for (svc : ac.serviceImplementations) {
+ initializerList.add('''«svc.spp.name»(*this, this, "«svc.spp.name»", IFITEM_«svc.spp.name», port_addr[IFITEM_«svc.spp.name»], peer_addr[IFITEM_«svc.spp.name»])''');
+ }
+ for (attrib: ac.attributes) {
+ initializerList.add(attrib.attributeInitialization(false))
+ }
+ return
+ '''
+ «initializerList.join(',\n')»
+ '''
+ }
+
+
+ def private generateSourceFile(Root root, ExpandedActorClass xpac, ActorClass ac) {
+ val ctor = ac.operations.filter(op|op.constructor).head
+ val dtor = ac.operations.filter(op|op.destructor).head
+ val async = xpac.actorClass.commType==ActorCommunicationType::ASYNCHRONOUS
+
+ '''
+ /**
+ * @author generated by eTrice
+ *
+ * Source File of ActorClass «ac.name»
+ *
+ */
+
+ #include "«ac.getCppHeaderFileName»"
+ #include "common/debugging/DebuggingService.h"
+ #include <iostream>
+
+ using namespace etRuntime;
+
+
+ «ac.name»::«ac.name»(etRuntime::IRTObject* parent, std::string name, const std::vector<std::vector<etRuntime::Address> >& port_addr,
+ const std::vector<std::vector<etRuntime::Address> >& peer_addr)
+ : «ac.generateConstructorInitalizerList»
+ {
+ «IF ac.hasNonEmptyStateMachine»
+ history = new int[s_numberOfStates];
+ for (int i = 0; i < s_numberOfStates; i++) {
+ history[i] = NO_STATE;
+ }
+ «ENDIF»
+ setClassName("«ac.name»");
+ «ac.attributes.attributeInitialization(false)»
+
+ «IF async»
+ getMsgsvc()->addAsyncActor(*this);
+ «ENDIF»
+ «IF ctor!=null»
+ // user defined constructor body
+ «AbstractGenerator::getInstance().getTranslatedCode(ctor.detailCode)»
+ «ENDIF»
+ }
+
+ void «ac.name»::init(){
+ initUser();
+ }
+
+ void «ac.name»::start(){
+ startUser();
+ }
+
+ «IF !ac.overridesStop()»
+ void «ac.name»::stop(){
+ stopUser();
+ }
+ «ENDIF»
+
+ void «ac.name»::destroy(){
+ «IF dtor!=null»
+
+ // user defined destructor body
+ «AbstractGenerator::getInstance().getTranslatedCode(dtor.detailCode)»
+ «ENDIF»
+ }
+
+ «IF ac.hasNonEmptyStateMachine»
+ «xpac.genStateMachine(false)»
+ «ELSEIF !xpac.hasStateMachine()»
+ //--------------------- no state machine
+ void «ac.name»::receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data) {
+ handleSystemEvent(ifitem, evt, data);
+ }
+
+ void «ac.name»::executeInitTransition(){
+ }
+ «ENDIF»
+ '''
+ }
+
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend
index 282301704..f59a1db1f 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend
@@ -11,22 +11,22 @@
*
*******************************************************************************/
-package org.eclipse.etrice.generator.cpp.gen
-
-import com.google.inject.Inject
-import java.util.ArrayList
-import java.util.List
-import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance
-import org.eclipse.etrice.core.genmodel.etricegen.InstanceBase
-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.ExternalType
-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.generic.ProcedureHelpers
-import org.eclipse.etrice.generator.generic.RoomExtensions
+package org.eclipse.etrice.generator.cpp.gen
+
+import com.google.inject.Inject
+import java.util.ArrayList
+import java.util.List
+import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance
+import org.eclipse.etrice.core.genmodel.etricegen.InstanceBase
+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.ExternalType
+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.generic.ProcedureHelpers
+import org.eclipse.etrice.generator.generic.RoomExtensions
import org.eclipse.etrice.generator.generic.TypeHelpers
import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
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 1e2ef4628..0380ced99 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
@@ -1,225 +1,225 @@
-/*******************************************************************************
- * 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
- *
- *******************************************************************************/
-
-/*
- collection of convenience functions for code generation
-*/
-
-
-package org.eclipse.etrice.generator.cpp.gen
-
-import com.google.inject.Inject
-import com.google.inject.Singleton
-import java.util.List
-import org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician
-import org.eclipse.etrice.core.room.DataType
-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.RoomClass
-import org.eclipse.etrice.core.room.VarDecl
-import org.eclipse.etrice.core.room.DataClass
-import org.eclipse.etrice.generator.generic.ILanguageExtension
-import org.eclipse.etrice.generator.generic.TypeHelpers
-import org.eclipse.xtext.util.Pair
-
-@Singleton
-class CppExtensions implements ILanguageExtension {
-
- @Inject IDiagnostician diagnostician
- @Inject extension TypeHelpers
-
-
- override String getTypedDataDefinition(Message m) {
- generateArglistAndTypedData(m.data).get(1)
- }
-
-
- def String getCppHeaderFileName(RoomClass rc) {rc.name+".h"}
- def String getCppSourceFileName(RoomClass rc) {rc.name+".cpp"}
- def String getInstSourceFileName(RoomClass rc) {rc.name+"_Inst.h"}
- def String getDispSourceFileName(RoomClass rc) {rc.name+"_Disp.h"}
-
- override String accessLevelPrivate() {""}
- override String accessLevelProtected() {""}
- override String accessLevelPublic() {""}
-
- override String memberAccess() {"this->"}
- override String selfPointer(String classname, boolean hasArgs) {""}
- override String selfPointer(boolean hasArgs) { "" }
-
- override String operationScope(String classname, boolean isDeclaration) {
- if (isDeclaration)
- ""
- else
- classname+"::"
- }
-
-
- override String memberInDeclaration(String namespace, String member) {
- return member
- }
-
- override String memberInUse(String namespace, String member) {
- return namespace+"."+member
- }
-
- override boolean usesInheritance() {
- return true
- }
-
- override boolean usesPointers() {
- return true
- }
-
- override String genEnumeration(String name, List<Pair<String, String>> entries) {
- '''
- typedef enum {
- «FOR entry: entries»
- «entry.first» = «entry.second»,
- «ENDFOR»
- } «name»;'''.toString
- }
-
- override String booleanConstant(boolean b) {
- b.toString
- }
-
- override String pointerLiteral() { "*" }
- override String nullPointer() { "0" }
- override String voidPointer() { "void*" }
-
- override String arrayDeclaration(String type, int size, String name, boolean isRef) {
- type+" "+name+"["+size+"]";
- }
-
- override String constructorName(String cls) {
- cls
- }
- override String destructorName(String cls) {
- cls+"_dtor"
- }
- override String constructorReturnType() {
- ""
- }
- override String destructorReturnType() {
- "void"
- }
-
- def getIncludeGuardString(String filename){
- '''_«filename.replaceAll("\\/.", "_").toUpperCase»_H_'''
- }
-
- def generateIncludeGuardBegin(String filename){'''
- #ifndef «filename.getIncludeGuardString»
- #define «filename.getIncludeGuardString»
- '''
- }
-
- def generateIncludeGuardEnd(String filename){'''
- #endif /* «filename.getIncludeGuardString» */
- '''
- }
-
-
-
- override superCall(String baseClassName, String method, String arguments) {
- baseClassName+"::"+method+"("+arguments+");"
- }
-
-
- override String toValueLiteral(PrimitiveType type, String value){
- throw new UnsupportedOperationException("TODO Config for Cpp");
- }
-
- override String defaultValue(DataType dt) {
- if (dt instanceof PrimitiveType) {
- return (dt as PrimitiveType).getDefaultValueLiteral
- }
- else if (dt instanceof ExternalType) {
- diagnostician.warning("initialize external type with default constructor"+dt.name, dt.eContainer, dt.eContainingFeature)
- return dt.typeName + "()"
- }
- else {
- val dc = dt as DataClass
-
- '''
- {
- «FOR att : dc.attributes SEPARATOR ","»
- «att.refType.type.initializationWithDefaultValues(att.size)»
- «ENDFOR»
- }
- '''
- }
- }
-
- override initializationWithDefaultValues(DataType dt, int size) {
- val dv = dt.defaultValue
- if (size>1) {
- var res = "{"
- var i = 0
- while (i<size) {
- res = res + dv
- i = i+1
- if (i<size)
- res = res + ","
- }
- res+"}"
- }
- else
- dv
- }
-
- override generateArglistAndTypedData(VarDecl data) {
- var deref = "*"
- if (data==null)
- return newArrayList("", "", "")
-
- var typeName = if (data.getRefType().getType() instanceof PrimitiveType)
- (data.getRefType().getType() as PrimitiveType).getTargetName()
- else
- data.getRefType().getType().getName()
-
- var castTypeName = if (data.getRefType().getType() instanceof PrimitiveType) {
- val ct = (data.getRefType().getType() as PrimitiveType).getCastName()
- if (ct!=null && !ct.isEmpty())
- ct
- else
- typeName
- }
- else
- typeName
- castTypeName = castTypeName+"*"
-
- if (data.getRefType().isRef()) {
- typeName = typeName+"*"
- castTypeName = castTypeName+"*"
- }
- else if (!(data.getRefType().getType() instanceof PrimitiveType)) {
- typeName = typeName+"*"
- castTypeName = castTypeName+"*"
- }
- else {
- castTypeName = typeName
- deref = ""
- }
-
- val typedData = typeName+" "+data.getName() + " = " + deref + "(("+castTypeName+") generic_data);\n"
-
- val dataArg = ", "+data.getName()
- val typedArgList = ", "+typeName+" "+data.getName()
-
- return newArrayList(dataArg, typedData, typedArgList);
- }
-
-}
+/*******************************************************************************
+ * 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
+ *
+ *******************************************************************************/
+
+/*
+ collection of convenience functions for code generation
+*/
+
+
+package org.eclipse.etrice.generator.cpp.gen
+
+import com.google.inject.Inject
+import com.google.inject.Singleton
+import java.util.List
+import org.eclipse.etrice.core.genmodel.etricegen.IDiagnostician
+import org.eclipse.etrice.core.room.DataType
+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.RoomClass
+import org.eclipse.etrice.core.room.VarDecl
+import org.eclipse.etrice.core.room.DataClass
+import org.eclipse.etrice.generator.generic.ILanguageExtension
+import org.eclipse.etrice.generator.generic.TypeHelpers
+import org.eclipse.xtext.util.Pair
+
+@Singleton
+class CppExtensions implements ILanguageExtension {
+
+ @Inject IDiagnostician diagnostician
+ @Inject extension TypeHelpers
+
+
+ override String getTypedDataDefinition(Message m) {
+ generateArglistAndTypedData(m.data).get(1)
+ }
+
+
+ def String getCppHeaderFileName(RoomClass rc) {rc.name+".h"}
+ def String getCppSourceFileName(RoomClass rc) {rc.name+".cpp"}
+ def String getInstSourceFileName(RoomClass rc) {rc.name+"_Inst.h"}
+ def String getDispSourceFileName(RoomClass rc) {rc.name+"_Disp.h"}
+
+ override String accessLevelPrivate() {""}
+ override String accessLevelProtected() {""}
+ override String accessLevelPublic() {""}
+
+ override String memberAccess() {"this->"}
+ override String selfPointer(String classname, boolean hasArgs) {""}
+ override String selfPointer(boolean hasArgs) { "" }
+
+ override String operationScope(String classname, boolean isDeclaration) {
+ if (isDeclaration)
+ ""
+ else
+ classname+"::"
+ }
+
+
+ override String memberInDeclaration(String namespace, String member) {
+ return member
+ }
+
+ override String memberInUse(String namespace, String member) {
+ return namespace+"."+member
+ }
+
+ override boolean usesInheritance() {
+ return true
+ }
+
+ override boolean usesPointers() {
+ return true
+ }
+
+ override String genEnumeration(String name, List<Pair<String, String>> entries) {
+ '''
+ typedef enum {
+ «FOR entry: entries»
+ «entry.first» = «entry.second»,
+ «ENDFOR»
+ } «name»;'''.toString
+ }
+
+ override String booleanConstant(boolean b) {
+ b.toString
+ }
+
+ override String pointerLiteral() { "*" }
+ override String nullPointer() { "0" }
+ override String voidPointer() { "void*" }
+
+ override String arrayDeclaration(String type, int size, String name, boolean isRef) {
+ type+" "+name+"["+size+"]";
+ }
+
+ override String constructorName(String cls) {
+ cls
+ }
+ override String destructorName(String cls) {
+ cls+"_dtor"
+ }
+ override String constructorReturnType() {
+ ""
+ }
+ override String destructorReturnType() {
+ "void"
+ }
+
+ def getIncludeGuardString(String filename){
+ '''_«filename.replaceAll("\\/.", "_").toUpperCase»_H_'''
+ }
+
+ def generateIncludeGuardBegin(String filename){'''
+ #ifndef «filename.getIncludeGuardString»
+ #define «filename.getIncludeGuardString»
+ '''
+ }
+
+ def generateIncludeGuardEnd(String filename){'''
+ #endif /* «filename.getIncludeGuardString» */
+ '''
+ }
+
+
+
+ override superCall(String baseClassName, String method, String arguments) {
+ baseClassName+"::"+method+"("+arguments+");"
+ }
+
+
+ override String toValueLiteral(PrimitiveType type, String value){
+ throw new UnsupportedOperationException("TODO Config for Cpp");
+ }
+
+ override String defaultValue(DataType dt) {
+ if (dt instanceof PrimitiveType) {
+ return (dt as PrimitiveType).getDefaultValueLiteral
+ }
+ else if (dt instanceof ExternalType) {
+ diagnostician.warning("initialize external type with default constructor"+dt.name, dt.eContainer, dt.eContainingFeature)
+ return dt.typeName + "()"
+ }
+ else {
+ val dc = dt as DataClass
+
+ '''
+ {
+ «FOR att : dc.attributes SEPARATOR ","»
+ «att.refType.type.initializationWithDefaultValues(att.size)»
+ «ENDFOR»
+ }
+ '''
+ }
+ }
+
+ override initializationWithDefaultValues(DataType dt, int size) {
+ val dv = dt.defaultValue
+ if (size>1) {
+ var res = "{"
+ var i = 0
+ while (i<size) {
+ res = res + dv
+ i = i+1
+ if (i<size)
+ res = res + ","
+ }
+ res+"}"
+ }
+ else
+ dv
+ }
+
+ override generateArglistAndTypedData(VarDecl data) {
+ var deref = "*"
+ if (data==null)
+ return newArrayList("", "", "")
+
+ var typeName = if (data.getRefType().getType() instanceof PrimitiveType)
+ (data.getRefType().getType() as PrimitiveType).getTargetName()
+ else
+ data.getRefType().getType().getName()
+
+ var castTypeName = if (data.getRefType().getType() instanceof PrimitiveType) {
+ val ct = (data.getRefType().getType() as PrimitiveType).getCastName()
+ if (ct!=null && !ct.isEmpty())
+ ct
+ else
+ typeName
+ }
+ else
+ typeName
+ castTypeName = castTypeName+"*"
+
+ if (data.getRefType().isRef()) {
+ typeName = typeName+"*"
+ castTypeName = castTypeName+"*"
+ }
+ else if (!(data.getRefType().getType() instanceof PrimitiveType)) {
+ typeName = typeName+"*"
+ castTypeName = castTypeName+"*"
+ }
+ else {
+ castTypeName = typeName
+ deref = ""
+ }
+
+ val typedData = typeName+" "+data.getName() + " = " + deref + "(("+castTypeName+") generic_data);\n"
+
+ val dataArg = ", "+data.getName()
+ val typedArgList = ", "+typeName+" "+data.getName()
+
+ return newArrayList(dataArg, typedData, typedArgList);
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.java b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.java
index 79d54f867..9de2326ae 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.java
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppTranslationProvider.java
@@ -1,60 +1,60 @@
-/*******************************************************************************
- * Copyright (c) 2012 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)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.generator.cpp.gen;
-
-import java.util.ArrayList;
-
-import org.eclipse.etrice.core.room.DetailCode;
-import org.eclipse.etrice.core.room.InterfaceItem;
-import org.eclipse.etrice.core.room.Message;
-import org.eclipse.etrice.generator.base.DefaultTranslationProvider;
-
-/**
- * @author hrentz
- *
- */
-public class CppTranslationProvider extends DefaultTranslationProvider {
-
- @Override
- public boolean translateMembers() {
- return true;
- }
-
- @Override
- public boolean translateTags() {
- return true;
- }
-
- @Override
- public String getInterfaceItemMessageText(InterfaceItem item, Message msg, ArrayList<String> args, String index, String orig) {
- if (index==null)
- return orig;
-
- StringBuilder argtext = new StringBuilder();
- for (String arg : args) {
- argtext.append(", "+arg);
- }
-
- // TODO: overload operator[] ???
- return item.getName()+".get("+index+")."+msg.getName()+"("+argtext.toString()+")";
- }
-
- @Override
- public String translateTag(String tag, DetailCode code) {
- if (tag.equals("ifitem.index"))
- return "ifitem.getIdx()";
-
- return super.translateTag(tag, code);
- }
-
-}
+/*******************************************************************************
+ * Copyright (c) 2012 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)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.cpp.gen;
+
+import java.util.ArrayList;
+
+import org.eclipse.etrice.core.room.DetailCode;
+import org.eclipse.etrice.core.room.InterfaceItem;
+import org.eclipse.etrice.core.room.Message;
+import org.eclipse.etrice.generator.base.DefaultTranslationProvider;
+
+/**
+ * @author hrentz
+ *
+ */
+public class CppTranslationProvider extends DefaultTranslationProvider {
+
+ @Override
+ public boolean translateMembers() {
+ return true;
+ }
+
+ @Override
+ public boolean translateTags() {
+ return true;
+ }
+
+ @Override
+ public String getInterfaceItemMessageText(InterfaceItem item, Message msg, ArrayList<String> args, String index, String orig) {
+ if (index==null)
+ return orig;
+
+ StringBuilder argtext = new StringBuilder();
+ for (String arg : args) {
+ argtext.append(", "+arg);
+ }
+
+ // TODO: overload operator[] ???
+ return item.getName()+".get("+index+")."+msg.getName()+"("+argtext.toString()+")";
+ }
+
+ @Override
+ public String translateTag(String tag, DetailCode code) {
+ if (tag.equals("ifitem.index"))
+ return "ifitem.getIdx()";
+
+ return super.translateTag(tag, code);
+ }
+
+}
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 ac5a4ae9e..cb17d57bc 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
@@ -1,281 +1,281 @@
-/*******************************************************************************
- * 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.inject.Inject
-import com.google.inject.Singleton
-import java.util.List
-import org.eclipse.etrice.core.genmodel.base.ILogger
-import org.eclipse.etrice.core.genmodel.etricegen.Root
-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.generator.generic.ProcedureHelpers
-import org.eclipse.etrice.generator.generic.RoomExtensions
-import org.eclipse.etrice.generator.generic.TypeHelpers
-import org.eclipse.etrice.generator.cpp.gen.Initialization
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-import org.eclipse.etrice.generator.cpp.GeneratorOptions
-
-import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
-
-/**
- * @author Peter Karlitschek
- *
- */
-@Singleton
-class DataClassGen {
-
- @Inject extension JavaIoFileSystemAccess fileAccess
- @Inject extension CppExtensions stdExt
- @Inject extension RoomExtensions roomExt
- @Inject extension ProcedureHelpers helpers
- @Inject extension TypeHelpers typeHelpers
- @Inject extension Initialization
- @Inject ILogger logger
-
- def doGenerate(Root root) {
- logger.logInfo("generating code")
- for (dc: root.usedDataClasses) {
- var path = dc.generationTargetPath + dc.getPath
-
- // header file
- logger.logInfo("generating DataClass header '"+dc.getCppHeaderFileName+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(dc.getCppHeaderFileName, root.generateHeaderFile(dc))
-
- // source file
- logger.logInfo("generating DataClass source '"+dc.getCppSourceFileName+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(dc.getCppSourceFileName, root.generateSourceFile(dc))
-
- }
-
- }
-
- def generateHeaderFile(Root root, DataClass dc) {
- val ctor = dc.operations.filter(op|op.constructor).head
- val dtor = dc.operations.filter(op|op.destructor).head
- //TODO: getReferencedDataClasses does not contain a base class of the own package
- '''
- «generateIncludeGuardBegin(dc.path + dc.name)»
-
- «IF dc.base!=null»
- #include "«dc.base.path»«dc.base.name».h"
- «ENDIF»
- «FOR classes : root.getReferencedDataClasses(dc)»
- #include "«classes.path»«classes.name».h"
- «ENDFOR»
- «var models = root.getReferencedModels(dc)»
- «FOR model : models»
- «FOR classes : model.dataClasses»
- #include "«classes.path»«classes.name».h"
- «ENDFOR»
- «ENDFOR»
-
- «helpers.userCode(dc.userCode1)»
-
-
- class «dc.name»«IF dc.base!=null» : public «dc.base.name»«ENDIF» {
-
- public:
- «helpers.userCode(dc.userCode2)»
-
- «helpers.attributes(dc.attributes)»
-
- «helpers.attributeSettersGettersImplementation(dc.attributes, dc.name)»
-
- «helpers.operationsDeclaration(dc.operations, dc.name)»
-
- // default constructor, copy constructor and assignment operator
- «dc.name»();
- «dc.name»(const «dc.name»& rhs);
- «dc.name»& operator=(const «dc.name»& rhs);
-
- // constructor using fields
- «dc.name»(«dc.argList»);
-
- «IF dc.base!=null»
- // constructor using base class constructor
- «dc.name»(«dc.base.name» _super, «dc.attributes.argListConstructor.toString»);
- «ENDIF»
-
- };
-
- «generateIncludeGuardEnd(dc.name)»
-
- '''
- }
-
- def generateSourceFile(Root root, DataClass dc) {
- val ctor = dc.operations.filter(op|op.constructor).head
- val dtor = dc.operations.filter(op|op.destructor).head
-
- '''
- /**
- * @author generated by eTrice
- *
- * Source File of DataClass «dc.name»
- */
-
- #include "«dc.getCppHeaderFileName»"
- «IF GeneratorOptions::useEtUnit»
- extern "C" {
- #include "etUnit.h"
- }
- «ENDIF»
-
- «helpers.userCode(dc.userCode3)»
-
-
- // default constructor
- «dc.name»::«dc.name»()
- «IF dc.base!=null»
- :«dc.base.name»()
- «ENDIF»
- {
- «dc.attributes.attributeInitialization(false)»
- «IF ctor!=null»
- {
- // user defined constructor body
- «FOR l : ctor.detailCode.commands»
- «l»
- «ENDFOR»
- }
- «ENDIF»
- }
-
- // copy constructor
- «dc.name»::«dc.name»(const «dc.name»& rhs)
- :
- «IF dc.base!=null»
- «dc.base.name»(rhs),
- «ENDIF»
- «FOR a : dc.attributes SEPARATOR ","»
- «a.name»(rhs.«a.name»)
- «ENDFOR»
- {
- }
-
- // constructor using fields
- «dc.name»::«dc.name»(«dc.argList»)
- :
- «IF dc.base!=null»
- «dc.base.name»(«dc.base.paramList»),
- «ENDIF»
- «FOR a : dc.attributes SEPARATOR ","»
- «a.name»(«a.name»_)
- «ENDFOR»
- {
- }
-
- «IF dc.base!=null»
- // constructor using base class constructor
- «dc.name»::«dc.name»(«dc.base.name» _super, «dc.attributes.argListConstructor.toString»)
- :
- «dc.base.name»(_super),
- «FOR a : dc.attributes SEPARATOR ","»
- «a.name»(«a.name»_)
- «ENDFOR»
- {
- }
- «ENDIF»
-
- // assignment operator
- «dc.name»& «dc.name»::operator=(const «dc.name»& rhs)
- {
- if (this == &rhs) { return *this; };
- «IF dc.base!=null»
- «dc.base.name»::operator=(rhs);
- «ENDIF»
- «FOR a : dc.attributes»
- «a.name»= rhs.«a.name»;
- «ENDFOR»
- return *this;
- }
-
- «helpers.operationsImplementation(dc.operations, dc.name)»
-
- '''}
-
- def paramList(DataClass _dc) {
- var result = ""
- var dc = _dc
- while (dc!=null) {
- result = dc.attributes.paramList.toString + result
- dc = dc.base
- if (dc!=null)
- result = ", "+result
- }
- return result
- }
-
- def paramList(List<Attribute> attributes) {
- '''«FOR a: attributes SEPARATOR ", "»«a.name»_«ENDFOR»'''
- }
-
- def argList(DataClass _dc) {
- var result = ""
- var dc = _dc
- while (dc!=null) {
- result = dc.attributes.argListConstructor.toString + result
- dc = dc.base
- if (dc!=null)
- result = ", "+result
- }
- return result
- }
-
- def argListConstructor(List<Attribute> attributes) {
- '''«FOR a : attributes SEPARATOR ", "»«a.refType.type.typeName»«IF a.size>1»[]«ENDIF» «a.name»_«ENDFOR»'''
- }
-
-
-
- def deepCopy(DataClass _dc) {
- var result = ""
- var dc = _dc
- while (dc!=null) {
- result = deepCopy(dc.attributes).toString + result
- dc = dc.base
- }
- return result
- }
-
- def deepCopy(List<Attribute> attributes) {
- '''
- «FOR a : attributes»
- «IF a.refType.type instanceof ComplexType»
- if («a.name»!=null) {
- «IF a.size==0»
- copy.«a.name» = «a.name».deepCopy();
- «ELSE»
- for (int i=0;i<«a.name».length;i++){
- copy.«a.name»[i] = «a.name»[i].deepCopy();
- }
- «ENDIF»
- }
- «ELSE»
- «IF a.size==0»
- copy.«a.name» = «a.name»;
- «ELSE»
- for (int i=0;i<«a.name».length;i++){
- copy.«a.name»[i] = «a.name»[i];
- }
- «ENDIF»
- «ENDIF»
- «ENDFOR»
- '''
- }
-
-}
+/*******************************************************************************
+ * 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.inject.Inject
+import com.google.inject.Singleton
+import java.util.List
+import org.eclipse.etrice.core.genmodel.base.ILogger
+import org.eclipse.etrice.core.genmodel.etricegen.Root
+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.generator.generic.ProcedureHelpers
+import org.eclipse.etrice.generator.generic.RoomExtensions
+import org.eclipse.etrice.generator.generic.TypeHelpers
+import org.eclipse.etrice.generator.cpp.gen.Initialization
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+import org.eclipse.etrice.generator.cpp.GeneratorOptions
+
+import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
+
+/**
+ * @author Peter Karlitschek
+ *
+ */
+@Singleton
+class DataClassGen {
+
+ @Inject extension JavaIoFileSystemAccess fileAccess
+ @Inject extension CppExtensions stdExt
+ @Inject extension RoomExtensions roomExt
+ @Inject extension ProcedureHelpers helpers
+ @Inject extension TypeHelpers typeHelpers
+ @Inject extension Initialization
+ @Inject ILogger logger
+
+ def doGenerate(Root root) {
+ logger.logInfo("generating code")
+ for (dc: root.usedDataClasses) {
+ var path = dc.generationTargetPath + dc.getPath
+
+ // header file
+ logger.logInfo("generating DataClass header '"+dc.getCppHeaderFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(dc.getCppHeaderFileName, root.generateHeaderFile(dc))
+
+ // source file
+ logger.logInfo("generating DataClass source '"+dc.getCppSourceFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(dc.getCppSourceFileName, root.generateSourceFile(dc))
+
+ }
+
+ }
+
+ def generateHeaderFile(Root root, DataClass dc) {
+ val ctor = dc.operations.filter(op|op.constructor).head
+ val dtor = dc.operations.filter(op|op.destructor).head
+ //TODO: getReferencedDataClasses does not contain a base class of the own package
+ '''
+ «generateIncludeGuardBegin(dc.path + dc.name)»
+
+ «IF dc.base!=null»
+ #include "«dc.base.path»«dc.base.name».h"
+ «ENDIF»
+ «FOR classes : root.getReferencedDataClasses(dc)»
+ #include "«classes.path»«classes.name».h"
+ «ENDFOR»
+ «var models = root.getReferencedModels(dc)»
+ «FOR model : models»
+ «FOR classes : model.dataClasses»
+ #include "«classes.path»«classes.name».h"
+ «ENDFOR»
+ «ENDFOR»
+
+ «helpers.userCode(dc.userCode1)»
+
+
+ class «dc.name»«IF dc.base!=null» : public «dc.base.name»«ENDIF» {
+
+ public:
+ «helpers.userCode(dc.userCode2)»
+
+ «helpers.attributes(dc.attributes)»
+
+ «helpers.attributeSettersGettersImplementation(dc.attributes, dc.name)»
+
+ «helpers.operationsDeclaration(dc.operations, dc.name)»
+
+ // default constructor, copy constructor and assignment operator
+ «dc.name»();
+ «dc.name»(const «dc.name»& rhs);
+ «dc.name»& operator=(const «dc.name»& rhs);
+
+ // constructor using fields
+ «dc.name»(«dc.argList»);
+
+ «IF dc.base!=null»
+ // constructor using base class constructor
+ «dc.name»(«dc.base.name» _super, «dc.attributes.argListConstructor.toString»);
+ «ENDIF»
+
+ };
+
+ «generateIncludeGuardEnd(dc.name)»
+
+ '''
+ }
+
+ def generateSourceFile(Root root, DataClass dc) {
+ val ctor = dc.operations.filter(op|op.constructor).head
+ val dtor = dc.operations.filter(op|op.destructor).head
+
+ '''
+ /**
+ * @author generated by eTrice
+ *
+ * Source File of DataClass «dc.name»
+ */
+
+ #include "«dc.getCppHeaderFileName»"
+ «IF GeneratorOptions::useEtUnit»
+ extern "C" {
+ #include "etUnit.h"
+ }
+ «ENDIF»
+
+ «helpers.userCode(dc.userCode3)»
+
+
+ // default constructor
+ «dc.name»::«dc.name»()
+ «IF dc.base!=null»
+ :«dc.base.name»()
+ «ENDIF»
+ {
+ «dc.attributes.attributeInitialization(false)»
+ «IF ctor!=null»
+ {
+ // user defined constructor body
+ «FOR l : ctor.detailCode.commands»
+ «l»
+ «ENDFOR»
+ }
+ «ENDIF»
+ }
+
+ // copy constructor
+ «dc.name»::«dc.name»(const «dc.name»& rhs)
+ :
+ «IF dc.base!=null»
+ «dc.base.name»(rhs),
+ «ENDIF»
+ «FOR a : dc.attributes SEPARATOR ","»
+ «a.name»(rhs.«a.name»)
+ «ENDFOR»
+ {
+ }
+
+ // constructor using fields
+ «dc.name»::«dc.name»(«dc.argList»)
+ :
+ «IF dc.base!=null»
+ «dc.base.name»(«dc.base.paramList»),
+ «ENDIF»
+ «FOR a : dc.attributes SEPARATOR ","»
+ «a.name»(«a.name»_)
+ «ENDFOR»
+ {
+ }
+
+ «IF dc.base!=null»
+ // constructor using base class constructor
+ «dc.name»::«dc.name»(«dc.base.name» _super, «dc.attributes.argListConstructor.toString»)
+ :
+ «dc.base.name»(_super),
+ «FOR a : dc.attributes SEPARATOR ","»
+ «a.name»(«a.name»_)
+ «ENDFOR»
+ {
+ }
+ «ENDIF»
+
+ // assignment operator
+ «dc.name»& «dc.name»::operator=(const «dc.name»& rhs)
+ {
+ if (this == &rhs) { return *this; };
+ «IF dc.base!=null»
+ «dc.base.name»::operator=(rhs);
+ «ENDIF»
+ «FOR a : dc.attributes»
+ «a.name»= rhs.«a.name»;
+ «ENDFOR»
+ return *this;
+ }
+
+ «helpers.operationsImplementation(dc.operations, dc.name)»
+
+ '''}
+
+ def paramList(DataClass _dc) {
+ var result = ""
+ var dc = _dc
+ while (dc!=null) {
+ result = dc.attributes.paramList.toString + result
+ dc = dc.base
+ if (dc!=null)
+ result = ", "+result
+ }
+ return result
+ }
+
+ def paramList(List<Attribute> attributes) {
+ '''«FOR a: attributes SEPARATOR ", "»«a.name»_«ENDFOR»'''
+ }
+
+ def argList(DataClass _dc) {
+ var result = ""
+ var dc = _dc
+ while (dc!=null) {
+ result = dc.attributes.argListConstructor.toString + result
+ dc = dc.base
+ if (dc!=null)
+ result = ", "+result
+ }
+ return result
+ }
+
+ def argListConstructor(List<Attribute> attributes) {
+ '''«FOR a : attributes SEPARATOR ", "»«a.refType.type.typeName»«IF a.size>1»[]«ENDIF» «a.name»_«ENDFOR»'''
+ }
+
+
+
+ def deepCopy(DataClass _dc) {
+ var result = ""
+ var dc = _dc
+ while (dc!=null) {
+ result = deepCopy(dc.attributes).toString + result
+ dc = dc.base
+ }
+ return result
+ }
+
+ def deepCopy(List<Attribute> attributes) {
+ '''
+ «FOR a : attributes»
+ «IF a.refType.type instanceof ComplexType»
+ if («a.name»!=null) {
+ «IF a.size==0»
+ copy.«a.name» = «a.name».deepCopy();
+ «ELSE»
+ for (int i=0;i<«a.name».length;i++){
+ copy.«a.name»[i] = «a.name»[i].deepCopy();
+ }
+ «ENDIF»
+ }
+ «ELSE»
+ «IF a.size==0»
+ copy.«a.name» = «a.name»;
+ «ELSE»
+ for (int i=0;i<«a.name».length;i++){
+ copy.«a.name»[i] = «a.name»[i];
+ }
+ «ENDIF»
+ «ENDIF»
+ «ENDFOR»
+ '''
+ }
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Initialization.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Initialization.xtend
index 6b1d729af..cbf7d7bf7 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Initialization.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/Initialization.xtend
@@ -1,104 +1,104 @@
-/*******************************************************************************
- * Copyright (c) 2012 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.Inject
-import com.google.inject.Singleton
-import java.util.List
-import org.eclipse.etrice.core.room.Attribute
-import org.eclipse.etrice.core.room.ComplexType
-import org.eclipse.etrice.generator.base.IDataConfiguration
-import org.eclipse.etrice.generator.generic.ILanguageExtension
-import org.eclipse.etrice.generator.generic.ProcedureHelpers
-import org.eclipse.etrice.generator.generic.RoomExtensions
-import org.eclipse.etrice.generator.generic.TypeHelpers
-
-@Singleton
-class Initialization {
-
- @Inject extension TypeHelpers
- @Inject extension RoomExtensions
- @Inject ILanguageExtension languageExt
- @Inject IDataConfiguration dataConfigExt
- @Inject ProcedureHelpers procedureHelpers
-
- def attributeInitialization(List<Attribute> attribs, boolean useClassDefaultsOnly) {
- '''
- // initialize attributes
- «FOR a : attribs»
- «var aType = a.refType.type»
- «var value = a.defaultValueLiteral»
- «IF value!=null»
- «IF a.size == 0 || aType.characterType»
- «ELSEIF value.startsWith("{")»
- «initializeArrayWithValues(a.name, value.replace("{", "").replace("}", "").split(","))»
- «ELSE»
- for (int i=0;i<«a.size»;i++){
- «a.name»[i] = «value»;
- }
- «ENDIF»
- «ELSEIF aType instanceof ComplexType || a.size>1 || !useClassDefaultsOnly»
- «IF a.size==0»
- «ELSE»
- «IF !useClassDefaultsOnly»
- for (int i=0;i<«a.size»;i++){
- «a.name»[i] = «IF a.refType.isRef»«languageExt.nullPointer()»«ELSE»«languageExt.defaultValue(aType)»«ENDIF»;
- }
- «ENDIF»
- «ENDIF»
- «ENDIF»
- «ENDFOR»
- '''
- }
-
- def initializeArrayWithValues(String varName, String[] values) {
- '''
- «var i = -1»
- «FOR v : values»
- «varName»[«i=i+1»] = «v»;
- «ENDFOR»
- '''
- }
-
- def attributeInitialization(Attribute a, boolean useClassDefaultsOnly) {
- var aType = a.refType.type
- var value = a.defaultValueLiteral
- if (value != null) {
- if (a.size == 0 || aType.characterType) {
- if (a.refType.isRef)
- '''«a.name»(new «aType.name»(«value»))'''
- else
- '''«a.name»(«value»)'''
- }
- else if (value.startsWith("{")) {
- '''«a.name»()'''
- }
- else {
- '''«a.name»()'''
- }
- }
- else if (aType instanceof ComplexType || a.size>1 || !useClassDefaultsOnly) {
- if (a.size==0) {
- if (a.refType.isRef)
- '''«a.name»(«languageExt.nullPointer()»)'''
- else
- '''«a.name»(«languageExt.defaultValue(aType)»)'''
- }
- else
- '''«a.name»()'''
- }
- }
-
-
+/*******************************************************************************
+ * Copyright (c) 2012 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.Inject
+import com.google.inject.Singleton
+import java.util.List
+import org.eclipse.etrice.core.room.Attribute
+import org.eclipse.etrice.core.room.ComplexType
+import org.eclipse.etrice.generator.base.IDataConfiguration
+import org.eclipse.etrice.generator.generic.ILanguageExtension
+import org.eclipse.etrice.generator.generic.ProcedureHelpers
+import org.eclipse.etrice.generator.generic.RoomExtensions
+import org.eclipse.etrice.generator.generic.TypeHelpers
+
+@Singleton
+class Initialization {
+
+ @Inject extension TypeHelpers
+ @Inject extension RoomExtensions
+ @Inject ILanguageExtension languageExt
+ @Inject IDataConfiguration dataConfigExt
+ @Inject ProcedureHelpers procedureHelpers
+
+ def attributeInitialization(List<Attribute> attribs, boolean useClassDefaultsOnly) {
+ '''
+ // initialize attributes
+ «FOR a : attribs»
+ «var aType = a.refType.type»
+ «var value = a.defaultValueLiteral»
+ «IF value!=null»
+ «IF a.size == 0 || aType.characterType»
+ «ELSEIF value.startsWith("{")»
+ «initializeArrayWithValues(a.name, value.replace("{", "").replace("}", "").split(","))»
+ «ELSE»
+ for (int i=0;i<«a.size»;i++){
+ «a.name»[i] = «value»;
+ }
+ «ENDIF»
+ «ELSEIF aType instanceof ComplexType || a.size>1 || !useClassDefaultsOnly»
+ «IF a.size==0»
+ «ELSE»
+ «IF !useClassDefaultsOnly»
+ for (int i=0;i<«a.size»;i++){
+ «a.name»[i] = «IF a.refType.isRef»«languageExt.nullPointer()»«ELSE»«languageExt.defaultValue(aType)»«ENDIF»;
+ }
+ «ENDIF»
+ «ENDIF»
+ «ENDIF»
+ «ENDFOR»
+ '''
+ }
+
+ def initializeArrayWithValues(String varName, String[] values) {
+ '''
+ «var i = -1»
+ «FOR v : values»
+ «varName»[«i=i+1»] = «v»;
+ «ENDFOR»
+ '''
+ }
+
+ def attributeInitialization(Attribute a, boolean useClassDefaultsOnly) {
+ var aType = a.refType.type
+ var value = a.defaultValueLiteral
+ if (value != null) {
+ if (a.size == 0 || aType.characterType) {
+ if (a.refType.isRef)
+ '''«a.name»(new «aType.name»(«value»))'''
+ else
+ '''«a.name»(«value»)'''
+ }
+ else if (value.startsWith("{")) {
+ '''«a.name»()'''
+ }
+ else {
+ '''«a.name»()'''
+ }
+ }
+ else if (aType instanceof ComplexType || a.size>1 || !useClassDefaultsOnly) {
+ if (a.size==0) {
+ if (a.refType.isRef)
+ '''«a.name»(«languageExt.nullPointer()»)'''
+ else
+ '''«a.name»(«languageExt.defaultValue(aType)»)'''
+ }
+ else
+ '''«a.name»()'''
+ }
+ }
+
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend
index d6b72e868..b15b11e28 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend
@@ -1,53 +1,53 @@
-/*******************************************************************************
- * 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.Inject
-import com.google.inject.Singleton
-import org.eclipse.emf.ecore.resource.Resource
-import org.eclipse.etrice.core.genmodel.etricegen.Root
-import org.eclipse.etrice.generator.generic.PrepareFileSystem
-import org.eclipse.xtext.generator.IFileSystemAccess
-import org.eclipse.xtext.generator.IGenerator
-
-@Singleton
-class MainGen implements IGenerator {
-
- @Inject DataClassGen dataClassGen
- @Inject ProtocolClassGen protocolClassGen
- @Inject ActorClassGen actorClassGen
- @Inject SubSystemClassGen subsystemClassGen
- @Inject SubSystemRunnerGen subsystemRunnerGen
- @Inject PrepareFileSystem prepFS
-
- override void doGenerate(Resource resource, IFileSystemAccess fsa) {
- prepFS.prepare(resource)
- for (e: resource.contents){
- if (e instanceof Root) {
- doGenerate(e as Root)
- }
- }
- }
-
- def void doGenerate(Root e) {
- dataClassGen.doGenerate(e);
- protocolClassGen.doGenerate(e);
- actorClassGen.doGenerate(e);
- subsystemClassGen.doGenerate(e);
-
- if (!e.library) {
- subsystemRunnerGen.doGenerate(e);
- }
- }
+/*******************************************************************************
+ * 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.Inject
+import com.google.inject.Singleton
+import org.eclipse.emf.ecore.resource.Resource
+import org.eclipse.etrice.core.genmodel.etricegen.Root
+import org.eclipse.etrice.generator.generic.PrepareFileSystem
+import org.eclipse.xtext.generator.IFileSystemAccess
+import org.eclipse.xtext.generator.IGenerator
+
+@Singleton
+class MainGen implements IGenerator {
+
+ @Inject DataClassGen dataClassGen
+ @Inject ProtocolClassGen protocolClassGen
+ @Inject ActorClassGen actorClassGen
+ @Inject SubSystemClassGen subsystemClassGen
+ @Inject SubSystemRunnerGen subsystemRunnerGen
+ @Inject PrepareFileSystem prepFS
+
+ override void doGenerate(Resource resource, IFileSystemAccess fsa) {
+ prepFS.prepare(resource)
+ for (e: resource.contents){
+ if (e instanceof Root) {
+ doGenerate(e as Root)
+ }
+ }
+ }
+
+ def void doGenerate(Root e) {
+ dataClassGen.doGenerate(e);
+ protocolClassGen.doGenerate(e);
+ actorClassGen.doGenerate(e);
+ subsystemClassGen.doGenerate(e);
+
+ if (!e.library) {
+ subsystemRunnerGen.doGenerate(e);
+ }
+ }
} \ No newline at end of file
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 d181aa99d..66249885d 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
@@ -1,444 +1,444 @@
-/*******************************************************************************
- * 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.inject.Inject
-import com.google.inject.Singleton
-import java.util.ArrayList
-import org.eclipse.etrice.core.genmodel.base.ILogger
-import org.eclipse.etrice.core.genmodel.etricegen.Root
-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.Port
-import org.eclipse.etrice.core.room.PrimitiveType
-import org.eclipse.etrice.core.room.ProtocolClass
-import org.eclipse.etrice.core.room.SAPRef
-import org.eclipse.etrice.core.room.SPPRef
-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.xtext.generator.JavaIoFileSystemAccess
-import org.eclipse.etrice.core.room.PortClass
-import org.eclipse.etrice.generator.cpp.GeneratorOptions
-import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
-
-/**
- * @author Peter Karlitschek
- *
- */
-@Singleton
-class ProtocolClassGen extends GenericProtocolClassGenerator {
-
- @Inject extension JavaIoFileSystemAccess fileAccess
- @Inject extension CppExtensions stdExt
- @Inject extension RoomExtensions roomExt
- @Inject extension ProcedureHelpers helpers
- @Inject extension TypeHelpers
- @Inject extension Initialization
- @Inject ILogger logger
-
- def doGenerate(Root root) {
- for (pc: root.usedProtocolClasses) {
- var path = pc.generationTargetPath+pc.getPath
-
- logger.logInfo("generating ProtocolClass header '"+pc.getCppHeaderFileName+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(pc.getCppHeaderFileName, root.generateHeaderFile(pc))
-
- logger.logInfo("generating ProtocolClass source '"+pc.getCppSourceFileName+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(pc.getCppSourceFileName, root.generateSourceFile(pc))
- }
- }
-
-
- def private generateHeaderFile(Root root, ProtocolClass pc) {'''
- /**
- * @author generated by eTrice
- *
- * Header File of ProtocolClass «pc.name»
- *
- */
-
- «generateIncludeGuardBegin(pc.name)»
-
- #include "platforms/generic/etDatatypes.h"
- #include "common/messaging/IRTObject.h"
- #include "common/modelbase/PortBase.h"
- #include "common/modelbase/InterfaceItemBase.h"
- #include "common/messaging/Address.h"
- #include "common/messaging/Message.h"
- #include <vector>
- #include <string>
-
- namespace etRuntime {
- class IEventReceiver;
-
- }
-
- «helpers.userCode(pc.userCode1)»
-
- «FOR dataClass : root.getReferencedDataClasses(pc)»
- #include "«dataClass.path»«dataClass.name».h"
- «ENDFOR»
-
- class «pc.name» {
- public:
- «IF pc.commType==CommunicationType::EVENT_DRIVEN» /* message IDs */
- «genMessageIDs(pc)»
- static bool isValidEvtID(int evtId) {
- return ((MSG_MIN < evtId) && (evtId < MSG_MAX));
- };
- static bool isValidOutgoingEvtID(int evtId) {
- return ((MSG_MIN < evtId) && (evtId < «IF pc.incomingMessages.size == 0»MSG_MAX«ELSE»IN_«pc.incomingMessages.get(0).name»«ENDIF»));
- };
- static bool isValidIncomingEvtID(int evtId) {
- return ((«IF pc.incomingMessages.size == 0»MSG_MAX«ELSE»IN_«pc.incomingMessages.get(0).name»«ENDIF» <= evtId) && (evtId < MSG_MAX));
- };
- static std::string getMessageString(int msg_id);
-
- private:
- static std::string s_messageStrings[];
- «ENDIF»
- «helpers.userCode(pc.userCode2)»
- };
-
- «portClassDeclaration(pc, false)»
- «portClassDeclaration(pc, true)»
- «generateIncludeGuardEnd(pc.name)»
- '''
- }
-
- def private portClassDeclaration(ProtocolClass pc, Boolean conj) {
- var pclass = pc.getPortClass(conj)
- var portClassName = pc.getPortClassName(conj)
- var replPortClassName = pc.getPortClassName(conj, true)
- '''
- //------------------------------------------------------------------------------------------------------------
- // «IF conj»conjugated «ENDIF»port class
- //------------------------------------------------------------------------------------------------------------
- class «portClassName» : public etRuntime::PortBase {
- «IF pclass!=null»
- «helpers.userCode(pclass.userCode)»
- «ENDIF»
- public:
- // constructors
- «portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
- «portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
-
- virtual void receive(etRuntime::Message* m);
- «IF pclass!=null»
- «helpers.attributes(pclass.attributes)»
- «helpers.operationsDeclaration(pclass.operations, portClassName)»
- «ENDIF»
-
- // outgoing messages
- «FOR m : pc.getAllMessages(conj)»
- «sendMessageDeclaration(m,conj)»
- «ENDFOR»
- };
-
- //------------------------------------------------------------------------------------------------------------
- // «IF conj»conjugated «ENDIF»replicated port class
- //------------------------------------------------------------------------------------------------------------
- class «replPortClassName» {
- private:
- int m_replication;
- «portClassName»* m_ports; //dynamic array used instead of vector to avoid copy construction
-
- public:
- «replPortClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<etRuntime::Address> addr, std::vector<etRuntime::Address> peerAddress);
- virtual ~«replPortClassName»() {};
-
- int getReplication() { return m_replication; }
- int getIndexOf(const etRuntime::InterfaceItemBase& ifitem){ return ifitem.getIdx(); }
- «portClassName» get(int i) {return m_ports[i];}
-
- «IF pc.commType==CommunicationType::EVENT_DRIVEN»
- // outgoing messages
- «FOR m : pc.getAllMessages(conj)»
- «sendMessageDeclaration(m,conj)»
- «ENDFOR»
- «ENDIF»
-
- };
- '''
- }
-
- def private generateSourceFile(Root root, ProtocolClass pc) {'''
- /**
- * @author generated by eTrice
- *
- * Source File of ProtocolClass «pc.name»
- *
- */
-
- #include "«pc.getCppHeaderFileName»"
- #include "common/debugging/DebuggingService.h"
- #include <iostream>
- «IF GeneratorOptions::useEtUnit»
- extern "C" {
- #include "etUnit.h"
- }
- «ENDIF»
-
- using namespace etRuntime;
-
- «helpers.userCode(pc.userCode3)»
-
- «IF pc.commType==CommunicationType::EVENT_DRIVEN»
- «helpers.userCode(pc.userCode2)»
-
- «portClassImplementation(pc, false)»
- «portClassImplementation(pc, true)»
-
- /*--------------------- debug helpers */
- «generateDebugHelpersImplementation(root, pc)»
- «ENDIF»
-
-
- '''
- }
-
-
- def portClassImplementation(ProtocolClass pc, Boolean conj) {
- var pclass = pc.getPortClass(conj)
- var portClassName = pc.getPortClassName(conj)
- var replPortClassName = pc.getPortClassName(conj, true)
- '''
- //------------------------------------------------------------------------------------------------------------
- // «IF conj»conjugated «ENDIF»port class
- //------------------------------------------------------------------------------------------------------------
-
- «portClassName»::«portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress, bool doRegistration)
- : «pclass.generateConstructorInitalizerList("0")»
- {
- «IF pclass!=null»«pclass.attributes.attributeInitialization(false)»«ENDIF»
- if (doRegistration) {
- DebuggingService::getInstance().addPortInstance(*this);
- }
- }
-
- «portClassName»::«portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, Address addr, Address peerAddress, bool doRegistration)
- : «pclass.generateConstructorInitalizerList("idx")»
- {
- «IF pclass!=null»«pclass.attributes.attributeInitialization(false)»«ENDIF»
- if (doRegistration) {
- DebuggingService::getInstance().addPortInstance(*this);
- }
- }
-
- void «portClassName»::receive(Message* msg) {
- if (! «pc.name»::«IF conj»isValidOutgoingEvtID«ELSE»isValidIncomingEvtID«ENDIF»(msg->getEvtId())) {
- std::cout << "unknown" << std::endl;
- }
- else {
- if (msg->hasDebugFlagSet()) { // TODO: model switch for activation of this flag
- DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), «pc.name»::getMessageString(msg->getEvtId()));
- }
-
- «IF pc.handlesReceive(conj)»
- switch (msg->getEvtId()) {
- «FOR hdlr : pc.getReceiveHandlers(conj)»
- case «pc.name»::«hdlr.msg.getCodeName()»:
- {
- «FOR command : hdlr.detailCode.commands»
- «command»
- «ENDFOR»
- }
- break;
- «ENDFOR»
- default:
- «ENDIF»
- getEventReceiver().receiveEvent(this, msg->getEvtId(), msg->getData());
- «IF pc.handlesReceive(conj)»
- break;
- }
- «ENDIF»
- }
- };
-
- «IF pclass!=null»
- «helpers.operationsImplementation(pclass.operations, portClassName)»
- «ENDIF»
-
- // sent messages
- «FOR m : pc.getAllMessages(conj)»
- «sendMessage(m, pc.name, portClassName, conj)»
- «ENDFOR»
-
- //------------------------------------------------------------------------------------------------------------
- // «IF conj»conjugated «ENDIF»replicated port class
- //------------------------------------------------------------------------------------------------------------
- «replPortClassName»::«replPortClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<Address> addr, std::vector<Address> peerAddress)
- : m_replication(addr.size()),
- m_ports()
- {
- char numstr[10]; // enough to hold all numbers up to 32-bits
-
- m_ports = reinterpret_cast<«portClassName»*> (new char[sizeof(«portClassName») * addr.size()]);
- for (int i = 0; i < m_replication; ++i) {
- snprintf(numstr, sizeof(numstr), "%d", i);
- //placement new to avoid copy construction, therefore no vector is used
- new (&m_ports[i]) «portClassName»(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]);
- }
- };
-
-
- // outgoing messages
- «FOR m : pc.getAllMessages(conj)»
- «messageSignatureDefinition(m, replPortClassName)»{
- for (int i=0; i<m_replication; ++i) {
- m_ports[i].«messageCall(m)»;
- }
- }
- «ENDFOR»
- '''
- }
-
- def generateConstructorInitalizerList(PortClass pc, String index) {
- var initializerList = new ArrayList<CharSequence>();
- initializerList.add('''PortBase(actor, parent, name, localId, «index», addr, peerAddress)''')
- if (pc != null) {
- for (attrib: pc.attributes) {
- initializerList.add(attrib.attributeInitialization(false))
- }
- }
- return
- '''
- «initializerList.join(',\n')»
- '''
- }
-
-
-
-
- def private messageCall(Message m) {
- '''«m.name»(«IF m.data!=null» «m.data.name»«ENDIF»)'''
- }
-
-
-
- def private generateDebugHelpersImplementation(Root root, ProtocolClass pc){'''
-
-««« TODO: make this optional or different for smaller footprint
- /* message names as strings for debugging (generate MSC) */
- std::string «pc.name»::s_messageStrings[]
- = {"MIN",
- «FOR m : pc.getAllOutgoingMessages()»
- "«m.name»",
- «ENDFOR»
- «FOR m : pc.getAllIncomingMessages()»
- "«m.name»",
- «ENDFOR»
- "MAX"};
-
- std::string «pc.name»::getMessageString(int msg_id) {
- if ((MSG_MIN < msg_id ) && ( msg_id < MSG_MAX )) {
- return s_messageStrings[msg_id];
- } else {
- // id out of range
- return "Message ID out of range";
- }
- }
-
- '''
- }
-
-
- def messageSignature(Message m) {
- '''«IF m.priv»private:«ELSE»public:«ENDIF» void «m.name»(«IF m.data!=null»«m.data.refType.type.typeName» «m.data.name»«ENDIF»)'''
- }
-
- def messageSignatureExplicit(Message m) {
- var dc = (m.data.refType.type as DataClass)
- '''public: void «m.name»(«IF dc.base!=null»«dc.base.typeName» _super, «ENDIF»«FOR a : dc.attributes SEPARATOR ", "»«a.refType.type.typeName»«IF a.size>1»[]«ENDIF» «a.name»«ENDFOR»)'''
- }
-
- def messageSignatureDefinition(Message m, String classPrefix) {
- '''void «classPrefix»::«m.name»(«IF m.data!=null»«m.data.refType.type.typeName» «m.data.name»«ENDIF»)'''
- }
-
- def messageSignatureExplicitDefinition(Message m, String classPrefix) {
- var dc = (m.data.refType.type as DataClass)
- '''void «classPrefix»::«m.name»(«IF dc.base!=null»«dc.base.typeName» _super, «ENDIF»«FOR a : dc.attributes SEPARATOR ", "»«a.refType.type.typeName»«IF a.size>1»[]«ENDIF» «a.name»«ENDFOR»)'''
- }
-
-// def messageCall(Message m) {
-// '''«m.name»(«IF m.data!=null» «m.data.name»«ENDIF»)'''
-// }
-
- def sendMessageDeclaration(Message m, boolean conj) {
- '''
- «messageSignature(m)»;
- «IF m.data!=null && m.data.refType.type instanceof DataClass»
- «messageSignatureExplicit(m)»;
- «ENDIF»
- '''
- }
-
- def sendMessage(Message m, String portClassName, String classPrefix, boolean conj) {
- var dir = if (conj) "IN" else "OUT"
- var hdlr = m.getSendHandler(conj)
- '''
- «messageSignatureDefinition(m, classPrefix)» {
- «IF hdlr!=null»
- «FOR command : hdlr.detailCode.commands» «command»
- «ENDFOR»
- «ELSE»
- DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- «portClassName»::getMessageString(«portClassName»::«dir»_«m.name»));
- if (getPeerAddress().isValid()){
- «IF m.data==null»getPeerMsgReceiver()->receive(new Message(getPeerAddress(), «portClassName»::«dir»_«m.name»));
- «ELSE»getPeerMsgReceiver()->receive(new Message(getPeerAddress(),«portClassName»::«dir»_«m.name»,
- reinterpret_cast<void*>(«IF (!m.data.refType.ref && !(m.data.refType.type instanceof PrimitiveType))»&«ENDIF»«m.data.name»),
- sizeof(«m.data.refType.type.typeName»)));
- «ENDIF»
- }
- «ENDIF»
- }
-
- «IF m.data!=null && m.data.refType.type instanceof DataClass»
- «messageSignatureExplicitDefinition(m, classPrefix)» {
- «m.name»(«m.data.refType.type.name»(«IF (m.data.refType.type as DataClass).base!=null»_super, «ENDIF»«FOR a : (m.data.refType.type as DataClass).attributes SEPARATOR ", "»«a.name»«ENDFOR»));
- }
- «ENDIF»
- '''
- //TODO derived data classes are not yet handled correctly
- }
-
- override getMessageID(Message msg, InterfaceItem item) {
- if (item instanceof Port) {
- var p = item as Port;
- var direction = if (p.isConjugated())"OUT_" else "IN_"
- return enumInUse(p.getProtocol().getName(), direction+msg.getName())
- }
- else if (item instanceof SAPRef) {
- var sap = item as SAPRef;
- return enumInUse(sap.getProtocol().getName(), "OUT_"+msg.getName())
- }
- else if (item instanceof SPPRef) {
- var spp = item as SPPRef;
- return enumInUse(spp.getProtocol().getName(), "IN_"+msg.getName())
- }
-
- return "unknown interface item";
- }
-
- def String enumInUse(String namespace, String member) {
- return namespace+"::"+member
- }
+/*******************************************************************************
+ * 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.inject.Inject
+import com.google.inject.Singleton
+import java.util.ArrayList
+import org.eclipse.etrice.core.genmodel.base.ILogger
+import org.eclipse.etrice.core.genmodel.etricegen.Root
+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.Port
+import org.eclipse.etrice.core.room.PrimitiveType
+import org.eclipse.etrice.core.room.ProtocolClass
+import org.eclipse.etrice.core.room.SAPRef
+import org.eclipse.etrice.core.room.SPPRef
+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.xtext.generator.JavaIoFileSystemAccess
+import org.eclipse.etrice.core.room.PortClass
+import org.eclipse.etrice.generator.cpp.GeneratorOptions
+import static extension org.eclipse.etrice.core.room.util.RoomHelpers.*
+
+/**
+ * @author Peter Karlitschek
+ *
+ */
+@Singleton
+class ProtocolClassGen extends GenericProtocolClassGenerator {
+
+ @Inject extension JavaIoFileSystemAccess fileAccess
+ @Inject extension CppExtensions stdExt
+ @Inject extension RoomExtensions roomExt
+ @Inject extension ProcedureHelpers helpers
+ @Inject extension TypeHelpers
+ @Inject extension Initialization
+ @Inject ILogger logger
+
+ def doGenerate(Root root) {
+ for (pc: root.usedProtocolClasses) {
+ var path = pc.generationTargetPath+pc.getPath
+
+ logger.logInfo("generating ProtocolClass header '"+pc.getCppHeaderFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(pc.getCppHeaderFileName, root.generateHeaderFile(pc))
+
+ logger.logInfo("generating ProtocolClass source '"+pc.getCppSourceFileName+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(pc.getCppSourceFileName, root.generateSourceFile(pc))
+ }
+ }
+
+
+ def private generateHeaderFile(Root root, ProtocolClass pc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * Header File of ProtocolClass «pc.name»
+ *
+ */
+
+ «generateIncludeGuardBegin(pc.name)»
+
+ #include "platforms/generic/etDatatypes.h"
+ #include "common/messaging/IRTObject.h"
+ #include "common/modelbase/PortBase.h"
+ #include "common/modelbase/InterfaceItemBase.h"
+ #include "common/messaging/Address.h"
+ #include "common/messaging/Message.h"
+ #include <vector>
+ #include <string>
+
+ namespace etRuntime {
+ class IEventReceiver;
+
+ }
+
+ «helpers.userCode(pc.userCode1)»
+
+ «FOR dataClass : root.getReferencedDataClasses(pc)»
+ #include "«dataClass.path»«dataClass.name».h"
+ «ENDFOR»
+
+ class «pc.name» {
+ public:
+ «IF pc.commType==CommunicationType::EVENT_DRIVEN» /* message IDs */
+ «genMessageIDs(pc)»
+ static bool isValidEvtID(int evtId) {
+ return ((MSG_MIN < evtId) && (evtId < MSG_MAX));
+ };
+ static bool isValidOutgoingEvtID(int evtId) {
+ return ((MSG_MIN < evtId) && (evtId < «IF pc.incomingMessages.size == 0»MSG_MAX«ELSE»IN_«pc.incomingMessages.get(0).name»«ENDIF»));
+ };
+ static bool isValidIncomingEvtID(int evtId) {
+ return ((«IF pc.incomingMessages.size == 0»MSG_MAX«ELSE»IN_«pc.incomingMessages.get(0).name»«ENDIF» <= evtId) && (evtId < MSG_MAX));
+ };
+ static std::string getMessageString(int msg_id);
+
+ private:
+ static std::string s_messageStrings[];
+ «ENDIF»
+ «helpers.userCode(pc.userCode2)»
+ };
+
+ «portClassDeclaration(pc, false)»
+ «portClassDeclaration(pc, true)»
+ «generateIncludeGuardEnd(pc.name)»
+ '''
+ }
+
+ def private portClassDeclaration(ProtocolClass pc, Boolean conj) {
+ var pclass = pc.getPortClass(conj)
+ var portClassName = pc.getPortClassName(conj)
+ var replPortClassName = pc.getPortClassName(conj, true)
+ '''
+ //------------------------------------------------------------------------------------------------------------
+ // «IF conj»conjugated «ENDIF»port class
+ //------------------------------------------------------------------------------------------------------------
+ class «portClassName» : public etRuntime::PortBase {
+ «IF pclass!=null»
+ «helpers.userCode(pclass.userCode)»
+ «ENDIF»
+ public:
+ // constructors
+ «portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
+ «portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);
+
+ virtual void receive(etRuntime::Message* m);
+ «IF pclass!=null»
+ «helpers.attributes(pclass.attributes)»
+ «helpers.operationsDeclaration(pclass.operations, portClassName)»
+ «ENDIF»
+
+ // outgoing messages
+ «FOR m : pc.getAllMessages(conj)»
+ «sendMessageDeclaration(m,conj)»
+ «ENDFOR»
+ };
+
+ //------------------------------------------------------------------------------------------------------------
+ // «IF conj»conjugated «ENDIF»replicated port class
+ //------------------------------------------------------------------------------------------------------------
+ class «replPortClassName» {
+ private:
+ int m_replication;
+ «portClassName»* m_ports; //dynamic array used instead of vector to avoid copy construction
+
+ public:
+ «replPortClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<etRuntime::Address> addr, std::vector<etRuntime::Address> peerAddress);
+ virtual ~«replPortClassName»() {};
+
+ int getReplication() { return m_replication; }
+ int getIndexOf(const etRuntime::InterfaceItemBase& ifitem){ return ifitem.getIdx(); }
+ «portClassName» get(int i) {return m_ports[i];}
+
+ «IF pc.commType==CommunicationType::EVENT_DRIVEN»
+ // outgoing messages
+ «FOR m : pc.getAllMessages(conj)»
+ «sendMessageDeclaration(m,conj)»
+ «ENDFOR»
+ «ENDIF»
+
+ };
+ '''
+ }
+
+ def private generateSourceFile(Root root, ProtocolClass pc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * Source File of ProtocolClass «pc.name»
+ *
+ */
+
+ #include "«pc.getCppHeaderFileName»"
+ #include "common/debugging/DebuggingService.h"
+ #include <iostream>
+ «IF GeneratorOptions::useEtUnit»
+ extern "C" {
+ #include "etUnit.h"
+ }
+ «ENDIF»
+
+ using namespace etRuntime;
+
+ «helpers.userCode(pc.userCode3)»
+
+ «IF pc.commType==CommunicationType::EVENT_DRIVEN»
+ «helpers.userCode(pc.userCode2)»
+
+ «portClassImplementation(pc, false)»
+ «portClassImplementation(pc, true)»
+
+ /*--------------------- debug helpers */
+ «generateDebugHelpersImplementation(root, pc)»
+ «ENDIF»
+
+
+ '''
+ }
+
+
+ def portClassImplementation(ProtocolClass pc, Boolean conj) {
+ var pclass = pc.getPortClass(conj)
+ var portClassName = pc.getPortClassName(conj)
+ var replPortClassName = pc.getPortClassName(conj, true)
+ '''
+ //------------------------------------------------------------------------------------------------------------
+ // «IF conj»conjugated «ENDIF»port class
+ //------------------------------------------------------------------------------------------------------------
+
+ «portClassName»::«portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress, bool doRegistration)
+ : «pclass.generateConstructorInitalizerList("0")»
+ {
+ «IF pclass!=null»«pclass.attributes.attributeInitialization(false)»«ENDIF»
+ if (doRegistration) {
+ DebuggingService::getInstance().addPortInstance(*this);
+ }
+ }
+
+ «portClassName»::«portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, Address addr, Address peerAddress, bool doRegistration)
+ : «pclass.generateConstructorInitalizerList("idx")»
+ {
+ «IF pclass!=null»«pclass.attributes.attributeInitialization(false)»«ENDIF»
+ if (doRegistration) {
+ DebuggingService::getInstance().addPortInstance(*this);
+ }
+ }
+
+ void «portClassName»::receive(Message* msg) {
+ if (! «pc.name»::«IF conj»isValidOutgoingEvtID«ELSE»isValidIncomingEvtID«ENDIF»(msg->getEvtId())) {
+ std::cout << "unknown" << std::endl;
+ }
+ else {
+ if (msg->hasDebugFlagSet()) { // TODO: model switch for activation of this flag
+ DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), «pc.name»::getMessageString(msg->getEvtId()));
+ }
+
+ «IF pc.handlesReceive(conj)»
+ switch (msg->getEvtId()) {
+ «FOR hdlr : pc.getReceiveHandlers(conj)»
+ case «pc.name»::«hdlr.msg.getCodeName()»:
+ {
+ «FOR command : hdlr.detailCode.commands»
+ «command»
+ «ENDFOR»
+ }
+ break;
+ «ENDFOR»
+ default:
+ «ENDIF»
+ getEventReceiver().receiveEvent(this, msg->getEvtId(), msg->getData());
+ «IF pc.handlesReceive(conj)»
+ break;
+ }
+ «ENDIF»
+ }
+ };
+
+ «IF pclass!=null»
+ «helpers.operationsImplementation(pclass.operations, portClassName)»
+ «ENDIF»
+
+ // sent messages
+ «FOR m : pc.getAllMessages(conj)»
+ «sendMessage(m, pc.name, portClassName, conj)»
+ «ENDFOR»
+
+ //------------------------------------------------------------------------------------------------------------
+ // «IF conj»conjugated «ENDIF»replicated port class
+ //------------------------------------------------------------------------------------------------------------
+ «replPortClassName»::«replPortClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector<Address> addr, std::vector<Address> peerAddress)
+ : m_replication(addr.size()),
+ m_ports()
+ {
+ char numstr[10]; // enough to hold all numbers up to 32-bits
+
+ m_ports = reinterpret_cast<«portClassName»*> (new char[sizeof(«portClassName») * addr.size()]);
+ for (int i = 0; i < m_replication; ++i) {
+ snprintf(numstr, sizeof(numstr), "%d", i);
+ //placement new to avoid copy construction, therefore no vector is used
+ new (&m_ports[i]) «portClassName»(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]);
+ }
+ };
+
+
+ // outgoing messages
+ «FOR m : pc.getAllMessages(conj)»
+ «messageSignatureDefinition(m, replPortClassName)»{
+ for (int i=0; i<m_replication; ++i) {
+ m_ports[i].«messageCall(m)»;
+ }
+ }
+ «ENDFOR»
+ '''
+ }
+
+ def generateConstructorInitalizerList(PortClass pc, String index) {
+ var initializerList = new ArrayList<CharSequence>();
+ initializerList.add('''PortBase(actor, parent, name, localId, «index», addr, peerAddress)''')
+ if (pc != null) {
+ for (attrib: pc.attributes) {
+ initializerList.add(attrib.attributeInitialization(false))
+ }
+ }
+ return
+ '''
+ «initializerList.join(',\n')»
+ '''
+ }
+
+
+
+
+ def private messageCall(Message m) {
+ '''«m.name»(«IF m.data!=null» «m.data.name»«ENDIF»)'''
+ }
+
+
+
+ def private generateDebugHelpersImplementation(Root root, ProtocolClass pc){'''
+
+««« TODO: make this optional or different for smaller footprint
+ /* message names as strings for debugging (generate MSC) */
+ std::string «pc.name»::s_messageStrings[]
+ = {"MIN",
+ «FOR m : pc.getAllOutgoingMessages()»
+ "«m.name»",
+ «ENDFOR»
+ «FOR m : pc.getAllIncomingMessages()»
+ "«m.name»",
+ «ENDFOR»
+ "MAX"};
+
+ std::string «pc.name»::getMessageString(int msg_id) {
+ if ((MSG_MIN < msg_id ) && ( msg_id < MSG_MAX )) {
+ return s_messageStrings[msg_id];
+ } else {
+ // id out of range
+ return "Message ID out of range";
+ }
+ }
+
+ '''
+ }
+
+
+ def messageSignature(Message m) {
+ '''«IF m.priv»private:«ELSE»public:«ENDIF» void «m.name»(«IF m.data!=null»«m.data.refType.type.typeName» «m.data.name»«ENDIF»)'''
+ }
+
+ def messageSignatureExplicit(Message m) {
+ var dc = (m.data.refType.type as DataClass)
+ '''public: void «m.name»(«IF dc.base!=null»«dc.base.typeName» _super, «ENDIF»«FOR a : dc.attributes SEPARATOR ", "»«a.refType.type.typeName»«IF a.size>1»[]«ENDIF» «a.name»«ENDFOR»)'''
+ }
+
+ def messageSignatureDefinition(Message m, String classPrefix) {
+ '''void «classPrefix»::«m.name»(«IF m.data!=null»«m.data.refType.type.typeName» «m.data.name»«ENDIF»)'''
+ }
+
+ def messageSignatureExplicitDefinition(Message m, String classPrefix) {
+ var dc = (m.data.refType.type as DataClass)
+ '''void «classPrefix»::«m.name»(«IF dc.base!=null»«dc.base.typeName» _super, «ENDIF»«FOR a : dc.attributes SEPARATOR ", "»«a.refType.type.typeName»«IF a.size>1»[]«ENDIF» «a.name»«ENDFOR»)'''
+ }
+
+// def messageCall(Message m) {
+// '''«m.name»(«IF m.data!=null» «m.data.name»«ENDIF»)'''
+// }
+
+ def sendMessageDeclaration(Message m, boolean conj) {
+ '''
+ «messageSignature(m)»;
+ «IF m.data!=null && m.data.refType.type instanceof DataClass»
+ «messageSignatureExplicit(m)»;
+ «ENDIF»
+ '''
+ }
+
+ def sendMessage(Message m, String portClassName, String classPrefix, boolean conj) {
+ var dir = if (conj) "IN" else "OUT"
+ var hdlr = m.getSendHandler(conj)
+ '''
+ «messageSignatureDefinition(m, classPrefix)» {
+ «IF hdlr!=null»
+ «FOR command : hdlr.detailCode.commands» «command»
+ «ENDFOR»
+ «ELSE»
+ DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
+ «portClassName»::getMessageString(«portClassName»::«dir»_«m.name»));
+ if (getPeerAddress().isValid()){
+ «IF m.data==null»getPeerMsgReceiver()->receive(new Message(getPeerAddress(), «portClassName»::«dir»_«m.name»));
+ «ELSE»getPeerMsgReceiver()->receive(new Message(getPeerAddress(),«portClassName»::«dir»_«m.name»,
+ reinterpret_cast<void*>(«IF (!m.data.refType.ref && !(m.data.refType.type instanceof PrimitiveType))»&«ENDIF»«m.data.name»),
+ sizeof(«m.data.refType.type.typeName»)));
+ «ENDIF»
+ }
+ «ENDIF»
+ }
+
+ «IF m.data!=null && m.data.refType.type instanceof DataClass»
+ «messageSignatureExplicitDefinition(m, classPrefix)» {
+ «m.name»(«m.data.refType.type.name»(«IF (m.data.refType.type as DataClass).base!=null»_super, «ENDIF»«FOR a : (m.data.refType.type as DataClass).attributes SEPARATOR ", "»«a.name»«ENDFOR»));
+ }
+ «ENDIF»
+ '''
+ //TODO derived data classes are not yet handled correctly
+ }
+
+ override getMessageID(Message msg, InterfaceItem item) {
+ if (item instanceof Port) {
+ var p = item as Port;
+ var direction = if (p.isConjugated())"OUT_" else "IN_"
+ return enumInUse(p.getProtocol().getName(), direction+msg.getName())
+ }
+ else if (item instanceof SAPRef) {
+ var sap = item as SAPRef;
+ return enumInUse(sap.getProtocol().getName(), "OUT_"+msg.getName())
+ }
+ else if (item instanceof SPPRef) {
+ var spp = item as SPPRef;
+ return enumInUse(spp.getProtocol().getName(), "IN_"+msg.getName())
+ }
+
+ return "unknown interface item";
+ }
+
+ def String enumInUse(String namespace, String member) {
+ return namespace+"::"+member
+ }
} \ No newline at end of file
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 c1f7c9eab..876eafbcb 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
@@ -1,89 +1,89 @@
-/*******************************************************************************
- * 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.Inject
-import com.google.inject.Singleton
-import java.util.ArrayList
-import org.eclipse.xtext.util.Pair
-import static org.eclipse.xtext.util.Tuples.*
-import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
-import org.eclipse.etrice.generator.generic.GenericStateMachineGenerator
-import org.eclipse.etrice.generator.generic.RoomExtensions
-
-import static extension org.eclipse.etrice.generator.base.CodegenHelpers.*
-
-/**
- * @author Peter Karlitschek
- *
- */
- @Singleton
-class StateMachineGen extends GenericStateMachineGenerator {
-
- @Inject extension RoomExtensions
- @Inject ProtocolClassGen cppProtGen
-
- override genExtraDecl(ExpandedActorClass xpac) {
-// val ac = xpac.actorClass
- '''
- protected:
- static std::string s_stateStrings[];
- static const int s_numberOfStates;
-
- private:
- void setState(int new_state);
- '''}
-
- override genExtra(ExpandedActorClass xpac) {
- val ac = xpac.actorClass
- '''
- std::string «ac.name»::s_stateStrings[] = {"<no state>","<top>",«FOR state : ac.getAllBaseStatesLeavesLast() SEPARATOR ","»"«state.genStatePathName»"
- «ENDFOR»};
- const int «ac.name»::s_numberOfStates = «ac.getAllBaseStatesLeavesLast().size + 2»;
-
- void «ac.name»::setState(int new_state) {
- DebuggingService::getInstance().addActorState(*this, s_stateStrings[new_state]);
- if (s_stateStrings[new_state]!="Idle") {
-««« TODOTS: model switch for activation
- std::cout << getInstancePath() << " -> " << s_stateStrings[new_state] << std::endl;
- }
- m_state = new_state;
- }
- '''}
-
- override genTriggerConstants(ExpandedActorClass xpac) {
- val triggers = if (langExt.usesInheritance)
- xpac.getOwnTriggers() else xpac.triggers
-
- val list = new ArrayList<Pair<String, String>>()
- list.add(pair("POLLING", "0"));
- for (mif : triggers) {
- list.add(pair(xpac.getTriggerCodeName(mif), "IFITEM_"+mif.from.name+" + EVT_SHIFT*"+cppProtGen.getMessageID(mif)))
- }
-
- return langExt.genEnumeration("triggers", list)
- }
-
- override constPointer(String classname) {
- return "const " + classname + "*"
- }
-
- override boolType() {
- return "bool"
- }
-
-
-
-
-}
+/*******************************************************************************
+ * 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.Inject
+import com.google.inject.Singleton
+import java.util.ArrayList
+import org.eclipse.xtext.util.Pair
+import static org.eclipse.xtext.util.Tuples.*
+import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
+import org.eclipse.etrice.generator.generic.GenericStateMachineGenerator
+import org.eclipse.etrice.generator.generic.RoomExtensions
+
+import static extension org.eclipse.etrice.generator.base.CodegenHelpers.*
+
+/**
+ * @author Peter Karlitschek
+ *
+ */
+ @Singleton
+class StateMachineGen extends GenericStateMachineGenerator {
+
+ @Inject extension RoomExtensions
+ @Inject ProtocolClassGen cppProtGen
+
+ override genExtraDecl(ExpandedActorClass xpac) {
+// val ac = xpac.actorClass
+ '''
+ protected:
+ static std::string s_stateStrings[];
+ static const int s_numberOfStates;
+
+ private:
+ void setState(int new_state);
+ '''}
+
+ override genExtra(ExpandedActorClass xpac) {
+ val ac = xpac.actorClass
+ '''
+ std::string «ac.name»::s_stateStrings[] = {"<no state>","<top>",«FOR state : ac.getAllBaseStatesLeavesLast() SEPARATOR ","»"«state.genStatePathName»"
+ «ENDFOR»};
+ const int «ac.name»::s_numberOfStates = «ac.getAllBaseStatesLeavesLast().size + 2»;
+
+ void «ac.name»::setState(int new_state) {
+ DebuggingService::getInstance().addActorState(*this, s_stateStrings[new_state]);
+ if (s_stateStrings[new_state]!="Idle") {
+««« TODOTS: model switch for activation
+ std::cout << getInstancePath() << " -> " << s_stateStrings[new_state] << std::endl;
+ }
+ m_state = new_state;
+ }
+ '''}
+
+ override genTriggerConstants(ExpandedActorClass xpac) {
+ val triggers = if (langExt.usesInheritance)
+ xpac.getOwnTriggers() else xpac.triggers
+
+ val list = new ArrayList<Pair<String, String>>()
+ list.add(pair("POLLING", "0"));
+ for (mif : triggers) {
+ list.add(pair(xpac.getTriggerCodeName(mif), "IFITEM_"+mif.from.name+" + EVT_SHIFT*"+cppProtGen.getMessageID(mif)))
+ }
+
+ return langExt.genEnumeration("triggers", list)
+ }
+
+ override constPointer(String classname) {
+ return "const " + classname + "*"
+ }
+
+ override boolType() {
+ return "bool"
+ }
+
+
+
+
+}
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.xtend
index 589294d7e..aee648035 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.xtend
@@ -1,302 +1,302 @@
-/*******************************************************************************
- * 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.inject.Inject
-import com.google.inject.Singleton
-import org.eclipse.etrice.core.genmodel.base.ILogger
-import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance
-import org.eclipse.etrice.core.genmodel.etricegen.Root
-import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
-import org.eclipse.etrice.core.room.SubSystemClass
-import org.eclipse.etrice.generator.generic.ProcedureHelpers
-import org.eclipse.etrice.generator.generic.RoomExtensions
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-
-import static extension org.eclipse.etrice.generator.base.Indexed.*
-import org.eclipse.etrice.generator.base.IDataConfiguration
-
-/**
- * @author Peter Karlitschek
- *
- */
-@Singleton
-class SubSystemClassGen {
-
- @Inject JavaIoFileSystemAccess fileAccess
- @Inject extension CppExtensions
- @Inject extension RoomExtensions
- @Inject extension ProcedureHelpers
- @Inject IDataConfiguration dataConfigExt
- @Inject ConfigGenAddon configGenAddon
- @Inject ConfigGenAddon configAddon
- @Inject ILogger logger
-
- def doGenerate(Root root) {
- for (ssi: root.subSystemInstances) {
- var path = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath
- var file = ssi.subSystemClass.getCppHeaderFileName
- logger.logInfo("generating SubSystemClass declaration: '"+file+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(file, root.generateHeaderFile(ssi, ssi.subSystemClass))
-
- file = ssi.subSystemClass.getCppSourceFileName
- logger.logInfo("generating SubSystemClass implementation: '"+file+"' in '"+path+"'")
- fileAccess.setOutputPath(path)
- fileAccess.generateFile(file, root.generateSourceFile(ssi, ssi.subSystemClass))
-
-// file = ssi.subSystemClass.getInstSourceFileName
-// logger.logInfo("generating SubSystemClass instance file: '"+file+"' in '"+path+"'")
-// fileAccess.setOutputPath(path)
-// fileAccess.generateFile(file, root.generateInstanceFile(ssi, ssi.subSystemClass))
-//
-// file = ssi.subSystemClass.getDispSourceFileName
-// logger.logInfo("generating SubSystemClass dispatcher file: '"+file+"' in '"+path+"'")
-// fileAccess.setOutputPath(path)
-// fileAccess.generateFile(file, root.generateDispatcherFile(ssi, ssi.subSystemClass))
- }
- }
-
- def generateHeaderFile(Root root, SubSystemInstance comp, SubSystemClass cc) {'''
-
- /**
- * @author generated by eTrice
- *
- * Header File of SubSystemClass «cc.name»
- *
- */
-
- «generateIncludeGuardBegin(cc.name)»
-
- #include "platforms/generic/etDatatypes.h"
- #include "common/messaging/IRTObject.h"
- #include "common/modelbase/PortBase.h"
- #include "common/modelbase/InterfaceItemBase.h"
- #include "common/modelbase/ActorClassBase.h"
- #include "common/modelbase/SubSystemClassBase.h"
- #include "common/messaging/Address.h"
- #include "common/messaging/IMessageReceiver.h"
- #include "common/debugging/DebuggingService.h"
- #include <string>
- #include <vector>
-
- «FOR model : root.getReferencedModels(cc)»
-««« #include "«model.name».h"
- «ENDFOR»
-
-
- «cc.userCode(1)»
-
- class «cc.name» : public etRuntime::SubSystemClassBase{
-
- «cc.userCode(2)»
-
- public:
- «cc.name»(IRTObject* parent, std::string name)
- : etRuntime::SubSystemClassBase(parent, name)
- {
- }
-
- virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data);
- virtual void instantiateMessageServices();
- virtual void instantiateActors();
-
- private:
- std::vector<etRuntime::MessageService*> m_msgServices;
- };
-
- «generateIncludeGuardEnd(cc.name)»
- '''
- }
-
- def generateSourceFile(Root root, SubSystemInstance comp, SubSystemClass cc) {'''
-
- /**
- * @author generated by eTrice
- *
- * Source File of SubsystemClass «cc.name»
- *
- */
-
- #include "«cc.getCppHeaderFileName»"
- #include "common/debugging/DebuggingService.h"
- #include "common/messaging/RTSystemServicesProtocol.h"
- «FOR ai : comp.allContainedInstances»
- #include "«ai.actorClass.path»«ai.actorClass.name».h"
- «ENDFOR»
- #include <iostream>
-
- using namespace etRuntime;
-
- void «cc.name»::receiveEvent(InterfaceItemBase* ifitem, int evt, void* data){
- }
-
- void «cc.name»::instantiateMessageServices(){
-
- m_msgServices.push_back( new MessageService(this, Address(0, 0, 0),"MessageService_Main") );
- «FOR thread : cc.threads»
- m_msgServices.push_back(new MessageService(this, Address(0, «cc.threads.indexOf(thread)+1», 0),"MessageService_«thread.name»", /* threadprio */ 0));
- «ENDFOR»
- for (std::vector<MessageService*>::iterator it=m_msgServices.begin(); it != m_msgServices.end(); ++it) {
- RTServices::getInstance().getMsgSvcCtrl().addMsgSvc( *(*it));
- }
- }
-
- void «cc.name»::instantiateActors(){
- // all addresses
- // Addresses for the Subsystem Systemport
- «FOR ai : comp.allContainedInstances.indexed(comp.maxObjId)»
- Address addr_item_SystemPort_«comp.allContainedInstances.indexOf(ai.value)»(0,0,«ai.index1»);
- «ENDFOR»
-
- «FOR ai : comp.allContainedInstances»
- // actor instance «ai.path» itself => Systemport Address
- // TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport)
- Address addr_item_«ai.path.getPathName()»(0,«ai.threadId»,«ai.objId»);
- // interface items of «ai.path»
- «FOR pi : ai.orderedIfItemInstances»
- «IF pi.replicated»
- «FOR peer : pi.peers»
- «var i = pi.peers.indexOf(peer)»
- Address addr_item_«pi.path.getPathName()»_«i»(0,«pi.threadId»,«pi.objId+i»);
- «ENDFOR»
- «ELSE»
- Address addr_item_«pi.path.getPathName()»(0,«ai.threadId»,«pi.objId»);
- «ENDIF»
- «ENDFOR»
- «ENDFOR»
-
- // instantiate all actor instances
- m_instances.reserve(«comp.allContainedInstances.size»);
- «FOR ai : comp.allContainedInstances»
- //----------------------------------------------------------------------------------------------
- // addresses for actor instance: «ai.name»
- //----------------------------------------------------------------------------------------------
- «generateOwnInterfaceItemAddresses(ai)»
- «generatePeerInterfaceItemAddresses(ai, comp)»
-
- m_instances[«comp.allContainedInstances.indexOf(ai)»] = new «ai.actorClass.name»(
- «IF ai.eContainer instanceof SubSystemInstance»
- this,
- «ELSE»
- m_instances[«comp.allContainedInstances.indexOf(ai.eContainer)»],
- «ENDIF»
- "«ai.name»",
- «ai.name»_ownInterfaceItemAddresses,
- «ai.name»_peerInterfaceItemAddresses
- );
- «ENDFOR»
-
-««« // apply instance attribute configurations
-««« «FOR ai : comp.allContainedInstances»
-««« «IF !(ai.configAttributes.empty && ai.getConfigPorts.empty)»
-««« {
-««« «ai.actorClass.name» inst = («ai.actorClass.name») instances[«comp.allContainedInstances.indexOf(ai)»];
-««« «configAddon.applyInstanceConfig("inst", ai.actorClass.name, ai.configAttributes)»
-««« «FOR portConfig : ai.configPorts»
-««« «configAddon.applyInstanceConfig(("inst."+portConfig.item.name.invokeGetter(ai.actorClass.name)), portConfig.item.portClassName, portConfig.attributes)»
-««« «ENDFOR»
-««« }
-««« «ENDIF»
-««« «ENDFOR»
-
- // apply instance attribute configurations
- «FOR ai: comp.allContainedInstances»
- «val cfg = configGenAddon.genActorInstanceConfig(ai, "inst")»
- «IF cfg.length>0»
- {
- «ai.actorClass.name» inst = («ai.actorClass.name») instances[«comp.allContainedInstances.indexOf(ai)»];
- «cfg»
- }
- «ENDIF»
- «ENDFOR»
-
- //----------------------------------------------------------------------------------------------
- // addresses for the subsystem system port
- //----------------------------------------------------------------------------------------------
-
- std::vector<Address> ownAddresses(«comp.allContainedInstances.size»);
- «FOR ai : comp.allContainedInstances»
- ownAddresses[«comp.allContainedInstances.indexOf(ai)»] = addr_item_SystemPort_«comp.allContainedInstances.indexOf(ai)»;
- «ENDFOR»
- std::vector<Address> peerAddresses(«comp.allContainedInstances.size»);
- «FOR ai : comp.allContainedInstances»
- peerAddresses[«comp.allContainedInstances.indexOf(ai)»] = addr_item_«ai.path.getPathName()»;
- «ENDFOR»
-
-
- // create the subsystem system port
- m_RTSystemPort = new RTSystemServicesProtocolConjPortRepl(*this, this, "RTSystemPort",
- 0, //local ID
- ownAddresses,
- peerAddresses);
-
- }
-
-
- '''
- }
- def generateOwnInterfaceItemAddresses(ActorInstance ai) '''
- std::vector<std::vector<Address> > «ai.name»_ownInterfaceItemAddresses;
-
- std::vector<Address> «ai.name»_actorInstanceAddresses(1);
- «ai.name»_actorInstanceAddresses[0] = addr_item_«ai.path.getPathName()»;
-
- «ai.name»_ownInterfaceItemAddresses.push_back(«ai.name»_actorInstanceAddresses);
- «FOR pi : ai.orderedIfItemInstances»
- «IF pi.replicated»
- «IF pi.peers.empty»
- std::vector<Address> «ai.name»_«pi.name»Addresses;
- «ELSE»
- std::vector<Address> «ai.name»_«pi.name»Addresses(«pi.peers.size»);
- «FOR peer : pi.peers»
- «ai.name»_«pi.name»Addresses[«pi.peers.indexOf(peer)»] = addr_item_«pi.path.getPathName()»_«pi.peers.indexOf(peer)»;
- «ENDFOR»
- «ENDIF»
- «ELSE»
- std::vector<Address> «ai.name»_«pi.name»Addresses(1);
- «ai.name»_«pi.name»Addresses[0] = addr_item_«pi.path.getPathName()»;
- «ENDIF»
- «ai.name»_ownInterfaceItemAddresses.push_back(«ai.name»_«pi.name»Addresses);
-
- «ENDFOR»
- '''
-
- def generatePeerInterfaceItemAddresses(ActorInstance ai, SubSystemInstance comp) '''
- std::vector<std::vector<Address> > «ai.name»_peerInterfaceItemAddresses;
-
- std::vector<Address> «ai.name»_systemPortAddresses(1);
- «ai.name»_systemPortAddresses[0] = addr_item_SystemPort_«comp.allContainedInstances.indexOf(ai)»;
-
- «ai.name»_peerInterfaceItemAddresses.push_back(«ai.name»_systemPortAddresses);
- «FOR pi : ai.orderedIfItemInstances »
- «IF pi.replicated && pi.peers.isEmpty»
- «ELSE»
- «IF pi.peers.empty»
- std::vector<Address> «ai.name»_«pi.name»PeerAddresses;
- «ELSE»
- std::vector<Address> «ai.name»_«pi.name»PeerAddresses(«pi.peers.size»);
- «FOR pp : pi.peers»
- «IF pp.replicated»
- «ai.name»_«pi.name»PeerAddresses[«pi.peers.indexOf(pp)»] = addr_item_«pp.path.getPathName()»_«pp.peers.indexOf(pi)»;
- «ELSE»
- «ai.name»_«pi.name»PeerAddresses[«pi.peers.indexOf(pp)»] = addr_item_«pp.path.getPathName()»;
- «ENDIF»
- «ENDFOR»
- «ENDIF»
- «ai.name»_peerInterfaceItemAddresses.push_back(«ai.name»_«pi.name»PeerAddresses);
- «ENDIF»
- «ENDFOR»
- '''
-
+/*******************************************************************************
+ * 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.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.etrice.core.genmodel.base.ILogger
+import org.eclipse.etrice.core.genmodel.etricegen.ActorInstance
+import org.eclipse.etrice.core.genmodel.etricegen.Root
+import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
+import org.eclipse.etrice.core.room.SubSystemClass
+import org.eclipse.etrice.generator.generic.ProcedureHelpers
+import org.eclipse.etrice.generator.generic.RoomExtensions
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+
+import static extension org.eclipse.etrice.generator.base.Indexed.*
+import org.eclipse.etrice.generator.base.IDataConfiguration
+
+/**
+ * @author Peter Karlitschek
+ *
+ */
+@Singleton
+class SubSystemClassGen {
+
+ @Inject JavaIoFileSystemAccess fileAccess
+ @Inject extension CppExtensions
+ @Inject extension RoomExtensions
+ @Inject extension ProcedureHelpers
+ @Inject IDataConfiguration dataConfigExt
+ @Inject ConfigGenAddon configGenAddon
+ @Inject ConfigGenAddon configAddon
+ @Inject ILogger logger
+
+ def doGenerate(Root root) {
+ for (ssi: root.subSystemInstances) {
+ var path = ssi.subSystemClass.generationTargetPath+ssi.subSystemClass.getPath
+ var file = ssi.subSystemClass.getCppHeaderFileName
+ logger.logInfo("generating SubSystemClass declaration: '"+file+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(file, root.generateHeaderFile(ssi, ssi.subSystemClass))
+
+ file = ssi.subSystemClass.getCppSourceFileName
+ logger.logInfo("generating SubSystemClass implementation: '"+file+"' in '"+path+"'")
+ fileAccess.setOutputPath(path)
+ fileAccess.generateFile(file, root.generateSourceFile(ssi, ssi.subSystemClass))
+
+// file = ssi.subSystemClass.getInstSourceFileName
+// logger.logInfo("generating SubSystemClass instance file: '"+file+"' in '"+path+"'")
+// fileAccess.setOutputPath(path)
+// fileAccess.generateFile(file, root.generateInstanceFile(ssi, ssi.subSystemClass))
+//
+// file = ssi.subSystemClass.getDispSourceFileName
+// logger.logInfo("generating SubSystemClass dispatcher file: '"+file+"' in '"+path+"'")
+// fileAccess.setOutputPath(path)
+// fileAccess.generateFile(file, root.generateDispatcherFile(ssi, ssi.subSystemClass))
+ }
+ }
+
+ def generateHeaderFile(Root root, SubSystemInstance comp, SubSystemClass cc) {'''
+
+ /**
+ * @author generated by eTrice
+ *
+ * Header File of SubSystemClass «cc.name»
+ *
+ */
+
+ «generateIncludeGuardBegin(cc.name)»
+
+ #include "platforms/generic/etDatatypes.h"
+ #include "common/messaging/IRTObject.h"
+ #include "common/modelbase/PortBase.h"
+ #include "common/modelbase/InterfaceItemBase.h"
+ #include "common/modelbase/ActorClassBase.h"
+ #include "common/modelbase/SubSystemClassBase.h"
+ #include "common/messaging/Address.h"
+ #include "common/messaging/IMessageReceiver.h"
+ #include "common/debugging/DebuggingService.h"
+ #include <string>
+ #include <vector>
+
+ «FOR model : root.getReferencedModels(cc)»
+««« #include "«model.name».h"
+ «ENDFOR»
+
+
+ «cc.userCode(1)»
+
+ class «cc.name» : public etRuntime::SubSystemClassBase{
+
+ «cc.userCode(2)»
+
+ public:
+ «cc.name»(IRTObject* parent, std::string name)
+ : etRuntime::SubSystemClassBase(parent, name)
+ {
+ }
+
+ virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data);
+ virtual void instantiateMessageServices();
+ virtual void instantiateActors();
+
+ private:
+ std::vector<etRuntime::MessageService*> m_msgServices;
+ };
+
+ «generateIncludeGuardEnd(cc.name)»
+ '''
+ }
+
+ def generateSourceFile(Root root, SubSystemInstance comp, SubSystemClass cc) {'''
+
+ /**
+ * @author generated by eTrice
+ *
+ * Source File of SubsystemClass «cc.name»
+ *
+ */
+
+ #include "«cc.getCppHeaderFileName»"
+ #include "common/debugging/DebuggingService.h"
+ #include "common/messaging/RTSystemServicesProtocol.h"
+ «FOR ai : comp.allContainedInstances»
+ #include "«ai.actorClass.path»«ai.actorClass.name».h"
+ «ENDFOR»
+ #include <iostream>
+
+ using namespace etRuntime;
+
+ void «cc.name»::receiveEvent(InterfaceItemBase* ifitem, int evt, void* data){
+ }
+
+ void «cc.name»::instantiateMessageServices(){
+
+ m_msgServices.push_back( new MessageService(this, Address(0, 0, 0),"MessageService_Main") );
+ «FOR thread : cc.threads»
+ m_msgServices.push_back(new MessageService(this, Address(0, «cc.threads.indexOf(thread)+1», 0),"MessageService_«thread.name»", /* threadprio */ 0));
+ «ENDFOR»
+ for (std::vector<MessageService*>::iterator it=m_msgServices.begin(); it != m_msgServices.end(); ++it) {
+ RTServices::getInstance().getMsgSvcCtrl().addMsgSvc( *(*it));
+ }
+ }
+
+ void «cc.name»::instantiateActors(){
+ // all addresses
+ // Addresses for the Subsystem Systemport
+ «FOR ai : comp.allContainedInstances.indexed(comp.maxObjId)»
+ Address addr_item_SystemPort_«comp.allContainedInstances.indexOf(ai.value)»(0,0,«ai.index1»);
+ «ENDFOR»
+
+ «FOR ai : comp.allContainedInstances»
+ // actor instance «ai.path» itself => Systemport Address
+ // TODOTJ: For each Actor, multiple addresses should be generated (actor?, systemport, debugport)
+ Address addr_item_«ai.path.getPathName()»(0,«ai.threadId»,«ai.objId»);
+ // interface items of «ai.path»
+ «FOR pi : ai.orderedIfItemInstances»
+ «IF pi.replicated»
+ «FOR peer : pi.peers»
+ «var i = pi.peers.indexOf(peer)»
+ Address addr_item_«pi.path.getPathName()»_«i»(0,«pi.threadId»,«pi.objId+i»);
+ «ENDFOR»
+ «ELSE»
+ Address addr_item_«pi.path.getPathName()»(0,«ai.threadId»,«pi.objId»);
+ «ENDIF»
+ «ENDFOR»
+ «ENDFOR»
+
+ // instantiate all actor instances
+ m_instances.reserve(«comp.allContainedInstances.size»);
+ «FOR ai : comp.allContainedInstances»
+ //----------------------------------------------------------------------------------------------
+ // addresses for actor instance: «ai.name»
+ //----------------------------------------------------------------------------------------------
+ «generateOwnInterfaceItemAddresses(ai)»
+ «generatePeerInterfaceItemAddresses(ai, comp)»
+
+ m_instances[«comp.allContainedInstances.indexOf(ai)»] = new «ai.actorClass.name»(
+ «IF ai.eContainer instanceof SubSystemInstance»
+ this,
+ «ELSE»
+ m_instances[«comp.allContainedInstances.indexOf(ai.eContainer)»],
+ «ENDIF»
+ "«ai.name»",
+ «ai.name»_ownInterfaceItemAddresses,
+ «ai.name»_peerInterfaceItemAddresses
+ );
+ «ENDFOR»
+
+««« // apply instance attribute configurations
+««« «FOR ai : comp.allContainedInstances»
+««« «IF !(ai.configAttributes.empty && ai.getConfigPorts.empty)»
+««« {
+««« «ai.actorClass.name» inst = («ai.actorClass.name») instances[«comp.allContainedInstances.indexOf(ai)»];
+««« «configAddon.applyInstanceConfig("inst", ai.actorClass.name, ai.configAttributes)»
+««« «FOR portConfig : ai.configPorts»
+««« «configAddon.applyInstanceConfig(("inst."+portConfig.item.name.invokeGetter(ai.actorClass.name)), portConfig.item.portClassName, portConfig.attributes)»
+««« «ENDFOR»
+««« }
+««« «ENDIF»
+««« «ENDFOR»
+
+ // apply instance attribute configurations
+ «FOR ai: comp.allContainedInstances»
+ «val cfg = configGenAddon.genActorInstanceConfig(ai, "inst")»
+ «IF cfg.length>0»
+ {
+ «ai.actorClass.name» inst = («ai.actorClass.name») instances[«comp.allContainedInstances.indexOf(ai)»];
+ «cfg»
+ }
+ «ENDIF»
+ «ENDFOR»
+
+ //----------------------------------------------------------------------------------------------
+ // addresses for the subsystem system port
+ //----------------------------------------------------------------------------------------------
+
+ std::vector<Address> ownAddresses(«comp.allContainedInstances.size»);
+ «FOR ai : comp.allContainedInstances»
+ ownAddresses[«comp.allContainedInstances.indexOf(ai)»] = addr_item_SystemPort_«comp.allContainedInstances.indexOf(ai)»;
+ «ENDFOR»
+ std::vector<Address> peerAddresses(«comp.allContainedInstances.size»);
+ «FOR ai : comp.allContainedInstances»
+ peerAddresses[«comp.allContainedInstances.indexOf(ai)»] = addr_item_«ai.path.getPathName()»;
+ «ENDFOR»
+
+
+ // create the subsystem system port
+ m_RTSystemPort = new RTSystemServicesProtocolConjPortRepl(*this, this, "RTSystemPort",
+ 0, //local ID
+ ownAddresses,
+ peerAddresses);
+
+ }
+
+
+ '''
+ }
+ def generateOwnInterfaceItemAddresses(ActorInstance ai) '''
+ std::vector<std::vector<Address> > «ai.name»_ownInterfaceItemAddresses;
+
+ std::vector<Address> «ai.name»_actorInstanceAddresses(1);
+ «ai.name»_actorInstanceAddresses[0] = addr_item_«ai.path.getPathName()»;
+
+ «ai.name»_ownInterfaceItemAddresses.push_back(«ai.name»_actorInstanceAddresses);
+ «FOR pi : ai.orderedIfItemInstances»
+ «IF pi.replicated»
+ «IF pi.peers.empty»
+ std::vector<Address> «ai.name»_«pi.name»Addresses;
+ «ELSE»
+ std::vector<Address> «ai.name»_«pi.name»Addresses(«pi.peers.size»);
+ «FOR peer : pi.peers»
+ «ai.name»_«pi.name»Addresses[«pi.peers.indexOf(peer)»] = addr_item_«pi.path.getPathName()»_«pi.peers.indexOf(peer)»;
+ «ENDFOR»
+ «ENDIF»
+ «ELSE»
+ std::vector<Address> «ai.name»_«pi.name»Addresses(1);
+ «ai.name»_«pi.name»Addresses[0] = addr_item_«pi.path.getPathName()»;
+ «ENDIF»
+ «ai.name»_ownInterfaceItemAddresses.push_back(«ai.name»_«pi.name»Addresses);
+
+ «ENDFOR»
+ '''
+
+ def generatePeerInterfaceItemAddresses(ActorInstance ai, SubSystemInstance comp) '''
+ std::vector<std::vector<Address> > «ai.name»_peerInterfaceItemAddresses;
+
+ std::vector<Address> «ai.name»_systemPortAddresses(1);
+ «ai.name»_systemPortAddresses[0] = addr_item_SystemPort_«comp.allContainedInstances.indexOf(ai)»;
+
+ «ai.name»_peerInterfaceItemAddresses.push_back(«ai.name»_systemPortAddresses);
+ «FOR pi : ai.orderedIfItemInstances »
+ «IF pi.replicated && pi.peers.isEmpty»
+ «ELSE»
+ «IF pi.peers.empty»
+ std::vector<Address> «ai.name»_«pi.name»PeerAddresses;
+ «ELSE»
+ std::vector<Address> «ai.name»_«pi.name»PeerAddresses(«pi.peers.size»);
+ «FOR pp : pi.peers»
+ «IF pp.replicated»
+ «ai.name»_«pi.name»PeerAddresses[«pi.peers.indexOf(pp)»] = addr_item_«pp.path.getPathName()»_«pp.peers.indexOf(pi)»;
+ «ELSE»
+ «ai.name»_«pi.name»PeerAddresses[«pi.peers.indexOf(pp)»] = addr_item_«pp.path.getPathName()»;
+ «ENDIF»
+ «ENDFOR»
+ «ENDIF»
+ «ai.name»_peerInterfaceItemAddresses.push_back(«ai.name»_«pi.name»PeerAddresses);
+ «ENDIF»
+ «ENDFOR»
+ '''
+
} \ No newline at end of file
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.xtend
index 5393e23e1..18f9c60a7 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.xtend
@@ -1,93 +1,93 @@
-/*******************************************************************************
- * 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.inject.Inject
-import com.google.inject.Singleton
-import org.eclipse.etrice.core.room.SubSystemClass
-import org.eclipse.etrice.core.genmodel.etricegen.Root
-import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
-import org.eclipse.xtext.generator.JavaIoFileSystemAccess
-import org.eclipse.etrice.generator.generic.RoomExtensions
-
-/**
- * @author Peter Karlitschek
- *
- */
-@Singleton
-class SubSystemRunnerGen {
-
- @Inject extension JavaIoFileSystemAccess fileAccess
- @Inject extension CppExtensions
- @Inject extension RoomExtensions roomExt
-
- def doGenerate(Root root) {
- for (sc: root.subSystemInstances) {
- fileAccess.setOutputPath(sc.subSystemClass.generationTargetPath+sc.subSystemClass.getPath)
- fileAccess.generateFile( sc.subSystemClass.name+"_Runner.h", root.generateHeaderFile(sc, sc.subSystemClass))
-
- fileAccess.setOutputPath(sc.subSystemClass.generationTargetPath+sc.subSystemClass.getPath)
- fileAccess.generateFile( sc.subSystemClass.name+"_Runner.cpp", root.generateSourceFile(sc, sc.subSystemClass))
- }
- }
-
- def generateHeaderFile(Root root, SubSystemInstance ssc, SubSystemClass cc) {'''
- /**
- * @author generated by eTrice
- *
- * this class contains the main function running component «cc.name»
- * it instantiates «cc.name» and starts and ends the lifecycle
- */
-
- «generateIncludeGuardBegin(cc.name+"_Runner")»
-
- #include "common/modelbase/SubSystemRunnerBase.h"
-
- class «cc.name+"Runner"» :public etRuntime::SubSystemRunnerBase {
-
- };
-
- «generateIncludeGuardEnd(cc.name+"_Runner")»
- '''
- }
-
- def generateSourceFile(Root root, SubSystemInstance ssi, SubSystemClass ssc) {'''
- /**
- * @author generated by eTrice
- *
- * this class contains the main function running component «ssc.name»
- * it instantiates «ssc.name» and starts and ends the lifecycle
- */
-
-
- #include "«ssc.name».h"
- #include "«ssc.name»_Runner.h"
-
- #include <iostream>
-
-
- /**
- * main function
- * creates component and starts and stops the lifecycle
- */
-
-
- int main(int argc, char* argv[]) {
- «ssc.name» mainComponent(0, "«ssc.name»");
- «ssc.name+"Runner"»::run(mainComponent, argc, argv);
- return 0;
- }
-
-
- '''
- }
+/*******************************************************************************
+ * 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.inject.Inject
+import com.google.inject.Singleton
+import org.eclipse.etrice.core.room.SubSystemClass
+import org.eclipse.etrice.core.genmodel.etricegen.Root
+import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
+import org.eclipse.xtext.generator.JavaIoFileSystemAccess
+import org.eclipse.etrice.generator.generic.RoomExtensions
+
+/**
+ * @author Peter Karlitschek
+ *
+ */
+@Singleton
+class SubSystemRunnerGen {
+
+ @Inject extension JavaIoFileSystemAccess fileAccess
+ @Inject extension CppExtensions
+ @Inject extension RoomExtensions roomExt
+
+ def doGenerate(Root root) {
+ for (sc: root.subSystemInstances) {
+ fileAccess.setOutputPath(sc.subSystemClass.generationTargetPath+sc.subSystemClass.getPath)
+ fileAccess.generateFile( sc.subSystemClass.name+"_Runner.h", root.generateHeaderFile(sc, sc.subSystemClass))
+
+ fileAccess.setOutputPath(sc.subSystemClass.generationTargetPath+sc.subSystemClass.getPath)
+ fileAccess.generateFile( sc.subSystemClass.name+"_Runner.cpp", root.generateSourceFile(sc, sc.subSystemClass))
+ }
+ }
+
+ def generateHeaderFile(Root root, SubSystemInstance ssc, SubSystemClass cc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * this class contains the main function running component «cc.name»
+ * it instantiates «cc.name» and starts and ends the lifecycle
+ */
+
+ «generateIncludeGuardBegin(cc.name+"_Runner")»
+
+ #include "common/modelbase/SubSystemRunnerBase.h"
+
+ class «cc.name+"Runner"» :public etRuntime::SubSystemRunnerBase {
+
+ };
+
+ «generateIncludeGuardEnd(cc.name+"_Runner")»
+ '''
+ }
+
+ def generateSourceFile(Root root, SubSystemInstance ssi, SubSystemClass ssc) {'''
+ /**
+ * @author generated by eTrice
+ *
+ * this class contains the main function running component «ssc.name»
+ * it instantiates «ssc.name» and starts and ends the lifecycle
+ */
+
+
+ #include "«ssc.name».h"
+ #include "«ssc.name»_Runner.h"
+
+ #include <iostream>
+
+
+ /**
+ * main function
+ * creates component and starts and stops the lifecycle
+ */
+
+
+ int main(int argc, char* argv[]) {
+ «ssc.name» mainComponent(0, "«ssc.name»");
+ «ssc.name+"Runner"»::run(mainComponent, argc, argv);
+ return 0;
+ }
+
+
+ '''
+ }
} \ No newline at end of file
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 0a6a77ef3..1c98dda47 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
@@ -1,49 +1,49 @@
-/*******************************************************************************
- * 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)
- *
- *******************************************************************************/
-
-package org.eclipse.etrice.generator.cpp.gen;
-
-import org.eclipse.etrice.core.genmodel.etricegen.Root;
-import org.eclipse.etrice.core.genmodel.base.ILogger;
-
-import com.google.inject.Inject;
-
-/**
- * @author Henrik Rentz-Reichert
- *
- */
-public class Validator {
-
- @Inject
- private ILogger logger;
-
- public boolean validate(Root genModel) {
-
-// currently unused
-
- int errorCount = 0;
-// for (RoomModel mdl : genModel.getUsedRoomModels()) {
-// TreeIterator<EObject> it = mdl.eAllContents();
-// while (it.hasNext()) {
-// EObject obj = it.next();
-//
-// }
-// }
-
- if (errorCount>0) {
- logger.logError("C++ generator detected "+errorCount+" error(s) - terminating", null);
- return false;
- }
-
- return true;
- }
-}
+/*******************************************************************************
+ * 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)
+ *
+ *******************************************************************************/
+
+package org.eclipse.etrice.generator.cpp.gen;
+
+import org.eclipse.etrice.core.genmodel.etricegen.Root;
+import org.eclipse.etrice.core.genmodel.base.ILogger;
+
+import com.google.inject.Inject;
+
+/**
+ * @author Henrik Rentz-Reichert
+ *
+ */
+public class Validator {
+
+ @Inject
+ private ILogger logger;
+
+ public boolean validate(Root genModel) {
+
+// currently unused
+
+ int errorCount = 0;
+// for (RoomModel mdl : genModel.getUsedRoomModels()) {
+// TreeIterator<EObject> it = mdl.eAllContents();
+// while (it.hasNext()) {
+// EObject obj = it.next();
+//
+// }
+// }
+
+ if (errorCount>0) {
+ logger.logError("C++ generator detected "+errorCount+" error(s) - terminating", null);
+ return false;
+ }
+
+ return true;
+ }
+}

Back to the top