001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.io.remotecontrol;
003
004import org.openstreetmap.josm.data.preferences.BooleanProperty;
005import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler;
006
007/**
008 * Manager class for remote control operations.
009 *
010 * IMPORTANT! increment the minor version on compatible API extensions
011 * and increment the major version and set minor to 0 on incompatible changes.
012 */
013public class RemoteControl
014{
015    /**
016     * If the remote control feature is enabled or disabled. If disabled,
017     * it should not start the server.
018     */
019    public static final BooleanProperty PROP_REMOTECONTROL_ENABLED = new BooleanProperty("remotecontrol.enabled", false);
020
021    /**
022     * RemoteControl HTTP protocol version. Change minor number for compatible
023     * interface extensions. Change major number in case of incompatible
024     * changes.
025     */
026    static final int protocolMajorVersion = 1;
027    static final int protocolMinorVersion = 5;
028
029    /**
030     * Starts the remote control server
031     */
032    public static void start() {
033        RemoteControlHttpServer.restartRemoteControlHttpServer();
034    }
035
036    /**
037     * Stops the remote control server
038     * @since 5861
039     */
040    public static void stop() {
041        RemoteControlHttpServer.stopRemoteControlHttpServer();
042    }
043
044    /**
045     * Adds external request handler.
046     * Can be used by plugins that want to use remote control.
047     *
048     * @param command The command name.
049     * @param handlerClass The additional request handler.
050     */
051    public void addRequestHandler(String command, Class<? extends RequestHandler> handlerClass) {
052        RequestProcessor.addRequestHandlerClass(command, handlerClass);
053    }
054}