Pārlūkot izejas kodu

implemented issue #129 --> Guard the statemachine state in the generated Code #129

Dominik Jetzen 10 gadi atpakaļ
vecāks
revīzija
5c78cc6b02

+ 10 - 0
plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/Statemachine.xtend

@@ -103,7 +103,10 @@ class Statemachine {
 			
 			protected «scope.interfaceImplName» «scope.interfaceName.asEscapedIdentifier»;
 			
+			
 		«ENDFOR»
+		private boolean initialized=false;
+
 		public enum State {
 			«FOR state : flow.states»
 				«state.stateName.asEscapedIdentifier»,
@@ -174,6 +177,7 @@ class Statemachine {
 	
 	def protected initFunction(ExecutionFlow flow) '''
 		public void init() {
+			this.initialized=true;
 			«IF flow.timed»
 			if (timer == null) {
 				throw new IllegalStateException("timer not set.");
@@ -574,6 +578,8 @@ class Statemachine {
 	
 	def protected runCycleFunction(ExecutionFlow flow) '''
 		public void runCycle() {
+			if(!initialized)
+				throw new IllegalStateException("The statemachine needs to be initialized first by calling the init() function.");
 			
 			clearOutEvents();
 			
@@ -598,6 +604,9 @@ class Statemachine {
 	
 	def protected enterFunction(ExecutionFlow it) '''
 		public void enter() {
+			if(!initialized)
+				throw new IllegalStateException("The statemachine needs to be initialized first by calling the init() function.");
+			
 			«IF timed»
 			if (timer == null) {
 				throw new IllegalStateException("timer not set.");
@@ -609,6 +618,7 @@ class Statemachine {
 	
 	def protected exitFunction(ExecutionFlow it) '''
 		public void exit(){
+			initialized=false;
 			«exitSequence.code»
 		}
 	'''