Bläddra i källkod

Changed code to work with different interfaces on one state machine
+ some bug fixes

jos.itemis@gmail.com 13 år sedan
förälder
incheckning
b164fbbde0

+ 1 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/subscriber/CCodeGeneratorSubscriber.java

@@ -20,7 +20,7 @@ public class CCodeGeneratorSubscriber extends
 
 	@Override
 	public String getOutletPath(IResource resource) {
-		return "src-gen" + File.separator
+		return "src-gen-c" + File.separator
 				+ resource.getName().replaceAll(" ", "");
 	}
 

+ 5 - 6
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CMakeLists.xpt

@@ -16,8 +16,6 @@ Templates for the main statechart cpp file.
 «DEFINE file FOR ExecutionFlow»
 
 «FILE 'CMakeLists.txt'»
-cmake_minimum_required(VERSION 2.8)
-
 set( SRC
 	Statemachine_cy.c
 	StatemachineBase.c
@@ -26,14 +24,15 @@ set( SRC
 	EventPool.c
 	«StName()».c
 	«EvName()».c
-	«DRName()».c
+«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface -»
+	«interface.interfaceClassName()».c
+«ENDFOREACH»
 	Timer.c
 	DummyTimer.c
-	main.c
 )
 
-add_definitions( -Wall -O0 -g)
-add_executable(«StName()»Main ${SRC})
+add_library(«StName()» ${SRC})
+
 «ENDFILE»
 
 «ENDDEFINE»

+ 2 - 1
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomEventH.xpt

@@ -32,8 +32,9 @@ typedef enum {
 «FOREACH this.declaredEvents() AS ev»
 typedef struct { 
   _Event baseEvent;
+  «IF ((EventDefinition)ev).type != Type::void»
   «eventTypeToString(((EventDefinition)ev).type)» value;    
-  
+  «ENDIF»
 } «((EventDefinition)ev).name»;
 «ENDFOREACH»
  

+ 58 - 19
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomStatemachineC.xpt

@@ -21,7 +21,7 @@ Templates for the main statechart cpp file.
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR Execution»
-	«this.statement.toCppCode()»
+	«this.statement.toCCode()»
 «ENDDEFINE»
 
 «DEFINE ActionCode FOR Call»
@@ -34,7 +34,7 @@ Templates for the main statechart cpp file.
 
 «DEFINE ActionCode FOR Check -»
   «IF this != null -»
-«this.condition.toCppCode() -»
+«this.condition.toCCode() -»
   «ELSE -»
  bool_true «
  ENDIF -»«
@@ -69,12 +69,19 @@ else {
 ((StatemachineBase*)handle)->state[0] = last_state;
 «ENDDEFINE»
 
+«DEFINE ConditionMethodsProto FOR ExecutionState»
+  «FOREACH reactions AS r -»
+  «IF r.check != null -»
+static boolean «r.check.functionName()»(«StName()»* handle);
+  «ENDIF -»«ENDFOREACH -»
+«ENDDEFINE»
+
 «DEFINE ConditionMethodsImplement FOR ExecutionState»
-  «FOREACH reactions AS r»
+  «FOREACH reactions AS r -»
   «IF r.check != null -»
 boolean «r.check.functionName()»(«StName()»* handle) {
   boolean retValue = bool_false;
-  if («r.check.condition.toCppCode()»)
+  if («r.check.condition.toCCode()»)
     retValue = bool_true;
   
   return retValue;
@@ -83,21 +90,28 @@ boolean 
   «ENDFOREACH»
 «ENDDEFINE»
 
+«DEFINE StatementMethodsProto FOR ExecutionState»
+  «FOREACH reactions AS r -»
+static void «r.effect.functionName()»(«StName()»* handle);
+ «ENDFOREACH -»
+«ENDDEFINE»
+
 «DEFINE StatementMethodsImplement FOR ExecutionState»
-  «FOREACH reactions AS r»
-void «r.effect.functionName()»(«StName()»* handle) {
- 
-  «DRName()»* variable = &handle->variableData;
-  
-  «EXPAND ActionCode FOR r.effect»
+  «FOREACH reactions AS r -»
+void «r.effect.functionName()»(«StName()»* handle) {   
+  «EXPAND ActionCode FOR r.effect -»
 }
-  «ENDFOREACH»
+  «ENDFOREACH -»
 «ENDDEFINE»
 
 «DEFINE CycleCode FOR Cycle» 
 «EXPAND ActionCode FOREACH this.steps»
 «ENDDEFINE»
 
+«DEFINE CycleMethodsProto FOR ExecutionState»
+static void «StName().toFirstLower()»_cycle_«this.simpleName»(«StName()»* handle);
+«ENDDEFINE»
+
 «DEFINE CycleMethodsImplement FOR ExecutionState»
 void «StName().toFirstLower()»_cycle_«this.simpleName»(«StName()»* handle)
 {
@@ -105,18 +119,30 @@ void 
 }
 «ENDDEFINE»
 
+«DEFINE EnterMethodProto FOR ExecutionState»
+«IF this.entryAction != null -»
+static void «this.entryAction.entryActionFunctionName()»(«StName()»* handle);
+«ENDIF -»
+«ENDDEFINE»
+
 «DEFINE EnterMethodImplement FOR ExecutionState»
 «IF this.entryAction != null»
-void «StName().toFirstLower()»_«this.entryAction.entryActionFunctionName()»(«StName()»* handle)
+void «this.entryAction.entryActionFunctionName()»(«StName()»* handle)
 {
 «EXPAND ActionCode FOR this.entryAction»
 }
 «ENDIF»
 «ENDDEFINE»
 
+«DEFINE ExitMethodProto FOR ExecutionState»
+«IF this.exitAction != null -»
+static void «this.exitAction.exitActionFunctionName()»(«StName()»* handle);
+«ENDIF -»
+«ENDDEFINE»
+
 «DEFINE ExitMethodImplement FOR ExecutionState»
 «IF this.exitAction != null»
-void «StName().toFirstLower()»_«this.exitAction.exitActionFunctionName()»(«StName()»* handle)
+void «this.exitAction.exitActionFunctionName()»(«StName()»* handle)
 {
 «EXPAND ActionCode FOR this.exitAction»
 }
@@ -127,23 +153,36 @@ void 
 «FILE StName()+'.c'»
 #include "«StName()».h"
 
-«EXPAND ConditionMethodsImplement FOREACH this.states»
+«EXPAND ConditionMethodsProto FOREACH this.states»
+«EXPAND StatementMethodsProto FOREACH this.states»
+«EXPAND CycleMethodsProto FOREACH this.states»
+«EXPAND EnterMethodProto FOREACH this.states»
+«EXPAND ExitMethodProto FOREACH this.states»
 
+«EXPAND ConditionMethodsImplement FOREACH this.states»
 «EXPAND StatementMethodsImplement FOREACH this.states»
-
 «EXPAND CycleMethodsImplement FOREACH this.states»
-
 «EXPAND EnterMethodImplement FOREACH this.states»
-
 «EXPAND ExitMethodImplement FOREACH this.states»
 
-
 void «stName()»_init(«StName()»* handle, Timer* timer, EventPool* eventPool)
 {
 	statemachine_cy_init(&handle->base, MAX_PARALLEL_STATES,
 			event_last, timer, eventPool);
 			
-	«DRName().toFirstLower()»_init(&handle->variableData);
+«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface -»
+	«interface.interfaceName()»_init(&handle->«interface.interfaceObjectName().toFirstLower()», &handle->base, &handle->base.eventSet, eventPool);
+«FOREACH interface.getInEvents() AS event -»
+	eventSet_set_type(&handle->base.eventSet, «event.getEventEnumName()», ev_type_input); 
+«ENDFOREACH -»
+«FOREACH interface.getOutEvents() AS event -»
+	eventSet_set_type(&handle->base.eventSet, «event.getEventEnumName()», ev_type_output); 
+«ENDFOREACH -»
+«FOREACH interface.getLocalEvents() AS event -»
+	eventSet_set_type(&handle->base.eventSet, «event.getEventEnumName()», ev_type_local); 
+«ENDFOREACH -»
+
+«ENDFOREACH»	
 	
 	//((StatemachineBase*)handle)->state[0] = st_State1;
 

+ 6 - 2
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/CustomStatemachineH.xpt

@@ -19,8 +19,10 @@ Templates for the main statechart cpp file.
 #ifndef «STNAME()»_H_
 #define «STNAME()»_H_
 
+«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface -»
+#include "«interface.interfaceClassName()».h"
+«ENDFOREACH»
 #include "Statemachine_cy.h"
-#include "«DRName()».h"
 #include "«EvName()».h"
 
 typedef enum {
@@ -38,7 +40,9 @@ typedef void(*raiseEventFPtr)(_Event* evPtr);
 typedef struct {
 
 	Statemachine_cy  base;
-	«DRName()» variableData;
+«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface»
+	«interface.interfaceClassName()» «interface.interfaceObjectName().toFirstLower()»;
+«ENDFOREACH»
 	raiseEventFPtr raiseEvent;
 	
 } «StName()»;

+ 56 - 4
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/EventSetC.xpt

@@ -18,22 +18,59 @@ Templates for the main statechart c file.
 #include <stdlib.h>
 
 void eventSet_init(EventSet* handle, const uint32_t _maxEvents) {
+
+	int i;
+
 	handle->isStaticData = bool_false;
 	handle->maxEvents = _maxEvents;
 	handle->_set = malloc(sizeof(boolean) * _maxEvents);
+	handle->eventType = malloc(sizeof(EventType) * _maxEvents);
+
 	eventSet_clean(handle);
+
+	for(i=0; i<_maxEvents; ++i) {
+		handle->eventType[i] = ev_type_input;
+	}
 }
 
 void eventSet_init_staticData(EventSet* handle, const uint32_t _maxEvents,
-		boolean* _dataSet) {
+		boolean* _dataSet, EventType* _eventTypes) {
+	int i;
+
 	handle->isStaticData = bool_true;
 	handle->maxEvents = _maxEvents;
 	handle->_set = _dataSet;
+	handle->eventType = _eventTypes;
+
+	eventSet_clean(handle);
+
+	for(i=0; i<_maxEvents; ++i) {
+		handle->eventType[i] = ev_type_input;
+	}
+
+}
+
+void eventSet_set_type(EventSet* handle, const uint32_t evid, const EventType type)
+{
+	if (evid < handle->maxEvents)
+		handle->eventType[evid] = type;
+}
+
+boolean eventSet_is_type(EventSet* handle, const uint32_t evid, const EventType type)
+{
+	boolean ret = bool_false;
+	if (evid < handle->maxEvents)
+		if (handle->eventType[evid] == type)
+			ret = bool_true;
+
+	return ret;
 }
 
 void eventSet_exit(EventSet* handle) {
-	if (!handle->isStaticData)
+	if (!handle->isStaticData) {
 		free(handle->_set);
+		free(handle->eventType);
+	}
 	handle->maxEvents = 0;
 }
 
@@ -56,14 +93,29 @@ void eventSet_set(EventSet* handle, const uint32_t evid) {
 	}
 }
 
-boolean eventSet_isAny(EventSet* handle) {
+boolean eventSet_isAny_input(EventSet* handle) {
 	uint32_t i;
 	for (i = 0; i < handle->maxEvents; ++i)
-		if (handle->_set[i])
+		if (handle->eventType[i] == ev_type_input &&handle->_set[i])
 			return (bool_true);
 	return (bool_false);
 }
 
+boolean eventSet_isAny_output(EventSet* handle) {
+	uint32_t i;
+	for (i = 0; i < handle->maxEvents; ++i)
+		if (handle->eventType[i] == ev_type_output && handle->_set[i])
+			return (bool_true);
+	return (bool_false);
+}
+
+void eventSet_clean_single(EventSet* handle, const uint32_t evid)
+{
+	if (evid < handle->maxEvents) {
+		handle->_set[evid] = bool_false;
+	}
+}
+
 «ENDFILE»
 
 «ENDDEFINE»

+ 13 - 3
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/EventSetH.xpt

@@ -19,8 +19,15 @@ Templates for the main statechart c file.
 
 #include "definition.h"
 
+typedef enum {
+	ev_type_input,
+	ev_type_output,
+	ev_type_local
+} EventType;
+
 typedef struct {
 	boolean* _set;
+	EventType* eventType;
 	uint32_t maxEvents;
 	boolean isStaticData;
 } EventSet;
@@ -28,14 +35,17 @@ typedef struct {
 /* constructor and destructor */
 extern void eventSet_init(EventSet* handle, const uint32_t maxEvents);
 extern void eventSet_init_staticData(EventSet* handle, const uint32_t maxEvents,
-		boolean* _dataSet);
+		boolean* _dataSet, EventType* _eventTypes);
 extern void eventSet_exit(EventSet* handle);
 
-
+extern void eventSet_set_type(EventSet* handle, const uint32_t evid, const EventType type);
+extern boolean eventSet_is_type(EventSet* handle, const uint32_t evid, const EventType type);
 extern boolean eventSet_check(EventSet* handle, const uint32_t evid);
 extern void eventSet_clean(EventSet* handle);
 extern void eventSet_set(EventSet* handle, const uint32_t evid);
-extern boolean eventSet_isAny(EventSet* handle);
+extern boolean eventSet_isAny_input(EventSet* handle);
+extern boolean eventSet_isAny_output(EventSet* handle);
+extern void eventSet_clean_single(EventSet* handle, const uint32_t evid);
 
 #endif /* EVENTSET_H_ */
 «ENDFILE»

+ 65 - 37
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Expression.ext

@@ -2,69 +2,75 @@ import stext;
 import sexec;
 import ecore;
 import sgraph;
-toCppCode(Void void) :
-	"/*toCppCode() called with NULL element. Polymorphic resolver could not match callable method!*/";
-String toCppCode(Void o, String statechartReference) : 
+
+toCCode(Void void) :
+	"/*toCCode() called with NULL element. Polymorphic resolver could not match callable method!*/";
+String toCCode(Void o, String statechartReference) : 
 	""; //polymorphic placeholder (abstract rule)
 
-String toCppCode(Expression statement) : 
+String toCCode(Expression statement) : 
 	null; //polymorphic placeholder (abstract rule)
  
-String toCppCode(Statement statement) : 
+String toCCode(Statement statement) : 
 	null; //polymorphic placeholder (abstract rule)
  
-String toCppCode(PrimitiveValueExpression primValue) :
+String toCCode(PrimitiveValueExpression primValue) :
 	primValue.value;
 
 /* Assignment */
-String toCppCode(Assignment assignment) :
+String toCCode(Assignment assignment) :
   switch (assignment.operator) {
-  case (AssignmentOperator::assign) : "variable->" + assignment.varRef.name + " = " + assignment.expression.toCppCode() + ";"  
-  case (AssignmentOperator::multAssign) : "variable->" + assignment.varRef.name + " *= " + assignment.expression.toCppCode() + ";"
-  case (AssignmentOperator::divAssign) : "variable->" + assignment.varRef.name + " /= " + assignment.expression.toCppCode() + ";"
-  case (AssignmentOperator::modAssign) : "variable->" + assignment.varRef.name + " %= " + assignment.expression.toCppCode() + ";"
-  case (AssignmentOperator::addAssign) : "variable->" + assignment.varRef.name + " += " + assignment.expression.toCppCode() + ";"
-  case (AssignmentOperator::subAssign) : "variable->" + assignment.varRef.name + " -= " + assignment.expression.toCppCode() + ";"
-  case (AssignmentOperator::leftShiftAssign) : "variable->" + assignment.varRef.name + " <<= "+ assignment.expression.toCppCode() + ";"
-  case (AssignmentOperator::rightShiftAssign) : "variable->" + assignment.varRef.name + " >>= " + assignment.expression.toCppCode() + ";"
-  case (AssignmentOperator::andAssign) : "variable->" + assignment.varRef.name + " &= " + assignment.expression.toCppCode() + ";"
-  case (AssignmentOperator::xorAssign) : "variable->" + assignment.varRef.name + " ^= " + assignment.expression.toCppCode() + ";"
-  case (AssignmentOperator::orAssign) : "variable->" + assignment.varRef.name + " |= " + assignment.expression.toCppCode() + ";"
+  case (AssignmentOperator::assign) : ((InterfaceScope)assignment.varRef.eContainer).name + "->" + assignment.varRef.name + " = " + assignment.expression.toCCode() + ";"  
+  case (AssignmentOperator::multAssign) : ((InterfaceScope)assignment.varRef.eContainer).name + "->" + " *= " + assignment.expression.toCCode() + ";"
+  case (AssignmentOperator::divAssign) : ((InterfaceScope)assignment.varRef.eContainer).name + "->" + " /= " + assignment.expression.toCCode() + ";"
+  case (AssignmentOperator::modAssign) : ((InterfaceScope)assignment.varRef.eContainer).name + "->" + " %= " + assignment.expression.toCCode() + ";"
+  case (AssignmentOperator::addAssign) : ((InterfaceScope)assignment.varRef.eContainer).name + "->" + " += " + assignment.expression.toCCode() + ";"
+  case (AssignmentOperator::subAssign) : ((InterfaceScope)assignment.varRef.eContainer).name + "->" + " -= " + assignment.expression.toCCode() + ";"
+  case (AssignmentOperator::leftShiftAssign) : ((InterfaceScope)assignment.varRef.eContainer).name + "->" + " <<= "+ assignment.expression.toCCode() + ";"
+  case (AssignmentOperator::rightShiftAssign) : ((InterfaceScope)assignment.varRef.eContainer).name + "->" + " >>= " + assignment.expression.toCCode() + ";"
+  case (AssignmentOperator::andAssign) : ((InterfaceScope)assignment.varRef.eContainer).name + "->" + " &= " + assignment.expression.toCCode() + ";"
+  case (AssignmentOperator::xorAssign) : ((InterfaceScope)assignment.varRef.eContainer).name + "->" + " ^= " + assignment.expression.toCCode() + ";"
+  case (AssignmentOperator::orAssign) : ((InterfaceScope)assignment.varRef.eContainer).name + "->" + " |= " + assignment.expression.toCCode() + ";"
   default : ""
   };
 		
 /* EventRaising */
+String toCCode(EventRaising eventRaising) :
+  "{ _Event* ev = eventPool_createEvent(handle->base.eventPool, ev_"+eventRaising.event.name+"); if (ev) { " + eventRaising.addValue() + "statemachine_cy_setEvent(&handle->base, ev); } }";
+
+String addValue(EventRaising event) :
+  ( (event.value == null)?"":("ev->value = " + event.value.toCCode() + ";") );
 
 /* Logical Expressions */
-String toCppCode(LogicalOrExpression expression) :
-  	expression.leftOperand.toCppCode() + " || " + expression.rightOperand.toCppCode();
+String toCCode(LogicalOrExpression expression) :
+  	expression.leftOperand.toCCode() + " || " + expression.rightOperand.toCCode();
   	
-String toCppCode(LogicalAndExpression expression) :
-  	expression.leftOperand.toCppCode() + " && " + expression.rightOperand.toCppCode();
+String toCCode(LogicalAndExpression expression) :
+  	expression.leftOperand.toCCode() + " && " + expression.rightOperand.toCCode();
 
-String toCppCode(LogicalNotExpression expression) :
-  	" ~" + expression.operand.toCppCode();
+String toCCode(LogicalNotExpression expression) :
+  	" ~" + expression.operand.toCCode();
 
-String toCppCode(LogicalRelationExpression expression) :
-   expression.leftOperand.toCppCode() + getOperator(expression.operator) + expression.rightOperand.toCppCode();
+String toCCode(LogicalRelationExpression expression) :
+   expression.leftOperand.toCCode() + getOperator(expression.operator) + expression.rightOperand.toCCode();
     
-String toCppCode(BitwiseAndExpression expression) :
-  	expression.leftOperand.toCppCode() + " & " + expression.rightOperand.toCppCode();
+String toCCode(BitwiseAndExpression expression) :
+  	expression.leftOperand.toCCode() + " & " + expression.rightOperand.toCCode();
 
-String toCppCode(BitwiseOrExpression expression) :
-  	expression.leftOperand.toCppCode() + " | " + expression.rightOperand.toCppCode();
+String toCCode(BitwiseOrExpression expression) :
+  	expression.leftOperand.toCCode() + " | " + expression.rightOperand.toCCode();
 
-String toCppCode(BitwiseXorExpression expression) :
-  	expression.leftOperand.toCppCode() + " ^ " + expression.rightOperand.toCppCode();
+String toCCode(BitwiseXorExpression expression) :
+  	expression.leftOperand.toCCode() + " ^ " + expression.rightOperand.toCCode();
 
-String toCppCode(NumericalAddSubtractExpression expression) :
-  	expression.leftOperand.toCppCode() + getOperator(expression.operator) + expression.rightOperand.toCppCode();
+String toCCode(NumericalAddSubtractExpression expression) :
+  	expression.leftOperand.toCCode() + getOperator(expression.operator) + expression.rightOperand.toCCode();
   	
-String toCppCode(NumericalMultiplyDivideExpression expression) :
-  	expression.leftOperand.toCppCode() + getOperator(expression.operator) + expression.rightOperand.toCppCode();
+String toCCode(NumericalMultiplyDivideExpression expression) :
+  	expression.leftOperand.toCCode() + getOperator(expression.operator) + expression.rightOperand.toCCode();
 
 // is this just relevant for events?
-String toCppCode(ElementReferenceExpression ev) :
+String toCCode(ElementReferenceExpression ev) :
     " ( eventSet_check( &handle->base.eventSet, ev_" + ev.value.name.toLowerCase() + ") ) ";
 
 String getOperator(AdditiveOperator operator) : 
@@ -92,3 +98,25 @@ String getOperator(RelationalOperator operator) :
 	  case (RelationalOperator::notEquals) : " != "
 	  default : ""
 	};
+
+String eventTypeToString(Type type) : 
+  switch (type) {
+  case (Type::void) : "void"
+  case (Type::real) : "real"
+  case (Type::integer) : "integer"
+  case (Type::boolean) : "boolean"
+  case (Type::string)  : "strng"
+  default : "unknownType"
+ };
+  
+Set[EventDefinition] getInEvents(InterfaceScope interface) : 
+	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::IN);
+
+Set[EventDefinition] getOutEvents(InterfaceScope interface) : 
+	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::OUT);
+
+Set[EventDefinition] getLocalEvents(InterfaceScope interface) : 
+	interface.declarations.typeSelect(EventDefinition).select(e|e.direction == Direction::LOCAL);
+
+
+	

+ 224 - 0
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Interfaces.xpt

@@ -0,0 +1,224 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::c::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::c::templates::Naming»
+
+
+«DEFINE file FOR ExecutionFlow»
+«FOREACH this.scopes.typeSelect(InterfaceScope) AS interface»
+«FILE interface.interfaceClassName()+".h"»
+
+#ifndef «interface.interfaceClassName().toUpperCase()»_H_
+#define «interface.interfaceClassName().toUpperCase()»_H_
+
+#include "definition.h"
+#include "Event.h"
+#include "EventSet.h"
+#include "EventPool.h"
+#include "Statemachine_cy.h"
+#include "«EvName()».h"
+
+typedef void(*handleEvent)(_Event ev);
+
+typedef struct {
+	EventSet* eventSet;
+	Statemachine_cy* statemachine;
+#ifdef INTERFACE_LISTENER
+	handleEvent handleEventCallback;
+#else
+	EventPool* eventPool;
+«FOREACH interface.getOutEvents() AS event -»
+    _Event* «event.name»;
+«ENDFOREACH»
+#endif // INTERFACE_LISTENER
+
+«FOREACH interface.declarations.typeSelect(VariableDefinition) AS variable -»
+	«variable.type» «variable.name»;
+«ENDFOREACH» 
+	
+} «interfaceClassName(interface)»;
+
+«FOREACH interface.declarations.typeSelect(VariableDefinition) AS variable -»
+extern «eventTypeToString(variable.type)» «interface.interfaceName()»_get_«variable.name»(«interfaceClassName(interface)»* handle);
+«IF variable.readonly == false -»
+extern void «interface.interfaceName()»_set_«variable.name»(«interfaceClassName(interface)»* handle, «eventTypeToString(variable.type)» value);
+«ENDIF»
+«ENDFOREACH» 
+
+
+extern void «interface.interfaceName()»_reset_event(«interfaceClassName(interface)»* handle);
+
+#ifdef INTERFACE_LISTENER
+
+extern void «interface.interfaceName()»_init(«interfaceClassName(interface)»* handle, 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);
+
+#else
+
+extern void «interface.interfaceName()»_init(«interfaceClassName(interface)»* handle, 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» );
+«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»);
+«ENDFOREACH» 
+
+#endif // INTERFACE_LISTENER
+
+
+#endif /* INTERFACEBASE_H_ */
+
+
+«ENDFILE»
+
+«FILE interface.interfaceClassName()+".c"»
+#include "«interface.interfaceClassName()».h"
+#include <stdlib.h>
+
+static boolean «interface.interfaceName()»_is_my_event(«interface.interfaceClassName()»* handle, uint32_t evid);
+
+#ifdef INTERFACE_LISTENER
+void «interface.interfaceName()»_init(«interface.interfaceClassName()»* handle, Statemachine_cy* statemachine,
+		EventSet* eventSet)
+#else
+void «interface.interfaceName()»_init(«interface.interfaceClassName()»* handle, Statemachine_cy* statemachine,
+		EventSet* eventSet, EventPool* eventPool)
+#endif
+{
+	handle->eventSet = eventSet;
+	/* initial values */
+	
+«FOREACH interface.declarations.typeSelect(VariableDefinition) AS variable -»
+«IF variable.initialValue != null»
+	handle->«variable.name» = «variable.initialValue»;
+«ENDIF»
+«ENDFOREACH»
+
+	«interface.interfaceName()»_reset_event(handle);
+
+	handle->statemachine = statemachine;
+
+#ifndef INTERFACE_LISTENER
+	handle->eventPool = eventPool;
+«FOREACH interface.getOutEvents() AS event -»
+	handle->«event.name» = eventPool_createEvent(handle->eventPool, «event.getEventEnumName()»);
+	// ((«event.name»*)handle->«event.name»)->value = initial value for events is missing in model;
+«ENDFOREACH»
+#endif
+
+}
+
+«FOREACH interface.declarations.typeSelect(VariableDefinition) AS variable -»
+«variable.type.eventTypeToString()» «interface.interfaceName()»_get_«variable.name»(«interface.interfaceClassName()»* handle)
+{
+	return handle->«variable.name»;
+}
+«IF variable.readonly == false -»
+void «interface.interfaceName()»_set_«variable.name»(«interface.interfaceClassName()»* handle, «variable.type.eventTypeToString()» value)
+{
+	handle->«variable.name» = value;
+}
+«ENDIF»
+«ENDFOREACH»
+
+
+boolean «interface.interfaceName()»_is_set(«interface.interfaceClassName()»* handle, uint32_t evid)
+{
+	if («interface.interfaceName()»_is_my_event(handle, evid))
+		return eventSet_check(handle->eventSet, evid);
+	return bool_false;
+}
+
+void «interface.interfaceName()»_reset_event(«interface.interfaceClassName()»* handle)
+{
+	// clean all out events
+	«FOREACH interface.getOutEvents() AS outEvent»
+	eventSet_clean_single(handle->eventSet, «outEvent.getEventEnumName()»);
+	«ENDFOREACH»
+
+}
+
+#ifdef INTERFACE_LISTENER
+
+void «interface.interfaceName()»_set_listener(«interface.interfaceClassName()»* handle, handleEvent handleEventPtr)
+{
+	handle->handleEventCallback = handleEventPtr;
+}
+
+void «interface.interfaceName()»_raiseEvent(«interface.interfaceClassName()»* handle, _Event event) {
+	if («interface.interfaceName()»_is_my_event(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») 
+{
+	boolean ret = bool_false;
+	if (eventSet_check(handle->eventSet,«event.getEventEnumName()»)) {
+«IF event.type != Type::void -»	
+		*value = ((«event.name»*)handle->«event.name»)->value;
+«ENDIF»
+		ret = bool_true;
+	}
+	return ret;
+}
+
+«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»)
+{
+	_Event* ev = eventPool_createEvent(handle->eventPool, «event.getEventEnumName()»);
+
+«IF event.type != Type::void -»
+	ev->value = value;
+«ENDIF»
+
+	if (ev != NULL)
+		statemachine_cy_setEvent(handle->statemachine, ev);
+}
+«ENDFOREACH» 
+
+#endif // INTERFACE_LISTENER
+
+
+boolean «interface.interfaceName()»_is_my_event(«interface.interfaceClassName()»* handle, uint32_t evid)
+{
+	boolean ret = bool_false;
+	switch (evid) {
+«FOREACH interface.getInEvents() AS event -»
+	case «event.getEventEnumName()»:
+«ENDFOREACH»
+		ret = bool_true;
+		break;
+	default:
+		break;
+	}
+	return ret;
+}
+
+«ENDFILE»
+«ENDFOREACH»
+«ENDDEFINE»

+ 4 - 5
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Main.xpt

@@ -32,6 +32,7 @@ Contais the root templates that call the different file templates.
 	«EXPAND Statemachine_cyH::file FOR this»
 	«EXPAND Statemachine_cyC::file FOR this»
 
+	«EXPAND Interfaces::file FOR this»
 
     «REM» code that is created by the model «ENDREM»
 	«EXPAND definitionH::file FOR this»
@@ -42,16 +43,14 @@ Contais the root templates that call the different file templates.
 	«EXPAND CustomStatemachineH::file FOR this»
 	«EXPAND CustomStatemachineC::file FOR this»
 	
-	«EXPAND CustomRepositoryH::file FOR this»
-	«EXPAND CustomRepositoryC::file FOR this»
-
 	«EXPAND CustomEventH::file FOR this»
 	«EXPAND CustomEventC::file FOR this»
-	
+
 	«EXPAND CMakeLists::file FOR this»
 	
-	«REM» Test Code «ENDREM»
+	«REM» Test Code
 	«EXPAND TestMain::file FOR this»
+	 «ENDREM»
 	«EXPAND DummyTimer::file FOR this»
 
 «ENDDEFINE»

+ 10 - 2
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Naming.ext

@@ -6,9 +6,9 @@ import sgraph;
 
 String scName(Expression statement) : ((ExecutionFlow)statement.eRootContainer).name ;
 
-List declaredEvents(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(EventDefinition);
+List[EventDefinition] declaredEvents(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(EventDefinition);
 
-List declaredVariables(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(VariableDefinition);
+List[VariableDefinition] declaredVariables(ExecutionFlow flow) : flow.scopes.declarations.typeSelect(VariableDefinition);
 
 String test(NamedElement obj) :  "";
 String StName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "Statemachine";
@@ -42,4 +42,12 @@ Reaction reaction(Step this) : (Reaction) this.eContainer ;
 ExecutionState state(Reaction this) : (ExecutionState) eContainer;
 ExecutionState state(Step this) : (ExecutionState) eContainer;
 
+ExecutionFlow getExecutionFlow(InterfaceScope this) : ((ExecutionFlow)this.eContainer);
+
+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());
+String interfaceObjectName(InterfaceScope this) : "interface" + ((this.name == null)?"":this.name.toFirstUpper());
+
+String getEventEnumName(EventDefinition this) : "ev_" + this.name;
+
 

+ 27 - 12
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Statemachine_cyC.xpt

@@ -14,6 +14,13 @@ Templates for the main statechart c file.
 «DEFINE file FOR ExecutionFlow»
 
 «FILE 'Statemachine_cy.c'»
+/*
+ * Statemachine_cy.cpp
+ *
+ *  Created on: 10.09.2011
+ *      Author: seger
+ */
+
 #include <stdlib.h>
 #include "definition.h"
 #include "Statemachine_cy.h"
@@ -22,7 +29,7 @@ void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
 		uint16_t maxEvents, Timer* timer, EventPool* eventPool) {
 
 	uint32_t i;
-	
+
 	statemachineBase_init((StatemachineBase*) handle, maxStates, timer);
 	eventSet_init(&handle->eventSet, maxEvents);
 
@@ -41,10 +48,10 @@ void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
 
 void statemachine_cy_init_staticData(Statemachine_cy* handle,
 		uint16_t maxEvents, Timer* timer, uint32_t* staticStateData,
-		boolean* staticEventSet, _Event** staticListPtr, EventPool* eventPool) {
+		boolean* staticEventSet, EventType* eventTypes, _Event** staticListPtr, EventPool* eventPool) {
 	statemachineBase_init_staticData((StatemachineBase*) handle,
 			staticStateData, timer);
-	eventSet_init_staticData(&handle->eventSet, maxEvents, staticEventSet);
+	eventSet_init_staticData(&handle->eventSet, maxEvents, staticEventSet, eventTypes);
 
 	/* Hand out event List */
 	handle->eventList = staticListPtr;
@@ -57,10 +64,9 @@ void statemachine_cy_init_staticData(Statemachine_cy* handle,
 void statemachine_cy_exit(Statemachine_cy* handle) {
 
 	uint32_t i;
-
 	// the active events, which are not been handled need to be freed
 	for (i = 0; i < handle->eventSet.maxEvents; ++i) {
-		if (eventSet_check(&handle->eventSet, i))
+		if (eventSet_is_type(&handle->eventSet, i, ev_type_input) && eventSet_check(&handle->eventSet, i))
 			eventPool_freeEvent(handle->eventPool, handle->eventList[i]);
 	}
 
@@ -76,20 +82,30 @@ void statemachine_cy_runCycle(Statemachine_cy* handle) {
 
 	uint32_t i;
 
+	/* delete all outgoing events */
+	for (i=0; i<handle->eventSet.maxEvents; ++i) {
+		// only delete events, that where marked as out
+		if (eventSet_is_type(&handle->eventSet,i,ev_type_output) && eventSet_check(&handle->eventSet, i)) {
+			// output events are out of our control
+			//eventPool_freeEvent(handle->eventPool, handle->eventList[i]);
+			eventSet_clean_single(&handle->eventSet, i);
+			handle->eventList[i] = 0;
+		}
+	}
+
 	/* call internal cycle */
 	statemachine_cy__runCycle(handle);
 
-	/* delete all events */
+	/* delete all incoming events */
 	for (i=0; i<handle->eventSet.maxEvents; ++i) {
-		if (eventSet_check(&handle->eventSet, i)) {
+		// only delete events, that where marked as out
+		if (eventSet_is_type(&handle->eventSet,i,ev_type_input) && eventSet_check(&handle->eventSet, i)) {
 			eventPool_freeEvent(handle->eventPool, handle->eventList[i]);
+			eventSet_clean_single(&handle->eventSet, i);
 			handle->eventList[i] = 0;
 		}
 	}
 
-	/* cleanup all events */
-	eventSet_clean(&handle->eventSet);
-
 }
 
 void statemachine_cy_setEvent(Statemachine_cy* handle, _Event* ev) {
@@ -101,10 +117,9 @@ void statemachine_cy_setEvent(Statemachine_cy* handle, _Event* ev) {
 
 boolean statemachine_cy_eventWaiting(Statemachine_cy* handle) {
 
-	return eventSet_isAny(&handle->eventSet);
+	return eventSet_isAny_input(&handle->eventSet);
 }
 
-
 «ENDFILE»
 
 «ENDDEFINE»

+ 1 - 3
plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/templates/Statemachine_cyH.xpt

@@ -34,11 +34,10 @@ extern void statemachine_cy_init(Statemachine_cy* handle, uint16_t maxStates,
 
 extern void statemachine_cy_init_staticData(Statemachine_cy* handle,
 		uint16_t maxEvents, Timer* timer, uint32_t* staticStateData,
-		boolean* staticEventSet, _Event** staticListPtr, EventPool* eventPool);
+		boolean* staticEventSet, EventType* eventTypes, _Event** staticListPtr, EventPool* eventPool);
 
 extern void statemachine_cy_exit(Statemachine_cy* handle);
 
-/* implement me */
 extern void statemachine_cy_runCycle(Statemachine_cy* handle);
 
 extern void statemachine_cy_setEvent(Statemachine_cy* handle, _Event* ev);
@@ -48,7 +47,6 @@ extern boolean statemachine_cy_eventWaiting(Statemachine_cy* handle);
 extern void statemachine_cy__runCycle(Statemachine_cy* handle);
 
 #endif /* STATEMACHINE_CY_H_ */
-
 «ENDFILE»
 
 «ENDDEFINE»