Procházet zdrojové kódy

Added first Version of cpp templates for Cycle Based Stuff

jos.itemis@gmail.com před 14 roky
rodič
revize
a3bace6f4b
30 změnil soubory, kde provedl 1088 přidání a 228 odebrání
  1. 22 5
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CMakeLists.xpt
  2. 2 2
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomEventH.xpt
  3. 14 14
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomStatemachineCPP.xpt
  4. 94 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomStatemachine_cyH.xpt
  5. 178 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomStatemachine_evCPP.xpt
  6. 7 5
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomStatemachineH.xpt
  7. 38 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DataRepositoryBoost.xpt
  8. 59 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DataRepositoryCPP.xpt
  9. 9 19
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DataRepositoryH.xpt
  10. 33 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DummyTimerCPP.xpt
  11. 35 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DummyTimerH.xpt
  12. 1 1
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/EventH.xpt
  13. 34 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/EventReceiverH.xpt
  14. 71 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/EventSetCPP.xpt
  15. 41 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/EventSetH.xpt
  16. 12 2
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Expression.ext
  17. 35 9
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Main.xpt
  18. 2 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Naming.ext
  19. 0 21
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatechartCPP.xpt
  20. 0 76
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatechartH.xpt
  21. 40 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatemachineBaseCPP.xpt
  22. 49 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatemachineBaseH.xpt
  23. 0 51
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatemachineH.xpt
  24. 48 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Statemachine_cyCPP.xpt
  25. 46 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Statemachine_cyH.xpt
  26. 10 11
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatemachineCPP.xpt
  27. 54 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Statemachine_evH.xpt
  28. 112 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/TestMain_cy.xpt
  29. 6 12
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/TestMain.xpt
  30. 36 0
      plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/TimerH.xpt

+ 22 - 5
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CMakeLists.xpt

@@ -18,14 +18,31 @@ Templates for the main statechart cpp file.
 «FILE 'CMakeLists.txt'»
 cmake_minimum_required(VERSION 2.8)
 
-set(SRC
-	Statemachine.cpp
-	«StName()».cpp
-	main.cpp
+set ( SRC_BASE
+	DataRepository.cpp
+	DummyTimer.cpp
+	EventSet.cpp
+	StatemachineBase.cpp
+)
+
+set ( SRC_EV
+	Statemachine_ev.cpp
+	Statemachine_ev.h
+	main_ev.cpp
+	«StName()»_ev.cpp
+)
+
+set ( SRC_CY
+	Statemachine_cy.cpp
+	Statemachine_cy.h
+	main_cy.cpp
+	«StName()»_cy.cpp
 )
 
 add_definitions( -Wall -O0 -g)
-add_executable(«StName()»Main ${SRC})
+add_executable(«StName()»_ev_main ${SRC_BASE} ${SRC_EV})
+add_executable(«StName()»_cy_main ${SRC_BASE} ${SRC_CY})
+
 «ENDFILE»
 
 «ENDDEFINE»

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

@@ -24,13 +24,13 @@ Templates for the main statechart cpp file.
 
 enum EventID {
 «FOREACH this.declaredEvents() AS ev»
-  _«((EventDefinition)ev).name.toLowerCase()»,
+  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)_«((EventDefinition)ev).name.toLowerCase()») {} };
+  class «((EventDefinition)ev).name» : public _Event { public: «((EventDefinition)ev).name»() : _Event((uint32_t)ev_«((EventDefinition)ev).name.toLowerCase()») {} };
   // internal variables unhandled
 «ENDFOREACH»
  

+ 14 - 14
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomStatemachineCPP.xpt

@@ -41,7 +41,7 @@ Templates for the main statechart cpp file.
 
 «DEFINE ActionCode FOR CheckRef -»
   «IF this.check != null -»
-  «this.check.functionName()»(ev) «
+  «this.check.functionName()»() «
   ELSE -»
  true «
   ENDIF -»«
@@ -71,7 +71,7 @@ state[0] = last_state;
 «DEFINE ConditionMethodsImplement FOR ExecutionState»
   «FOREACH reactions AS r»
   «IF r.check != null -»
-bool «StName()»::«r.check.functionName()»(const _Event& ev) {
+bool «StNameCy()»::«r.check.functionName()»() {
   return (	«r.check.condition.toCppCode()» );
 }
   «ENDIF -»
@@ -80,7 +80,7 @@ bool 
 
 «DEFINE StatementMethodsImplement FOR ExecutionState»
   «FOREACH reactions AS r»
-void «this.StName()»::«r.effect.functionName()»() {
+void «StNameCy()»::«r.effect.functionName()»() {
   «EXPAND ActionCode FOR r.effect»
 }
   «ENDFOREACH»
@@ -91,7 +91,7 @@ void 
 «ENDDEFINE»
 
 «DEFINE CycleMethodsImplement FOR ExecutionState»
-void «StName()»::cycle_«this.simpleName»(const _Event& ev)
+void «StNameCy()»::cycle_«this.simpleName»()
 {
 	«EXPAND CycleCode FOR cycle»
 }
@@ -99,7 +99,7 @@ void 
 
 «DEFINE EnterMethodImplement FOR ExecutionState»
 «IF this.entryAction != null»
-void «StName()»::«this.entryAction.entryActionFunctionName()»()
+void «StNameCy()»::«this.entryAction.entryActionFunctionName()»()
 {
 «EXPAND ActionCode FOR this.entryAction»
 }
@@ -108,7 +108,7 @@ void 
 
 «DEFINE ExitMethodImplement FOR ExecutionState»
 «IF this.exitAction != null»
-void «StName()»::«this.exitAction.exitActionFunctionName()»()
+void «StNameCy()»::«this.exitAction.exitActionFunctionName()»()
 {
 «EXPAND ActionCode FOR this.exitAction»
 }
@@ -116,14 +116,14 @@ void 
 «ENDDEFINE»
 
 «DEFINE file FOR ExecutionFlow»
-«FILE StName()+'.cpp'»
+«FILE StName()+'_cy.cpp'»
 #include <iostream>
-#include "«StName()».h"
+#include "«StNameCy()».h"
 
-«StName()»::«StName()»() : Statemachine(«((ExecutionFlow)this.eRootContainer).stateVector.size») {
+«StNameCy()»::«StNameCy()»(Timer* _timer) : Statemachine_cy(«((ExecutionFlow)this.eRootContainer).stateVector.size», event_last, _timer) {
 }
 
-«StName()»::~«StName()»() {
+«StNameCy()»::~«StNameCy()»() {
 }
 
 «EXPAND ConditionMethodsImplement FOREACH this.states»
@@ -137,24 +137,24 @@ void 
 «EXPAND ExitMethodImplement FOREACH this.states»
 
 
-void «StName()»::init()
+void «StNameCy()»::init()
 {
 	«EXPAND ActionCode FOREACH this.enterSequence.steps»
 }
 
 /* Yet unimplemented
-void «StName()»::exit()
+void «StNameCy()»::exit()
 {
 }
 */
 
-void «StName()»::_runCycle(Event ev)
+void «StNameCy()»::_runCycle()
 {
 	for (int i=0; i<MAX_PARALLEL_STATES; ++i) {
 		switch(state[i]) {
 	«FOREACH this.states AS state»
 	    case _«state.simpleName»:
-	        cycle_«state.simpleName»(*ev);
+	        cycle_«state.simpleName»();
 	        break;
 	«ENDFOREACH»
 		default:

+ 94 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomStatemachine_cyH.xpt

@@ -0,0 +1,94 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::cpp::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::cpp::templates::Naming»
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE StName()+'_cy.h'»
+#ifndef «STNAME()»_H_
+#define «STNAME()»_H_
+
+#include "Statemachine_cy.h"
+#include "«DRName()».h"
+#include "«EvName()».h"
+
+
+#define MAX_PARALLEL_STATES «this.stateVector.size»
+
+class «StNameCy()»: public Statemachine_cy, public «DRName()» {
+
+public:
+	enum States {
+	    «FOREACH this.states AS exState-»
+	      _«exState.simpleName»,
+	    «ENDFOREACH»
+		last_state
+	};		
+
+protected:
+	/* conditions */
+	«FOREACH states AS state -»
+	  «FOREACH state.reactions AS reaction -»
+	  «IF reaction.check != null -»
+	bool «reaction.check.functionName()»();
+	  «ENDIF»
+	  «ENDFOREACH»
+	«ENDFOREACH»
+	
+	/* actions */
+	«FOREACH states AS state -»
+	  «FOREACH state.reactions AS reaction -»
+	void «reaction.effect.functionName()»();
+	  «ENDFOREACH»
+	«ENDFOREACH»
+
+	/* cycles */
+	«FOREACH states AS state -»
+	void cycle_«state.simpleName»();
+	«ENDFOREACH»
+	
+	/* entrys */
+	«FOREACH states AS state -»
+	«IF state.entryAction != null»
+	void «state.entryAction.entryActionFunctionName()»();
+	«ENDIF»
+	«ENDFOREACH»
+	
+	/*exits */
+	«FOREACH states AS state -»
+	«IF state.exitAction != null»
+	void «state.exitAction.exitActionFunctionName()»();
+	«ENDIF»
+	«ENDFOREACH»
+	
+	virtual void _runCycle();
+
+public:
+
+	«StNameCy()»(Timer* timer);
+	virtual ~«StNameCy()»();
+
+	virtual void init();
+
+	//virtual void queueEvent(const Event& ev);
+
+};
+
+//}; // namespace
+#endif /* «STNAME()»_H_ */
+
+«ENDFILE»
+
+«ENDDEFINE»
+

+ 178 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomStatemachine_evCPP.xpt

@@ -0,0 +1,178 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+«IMPORT ecore»
+
+«IMPORT org::yakindu::sct::generator::cpp::templates»
+«EXTENSION org::yakindu::sct::generator::cpp::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::cpp::templates::Naming»
+
+«DEFINE ActionCode FOR Step»
+// ActionCode for Step not defined
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Execution»
+	«this.statement.toCppCode()»
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Call»
+«this.step.functionName()»();
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Sequence»
+  «EXPAND ActionCode FOREACH this.steps»
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR Check -»
+  «IF this != null -»
+«this.condition.toCppCode() -»
+  «ELSE -»
+ true «
+ ENDIF -»«
+  ENDDEFINE»
+
+«DEFINE ActionCode FOR CheckRef -»
+  «IF this.check != null -»
+  «this.check.functionName()»(ev) «
+  ELSE -»
+ true «
+  ENDIF -»«
+ENDDEFINE»
+
+«DEFINE ActionCode FOR Reaction»
+  «EXPAND ActionCode FOR this.effect» 
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR If»
+if («EXPAND ActionCode FOR this.check») { 
+  «EXPAND ActionCode FOR this.thenStep»
+}
+else {
+  «EXPAND ActionCode FOR this.elseStep»
+}
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR EnterState»
+state[0] = _«this.state.simpleName»;
+«ENDDEFINE»
+
+«DEFINE ActionCode FOR ExitState»
+state[0] = last_state;
+«ENDDEFINE»
+
+«DEFINE ConditionMethodsImplement FOR ExecutionState»
+  «FOREACH reactions AS r»
+  «IF r.check != null -»
+bool «StNameEv()»::«r.check.functionName()»(const _Event& ev) {
+  return (	«r.check.condition.toCppCode()» );
+}
+  «ENDIF -»
+  «ENDFOREACH»
+«ENDDEFINE»
+
+«DEFINE StatementMethodsImplement FOR ExecutionState»
+  «FOREACH reactions AS r»
+void «this.StName()»::«r.effect.functionName()»() {
+  «EXPAND ActionCode FOR r.effect»
+}
+  «ENDFOREACH»
+«ENDDEFINE»
+
+«DEFINE CycleCode FOR Cycle» 
+«EXPAND ActionCode FOREACH this.steps»
+«ENDDEFINE»
+
+«DEFINE CycleMethodsImplement FOR ExecutionState»
+void «StNameEv()»::cycle_«this.simpleName»(const _Event& ev)
+{
+	«EXPAND CycleCode FOR cycle»
+}
+«ENDDEFINE»
+
+«DEFINE EnterMethodImplement FOR ExecutionState»
+«IF this.entryAction != null»
+void «StNameEv()»::«this.entryAction.entryActionFunctionName()»()
+{
+«EXPAND ActionCode FOR this.entryAction»
+}
+«ENDIF»
+«ENDDEFINE»
+
+«DEFINE ExitMethodImplement FOR ExecutionState»
+«IF this.exitAction != null»
+void «StNameEv()»::«this.exitAction.exitActionFunctionName()»()
+{
+«EXPAND ActionCode FOR this.exitAction»
+}
+«ENDIF»
+«ENDDEFINE»
+
+«DEFINE file FOR ExecutionFlow»
+«FILE StName()+'_ev.cpp'»
+#include <iostream>
+#include "«StNameEv()».h"
+
+«StNameEv()»::«StNameEv()»(Timer* _timer) : Statemachine_ev(«((ExecutionFlow)this.eRootContainer).stateVector.size», event_last, _timer) {
+}
+
+«StNameEv()»::~«StNameEv()»() {
+}
+
+«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 «StNameEv()»::init()
+{
+	«EXPAND ActionCode FOREACH this.enterSequence.steps»
+}
+
+/* Yet unimplemented
+void «StNameEv()»::exit()
+{
+}
+*/
+
+void «StNameEv()»::_setActualEventData(Event ev)
+{
+	setEventData(ev);
+}
+
+void «StNameEv()»::_removeActualEventData()
+{
+	clearEventData();
+}
+
+void «StNameEv()»::_runCycle(Event ev)
+{
+	for (int i=0; i<MAX_PARALLEL_STATES; ++i) {
+		switch(state[i]) {
+	«FOREACH this.states AS state»
+	    case _«state.simpleName»:
+	        cycle_«state.simpleName»(*ev);
+	        break;
+	«ENDFOREACH»
+		default:
+			/* no state found */
+			break;
+		}
+	}
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 7 - 5
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/CustomStatemachineH.xpt

@@ -15,18 +15,18 @@ Templates for the main statechart cpp file.
 
 «DEFINE file FOR ExecutionFlow»
 
-«FILE StName()+'.h'»
+«FILE StName()+'_ev.h'»
 #ifndef «STNAME()»_H_
 #define «STNAME()»_H_
 
-#include "Statemachine.h"
+#include "Statemachine_ev.h"
 #include "«DRName()».h"
 #include "«EvName()».h"
 
 
 #define MAX_PARALLEL_STATES «this.stateVector.size»
 
-class «StName()»: public Statemachine, public «DRName()» {
+class «StNameEv()»: public Statemachine_ev, public «DRName()» {
 
 public:
 	enum States {
@@ -73,11 +73,13 @@ protected:
 	«ENDFOREACH»
 	
 	virtual void _runCycle(Event ev);
+	virtual void _setActualEventData(Event ev);
+	virtual void _removeActualEventData();
 
 public:
 
-	«StName()»();
-	virtual ~«StName()»();
+	«StNameEv()»(Timer* timer);
+	virtual ~«StNameEv()»();
 
 	virtual void init();
 

+ 38 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DataRepositoryBoost.xpt

@@ -0,0 +1,38 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'DataRepositoryBoost.cpp'»
+#ifndef DATAREPOSITORYBOOST_H_
+#define DATAREPOSITORYBOOST_H_
+
+#include "DataRepository.h"
+#include <boost/thread/mutex.hpp>
+
+class DataRepositoryBoost : public DataRepository {
+protected:
+	boost::recursive_mutex mutex;
+
+	virtual void lock(){ mutex.lock(); }
+	virtual void unlock(){ mutex.unlock(); }
+
+public:
+	DataRepositoryBoost(){};
+	virtual ~DataRepositoryBoost(){};
+};
+
+#endif /* DATAREPOSITORYBOOST_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 59 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DataRepositoryCPP.xpt

@@ -0,0 +1,59 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'DataRepository.cpp'»
+#include "DataRepository.h"
+#include "StatemachineException.h"
+
+#include <iostream>
+
+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::setEventData(const Event & data)
+{
+	std::cout << "Set Event Data (ID "<<data->getID()<<")\n";
+
+	if (data->getID() < maxDataListItems) {
+		eventDataList[data->getID()] =
+				data;
+	}
+	else
+		throw StatechartException("DataRepository::setEvent: event ID out of range!");
+}
+
+DataRepository::DataRepository(const uint32_t maxEvents)
+: maxDataListItems(maxEvents)
+{
+	eventDataList = new Event[maxDataListItems];
+	clearEventData();
+}
+
+DataRepository::~DataRepository() {
+	clearEventData();
+	delete[] eventDataList;
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 9 - 19
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DataRepositoryH.xpt

@@ -17,36 +17,26 @@ Templates for the main statechart cpp file.
 #ifndef DATAREPOSITORY_H_
 #define DATAREPOSITORY_H_
 
-#ifndef WITH_BOOST
+#include "definition.h"
+#include "Event.h"
 
 class DataRepository {
 protected:
 	virtual void lock(){}
 	virtual void unlock(){}
 
-public:
-	DataRepository(){};
-	virtual ~DataRepository(){};
-};
+	Event* eventDataList;
+	uint32_t maxDataListItems;
 
-#else
-
-#include <boost/thread/mutex.hpp>
-
-class  DataRepository {
-protected:
-	boost::mutex mutex;
-
-	virtual void lock(){ mutex.lock(); }
-	virtual void unlock(){ mutex.unlock(); }
+	void clearEventData();
+	void setEventData(const Event& data);
 
 public:
-	DataRepositoryBoost(){};
-	virtual ~DataRepositoryBoost(){};
+	DataRepository();
+	DataRepository(const uint32_t maxEvents);
+	virtual ~DataRepository();
 };
 
-#endif
-
 #endif /* DATAREPOSITORY_H_ */
 «ENDFILE»
 

+ 33 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DummyTimerCPP.xpt

@@ -0,0 +1,33 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'DummyTimer.cpp'»
+#include "DummyTimer.h"
+
+DummyTimer::DummyTimer() 
+{}
+
+DummyTimer::~DummyTimer() 
+{}
+
+void DummyTimer::setTimer(const uint32_t evid, const uint32_t time_ms, bool periodic)
+{}
+
+void DummyTimer::unsetTimer(const uint32_t evid)
+{}
+
+«ENDFILE»
+
+«ENDDEFINE»

+ 35 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/DummyTimerH.xpt

@@ -0,0 +1,35 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'DummyTimer.h'»
+#ifndef DUMMYTIMER_H_
+#define DUMMYTIMER_H_
+
+#include "Timer.h"
+
+class DummyTimer: public Timer {
+public:
+	DummyTimer();
+	virtual ~DummyTimer();
+
+	virtual void setTimer(const uint32_t evid, const uint32_t time_ms, bool periodic = false);
+	virtual void unsetTimer(const uint32_t evid);
+
+};
+
+#endif /* DUMMYTIMER_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

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

@@ -25,7 +25,7 @@ protected:
 	uint32_t ID;
 
 public:
-	_Event() : ID(-1) {}
+	_Event() : ID(0xffffffff) {}
 	_Event(int _ID) : ID(_ID) {}
 	virtual ~_Event() {}
 

+ 34 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/EventReceiverH.xpt

@@ -0,0 +1,34 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther axel terfloth
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'EventReceiver.h'»
+#ifndef EVENTRECEIVER_H_
+#define EVENTRECEIVER_H_
+
+#include "Event.h"
+
+class EventReceiver {
+
+public:
+	EventReceiver(){}
+	virtual ~EventReceiver(){}
+
+	virtual void queueEvent(Event ev) = 0; // setEvent()
+};
+
+#endif /* EVENTRECEIVER_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 71 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/EventSetCPP.xpt

@@ -0,0 +1,71 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'EventSet.cpp'»
+#include "EventSet.h"
+#include "StatemachineException.h"
+
+EventSet::EventSet() : _set(0), maxEvents(0) {
+}
+
+EventSet::EventSet(const uint32_t & _maxEvents)
+: maxEvents(_maxEvents)
+{
+	_set = new bool[maxEvents];
+	clean();
+}
+
+EventSet::~EventSet() {
+	delete[] _set;
+}
+
+bool EventSet::check(const uint32_t evid) const
+{
+	if (evid < maxEvents) {
+		return _set[evid];
+	}
+	throw StatechartException("EventSet::check: Event ID out of range");
+}
+
+
+
+void EventSet::clean()
+{
+	for (uint32_t i(0);i<maxEvents;++i)
+		_set[i] = false;
+}
+
+
+
+void EventSet::set(const uint32_t evid)
+{
+	if (evid < maxEvents) {
+		_set[evid] = true;
+	} else {
+		throw StatechartException("EventSet::set‚: Event ID out of range");
+	}
+}
+
+bool EventSet::isAny() const
+{
+	for (uint32_t i(0);i<maxEvents;++i)
+		if (_set[i])
+			return(true);
+	return(false);
+
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 41 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/EventSetH.xpt

@@ -0,0 +1,41 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'EventSet.h'»
+#ifndef EVENTSET_H_
+#define EVENTSET_H_
+
+#include "definition.h"
+
+class EventSet {
+protected:
+	bool* _set;
+	uint32_t maxEvents;
+
+public:
+	EventSet();
+	EventSet(const uint32_t& maxEvents);
+	virtual ~EventSet();
+
+	bool check(const uint32_t evid) const;
+	void clean();
+	void set(const uint32_t evid);
+	bool isAny() const;
+};
+
+#endif /* EVENTSET_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 12 - 2
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Expression.ext

@@ -46,7 +46,7 @@ String toCppCode(LogicalNotExpression expression) :
   	" ^" + expression.operand.toCppCode();
 
 String toCppCode(LogicalRelationExpression expression) :
-   expression.leftOperand.toCppCode() + " ??? " + expression.rightOperand.toCppCode();
+   expression.leftOperand.toCppCode() + getOperator(expression.operator) + expression.rightOperand.toCppCode();
     
 String toCppCode(BitwiseAndExpression expression) :
   	expression.leftOperand.toCppCode() + " & " + expression.rightOperand.toCppCode();
@@ -65,7 +65,7 @@ String toCppCode(NumericalMultiplyDivideExpression expression) :
 
 // is this just relevant for events?
 String toCppCode(ElementReferenceExpression ev) :
-    " ( _" + ev.value.name.toLowerCase() + " == ev.getID() ) ";
+    " eventSet.check( ev_" + ev.value.name.toLowerCase() + ") ";
 
 String getOperator(AdditiveOperator operator) : 
     switch(operator) {
@@ -82,3 +82,13 @@ String getOperator(MultiplicativeOperator operator) :
     	default : ""
     };
 
+String getOperator(RelationalOperator operator) :
+	switch (operator) {
+	  case (RelationalOperator::greater) : " > "
+	  case (RelationalOperator::greaterEqual) : " >= "
+	  case (RelationalOperator::smaller) : " < "
+	  case (RelationalOperator::smallerEqual) : " <= "
+	  case (RelationalOperator::equals) : " == "
+	  case (RelationalOperator::notEquals) : " != "
+	  default : ""
+	};

+ 35 - 9
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Main.xpt

@@ -17,25 +17,51 @@ Contais the root templates that call the different file templates.
 «DEFINE main FOR ExecutionFlow»
 
 	«REM» basis files «ENDREM»
-	«EXPAND EventH::file FOR this»
-	«EXPAND DataRepositoryH::file FOR this»
-	«EXPAND StatemachineH::file FOR this»
 	«EXPAND StatemachineExceptionH::file FOR this»
 	«EXPAND definitionH::file FOR this»
+
+	«EXPAND EventH::file FOR this»
+	«EXPAND TimerH::file FOR this»
+	
+
+	«EXPAND EventSetH::file FOR this»
+	«EXPAND EventSetCPP::file FOR this»
+
+	«EXPAND EventReceiverH::file FOR this»
+
+	«EXPAND StatemachineBaseH::file FOR this»
+	«EXPAND StatemachineBaseCPP::file FOR this»
+	
+	«EXPAND Statemachine_cyH::file FOR this»
+	«EXPAND Statemachine_cyCPP::file FOR this»
 	
-	«EXPAND StatemachineCPP::file FOR this»
+	«EXPAND Statemachine_evH::file FOR this»
+	«EXPAND Statemachine_evCPP::file FOR this»
+
+	«EXPAND DataRepositoryH::file FOR this»
+	«EXPAND DataRepositoryCPP::file FOR this»
+	«EXPAND DataRepositoryBoost::file FOR this»
+	
+	«EXPAND DummyTimerH::file FOR this»
+	«EXPAND DummyTimerCPP::file FOR this»
+	
+	«REM» custom code «ENDREM»	
+
+	«EXPAND CustomStatemachine_cyH::file FOR this»
+	«EXPAND CustomStatemachine_cyCPP::file FOR this»
+
+	«EXPAND CustomStatemachine_evH::file FOR this»
+	«EXPAND CustomStatemachine_evCPP::file FOR this»
+
 
-	«EXPAND CustomStatemachineH::file FOR this»
-	«EXPAND CustomStatemachineCPP::file FOR this»
 	«EXPAND CustomRepositoryH::file FOR this»
 	«EXPAND CustomEventH::file FOR this»
 	
 	«EXPAND CMakeLists::file FOR this»
-	«EXPAND TestMain::file FOR this»
+	«EXPAND TestMain_cy::file FOR this»
+	«EXPAND TestMain_ev::file FOR this»
 
 
-	«EXPAND Dump::file FOR this»
-	
 «ENDDEFINE»
 
 

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

@@ -13,6 +13,8 @@ List declaredVariables(ExecutionFlow flow) : flow.scopes.declarations.typeSelect
 String test(NamedElement obj) :  "";
 String StName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "Statemachine";
 String STNAME(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toUpperCase() + "STATEMACHINE";
+String StNameEv(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "Statemachine_ev";
+String StNameCy(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "Statemachine_cy";
 
 String DRName(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toFirstUpper() + "DataRepository";
 String DRNAME(Object this) : ((ExecutionFlow)((EObject)this).eRootContainer).name.toUpperCase() + "DATAREPOSITORY";

+ 0 - 21
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatechartCPP.xpt

@@ -1,21 +0,0 @@
-«REM»
-
-Templates for the main statechart cpp file.
-
-@auther axel terfloth
-
-«ENDREM»
-
-«IMPORT sexec»
-«IMPORT stext»
-«IMPORT sgraph»
-
-
-«DEFINE file FOR ExecutionFlow»
-
-«FILE 'statechart.cpp'»
-// generated by YAKINDU C++ statechart generator
-
-«ENDFILE»
-
-«ENDDEFINE»

+ 0 - 76
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatechartH.xpt

@@ -1,76 +0,0 @@
-«REM»
-
-Templates for the main statechart cpp file.
-
-@auther axel terfloth
-
-«ENDREM»
-
-«IMPORT sexec»
-«IMPORT stext»
-«IMPORT sgraph»
-
-
-«DEFINE file FOR ExecutionFlow»
-
-«FILE 'MyStatemachine.h'»
-#ifndef MYSTATEMACHINE_H_
-#define MYSTATEMACHINE_H_
-
-#include "Statemachine.h"
-#include "MyDataRepository.h"
-#include "MyEvents.h"
-
-//namespace MyStatemachineNS {
-
-#define MAX_PARALLEL_STATES 1
-
-class MyStatemachine: public Statemachine, public MyDataRepository {
-
-public:
-	enum States {
-		State1,
-		State2,
-		State3,
-		State4,
-		last_state
-	};
-
-protected:
-	/* conditions */
-	bool condition_state1_id1(const _Event& event, const MyDataRepository& data);
-	bool condition_state3_id1(const _Event& event, const MyDataRepository& data);
-	bool condition_state3_id2(const _Event& event, const MyDataRepository& data);
-	bool condition_state4_id1(const _Event& event, const MyDataRepository& data);
-	bool condition_state4_id2(const _Event& event, const MyDataRepository& data);
-	bool condition_state4_id3(const _Event& event, const MyDataRepository& data);
-
-	/* statement */
-	void statement_state1_id1();
-	void statement_state3_id1();
-	void statement_state3_id2();
-	void statement_state4_id1();
-	void statement_state4_id2();
-	void statement_state4_id3();
-
-	/* cycles */
-	void cycle_state1(const _Event& ev);
-	void cycle_state3(const _Event& ev);
-	void cycle_state4(const _Event& ev);
-
-public:
-
-	MyStatemachine();
-	virtual ~MyStatemachine();
-
-	virtual void init();
-	virtual void runCycle();
-
-};
-
-//}; // namespace
-#endif /* MYSTATEMACHINE_H_ */
-
-«ENDFILE»
-
-«ENDDEFINE»

+ 40 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatemachineBaseCPP.xpt

@@ -0,0 +1,40 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'StatemachineBase.cpp'»
+#include "StatemachineBase.h"
+
+StatemachineBase::StatemachineBase(uint16_t maxStates, Timer* _timer) : timer(_timer)
+{
+	state = new uint32_t[maxStates]; /* memory allocation for all states */
+	statePtr = 0; /* actual state referencer */
+}
+StatemachineBase::~StatemachineBase() {
+	delete[] state;
+	delete timer;
+}
+
+void StatemachineBase::setEventReceiver(EventReceiver& receiver)
+{
+	outgoingEvents = &receiver;
+}
+
+uint32_t StatemachineBase::getState(uint16_t pos)
+{
+    return (state[pos]);
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 49 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatemachineBaseH.xpt

@@ -0,0 +1,49 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'StatemachineBase.h'»
+#ifndef STATEMACHINEBASE_H_
+#define STATEMACHINEBASE_H_
+
+#include "definition.h"
+#include "EventReceiver.h"
+#include "Timer.h"
+
+class StatemachineBase : public EventReceiver {
+protected:
+	uint32_t* state;
+	uint16_t statePtr;
+
+	Timer* timer;
+	EventReceiver *outgoingEvents;
+
+public:
+
+	StatemachineBase(uint16_t maxStates, Timer* timer);
+	virtual ~StatemachineBase();
+
+	virtual void init() = 0;
+	virtual void runCycle() = 0;
+	virtual bool eventWaiting() const = 0;
+
+	virtual void setEventReceiver(EventReceiver& receiver);
+
+	uint32_t getState(uint16_t pos);
+
+};
+#endif /* STATEMACHINEBASE_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 0 - 51
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatemachineH.xpt

@@ -1,51 +0,0 @@
-«REM»
-
-Templates for the main statechart cpp file.
-
-@auther joern seger
-
-«ENDREM»
-
-«IMPORT sexec»
-«IMPORT stext»
-«IMPORT sgraph»
-
-
-«DEFINE file FOR ExecutionFlow»
-
-«FILE 'Statemachine.h'»
-#ifndef STATEMACHINE_H_
-#define STATEMACHINE_H_
-
-#include <deque>
-#include "Event.h"
-
-class Statemachine {
-
-protected:
-	uint32_t* state;
-	uint16_t statePtr;
-
-	std::deque<Event> eventList;
-
-	Event getEvent();
-
-	virtual void _runCycle(Event ev) = 0;
-
-public:
-	Statemachine(uint16_t maxStates);
-	virtual ~Statemachine();
-
-	virtual void init() = 0;
-	void runCycle();
-	void queueEvent(Event ev);
-	bool eventWaiting() const;
-
-	uint32_t getState(uint16_t pos) { return(state[pos]); }
-
-};
-
-#endif /* STATEMACHINE_H_ */
-«ENDFILE»
-
-«ENDDEFINE»

+ 48 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Statemachine_cyCPP.xpt

@@ -0,0 +1,48 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther axel terfloth
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Statemachine_cy.cpp'»
+#include "Statemachine_cy.h"
+#include "StatemachineException.h"
+
+Statemachine_cy::Statemachine_cy(uint16_t maxStates, uint16_t maxEvents, Timer* _timer)
+  : StatemachineBase(maxStates, _timer), eventSet(maxEvents) {
+}
+
+Statemachine_cy::~Statemachine_cy() {
+}
+
+void Statemachine_cy::queueEvent(Event ev) {
+	eventSet.set(ev->getID());
+}
+
+bool Statemachine_cy::check(const Event& ev) const
+{
+	return eventSet.check(ev->getID());
+}
+
+bool Statemachine_cy::eventWaiting() const {
+	return eventSet.isAny();
+}
+
+void Statemachine_cy::runCycle() {
+
+	_runCycle();
+	eventSet.clean();
+
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 46 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Statemachine_cyH.xpt

@@ -0,0 +1,46 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther axel terfloth
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Statemachine_cy.h'»
+#ifndef STATEMACHINE_CY_H_
+#define STATEMACHINE_CY_H_
+
+#include <deque>
+#include "EventSet.h"
+#include "StatemachineBase.h"
+
+class Statemachine_cy : public StatemachineBase {
+
+protected:
+	EventSet eventSet;
+
+	virtual bool check(const Event& ev) const;
+	virtual void _runCycle() {}
+
+public:
+	Statemachine_cy(uint16_t maxStates, uint16_t maxEvents, Timer* timer);
+	virtual ~Statemachine_cy();
+
+	virtual void init() {}
+	void runCycle();
+	virtual void queueEvent(Event ev);
+	bool eventWaiting() const;
+
+};
+
+#endif /* STATEMACHINE_CY_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 10 - 11
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/StatemachineCPP.xpt

@@ -13,25 +13,22 @@ Templates for the main statechart cpp file.
 
 «DEFINE file FOR ExecutionFlow»
 
-«FILE 'Statemachine.cpp'»
-#include "Statemachine.h"
+«FILE 'Statemachine_ev.cpp'»
+#include "Statemachine_ev.h"
 #include "StatemachineException.h"
 
-Statemachine::Statemachine(uint16_t maxStates) {
-	state = new uint32_t[maxStates]; /* memory allocation for all states */
-	statePtr = 0; /* actual state referencer */
+Statemachine_ev::Statemachine_ev(uint16_t maxStates, uint16_t maxEvents, Timer* _timer) : StatemachineBase(maxStates, _timer){
 }
 
-Statemachine::~Statemachine() {
-	delete[] state;
+Statemachine_ev::~Statemachine_ev() {
 }
 
-void Statemachine::queueEvent(Event ev) {
+void Statemachine_ev::queueEvent(Event ev) {
 	/* creates a copy */
 	eventList.push_back(ev);
 }
 
-Event Statemachine::getEvent() {
+Event Statemachine_ev::getEvent() {
 	if (eventList.empty())
 		throw(StatechartException("There is no event available"));
 	Event retEvent = eventList.front();
@@ -39,16 +36,18 @@ Event Statemachine::getEvent() {
 	return (retEvent);
 }
 
-bool Statemachine::eventWaiting() const {
+bool Statemachine_ev::eventWaiting() const {
 	return (!eventList.empty());
 }
 
-void Statemachine::runCycle() {
+void Statemachine_ev::runCycle() {
 	if (!eventWaiting())
 		return;
 
 	Event ev = getEvent();
+	_setActualEventData(ev);
 	_runCycle(ev);
+	_removeActualEventData();
 
 	delete ev;
 }

+ 54 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/Statemachine_evH.xpt

@@ -0,0 +1,54 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Statemachine_ev.h'»
+#ifndef STATEMACHINE_EV_H_
+#define STATEMACHINE_EV_H_
+
+#include <deque>
+#include "Event.h"
+#include "Timer.h"
+#include "EventSet.h"
+#include "StatemachineBase.h"
+
+class Statemachine_ev : public StatemachineBase {
+
+protected:
+
+	std::deque<Event> eventList;
+
+	Event getEvent();
+
+	virtual void _runCycle(Event ev) = 0;
+	virtual void _setActualEventData(Event ev) = 0;
+	virtual void _removeActualEventData() = 0;
+
+public:
+	Statemachine_ev(uint16_t maxStates, uint16_t maxEvents, Timer* timer);
+	virtual ~Statemachine_ev();
+
+	virtual void init() {}
+	virtual void runCycle();
+	virtual void queueEvent(Event ev);
+	virtual bool eventWaiting() const;
+
+	uint32_t getState(uint16_t pos) { return(state[pos]); }
+
+};
+
+#endif /* STATEMACHINE_EV_H_ */
+«ENDFILE»
+
+«ENDDEFINE»

+ 112 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/TestMain_cy.xpt

@@ -0,0 +1,112 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+«EXTENSION org::yakindu::sct::generator::cpp::templates::Expression»
+«EXTENSION org::yakindu::sct::generator::cpp::templates::Naming»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'main_cy.cpp'»
+#include <cstdio>
+#include <iostream>
+#include <cstring>
+#include <assert.h>
+#include "«StNameCy()».h"
+#include "«EvName()».h"
+#include "Timer.h"
+#include "DummyTimer.h"
+
+int main()
+{
+	Timer* timer;
+	
+	const char* stateName[6] = {"State1", "State2", "State3", "State4", "State5", "State6"};
+	«StNameCy()» machine(timer = new DummyTimer);
+
+	/* initialize the initial states */
+	machine.init();
+
+	/* create one event and enqueue it */
+	Event e = createEvent<Event1>();
+	machine.queueEvent(e);
+
+	/* run the cycle */
+	machine.runCycle();
+
+	/* check the state */
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State3") == 0);
+
+	e = createEvent<Event2>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State1") == 0);
+
+	/* does event queuing work? */
+	e = createEvent<Event1>();
+	machine.queueEvent(e);
+	e = createEvent<Event3>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State3") == 0);
+
+	assert( machine.eventWaiting() == false );
+
+	e = createEvent<Event3>();
+	machine.queueEvent(e);
+
+	assert( machine.eventWaiting() == true );
+
+	/* run second cycle */
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State4") == 0);
+
+	e = createEvent<Event4>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State3") == 0);
+
+	e = createEvent<Event3>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State4") == 0);
+
+	e = createEvent<Event5>();
+	machine.queueEvent(e);
+
+	machine.runCycle();
+
+	std::cout << stateName[machine.getState(0)] << "\n";
+	assert( strcmp(stateName[machine.getState(0)], "State1") == 0);
+
+    delete timer;
+
+	return(0);
+}
+«ENDFILE»
+
+«ENDDEFINE»

+ 6 - 12
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/TestMain.xpt

@@ -16,26 +16,19 @@ Templates for the main statechart cpp file.
 
 «DEFINE file FOR ExecutionFlow»
 
-«FILE 'main.cpp'»
-
-/*
- * main.cpp
- *
- *  Created on: 10.09.2011
- *      Author: seger
- */
-
+«FILE 'main_ev.cpp'»
 #include <cstdio>
 #include <iostream>
-#include "«StName()».h"
-// #include "«DRName()».h"
+#include "«StNameEv()».h"
 #include "«EvName()».h"
+#include "DummyTimer.h"
 
 int main()
 {
+	Timer* timer;
 
 	char* stateName[6] = {"State1", "State2", "State3", "State4", "State5", "State6"};
-	«StName()» machine;
+	«StNameEv()» machine(timer = new DummyTimer);
 
 	// initialize the initial states 
 	machine.init();
@@ -103,6 +96,7 @@ int main()
 
 	*/
 	
+	delete timer;
 	return(0);
 	
 }

+ 36 - 0
plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/templates/TimerH.xpt

@@ -0,0 +1,36 @@
+«REM»
+
+Templates for the main statechart cpp file.
+
+@auther joern seger
+
+«ENDREM»
+
+«IMPORT sexec»
+«IMPORT stext»
+«IMPORT sgraph»
+
+
+«DEFINE file FOR ExecutionFlow»
+
+«FILE 'Timer.h'»
+#ifndef TIMER_H_
+#define TIMER_H_
+
+#include "definition.h"
+//#include "Event.h"
+
+class Timer {
+public:
+	Timer() {}
+	virtual ~Timer() {}
+
+	virtual void setTimer(const uint32_t evid, const uint32_t time_ms, bool periodic = false) = 0;
+	virtual void unsetTimer(const uint32_t evid) = 0;
+
+};
+
+#endif /* TIMER_H_ */
+«ENDFILE»
+
+«ENDDEFINE»