1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.remotecontrol;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.preferences.BooleanProperty;
|
---|
5 | import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Manager class for remote control operations.
|
---|
9 | *
|
---|
10 | * To allow API there is a @see getVersion() method.
|
---|
11 | *
|
---|
12 | * IMPORTANT! increment the minor version on compatible API extensions
|
---|
13 | * and increment the major version and set minor to 0 on incompatible changes.
|
---|
14 | */
|
---|
15 | public class RemoteControl
|
---|
16 | {
|
---|
17 | // deactivate the remote control code for now. FIXME: Remove this completely if it gets turned on.
|
---|
18 | static final public boolean on = false;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * If the remote cotrol feature is enabled or disabled. If disabled,
|
---|
22 | * it should not start the server.
|
---|
23 | */
|
---|
24 | public static final BooleanProperty PROP_REMOTECONTROL_ENABLED = new BooleanProperty("remotecontrol.enabled", false);
|
---|
25 |
|
---|
26 | /** API version
|
---|
27 | * IMPORTANT! update the version number on API changes.
|
---|
28 | */
|
---|
29 | static final int apiMajorVersion = 1;
|
---|
30 | static final int apiMinorVersion = 0;
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * RemoteControl HTTP protocol version. Change minor number for compatible
|
---|
34 | * interface extensions. Change major number in case of incompatible
|
---|
35 | * changes.
|
---|
36 | */
|
---|
37 | static final int protocolMajorVersion = 1;
|
---|
38 | static final int protocolMinorVersion = 2;
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Returns an array of int values with major and minor API version
|
---|
42 | * and major and minor HTTP protocol version.
|
---|
43 | *
|
---|
44 | * The function returns an int[4] instead of an object with fields
|
---|
45 | * to avoid ClassNotFound errors with old versions of remotecontrol.
|
---|
46 | *
|
---|
47 | * @return array of integer version numbers:
|
---|
48 | * apiMajorVersion, apiMinorVersion, protocolMajorVersion, protocolMajorVersion
|
---|
49 | */
|
---|
50 | public int[] getVersion()
|
---|
51 | {
|
---|
52 | int versions[] = {apiMajorVersion, apiMinorVersion, protocolMajorVersion, protocolMajorVersion};
|
---|
53 | return versions;
|
---|
54 | }
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * Start the remote control server
|
---|
58 | */
|
---|
59 | public static void start() {
|
---|
60 | RemoteControlHttpServer.restartRemoteControlHttpServer();
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Add external external request handler.
|
---|
65 | * Can be used by plugins that want to use remote control.
|
---|
66 | *
|
---|
67 | * @param handler The additional request handler.
|
---|
68 | */
|
---|
69 | public void addRequestHandler(String command, Class<? extends RequestHandler> handlerClass)
|
---|
70 | {
|
---|
71 | RequestProcessor.addRequestHandlerClass(command, handlerClass);
|
---|
72 | }
|
---|
73 | }
|
---|