source: josm/trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControl.java@ 7834

Last change on this file since 7834 was 7834, checked in by Don-vip, 9 years ago

see #10026 - use recommended user data directory on OSX (distinct from preferences directory). Linux and Windows behaviour is unchanged.

  • Property svn:eol-style set to native
File size: 3.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.remotecontrol;
3
4import java.io.File;
5import java.net.InetAddress;
6import java.net.UnknownHostException;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.data.preferences.BooleanProperty;
10import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler;
11
12/**
13 * Manager class for remote control operations.
14 *
15 * IMPORTANT! increment the minor version on compatible API extensions
16 * and increment the major version and set minor to 0 on incompatible changes.
17 */
18public class RemoteControl {
19
20 /**
21 * If the remote control 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 /**
27 * If the remote control feature is enabled or disabled for HTTPS. If disabled,
28 * only HTTP access will be available.
29 * @since 7335
30 */
31 public static final BooleanProperty PROP_REMOTECONTROL_HTTPS_ENABLED = new BooleanProperty(
32 "remotecontrol.https.enabled", false);
33
34 /**
35 * RemoteControl HTTP protocol version. Change minor number for compatible
36 * interface extensions. Change major number in case of incompatible
37 * changes.
38 */
39 static final int protocolMajorVersion = 1;
40 static final int protocolMinorVersion = 7;
41
42 /**
43 * Starts the remote control server
44 */
45 public static void start() {
46 RemoteControlHttpServer.restartRemoteControlHttpServer();
47 RemoteControlHttpsServer.restartRemoteControlHttpsServer();
48 }
49
50 /**
51 * Stops the remote control server
52 * @since 5861
53 */
54 public static void stop() {
55 RemoteControlHttpServer.stopRemoteControlHttpServer();
56 RemoteControlHttpsServer.stopRemoteControlHttpsServer();
57 }
58
59 /**
60 * Adds external request handler.
61 * Can be used by plugins that want to use remote control.
62 *
63 * @param command The command name.
64 * @param handlerClass The additional request handler.
65 */
66 public void addRequestHandler(String command, Class<? extends RequestHandler> handlerClass) {
67 RequestProcessor.addRequestHandlerClass(command, handlerClass);
68 }
69
70 /**
71 * Returns the remote control directory.
72 * @return The remote control directory
73 * @since 7335
74 */
75 public static String getRemoteControlDir() {
76 return new File(Main.pref.getUserDataDirectory(), "remotecontrol").getAbsolutePath();
77 }
78
79 /**
80 * Returns the inet address used for remote control.
81 * @return the inet address used for remote control
82 * @throws UnknownHostException if the local host name could not be resolved into an address.
83 * @since 7800
84 */
85 public static InetAddress getInetAddress() throws UnknownHostException {
86 // Return an address to the loopback interface by default
87 return InetAddress.getByName(Main.pref.get("remote.control.host", null));
88 }
89}
Note: See TracBrowser for help on using the repository browser.