import java.net.ServerSocket;

/**
 * The class ClipsSimulatorServer is a wrapper for the Clips-based
 * simulator
 *
 * @see TestSimulatorServer
 * @see LocalSimulator
 * @version 1.0
 * @author Henrik Eriksson
 */


class ClipsSimulatorServer extends SimulatorServer {


        /** The Clips object */
        protected static Clips c;
	private ServerSocket serversocket;

        /** Create the server and start listening for incoming requests */
        ClipsSimulatorServer () {
	    try {
	    serversocket.accept();
	    } catch (Exception e) { 
		System.out.println("Connection accepted");  } 
//          clientSocket.listen(1);
        }


        /** Start the server. Callsthe Clips function
            ClipsSimulatorServer_start(), which process the start
            service request */
        public synchronized native void start();


        /** Perform one time step. Calls the Clips function
            ClipsSimulatorServer_timeStep(), which computes the next
            plant state. */
        public synchronized native void timeStep();


        /** Blow a plant component. Calls the Clips function
            ClipsSimulatorServer_blow(device), which processes the
            blow request.
            @param device The device to blow (e.g., "turbine") */
        synchronized public void blow(String device) {
          c.CLIPSFunctionCall("ClipsSimulatorServer_blow", device);
        }


        /** The main method for the server. It is called automatically
            when the server is invoked */
        public static void main (String args[]) {
          c = new Clips();
          c.Load("ClipsSimulator.clp");
//          c.Reset();
          c.CLIPSFunctionCall("start", "");
          c.CommandLoop();
        }

}
