Skip to content

Commit

Permalink
Apply client adjustments to refactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
Berenz committed Apr 14, 2016
1 parent f3104f2 commit 1d2f230
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/qz/utils/PrintingUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,18 @@ public static PrinterResolution getNativeDensity(PrintService service) {
* @param UID ID of call from web API
* @param params Params of call from web API
*/
public static void processPrintRequest(Session session, String UID, JSONObject params) {
public static void processPrintRequest(Session session, String UID, JSONObject params) throws JSONException {
PrintProcessor processor = PrintingUtilities.getPrintProcessor(params.getJSONArray("data"));
log.debug("Using {} to print", processor.getClass().getName());

try {
PrintOutput output = new PrintOutput(params.optJSONObject("printer"));
PrintOptions options = new PrintOptions(params.optJSONObject("options"), output);

PrintProcessor processor = PrintingUtilities.getPrintProcessor(params.getJSONArray("data"));
log.debug("Using {} to print", processor.getClass().getName());

processor.parseData(params.optJSONArray("data"), options);
processor.print(output, options);
log.info("Printing complete");

releasePrintProcessor(processor);

PrintSocketClient.sendResult(session, UID, null);
}
catch(PrinterAbortException e) {
Expand All @@ -154,6 +152,8 @@ public static void processPrintRequest(Session session, String UID, JSONObject p
log.error("Failed to print", e);
PrintSocketClient.sendError(session, UID, e);
}

PrintingUtilities.releasePrintProcessor(processor);
}

}
10 changes: 6 additions & 4 deletions src/qz/utils/SerialUtilities.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,13 @@ public static void setupSerialPort(final Session session, String UID, SocketConn
serial.applyPortListener(new SerialPortEventListener() {
public void serialEvent(SerialPortEvent spe) {
String output = serial.processSerialEvent(spe);
log.debug("Received serial output: {}", output);

StreamEvent event = new StreamEvent(StreamEvent.Stream.SERIAL, StreamEvent.Type.RECEIVE)
.withData("portName", portName).withData("output", output);
PrintSocketClient.sendStream(session, event);
if (output != null) {
log.debug("Received serial output: {}", output);
StreamEvent event = new StreamEvent(StreamEvent.Stream.SERIAL, StreamEvent.Type.RECEIVE)
.withData("portName", portName).withData("output", output);
PrintSocketClient.sendStream(session, event);
}
}
});

Expand Down

0 comments on commit 1d2f230

Please sign in to comment.