Bladeren bron

moved and refactored traffic light implementation from
trafficlight_example to traffic_light (issue #569)

Axel Terfloth 9 jaren geleden
bovenliggende
commit
5ede8056d4
28 gewijzigde bestanden met toevoegingen van 694 en 2728 verwijderingen
  1. 2 1
      examples/traffic_light/.classpath
  2. 1 1
      examples/traffic_light/.settings/org.eclipse.core.resources.prefs
  3. 12 0
      examples/traffic_light/.settings/org.eclipse.jdt.core.prefs
  4. 17 0
      examples/traffic_light/README.TXT
  5. 549 549
      examples/traffic_light/model/TrafficLightWaiting.sct
  6. 2 1
      examples/traffic_light/model/GenModelJava.sgen
  7. 4 5
      examples/traffic_light/src-gen/traffic/light/IStatemachine.java
  8. 2 3
      examples/traffic_light/src-gen/traffic/light/ITimer.java
  9. 2 3
      examples/traffic_light/src-gen/traffic/light/ITimerCallback.java
  10. 13 14
      examples/traffic_light/src-gen/traffic/light/RuntimeService.java
  11. 16 7
      examples/traffic_light/src-gen/traffic/light/TimerService.java
  12. 10 5
      examples/traffic_light/src-gen/traffic/light/trafficlightwaiting/ITrafficLightWaitingStatemachine.java
  13. 40 7
      examples/traffic_light/src-gen/traffic/light/trafficlightwaiting/TrafficLightWaitingStatemachine.java
  14. 1 1
      examples/trafficlight_example/src/trafficlight_example/ButtonPanel.java
  15. 6 4
      examples/trafficlight_example/src/trafficlight_example/CrossingPanel.java
  16. 1 1
      examples/trafficlight_example/src/trafficlight_example/PedestrianLight.java
  17. 1 1
      examples/trafficlight_example/src/trafficlight_example/TrafficLight.java
  18. 15 11
      examples/trafficlight_example/src/trafficlight_example/TrafficlightDemo.java
  19. 0 549
      examples/trafficlight_example/model/TrafficLightWaiting.sct
  20. 0 19
      examples/trafficlight_example/model/default2.sgen
  21. 0 7
      examples/trafficlight_example/readme.txt
  22. 0 207
      examples/trafficlight_example/src-gen/org/yakindu/scr/RuntimeService.java
  23. 0 91
      examples/trafficlight_example/src-gen/org/yakindu/scr/TimerService.java
  24. 0 38
      examples/trafficlight_example/src-gen/org/yakindu/scr/trafficlightwaiting/ITrafficLightWaitingStatemachine.java
  25. 0 1111
      examples/trafficlight_example/src-gen/org/yakindu/scr/trafficlightwaiting/TrafficLightWaitingStatemachine.java
  26. 0 39
      examples/trafficlight_example/src/org/yakindu/scr/IStatemachine.java
  27. 0 38
      examples/trafficlight_example/src/org/yakindu/scr/ITimer.java
  28. 0 15
      examples/trafficlight_example/src/org/yakindu/scr/ITimerCallback.java

+ 2 - 1
examples/traffic_light/.classpath

@@ -1,7 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
 	<classpathentry kind="src" path="src-gen"/>
-	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/>
+	<classpathentry kind="src" path="src"/>
+	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>

+ 1 - 1
examples/traffic_light/.settings/org.eclipse.core.resources.prefs

@@ -1,3 +1,3 @@
 eclipse.preferences.version=1
-encoding//model/TrafficLightWaiting.sct=UTF-8
+encoding//model/TrafficLightCtrl.sct=UTF-8
 encoding/<project>=UTF-8

+ 12 - 0
examples/traffic_light/.settings/org.eclipse.jdt.core.prefs

@@ -0,0 +1,12 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.8

+ 17 - 0
examples/traffic_light/README.TXT

@@ -0,0 +1,17 @@
+The traffic light example project is based on Java and contains a small GUI 
+that demonstrate the state machine behaviour in /model/TrafficLightWaiting.sct. 
+This example combines generated java code with manual Java implementations (the GUI). 
+To start the application run src/trafficlight_example/TrafficlightDemo.java. 
+In Eclipse select the project in the project explorer and right-click to open the 
+context menu. Select 'Run As > Java Application'. The application will start and 
+everything else should be self explaining
+
+ATTENTION:
+
+1! The example REQUIRES a JAVA 8 JDK. 
+
+2! When you installed the example then Eclipse may show errors on the project. This 
+is likely due to a missing configuration of the JDK. In this case select 'Properties'
+from the context menu on the project and set the correct JDK in 'Java Build Path'. You 
+will find further help in the 'Java development user guide' section of the Eclipse help.
+

File diff suppressed because it is too large
+ 549 - 549
examples/traffic_light/model/TrafficLightWaiting.sct


+ 2 - 1
examples/traffic_light/model/GenModelJava.sgen

@@ -1,6 +1,6 @@
 GeneratorModel for yakindu::java {
 
-	statechart TrafficLightWaiting {
+	statechart TrafficLightCtrl {
 	 	
 		feature Outlet {
 			targetProject = "traffic_light"
@@ -9,6 +9,7 @@ GeneratorModel for yakindu::java {
 
 		feature Naming {
 			basePackage = "traffic.light"
+			implementationSuffix =""
 		}
 
 		feature GeneralFeatures {

+ 4 - 5
examples/traffic_light/src-gen/traffic/light/IStatemachine.java

@@ -1,5 +1,4 @@
-/**
-Copyright (c) 2012-2015 committers of YAKINDU and others.
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
 All rights reserved. This program and the accompanying materials
 are made available under the terms of the Eclipse Public License v1.0
 which accompanies this distribution, and is available at
@@ -7,7 +6,7 @@ http://www.eclipse.org/legal/epl-v10.html
 
 Contributors:
     committers of YAKINDU - initial API and implementation
-�*/
+� */
 package traffic.light;
 
 /**
@@ -16,7 +15,7 @@ package traffic.light;
 public interface IStatemachine {
 
 	/**
-	 * Initializes the state machine. Used to init internal variables etc.
+	 * Initializes the state machine. Used to initialize internal variables etc.
 	 */
 	public void init();
 
@@ -38,7 +37,7 @@ public interface IStatemachine {
 
 	/**
 	 * Checks whether all active states are final. 
-	 * If there are no active states then the state machine is considered to be incative and this method returns <code>false</code>.
+	 * If there are no active states then the state machine is considered being incative. In this case this method returns <code>false</code>.
 	 */
 	public boolean isFinal();
 

+ 2 - 3
examples/traffic_light/src-gen/traffic/light/ITimer.java

@@ -1,5 +1,4 @@
-/**
-Copyright (c) 2012-2015 committers of YAKINDU and others.
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
 All rights reserved. This program and the accompanying materials
 are made available under the terms of the Eclipse Public License v1.0
 which accompanies this distribution, and is available at
@@ -7,7 +6,7 @@ http://www.eclipse.org/legal/epl-v10.html
 
 Contributors:
     committers of YAKINDU - initial API and implementation
-�*/
+� */
 package traffic.light;
 
 /**

+ 2 - 3
examples/traffic_light/src-gen/traffic/light/ITimerCallback.java

@@ -1,5 +1,4 @@
-/**
-Copyright (c) 2012-2015 committers of YAKINDU and others.
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
 All rights reserved. This program and the accompanying materials
 are made available under the terms of the Eclipse Public License v1.0
 which accompanies this distribution, and is available at
@@ -7,7 +6,7 @@ http://www.eclipse.org/legal/epl-v10.html
 
 Contributors:
     committers of YAKINDU - initial API and implementation
-�*/
+� */
 package traffic.light;
 
 /**

+ 13 - 14
examples/traffic_light/src-gen/traffic/light/RuntimeService.java

@@ -1,5 +1,4 @@
-/**
-Copyright (c) 2012-2015 committers of YAKINDU and others.
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
 All rights reserved. This program and the accompanying materials
 are made available under the terms of the Eclipse Public License v1.0
 which accompanies this distribution, and is available at
@@ -7,7 +6,7 @@ http://www.eclipse.org/legal/epl-v10.html
 
 Contributors:
     committers of YAKINDU - initial API and implementation
-�*/
+� */
 package traffic.light;
 
 import java.util.HashMap;
@@ -52,7 +51,7 @@ public class RuntimeService {
 
 		/**
 		 * Adds the given state machine to the TimerTask.
-		 * 
+		 *
 		 * @param statemachine
 		 * @return {@code true} if state machine is added properly.
 		 */
@@ -65,7 +64,7 @@ public class RuntimeService {
 
 		/**
 		 * Removes the given state machine from the TimerTask.
-		 * 
+		 *
 		 * @param statemachine
 		 * @return {@code true} if state machine is removed properly.
 		 */
@@ -91,7 +90,7 @@ public class RuntimeService {
 
 	/**
 	 * Returns the {@code RuntimeService} instance as singleton.
-	 * 
+	 *
 	 * @return The singleton {@code RuntimeService} instance
 	 */
 	public static RuntimeService getInstance() {
@@ -103,7 +102,7 @@ public class RuntimeService {
 
 	/**
 	 * Registers an {@link IStatemachine} for scheduled fixed rate execution
-	 * 
+	 *
 	 * @param statemachine
 	 *            - The state machine to execute
 	 * @param cyclePeriod
@@ -133,9 +132,9 @@ public class RuntimeService {
 
 	/**
 	 * Removes the given state machine from runtime service.
-	 * 
+	 *
 	 * @param statemachine
-	 *            - the state machine which should be removed
+	 *            - the state machine to be removed
 	 * @param cyclePeriod
 	 *            - the scheduling cycle period of the state machine
 	 * @return {@code true} if state machine is removed properly.
@@ -155,7 +154,7 @@ public class RuntimeService {
 	 * Cancels the execution of state machines for the given cycle period. This
 	 * stops the execution of state machines which are registered for the given
 	 * cycle period and cancels the executing {@link TimerTask}.
-	 * 
+	 *
 	 * @return {@code true} if poperly cancelled
 	 */
 	public boolean cancelAll(long cyclePeriod) {
@@ -172,10 +171,10 @@ public class RuntimeService {
 	/**
 	 * Pauses the execution of all state machines which are registered for the
 	 * given cyclePeriod.
-	 * 
+	 *
 	 * @param cyclePeriod
 	 * @return {@code true} if properly paused
-	 * 
+	 *
 	 */
 	public boolean pauseAll(long cyclePeriod) {
 		if (timerTasks.containsKey(cyclePeriod)) {
@@ -188,10 +187,10 @@ public class RuntimeService {
 	/**
 	 * Resumes the execution of all state machines which are registered for the
 	 * given cyclePeriod.
-	 * 
+	 *
 	 * @param cyclePeriod
 	 * @return {@code true} if properly resumed
-	 * 
+	 *
 	 */
 	public boolean resumeAll(long cyclePeriod) {
 		if (timerTasks.containsKey(cyclePeriod)) {

+ 16 - 7
examples/traffic_light/src-gen/traffic/light/TimerService.java

@@ -1,5 +1,4 @@
-/**
-Copyright (c) 2012-2015 committers of YAKINDU and others.
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
 All rights reserved. This program and the accompanying materials
 are made available under the terms of the Eclipse Public License v1.0
 which accompanies this distribution, and is available at
@@ -7,17 +6,19 @@ http://www.eclipse.org/legal/epl-v10.html
 
 Contributors:
     committers of YAKINDU - initial API and implementation
-�*/
+� */
 package traffic.light;
 
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Timer;
 import java.util.TimerTask;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
 
 /**
  * Default timer service implementation.
- * 
+ *
  */
 public class TimerService implements ITimer {
 
@@ -25,10 +26,12 @@ public class TimerService implements ITimer {
 	
 	private final List<TimeEventTask> timerTaskList = new ArrayList<TimeEventTask>();
 	
+	private final Lock lock = new ReentrantLock();
+	
 	/**
 	 * Timer task that reflects a time event. It's internally used by
 	 * {@link TimerService}.
-	 * 
+	 *
 	 */
 	private class TimeEventTask extends TimerTask {
 	
@@ -38,11 +41,11 @@ public class TimerService implements ITimer {
 	
 		/**
 		 * Constructor for a time event.
-		 * 
+		 *
 		 * @param callback
 		 *            : Set to {@code true} if event should be repeated
 		 *            periodically.
-		 * 
+		 *
 		 * @param eventID
 		 *            : Index position within the state machine's timeEvent
 		 *            array.
@@ -70,6 +73,7 @@ public class TimerService implements ITimer {
 	
 		// Create a new TimerTask for given event and store it.
 		TimeEventTask timerTask = new TimeEventTask(callback, eventID);
+		lock.lock();
 		timerTaskList.add(timerTask);
 	
 		// start scheduling the timer
@@ -78,15 +82,18 @@ public class TimerService implements ITimer {
 		} else {
 			timer.schedule(timerTask, time);
 		}
+		lock.unlock();
 	}
 	
 	public void unsetTimer(ITimerCallback callback, int eventID) {
+		lock.lock();
 		int index = timerTaskList.indexOf(new TimeEventTask(callback, eventID));
 		if (index != -1) {
 			timerTaskList.get(index).cancel();
 			timer.purge();
 			timerTaskList.remove(index);
 		}
+		lock.unlock();
 	}
 	
 	/**
@@ -94,8 +101,10 @@ public class TimerService implements ITimer {
 	 * memory resources.
 	 */
 	public void cancel() {
+		lock.lock();
 		timer.cancel();
 		timer.purge();
+		lock.unlock();
 	}
 }
 

+ 10 - 5
examples/traffic_light/src-gen/traffic/light/trafficlightwaiting/ITrafficLightWaitingStatemachine.java

@@ -1,5 +1,4 @@
-/**
-Copyright (c) 2012-2015 committers of YAKINDU and others.
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
 All rights reserved. This program and the accompanying materials
 are made available under the terms of the Eclipse Public License v1.0
 which accompanies this distribution, and is available at
@@ -7,12 +6,13 @@ http://www.eclipse.org/legal/epl-v10.html
 
 Contributors:
     committers of YAKINDU - initial API and implementation
-�*/
-package traffic.light.trafficlightwaiting;
+� */
+package traffic.light.trafficlightctrl;
 import traffic.light.IStatemachine;
 import traffic.light.ITimerCallback;
 
-public interface ITrafficLightWaitingStatemachine extends ITimerCallback, IStatemachine {
+public interface ITrafficLightCtrlStatemachine extends ITimerCallback, IStatemachine {
+
 	public interface SCITrafficLight {
 		public boolean getRed();
 		public void setRed(boolean value);
@@ -41,6 +41,11 @@ public interface ITrafficLightWaitingStatemachine extends ITimerCallback, IState
 		public void raisePedestrianRequest();
 		public void raiseOnOff();
 
+		public void setSCInterfaceOperationCallback(SCInterfaceOperationCallback operationCallback);
+	}
+
+	public interface SCInterfaceOperationCallback {
+		public void synchronize();
 	}
 
 	public SCInterface getSCInterface();

+ 40 - 7
examples/traffic_light/src-gen/traffic/light/trafficlightwaiting/TrafficLightWaitingStatemachine.java

@@ -1,5 +1,4 @@
-/**
-Copyright (c) 2012-2015 committers of YAKINDU and others.
+/** Copyright (c) 2012-2015 committers of YAKINDU and others.
 All rights reserved. This program and the accompanying materials
 are made available under the terms of the Eclipse Public License v1.0
 which accompanies this distribution, and is available at
@@ -7,11 +6,11 @@ http://www.eclipse.org/legal/epl-v10.html
 
 Contributors:
     committers of YAKINDU - initial API and implementation
-�*/
-package traffic.light.trafficlightwaiting;
+� */
+package traffic.light.trafficlightctrl;
 import traffic.light.ITimer;
 
-public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStatemachine {
+public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachine {
 
 	protected class SCITrafficLightImpl implements SCITrafficLight {
 
@@ -87,6 +86,12 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	protected class SCInterfaceImpl implements SCInterface {
 
+		private SCInterfaceOperationCallback operationCallback;
+
+		public void setSCInterfaceOperationCallback(SCInterfaceOperationCallback operationCallback) {
+			this.operationCallback = operationCallback;
+		}
+
 		private boolean pedestrianRequest;
 
 		public void raisePedestrianRequest() {
@@ -122,7 +127,7 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	private final boolean[] timeEvents = new boolean[10];
 
-	public TrafficLightWaitingStatemachine() {
+	public TrafficLightCtrlStatemachine() {
 
 		sCITrafficLight = new SCITrafficLightImpl();
 		sCIPedestrian = new SCIPedestrianImpl();
@@ -180,7 +185,7 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 	/** 
 	* Always returns 'false' since this state machine can never become final.
 	*
-	 * @see IStatemachine#isFinal() 
+	 * @see IStatemachine#isFinal()
 	 */
 	public boolean isFinal() {
 		return false;
@@ -283,6 +288,10 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 		sCInterface.raiseOnOff();
 	}
 
+	private boolean check__lr0() {
+		return true;
+	}
+
 	private boolean check_main_region_on_tr0_tr0() {
 		return sCInterface.onOff;
 	}
@@ -335,6 +344,10 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 		return timeEvents[9];
 	}
 
+	private void effect__lr0() {
+		sCInterface.operationCallback.synchronize();
+	}
+
 	private void effect_main_region_on_tr0() {
 		exitSequence_main_region_on();
 
@@ -935,6 +948,8 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	/* The reactions of state StreetGreen. */
 	private void react_main_region_on_r1_StreetGreen() {
+		effect__lr0();
+
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
 		} else {
@@ -946,6 +961,8 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	/* The reactions of state waitOn. */
 	private void react_main_region_on_r1_PedWaiting_r1_waitOn() {
+		effect__lr0();
+
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
 		} else {
@@ -961,6 +978,8 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	/* The reactions of state waitOff. */
 	private void react_main_region_on_r1_PedWaiting_r1_waitOff() {
+		effect__lr0();
+
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
 		} else {
@@ -976,6 +995,8 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	/* The reactions of state StreetAttention. */
 	private void react_main_region_on_r1_StreetAttention() {
+		effect__lr0();
+
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
 		} else {
@@ -987,6 +1008,8 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	/* The reactions of state StreetRed. */
 	private void react_main_region_on_r1_StreetRed() {
+		effect__lr0();
+
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
 		} else {
@@ -998,6 +1021,8 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	/* The reactions of state PedestrianGreen. */
 	private void react_main_region_on_r1_PedestrianGreen() {
+		effect__lr0();
+
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
 		} else {
@@ -1009,6 +1034,8 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	/* The reactions of state PedestrianRed. */
 	private void react_main_region_on_r1_PedestrianRed() {
+		effect__lr0();
+
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
 		} else {
@@ -1020,6 +1047,8 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	/* The reactions of state StreetPrepare. */
 	private void react_main_region_on_r1_StreetPrepare() {
+		effect__lr0();
+
 		if (check_main_region_on_tr0_tr0()) {
 			effect_main_region_on_tr0();
 		} else {
@@ -1031,6 +1060,8 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	/* The reactions of state YellowOn. */
 	private void react_main_region_off_r1_YellowOn() {
+		effect__lr0();
+
 		if (check_main_region_off_tr0_tr0()) {
 			effect_main_region_off_tr0();
 		} else {
@@ -1042,6 +1073,8 @@ public class TrafficLightWaitingStatemachine implements ITrafficLightWaitingStat
 
 	/* The reactions of state YellowOff. */
 	private void react_main_region_off_r1_YellowOff() {
+		effect__lr0();
+
 		if (check_main_region_off_tr0_tr0()) {
 			effect_main_region_off_tr0();
 		} else {

+ 1 - 1
examples/trafficlight_example/src/trafficlight_example/ButtonPanel.java

@@ -8,7 +8,7 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package trafficlight_example;
+package traffic.light;
 
 import java.awt.BorderLayout;
 

+ 6 - 4
examples/trafficlight_example/src/trafficlight_example/CrossingPanel.java

@@ -8,7 +8,7 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package trafficlight_example;
+package traffic.light;
 
 import java.awt.Color;
 import java.awt.Graphics;
@@ -16,7 +16,9 @@ import java.awt.Point;
 
 import javax.swing.JPanel;
 
-import trafficlight_example.TrafficLight.Alignment;
+import traffic.light.PedestrianLight;
+import traffic.light.TrafficLight;
+import traffic.light.TrafficLight.Alignment;
 
 /**
  * 
@@ -39,8 +41,8 @@ public class CrossingPanel extends JPanel {
 		light2 = new TrafficLight(Alignment.VERTICAL);
 		light3 = new TrafficLight(Alignment.HORIZONTAL);
 		light4 = new TrafficLight(Alignment.VERTICAL);
-		light5 = new PedestrianLight(trafficlight_example.PedestrianLight.Alignment.HORIZONTAL);
-		light6 = new PedestrianLight(trafficlight_example.PedestrianLight.Alignment.VERTICAL);
+		light5 = new PedestrianLight(PedestrianLight.Alignment.HORIZONTAL);
+		light6 = new PedestrianLight(PedestrianLight.Alignment.VERTICAL);
 	}
 
 	public void paint(Graphics g) {

+ 1 - 1
examples/trafficlight_example/src/trafficlight_example/PedestrianLight.java

@@ -8,7 +8,7 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package trafficlight_example;
+package traffic.light;
 
 import java.awt.Color;
 import java.awt.Graphics;

+ 1 - 1
examples/trafficlight_example/src/trafficlight_example/TrafficLight.java

@@ -8,7 +8,7 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package trafficlight_example;
+package traffic.light;
 
 import java.awt.Color;
 import java.awt.Graphics;

+ 15 - 11
examples/trafficlight_example/src/trafficlight_example/TrafficlightDemo.java

@@ -8,16 +8,15 @@
  * 	committers of YAKINDU - initial API and implementation
  * 
  */
-package trafficlight_example;
+package traffic.light;
 
 import java.awt.BorderLayout;
 import java.awt.Graphics;
 
 import javax.swing.JFrame;
 
-import org.yakindu.scr.RuntimeService;
-import org.yakindu.scr.TimerService;
-import org.yakindu.scr.trafficlightwaiting.TrafficLightWaitingStatemachine;
+import traffic.light.trafficlightctrl.ITrafficLightCtrlStatemachine;
+import traffic.light.trafficlightctrl.TrafficLightCtrlStatemachine;
 
 /**
  * 
@@ -29,7 +28,7 @@ public class TrafficlightDemo extends JFrame {
 
 	private static final long serialVersionUID = -8909693541678814631L;
 
-	protected TrafficLightWaitingStatemachine statemachine;
+	protected TrafficLightCtrlStatemachine statemachine;
 
 	protected TimerService timer;
 
@@ -47,15 +46,11 @@ public class TrafficlightDemo extends JFrame {
 	protected void run() {
 		statemachine.enter();
 		RuntimeService.getInstance().registerStatemachine(statemachine, 100);
-		while (isVisible()) {
-			checkTrafficLightStates();
-			repaint();
-		}
 	}
 
 	protected void createContents() {
 		setLayout(new BorderLayout());
-		setTitle("CycleBasedDemo");
+		setTitle("Traffic Light Crossing");
 		crossing = new CrossingPanel();
 		add(BorderLayout.CENTER, crossing);
 		buttonPanel = new ButtonPanel();
@@ -70,9 +65,17 @@ public class TrafficlightDemo extends JFrame {
 	}
 
 	protected void setupStatemachine() {
-		statemachine = new TrafficLightWaitingStatemachine();
+		statemachine = new TrafficLightCtrlStatemachine();
 		timer = new TimerService();
 		statemachine.setTimer(timer);
+		statemachine.getSCInterface().setSCInterfaceOperationCallback(new ITrafficLightCtrlStatemachine.SCInterfaceOperationCallback() {
+			@Override
+			public void synchronize() {
+				checkTrafficLightStates();
+				repaint();
+			}
+		});
+		
 		statemachine.init();
 
 		buttonPanel.getPedestrianRequest()
@@ -80,6 +83,7 @@ public class TrafficlightDemo extends JFrame {
 		buttonPanel.getOnOff().addActionListener(e -> statemachine.getSCInterface().raiseOnOff());
 	}
 
+	
 	protected void checkTrafficLightStates() {
 		crossing.getLight1().setRed(statemachine.getSCITrafficLight().getRed());
 		crossing.getLight1().setYellow(statemachine.getSCITrafficLight().getYellow());

File diff suppressed because it is too large
+ 0 - 549
examples/trafficlight_example/model/TrafficLightWaiting.sct


+ 0 - 19
examples/trafficlight_example/model/default2.sgen

@@ -1,19 +0,0 @@
-GeneratorModel for yakindu::java {
-
-	statechart TrafficLightWaiting {
-
-		feature Outlet {
-			targetProject = "trafficlight_example"
-			targetFolder = "src-gen"
-			libraryTargetFolder = "src"
-		}
-		
-		feature GeneralFeatures {
-			InterfaceObserverSupport = false
-			RuntimeService = true
-			TimerService = true
-			UseJavaIntForInteger = false
-		}
-		
-	}
-}

+ 0 - 7
examples/trafficlight_example/readme.txt

@@ -1,7 +0,0 @@
-The Trafficlight example contains a simple Swing based Java GUI to
-demonstrate the state machine behaviour in /model/TrafficLightWaiting.sct
-
-To start the application run src/trafficlight_example/TrafficlightDemo.java
-
-The example requires Java 8.
-

+ 0 - 207
examples/trafficlight_example/src-gen/org/yakindu/scr/RuntimeService.java

@@ -1,207 +0,0 @@
-package org.yakindu.scr;
-
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Timer;
-import java.util.TimerTask;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
-
-/**
- * Runtime service for state machines to execute a run to completion step
- * periodically.
- * 
- */
-public class RuntimeService {
-
-	private static RuntimeService runtimeService;
-
-	private Timer timer = null;
-
-	private Map<Long, StatemachineTimerTask> timerTasks = new HashMap<Long, StatemachineTimerTask>();
-
-	private class StatemachineTimerTask extends TimerTask {
-
-		private List<IStatemachine> statemachineList = new LinkedList<IStatemachine>();
-
-		private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
-
-		private boolean isPaused = false;
-
-		@Override
-		public void run() {
-			lock.readLock().lock();
-			if (!isPaused) {
-				for (IStatemachine statemachine : statemachineList) {
-					statemachine.runCycle();
-				}
-			}
-			lock.readLock().unlock();
-		}
-
-		/**
-		 * Adds the given state machine to the TimerTask.
-		 * 
-		 * @param statemachine
-		 * @return {@code true} if state machine is added properly.
-		 */
-		public boolean addStatemachine(IStatemachine statemachine) {
-			lock.writeLock().lock();
-			boolean ret = statemachineList.add(statemachine);
-			lock.writeLock().unlock();
-			return ret;
-		}
-
-		/**
-		 * Removes the given state machine from the TimerTask.
-		 * 
-		 * @param statemachine
-		 * @return {@code true} if state machine is removed properly.
-		 */
-		public boolean removeStatemachine(IStatemachine statemachine) {
-			lock.writeLock().lock();
-			boolean ret = statemachineList.remove(statemachine);
-			lock.writeLock().unlock();
-			return ret;
-		}
-
-		public void pause() {
-			isPaused = true;
-		}
-
-		public void resume() {
-			isPaused = false;
-		}
-	}
-
-	private RuntimeService() {
-		// Not intended to be instantiated.
-	}
-
-	/**
-	 * Returns the {@code RuntimeService} instance as singleton.
-	 * 
-	 * @return The singleton {@code RuntimeService} instance
-	 */
-	public static RuntimeService getInstance() {
-		if (runtimeService == null) {
-			runtimeService = new RuntimeService();
-		}
-		return runtimeService;
-	}
-
-	/**
-	 * Registers an {@link IStatemachine} for scheduled fixed rate execution
-	 * 
-	 * @param statemachine
-	 *            - The statemachine to execute
-	 * @param cyclePeriod
-	 *            - the fixed rate cycle period for scheduling
-	 * @return {@code true} if state machine is added properly.
-	 */
-	public boolean registerStatemachine(IStatemachine statemachine,
-			long cyclePeriod) {
-
-		if (timerTasks.containsKey(cyclePeriod)) {
-			// TimerTask for cycle time already existing -> add statemachine
-			return timerTasks.get(cyclePeriod).addStatemachine(statemachine);
-		} else {
-			// Create new TimerTask for cycle period and add statemachine
-			StatemachineTimerTask timerTask = new StatemachineTimerTask();
-			timerTasks.put(cyclePeriod, timerTask);
-			boolean ret = timerTask.addStatemachine(statemachine);
-			// Create a new Timer instance if runtime service was cancelled
-			// before
-			if (timer == null) {
-				timer = new Timer();
-			}
-			timer.scheduleAtFixedRate(timerTask, 0, cyclePeriod);
-			return ret;
-		}
-	}
-
-	/**
-	 * Removes the given state machine from runtime service.
-	 * 
-	 * @param statemachine
-	 *            - the statemachine which should be removed
-	 * @param cyclePeriod
-	 *            - the scheduling cycle period of the statemachine
-	 * @return {@code true} if state machine is removed properly.
-	 */
-	public boolean unregisterStatemachine(IStatemachine statemachine,
-			long cyclePeriod) {
-		if (timerTasks.containsKey(cyclePeriod)) {
-			boolean ret = timerTasks.get(cyclePeriod).removeStatemachine(
-					statemachine);
-
-			return ret;
-		}
-		return false;
-	}
-
-	/**
-	 * Cancels the execution of statemachines for the given cycle period. This
-	 * stops the execution of statemachines which are registered for the given
-	 * cycle period and cancels the executing {@link TimerTask}.
-	 * 
-	 * @return {@code true} if poperly cancelled
-	 */
-	public boolean cancelAll(long cyclePeriod) {
-		if (timer != null && timerTasks.containsKey(cyclePeriod)) {
-			TimerTask task = timerTasks.get(cyclePeriod);
-			task.cancel();
-			timer.purge();
-			timerTasks.remove(cyclePeriod);
-			return true;
-		}
-		return false;
-	}
-
-	/**
-	 * Pauses the execution of all statemachines which are registered for the
-	 * given cyclePeriod.
-	 * 
-	 * @param cyclePeriod
-	 * @return {@code true} if properly paused
-	 * 
-	 */
-	public boolean pauseAll(long cyclePeriod) {
-		if (timerTasks.containsKey(cyclePeriod)) {
-			timerTasks.get(cyclePeriod).pause();
-			return true;
-		}
-		return false;
-	}
-
-	/**
-	 * Resumes the execution of all statemachines which are registered for the
-	 * given cyclePeriod.
-	 * 
-	 * @param cyclePeriod
-	 * @return {@code true} if properly resumed
-	 * 
-	 */
-	public boolean resumeAll(long cyclePeriod) {
-		if (timerTasks.containsKey(cyclePeriod)) {
-			timerTasks.get(cyclePeriod).resume();
-			return true;
-		}
-		return false;
-	}
-
-	/**
-	 * Cancels the execution of all registered statemachines. This cancels the
-	 * executing {@link Timer} freeing all allocated resources and terminates
-	 * all existing execution threads.
-	 */
-	public void cancelTimer() {
-		if (timer != null) {
-			timer.cancel();
-			timer.purge();
-			timerTasks.clear();
-			timer = null;
-		}
-	}
-}

+ 0 - 91
examples/trafficlight_example/src-gen/org/yakindu/scr/TimerService.java

@@ -1,91 +0,0 @@
-package org.yakindu.scr;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Timer;
-import java.util.TimerTask;
-
-/**
- * Default timer service implementation.
- * 
- */
-public class TimerService implements ITimer {
-
-	private final Timer timer = new Timer();
-	
-	private final List<TimeEventTask> timerTaskList = new ArrayList<TimeEventTask>();
-	
-	/**
-	 * Timer task that reflects a time event. It's internally used by
-	 * {@link TimerService}.
-	 * 
-	 */
-	private class TimeEventTask extends TimerTask {
-	
-		private ITimerCallback callback;
-	
-		int eventID;
-	
-		/**
-		 * Constructor for a time event.
-		 * 
-		 * @param callback
-		 *            : Set to {@code true} if event should be repeated
-		 *            periodically.
-		 * 
-		 * @param eventID
-		 *            : Index position within the state machine's timeEvent
-		 *            array.
-		 */
-		public TimeEventTask(ITimerCallback callback, int eventID) {
-			this.callback = callback;
-			this.eventID = eventID;
-		}
-	
-		public void run() {
-			callback.timeElapsed(eventID);
-		}
-	
-		public boolean equals(Object obj) {
-			if (obj instanceof TimeEventTask) {
-				return ((TimeEventTask) obj).callback.equals(callback)
-						&& ((TimeEventTask) obj).eventID == eventID;
-			}
-			return super.equals(obj);
-		}
-	}
-	
-	public void setTimer(final ITimerCallback callback, final int eventID,
-			long time, boolean isPeriodic) {
-	
-		// Create a new TimerTask for given event and store it.
-		TimeEventTask timerTask = new TimeEventTask(callback, eventID);
-		timerTaskList.add(timerTask);
-	
-		// start scheduling the timer
-		if (isPeriodic) {
-			timer.scheduleAtFixedRate(timerTask, time, time);
-		} else {
-			timer.schedule(timerTask, time);
-		}
-	}
-	
-	public void unsetTimer(ITimerCallback callback, int eventID) {
-		int index = timerTaskList.indexOf(new TimeEventTask(callback, eventID));
-		if (index != -1) {
-			timerTaskList.get(index).cancel();
-			timer.purge();
-			timerTaskList.remove(index);
-		}
-	}
-	
-	/**
-	 * Cancel timer service. Use this to end possible timing threads and free
-	 * memory resources.
-	 */
-	public void cancel() {
-		timer.cancel();
-		timer.purge();
-	}
-}
-

+ 0 - 38
examples/trafficlight_example/src-gen/org/yakindu/scr/trafficlightwaiting/ITrafficLightWaitingStatemachine.java

@@ -1,38 +0,0 @@
-package org.yakindu.scr.trafficlightwaiting;
-import org.yakindu.scr.IStatemachine;
-import org.yakindu.scr.ITimerCallback;
-
-public interface ITrafficLightWaitingStatemachine extends ITimerCallback, IStatemachine {
-	public interface SCITrafficLight {
-		public boolean getRed();
-		public void setRed(boolean value);
-		public boolean getYellow();
-		public void setYellow(boolean value);
-		public boolean getGreen();
-		public void setGreen(boolean value);
-
-	}
-
-	public SCITrafficLight getSCITrafficLight();
-
-	public interface SCIPedestrian {
-		public boolean getRequest();
-		public void setRequest(boolean value);
-		public boolean getRed();
-		public void setRed(boolean value);
-		public boolean getGreen();
-		public void setGreen(boolean value);
-
-	}
-
-	public SCIPedestrian getSCIPedestrian();
-
-	public interface SCInterface {
-		public void raisePedestrianRequest();
-		public void raiseOnOff();
-
-	}
-
-	public SCInterface getSCInterface();
-
-}

File diff suppressed because it is too large
+ 0 - 1111
examples/trafficlight_example/src-gen/org/yakindu/scr/trafficlightwaiting/TrafficLightWaitingStatemachine.java


+ 0 - 39
examples/trafficlight_example/src/org/yakindu/scr/IStatemachine.java

@@ -1,39 +0,0 @@
-package org.yakindu.scr;
-
-/**
- * Basic interface for statemachines.
- */
-public interface IStatemachine {
-
-	/**
-	 * Initializes the statemachine. Use to init internal variables etc.
-	 */
-	public void init();
-
-	/**
-	 * Enters the statemachine. Sets the statemachine in a defined state.
-	 */
-	public void enter();
-
-	/**
-	 * Exits the statemachine. Leaves the statemachine with a defined state.
-	 */
-	public void exit();
-
-	/**
-	 * Checks if the statemachine is active. 
-	 * A statemachine is active if it was entered. It is inactive if it has not been entered at all or if it was exited.
-	 */
-	public boolean isActive();
-
-	/**
-	 * Checks if all active states are final. 
-	 * If there are no active states then the statemachine is considered as incative and this method returns false.
-	 */
-	public boolean isFinal();
-
-	/**
-	* Start a run-to-completion cycle.
-	*/
-	public void runCycle();
-}

+ 0 - 38
examples/trafficlight_example/src/org/yakindu/scr/ITimer.java

@@ -1,38 +0,0 @@
-package org.yakindu.scr;
-
-/**
- * Interface a timer has to implement. Use to implement your own timer
- * service.
- * 
- */
-public interface ITimer {
-
-	/**
-	 * Starts the timing for a given time event id.
-	 * 
-	 * @param callback
-	 * 			  : The target callback where the time event has to be raised.
-	 * 
-	 * @param eventID
-	 *            : The eventID the timer should use if timed out.
-	 *            
-	 * @param time
-	 *            : Time in milliseconds after the given time event should be
-	 *            triggered
-	 *            
-	 * @param isPeriodic
-	 * 			  : Set to true if the time event should be triggered periodically
-	 */
-	public void setTimer(ITimerCallback callback, int eventID, long time, boolean isPeriodic);
-
-	/**
-	 * Unset a time event.
-	 * 
-	 * @param callback
-	 * 			: The target callback for which the time event has to be unset.
-	 * 
-	 * @param eventID
-	 * 			: The time event id.
-	 */
-	public void unsetTimer(ITimerCallback callback, int eventID);
-}

+ 0 - 15
examples/trafficlight_example/src/org/yakindu/scr/ITimerCallback.java

@@ -1,15 +0,0 @@
-package org.yakindu.scr;
-
-/**
-* Interface for state machines which use timed event triggers.
-*/
-public interface ITimerCallback {
-	
-	/**
-	* Callback method if a time event occurred.
-	* 
-	* @param eventID
-	* 			:The id of the occurred event.
-	*/
-	public void timeElapsed(int eventID);
-}