Skip to content

Commit

Permalink
v1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
cigone-openindoor committed Dec 20, 2021
1 parent e97db76 commit df5b51b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@

import org.openstreetmap.josm.tools.Logging;

public class OIDAction extends JosmAction {
public class OpenIndoorAction extends JosmAction {

public OIDAction() {
public OpenIndoorAction() {
super(tr("View in OpenIndoor..."), null,
tr("View current layer in OpenIndoor web app"), null, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@
import java.text.SimpleDateFormat;
import java.util.TimeZone;

import org.openstreetmap.josm.tools.Logging;

/**
* @author ambarmodi
*
*/
public class HttpHandler implements Runnable {
public class OpenIndoorHttpHandler implements Runnable {
private Socket socket;
private String res;

public HttpHandler(Socket socket) {
public OpenIndoorHttpHandler(Socket socket) {
this.res = null;
this.socket = socket;
}
Expand All @@ -31,15 +33,13 @@ public void run() {
try {
handleRequest();
} catch (Exception e) {
System.err.println("Error Occured: " + e.getMessage());
Logging.error("Error Occured: " + e.getMessage());
try {
socket.close();
System.exit(0);
} catch (IOException e1) {
System.err.println("Error Closing socket Connection.");
System.exit(0);
Logging.error("Error Closing socket Connection.");
}
System.err.println("Server is Terminating!");
Logging.error("OpenIndoor is Terminating!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,53 +30,49 @@
import org.openstreetmap.josm.plugins.Plugin;
import org.openstreetmap.josm.plugins.PluginInformation;

import org.openstreetmap.josm.plugins.openindoor.OIDAction;
import org.openstreetmap.josm.plugins.openindoor.OpenIndoorAction;
import org.openstreetmap.josm.plugins.openindoor.IndoorEqualAction;

import org.openstreetmap.josm.tools.Pair;
import org.openstreetmap.josm.tools.ResourceProvider;

import org.openstreetmap.josm.plugins.openindoor.Server;
import org.openstreetmap.josm.plugins.openindoor.OpenIndoorServer;
import org.openstreetmap.josm.tools.Logging;

// import fi.iki.elonen.NanoHTTPD;

/**
* OpenIndoor plugin.
*/
public final class OIDPlugin extends Plugin {
public final class OpenIndoorPlugin extends Plugin {

private static OIDPlugin instance;
private static OpenIndoorPlugin instance;
private static int PORT = 8432;

public OIDPlugin(PluginInformation info) {
public OpenIndoorPlugin(PluginInformation info) {
super(info);
if (instance == null) {
instance = this;
try {
System.out.println("\n====================Server Details====================");
System.out.println("Server Machine: " + InetAddress.getLocalHost().getCanonicalHostName());
System.out.println("Port number: " + PORT);
System.out.println();
Logging.info("\n====================OpenIndoor Server Details====================");
Logging.info("OpenIndoor Server Machine: " + InetAddress.getLocalHost().getCanonicalHostName());
Logging.info("Port number: " + PORT);
} catch (UnknownHostException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//Here one instance of server is started..
try {
Server server = new Server(PORT);
OpenIndoorServer server = new OpenIndoorServer(PORT);
server.start();
// server.start();
} catch (IOException e) {
System.err.println("Error occured:" + e.getMessage());
System.exit(0);
Logging.error("Error occured:" + e.getMessage());
}
refreshMenu();
} else {
throw new IllegalStateException("Cannot instantiate plugin twice !");
}
}

public static OIDPlugin getInstance() {
public static OpenIndoorPlugin getInstance() {
return instance;
}

Expand All @@ -87,7 +83,7 @@ public static void refreshMenu() {
else {
menu.setVisible(true);
}
menu.add(new JMenuItem(new OIDAction()));
menu.add(new JMenuItem(new OpenIndoorAction()));
menu.add(new JMenuItem(new IndoorEqualAction()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@
import java.net.UnknownHostException;
import java.util.HashMap;

import org.openstreetmap.josm.plugins.openindoor.HttpHandler;
import org.openstreetmap.josm.plugins.openindoor.OpenIndoorHttpHandler;
import org.openstreetmap.josm.tools.Logging;

/**
* @author ambarmodi
*
*/
// public class Server {
public class Server extends Thread {
// private static int PORT = 8080;
public class OpenIndoorServer extends Thread {
private ServerSocket serverSocket;
private static HashMap<String,Integer> requestedRes = new HashMap<String,Integer>();
private static final String DELIMITER = "|";

public Server(int port) throws IOException {
// PORT = port;
public OpenIndoorServer(int port) throws IOException {
serverSocket = new ServerSocket(port);
}

Expand All @@ -31,7 +25,7 @@ public Server(int port) throws IOException {
private void start_() throws IOException {
while (true) {
Socket socket = serverSocket.accept();
HttpHandler connection = new HttpHandler(socket);
OpenIndoorHttpHandler connection = new OpenIndoorHttpHandler(socket);

Thread request = new Thread(connection);
request.start();
Expand All @@ -42,8 +36,7 @@ public void run() {
try {
this.start_();
} catch (IOException e1) {
System.err.println(e1.getMessage());
System.exit(0);
Logging.error(e1.getMessage());
}
}

Expand All @@ -60,6 +53,6 @@ public static void printResult(String res, int port2, String ipAddress) {
} else {
requestedRes.put(res, requestedRes.get(res) + 1);
}
System.out.println(res + DELIMITER+ ipAddress + DELIMITER + port2 +DELIMITER + requestedRes.get(res));
Logging.info(res + DELIMITER+ ipAddress + DELIMITER + port2 +DELIMITER + requestedRes.get(res));
}
}

0 comments on commit df5b51b

Please sign in to comment.