1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.remotecontrol;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.Main;
|
---|
5 | import org.openstreetmap.josm.data.preferences.BooleanProperty;
|
---|
6 | import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler;
|
---|
7 |
|
---|
8 | /**
|
---|
9 | * Manager class for remote control operations.
|
---|
10 | *
|
---|
11 | * IMPORTANT! increment the minor version on compatible API extensions
|
---|
12 | * and increment the major version and set minor to 0 on incompatible changes.
|
---|
13 | */
|
---|
14 | public class RemoteControl {
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * If the remote control feature is enabled or disabled. If disabled,
|
---|
18 | * it should not start the server.
|
---|
19 | */
|
---|
20 | public static final BooleanProperty PROP_REMOTECONTROL_ENABLED = new BooleanProperty("remotecontrol.enabled", false);
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * If the remote control feature is enabled or disabled for HTTPS. If disabled,
|
---|
24 | * only HTTP access will be available.
|
---|
25 | * @since 7335
|
---|
26 | */
|
---|
27 | public static final BooleanProperty PROP_REMOTECONTROL_HTTPS_ENABLED = new BooleanProperty("remotecontrol.https.enabled", false);
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * RemoteControl HTTP protocol version. Change minor number for compatible
|
---|
31 | * interface extensions. Change major number in case of incompatible
|
---|
32 | * changes.
|
---|
33 | */
|
---|
34 | static final int protocolMajorVersion = 1;
|
---|
35 | static final int protocolMinorVersion = 6;
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Starts the remote control server
|
---|
39 | */
|
---|
40 | public static void start() {
|
---|
41 | RemoteControlHttpServer.restartRemoteControlHttpServer();
|
---|
42 | RemoteControlHttpsServer.restartRemoteControlHttpsServer();
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Stops the remote control server
|
---|
47 | * @since 5861
|
---|
48 | */
|
---|
49 | public static void stop() {
|
---|
50 | RemoteControlHttpServer.stopRemoteControlHttpServer();
|
---|
51 | RemoteControlHttpsServer.stopRemoteControlHttpsServer();
|
---|
52 | }
|
---|
53 |
|
---|
54 | /**
|
---|
55 | * Adds external request handler.
|
---|
56 | * Can be used by plugins that want to use remote control.
|
---|
57 | *
|
---|
58 | * @param command The command name.
|
---|
59 | * @param handlerClass The additional request handler.
|
---|
60 | */
|
---|
61 | public void addRequestHandler(String command, Class<? extends RequestHandler> handlerClass) {
|
---|
62 | RequestProcessor.addRequestHandlerClass(command, handlerClass);
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * Returns the remote control directory.
|
---|
67 | * @return The remote control directory
|
---|
68 | * @since 7335
|
---|
69 | */
|
---|
70 | public static String getRemoteControlDir() {
|
---|
71 | return Main.pref.getPreferencesDir() + "remotecontrol/";
|
---|
72 | }
|
---|
73 | }
|
---|