From 71f2c21f0b278fa2bdc39ce9ac5669c39a8e9200 Mon Sep 17 00:00:00 2001 From: Peter Karlitschek Date: Wed, 5 Dec 2012 09:49:33 +0100 Subject: timing service for cpp generator I01e6dbef030587721bcd6a8e689ce8c2f36b1386--- .../etrice/generator/c/gen/CExtensions.xtend | 4 + .../etrice/generator/c/gen/CExtensions.java | 4 + .../etrice/generator/cpp/gen/ActorClassGen.xtend | 21 +-- .../etrice/generator/cpp/gen/CppExtensions.xtend | 50 ++---- .../etrice/generator/cpp/gen/DataClassGen.xtend | 17 +++ .../etrice/generator/cpp/gen/Initialization.xtend | 46 ++++-- .../generator/cpp/gen/ProtocolClassGen.xtend | 64 +++++--- .../generator/cpp/gen/SubSystemClassGen.xtend | 4 +- .../etrice/generator/cpp/gen/ConfigGenAddon.smap | 94 ++++++++++++ .../etrice/generator/cpp/gen/CppExtensions.java | 47 +++--- .../etrice/generator/cpp/gen/DataClassGen.java | 126 +++++++++++++--- .../eclipse/etrice/generator/cpp/gen/MainGen.smap | 22 +++ .../etrice/generator/cpp/gen/ProtocolClassGen.java | 126 +++++++++++++--- .../etrice/generator/cpp/gen/StateMachineGen.smap | 47 ++++++ .../generator/cpp/gen/SubSystemClassGen.smap | 167 +++++++++++++++++++++ .../generator/cpp/gen/SubSystemRunnerGen.smap | 31 ++++ .../etrice/generator/java/gen/JavaExtensions.xtend | 4 + .../etrice/generator/java/gen/JavaExtensions.java | 4 + .../generic/GenericStateMachineGenerator.xtend | 12 +- .../generator/generic/ILanguageExtension.java | 9 +- .../generic/GenericStateMachineGenerator.java | 32 ++-- runtime/org.eclipse.etrice.modellib.cpp/.cproject | 4 +- .../model/TimingService.room | 4 +- .../room/basic/service/timing/ATimingService.cpp | 29 ++-- .../room/basic/service/timing/ATimingService.h | 4 +- .../src-gen/room/basic/service/timing/PTimer.cpp | 58 ++++--- .../src-gen/room/basic/service/timing/PTimer.h | 16 +- runtime/org.eclipse.etrice.runtime.cpp/.cproject | 5 +- .../src/common/debugging/DebuggingService.cpp | 2 + .../src/common/messaging/Address.cpp | 18 ++- .../src/common/messaging/Address.h | 9 +- .../src/common/messaging/MessageDispatcher.cpp | 1 + .../src/common/messaging/MessageDispatcher.h | 1 + .../src/common/messaging/MessageService.cpp | 17 ++- .../src/common/messaging/MessageService.h | 8 + .../common/messaging/MessageServiceController.cpp | 2 +- .../common/messaging/MessageServiceController.h | 3 + .../common/messaging/RTSystemServicesProtocol.cpp | 60 +++++--- .../common/messaging/RTSystemServicesProtocol.h | 17 ++- .../src/common/modelbase/ActorClassBase.cpp | 6 +- .../src/common/modelbase/ActorClassBase.h | 2 +- .../src/common/modelbase/IEventReceiver.h | 2 +- .../src/common/modelbase/SubSystemRunnerBase.cpp | 8 +- .../src/common/platform/etTimer.h | 6 + .../src/platforms/generic/etTimer.c | 39 ----- 45 files changed, 952 insertions(+), 300 deletions(-) create mode 100644 plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.smap create mode 100644 plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/MainGen.smap create mode 100644 plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.smap create mode 100644 plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.smap create mode 100644 plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.smap delete mode 100644 runtime/org.eclipse.etrice.runtime.cpp/src/platforms/generic/etTimer.c diff --git a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend index cb217c6d5..083bc841d 100644 --- a/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend +++ b/plugins/org.eclipse.etrice.generator.c/src/org/eclipse/etrice/generator/c/gen/CExtensions.xtend @@ -110,6 +110,10 @@ class CExtensions implements ILanguageExtension { return false } + override boolean usesPointers() { + return true + } + override String genEnumeration(String name, List> entries) { if (entries.empty) return "/* empty enum not generated */" diff --git a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java index a25ace5e9..24edb4ef4 100644 --- a/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java +++ b/plugins/org.eclipse.etrice.generator.c/xtend-gen/org/eclipse/etrice/generator/c/gen/CExtensions.java @@ -150,6 +150,10 @@ public class CExtensions implements ILanguageExtension { return false; } + public boolean usesPointers() { + return true; + } + public String genEnumeration(final String name, final List> entries) { String _xblockexpression = null; { 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 f24cc83b3..d87388e0a 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 @@ -13,11 +13,10 @@ 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.etrice.generator.cpp.gen.Initialization -import org.eclipse.etrice.generator.cpp.gen.StateMachineGen import org.eclipse.xtext.generator.JavaIoFileSystemAccess import static extension org.eclipse.etrice.core.room.util.RoomHelpers.* +import org.eclipse.etrice.core.room.ActorCommunicationType @Singleton class ActorClassGen extends GenericActorClassGenerator { @@ -133,7 +132,7 @@ class ActorClassGen extends GenericActorClassGenerator { «ELSEIF !xpac.hasStateMachine()» public: //--------------------- no state machine - virtual void receiveEvent(const etRuntime::InterfaceItemBase& ifitem, int evt, void* data); + virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data); virtual void executeInitTransition(); «ENDIF» @@ -165,6 +164,9 @@ class ActorClassGen extends GenericActorClassGenerator { 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')» @@ -175,6 +177,7 @@ class ActorClassGen extends GenericActorClassGenerator { def 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 ''' /** @@ -196,14 +199,14 @@ class ActorClassGen extends GenericActorClassGenerator { : «ac.generateConstructorInitalizerList» { setClassName("«ac.name»"); - ««« TODO change to constructor initializer list «ac.attributes.attributeInitialization(false)» + «IF async» + getMsgsvc()->addAsyncActor(*this); + «ENDIF» «IF ctor!=null» - { - // user defined constructor body - «AbstractGenerator::getInstance().getTranslatedCode(ctor.detailCode)» - } + // user defined constructor body + «AbstractGenerator::getInstance().getTranslatedCode(ctor.detailCode)» «ENDIF» } @@ -233,7 +236,7 @@ class ActorClassGen extends GenericActorClassGenerator { «xpac.genStateMachine(false)» «ELSEIF !xpac.hasStateMachine()» //--------------------- no state machine - void «ac.name»::receiveEvent(const etRuntime::InterfaceItemBase& ifitem, int evt, void* data) { + void «ac.name»::receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data) { handleSystemEvent(ifitem, evt, data); } diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/CppExtensions.xtend index 0da6b4bb0..69ff87af4 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 @@ -75,6 +75,10 @@ class CppExtensions implements ILanguageExtension { return true } + override boolean usesPointers() { + return true + } + override String genEnumeration(String name, List> entries) { ''' typedef enum { @@ -93,7 +97,7 @@ class CppExtensions implements ILanguageExtension { override String voidPointer() { "void*" } override String arrayDeclaration(String type, int size, String name, boolean isRef) { - type+" "+name+"[]"; + type+" "+name+"["+size+"]"; } override String constructorName(String cls) { @@ -135,41 +139,6 @@ class CppExtensions implements ILanguageExtension { } -// def attributeConstructorInitList(List attribs, boolean useClassDefaultsOnly) { -// ''' -// // initialize attributes -// «FOR a : attribs» -// «var value = a.initValue» -// «IF value!=null» -// «IF !a.isArray» -// «a.name» ( «value» ), -// «ELSE» -// «a.name» ( { -// «FOR i : 0 .. a.size» -// value, -// «ENDFOR» -// } ) -// «ENDIF» -// «ELSEIF a.refType.type instanceof ComplexType || a.size>1 || !useClassDefaultsOnly» -// «IF a.size==0» -// «IF a.refType.isRef» -// «a.name» ( «languageExt.nullPointer()» ), -// «ELSE» -// «a.name» ( «a.refType.type.defaultValue» ), -// «ENDIF» -// «ELSE» -// «a.name» ( new «a.refType.type.typeName»[«a.size»] ), -// «IF !useClassDefaultsOnly» -// for (int i=0;i<«a.size»;i++){ -// «a.name»[i] = «IF a.refType.isRef»«languageExt.nullPointer()»«ELSE»«a.refType.type.defaultValue»«ENDIF»; -// } -// «ENDIF» -// «ENDIF» -// «ENDIF» -// «ENDFOR» -// ''' -// } - override String toValueLiteral(PrimitiveType type, String value){ throw new UnsupportedOperationException("TODO Config for Cpp"); } @@ -213,6 +182,7 @@ class CppExtensions implements ILanguageExtension { } override generateArglistAndTypedData(VarDecl data) { + var deref = "*" if (data==null) return newArrayList("", "", "") @@ -236,12 +206,16 @@ class CppExtensions implements ILanguageExtension { typeName = typeName+"*" castTypeName = castTypeName+"*" } - if (!(data.getRefType().getType() instanceof PrimitiveType)) { + else if (!(data.getRefType().getType() instanceof PrimitiveType)) { typeName = typeName+"*" castTypeName = castTypeName+"*" } + else { + castTypeName = typeName + deref = "" + } - val typedData = typeName+" "+data.getName() + " = *(("+castTypeName+") generic_data);\n" + val typedData = typeName+" "+data.getName() + " = " + deref + "(("+castTypeName+") generic_data);\n" val dataArg = ", "+data.getName() val typedArgList = ", "+typeName+" "+data.getName() 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 d94ef0cbe..df44859bd 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 @@ -91,6 +91,11 @@ class DataClassGen { // 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)» @@ -155,6 +160,18 @@ class DataClassGen { { } + «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) { 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 4e0be556d..a684bead5 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 @@ -24,24 +24,16 @@ class Initialization { «var value = a.initValueLiteral» «IF value!=null» «IF a.size == 0 || aType.characterType» - «a.name» = «value»; «ELSEIF value.startsWith("{")» - «a.name» = new «aType.typeName»[] «value»; + «initializeArrayWithValues(a.name, value.replace("{", "").replace("}", "").split(","))» «ELSE» - «a.name» = new «aType.typeName»[«a.size»]; 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» - «IF a.refType.isRef» - «a.name» = «languageExt.nullPointer()»; - «ELSE» - «a.name» = «languageExt.defaultValue(aType)»; - «ENDIF» «ELSE» - «a.name» = new «aType.typeName»[«a.size»]; «IF !useClassDefaultsOnly» for (int i=0;i<«a.size»;i++){ «a.name»[i] = «IF a.refType.isRef»«languageExt.nullPointer()»«ELSE»«languageExt.defaultValue(aType)»«ENDIF»; @@ -52,4 +44,40 @@ class Initialization { «ENDFOR» ''' } + + def initializeArrayWithValues(String varName, String[] values) { + ''' + «values.map(v | varName + "[" + values.indexOf(v) + "] = " + v + ";" ).join("\r\n")» + ''' + } + + def attributeInitialization(Attribute a, boolean useClassDefaultsOnly) { + var aType = a.refType.type + var value = a.initValueLiteral + 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/ProtocolClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend index afe525b28..38601e088 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 @@ -4,23 +4,24 @@ 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.InterfaceItem -import org.eclipse.etrice.core.room.Port -import org.eclipse.etrice.core.room.SAPRef -import org.eclipse.etrice.core.room.SPPRef - +import org.eclipse.etrice.core.room.PortClass @Singleton class ProtocolClassGen extends GenericProtocolClassGenerator { @@ -30,6 +31,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { @Inject extension RoomExtensions roomExt @Inject extension ProcedureHelpers helpers @Inject extension TypeHelpers + @Inject extension Initialization @Inject ILogger logger def doGenerate(Root root) { @@ -118,8 +120,8 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { «ENDIF» public: // constructors - «portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, etRuntime::Address addr, etRuntime::Address peerAddress); - «portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, etRuntime::Address addr, etRuntime::Address peerAddress); + «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» @@ -139,7 +141,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { class «replPortClassName» { private: int m_replication; - std::vector<«portClassName»> m_ports; + «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 addr, std::vector peerAddress); @@ -147,7 +149,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { int getReplication() { return m_replication; } int getIndexOf(const etRuntime::InterfaceItemBase& ifitem){ return ifitem.getIdx(); } - «portClassName» get(int i) {return m_ports.at(i);} + «portClassName» get(int i) {return m_ports[i];} «IF pc.commType==CommunicationType::EVENT_DRIVEN» // outgoing messages @@ -200,20 +202,26 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { // «IF conj»conjugated «ENDIF»port class //------------------------------------------------------------------------------------------------------------ - «portClassName»::«portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress) - : PortBase(actor, parent, name, localId, 0, addr, peerAddress) + «portClassName»::«portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress, bool doRegistration) + : «pclass.generateConstructorInitalizerList("0")» { - DebuggingService::getInstance().addPortInstance(*this); + «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) - : PortBase(actor, parent, name, localId, idx, addr, peerAddress) + «portClassName»::«portClassName»(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, Address addr, Address peerAddress, bool doRegistration) + : «pclass.generateConstructorInitalizerList("idx")» { - DebuggingService::getInstance().addPortInstance(*this); + «IF pclass!=null»«pclass.attributes.attributeInitialization(false)»«ENDIF» + if (doRegistration) { + DebuggingService::getInstance().addPortInstance(*this); + } } void «portClassName»::receive(Message* msg) { - if (! «pc.name»::isValidIncomingEvtID(msg->getEvtId())) { + if (! «pc.name»::«IF conj»isValidOutgoingEvtID«ELSE»isValidIncomingEvtID«ENDIF»(msg->getEvtId())) { std::cout << "unknown" << std::endl; } else { @@ -234,7 +242,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { «ENDFOR» default: «ENDIF» - getActor().receiveEvent(*this, msg->getEvtId(), msg->getData()); + getActor().receiveEvent(this, msg->getEvtId(), msg->getData()); «IF pc.handlesReceive(conj)» break; } @@ -260,10 +268,11 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { { char numstr[10]; // enough to hold all numbers up to 32-bits - m_ports.reserve(m_replication); + 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); - m_ports.push_back(«portClassName»(actor, parent, name + numstr, localId, i, addr[i], peerAddress[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]); } }; @@ -272,13 +281,26 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { «FOR m : pc.getOutgoing(conj)» «messageSignatureDefinition(m, replPortClassName)»{ for (int i=0; i(); + 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')» + ''' + } @@ -361,7 +383,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator { 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(«IF (m.data.refType.ref && !(m.data.refType.type instanceof PrimitiveType))»&«ENDIF»«m.data.name»), + reinterpret_cast(«IF (!m.data.refType.ref && !(m.data.refType.type instanceof PrimitiveType))»&«ENDIF»«m.data.name»), sizeof(«m.data.refType.type.typeName»))); «ENDIF» } 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 86a9328ea..eedcc9104 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 @@ -96,7 +96,7 @@ class SubSystemClassGen { { } - virtual void receiveEvent(const etRuntime::InterfaceItemBase& ifitem, int evt, void* data); + virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data); virtual void instantiateMessageServices(); virtual void instantiateActors(); @@ -127,7 +127,7 @@ class SubSystemClassGen { using namespace etRuntime; - void «comp.name»::receiveEvent(const InterfaceItemBase& ifitem, int evt, void* data){ + void «comp.name»::receiveEvent(InterfaceItemBase* ifitem, int evt, void* data){ } void «comp.name»::instantiateMessageServices(){ diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.smap b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.smap new file mode 100644 index 000000000..704f2d2f9 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.smap @@ -0,0 +1,94 @@ +SMAP +ConfigGenAddon.java +Xtend +*S Xtend +*F ++ 0 ConfigGenAddon.xtend +src/org/eclipse/etrice/generator/cpp/gen/ConfigGenAddon.xtend +*L +34:42,2 +35:44 +36:45,2 +37:47,3 +34:50 +38:51,2 +39:53,3 +34:56 +40:57,2 +34:59 +41:60,10 +42:70,10 +34:80 +43:81,5 +44:86,12 +34:98 +45:99,3 +47:102,12 +48:114,6 +49:120,11 +34:131,5 +53:136,2 +54:138,9 +34:147,6 +61:156,2 +62:158,3 +63:161,4 +61:165 +63:166,4 +61:170,2 +63:172,8 +64:180,6 +65:186,9 +67:195,6 +68:201,10 +71:211,8 +61:219 +71:220,4 +61:224,2 +71:226,7 +72:233,6 +73:239,12 +75:251,6 +76:257,13 +79:270,7 +80:277,6 +61:283,3 +83:286,3 +84:289,8 +61:297 +84:298,4 +61:302,2 +84:304,7 +85:311,10 +86:321,9 +61:330,3 +91:336,2 +92:338,17 +91:355,2 +94:357,5 +91:362,2 +96:364,2 +91:366 +98:367 +99:368,5 +91:373 +100:374,4 +101:378,13 +91:391,3 +103:394,4 +104:398,13 +91:411,4 +93:415 +91:416,2 +111:421,3 +112:424,3 +113:427 +112:428,2 +114:430,3 +115:433 +114:434,2 +116:436,3 +117:439 +116:440,2 +119:442 +*E diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java index bdc47ebac..8d6ba7423 100644 --- a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/CppExtensions.java @@ -112,6 +112,10 @@ public class CppExtensions implements ILanguageExtension { return true; } + public boolean usesPointers() { + return true; + } + public String genEnumeration(final String name, final List> entries) { StringConcatenation _builder = new StringConcatenation(); _builder.append("typedef enum {"); @@ -154,8 +158,10 @@ public class CppExtensions implements ILanguageExtension { public String arrayDeclaration(final String type, final int size, final String name, final boolean isRef) { String _plus = (type + " "); String _plus_1 = (_plus + name); - String _plus_2 = (_plus_1 + "[]"); - return _plus_2; + String _plus_2 = (_plus_1 + "["); + String _plus_3 = (_plus_2 + Integer.valueOf(size)); + String _plus_4 = (_plus_3 + "]"); + return _plus_4; } public String constructorName(final String cls) { @@ -319,6 +325,7 @@ public class CppExtensions implements ILanguageExtension { } public String[] generateArglistAndTypedData(final VarDecl data) { + String deref = "*"; boolean _equals = Objects.equal(data, null); if (_equals) { return ((String[])Conversions.unwrapArray(CollectionLiterals.newArrayList("", "", ""), String.class)); @@ -378,28 +385,34 @@ public class CppExtensions implements ILanguageExtension { typeName = _plus_1; String _plus_2 = (castTypeName + "*"); castTypeName = _plus_2; - } - RefableType _refType_5 = data.getRefType(); - DataType _type_4 = _refType_5.getType(); - boolean _not = (!(_type_4 instanceof PrimitiveType)); - if (_not) { - String _plus_3 = (typeName + "*"); - typeName = _plus_3; - String _plus_4 = (castTypeName + "*"); - castTypeName = _plus_4; + } else { + RefableType _refType_5 = data.getRefType(); + DataType _type_4 = _refType_5.getType(); + boolean _not = (!(_type_4 instanceof PrimitiveType)); + if (_not) { + String _plus_3 = (typeName + "*"); + typeName = _plus_3; + String _plus_4 = (castTypeName + "*"); + castTypeName = _plus_4; + } else { + castTypeName = typeName; + deref = ""; + } } String _plus_5 = (typeName + " "); String _name_1 = data.getName(); String _plus_6 = (_plus_5 + _name_1); - String _plus_7 = (_plus_6 + " = *(("); - String _plus_8 = (_plus_7 + castTypeName); - final String typedData = (_plus_8 + ") generic_data);\n"); + String _plus_7 = (_plus_6 + " = "); + String _plus_8 = (_plus_7 + deref); + String _plus_9 = (_plus_8 + "(("); + String _plus_10 = (_plus_9 + castTypeName); + final String typedData = (_plus_10 + ") generic_data);\n"); String _name_2 = data.getName(); final String dataArg = (", " + _name_2); - String _plus_9 = (", " + typeName); - String _plus_10 = (_plus_9 + " "); + String _plus_11 = (", " + typeName); + String _plus_12 = (_plus_11 + " "); String _name_3 = data.getName(); - final String typedArgList = (_plus_10 + _name_3); + final String typedArgList = (_plus_12 + _name_3); return ((String[])Conversions.unwrapArray(CollectionLiterals.newArrayList(dataArg, typedData, typedArgList), String.class)); } } diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java index 2450aa048..6010749c6 100644 --- a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/DataClassGen.java @@ -252,11 +252,36 @@ public class DataClassGen { _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.newLine(); + { + DataClass _base_5 = dc.getBase(); + boolean _notEquals_2 = (!Objects.equal(_base_5, null)); + if (_notEquals_2) { + _builder.append("\t"); + _builder.append("// constructor using base class constructor"); + _builder.newLine(); + _builder.append("\t"); + String _name_14 = dc.getName(); + _builder.append(_name_14, " "); + _builder.append("("); + DataClass _base_6 = dc.getBase(); + String _name_15 = _base_6.getName(); + _builder.append(_name_15, " "); + _builder.append(" _super, "); + EList _attributes_3 = dc.getAttributes(); + CharSequence _argListConstructor = this.argListConstructor(_attributes_3); + String _string = _argListConstructor.toString(); + _builder.append(_string, " "); + _builder.append(");"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("\t"); + _builder.newLine(); _builder.append("};"); _builder.newLine(); _builder.newLine(); - String _name_14 = dc.getName(); - CharSequence _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(_name_14); + String _name_16 = dc.getName(); + CharSequence _generateIncludeGuardEnd = this.stdExt.generateIncludeGuardEnd(_name_16); _builder.append(_generateIncludeGuardEnd, ""); _builder.newLineIfNotEmpty(); _builder.newLine(); @@ -480,16 +505,73 @@ public class DataClassGen { _builder.append("}"); _builder.newLine(); _builder.newLine(); + { + DataClass _base_7 = dc.getBase(); + boolean _notEquals_4 = (!Objects.equal(_base_7, null)); + if (_notEquals_4) { + _builder.append("// constructor using base class constructor"); + _builder.newLine(); + String _name_15 = dc.getName(); + _builder.append(_name_15, ""); + _builder.append("::"); + String _name_16 = dc.getName(); + _builder.append(_name_16, ""); + _builder.append("("); + DataClass _base_8 = dc.getBase(); + String _name_17 = _base_8.getName(); + _builder.append(_name_17, ""); + _builder.append(" _super, "); + EList _attributes_3 = dc.getAttributes(); + CharSequence _argListConstructor = this.argListConstructor(_attributes_3); + String _string = _argListConstructor.toString(); + _builder.append(_string, ""); + _builder.append(")"); + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append(":"); + _builder.newLine(); + _builder.append("\t"); + DataClass _base_9 = dc.getBase(); + String _name_18 = _base_9.getName(); + _builder.append(_name_18, " "); + _builder.append("(_super),"); + _builder.newLineIfNotEmpty(); + { + EList _attributes_4 = dc.getAttributes(); + boolean _hasElements_2 = false; + for(final Attribute a_2 : _attributes_4) { + if (!_hasElements_2) { + _hasElements_2 = true; + } else { + _builder.appendImmediate(",", " "); + } + _builder.append("\t"); + String _name_19 = a_2.getName(); + _builder.append(_name_19, " "); + _builder.append("("); + String _name_20 = a_2.getName(); + _builder.append(_name_20, " "); + _builder.append("_)"); + _builder.newLineIfNotEmpty(); + } + } + _builder.append("{"); + _builder.newLine(); + _builder.append("}"); + _builder.newLine(); + } + } + _builder.newLine(); _builder.append("// assignment operator"); _builder.newLine(); - String _name_15 = dc.getName(); - _builder.append(_name_15, ""); + String _name_21 = dc.getName(); + _builder.append(_name_21, ""); _builder.append("& "); - String _name_16 = dc.getName(); - _builder.append(_name_16, ""); + String _name_22 = dc.getName(); + _builder.append(_name_22, ""); _builder.append("::operator=(const "); - String _name_17 = dc.getName(); - _builder.append(_name_17, ""); + String _name_23 = dc.getName(); + _builder.append(_name_23, ""); _builder.append("& rhs)"); _builder.newLineIfNotEmpty(); _builder.append("{\t\t"); @@ -498,26 +580,26 @@ public class DataClassGen { _builder.append("if (this == &rhs) { return *this; };"); _builder.newLine(); { - DataClass _base_7 = dc.getBase(); - boolean _notEquals_4 = (!Objects.equal(_base_7, null)); - if (_notEquals_4) { + DataClass _base_10 = dc.getBase(); + boolean _notEquals_5 = (!Objects.equal(_base_10, null)); + if (_notEquals_5) { _builder.append("\t"); - DataClass _base_8 = dc.getBase(); - String _name_18 = _base_8.getName(); - _builder.append(_name_18, " "); + DataClass _base_11 = dc.getBase(); + String _name_24 = _base_11.getName(); + _builder.append(_name_24, " "); _builder.append("::operator=(rhs);"); _builder.newLineIfNotEmpty(); } } { - EList _attributes_3 = dc.getAttributes(); - for(final Attribute a_2 : _attributes_3) { + EList _attributes_5 = dc.getAttributes(); + for(final Attribute a_3 : _attributes_5) { _builder.append("\t"); - String _name_19 = a_2.getName(); - _builder.append(_name_19, " "); + String _name_25 = a_3.getName(); + _builder.append(_name_25, " "); _builder.append("= rhs."); - String _name_20 = a_2.getName(); - _builder.append(_name_20, " "); + String _name_26 = a_3.getName(); + _builder.append(_name_26, " "); _builder.append(";"); _builder.newLineIfNotEmpty(); } @@ -529,8 +611,8 @@ public class DataClassGen { _builder.newLine(); _builder.newLine(); EList _operations_2 = dc.getOperations(); - String _name_21 = dc.getName(); - CharSequence _operationsImplementation = this.helpers.operationsImplementation(_operations_2, _name_21); + String _name_27 = dc.getName(); + CharSequence _operationsImplementation = this.helpers.operationsImplementation(_operations_2, _name_27); _builder.append(_operationsImplementation, ""); _builder.newLineIfNotEmpty(); _builder.newLine(); diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/MainGen.smap b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/MainGen.smap new file mode 100644 index 000000000..8c098acdf --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/MainGen.smap @@ -0,0 +1,22 @@ +SMAP +MainGen.java +Xtend +*S Xtend +*F ++ 0 MainGen.xtend +src/org/eclipse/etrice/generator/cpp/gen/MainGen.xtend +*L +34:40 +35:41,2 +36:43 +37:44 +36:45 +35:46 +43:50 +44:51 +45:52 +46:53 +48:54,3 +49:57 +48:58 +*E diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.java b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.java index 0cd388367..06c8a4345 100644 --- a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.java +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.java @@ -3,6 +3,7 @@ package org.eclipse.etrice.generator.cpp.gen; import com.google.common.base.Objects; import com.google.inject.Inject; import com.google.inject.Singleton; +import java.util.ArrayList; import java.util.HashSet; import java.util.List; import org.eclipse.emf.common.util.EList; @@ -27,12 +28,14 @@ import org.eclipse.etrice.core.room.SAPRef; import org.eclipse.etrice.core.room.SPPRef; import org.eclipse.etrice.core.room.VarDecl; import org.eclipse.etrice.generator.cpp.gen.CppExtensions; +import org.eclipse.etrice.generator.cpp.gen.Initialization; import org.eclipse.etrice.generator.generic.GenericProtocolClassGenerator; import org.eclipse.etrice.generator.generic.ProcedureHelpers; import org.eclipse.etrice.generator.generic.RoomExtensions; import org.eclipse.etrice.generator.generic.TypeHelpers; import org.eclipse.xtend2.lib.StringConcatenation; import org.eclipse.xtext.generator.JavaIoFileSystemAccess; +import org.eclipse.xtext.xbase.lib.IterableExtensions; @Singleton @SuppressWarnings("all") @@ -52,6 +55,9 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { @Inject private TypeHelpers _typeHelpers; + @Inject + private Initialization _initialization; + @Inject private ILogger logger; @@ -309,11 +315,11 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _builder.newLine(); _builder.append("\t "); _builder.append(portClassName, " "); - _builder.append("(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, etRuntime::Address addr, etRuntime::Address peerAddress); "); + _builder.append("(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true); "); _builder.newLineIfNotEmpty(); _builder.append("\t "); _builder.append(portClassName, " "); - _builder.append("(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, etRuntime::Address addr, etRuntime::Address peerAddress);"); + _builder.append("(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true);"); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append("\t "); @@ -374,9 +380,8 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _builder.append("int m_replication;"); _builder.newLine(); _builder.append("\t "); - _builder.append("std::vector<"); _builder.append(portClassName, " "); - _builder.append("> m_ports;"); + _builder.append("* m_ports; //dynamic array used instead of vector to avoid copy construction"); _builder.newLineIfNotEmpty(); _builder.newLine(); _builder.append("\t"); @@ -401,7 +406,7 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _builder.newLine(); _builder.append("\t\t"); _builder.append(portClassName, " "); - _builder.append(" get(int i) {return m_ports.at(i);}"); + _builder.append(" get(int i) {return m_ports[i];}"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.newLine(); @@ -540,32 +545,68 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _builder.append(portClassName, ""); _builder.append("::"); _builder.append(portClassName, ""); - _builder.append("(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress)"); + _builder.append("(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress, bool doRegistration)"); _builder.newLineIfNotEmpty(); _builder.append("\t"); - _builder.append(": PortBase(actor, parent, name, localId, 0, addr, peerAddress)"); - _builder.newLine(); + _builder.append(": "); + CharSequence _generateConstructorInitalizerList = this.generateConstructorInitalizerList(pclass, "0"); + _builder.append(_generateConstructorInitalizerList, " "); + _builder.newLineIfNotEmpty(); _builder.append("{"); _builder.newLine(); _builder.append("\t"); + { + boolean _notEquals = (!Objects.equal(pclass, null)); + if (_notEquals) { + EList _attributes = pclass.getAttributes(); + CharSequence _attributeInitialization = this._initialization.attributeInitialization(_attributes, false); + _builder.append(_attributeInitialization, " "); + } + } + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("if (doRegistration) {"); + _builder.newLine(); + _builder.append("\t\t"); _builder.append("DebuggingService::getInstance().addPortInstance(*this);"); _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.newLine(); _builder.append(portClassName, ""); _builder.append("::"); _builder.append(portClassName, ""); - _builder.append("(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, Address addr, Address peerAddress)"); + _builder.append("(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, Address addr, Address peerAddress, bool doRegistration)"); _builder.newLineIfNotEmpty(); _builder.append("\t"); - _builder.append(": PortBase(actor, parent, name, localId, idx, addr, peerAddress)"); - _builder.newLine(); + _builder.append(": "); + CharSequence _generateConstructorInitalizerList_1 = this.generateConstructorInitalizerList(pclass, "idx"); + _builder.append(_generateConstructorInitalizerList_1, " "); + _builder.newLineIfNotEmpty(); _builder.append("{"); _builder.newLine(); _builder.append("\t"); + { + boolean _notEquals_1 = (!Objects.equal(pclass, null)); + if (_notEquals_1) { + EList _attributes_1 = pclass.getAttributes(); + CharSequence _attributeInitialization_1 = this._initialization.attributeInitialization(_attributes_1, false); + _builder.append(_attributeInitialization_1, " "); + } + } + _builder.newLineIfNotEmpty(); + _builder.append("\t"); + _builder.append("if (doRegistration) {"); + _builder.newLine(); + _builder.append("\t\t"); _builder.append("DebuggingService::getInstance().addPortInstance(*this);"); _builder.newLine(); + _builder.append("\t"); + _builder.append("}"); + _builder.newLine(); _builder.append("}"); _builder.newLine(); _builder.append("\t"); @@ -578,7 +619,15 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _builder.append("if (! "); String _name = pc.getName(); _builder.append(_name, " "); - _builder.append("::isValidIncomingEvtID(msg->getEvtId())) {"); + _builder.append("::"); + { + if ((conj).booleanValue()) { + _builder.append("isValidOutgoingEvtID"); + } else { + _builder.append("isValidIncomingEvtID"); + } + } + _builder.append("(msg->getEvtId())) {"); _builder.newLineIfNotEmpty(); _builder.append("\t\t"); _builder.append("std::cout << \"unknown\" << std::endl;"); @@ -658,7 +707,7 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { } } _builder.append("\t\t\t\t"); - _builder.append("getActor().receiveEvent(*this, msg->getEvtId(),\tmsg->getData());"); + _builder.append("getActor().receiveEvent(this, msg->getEvtId(),\tmsg->getData());"); _builder.newLine(); { boolean _handlesReceive_1 = this.roomExt.handlesReceive(pc, (conj).booleanValue()); @@ -679,8 +728,8 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _builder.newLine(); _builder.newLine(); { - boolean _notEquals = (!Objects.equal(pclass, null)); - if (_notEquals) { + boolean _notEquals_2 = (!Objects.equal(pclass, null)); + if (_notEquals_2) { EList _operations = pclass.getOperations(); CharSequence _operationsImplementation = this.helpers.operationsImplementation(_operations, portClassName); _builder.append(_operationsImplementation, ""); @@ -732,8 +781,12 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _builder.newLine(); _builder.newLine(); _builder.append("\t"); - _builder.append("m_ports.reserve(m_replication);"); - _builder.newLine(); + _builder.append("m_ports = reinterpret_cast<"); + _builder.append(portClassName, " "); + _builder.append("*> (new char[sizeof("); + _builder.append(portClassName, " "); + _builder.append(") * addr.size()]);"); + _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("for (int i = 0; i < m_replication; ++i) {"); _builder.newLine(); @@ -741,9 +794,12 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _builder.append("snprintf(numstr, sizeof(numstr), \"%d\", i);"); _builder.newLine(); _builder.append("\t\t"); - _builder.append("m_ports.push_back("); + _builder.append("//placement new to avoid copy construction, therefore no vector is used"); + _builder.newLine(); + _builder.append("\t\t"); + _builder.append("new (&m_ports[i]) "); _builder.append(portClassName, " "); - _builder.append("(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]));"); + _builder.append("(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]);"); _builder.newLineIfNotEmpty(); _builder.append("\t"); _builder.append("}"); @@ -766,7 +822,7 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { _builder.append("for (int i=0; i _arrayList = new ArrayList(); + ArrayList initializerList = _arrayList; + StringConcatenation _builder = new StringConcatenation(); + _builder.append("PortBase(actor, parent, name, localId, "); + _builder.append(index, ""); + _builder.append(", addr, peerAddress)"); + initializerList.add(_builder); + boolean _notEquals = (!Objects.equal(pc, null)); + if (_notEquals) { + EList _attributes = pc.getAttributes(); + for (final Attribute attrib : _attributes) { + CharSequence _attributeInitialization = this._initialization.attributeInitialization(attrib, false); + initializerList.add(_attributeInitialization); + } + } + StringConcatenation _builder_1 = new StringConcatenation(); + String _join = IterableExtensions.join(initializerList, ",\n"); + _builder_1.append(_join, ""); + _builder_1.newLineIfNotEmpty(); + return _builder_1; + } + private CharSequence messageCall(final Message m) { StringConcatenation _builder = new StringConcatenation(); String _name = m.getName(); @@ -1150,14 +1229,15 @@ public class ProtocolClassGen extends GenericProtocolClassGenerator { VarDecl _data_1 = m.getData(); RefableType _refType = _data_1.getRefType(); boolean _isRef = _refType.isRef(); - if (!_isRef) { + boolean _not = (!_isRef); + if (!_not) { _and = false; } else { VarDecl _data_2 = m.getData(); RefableType _refType_1 = _data_2.getRefType(); DataType _type = _refType_1.getType(); - boolean _not = (!(_type instanceof PrimitiveType)); - _and = (_isRef && _not); + boolean _not_1 = (!(_type instanceof PrimitiveType)); + _and = (_not && _not_1); } if (_and) { _builder.append("&"); diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.smap b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.smap new file mode 100644 index 000000000..e0fd14248 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.smap @@ -0,0 +1,47 @@ +SMAP +StateMachineGen.java +Xtend +*S Xtend +*F ++ 0 StateMachineGen.xtend +src/org/eclipse/etrice/generator/cpp/gen/StateMachineGen.xtend +*L +30:30,2 +31:32 +30:33 +32:34,16 +30:50,2 +47:55,2 +48:57 +47:58 +49:59 +50:60,3 +47:63 +50:64,3 +47:67,3 +50:70 +47:71 +50:72,5 +47:77,2 +51:79,6 +59:85,21 +49:106 +47:107,2 +70:112,3 +71:115 +70:116,2 +71:118 +70:119,3 +73:122,2 +74:124,2 +75:126 +76:127,9 +75:136 +79:137 +83:141,2 +87:146 +91:150 +95:154 +99:158,2 +103:163 +*E diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.smap b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.smap new file mode 100644 index 000000000..c1c4867e8 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.smap @@ -0,0 +1,167 @@ +SMAP +SubSystemClassGen.java +Xtend +*S Xtend +*F ++ 0 SubSystemClassGen.xtend +src/org/eclipse/etrice/generator/cpp/gen/SubSystemClassGen.xtend +*L +35:58,3 +36:61,5 +37:66,2 +38:68,5 +39:73 +40:74,3 +42:77,3 +43:80,5 +44:85 +45:86,3 +35:89,2 +59:94,14 +64:108,11 +68:119,40 +59:159 +82:160,2 +59:162,2 +84:164,5 +87:169,7 +89:176,7 +91:183,9 +94:192,38 +107:230,4 +59:234 +111:238,14 +116:252,12 +120:264,10 +111:274 +123:275,4 +124:279,8 +111:287,2 +125:289,12 +130:301,11 +133:312,9 +111:321 +136:322,4 +137:326,12 +111:338,2 +138:340,16 +144:356,10 +111:366 +147:367,6 +148:373,9 +111:382,2 +149:384,2 +111:386 +151:387,4 +152:391,9 +154:400,13 +155:413,3 +111:416 +156:417,2 +111:419 +157:420,2 +111:422 +158:423,3 +159:426,5 +160:431,14 +111:445,3 +162:448,2 +163:450,11 +111:461,6 +166:467,6 +169:473,5 +111:478 +170:479,7 +172:486,7 +174:493,4 +175:497,7 +177:504,9 +111:513 +178:514,6 +111:520 +180:521,3 +181:524,6 +111:530,2 +182:532,3 +183:535,6 +184:541,6 +185:547,7 +111:554,2 +187:556,4 +111:560 +190:561,2 +111:563 +191:564,15 +193:579,14 +194:593,6 +111:599 +195:600,3 +196:603,12 +111:615,2 +197:617,2 +111:619,4 +200:623,13 +206:636,5 +111:641 +207:642,4 +208:646,9 +111:655,2 +209:657,2 +210:659,5 +111:664 +211:665,4 +212:669,9 +111:678,2 +213:680,27 +111:707 +227:711,2 +228:713,6 +230:719,4 +231:723,9 +233:732,7 +227:739 +234:740,2 +227:742 +235:743,2 +227:745 +236:746,4 +237:750,7 +227:757 +238:758 +239:759,11 +227:770 +240:771,2 +241:773,19 +227:792,5 +244:797 +245:798,7 +246:805,11 +227:816,2 +248:818,11 +227:829,3 +253:835,2 +254:837,6 +256:843,4 +257:847,9 +259:856,7 +253:863 +260:864,2 +253:866 +261:867,10 +253:877,2 +263:879,4 +264:883,7 +253:890 +265:891 +266:892,11 +253:903 +267:904,2 +253:906 +268:907,2 +269:909,19 +253:928 +271:929,15 +253:944,6 +275:950,10 +253:960,5 +*E diff --git a/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.smap b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.smap new file mode 100644 index 000000000..e73e35954 --- /dev/null +++ b/plugins/org.eclipse.etrice.generator.cpp/xtend-gen/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.smap @@ -0,0 +1,31 @@ +SMAP +SubSystemRunnerGen.java +Xtend +*S Xtend +*F ++ 0 SubSystemRunnerGen.xtend +src/org/eclipse/etrice/generator/cpp/gen/SubSystemRunnerGen.xtend +*L +20:27,3 +21:30,6 +22:36,5 +24:41,6 +25:47,5 +20:52,2 +29:57,11 +33:68,5 +34:73,8 +37:81,10 +41:91,27 +51:118,5 +29:123 +55:127,11 +59:138,5 +60:143,10 +64:153,5 +65:158,24 +76:182,15 +81:197,6 +82:203,56 +55:259 +*E diff --git a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend index d76f23f5a..5596f7d63 100644 --- a/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend +++ b/plugins/org.eclipse.etrice.generator.java/src/org/eclipse/etrice/generator/java/gen/JavaExtensions.xtend @@ -68,6 +68,10 @@ class JavaExtensions implements ILanguageExtension { return true } + override boolean usesPointers() { + return false + } + override String genEnumeration(String name, List> entries) { ''' «FOR entry: entries» diff --git a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java index 782b2722a..135a63fda 100644 --- a/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java +++ b/plugins/org.eclipse.etrice.generator.java/xtend-gen/org/eclipse/etrice/generator/java/gen/JavaExtensions.java @@ -96,6 +96,10 @@ public class JavaExtensions implements ILanguageExtension { return true; } + public boolean usesPointers() { + return false; + } + public String genEnumeration(final String name, final List> entries) { StringConcatenation _builder = new StringConcatenation(); { diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend index 8c0e3841c..710b3ba7b 100644 --- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend +++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.xtend @@ -224,11 +224,11 @@ class GenericStateMachineGenerator { } /* receiveEvent contains the main implementation of the FSM */ - «IF langExt.usesInheritance»«langExt.accessLevelPublic»«ELSE»«langExt.accessLevelPrivate»«ENDIF»void «IF !shallGenerateOneFile»«ac.name»::«ENDIF»receiveEvent(«langExt.selfPointer(ac.name, handleEvents)»«IF handleEvents»«"InterfaceItemBase".constRef» ifitem, int evt, «langExt.voidPointer» generic_data«ENDIF») { + «IF langExt.usesInheritance»«langExt.accessLevelPublic»«ELSE»«langExt.accessLevelPrivate»«ENDIF»void «IF !shallGenerateOneFile»«ac.name»::«ENDIF»receiveEvent(«langExt.selfPointer(ac.name, handleEvents)»«IF handleEvents»«"InterfaceItemBase".pointer» ifitem, int evt, «langExt.voidPointer» generic_data«ENDIF») { «IF async» - int trigger = (ifitem==«langExt.nullPointer»)? POLLING : «IF langExt.usesInheritance»ifitem.getLocalId()«ELSE»ifitem->localId«ENDIF» + EVT_SHIFT*evt; + int trigger = (ifitem==«langExt.nullPointer»)? POLLING : «IF langExt.usesPointers»ifitem->getLocalId()«ELSE»ifitem.getLocalId()«ENDIF» + EVT_SHIFT*evt; «ELSEIF eventDriven» - int trigger = «IF langExt.usesInheritance»ifitem.getLocalId()«ELSE»ifitem->localId«ENDIF» + EVT_SHIFT*evt; + int trigger = «IF langExt.usesPointers»ifitem->getLocalId()«ELSE»ifitem.getLocalId()«ENDIF» + EVT_SHIFT*evt; «ENDIF» int chain = NOT_CAUGHT; int catching_state = NO_STATE; @@ -244,7 +244,7 @@ class GenericStateMachineGenerator { «ENDIF» if (chain != NOT_CAUGHT) { exitTo(getState(), catching_state, is_handler); - int next = executeTransitionChain(«langExt.selfPointer(true)»chain«IF handleEvents», «addressOp("ifitem")», generic_data«ENDIF»); + int next = executeTransitionChain(«langExt.selfPointer(true)»chain«IF handleEvents», ifitem, generic_data«ENDIF»); next = enterHistory(«langExt.selfPointer(true)»next, is_handler, skip_entry); setState(«langExt.selfPointer(true)»next); } @@ -352,7 +352,7 @@ class GenericStateMachineGenerator { def private genDoCodes(State state) {''' «IF state.hasDoCode()» - «state.getDoCodeOperationName()»(self); + «state.getDoCodeOperationName()»(«langExt.selfPointer(false)»); «ENDIF» «IF state.eContainer.eContainer instanceof State» «genDoCodes(state.eContainer.eContainer as State)» @@ -514,7 +514,7 @@ class GenericStateMachineGenerator { void executeInitTransition(«langExt.selfPointer(ac.name, false)»); /* receiveEvent contains the main implementation of the FSM */ - void receiveEvent(«langExt.selfPointer(ac.name, handleEvents)»«IF handleEvents»const etRuntime::InterfaceItemBase& ifitem, int evt, «langExt.voidPointer» generic_data«ENDIF»); + void receiveEvent(«langExt.selfPointer(ac.name, handleEvents)»«IF handleEvents»etRuntime::InterfaceItemBase* ifitem, int evt, «langExt.voidPointer» generic_data«ENDIF»); ''' } } diff --git a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ILanguageExtension.java b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ILanguageExtension.java index 1f6fb9c51..6cb771773 100644 --- a/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ILanguageExtension.java +++ b/plugins/org.eclipse.etrice.generator/src/org/eclipse/etrice/generator/generic/ILanguageExtension.java @@ -95,6 +95,13 @@ public interface ILanguageExtension { */ boolean usesInheritance(); + /** + * does the target language use pointers + * + * @return true for C++ and C, false for Java + */ + boolean usesPointers(); + /** * generate an enumeration (enum in C, int constants in Java) * @param name the enumeration name @@ -213,4 +220,4 @@ public interface ILanguageExtension { * @return the array initializer */ String initializationWithDefaultValues(DataType dt, int size); -} \ No newline at end of file +} diff --git a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java index e0d12816d..642b3449d 100644 --- a/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java +++ b/plugins/org.eclipse.etrice.generator/xtend-gen/org/eclipse/etrice/generator/generic/GenericStateMachineGenerator.java @@ -822,8 +822,8 @@ public class GenericStateMachineGenerator { _builder.append(_selfPointer_11, ""); { if (handleEvents) { - String _constRef = this.constRef("InterfaceItemBase"); - _builder.append(_constRef, ""); + String _pointer = this.pointer("InterfaceItemBase"); + _builder.append(_pointer, ""); _builder.append(" ifitem, int evt, "); String _voidPointer_1 = this.langExt.voidPointer(); _builder.append(_voidPointer_1, ""); @@ -840,11 +840,11 @@ public class GenericStateMachineGenerator { _builder.append(_nullPointer_4, " "); _builder.append(")? POLLING : "); { - boolean _usesInheritance_4 = this.langExt.usesInheritance(); - if (_usesInheritance_4) { - _builder.append("ifitem.getLocalId()"); + boolean _usesPointers = this.langExt.usesPointers(); + if (_usesPointers) { + _builder.append("ifitem->getLocalId()"); } else { - _builder.append("ifitem->localId"); + _builder.append("ifitem.getLocalId()"); } } _builder.append(" + EVT_SHIFT*evt;"); @@ -854,11 +854,11 @@ public class GenericStateMachineGenerator { _builder.append("\t"); _builder.append("int trigger = "); { - boolean _usesInheritance_5 = this.langExt.usesInheritance(); - if (_usesInheritance_5) { - _builder.append("ifitem.getLocalId()"); + boolean _usesPointers_1 = this.langExt.usesPointers(); + if (_usesPointers_1) { + _builder.append("ifitem->getLocalId()"); } else { - _builder.append("ifitem->localId"); + _builder.append("ifitem.getLocalId()"); } } _builder.append(" + EVT_SHIFT*evt;"); @@ -923,10 +923,7 @@ public class GenericStateMachineGenerator { _builder.append("chain"); { if (handleEvents) { - _builder.append(", "); - String _addressOp = this.addressOp("ifitem"); - _builder.append(_addressOp, " "); - _builder.append(", generic_data"); + _builder.append(", ifitem, generic_data"); } } _builder.append(");"); @@ -1308,7 +1305,10 @@ public class GenericStateMachineGenerator { if (_hasDoCode) { String _doCodeOperationName = CodegenHelpers.getDoCodeOperationName(state); _builder.append(_doCodeOperationName, ""); - _builder.append("(self);"); + _builder.append("("); + String _selfPointer = this.langExt.selfPointer(false); + _builder.append(_selfPointer, ""); + _builder.append(");"); _builder.newLineIfNotEmpty(); } } @@ -1790,7 +1790,7 @@ public class GenericStateMachineGenerator { _builder.append(_selfPointer_5, " "); { if (handleEvents) { - _builder.append("const etRuntime::InterfaceItemBase& ifitem, int evt, "); + _builder.append("etRuntime::InterfaceItemBase* ifitem, int evt, "); String _voidPointer_1 = this.langExt.voidPointer(); _builder.append(_voidPointer_1, " "); _builder.append(" generic_data"); diff --git a/runtime/org.eclipse.etrice.modellib.cpp/.cproject b/runtime/org.eclipse.etrice.modellib.cpp/.cproject index 023c99859..0191c0b6e 100644 --- a/runtime/org.eclipse.etrice.modellib.cpp/.cproject +++ b/runtime/org.eclipse.etrice.modellib.cpp/.cproject @@ -9,7 +9,7 @@ - + @@ -19,7 +19,7 @@ - + diff --git a/runtime/org.eclipse.etrice.modellib.cpp/model/TimingService.room b/runtime/org.eclipse.etrice.modellib.cpp/model/TimingService.room index 538fe7b03..1c13eb3ef 100644 --- a/runtime/org.eclipse.etrice.modellib.cpp/model/TimingService.room +++ b/runtime/org.eclipse.etrice.modellib.cpp/model/TimingService.room @@ -126,7 +126,7 @@ RoomModel room.basic.service.timing { etTimerControlBlock* temp=usedTcbsRoot; printf(\"list: \"); while (temp!=0){ - printf(\"(%d,%d),\",temp->expTime.sec,temp->expTime.nSec); + printf(\"(%ld,%ld),\",temp->expTime.sec,temp->expTime.nSec); temp=temp->next; } printf(\"\\n\"); @@ -277,7 +277,7 @@ RoomModel room.basic.service.timing { status=0; } // msg to fsm - getActor().receiveEvent(*this, msg->getEvtId(), msg->getData()); + getActor().receiveEvent(this, msg->getEvtId(), msg->getData()); } " } diff --git a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp index b7bdd599f..e8efe9edf 100644 --- a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp +++ b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.cpp @@ -15,17 +15,18 @@ using namespace etRuntime; ATimingService::ATimingService(etRuntime::IRTObject* parent, std::string name, const std::vector >& port_addr, const std::vector >& peer_addr) : ActorClassBase( parent, name, port_addr[0][0], peer_addr[0][0]), -timer(*this, this, "timer", IFITEM_timer, port_addr[IFITEM_timer], peer_addr[IFITEM_timer]) +timer(*this, this, "timer", IFITEM_timer, port_addr[IFITEM_timer], peer_addr[IFITEM_timer]), +tcbs(), +usedTcbsRoot(0), +freeTcbsRoot(0) { setClassName("ATimingService"); - // initialize attributes - tcbs = new etTimerControlBlock[10]; - for (int i=0;i<10;i++){ - tcbs[i] = etTimerControlBlock(); - } - usedTcbsRoot = 0; - freeTcbsRoot = 0; + // initialize attributes + for (int i=0;i<10;i++){ + tcbs[i] = etTimerControlBlock(); + } + getMsgsvc()->addAsyncActor(*this); } void ATimingService::init(){ @@ -160,13 +161,13 @@ int ATimingService::executeTransitionChain(int chain, const InterfaceItemBase* i } case CHAIN_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1: { - uint32 time = *((uint32*) generic_data); + uint32 time = ((uint32) generic_data); action_TRANS_tr1_FROM_Operational_TO_Operational_BY_startTimeouttimer_tr1(ifitem, time); return STATE_Operational; } case CHAIN_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3: { - uint32 time = *((uint32*) generic_data); + uint32 time = ((uint32) generic_data); action_TRANS_tr3_FROM_Operational_TO_Operational_BY_startTimertimer_tr3(ifitem, time); return STATE_Operational; } @@ -209,8 +210,8 @@ void ATimingService::executeInitTransition() { } /* receiveEvent contains the main implementation of the FSM */ -void ATimingService::receiveEvent(const InterfaceItemBase& ifitem, int evt, void* generic_data) { - int trigger = (ifitem==0)? POLLING : ifitem.getLocalId() + EVT_SHIFT*evt; +void ATimingService::receiveEvent(InterfaceItemBase* ifitem, int evt, void* generic_data) { + int trigger = (ifitem==0)? POLLING : ifitem->getLocalId() + EVT_SHIFT*evt; int chain = NOT_CAUGHT; int catching_state = NO_STATE; bool is_handler = false; @@ -221,7 +222,7 @@ void ATimingService::receiveEvent(const InterfaceItemBase& ifitem, int evt, void case STATE_Operational: switch(trigger) { case POLLING: - do_Operational(self); + do_Operational(); break; case TRIG_timer__startTimeout: { @@ -247,7 +248,7 @@ void ATimingService::receiveEvent(const InterfaceItemBase& ifitem, int evt, void } if (chain != NOT_CAUGHT) { exitTo(getState(), catching_state, is_handler); - int next = executeTransitionChain(chain, &ifitem, generic_data); + int next = executeTransitionChain(chain, ifitem, generic_data); next = enterHistory(next, is_handler, skip_entry); setState(next); } diff --git a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h index 32d4b4dda..de34e5728 100644 --- a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h +++ b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/ATimingService.h @@ -54,7 +54,7 @@ } interface_items; /*--------------------- attributes ---------------------*/ - etTimerControlBlock tcbs[]; + etTimerControlBlock tcbs[10]; etTimerControlBlock* usedTcbsRoot; etTimerControlBlock* freeTcbsRoot; @@ -251,7 +251,7 @@ void executeInitTransition(); /* receiveEvent contains the main implementation of the FSM */ - void receiveEvent(const etRuntime::InterfaceItemBase& ifitem, int evt, void* generic_data); + void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* generic_data); /*--------------------- begin user code ---------------------*/ //uc2 diff --git a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp index fd93ba2a8..9b4aa2678 100644 --- a/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp +++ b/runtime/org.eclipse.etrice.modellib.cpp/src-gen/room/basic/service/timing/PTimer.cpp @@ -20,16 +20,20 @@ // port class //------------------------------------------------------------------------------------------------------------ - PTimerPort::PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress) + PTimerPort::PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, Address addr, Address peerAddress, bool doRegistration) : PortBase(actor, parent, name, localId, 0, addr, peerAddress) { - DebuggingService::getInstance().addPortInstance(*this); + if (doRegistration) { + DebuggingService::getInstance().addPortInstance(*this); + } } - PTimerPort::PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, Address addr, Address peerAddress) + PTimerPort::PTimerPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, Address addr, Address peerAddress, bool doRegistration) : PortBase(actor, parent, name, localId, idx, addr, peerAddress) { - DebuggingService::getInstance().addPortInstance(*this); + if (doRegistration) { + DebuggingService::getInstance().addPortInstance(*this); + } } void PTimerPort::receive(Message* msg) { @@ -41,7 +45,7 @@ DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), PTimer::getMessageString(msg->getEvtId())); } - getActor().receiveEvent(*this, msg->getEvtId(), msg->getData()); + getActor().receiveEvent(this, msg->getEvtId(), msg->getData()); } }; @@ -65,10 +69,11 @@ { char numstr[10]; // enough to hold all numbers up to 32-bits - m_ports.reserve(m_replication); + m_ports = reinterpret_cast (new char[sizeof(PTimerPort) * addr.size()]); for (int i = 0; i < m_replication; ++i) { snprintf(numstr, sizeof(numstr), "%d", i); - m_ports.push_back(PTimerPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i])); + //placement new to avoid copy construction, therefore no vector is used + new (&m_ports[i]) PTimerPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]); } }; @@ -76,27 +81,35 @@ // outgoing messages void PTimerReplPort::timeout(){ for (int i=0; igetEvtId())) { + if (! PTimer::isValidOutgoingEvtID(msg->getEvtId())) { std::cout << "unknown" << std::endl; } else { @@ -115,12 +128,12 @@ status=0; } // msg to fsm - getActor().receiveEvent(*this, msg->getEvtId(), msg->getData()); + getActor().receiveEvent(this, msg->getEvtId(), msg->getData()); } } break; default: - getActor().receiveEvent(*this, msg->getEvtId(), msg->getData()); + getActor().receiveEvent(this, msg->getEvtId(), msg->getData()); break; } } @@ -179,10 +192,11 @@ { char numstr[10]; // enough to hold all numbers up to 32-bits - m_ports.reserve(m_replication); + m_ports = reinterpret_cast (new char[sizeof(PTimerConjPort) * addr.size()]); for (int i = 0; i < m_replication; ++i) { snprintf(numstr, sizeof(numstr), "%d", i); - m_ports.push_back(PTimerConjPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i])); + //placement new to avoid copy construction, therefore no vector is used + new (&m_ports[i]) PTimerConjPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]); } }; @@ -190,17 +204,17 @@ // outgoing messages void PTimerConjReplPort::startTimer(uint32 time){ for (int i=0; i m_ports; + PTimerPort* m_ports; //dynamic array used instead of vector to avoid copy construction public: PTimerReplPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector addr, std::vector peerAddress); @@ -88,7 +88,7 @@ class PTimerReplPort { int getReplication() { return m_replication; } int getIndexOf(const etRuntime::InterfaceItemBase& ifitem){ return ifitem.getIdx(); } - PTimerPort get(int i) {return m_ports.at(i);} + PTimerPort get(int i) {return m_ports[i];} // outgoing messages public: void timeout(); @@ -100,8 +100,8 @@ class PTimerReplPort { class PTimerConjPort : public etRuntime::PortBase { public: // constructors - PTimerConjPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, etRuntime::Address addr, etRuntime::Address peerAddress); - PTimerConjPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, int idx, etRuntime::Address addr, etRuntime::Address peerAddress); + PTimerConjPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, etRuntime::Address addr, etRuntime::Address peerAddress, bool doRegistration = true); + PTimerConjPort(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); /*--------------------- attributes ---------------------*/ @@ -120,7 +120,7 @@ class PTimerConjPort : public etRuntime::PortBase { class PTimerConjReplPort { private: int m_replication; - std::vector m_ports; + PTimerConjPort* m_ports; //dynamic array used instead of vector to avoid copy construction public: PTimerConjReplPort(etRuntime::IEventReceiver& actor, etRuntime::IRTObject* parent, std::string name, int localId, std::vector addr, std::vector peerAddress); @@ -128,7 +128,7 @@ class PTimerConjReplPort { int getReplication() { return m_replication; } int getIndexOf(const etRuntime::InterfaceItemBase& ifitem){ return ifitem.getIdx(); } - PTimerConjPort get(int i) {return m_ports.at(i);} + PTimerConjPort get(int i) {return m_ports[i];} // outgoing messages public: void startTimer(uint32 time); diff --git a/runtime/org.eclipse.etrice.runtime.cpp/.cproject b/runtime/org.eclipse.etrice.runtime.cpp/.cproject index 66d3daac4..c6d7573ce 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/.cproject +++ b/runtime/org.eclipse.etrice.runtime.cpp/.cproject @@ -54,7 +54,6 @@ - @@ -83,7 +82,7 @@ - @@ -100,8 +99,8 @@ diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.cpp index e1835e344..17593038c 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.cpp +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/debugging/DebuggingService.cpp @@ -7,6 +7,7 @@ #include "DebuggingService.h" #include "common/modelbase/ActorClassBase.h" +#include namespace etRuntime { @@ -54,6 +55,7 @@ void DebuggingService::addActorState(const ActorClassBase& actor, void DebuggingService::addPortInstance(PortBase& port) { portInstances[port.getAddress()] = &port; + std::cout << "adding " << port.getAddress().toID() << " " << &port << " " << port.getParent()->getInstancePathName()<< std::endl; } MSCLogger& DebuggingService::getSyncLogger() { diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Address.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Address.cpp index dc64afa95..aa1c49e22 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Address.cpp +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Address.cpp @@ -7,6 +7,7 @@ #include "Address.h" #include +#include namespace etRuntime { @@ -48,13 +49,13 @@ bool Address::operator< (const Address& right) const { Address::~Address() { } -std::string Address::toString(){ +std::string Address::toString() const{ std::stringstream strm; strm << "Address(nodeID=" << m_nodeID << ",threadID=" << m_threadID << ",objectID=" << m_objectID+")"; return strm.str(); } -std::string Address::toID(){ +std::string Address::toID() const{ std::stringstream strm; strm << m_nodeID << "_" << m_threadID << "_" << m_objectID; return strm.str(); @@ -64,5 +65,18 @@ Address Address::createInc(int i) { return Address(m_nodeID, m_threadID, m_objectID+i); } +void Address::printAddrVector(const std::vector >& addresses){ + std::vector >::const_iterator outerIt = addresses.begin(); + std::cout << "{" ; + for (int i=0; outerIt!= addresses.end(); ++outerIt,++i) { + std::cout << "{" ; + std::vector::const_iterator it = (*outerIt).begin(); + for (int j=0; it!=(*outerIt).end(); ++it,++j) { + std::cout << (*it).toID() << ":" << addresses[i][j].toID() << ","; + } + std::cout << "}" << std::endl; + } + std::cout << "}" << std::endl; +} } /* namespace etRuntime */ diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Address.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Address.h index 857f7daab..66a164b16 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Address.h +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/Address.h @@ -9,6 +9,7 @@ #define ADDRESS_H_ #include +#include namespace etRuntime { @@ -20,8 +21,8 @@ public: bool operator< (const Address& right) const; ~Address(); - std::string toString(); - std::string toID(); + std::string toString() const; + std::string toID()const; Address createInc(int i); bool isValid() const { @@ -32,6 +33,10 @@ public: int m_threadID; int m_objectID; + //debug helper function + static void printAddrVector(const std::vector >& addresses); + + private: }; diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.cpp index 7b38e047c..f709d47b6 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.cpp +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.cpp @@ -68,5 +68,6 @@ if (receiver!=0) // TODO: error handling for not found addresses } } + } /* namespace etRuntime */ diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.h index 2408e34e4..1a246e959 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.h +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageDispatcher.h @@ -22,6 +22,7 @@ public: MessageDispatcher(IRTObject* parent, Address addr, std::string name); void addMessageReceiver(IMessageReceiver& receiver); void receive(Message* msg); + Address getAddress() const { return m_address; }; private: diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.cpp index cbba84a92..264b4fbce 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.cpp +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.cpp @@ -21,7 +21,9 @@ MessageService::MessageService(IRTObject* parent, Address addr, std::string name Address(addr.m_nodeID, addr.m_threadID, addr.m_objectID + 1), "Dispatcher"), m_address(addr), - m_lastMessageTimestamp(0) { + m_lastMessageTimestamp(0), + m_asyncActors() +{ // check and set priority // assert priority >= Thread.MIN_PRIORITY : ("priority smaller than Thread.MIN_PRIORITY (1)"); @@ -42,6 +44,7 @@ void MessageService::run() { } void MessageService::runOnce() { + pollAsyncActors(); while (m_messageQueue.isNotEmpty()){ pollOneMessage(); } @@ -100,5 +103,17 @@ void MessageService::pollOneMessage() { } +void MessageService::addAsyncActor(IEventReceiver& evtReceiver) { + m_asyncActors.push_back(&evtReceiver); +} + +void MessageService::pollAsyncActors() { + std::vector::iterator it = m_asyncActors.begin(); + for ( ; it != m_asyncActors.end(); ++it) { + // polling event + (*it)->receiveEvent(0,0,0); + } +} + } /* namespace etRuntime */ diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h index 75fbff240..a9d25cb62 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageService.h @@ -9,8 +9,10 @@ #define MESSAGESERVICE_H_ #include +#include #include "common/messaging/MessageDispatcher.h" #include "common/messaging/Address.h" +#include "common/modelbase/IEventReceiver.h" #include "MessageSeQueue.h" namespace etRuntime { @@ -38,6 +40,10 @@ public: virtual std::string getInstancePathName() const ; virtual bool isMsgService() const { return true;}; + void addAsyncActor(IEventReceiver& evtReceiver); + void pollAsyncActors(); + + // protected methods for sole use by test cases protected: MessageSeQueue& getMessageQueue() { return m_messageQueue; } @@ -59,6 +65,8 @@ private: Address m_address; long m_lastMessageTimestamp; + std::vector m_asyncActors; + MessageService(); MessageService(const MessageService& right); MessageService& operator=(const MessageService& right); diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp index 3a47e7d57..e095ed02b 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.cpp @@ -108,7 +108,7 @@ void MessageServiceController::runOnce() { if (!m_running) { return; } - m_running = false; + //m_running = false; // terminate all message services for (std::vector::iterator it = m_messageServiceList.begin(); diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h index 57fd7cb10..a0668838c 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/MessageServiceController.h @@ -26,6 +26,9 @@ public: //raises an exception if the service does not exist for this threadID MessageService* getMsgSvc(int threadID); + void addAsyncActor(IEventReceiver& evtReceiver); + void pollAsyncActors(); + //the connectAll method connects all messageServices //it is included for test purposes //currently it is not called diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTSystemServicesProtocol.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTSystemServicesProtocol.cpp index 24fd082b3..5b2bc9f74 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTSystemServicesProtocol.cpp +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTSystemServicesProtocol.cpp @@ -44,17 +44,21 @@ RTSystemServicesProtocol::~RTSystemServicesProtocol() { //------------------------------------------------------------------ RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IEventReceiver& actor, IRTObject* parent, std::string name, - int localId, Address addr, Address peerAddress) + int localId, Address addr, Address peerAddress, bool doRegistration) :PortBase(actor, parent, name, localId, 0, addr, peerAddress) { - DebuggingService::getInstance().addPortInstance(*this); + if (doRegistration) { + DebuggingService::getInstance().addPortInstance(*this); + } }; RTSystemServicesProtocolPort::RTSystemServicesProtocolPort(IEventReceiver& actor, IRTObject* parent, std::string name, - int localId, int idx, Address addr, Address peerAddress) + int localId, int idx, Address addr, Address peerAddress, bool doRegistration) : PortBase(actor, parent, name, localId, idx, addr, peerAddress) { - DebuggingService::getInstance().addPortInstance(*this); + if (doRegistration) { + DebuggingService::getInstance().addPortInstance(*this); + } }; void RTSystemServicesProtocolPort::receive(Message* msg) { @@ -65,7 +69,7 @@ void RTSystemServicesProtocolPort::receive(Message* msg) { if (msg->hasDebugFlagSet()) { // TODO: model switch for activation of this flag DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), RTSystemServicesProtocol::getMessageString(msg->getEvtId())); } - getActor().receiveEvent(*this, msg->getEvtId(), msg->getData()); + getActor().receiveEvent(this, msg->getEvtId(), msg->getData()); } }; @@ -89,14 +93,19 @@ RTSystemServicesProtocolPortRepl(IEventReceiver& actor, IRTObject* parent, std:: { char numstr[10]; // enough to hold all numbers up to 32-bits - m_ports.reserve(m_replication); + //m_ports.reserve(m_replication); + m_ports = reinterpret_cast (new char[sizeof(RTSystemServicesProtocolPort) * addr.size()]); + for (int i = 0; i < m_replication; ++i) { snprintf(numstr, sizeof(numstr), "%d", i); - m_ports.push_back(RTSystemServicesProtocolPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i])); - } - for (int i = 0; i < m_replication; ++i) { - DebuggingService::getInstance().addPortInstance(m_ports.at(i)); + new (&m_ports[i]) RTSystemServicesProtocolPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]); + + //m_ports.push_back(std::auto_ptr_ref(new RTSystemServicesProtocolPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i], false))); + //m_ports[i] = std::auto_ptr(new RTSystemServicesProtocolPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i])); } +// for (int i = 0; i < m_replication; ++i) { +// DebuggingService::getInstance().addPortInstance(m_ports.at(i)); +// } }; @@ -104,7 +113,7 @@ RTSystemServicesProtocolPortRepl(IEventReceiver& actor, IRTObject* parent, std:: void RTSystemServicesProtocolPortRepl::dummy() { for (int i = 0; i < m_replication; ++i) { - m_ports.at(i).dummy(); + m_ports[i].dummy(); } }; @@ -113,17 +122,21 @@ void RTSystemServicesProtocolPortRepl::dummy() { //------------------------------------------------------------------ RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IEventReceiver& actor, IRTObject* parent, - std::string name, int localId, Address addr, Address peerAddress) + std::string name, int localId, Address addr, Address peerAddress, bool doRegistration) : PortBase(actor, parent, name, localId, 0, addr, peerAddress) { - DebuggingService::getInstance().addPortInstance(*this); + if (doRegistration) { + DebuggingService::getInstance().addPortInstance(*this); + } } RTSystemServicesProtocolConjPort::RTSystemServicesProtocolConjPort(IEventReceiver& actor, IRTObject* parent, std::string name, int localId, int idx, Address addr, - Address peerAddress) + Address peerAddress, bool doRegistration) : PortBase(actor, parent, name, localId, idx, addr, peerAddress) { - DebuggingService::getInstance().addPortInstance(*this); + if (doRegistration) { + DebuggingService::getInstance().addPortInstance(*this); + } } void RTSystemServicesProtocolConjPort::receive(Message* msg) { @@ -134,7 +147,7 @@ void RTSystemServicesProtocolConjPort::receive(Message* msg) { if (msg->hasDebugFlagSet()) { // TODO: model switch for activation of this flag DebuggingService::getInstance().addMessageAsyncIn(getPeerAddress(), getAddress(), RTSystemServicesProtocol::getMessageString(msg->getEvtId())); } - getActor().receiveEvent(*this, msg->getEvtId(), msg->getData()); + getActor().receiveEvent(this, msg->getEvtId(), msg->getData()); } } @@ -169,14 +182,11 @@ RTSystemServicesProtocolConjPortRepl(IEventReceiver& actor, IRTObject* parent, s m_ports() { char numstr[10]; // enough to hold all numbers up to 32-bits - - m_ports.reserve(m_replication); + m_ports = reinterpret_cast (new char[sizeof(RTSystemServicesProtocolConjPort) * addr.size()]); for (int i = 0; i < m_replication; ++i) { snprintf(numstr, sizeof(numstr), "%d", i); - m_ports.push_back(RTSystemServicesProtocolConjPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i])); - } - for (int i = 0; i < m_replication; ++i) { - DebuggingService::getInstance().addPortInstance(m_ports.at(i)); + //placement new to avoid copy construction, therefore no vector is used + new (&m_ports[i]) RTSystemServicesProtocolConjPort(actor, parent, name + numstr, localId, i, addr[i], peerAddress[i]); } }; @@ -185,19 +195,19 @@ RTSystemServicesProtocolConjPortRepl(IEventReceiver& actor, IRTObject* parent, s void RTSystemServicesProtocolConjPortRepl::executeInitialTransition() { for (int i = 0; i < m_replication; ++i) { - m_ports.at(i).executeInitialTransition(); + m_ports[i].executeInitialTransition(); } } void RTSystemServicesProtocolConjPortRepl::startDebugging() { for (int i = 0; i < m_replication; ++i) { - m_ports.at(i).startDebugging(); + m_ports[i].startDebugging(); } } void RTSystemServicesProtocolConjPortRepl::stopDebugging() { for (int i = 0; i < m_replication; ++i) { - m_ports.at(i).stopDebugging(); + m_ports[i].stopDebugging(); } } diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTSystemServicesProtocol.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTSystemServicesProtocol.h index ef1bf8d60..f8852c5ca 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTSystemServicesProtocol.h +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/messaging/RTSystemServicesProtocol.h @@ -13,6 +13,7 @@ #include "common/messaging/Address.h" #include #include +#include namespace etRuntime { @@ -72,10 +73,10 @@ public: class RTSystemServicesProtocolPort : public PortBase , public IRTSystemServicesProtocolPort { public: RTSystemServicesProtocolPort(IEventReceiver& actor, IRTObject* parent, std::string name, - int localId, Address addr, Address peerAddress); + int localId, Address addr, Address peerAddress, bool doRegistration = true); RTSystemServicesProtocolPort(IEventReceiver& actor, IRTObject* parent, std::string name, - int localId, int idx, Address addr, Address peerAddress); + int localId, int idx, Address addr, Address peerAddress, bool doRegistration = true); virtual void receive(Message* m); // sent messages @@ -88,7 +89,7 @@ public: class RTSystemServicesProtocolPortRepl: public IRTSystemServicesProtocolPort { private: int m_replication; - std::vector m_ports; + RTSystemServicesProtocolPort* m_ports; public: //TODO: data type of addr and peerAddress? @@ -96,7 +97,7 @@ public: const std::vector
& addr, const std::vector
peerAddress); int getReplication() const { return m_replication; } ; - RTSystemServicesProtocolPort& get(int i) { return m_ports.at(i); }; + RTSystemServicesProtocolPort& get(int i) { return m_ports[i]; }; // outgoing messages void dummy(); }; @@ -108,10 +109,10 @@ public: class RTSystemServicesProtocolConjPort : public PortBase, public IRTSystemServicesProtocolConjPort{ public: RTSystemServicesProtocolConjPort(IEventReceiver& actor, IRTObject* parent, - std::string name, int localId, Address addr, Address peerAddress); + std::string name, int localId, Address addr, Address peerAddress, bool doRegistration = true); RTSystemServicesProtocolConjPort(IEventReceiver& actor, IRTObject* parent, std::string name, int localId, int idx, Address addr, - Address peerAddress); + Address peerAddress, bool doRegistration = true); virtual void receive(Message* m); void executeInitialTransition(); @@ -125,7 +126,7 @@ public: class RTSystemServicesProtocolConjPortRepl : public IRTSystemServicesProtocolConjPort{ private: int m_replication; - std::vector m_ports; + RTSystemServicesProtocolConjPort* m_ports; //dynamic array used instead of vector to avoid copy construction public: //TODO: data type of addr and peerAddress @@ -133,7 +134,7 @@ public: const std::vector
& addr, const std::vector
& peerAddress); int getReplication() const { return m_replication; } ; - RTSystemServicesProtocolConjPort& get(int i) { return m_ports.at(i); }; + RTSystemServicesProtocolConjPort& get(int i) { return m_ports[i]; }; void executeInitialTransition(); void startDebugging(); diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.cpp index b3805dc3d..1a7879f3a 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.cpp +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.cpp @@ -28,8 +28,8 @@ ActorClassBase::~ActorClassBase() { m_RTSystemPort = 0; } -bool ActorClassBase::handleSystemEvent(const InterfaceItemBase& ifitem, int evt, void* generic_data) { - if (ifitem.getLocalId() != 0) { +bool ActorClassBase::handleSystemEvent(InterfaceItemBase* ifitem, int evt, void* generic_data) { + if ((ifitem != 0) && (ifitem->getLocalId() != 0)) { return false; } @@ -41,6 +41,8 @@ bool ActorClassBase::handleSystemEvent(const InterfaceItemBase& ifitem, int evt, break; case RTSystemServicesProtocol::IN_stopDebugging: break; + default: + return false; } return true; } diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.h index 2a7de727a..85cc8f136 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.h +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/ActorClassBase.h @@ -61,7 +61,7 @@ protected: int m_state; RTSystemServicesProtocolPort* m_RTSystemPort; - virtual bool handleSystemEvent(const InterfaceItemBase& ifitem, int evt, void* generic_data); + virtual bool handleSystemEvent(InterfaceItemBase* ifitem, int evt, void* generic_data); private: std::string m_className; Address m_ownAddr; diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/IEventReceiver.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/IEventReceiver.h index 52ebb937a..c6966c38b 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/IEventReceiver.h +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/IEventReceiver.h @@ -18,7 +18,7 @@ public: IEventReceiver(); virtual ~IEventReceiver(); - virtual void receiveEvent(const InterfaceItemBase& ifitem, int evt, void* data) = 0; + virtual void receiveEvent(InterfaceItemBase* ifitem, int evt, void* data) = 0; }; diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.cpp b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.cpp index 90b642585..f3e91ad77 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.cpp +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/modelbase/SubSystemRunnerBase.cpp @@ -7,6 +7,7 @@ #include "SubSystemRunnerBase.h" #include "SubSystemClassBase.h" +#include "common/platform/etTimer.h" namespace etRuntime { @@ -28,7 +29,12 @@ void SubSystemRunnerBase::waitMultiThreaded() { } void SubSystemRunnerBase::waitAndPollSingleThreaded(SubSystemClassBase& mainComponent) { - mainComponent.runOnce(); + for (int i=0; i< 100; ++i) { + if (etTimer_executeNeeded()) { + mainComponent.runOnce(); + } + Sleep(100); + } std::string token = ""; std::cout << "type 'quit' to exit" << std::endl; diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/common/platform/etTimer.h b/runtime/org.eclipse.etrice.runtime.cpp/src/common/platform/etTimer.h index 0d212c593..4f2c25bb9 100644 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/common/platform/etTimer.h +++ b/runtime/org.eclipse.etrice.runtime.cpp/src/common/platform/etTimer.h @@ -20,6 +20,9 @@ typedef struct etTargetTime { unsigned long sec; } etTargetTime_t; +#ifdef __cplusplus +extern "C" { +#endif void etTimer_init(void); uint32 getNSecFromTarget(void); @@ -37,4 +40,7 @@ uint32 getTimeBaseUS(void); uint32 getTimeBaseMS(void); +#ifdef __cplusplus +} +#endif #endif /* __ETTIMER_H__ */ diff --git a/runtime/org.eclipse.etrice.runtime.cpp/src/platforms/generic/etTimer.c b/runtime/org.eclipse.etrice.runtime.cpp/src/platforms/generic/etTimer.c deleted file mode 100644 index 39989b4c9..000000000 --- a/runtime/org.eclipse.etrice.runtime.cpp/src/platforms/generic/etTimer.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "common/platform/etTimer.h" - -#include - -#include "config/etRuntimeConfig.h" - -void etTimer_init(void){ -} - -uint64 getTargetTimeUs(void){ - struct timeval currentTime; - gettimeofday(¤tTime, NULL); - - return currentTime.tv_sec * 1000000L + currentTime.tv_usec; -} - -etBool etTimer_executeNeeded(void){ - - static uint64 lastTime = 0L; - - uint64 currentTime = getTargetTimeUs(); - - uint64 timestep = 1000000L/FREQUENCY; - - if (currentTime >= lastTime + timestep) { - lastTime = currentTime; - return TRUE; - } - else { - return FALSE; - } -} - -void getTimeFromTarget(etTargetTime_t *t){ - struct timeval currentTime; - gettimeofday(¤tTime, NULL); - t->sec = currentTime.tv_sec; - t->nSec = currentTime.tv_usec*1000; -} -- cgit v1.2.3