|
From: <br...@us...> - 2016-07-14 17:22:07
|
Revision: 4182
http://sourceforge.net/p/openlcb/svn/4182
Author: bracz
Date: 2016-07-14 17:22:04 +0000 (Thu, 14 Jul 2016)
Log Message:
-----------
Proxies IOExceptions from the gridconnect reader and writer directly into the OlcbConnection class. The previous detection methods of IO errors did not work.
The listeners of the OlcbConnection will now get the onDisconnect notifications when the socket is closed.
Modified Paths:
--------------
trunk/prototypes/java/src/org/openlcb/can/impl/GridConnectInput.java
trunk/prototypes/java/src/org/openlcb/can/impl/GridConnectOutput.java
trunk/prototypes/java/src/org/openlcb/can/impl/OlcbConnection.java
Modified: trunk/prototypes/java/src/org/openlcb/can/impl/GridConnectInput.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/impl/GridConnectInput.java 2016-07-14 17:21:44 UTC (rev 4181)
+++ trunk/prototypes/java/src/org/openlcb/can/impl/GridConnectInput.java 2016-07-14 17:22:04 UTC (rev 4182)
@@ -22,10 +22,19 @@
private ArrayList<Byte> data = new ArrayList<>();
private BufferedReader input;
private CanFrameListener listener;
+ private final Runnable onError;
- public GridConnectInput(BufferedReader input, CanFrameListener listener) {
+ /**
+ * Creates the gridconnect input parser. Starts the parsing thread.
+ *
+ * @param input the (buffered) socklet to read from
+ * @param listener the parsed CAN frames will be forwarded to this listener
+ * @param onError will be called when an IO error happens on the input thread. May be null.
+ */
+ public GridConnectInput(BufferedReader input, CanFrameListener listener, Runnable onError) {
this.input = input;
this.listener = listener;
+ this.onError = onError;
new Thread() {
public void run() {
threadBody();
@@ -106,6 +115,9 @@
} catch (IOException e1) {
logger.fine("Error closing from gridconnect port " + e1.toString());
}
+ if (onError != null) {
+ onError.run();
+ }
}
}
Modified: trunk/prototypes/java/src/org/openlcb/can/impl/GridConnectOutput.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/impl/GridConnectOutput.java 2016-07-14 17:21:44 UTC (rev 4181)
+++ trunk/prototypes/java/src/org/openlcb/can/impl/GridConnectOutput.java 2016-07-14 17:22:04 UTC (rev 4182)
@@ -19,9 +19,16 @@
private final static Logger logger = Logger.getLogger(TAG);
private BufferedOutputStream output;
+ private final Runnable onError;
- public GridConnectOutput(OutputStream output) {
+ /**
+ * Creates the object ussed for rendering CAN frames to GridConnect format.
+ * @param output the (raw) output socket to send the gridconnect data to.
+ * @param onError will be called when the output experiences an IO error. May be null.
+ */
+ public GridConnectOutput(OutputStream output, Runnable onError) {
this.output = new BufferedOutputStream(output);
+ this.onError = onError;
}
public static String format(CanFrame frame) {
@@ -60,6 +67,9 @@
} catch (IOException e1) {
logger.fine("Error closing gridconnect output: " + e1.toString());
}
+ if (onError != null) {
+ onError.run();
+ }
}
}
Modified: trunk/prototypes/java/src/org/openlcb/can/impl/OlcbConnection.java
===================================================================
--- trunk/prototypes/java/src/org/openlcb/can/impl/OlcbConnection.java 2016-07-14 17:21:44 UTC (rev 4181)
+++ trunk/prototypes/java/src/org/openlcb/can/impl/OlcbConnection.java 2016-07-14 17:22:04 UTC (rev 4182)
@@ -59,6 +59,15 @@
}.start();
}
+ private Runnable mOnError = new Runnable() {
+ @Override
+ public void run() {
+ outputHub.removeEntry(output);
+ listenerProxy.onDisconnect();
+ shutdown();
+ }
+ };
+
private void connect() {
this.inputHub = new CanFrameHub();
this.outputHub = new CanFrameHub();
@@ -77,8 +86,8 @@
listenerProxy.onDisconnect();
return;
}
- input = new GridConnectInput(reader, inputHub);
- output = new GridConnectOutput(outputStream);
+ input = new GridConnectInput(reader, inputHub, mOnError);
+ output = new GridConnectOutput(outputStream, mOnError);
outputHub.addEntry(output);
// Creates the actual OpenLCB objects and wires up with the interface.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|