Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Belle2016-10-07 07:43:11 +0000
committerJan Belle2016-10-07 10:15:04 +0000
commit6a2dc3b10e15050fd488514656e1c30902393437 (patch)
tree738d096fb3b632ec680c22f0c7b6888747f62794 /plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp
parent5401d4aee22c108a672d5f0724b54c9c3f847fcd (diff)
downloadorg.eclipse.etrice-6a2dc3b10e15050fd488514656e1c30902393437.tar.gz
org.eclipse.etrice-6a2dc3b10e15050fd488514656e1c30902393437.tar.xz
org.eclipse.etrice-6a2dc3b10e15050fd488514656e1c30902393437.zip
[runtime.cpp] Refactored cpp runtime
- Refactored initialization process - Fixed RTObject double deleting children - Sub actors are now static members - Added ReplicatedActorClassBase for replicated actors [generator.cpp] Modified ActorClassGen and NodeGen to fit the runtime changes Change-Id: I172bcae0cba98234d61c8e741b23be6604cc6131
Diffstat (limited to 'plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp')
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend114
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend128
-rw-r--r--plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ProtocolClassGen.xtend14
3 files changed, 194 insertions, 62 deletions
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/ActorClassGen.xtend
index 8251fcec9..e1228095b 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
@@ -16,7 +16,6 @@ import com.google.inject.Inject
import com.google.inject.Singleton
import java.util.Map
import org.eclipse.etrice.core.fsm.fSM.ComponentCommunicationType
-import org.eclipse.etrice.core.genmodel.builder.GenmodelConstants
import org.eclipse.etrice.core.genmodel.etricegen.ExpandedActorClass
import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.genmodel.etricegen.WiredActorClass
@@ -73,6 +72,7 @@ class ActorClassGen extends GenericActorClassGenerator {
#include "common/etDatatypesCpp.hpp"
#include "common/messaging/IRTObject.h"
#include "common/modelbase/PortBase.h"
+ #include "common/modelbase/ReplicatedActorClassBase.h"
#include "common/modelbase/InterfaceItemBase.h"
#include "common/modelbase/SubSystemClassBase.h"
#include "common/messaging/Address.h"
@@ -92,6 +92,9 @@ class ActorClassGen extends GenericActorClassGenerator {
«ELSE»
#include "«ac.actorBase.path»«ac.actorBase.name».h"
«ENDIF»
+ «FOR ar : ac.actorRefs»
+ #include "«ar.type.actorIncludePath»"
+ «ENDFOR»
«ac.userCode1.userCode»
@@ -108,6 +111,15 @@ class ActorClassGen extends GenericActorClassGenerator {
«ep.getPortClassName» «ep.name»;
«ENDFOR»
+ //--------------------- sub actors
+ «FOR sub : ac.actorRefs»
+ «IF sub.multiplicity > 1»
+ Replicated«sub.type.implementationClassName» «sub.name»;
+ «ELSE»
+ «sub.type.implementationClassName» «sub.name»;
+ «ENDIF»
+ «ENDFOR»
+
//--------------------- saps
«FOR sap : ac.serviceAccessPoints»
«sap.getPortClassName» «sap.name»;
@@ -128,6 +140,10 @@ class ActorClassGen extends GenericActorClassGenerator {
public:
//--------------------- construction
«ac.name»(etRuntime::IRTObject* parent, const std::string& name);
+ void initialize(void);
+ «IF Main::settings.generateMSCInstrumentation»
+ void setProbesActive(bool recursive, bool active);
+ «ENDIF»
««« TODO: check whether attribute setters/getters are necessary at all, if yes own cpp implementation is needed for *,[],& variables
««« «attributeSettersGettersImplementation(ac.attributes, ac.name)»
@@ -162,6 +178,17 @@ class ActorClassGen extends GenericActorClassGenerator {
};
+ class Replicated«clsname» : public ReplicatedActorClassBase {
+ public:
+ Replicated«clsname»(IRTObject* parent, const std::string& name) :
+ ReplicatedActorClassBase(parent, name) {}
+
+ protected:
+ ActorClassBase* createActor(IRTObject* parent, const std::string& name) {
+ return new «clsname»(parent, name);
+ }
+ };
+
«ac.generateNamespaceEnd»
«generateIncludeGuardEnd(ac, '')»
@@ -176,6 +203,8 @@ class ActorClassGen extends GenericActorClassGenerator {
initList += '''«ac.actorBase?.name ?: 'ActorClassBase'»(parent, name)'''
// own ports
initList += ac.endPorts.map['''«name»(this, "«name»", IFITEM_«name»)''']
+ // own sub actors
+ initList += ac.actorRefs.map['''«name»(this, "«name»")''']
// own saps
initList += ac.serviceAccessPoints.map['''«name»(this, "«name»", IFITEM_«name»)''']
// own service implementations
@@ -205,10 +234,8 @@ class ActorClassGen extends GenericActorClassGenerator {
#include "common/messaging/RTObject.h"
#include "common/messaging/RTServices.h"
-
- «FOR ar : ac.actorRefs»
- #include "«ar.type.actorIncludePath»"
- «ENDFOR»
+ #include "common/debugging/DebuggingService.h"
+ #include "common/debugging/MSCFunctionObject.h"
using namespace etRuntime;
@@ -217,6 +244,10 @@ class ActorClassGen extends GenericActorClassGenerator {
«clsname»::«clsname»(etRuntime::IRTObject* parent, const std::string& name)
«ac.generateConstructorInitalizerList»
{
+ «IF Main::settings.generateMSCInstrumentation»
+ MSCFunctionObject mscFunctionObject(getInstancePathName(), "Constructor");
+ «ENDIF»
+
«IF ac.hasNonEmptyStateMachine»
for (int i = 0; i < s_numberOfStates; i++) {
history[i] = NO_STATE;
@@ -227,20 +258,34 @@ class ActorClassGen extends GenericActorClassGenerator {
// sub actors
«FOR sub : ac.actorRefs»
«IF sub.multiplicity>1»
- for (int i=0; i<«sub.multiplicity»; ++i) {
- «IF Main::settings.generateMSCInstrumentation»
- DebuggingService::getInstance().addMessageActorCreate(*this, "«sub.name»«GenmodelConstants::INDEX_SEP»"+i);
- «ENDIF»
- new «sub.type.implementationClassName»(this, "«sub.name»«GenmodelConstants::INDEX_SEP»"+i);
- }
- «ELSE»
- «IF Main::settings.generateMSCInstrumentation»
- DebuggingService::getInstance().addMessageActorCreate(*this, "«sub.name»");
- «ENDIF»
- new «sub.type.implementationClassName»(this, "«sub.name»");
+ «sub.name».createSubActors(«sub.multiplicity»);
«ENDIF»
«ENDFOR»
+ «initHelper.genExtraInitializers(ac.attributes)»
+ «ac.userStructorBody(true)»
+ }
+
+ void «ac.name»::initialize() {
+ «IF Main::settings.generateMSCInstrumentation»
+ MSCFunctionObject mscFunctionObject(getInstancePathName(), "initialize()");
+ «FOR sub : ac.actorRefs»
+ «IF sub.multiplicity > 1»
+ for (int i=0; i<«sub.multiplicity»; ++i) {
+ DebuggingService::getInstance().addMessageActorCreate(*this, «sub.name».getSubActor(i)->getName());
+ }
+ «ELSE»
+ DebuggingService::getInstance().addMessageActorCreate(*this, "«sub.name»");
+ «ENDIF»
+ «ENDFOR»
+ «ENDIF»
+
+ ActorClassBase::initialize();
+
+ «FOR sub : ac.actorRefs»
+ «sub.name».initialize();
+ «ENDFOR»
+
// wiring
«FOR wire: wired.wires»
«if (wire.dataDriven) "DataPortBase" else "InterfaceItemBase"»::connect(this, "«wire.path1.join('/')»", "«wire.path2.join('/')»");
@@ -250,12 +295,43 @@ class ActorClassGen extends GenericActorClassGenerator {
// activate polling for data-driven communication
RTServices::getInstance().getMsgSvcCtrl().getMsgSvc(getThread())->addPollingMessageReceiver(*this);
«ENDIF»
-
- «initHelper.genExtraInitializers(ac.attributes)»
- «ac.userStructorBody(true)»
}
+
+ «IF Main::settings.generateMSCInstrumentation»
+ void «ac.name»::setProbesActive(bool recursive, bool active) {
+ DebuggingService::getInstance().addPortInstance(m_RTSystemPort);
+ «IF ac.actorRefs.size > 0»
+ if(recursive) {
+ «FOR sub : ac.actorRefs»
+ «sub.name».setProbesActive(recursive, active);
+ «ENDFOR»
+ }
+ «ENDIF»
+ «FOR ep : ac.endPorts»
+ «IF !ep.dataDriven»
+ «IF ep.replicated»
+ for(int i = 0; i < «ep.name».getNInterfaceItems(); i++)
+ DebuggingService::getInstance().addPortInstance(*(«ep.name».getInterfaceItem(i)));
+ «ELSE»
+ DebuggingService::getInstance().addPortInstance(«ep.name»);
+ «ENDIF»
+ «ENDIF»
+ «ENDFOR»
+ «FOR sap : ac.serviceAccessPoints»
+ DebuggingService::getInstance().addPortInstance(«sap.name»);
+ «ENDFOR»
+ «FOR spp : ac.serviceProvisionPoints»
+ for(int i = 0; i < «spp.name».getNInterfaceItems(); i++)
+ DebuggingService::getInstance().addPortInstance(*(«spp.name».getInterfaceItem(i)));
+ «ENDFOR»
+ }
+ «ENDIF»
void «ac.name»::destroy(){
+ «IF Main::settings.generateMSCInstrumentation»
+ MSCFunctionObject mscFunctionObject(getInstancePathName(), "destroy()");
+ «ENDIF»
+
«ac.userStructorBody(false)»
«IF Main::settings.generateMSCInstrumentation»
DebuggingService::getInstance().addMessageActorDestroy(*this);
diff --git a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend
index eb071adf9..2635252f8 100644
--- a/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend
+++ b/plugins/org.eclipse.etrice.generator.cpp/src/org/eclipse/etrice/generator/cpp/gen/NodeGen.xtend
@@ -16,14 +16,13 @@ import com.google.inject.Inject
import com.google.inject.Singleton
import java.util.Collection
import java.util.Map
+import org.eclipse.etrice.core.common.converter.TimeConverter
import org.eclipse.etrice.core.etmap.util.ETMapUtil
import org.eclipse.etrice.core.etphys.eTPhys.ExecMode
import org.eclipse.etrice.core.etphys.eTPhys.PhysicalThread
-import org.eclipse.etrice.core.genmodel.builder.GenmodelConstants
import org.eclipse.etrice.core.genmodel.etricegen.Root
import org.eclipse.etrice.core.genmodel.etricegen.SubSystemInstance
import org.eclipse.etrice.core.genmodel.etricegen.WiredSubSystemClass
-import org.eclipse.etrice.core.genmodel.fsm.fsmgen.IDiagnostician
import org.eclipse.etrice.core.room.SubSystemClass
import org.eclipse.etrice.generator.cpp.Main
import org.eclipse.etrice.generator.fsm.base.FileSystemHelpers
@@ -32,7 +31,6 @@ import org.eclipse.etrice.generator.generic.ProcedureHelpers
import org.eclipse.etrice.generator.generic.RoomExtensions
import static extension org.eclipse.etrice.generator.fsm.base.Indexed.*
-import org.eclipse.etrice.core.common.converter.TimeConverter
@Singleton
class NodeGen {
@@ -41,9 +39,9 @@ class NodeGen {
@Inject extension RoomExtensions
@Inject extension ProcedureHelpers
@Inject extension FileSystemHelpers
-
+
@Inject IGeneratorFileIo fileIO
- @Inject IDiagnostician diagnostician
+ @Inject Initialization initHelper
def doGenerate(Root root) {
val Map<SubSystemClass, WiredSubSystemClass> sscc2wired = newHashMap
@@ -86,6 +84,9 @@ class NodeGen {
«generateIncludeGuardBegin(cc, '')»
#include "common/modelbase/SubSystemClassBase.h"
+ «FOR ai : comp.actorInstances»
+ #include "«ai.actorClass.actorIncludePath»"
+ «ENDFOR»
««« «FOR model : root.getReferencedModels(cc)»
««« ««« #include "«model.name».h"
@@ -104,11 +105,25 @@ class NodeGen {
static const int «thread.value.threadId»;
«ENDFOR»
+ // sub actors
+ «FOR sub : cc.actorRefs»
+ «IF sub.multiplicity>1»
+ Replicated«sub.type.implementationClassName» «sub.name»;
+ «ELSE»
+ «sub.type.implementationClassName» «sub.name»;
+ «ENDIF»
+ «ENDFOR»
+
«clsname»(IRTObject* parent, const std::string& name);
+ ~«clsname»();
virtual void receiveEvent(etRuntime::InterfaceItemBase* ifitem, int evt, void* data);
virtual void instantiateMessageServices();
- virtual void instantiateActors();
+ virtual void mapThreads(void);
+ virtual void initialize(void);
+ «IF Main::settings.generateMSCInstrumentation»
+ virtual void setProbesActive(bool recursive, bool active);
+ «ENDIF»
virtual void init();
@@ -134,6 +149,18 @@ class NodeGen {
"THREAD_"+thread.name.toUpperCase
}
+ def private generateConstructorInitalizerList(SubSystemClass cc) {
+ val extension initHelper = initHelper
+ var initList = <CharSequence>newArrayList
+
+ // super class
+ initList += '''SubSystemClassBase(parent, name)'''
+ // own sub actors
+ initList += cc.actorRefs.map['''«name»(this, "«name»")''']
+
+ initList.generateCtorInitializerList
+ }
+
def generateSourceFile(Root root, SubSystemInstance comp, WiredSubSystemClass wired, Collection<PhysicalThread> usedThreads) {
val cc = comp.subSystemClass
val models = root.getReferencedModels(cc)
@@ -152,16 +179,13 @@ class NodeGen {
#include "«getCppHeaderFileName(nr, comp)»"
#include "common/debugging/DebuggingService.h"
+ #include "common/debugging/MSCFunctionObject.h"
#include "common/messaging/IMessageService.h"
#include "common/messaging/MessageService.h"
#include "common/messaging/MessageServiceController.h"
#include "common/messaging/RTServices.h"
#include "common/modelbase/InterfaceItemBase.h"
- «FOR ai : comp.actorInstances»
- #include "«ai.actorClass.actorIncludePath»"
- «ENDFOR»
-
using namespace etRuntime;
«cc.generateNamespaceBegin»
@@ -170,9 +194,23 @@ class NodeGen {
const int «clsname»::«thread.value.threadId» = «thread.index0»;
«ENDFOR»
- «clsname»::«clsname»(IRTObject* parent, const std::string& name) :
- SubSystemClassBase(parent, name)
+ «clsname»::«clsname»(IRTObject* parent, const std::string& name)
+ «cc.generateConstructorInitalizerList»
{
+ «IF Main::settings.generateMSCInstrumentation»
+ MSCFunctionObject mscFunctionObject(getInstancePathName(), "Constructor");
+ «ENDIF»
+ «FOR sub : cc.actorRefs»
+ «IF sub.multiplicity>1»
+ «sub.name».createSubActors(«sub.multiplicity»);
+ «ENDIF»
+ «ENDFOR»
+ }
+
+ «clsname»::~«clsname»() {
+ «IF Main::settings.generateMSCInstrumentation»
+ MSCFunctionObject mscFunctionObject(getInstancePathName(), "Destructor");
+ «ENDIF»
}
void «clsname»::receiveEvent(InterfaceItemBase* ifitem, int evt, void* data){
@@ -180,6 +218,10 @@ class NodeGen {
void «clsname»::instantiateMessageServices(){
+ «IF Main::settings.generateMSCInstrumentation»
+ MSCFunctionObject mscFunctionObject(getInstancePathName(), "instantiateMessageServices()");
+ «ENDIF»
+
IMessageService* msgService;
«FOR thread: threads»
{
@@ -197,8 +239,7 @@ class NodeGen {
«ENDFOR»
}
- void «clsname»::instantiateActors(){
-
+ void «clsname»::mapThreads() {
// thread mappings
«FOR ai : comp.allContainedInstances»
«val mapped = ETMapUtil::getMappedThread(ai)»
@@ -206,34 +247,47 @@ class NodeGen {
addPathToThread("«ai.path»", «mapped.thread.threadId»);
«ENDIF»
«ENDFOR»
+ }
- // sub actors
- «FOR sub : cc.actorRefs»
- «IF sub.multiplicity>1»
- for (int i=0; i<«sub.multiplicity»; ++i) {
- «IF Main::settings.generateMSCInstrumentation»
- DebuggingService::getInstance().addMessageActorCreate(*this, "«sub.name»«GenmodelConstants::INDEX_SEP»"+i);
- «ENDIF»
- new «sub.type.implementationClassName»(this, "«sub.name»«GenmodelConstants::INDEX_SEP»"+i);
- }
- «ELSE»
- «IF Main::settings.generateMSCInstrumentation»
+ void «clsname»::initialize() {
+ «IF Main::settings.generateMSCInstrumentation»
+ DebuggingService::getInstance().getSyncLogger().addVisibleComment("starting initialization");
+ MSCFunctionObject mscFunctionObject(getInstancePathName(), "initialize()");
+ «FOR sub : cc.actorRefs»
+ «IF sub.multiplicity>1»
+ for (int i=0; i<«sub.multiplicity»; ++i) {
+ DebuggingService::getInstance().addMessageActorCreate(*this, «sub.name».getSubActor(i)->getName());
+ }
+ «ELSE»
DebuggingService::getInstance().addMessageActorCreate(*this, "«sub.name»");
«ENDIF»
- new «sub.type.implementationClassName»(this, "«sub.name»");
- «ENDIF»
- «ENDFOR»
-
+ «ENDFOR»
+ «ENDIF»
+
// wiring
«FOR wire: wired.wires»
«if (wire.dataDriven) "DataPortBase" else "InterfaceItemBase"»::connect(this, "«wire.path1.join('/')»", "«wire.path2.join('/')»");
«ENDFOR»
+
+ // call initialize of sub actors
+ «FOR sub : cc.actorRefs»
+ «sub.name».initialize();
+ «ENDFOR»
}
+
+ «IF Main::settings.generateMSCInstrumentation»
+ void «clsname»::setProbesActive(bool recursive, bool active) {
+ for(int i = 0; i < m_RTSystemPort.getNInterfaceItems(); i++)
+ DebuggingService::getInstance().addPortInstance(*(m_RTSystemPort.getInterfaceItem(i)));
+ if(recursive) {
+ «FOR sub : cc.actorRefs»
+ «sub.name».setProbesActive(recursive, active);
+ «ENDFOR»
+ }
+ }
+ «ENDIF»
void «clsname»::init(){
- «IF Main::settings.generateMSCInstrumentation»
- DebuggingService::getInstance().addVisibleComment("begin sub system initialization");
- «ENDIF»
SubSystemClassBase::init();
«IF Main::settings.generateMSCInstrumentation»
DebuggingService::getInstance().addVisibleComment("done sub system initialization");
@@ -242,9 +296,15 @@ class NodeGen {
«IF Main::settings.generateMSCInstrumentation»
void «clsname»::destroy() {
- DebuggingService::getInstance().addVisibleComment("begin sub system destruction");
+ «IF Main::settings.generateMSCInstrumentation»
+ DebuggingService::getInstance().getSyncLogger().addVisibleComment("starting destruction");
+ MSCFunctionObject mscFunctionObject(getInstancePathName(), "destroy()");
+ DebuggingService::getInstance().addVisibleComment("begin sub system destruction");
+ «ENDIF»
SubSystemClassBase::destroy();
- DebuggingService::getInstance().addVisibleComment("done sub system destruction");
+ «IF Main::settings.generateMSCInstrumentation»
+ DebuggingService::getInstance().addVisibleComment("done sub system destruction");
+ «ENDIF»
}
«ENDIF»
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 ca48d5106..b588e276e 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
@@ -62,7 +62,6 @@ class ProtocolClassGen extends GenericProtocolClassGenerator {
case CommunicationType::SYNCHRONOUS:
logger.logError("synchronous protocols not supported yet", pc)
}
-
}
}
@@ -200,6 +199,7 @@ class ProtocolClassGen extends GenericProtocolClassGenerator {
#include "«pc.getCppHeaderFileName»"
#include "common/debugging/DebuggingService.h"
+ #include "common/debugging/MSCFunctionObject.h"
#include "common/messaging/AbstractMessageReceiver.h"
#include "common/messaging/Address.h"
#include "common/messaging/Message.h"
@@ -247,18 +247,12 @@ class ProtocolClassGen extends GenericProtocolClassGenerator {
«portClassName»::«portClassName»(IInterfaceItemOwner* actor, const std::string& name, int localId)
«pclass.generateConstructorInitalizerList('0')»
{
- «IF Main::settings.generateMSCInstrumentation»
- DebuggingService::getInstance().addPortInstance(*this);
- «ENDIF»
}
«portClassName»::«portClassName»(IInterfaceItemOwner* actor, const std::string& name, int localId, int idx)
«pclass.generateConstructorInitalizerList('idx')»
{
«IF pclass != null»«initHelper.genExtraInitializers(pclass.attributes)»«ENDIF»
- «IF Main::settings.generateMSCInstrumentation»
- DebuggingService::getInstance().addPortInstance(*this);
- «ENDIF»
}
«IF Main::settings.generateMSCInstrumentation»
@@ -372,8 +366,10 @@ class ProtocolClassGen extends GenericProtocolClassGenerator {
«FOR command : hdlr.detailCode.lines» «command»
«ENDFOR»
«ELSE»
- DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
- «portClassName»::getMessageString(«portClassName»::«dir»_«m.name»));
+ «IF Main::settings.generateMSCInstrumentation»
+ DebuggingService::getInstance().addMessageAsyncOut(getAddress(), getPeerAddress(),
+ «portClassName»::getMessageString(«portClassName»::«dir»_«m.name»));
+ «ENDIF»
if (getPeerAddress().isValid()){
getPeerMsgReceiver()->receive(«message»);
}

Back to the top