Add sendToLogger parameter (#6699)
This commit is contained in:
parent
a58876edd3
commit
ff59dca8d3
|
@ -1,18 +1,18 @@
|
|||
package com.rusefi.io;
|
||||
|
||||
public interface UpdateOperationCallbacks {
|
||||
void log(String message, boolean breakLineOnTextArea);
|
||||
void log(String message, boolean breakLineOnTextArea, boolean sendToLogger);
|
||||
|
||||
default void logLine(final String message) {
|
||||
log(message, true);
|
||||
log(message, true, true);
|
||||
}
|
||||
|
||||
default void append(final String message, final boolean breakLineOnTextArea) {
|
||||
log(message, breakLineOnTextArea);
|
||||
default void append(final String message, final boolean breakLineOnTextArea, final boolean sendToLogger) {
|
||||
log(message, breakLineOnTextArea, sendToLogger);
|
||||
}
|
||||
|
||||
default void appendLine(final String message) {
|
||||
append(message, true);
|
||||
append(message, true, true);
|
||||
}
|
||||
|
||||
void done();
|
||||
|
@ -20,7 +20,7 @@ public interface UpdateOperationCallbacks {
|
|||
|
||||
class UpdateOperationDummy implements UpdateOperationCallbacks {
|
||||
@Override
|
||||
public void log(final String message, final boolean breakLineOnTextArea) {
|
||||
public void log(final String message, final boolean breakLineOnTextArea, boolean sendToLogger) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -48,8 +48,10 @@ public class PCanIoStream extends AbstractIoStream {
|
|||
|
||||
@Nullable
|
||||
public static PCanIoStream createStream() {
|
||||
return createStream((message, breakLineOnTextArea) -> {
|
||||
log.info(message);
|
||||
return createStream((message, breakLineOnTextArea, sendToLogger) -> {
|
||||
if (sendToLogger) {
|
||||
log.info(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -57,10 +59,10 @@ public class PCanIoStream extends AbstractIoStream {
|
|||
PCANBasic can = PCanHelper.create();
|
||||
TPCANStatus status = PCanHelper.init(can);
|
||||
if (status != TPCANStatus.PCAN_ERROR_OK) {
|
||||
statusListener.append("Error initializing PCAN: " + status, true);
|
||||
statusListener.append("Error initializing PCAN: " + status, true, true);
|
||||
return null;
|
||||
}
|
||||
statusListener.append("Creating PCAN stream...", true);
|
||||
statusListener.append("Creating PCAN stream...", true, true);
|
||||
return new PCanIoStream(can, statusListener);
|
||||
}
|
||||
|
||||
|
@ -73,7 +75,7 @@ public class PCanIoStream extends AbstractIoStream {
|
|||
|
||||
TPCANStatus status = PCanHelper.send(can, isoTpConnector.canId(), payLoad);
|
||||
if (status != TPCANStatus.PCAN_ERROR_OK) {
|
||||
statusListener.append("Unable to write the CAN message: " + status, true);
|
||||
statusListener.append("Unable to write the CAN message: " + status, true, true);
|
||||
System.exit(0);
|
||||
}
|
||||
// log.info("Send OK! length=" + payLoad.length);
|
||||
|
|
|
@ -44,7 +44,7 @@ public class BinaryProtocolProxy {
|
|||
clientStream = new TcpIoStream("[[proxy]] ", clientSocket);
|
||||
runProxy(targetEcuSocket, clientStream, clientApplicationActivityListener, USER_IO_TIMEOUT);
|
||||
} catch (IOException e) {
|
||||
statusConsumer.append("ERROR BinaryProtocolProxy::run " + e, true);
|
||||
statusConsumer.append("ERROR BinaryProtocolProxy::run " + e, true, true);
|
||||
close(clientStream);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -96,7 +96,7 @@ public class BinaryProtocolServer {
|
|||
public static ServerSocketReference tcpServerSocket(int port, String threadName, CompatibleFunction<Socket, Runnable> socketRunnableFactory, Listener serverSocketCreationCallback, StatusConsumer statusConsumer) throws IOException {
|
||||
return tcpServerSocket(socketRunnableFactory, port, threadName, serverSocketCreationCallback, p -> {
|
||||
ServerSocket serverSocket = new ServerSocket(p);
|
||||
statusConsumer.append("ServerSocket " + p + " created. Feel free to point TS at IP Address 'localhost' port " + p, true);
|
||||
statusConsumer.append("ServerSocket " + p + " created. Feel free to point TS at IP Address 'localhost' port " + p, true, true);
|
||||
return serverSocket;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -10,11 +10,13 @@ import static com.devexperts.logging.Logging.getLogging;
|
|||
public interface StatusConsumer {
|
||||
Logging log = getLogging(StatusConsumer.class);
|
||||
|
||||
StatusConsumer ANONYMOUS = (status, breakLineOnTextArea) -> {
|
||||
log.info(status);
|
||||
StatusConsumer ANONYMOUS = (status, breakLineOnTextArea, sendToLogger) -> {
|
||||
if (sendToLogger) {
|
||||
log.info(status);
|
||||
}
|
||||
};
|
||||
StatusConsumer VOID = (status, breakLineOnTextArea) -> {
|
||||
StatusConsumer VOID = (status, breakLineOnTextArea, sendToLogger) -> {
|
||||
};
|
||||
|
||||
void append(String status, boolean breakLineOnTextArea);
|
||||
void append(String status, boolean breakLineOnTextArea, boolean sendToLogger);
|
||||
}
|
||||
|
|
|
@ -9,8 +9,8 @@ public class UpdateStatusWindow extends StatusWindow implements UpdateOperationC
|
|||
}
|
||||
|
||||
@Override
|
||||
public void log(final String message, final boolean breakLineOnTextArea) {
|
||||
append(message, breakLineOnTextArea);
|
||||
public void log(final String message, final boolean breakLineOnTextArea, boolean sendToLogger) {
|
||||
append(message, breakLineOnTextArea, sendToLogger);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,9 +15,9 @@ public class CANConnectorStartup {
|
|||
|
||||
String signature = BinaryProtocol.getSignature(tsStream);
|
||||
if (signature == null) {
|
||||
statusListener.append("Error: no ECU signature from " + tsStream, true);
|
||||
statusListener.append("Error: no ECU signature from " + tsStream, true, true);
|
||||
} else {
|
||||
statusListener.append("Got [" + signature + "] ECU signature via " + tsStream, true);
|
||||
statusListener.append("Got [" + signature + "] ECU signature via " + tsStream, true, true);
|
||||
}
|
||||
BinaryProtocolProxy.createProxy(tsStream, TcpConnector.DEFAULT_PORT, BinaryProtocolProxy.ClientApplicationActivityListener.VOID, statusListener);
|
||||
|
||||
|
|
|
@ -56,8 +56,10 @@ public class ConsoleTools {
|
|||
private static final StatusConsumer statusListener = new StatusConsumer() {
|
||||
final Logging log = getLogging(CANConnectorStartup.class);
|
||||
@Override
|
||||
public void append(final String message, final boolean breakLineOnTextArea) {
|
||||
log.info(message);
|
||||
public void append(final String message, final boolean breakLineOnTextArea, final boolean sendToLogger) {
|
||||
if (sendToLogger) {
|
||||
log.info(message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -24,8 +24,10 @@ public class PcanConnectorUI {
|
|||
JTextArea logTextArea = new JTextArea();
|
||||
panel.add(logTextArea, BorderLayout.CENTER);
|
||||
|
||||
StatusConsumer statusConsumer = (string, breakLineOnTextArea) -> SwingUtilities.invokeLater(() -> {
|
||||
log.info(string);
|
||||
StatusConsumer statusConsumer = (string, breakLineOnTextArea, sendToLogger) -> SwingUtilities.invokeLater(() -> {
|
||||
if (sendToLogger) {
|
||||
log.info(string);
|
||||
}
|
||||
String stringForTextArea = string;
|
||||
if (breakLineOnTextArea) {
|
||||
stringForTextArea += "\r\n";
|
||||
|
@ -40,7 +42,7 @@ public class PcanConnectorUI {
|
|||
if (stream != null)
|
||||
CANConnectorStartup.start(stream, statusConsumer);
|
||||
} catch (IOException e) {
|
||||
statusConsumer.append("Error " + e, true);
|
||||
statusConsumer.append("Error " + e, true, true);
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
|
|
@ -62,8 +62,8 @@ public class StatusWindow implements StatusConsumer, UpdateOperationCallbacks {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void log(final String message, final boolean breakLineOnTextArea) {
|
||||
append(message, breakLineOnTextArea);
|
||||
public void log(final String message, final boolean breakLineOnTextArea, final boolean sendToLogger) {
|
||||
append(message, breakLineOnTextArea, sendToLogger);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,11 +93,13 @@ public class StatusWindow implements StatusConsumer, UpdateOperationCallbacks {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void append(final String string, final boolean breakLineOnTextArea) {
|
||||
public void append(final String string, final boolean breakLineOnTextArea, final boolean sendToLogger) {
|
||||
// todo: check if AWT thread and do not invokeLater if already on AWT thread
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
String s = string.replaceAll(Character.toString((char) 219), "");
|
||||
log.info(s);
|
||||
if (sendToLogger) {
|
||||
log.info(s);
|
||||
}
|
||||
String stringForTestArea = s;
|
||||
if (breakLineOnTextArea) {
|
||||
stringForTestArea += "\r\n";
|
||||
|
|
|
@ -8,6 +8,6 @@ import java.io.IOException;
|
|||
public class PCanIoProxySandbox {
|
||||
public static void main(String[] args) throws IOException {
|
||||
PCanIoStream stream = PCanIoStream.createStream();
|
||||
CANConnectorStartup.start(stream, status -> System.out.println("Status: " + status));
|
||||
CANConnectorStartup.start(stream, (status, breakLineOnTextArea, sendToLogger) -> System.out.println("Status: " + status));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue