Browse Source

Changed Event Handling due to discussion and YAKHMI-190
More tests will follow

jos.itemis@gmail.com 14 years ago
parent
commit
09d3065a5b

+ 7 - 3
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomEventH.xpt

@@ -23,14 +23,18 @@ Templates for the main statechart cpp file.
 #include "Event.h"
 
 enum EventID {
-«FOREACH this.declaredEvents() AS ev»
-  ev_«((EventDefinition)ev).name.toLowerCase()»,
+«FOREACH this.declaredEvents() AS ev -»
+  ev_«((EventDefinition)ev).name.toLowerCase() -»,
 «ENDFOREACH»
 	event_last
 };
 
 «FOREACH this.declaredEvents() AS ev»
-  class «((EventDefinition)ev).name» : public _Event { public: «((EventDefinition)ev).name»() : _Event((uint32_t)ev_«((EventDefinition)ev).name.toLowerCase()») {} };
+class «((EventDefinition)ev).name» : public _Event { 
+  public: 
+    «((EventDefinition)ev).name»() : _Event((uint32_t)ev_«((EventDefinition)ev).name.toLowerCase()») {} 
+    «eventTypeToString(((EventDefinition)ev).type)» value;    
+};
   // internal variables unhandled
 «ENDFOREACH»
  

+ 47 - 36
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomStatemachine_cyCPP.xpt

@@ -19,15 +19,15 @@ Templates for the main statechart cpp file.
 // ActionCode for Step not defined
 «ENDDEFINE»
 
-«DEFINE ActionCode FOR Execution»
+«DEFINE ActionCode FOR Execution -»
 	«this.statement.toCppCode()»
 «ENDDEFINE»
 
-«DEFINE ActionCode FOR Call»
+«DEFINE ActionCode FOR Call -»
 «this.step.functionName()»();
 «ENDDEFINE»
 
-«DEFINE ActionCode FOR Sequence»
+«DEFINE ActionCode FOR Sequence -»
   «EXPAND ActionCode FOREACH this.steps»
 «ENDDEFINE»
 
@@ -47,72 +47,72 @@ Templates for the main statechart cpp file.
   ENDIF -»«
 ENDDEFINE»
 
-«DEFINE ActionCode FOR Reaction»
+«DEFINE ActionCode FOR Reaction -»
   «EXPAND ActionCode FOR this.effect» 
 «ENDDEFINE»
 
-«DEFINE ActionCode FOR If»
+«DEFINE ActionCode FOR If -»
 if («EXPAND ActionCode FOR this.check») { 
-  «EXPAND ActionCode FOR this.thenStep»
+  «EXPAND ActionCode FOR this.thenStep -»
 }
 else {
-  «EXPAND ActionCode FOR this.elseStep»
+  «EXPAND ActionCode FOR this.elseStep -»
 }
 «ENDDEFINE»
 
-«DEFINE ActionCode FOR EnterState»
+«DEFINE ActionCode FOR EnterState -»
 state[0] = _«this.state.simpleName»;
 «ENDDEFINE»
 
-«DEFINE ActionCode FOR ExitState»
+«DEFINE ActionCode FOR ExitState -»
 state[0] = last_state;
 «ENDDEFINE»
 
-«DEFINE ConditionMethodsImplement FOR ExecutionState»
-  «FOREACH reactions AS r»
+«DEFINE ConditionMethodsImplement FOR ExecutionState -»
+  «FOREACH reactions AS r -»
   «IF r.check != null -»
 bool «StNameCy()»::«r.check.functionName()»() {
   return (	«r.check.condition.toCppCode()» );
 }
   «ENDIF -»
-  «ENDFOREACH»
+  «ENDFOREACH -»
 «ENDDEFINE»
 
-«DEFINE StatementMethodsImplement FOR ExecutionState»
-  «FOREACH reactions AS r»
+«DEFINE StatementMethodsImplement FOR ExecutionState -»
+  «FOREACH reactions AS r -»
 void «StNameCy()»::«r.effect.functionName()»() {
-  «EXPAND ActionCode FOR r.effect»
+  «EXPAND ActionCode FOR r.effect -»
 }
   «ENDFOREACH»
 «ENDDEFINE»
 
-«DEFINE CycleCode FOR Cycle» 
+«DEFINE CycleCode FOR Cycle- » 
 «EXPAND ActionCode FOREACH this.steps»
 «ENDDEFINE»
 
-«DEFINE CycleMethodsImplement FOR ExecutionState»
+«DEFINE CycleMethodsImplement FOR ExecutionState -»
 void «StNameCy()»::cycle_«this.simpleName»()
 {
 	«EXPAND CycleCode FOR cycle»
 }
 «ENDDEFINE»
 
-«DEFINE EnterMethodImplement FOR ExecutionState»
-«IF this.entryAction != null»
+«DEFINE EnterMethodImplement FOR ExecutionState -»
+«IF this.entryAction != null -»
 void «StNameCy()»::«this.entryAction.entryActionFunctionName()»()
 {
-«EXPAND ActionCode FOR this.entryAction»
+«EXPAND ActionCode FOR this.entryAction -»
 }
-«ENDIF»
+«ENDIF -»
 «ENDDEFINE»
 
-«DEFINE ExitMethodImplement FOR ExecutionState»
-«IF this.exitAction != null»
+«DEFINE ExitMethodImplement FOR ExecutionState -»
+«IF this.exitAction != null -»
 void «StNameCy()»::«this.exitAction.exitActionFunctionName()»()
 {
-«EXPAND ActionCode FOR this.exitAction»
+«EXPAND ActionCode FOR this.exitAction -»
 }
-«ENDIF»
+«ENDIF -»
 «ENDDEFINE»
 
 «DEFINE file FOR ExecutionFlow»
@@ -126,21 +126,32 @@ void 
 «StNameCy()»::~«StNameCy()»() {
 }
 
-«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»
-
+«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 «StNameCy()»::init()
 {
-	«EXPAND ActionCode FOREACH this.enterSequence.steps»
+	«EXPAND ActionCode FOREACH this.enterSequence.steps -»
+}
+
+«FOREACH declaredEvents() AS event -»
+«IF (((EventDefinition)event).type == Type::void) -»
+void set«((EventDefinition)event).name.toFirstUpper()»()
+«ELSE -»
+void set«((EventDefinition)event).name.toFirstUpper()»(«eventTypeToString(((EventDefinition)event).type)» value)
+«ENDIF -»
+{
+	«((EventDefinition)event).name»* ev(new «((EventDefinition)event).name»);
+
+«IF (((EventDefinition)event).type != Type::void) -»
+	ev->value = value;
+«ENDIF -»
+	queueEvent(ev);
 }
+«ENDFOREACH -»
 
 /* Yet unimplemented
 void «StNameCy()»::exit()

+ 21 - 16
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomStatemachine_cyH.xpt

@@ -31,8 +31,8 @@ class 
 public:
 	enum States {
 	    «FOREACH this.states AS exState-»
-	      _«exState.simpleName»,
-	    «ENDFOREACH»
+	    _«exState.simpleName -»,
+	    «ENDFOREACH -»
 		last_state
 	};		
 
@@ -42,35 +42,35 @@ protected:
 	  «FOREACH state.reactions AS reaction -»
 	  «IF reaction.check != null -»
 	bool «reaction.check.functionName()»();
-	  «ENDIF»
-	  «ENDFOREACH»
-	«ENDFOREACH»
+	  «ENDIF -»
+	  «ENDFOREACH -»
+	«ENDFOREACH -»
 	
 	/* actions */
 	«FOREACH states AS state -»
 	  «FOREACH state.reactions AS reaction -»
 	void «reaction.effect.functionName()»();
-	  «ENDFOREACH»
-	«ENDFOREACH»
+	  «ENDFOREACH -»
+	«ENDFOREACH -»
 
 	/* cycles */
 	«FOREACH states AS state -»
 	void cycle_«state.simpleName»();
-	«ENDFOREACH»
+	«ENDFOREACH -»
 	
 	/* entrys */
 	«FOREACH states AS state -»
-	«IF state.entryAction != null»
+	«IF state.entryAction != null -»
 	void «state.entryAction.entryActionFunctionName()»();
-	«ENDIF»
-	«ENDFOREACH»
+	«ENDIF -»
+	«ENDFOREACH -»
 	
 	/*exits */
 	«FOREACH states AS state -»
-	«IF state.exitAction != null»
+	«IF state.exitAction != null -»
 	void «state.exitAction.exitActionFunctionName()»();
-	«ENDIF»
-	«ENDFOREACH»
+	«ENDIF -»
+	«ENDFOREACH -»
 	
 	virtual void _runCycle();
 
@@ -81,8 +81,13 @@ public:
 
 	virtual void init();
 
-	//virtual void queueEvent(const Event& ev);
-
+	«FOREACH declaredEvents() AS event -»
+	«IF (((EventDefinition)event).type == Type::void) -»
+	void set«((EventDefinition)event).name.toFirstUpper()»();
+	«ELSE -»
+	void set«((EventDefinition)event).name.toFirstUpper()»(«eventTypeToString(((EventDefinition)event).type)» value);
+	«ENDIF -»
+    «ENDFOREACH -»
 };
 
 //}; // namespace

+ 8 - 1
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DataRepositoryCPP.xpt

@@ -26,7 +26,14 @@ DataRepository::DataRepository() : eventDataList(0), maxDataListItems(0)
 void DataRepository::clearEventData()
 {
 	for(uint32_t i(0);i<maxDataListItems; ++i) {
-//		delete eventDataList[i];
+		eventDataList[i] = 0;
+	}
+}
+
+void DataRepository::deleteEventData()
+{
+	for(uint32_t i(0);i<maxDataListItems; ++i) {
+		delete eventDataList[i];
 		eventDataList[i] = 0;
 	}
 }

+ 2 - 1
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DataRepositoryH.xpt

@@ -30,7 +30,8 @@ protected:
 
 	void clearEventData();
 	void setEventData(const Event& data);
-
+    void deleteEventData();
+     
 public:
 	DataRepository();
 	DataRepository(const uint32_t maxEvents);

+ 11 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Expression.ext

@@ -92,3 +92,14 @@ 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"
+  };
+	

+ 2 - 1
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Naming.ext

@@ -28,7 +28,8 @@ cached String functionName(Step step) :
 	(step.isEntryAction()) ? step.entryActionFunctionName() : ( 
 	(step.isExitAction()) ? step.exitActionFunctionName() : 
 	" !! unknown function type !!" )));
- 
+
+
 String actionFunctionName(Step this) : "actions_" + this.reaction().state().simpleName + "_" + this.reaction().name; 
 String checkFunctionName(Step this) : "condition_" + this.reaction().state().simpleName + "_" + this.reaction().name; 
 String entryActionFunctionName(Step this) : "entryActions_" + this.state().simpleName;