Browse Source

Added singleton handling

jos.itemis@gmail.com 13 years ago
parent
commit
01f173ef4b

+ 3 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Constants.ext

@@ -2,4 +2,6 @@ String getBoolTrue() : "bool_true";
 String getBoolFalse() : "bool_false";
 String getLicenseFeature() : "licenseHeader";
 String getLicenseText() : "licenseText";
-
+String getCCodeFeature() : "CCodeFeature";
+String getSingleton() : "Singleton";
+Boolean getSingletonDefault() : false;

+ 104 - 101
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomStatemachineC.xpt

@@ -10,6 +10,7 @@ Templates for the main statechart c file.
 «IMPORT stext»
 «IMPORT sgraph»
 «IMPORT ecore»
+«IMPORT genmodel»
 
 «IMPORT org::yakindu::sct::generator::c::templates»
 
@@ -18,14 +19,14 @@ Templates for the main statechart c file.
 «EXTENSION org::yakindu::sct::generator::c::templates::Naming»
  
 «DEFINE ActionCode FOR Step»
-/* ActionCode for Step not defined */
+#warning ActionCode for Step not defined 
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR StateSwitch»
 «IF this.comment != null»
 /* «this.comment» */
 «ENDIF»
-	switch(((StatemachineBase*)handle)->state[0/* TODO: must be set correctly */]) {
+	switch(((StatemachineBase*)«statemachineHandleName()»)->state[0/* TODO: must be set correctly */]) {
 «FOREACH this.cases AS caseid»
   case _«caseid.state.simpleName» : {
   «EXPAND ActionCode FOR caseid.step»
@@ -41,13 +42,13 @@ Templates for the main statechart c file.
 «IF this.comment != null»
 /* «this.comment» */
 «ENDIF»
-	(*((StatemachineBase*)handle)->timer->setTimer)(«this.timeEvent.getEventEnumName()», «this.timeValue.toCCode()», «IF this.timeEvent.periodic == true -» «getBoolTrue()» «ELSE -» «getBoolFalse()» «ENDIF -»);
+	(*((StatemachineBase*)«statemachineHandleName()»)->timer->setTimer)(«this.timeEvent.getEventEnumName()», «this.timeValue.toCCode()», «IF this.timeEvent.periodic == true -» «getBoolTrue()» «ELSE -» «getBoolFalse()» «ENDIF -»);
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR UnscheduleTimeEvent»
 «IF this.comment != null»
 /* «this.comment» */
-	(*((StatemachineBase*)handle->timer->unsetTimer)(«this.timeEvent.getEventEnumName()»);
+	(*((StatemachineBase*)«statemachineHandleName()»)->timer->unsetTimer)(«this.timeEvent.getEventEnumName()»);
 «ENDIF»
 
 «ENDDEFINE»
@@ -57,7 +58,8 @@ Templates for the main statechart c file.
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR Call»
-«this.step.functionName()»(handle);
+«REM»«this.step.functionName()»(handle);«ENDREM»
+#error Action Code for Call missing!!
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR Sequence»
@@ -73,8 +75,11 @@ Templates for the main statechart c file.
   ENDDEFINE»
 
 «DEFINE ActionCode FOR CheckRef -»
-  «IF this.check != null -»
+  «IF this.check != null -» 
+ #error Action Code for CheckRef missing
+  «REM»
   «this.check.functionName()»(handle) «
+  «ENDREM»
   ELSE -»
  «getBoolTrue()» «
   ENDIF -»«
@@ -96,24 +101,24 @@ else {
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR EnterState»
-((StatemachineBase*)handle)->state[0] = _«this.state.simpleName»;
+((StatemachineBase*)«statemachineHandleName()»)->state[0] = _«this.state.simpleName»;
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR ExitState»
-((StatemachineBase*)handle)->state[0] = last_state;
+((StatemachineBase*)«statemachineHandleName()»)->state[0] = last_state;
 «ENDDEFINE»
 
-«DEFINE ConditionMethodsProto FOR ExecutionNode -»
+«DEFINE ConditionMethodsProto(sgen::GeneratorEntry genEntry) FOR ExecutionNode -»
   «FOREACH reactions.select(e|e.check.refs.size > 0) AS r -»
   «IF r.check != null -»
-static boolean «r.check.functionName()»(«StName()»* handle);
+static boolean «r.check.functionNamePrototype(genEntry)»
   «ENDIF -»«ENDFOREACH -»
 «ENDDEFINE»
 
-«DEFINE ConditionMethodsImplement FOR ExecutionNode -»
+«DEFINE ConditionMethodsImplement(sgen::GeneratorEntry genEntry) FOR ExecutionNode -»
   «FOREACH reactions.select(e|e.check.refs.size > 0) AS r -»
   «IF r.check != null -»
-boolean «r.check.functionName()»(«StName()»* handle) {
+boolean «r.check.functionName(genEntry)»(«StName()»* «statemachineHandleName()») {
   boolean retValue = «getBoolFalse()»;
   if («r.check.condition.toCCode()»)
     retValue = «getBoolTrue()»;
@@ -124,15 +129,16 @@ boolean 
   «ENDFOREACH -»
 «ENDDEFINE»
 
-«DEFINE StatementMethodsProto FOR ExecutionNode -»
+«DEFINE StatementMethodsProto(sgen::GeneratorEntry genEntry) FOR ExecutionNode -»
   «FOREACH reactions.select(e|e.effect.caller.size > 0) AS r -»
-static void «r.effect.functionName()»(«StName()»* handle);
+static void «r.effect.functionName(genEntry)»
  «ENDFOREACH -»
 «ENDDEFINE»
 
-«DEFINE StatementMethodsImplement FOR ExecutionNode -»
+«DEFINE StatementMethodsImplement(sgen::GeneratorEntry genEntry) FOR ExecutionNode -»
   «FOREACH reactions.select(e|e.effect.caller.size > 0) AS r -»
-void «r.effect.functionName()»(«StName()»* handle) {   
+void «r.effect.functionName(genEntry)»
+{   
   «EXPAND ActionCode FOR r.effect -»
 }
   «ENDFOREACH -»
@@ -142,45 +148,47 @@ void 
 «EXPAND ActionCode FOREACH this.steps»
 «ENDDEFINE»
 
-«DEFINE ReactMethodsProto FOR ExecutionNode -»
+«DEFINE ReactMethodsProto(sgen::GeneratorEntry genEntry) FOR ExecutionNode -»
 «IF (ExecutionState.isInstance(this) || this.reactSequence.caller.size > 0) -»
-static void «stName()»_react_«this.simpleName»(«StName()»* handle);
+static void «this.reactSequenceFunction(genEntry, true)»
+«REM»«stName()»_react_«this.simpleName»(«StName()»* handle);«ENDREM»
 «ENDIF -»
 «ENDDEFINE»
 
-«DEFINE ReactMethodsImplement FOR ExecutionNode -»
+«DEFINE ReactMethodsImplement(sgen::GeneratorEntry genEntry) FOR ExecutionNode -»
 «IF (ExecutionState.isInstance(this) || this.reactSequence.caller.size > 0) -»
-void «stName()»_react_«this.simpleName»(«StName()»* handle)
+void «this.reactSequenceFunction(genEntry, false)»
+«REM»void «stName()»_react_«this.simpleName»(«StName()»* handle)«ENDREM»
 {
 	«EXPAND ReactCode FOR reactSequence»
 }
 «ENDIF -»
 «ENDDEFINE»
 
-«DEFINE EnterMethodProto FOR ExecutionState -»
+«DEFINE EnterMethodProto(sgen::GeneratorEntry genEntry) FOR ExecutionState -»
 «IF this.entryAction != null && entryAction.caller.size > 0 -»
-static void «this.entryAction.entryActionFunctionName()»(«StName()»* handle);
+static void «entryAction.functionNamePrototype(genEntry)»
 «ENDIF -»
 «ENDDEFINE»
 
-«DEFINE EnterMethodImplement FOR ExecutionState -»
+«DEFINE EnterMethodImplement(sgen::GeneratorEntry genEntry) FOR ExecutionState -»
 «IF this.entryAction != null && entryAction.caller.size > 0»
-void «this.entryAction.entryActionFunctionName()»(«StName()»* handle)
+void «entryAction.functionName(genEntry)»
 {
 «EXPAND ActionCode FOR this.entryAction»
 }
 «ENDIF -»
 «ENDDEFINE»
 
-«DEFINE ExitMethodProto FOR ExecutionState -»
+«DEFINE ExitMethodProto(sgen::GeneratorEntry genEntry) FOR ExecutionState -»
 «IF this.exitAction != null && exitAction.caller.size > 0 -»
-static void «this.exitAction.exitActionFunctionName()»(«StName()»* handle);
+static void «this.exitAction.functionNamePrototype(genEntry)»
 «ENDIF -»
 «ENDDEFINE»
 
-«DEFINE ExitMethodImplement FOR ExecutionState -»
+«DEFINE ExitMethodImplement(sgen::GeneratorEntry genEntry) FOR ExecutionState -»
 «IF this.exitAction != null && exitAction.caller.size > 0 »
-void «this.exitAction.exitActionFunctionName()»(«StName()»* handle)
+void «this.exitAction.functionName(genEntry)»
 {
 «EXPAND ActionCode FOR this.exitAction»
 }
@@ -189,30 +197,30 @@ void 
 
 
 
-«DEFINE EnterSequenceProto FOR ExecutionState -»
+«DEFINE EnterSequenceProto(sgen::GeneratorEntry genEntry) FOR ExecutionState -»
 «IF this.enterSequence != null && enterSequence.caller.size > 0 -»
-static void «this.enterSequence.enterSequenceFunctionName()»(«StName()»* handle);
+static void «this.enterSequence.functionNamePrototype(genEntry)»
 «ENDIF -»
 «ENDDEFINE»
 
-«DEFINE EnterSequenceImplement FOR ExecutionState -»
+«DEFINE EnterSequenceImplement(sgen::GeneratorEntry genEntry) FOR ExecutionState -»
 «IF this.enterSequence != null && enterSequence .caller.size > 0 »
-void «this.enterSequence.enterSequenceFunctionName()»(«StName()»* handle)
+void «this.enterSequence.functionName(genEntry)»
 {
 «EXPAND ActionCode FOR this.enterSequence»
 }
 «ENDIF -»
 «ENDDEFINE»
 
-«DEFINE ExitSequenceProto FOR ExecutionState -»
+«DEFINE ExitSequenceProto(sgen::GeneratorEntry genEntry) FOR ExecutionState -»
 «IF this.exitSequence != null && exitSequence.caller.size > 0 -»
-static void «this.exitSequence.exitSequenceFunctionName()»(«StName()»* handle);
+static void «this.exitSequence.functionName(genEntry)»
 «ENDIF -»
 «ENDDEFINE»
 
-«DEFINE ExitSequenceImplement FOR ExecutionState -»
+«DEFINE ExitSequenceImplement(sgen::GeneratorEntry genEntry) FOR ExecutionState -»
 «IF this.exitSequence != null && exitSequence.caller.size > 0 -»
-void «this.exitSequence.exitSequenceFunctionName()»(«StName()»* handle)
+void «this.exitSequence.functionName(genEntry)»
 {
 «EXPAND ActionCode FOR this.exitSequence»
 }
@@ -229,109 +237,104 @@ void 
 
 #include "«StName()».h"
 
-«EXPAND ConditionMethodsProto FOREACH this.states -»
-«EXPAND ConditionMethodsProto FOREACH this.nodes -»
-«EXPAND StatementMethodsProto FOREACH this.states -»
-«EXPAND StatementMethodsProto FOREACH this.nodes -»
-«EXPAND EnterMethodProto FOREACH this.states -»
-«EXPAND ExitMethodProto FOREACH this.states -»
-«EXPAND EnterSequenceProto FOREACH this.states -»
-«EXPAND ExitSequenceProto FOREACH this.states -»
-«EXPAND ReactMethodsProto FOREACH this.states -»
-«EXPAND ReactMethodsProto FOREACH this.nodes -»
-
-«EXPAND ConditionMethodsImplement FOREACH this.states -»
-«EXPAND ConditionMethodsImplement FOREACH this.nodes -»
-«EXPAND StatementMethodsImplement FOREACH this.states -»
-«EXPAND StatementMethodsImplement FOREACH this.nodes -»
-«EXPAND EnterMethodImplement FOREACH this.states -»
-«EXPAND ExitMethodImplement FOREACH this.states -»
-«EXPAND EnterSequenceImplement FOREACH this.states -»
-«EXPAND ExitSequenceImplement FOREACH this.states -»
-«EXPAND ReactMethodsImplement FOREACH this.states -»
-«EXPAND ReactMethodsImplement FOREACH this.nodes -»
+«IF isSingleton(genEntry) == true»
+/* singleton handle and singleton handle pointer declaration */
+static «StName()» static_«statemachineHandleName()»;
+static «StName()»* «statemachineHandleName()»;
+«ENDIF»
 
-«REM»
-boolean «stName()»_is_in(«StName()»* handle, States state)
-{
-	switch (((StatemachineBase*)handle)->state[0 /* TODO: change to correct parallel region (may need a for loop */]) {
-	«FOREACH this.states AS state»
-	    case _«state.simpleName»:
-			«IF state.leaf == true»
-			  return bool_true;
-			«ELSE»
-			  if ( bool_true == bool_true )
-			    return bool_true;
-			«ENDIF»  
-	        break;
-	«ENDFOREACH»
-	    default:
-	        break;
-	}
-	return bool_false;
-}
-«ENDREM»
-void «stName()»_init(«StName()»* handle, Timer* timer, EventPool* eventPool)
+«EXPAND ConditionMethodsProto(genEntry) FOREACH this.states -»
+«EXPAND ConditionMethodsProto(genEntry) FOREACH this.nodes -»
+«EXPAND StatementMethodsProto(genEntry) FOREACH this.states -»
+«EXPAND StatementMethodsProto(genEntry) FOREACH this.nodes -»
+«EXPAND EnterMethodProto(genEntry) FOREACH this.states -»
+«EXPAND ExitMethodProto(genEntry) FOREACH this.states -»
+«EXPAND EnterSequenceProto(genEntry) FOREACH this.states -»
+«EXPAND ExitSequenceProto(genEntry) FOREACH this.states -»
+«EXPAND ReactMethodsProto(genEntry) FOREACH this.states -»
+«EXPAND ReactMethodsProto(genEntry) FOREACH this.nodes -»
+
+«EXPAND ConditionMethodsImplement(genEntry) FOREACH this.states -»
+«EXPAND ConditionMethodsImplement(genEntry) FOREACH this.nodes -»
+«EXPAND StatementMethodsImplement(genEntry) FOREACH this.states -»
+«EXPAND StatementMethodsImplement(genEntry) FOREACH this.nodes -»
+«EXPAND EnterMethodImplement(genEntry) FOREACH this.states -»
+«EXPAND ExitMethodImplement(genEntry) FOREACH this.states -»
+«EXPAND EnterSequenceImplement(genEntry) FOREACH this.states -»
+«EXPAND ExitSequenceImplement(genEntry) FOREACH this.states -»
+«EXPAND ReactMethodsImplement(genEntry) FOREACH this.states -»
+«EXPAND ReactMethodsImplement(genEntry) FOREACH this.nodes -»
+
+void «stName()»_init(«handleAdditionComma(genEntry)» Timer* timer, EventPool* eventPool)
 {
-	statemachine_cy_init(&handle->base, MAX_PARALLEL_STATES,
+«IF isSingleton(genEntry)»
+	«statemachineHandleName()» = &static_«statemachineHandleName()»;
+«ENDIF»
+	statemachine_cy_init(&«statemachineHandleName()»->base, MAX_PARALLEL_STATES,
 			event_last, timer, eventPool);
 			
 «FOREACH this.scopes.getUsableScopes() AS interface -»
-	«interface.interfaceName()»_init(&handle->«interface.interfaceObjectName().toFirstLower()», &handle->base, &handle->base.eventSet, eventPool);
+«IF isSingleton(genEntry) -»
+     «interface.interfaceName()»_set_interface_singleton(&«statemachineHandleName()»->«interface.interfaceObjectName()»);
+     «interface.interfaceName()»_init(&«statemachineHandleName()»->base, &«statemachineHandleName()»->base.eventSet, eventPool);
+«ELSE -»
+	«interface.interfaceName()»_init(&«statemachineHandleName()»->«interface.interfaceObjectName().toFirstLower()», 
+	&«statemachineHandleName()»->base, &«statemachineHandleName()»->base.eventSet, eventPool);
+«ENDIF»
 
 «FOREACH interface.getInEvents() AS event -»
-	eventSet_set_type(&handle->base.eventSet, «event.getEventEnumName()», ev_type_input); 
+	eventSet_set_type(&«statemachineHandleName()»->base.eventSet, «event.getEventEnumName()», ev_type_input); 
 «ENDFOREACH -»
 «FOREACH interface.getOutEvents() AS event -»
-	eventSet_set_type(&handle->base.eventSet, «event.getEventEnumName()», ev_type_output); 
+	eventSet_set_type(&«statemachineHandleName()»->base.eventSet, «event.getEventEnumName()», ev_type_output); 
 «ENDFOREACH -»
 «FOREACH interface.getLocalEvents() AS event -»
-	eventSet_set_type(&handle->base.eventSet, «event.getEventEnumName()», ev_type_local); 
+	eventSet_set_type(&«statemachineHandleName()»->base.eventSet, «event.getEventEnumName()», ev_type_local); 
 «ENDFOREACH -»
-
 «ENDFOREACH»	
-	
 }
 
+«IF isSingleton(genEntry) == true»
+«StName()»* «scName()»_get_handle()
+{ return «statemachineHandleName()»; } 
+«ELSE»
 «FOREACH this.scopes.typeSelect(InterfaceScope) AS interface»
-extern «interface.interfaceClassName()»* «stName()»_get_«interface.interfaceObjectName().toFirstLower()»(«StName()»* handle)
-{
-  return &handle->«interface.interfaceObjectName()»;
-}
+extern «interface.interfaceClassName()»* «stName()»_get_«interface.interfaceObjectName().toFirstLower()»(«handleAddition(genEntry)»)
+{  return &«statemachineHandleName()»->«interface.interfaceObjectName()»; }
 «ENDFOREACH»
+«ENDIF»
 
-void «stName()»_enter(«StName()»* handle)
+void «stName()»_enter(«handleAddition(genEntry)»)
 {
 	«EXPAND ActionCode FOR this.enterSequence»
 }
 
-void «stName()»_exit(«StName()»* handle)
+void «stName()»_exit(«handleAddition(genEntry)»)
 {
 	«EXPAND ActionCode FOR this.exitSequence»
 }
 
-void «stName()»_destruct(«StName()»* handle)
+void «stName()»_destruct(«handleAddition(genEntry)»)
 {
-	statemachine_cy_destruct(&handle->base);
+	statemachine_cy_destruct(&«statemachineHandleName()»->base);
 «REM»	variableData_exit(&handle->variableData); «ENDREM»
 }
 
-void «stName()»_runCycle(«StName()»* handle)
+void «stName()»_runCycle(«handleAddition(genEntry)»)
 {
-	statemachine_cy_runCycle(&handle->base);
+	statemachine_cy_runCycle(&«statemachineHandleName()»->base);
 }
 
-void «stName()»_setEvent(«StName()»* handle, _Event* ev)
+void «stName()»_setEvent(«handleAdditionComma(genEntry)» _Event* ev)
 {
-	statemachine_cy_setEvent(&handle->base, ev);
+	statemachine_cy_setEvent(&«statemachineHandleName()»->base, ev);
 }
 
-boolean «stName()»_eventWaiting(«StName()»* handle)
+boolean «stName()»_eventWaiting(«handleAddition(genEntry)»)
 {
-	return statemachine_cy_eventWaiting(&handle->base);
+	return statemachine_cy_eventWaiting(&«statemachineHandleName()»->base);
 }
 
-
 void statemachine_cy__runCycle(Statemachine_cy* handle)
 {
 	uint32_t i;
@@ -339,7 +342,7 @@ void statemachine_cy__runCycle(Statemachine_cy* handle)
 		switch(((StatemachineBase*)handle)->state[i]) {
 	«FOREACH this.states AS state»
 	    case _«state.simpleName»:
-	        «stName()»_react_«state.simpleName»((«StName()»*) handle);
+	    	«this.stName()»_reaction_«state.simpleName»(«IF isSingleton(genEntry) == false»(«StName()»*) handle«ENDIF»);
 	        break;
 	«ENDFOREACH»
 		default:

+ 18 - 13
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomStatemachineH.xpt

@@ -11,6 +11,7 @@ Templates for the main statechart cpp file.
 «IMPORT sgraph»
 
 «EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Constants»
 «EXTENSION org::yakindu::sct::generator::c::templates::Naming»
 
 «DEFINE file(sgen::GeneratorEntry genEntry) FOR ExecutionFlow»
@@ -51,26 +52,30 @@ typedef struct {
 	
 } «StName()»;
 
-«REM» «IF genEntry.features[genEntry.getFeatureConfiguration("")]»
- «ENDREM» 
 /* Explicit Constructor & Destructor */
-extern void «stName()»_init(«StName()»* handle, Timer* timer, EventPool* eventPool);
-extern void «stName()»_enter(«StName()»* handle);
-extern void «stName()»_exit(«StName()»* handle);
-extern void «stName()»_destruct(«StName()»* handle);
-extern void «stName()»_runCycle(«StName()»* handle);
-extern boolean «stName()»_eventWaiting(«StName()»* handle);
-
-«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface»
-extern «interface.interfaceClassName()»* «stName()»_get_«interface.interfaceObjectName()»(«StName()»* handle);
-«ENDFOREACH»
+extern void «stName()»_init(«this.handleAdditionComma(genEntry)» Timer* timer, EventPool* eventPool);
+extern void «stName()»_enter(«this.handleAddition(genEntry)»);
+extern void «stName()»_exit(«this.handleAddition(genEntry)»);
+extern void «stName()»_destruct(«this.handleAddition(genEntry)»);
+extern void «stName()»_runCycle(«this.handleAddition(genEntry)»);
+extern boolean «stName()»_eventWaiting(«this.handleAddition(genEntry)»);
+
+«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface -»
+extern «interface.interfaceClassName()»* «stName()»_get_«interface.interfaceObjectName()»(«this.handleAddition(genEntry)»);
+«ENDFOREACH -»
+
+«IF isSingleton(genEntry) == true»
+«StName()»* «scName()»_get_handle();
+«ENDIF»
+
 
 #define «scName()»_eventPool_init_heap(handle, maxElemPerEvent) eventPool_init_heap(handle, event_last, maxElemPerEvent, &«scName()»_getSizeofEvent )
 
 /* only friends can see these functions */
 #ifdef «STNAME()»_FRIENDS
 
-extern void «stName()»_setEvent(«StName()»* handle, _Event* ev);
+extern void «stName()»_setEvent(«this.handleAdditionComma(genEntry)»_Event* ev);
+
 
 /* virtual function form state machine must be implemented here */
 extern void statemachine_cy__runCycle(Statemachine_cy* handle);

+ 11 - 9
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Expression.ext

@@ -56,10 +56,12 @@ String toCCode(Assignment assignment) :
 /* EventRaising */
 String toCCode(EventRaising eventRaising) :
 	((eventRaising.value == null)?"":
-	"((" + eventRaising.event.getEventName() + "*) handle->" + eventRaising.getInterfaceName() + "." + eventRaising.event.getEventName() + ")->value = " 
+	"((" + eventRaising.event.getEventName() + "*)" + eventRaising.statemachineHandleName() + "->" + eventRaising.getInterfaceName() + "." + eventRaising.event.getEventName() + ")->value = " 
 	+ eventRaising.value.toCCode() + ";") + 
-	" statemachine_cy_setEvent(&handle->base, handle->" + eventRaising.getInterfaceName() + "." + eventRaising.event.getEventName() + "); ";
-//  "{ _Event* ev = eventPool_createEvent(handle->base.eventPool, ev_"+eventRaising.event.name+"); if (ev) { " + eventRaising.addValue() + "statemachine_cy_setEvent(&handle->base, ev); } }";
+	" statemachine_cy_setEvent(&" + eventRaising.statemachineHandleName() + 
+	"->base, " + eventRaising.statemachineHandleName() + "->" + 
+	eventRaising.getInterfaceName() + "." + 
+	eventRaising.event.getEventName() + "); ";
 
 String getScopeName(emf::EObject o) :
   "unknownScopeName";
@@ -72,7 +74,6 @@ String getScopeName(InternalScope inls) :
 
 String getInterfaceName(EventRaising event) :
 	"interface" + (( event.event.eContainer.getScopeName() == null)?"":event.event.eContainer.getScopeName().toFirstUpper());
-//	"interface" + (( ((InterfaceScope)event.event.eContainer).name == null)?"":((InterfaceScope)event.event.eContainer).name.toFirstUpper());
 
 String addValue(EventRaising event) :
   ( (event.value == null)?"":("((" +event.event.getEventName() + "*)ev)->value = " + event.value.toCCode() + "; ") );
@@ -185,19 +186,20 @@ String toCCode(Declaration dec) :
 	"Declartion type not specified";
 
 String toCCode(TimeEvent time_ev) :
-    " ( eventSet_check( &handle->base.eventSet, " + time_ev.getEventEnumName() + ") ) ";
+    " ( eventSet_check( &"+time_ev.statemachineHandleName()+"->base.eventSet, " + time_ev.getEventEnumName() + ") ) ";
 
 String toCCode(VariableDefinition var) :
-    " handle->"+ var.getInterface() + "." + var.name.toLowerCase() + " ";
+    " " + var.statemachineHandleName() + "->" + var.getInterface() + 
+    "." + var.name.toLowerCase() + " ";
 	
 String toCCode(EventDefinition evDef) :
-    " ( eventSet_check( &handle->base.eventSet, " + evDef.getEventEnumName() + ") ) ";
+    " ( eventSet_check( &" + evDef.statemachineHandleName() + "->base.eventSet, " + evDef.getEventEnumName() + ") ) ";
 
 String toCCode(EventRaisedReferenceExpression errExp) :
-	" eventSet_check( &handle->base.eventSet, " + errExp.value.getEventEnumName() + ")";
+	" eventSet_check( &" + errExp.statemachineHandleName() + "->base.eventSet, " + errExp.value.getEventEnumName() + ")";
 
 String toCCode(EventValueReferenceExpression evrExp) :
-	"((" +evrExp.value.name + "*)handle->base.eventList[" + evrExp.value.getEventEnumName() + "])->value";
+	"((" +evrExp.value.name + "*)" + evrExp.statemachineHandleName() + "->base.eventList[" + evrExp.value.getEventEnumName() + "])->value";
 
 List[Scope] getUsableScopes(List[Scope] scList) :
 	scList.select(e| InterfaceScope.isInstance(e) || InternalScope.isInstance(e));

+ 41 - 27
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Interfaces.xpt

@@ -55,36 +55,40 @@ typedef struct {
 	
 } «interfaceClassName(interface)»;
 
+«IF isSingleton(genEntry)»
+void «interface.interfaceName()»_set_interface_singleton(«interfaceClassName(interface)»* _handle);
+«ENDIF»
+
 «FOREACH interface.declarations.typeSelect(VariableDefinition) AS variable -»
-extern «eventTypeToString(variable.type)» «interface.interfaceName()»_get_«variable.name»(«interfaceClassName(interface)»* handle);
+extern «eventTypeToString(variable.type)» «interface.interfaceName()»_get_«variable.name»(«handleInterfaceAddition(interface, genEntry)»);
 «IF variable.readonly == false -»
-extern void «interface.interfaceName()»_set_«variable.name»(«interfaceClassName(interface)»* handle, «eventTypeToString(variable.type)» value);
+extern void «interface.interfaceName()»_set_«variable.name»(«handleInterfaceAdditionComma(interface, genEntry)»«eventTypeToString(variable.type)» value);
 «ENDIF»
 «ENDFOREACH» 
 
 
-extern void «interface.interfaceName()»_reset_event(«interfaceClassName(interface)»* handle);
+extern void «interface.interfaceName()»_reset_event(«handleInterfaceAddition(interface, genEntry)»);
 
 #ifdef INTERFACE_LISTENER
 
-extern void «interface.interfaceName()»_init(«interfaceClassName(interface)»* handle, Statemachine_cy* statemachine,
+extern void «interface.interfaceName()»_init(«handleInterfaceAddition(interface, genEntry)»Statemachine_cy* statemachine,
 		EventSet* eventSet);
-extern void «interface.interfaceName()»_set_listener(«interfaceClassName(interface)»* handle, handleEvent handleEventPtr);
-extern void «interface.interfaceName()»_raiseEvent(«interfaceClassName(interface)»* handle, _Event* event);
+extern void «interface.interfaceName()»_set_listener(«handleInterfaceAdditionComma(interface, genEntry)»handleEvent handleEventPtr);
+extern void «interface.interfaceName()»_raiseEvent«handleInterfaceAdditionComma(interface, genEntry)»_Event* event);
 
 #else
 
-extern void «interface.interfaceName()»_init(«interfaceClassName(interface)»* handle, Statemachine_cy* statemachine,
+extern void «interface.interfaceName()»_init(«handleInterfaceAdditionComma(interface, genEntry)»Statemachine_cy* statemachine,
 		EventSet* eventSet, EventPool* eventPool);
 		
 «FOREACH interface.getOutEvents() AS event -»
-extern boolean «interface.interfaceName()»_is_«event.name»_raised(«interface.interfaceClassName()»* handle«
-IF event.type != Type::void -», «event.type.eventTypeToString()»* value«ENDIF» );
+extern boolean «interface.interfaceName()»_is_«event.name»_raised(«handleInterfaceAddition(interface, genEntry)»«
+IF event.type != Type::void -»«IF isSingleton(genEntry) == false -», «ENDIF»«event.type.eventTypeToString()»* value«ENDIF» );
 «ENDFOREACH»
 
 «FOREACH interface.getInEvents() AS event -»
-extern void «interface.interfaceName()»_raise_«event.name»(«interface.interfaceClassName()»* handle«
-IF event.type != Type::void -», «event.type.eventTypeToString()» value «ENDIF»);
+extern void «interface.interfaceName()»_raise_«event.name»(«handleInterfaceAddition(interface, genEntry)»«
+IF event.type != Type::void -»«IF isSingleton(genEntry) == false -», «ENDIF»«event.type.eventTypeToString()» value «ENDIF»);
 «ENDFOREACH» 
 
 #endif // INTERFACE_LISTENER
@@ -100,13 +104,18 @@ IF event.type != Type::void -
 #include "«interface.interfaceClassName()».h"
 #include <stdlib.h>
 
-static boolean «interface.interfaceName()»_is_my_event(«interface.interfaceClassName()»* handle, uint32_t evid);
+«IF isSingleton(genEntry)»
+static «interfaceClassName(interface)»* handle;
+void «interface.interfaceName()»_set_interface_singleton(«interfaceClassName(interface)»* _handle);
+«ENDIF»
+
+static boolean «interface.interfaceName()»_is_my_event(«handleInterfaceAdditionComma(interface, genEntry)»uint32_t evid);
 
 #ifdef INTERFACE_LISTENER
-void «interface.interfaceName()»_init(«interface.interfaceClassName()»* handle, Statemachine_cy* statemachine,
+void «interface.interfaceName()»_init(«handleInterfaceAdditionComma(interface, genEntry)»Statemachine_cy* statemachine,
 		EventSet* eventSet)
 #else
-void «interface.interfaceName()»_init(«interface.interfaceClassName()»* handle, Statemachine_cy* statemachine,
+void «interface.interfaceName()»_init(«handleInterfaceAdditionComma(interface, genEntry)»Statemachine_cy* statemachine,
 		EventSet* eventSet, EventPool* eventPool)
 #endif
 {
@@ -135,13 +144,18 @@ void 
 
 }
 
+«IF isSingleton(genEntry)»
+void «interface.interfaceName()»_set_interface_singleton(«interfaceClassName(interface)»* _handle)
+{ handle = _handle; }
+«ENDIF»
+
 «FOREACH interface.declarations.typeSelect(VariableDefinition) AS variable -»
-«variable.type.eventTypeToString()» «interface.interfaceName()»_get_«variable.name»(«interface.interfaceClassName()»* handle)
+«variable.type.eventTypeToString()» «interface.interfaceName()»_get_«variable.name»(«handleInterfaceAddition(interface, genEntry)»)
 {
 	return handle->«variable.name»;
 }
 «IF variable.readonly == false -»
-void «interface.interfaceName()»_set_«variable.name»(«interface.interfaceClassName()»* handle, «variable.type.eventTypeToString()» value)
+void «interface.interfaceName()»_set_«variable.name»(«handleInterfaceAdditionComma(interface, genEntry)»«variable.type.eventTypeToString()» value)
 {
 	handle->«variable.name» = value;
 }
@@ -149,14 +163,14 @@ void 
 «ENDFOREACH»
 
 
-boolean «interface.interfaceName()»_is_set(«interface.interfaceClassName()»* handle, uint32_t evid)
+boolean «interface.interfaceName()»_is_set(«handleInterfaceAdditionComma(interface, genEntry)»uint32_t evid)
 {
-	if («interface.interfaceName()»_is_my_event(handle, evid))
+	if («interface.interfaceName()»_is_my_event(«IF isSingleton(genEntry) == false -»handle, «ENDIF»evid))
 		return eventSet_check(handle->eventSet, evid);
 	return bool_false;
 }
 
-void «interface.interfaceName()»_reset_event(«interface.interfaceClassName()»* handle)
+void «interface.interfaceName()»_reset_event(«handleInterfaceAddition(interface, genEntry)»)
 {
 	// clean all out events
 	«FOREACH interface.getOutEvents() AS outEvent»
@@ -167,21 +181,21 @@ void 
 
 #ifdef INTERFACE_LISTENER
 
-void «interface.interfaceName()»_set_listener(«interface.interfaceClassName()»* handle, handleEvent handleEventPtr)
+void «interface.interfaceName()»_set_listener(«handleInterfaceAdditionComma(interface, genEntry)»handleEvent handleEventPtr)
 {
 	handle->handleEventCallback = handleEventPtr;
 }
 
-void «interface.interfaceName()»_raiseEvent(«interface.interfaceClassName()»* handle, _Event event) {
-	if («interface.interfaceName()»_is_my_event(event->id))
+void «interface.interfaceName()»_raiseEvent(«handleInterfaceAdditionComma(interface, genEntry)»_Event event) {
+	if («interface.interfaceName()»_is_my_event(«IF isSingleton(genEntry) == false -»handle, «ENDIF»event->id))
 		statemachine_cy_setEvent(handle->statemachine, event);
 }
 
 #else
 
 «FOREACH interface.getOutEvents() AS event -»
-extern boolean «interface.interfaceName()»_is_«event.name»_raised(«interface.interfaceClassName()»* handle
-«IF event.type != Type::void -», «event.type.eventTypeToString()»* value«ENDIF») 
+extern boolean «interface.interfaceName()»_is_«event.name»_raised(«handleInterfaceAddition(interface, genEntry)»«
+IF event.type != Type::void -»«IF isSingleton(genEntry) == false -», «ENDIF»«event.type.eventTypeToString()»* value«ENDIF») 
 {
 	boolean ret = bool_false;
 	if (eventSet_check(handle->eventSet,«event.getEventEnumName()»)) {
@@ -196,8 +210,8 @@ extern boolean 
 «ENDFOREACH»
 
 «FOREACH interface.getInEvents() AS event -»
-extern void «interface.interfaceName()»_raise_«event.name»(«interface.interfaceClassName()»* handle
-«IF event.type != Type::void -» , «event.type.eventTypeToString()» value«
+extern void «interface.interfaceName()»_raise_«event.name»(«handleInterfaceAddition(interface, genEntry)»«
+IF event.type != Type::void -»«IF isSingleton(genEntry) == false -», «ENDIF»«event.type.eventTypeToString()» value«
 ENDIF»)
 {
 	_Event* ev = eventPool_createEvent(handle->eventPool, «event.getEventEnumName()»);
@@ -214,7 +228,7 @@ ENDIF
 #endif // INTERFACE_LISTENER
 
 
-boolean «interface.interfaceName()»_is_my_event(«interface.interfaceClassName()»* handle, uint32_t evid)
+boolean «interface.interfaceName()»_is_my_event(«handleInterfaceAdditionComma(interface, genEntry)»uint32_t evid)
 {
 	boolean ret = bool_false;
 	switch (evid) {

+ 67 - 9
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Naming.ext

@@ -29,16 +29,25 @@ String DRNAME(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).nam
 String EvName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "Event";
 String EVNAME(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toUpperCase() + "EVENT";
 
-cached String functionName(Step step) : 
-	(step.isEffect()) ? step.actionFunctionName() : (
-	(step.isReactionCheck()) ? step.checkFunctionName() : (
-	(step.isEntryAction()) ? step.entryActionFunctionName() : ( 
-	(step.isExitAction()) ? step.exitActionFunctionName() : (
-	(step.isEnterSequence()) ? step.enterSequenceFunctionName() : ( 
-	(step.isExitSequence()) ? step.exitSequenceFunctionName() : (
-	(step.isReactSequence()) ? step.reactSequenceFunctionName() :
-	" !! unknown function type !!" ))))));
+cached String functionName(Step step, GeneratorEntry genEntry) : 
+	(step.isEffect()) ? step.actionFunction(genEntry, false) : (
+	(step.isReactionCheck()) ? step.checkFunction(genEntry, false) : (
+	(step.isEntryAction()) ? step.entryActionFunction(genEntry, false) : ( 
+	(step.isExitAction()) ? step.exitActionFunction(genEntry, false) : (
+	(step.isEnterSequence()) ? step.enterSequenceFunction(genEntry, false) : ( 
+	(step.isExitSequence()) ? step.exitSequenceFunction(genEntry, false) : 
+	" !! unknown function type !!" )))));
  
+cached String functionNamePrototype(Step step, GeneratorEntry genEntry) : 
+	(step.isEffect()) ? step.actionFunction(genEntry, true) : (
+	(step.isReactionCheck()) ? step.checkFunction(genEntry, true) : (
+	(step.isEntryAction()) ? step.entryActionFunction(genEntry, true) : ( 
+	(step.isExitAction()) ? step.exitActionFunction(genEntry, true) : (
+	(step.isEnterSequence()) ? step.enterSequenceFunction(genEntry, true) : ( 
+	(step.isExitSequence()) ? step.exitSequenceFunction(genEntry, true) :
+	" !! unknown function type !!" )))));
+
+/*
 String actionFunctionName(Step this) :  this.stName() + "_actions_" + this.reaction().state().simpleName + "_" + this.reaction().name; 
 String checkFunctionName(Step this) : this.stName() + "_condition_" + this.reaction().state().simpleName + "_" + this.reaction().name; 
 String entryActionFunctionName(Step this) : this.stName() + "_entryActions_" + this.state().simpleName; 
@@ -46,8 +55,46 @@ String exitActionFunctionName(Step this) : this.stName() + "_exitActions_" + thi
 String enterSequenceFunctionName(Step this) : this.stName() + "_enterSequence_" + this.state().simpleName; 
 String exitSequenceFunctionName(Step this) : this.stName() + "_exitSequence_" + this.state().simpleName; 
 String reactSequenceFunctionName(Step this) : "react"+ this.state().simpleName; 
+*/
+
+String handleAddition(Object this, GeneratorEntry genEntry) :
+	(isSingleton(genEntry) == true) ? "" : StName() + "* " + this.statemachineHandleName();
+
+String handleAdditionComma(Object this, GeneratorEntry genEntry) :
+	(isSingleton(genEntry) == true) ? "" : StName() + "* " + this.statemachineHandleName() + ", ";
+
+
+String handleInterfaceAddition(Scope this, GeneratorEntry genEntry) :
+	(isSingleton(genEntry) == true) ? "" : this.interfaceClassName() + "* handle";
+
+String handleInterfaceAdditionComma(Scope this, GeneratorEntry genEntry) :
+	(isSingleton(genEntry) == true) ? "" : this.interfaceClassName() + "* handle, ";
+
+String prototypeEnd(Boolean isPrototype) :
+	(isPrototype == true) ? ";" : "";
 
+String actionFunction(Step this, GeneratorEntry genEntry, Boolean prototype) :  
+	  (this.stName() + "_actions_" + this.reaction().state().simpleName + "_" + this.reaction().name + "("+ handleAddition(genEntry) + ")"+prototypeEnd(prototype));
 
+String checkFunction(Step this, GeneratorEntry genEntry, Boolean prototype) :  
+	  (this.stName() + "_condition_" + this.reaction().state().simpleName + "_" + this.reaction().name + "("+ handleAddition(genEntry) + ")"+prototypeEnd(prototype));
+
+String entryActionFunction(Step this, GeneratorEntry genEntry, Boolean prototype) :  
+	  (this.stName() + "_entryActions_" + this.reaction().state().simpleName + "_" + this.reaction().name + "("+ handleAddition(genEntry) + ")"+prototypeEnd(prototype));
+ 
+String exitActionFunction(Step this, GeneratorEntry genEntry, Boolean prototype) :  
+	  (this.stName() + "_exitActions_" + this.reaction().state().simpleName + "_" + this.reaction().name + "("+ handleAddition(genEntry) + ")"+prototypeEnd(prototype));
+ 
+String enterSequenceFunction(Step this, GeneratorEntry genEntry, Boolean prototype) :  
+	  (this.stName() + "_enterSequence_" + this.reaction().state().simpleName + "_" + this.reaction().name + "("+ handleAddition(genEntry) + ")"+prototypeEnd(prototype));
+
+String exitSequenceFunction(Step this, GeneratorEntry genEntry, Boolean prototype) :  
+	  (this.stName() + "_exitSequence_" + this.reaction().state().simpleName + "_" + this.reaction().name + "("+ handleAddition(genEntry) + ")"+prototypeEnd(prototype));
+
+/* for some reason, this is handled completely different */ 
+String reactSequenceFunction(ExecutionNode this, GeneratorEntry genEntry, Boolean prototype) :  
+	  (this.stName() + "_reaction_" + this.simpleName + "("+ handleAddition(genEntry) + ")"+prototypeEnd(prototype));
+ 
 boolean isEffect(Step step) : (! Check.isInstance(step)) && Reaction.isInstance(step.eContainer) ;
 boolean isReactionCheck(Step step) : Reaction.isInstance(step.eContainer) && Check.isInstance(step);
 boolean isEntryAction(Step step) : ExecutionState.isInstance(step.eContainer) && step.state().entryAction == step;
@@ -64,6 +111,7 @@ String interfaceName(Scope this) : "unknownScope";
 String interfaceClassName(Scope this) : "unknownScope";
 String interfaceObjectName(Scope this) : "unknownScope";
 
+String statemachineHandleName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstLower()+"_handle";
 
 String interfaceName(InterfaceScope this) : this.getExecutionFlow().name.toFirstLower() + ((this.name == null) ? "_if" : "_if_" + this.name);
 String interfaceClassName(InterfaceScope this) : this.getExecutionFlow().name.toFirstUpper() + "If" + ((this.name == null)?"":this.name.toFirstUpper());
@@ -102,6 +150,16 @@ String getLicenseHeaderPlain(GeneratorEntry entry) :
 	else 
 		null;
 
+Boolean isSingleton(GeneratorEntry genEntry) : (
+	(genEntry.getFeatureConfiguration(getCCodeFeature()) != null) ? (
+      ((genEntry.getFeatureConfiguration(getCCodeFeature()).getParameterValue(getSingleton()) != null) ?
+       genEntry.getFeatureConfiguration(getCCodeFeature()).getParameterValue(getSingleton()).getBooleanValue()
+     : getSingletonDefault()))
+     : getSingletonDefault());
+ 
+//(
+//     (genEntry.getFeatureConfiguration(getCCodeFeature()).getParameterValue(getSingleton()).getBooleanValue() == true) ? 
+//     getBoolTrue():getBoolFalse())
 String getComment(Step this) :
 	if comment!=null then
 		"//"+comment