// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/cloud/api/Color.java
// public enum Color {
// 	GREEN, YELLOW, RED
// };
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/controller/api/SegmentController.java
// public interface SegmentController {
// 
// 	/**
// 	 * Service property for identifying this controller
// 	 */
// 	String CONTROLLER_ID = "controller.id";
// 
// 	/**
// 	 * Service property for identifying this controller, by segment name
// 	 */
// 	String CONTROLLER_SEGMENT = "controller.segment";
// 
// 	/**
// 	 * Get the host location of the segment controller.
// 	 */
// 	default String getLocation() {
// 		return "unknown";
// 	}
// 
// }
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/controller/api/SignalSegmentController.java
// public interface SignalSegmentController extends SegmentController {
// 
// 	/**
// 	 * Set the signal to the given color
// 	 * @param color
// 	 */
// 	void signal(Color color);
// 
// 	Color getSignal();
// }
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/controller/api/SwitchSegmentController.java
// public interface SwitchSegmentController extends SegmentController {
// 
// 	/**
// 	 * Set the switch to normal or the alternative
// 	 * @param alternative
// 	 */
// 	void swtch(boolean alternative);
// 	
// 	boolean getSwitch();
// }
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/train/api/TrainController.java
// public interface TrainController {
//     /**
//      * Service property identifying RC channel for this controller
//      */
//     String CONTROLLER_CHANNEL = "train.channel";
// 
// 	/**
// 	 * Control the motor. Positive is forward, negative is reverse, 0 is stop.
// 	 * 
// 	 * @param directionAndSpeed
// 	 */
// 	void move(int directionAndSpeed);
// 
// 	/**
// 	 * Control the light on the train
// 	 * @param on
// 	 */
// 	void light(boolean on);
// 	
// }


import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import osgi.enroute.debug.api.Debug;
import osgi.enroute.trains.cloud.api.Color;
import osgi.enroute.trains.controller.api.SegmentController;
import osgi.enroute.trains.controller.api.SignalSegmentController;
import osgi.enroute.trains.controller.api.SwitchSegmentController;
import osgi.enroute.trains.train.api.TrainController;
	}

	void removeSignal(SignalSegmentController s) {
		signals.values().remove(s);
	}

	final Map<Integer, SwitchSegmentController> switches = new ConcurrentHashMap<>();
	
	@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
	void addSwitch(SwitchSegmentController t, ServiceReference<?> ref) {
		switches.put((Integer) ref.getProperty(SegmentController.CONTROLLER_ID), t);
	}

	void removeSwitch(SwitchSegmentController s) {
		switches.values().remove(s);
	}

	public void move(String ch, int directionAndSpeed) {
		trains.get(ch).move(directionAndSpeed);
	}

	public void light(String ch, boolean on) {
		trains.get(ch).light(on);
	}

	public String signal(int controller, String color) {
		SignalSegmentController c = signals.get(controller);
		if (c == null)
			return "No such controller";
		else
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/cloud/api/Color.java
// public enum Color {
// 	GREEN, YELLOW, RED
// };
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/controller/api/SegmentController.java
// public interface SegmentController {
// 
// 	/**
// 	 * Service property for identifying this controller
// 	 */
// 	String CONTROLLER_ID = "controller.id";
// 
// 	/**
// 	 * Service property for identifying this controller, by segment name
// 	 */
// 	String CONTROLLER_SEGMENT = "controller.segment";
// 
// 	/**
// 	 * Get the host location of the segment controller.
// 	 */
// 	default String getLocation() {
// 		return "unknown";
// 	}
// 
// }
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/controller/api/SignalSegmentController.java
// public interface SignalSegmentController extends SegmentController {
// 
// 	/**
// 	 * Set the signal to the given color
// 	 * @param color
// 	 */
// 	void signal(Color color);
// 
// 	Color getSignal();
// }
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/controller/api/SwitchSegmentController.java
// public interface SwitchSegmentController extends SegmentController {
// 
// 	/**
// 	 * Set the switch to normal or the alternative
// 	 * @param alternative
// 	 */
// 	void swtch(boolean alternative);
// 	
// 	boolean getSwitch();
// }
// 
// Path: osgi.enroute.trains.api/src/osgi/enroute/trains/train/api/TrainController.java
// public interface TrainController {
//     /**
//      * Service property identifying RC channel for this controller
//      */
//     String CONTROLLER_CHANNEL = "train.channel";
// 
// 	/**
// 	 * Control the motor. Positive is forward, negative is reverse, 0 is stop.
// 	 * 
// 	 * @param directionAndSpeed
// 	 */
// 	void move(int directionAndSpeed);
// 
// 	/**
// 	 * Control the light on the train
// 	 * @param on
// 	 */
// 	void light(boolean on);
// 	
// }


// Path: osgi.enroute.trains.hw.provider/src/osgi/enroute/trains/hw/provider/Command.java
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.osgi.framework.ServiceReference;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import osgi.enroute.debug.api.Debug;
import osgi.enroute.trains.cloud.api.Color;
import osgi.enroute.trains.controller.api.SegmentController;
import osgi.enroute.trains.controller.api.SignalSegmentController;
import osgi.enroute.trains.controller.api.SwitchSegmentController;
import osgi.enroute.trains.train.api.TrainController;

	}

	void removeSignal(SignalSegmentController s) {
		signals.values().remove(s);
	}

	final Map<Integer, SwitchSegmentController> switches = new ConcurrentHashMap<>();
	
	@Reference(cardinality = ReferenceCardinality.MULTIPLE, policy = ReferencePolicy.DYNAMIC)
	void addSwitch(SwitchSegmentController t, ServiceReference<?> ref) {
		switches.put((Integer) ref.getProperty(SegmentController.CONTROLLER_ID), t);
	}

	void removeSwitch(SwitchSegmentController s) {
		switches.values().remove(s);
	}

	public void move(String ch, int directionAndSpeed) {
		trains.get(ch).move(directionAndSpeed);
	}

	public void light(String ch, boolean on) {
		trains.get(ch).light(on);
	}

	public String signal(int controller, String color) {
		SignalSegmentController c = signals.get(controller);
		if (c == null)
			return "No such controller";
		else
			c.signal(Color.valueOf(color.toUpperCase()));