Skip to content

Commit

Permalink
review updates
Browse files Browse the repository at this point in the history
  • Loading branch information
supertick committed Dec 16, 2023
1 parent d79f84f commit 750a595
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/myrobotlab/service/Keyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public void nativeMouseWheelMoved(NativeMouseWheelEvent me) {
public Keyboard(String n, String id) {
super(n, id);
if (Service.isHeadless()) {
log.info("the Keyboard service requires a DISPLAY to function correctly");
log.warn("the Keyboard service requires a DISPLAY to function correctly");
keyboard = null;
mouseEvent = null;
return;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/myrobotlab/service/KeyboardSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public KeyboardSim(String n, String id) {
if (!GraphicsEnvironment.isHeadless()) {
robot = new Robot();
} else {
log.info("headless environment - but KeyboardSim requires a display");
log.warn("headless environment - but KeyboardSim requires a display");
}
} catch (Exception e) {
log.error("could not create java.awt.Robot", e);
Expand Down
79 changes: 48 additions & 31 deletions src/main/java/org/myrobotlab/service/Vertx.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@

/**
* Vertx gateway - used to support a http and websocket gateway for myrobotlab.
* Write business logic in Verticles. Also, try not to write any logic besides initialization inside start() method.
* Write business logic in Verticles. Also, try not to write any logic besides
* initialization inside start() method.
*
* It currently does not utilize the Vertx event bus - which is pretty much the most important part of Vertx.
* TODO: take advantage of publishing on the event bus
* It currently does not utilize the Vertx event bus - which is pretty much the
* most important part of Vertx. TODO: take advantage of publishing on the event
* bus
*
* <a href="https://medium.com/@pvub/https-medium-com-pvub-vert-x-workers-6a8df9b2b9ee">vertx worker</a>
* {@link <a href=
* "https://medium.com/@pvub/https-medium-com-pvub-vert-x-workers-6a8df9b2b9ee">vertx
* worker</a>}
*
* @author GroG
*
Expand All @@ -45,7 +49,8 @@ public Vertx(String n, String id) {
}

/**
* deploys a http and websocket verticle on a secure TLS channel with self signed certificate
* deploys a http and websocket verticle on a secure TLS channel with self
* signed certificate
*/
public void start() {
log.info("starting driver");
Expand Down Expand Up @@ -73,13 +78,13 @@ public void start() {
vertx.deployVerticle(new ApiVerticle(this));

}

@Override
public void startService() {
super.startService();
start();
}

@Override
public void stopService() {
super.stopService();
Expand Down Expand Up @@ -111,53 +116,64 @@ public static void main(String[] args) {
Vertx vertx = (Vertx) Runtime.start("vertx", "Vertx");
vertx.start();

InMoov2 i01 = (InMoov2)Runtime.start("i01", "InMoov2");
// i01.startSimulator();
JMonkeyEngine jme = (JMonkeyEngine)i01.startPeer("simulator");
// Runtime.start("python", "Python");
//
WebGui webgui = (WebGui) Runtime.create("webgui", "WebGui");
// webgui.setSsl(true);
webgui.autoStartBrowser(false);
webgui.setPort(8888);
webgui.startService();
InMoov2 i01 = (InMoov2) Runtime.start("i01", "InMoov2");
// i01.startSimulator();
JMonkeyEngine jme = (JMonkeyEngine) i01.startPeer("simulator");
// Runtime.start("python", "Python");
//
WebGui webgui = (WebGui) Runtime.create("webgui", "WebGui");
// webgui.setSsl(true);
webgui.autoStartBrowser(false);
webgui.setPort(8888);
webgui.startService();

} catch (Exception e) {
log.error("main threw", e);
}
}

// FIXME - refactor for bare minimum

@Override /* FIXME "Gateway" is server/service oriented not connecting thing - remove this */

@Override /*
* FIXME "Gateway" is server/service oriented not connecting thing -
* remove this
*/
public void connect(String uri) throws URISyntaxException {
// TODO Auto-generated method stub

}

@Override /* FIXME not much point of these - as they are all consistently using Runtime's centralized connection info */

@Override /*
* FIXME not much point of these - as they are all consistently
* using Runtime's centralized connection info
*/
public List<String> getClientIds() {
return Runtime.getInstance().getConnectionUuids(getName());
}

@Override /* FIXME not much point of these - as they are all consistently using Runtime's centralized connection info */
@Override /*
* FIXME not much point of these - as they are all consistently
* using Runtime's centralized connection info
*/
public Map<String, Connection> getClients() {
return Runtime.getInstance().getConnections(getName());
}


@Override /* FIXME this is the one and probably "only" relevant method for Gateway - perhaps a handle(Connection c) */
@Override /*
* FIXME this is the one and probably "only" relevant method for
* Gateway - perhaps a handle(Connection c)
*/
public void sendRemote(Message msg) throws Exception {
log.info("sendRemote {}", msg.toString());
// FIXME MUST BE DIRECT THREAD FROM BROADCAST NOT OUTBOX !!!
msg.addHop(getId());
Map<String, Connection> clients = getClients();
for(Connection c: clients.values()) {
for (Connection c : clients.values()) {
try {
ServerWebSocket socket = (ServerWebSocket)c.get("websocket");
String json = CodecUtils.toJsonMsg(msg);
socket.writeTextMessage(json);
} catch(Exception e) {
ServerWebSocket socket = (ServerWebSocket) c.get("websocket");
String json = CodecUtils.toJsonMsg(msg);
socket.writeTextMessage(json);
} catch (Exception e) {
error(e);
}
}
Expand All @@ -166,8 +182,9 @@ public void sendRemote(Message msg) throws Exception {

@Override
public boolean isLocal(Message msg) {
return Runtime.getInstance().isLocal(msg); }

return Runtime.getInstance().isLocal(msg);
}

public io.vertx.core.Vertx getVertx() {
return vertx;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.myrobotlab.service.FiniteStateMachine.StateChange;

public interface StateChangeHandler {
public interface StateChangeListener {

public void handleStateChange(StateChange event);
public void onStateChange(StateChange event);

}

0 comments on commit 750a595

Please sign in to comment.