UI to show bytes flow
This commit is contained in:
parent
cc606bf515
commit
585268fce4
|
@ -5,7 +5,7 @@ import com.rusefi.io.IoStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
public abstract class AbstractIoStream implements IoStream {
|
public abstract class AbstractIoStream implements IoStream, StreamStatistics {
|
||||||
private boolean isClosed;
|
private boolean isClosed;
|
||||||
|
|
||||||
protected StreamStats streamStats = new StreamStats();
|
protected StreamStats streamStats = new StreamStats();
|
||||||
|
@ -64,10 +64,12 @@ public abstract class AbstractIoStream implements IoStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getBytesIn() {
|
public int getBytesIn() {
|
||||||
return streamStats.totalBytesArrived.get();
|
return streamStats.totalBytesArrived.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public int getBytesOut() {
|
public int getBytesOut() {
|
||||||
return bytesOut.get();
|
return bytesOut.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package com.rusefi.io.serial;
|
||||||
|
|
||||||
|
public interface StreamStatistics {
|
||||||
|
int getBytesIn();
|
||||||
|
|
||||||
|
int getBytesOut();
|
||||||
|
}
|
|
@ -5,6 +5,8 @@ import com.rusefi.NamedThreadFactory;
|
||||||
import com.rusefi.io.IoStream;
|
import com.rusefi.io.IoStream;
|
||||||
import com.rusefi.io.commands.GetOutputsCommand;
|
import com.rusefi.io.commands.GetOutputsCommand;
|
||||||
import com.rusefi.io.commands.HelloCommand;
|
import com.rusefi.io.commands.HelloCommand;
|
||||||
|
import com.rusefi.io.serial.AbstractIoStream;
|
||||||
|
import com.rusefi.io.serial.StreamStatistics;
|
||||||
import com.rusefi.io.tcp.BinaryProtocolProxy;
|
import com.rusefi.io.tcp.BinaryProtocolProxy;
|
||||||
import com.rusefi.io.tcp.ServerSocketReference;
|
import com.rusefi.io.tcp.ServerSocketReference;
|
||||||
import com.rusefi.io.tcp.TcpIoStream;
|
import com.rusefi.io.tcp.TcpIoStream;
|
||||||
|
@ -52,7 +54,7 @@ public class LocalApplicationProxy implements Closeable {
|
||||||
if (!version.contains(ProxyClient.BACKEND_VERSION))
|
if (!version.contains(ProxyClient.BACKEND_VERSION))
|
||||||
throw new IOException("Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION);
|
throw new IOException("Unexpected backend version " + version + " while we want " + ProxyClient.BACKEND_VERSION);
|
||||||
|
|
||||||
IoStream authenticatorToProxyStream = new TcpIoStream("authenticatorToProxyStream ", rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, context.serverPortForRemoteApplications()), disconnectListener);
|
AbstractIoStream authenticatorToProxyStream = new TcpIoStream("authenticatorToProxyStream ", rusEFISSLContext.getSSLSocket(HttpUtil.RUSEFI_PROXY_HOSTNAME, context.serverPortForRemoteApplications()), disconnectListener);
|
||||||
LocalApplicationProxy.sendHello(authenticatorToProxyStream, applicationRequest);
|
LocalApplicationProxy.sendHello(authenticatorToProxyStream, applicationRequest);
|
||||||
|
|
||||||
AtomicInteger relayCommandCounter = new AtomicInteger();
|
AtomicInteger relayCommandCounter = new AtomicInteger();
|
||||||
|
@ -87,7 +89,7 @@ public class LocalApplicationProxy implements Closeable {
|
||||||
|
|
||||||
ServerSocketReference serverHolder = BinaryProtocolProxy.createProxy(authenticatorToProxyStream, context.authenticatorPort(), relayCommandCounter);
|
ServerSocketReference serverHolder = BinaryProtocolProxy.createProxy(authenticatorToProxyStream, context.authenticatorPort(), relayCommandCounter);
|
||||||
LocalApplicationProxy localApplicationProxy = new LocalApplicationProxy(applicationRequest, serverHolder, authenticatorToProxyStream);
|
LocalApplicationProxy localApplicationProxy = new LocalApplicationProxy(applicationRequest, serverHolder, authenticatorToProxyStream);
|
||||||
connectionListener.onConnected(localApplicationProxy);
|
connectionListener.onConnected(localApplicationProxy, authenticatorToProxyStream);
|
||||||
return serverHolder;
|
return serverHolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,9 +114,9 @@ public class LocalApplicationProxy implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ConnectionListener {
|
public interface ConnectionListener {
|
||||||
ConnectionListener VOID = localApplicationProxy -> {
|
ConnectionListener VOID = (localApplicationProxy, authenticatorToProxyStream) -> {
|
||||||
};
|
};
|
||||||
|
|
||||||
void onConnected(LocalApplicationProxy localApplicationProxy);
|
void onConnected(LocalApplicationProxy localApplicationProxy, StreamStatistics authenticatorToProxyStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,9 @@ package com.rusefi.ts_plugin;
|
||||||
|
|
||||||
import com.rusefi.NamedThreadFactory;
|
import com.rusefi.NamedThreadFactory;
|
||||||
import com.rusefi.SignatureHelper;
|
import com.rusefi.SignatureHelper;
|
||||||
|
import com.rusefi.Timeouts;
|
||||||
import com.rusefi.autoupdate.AutoupdateUtil;
|
import com.rusefi.autoupdate.AutoupdateUtil;
|
||||||
|
import com.rusefi.io.serial.StreamStatistics;
|
||||||
import com.rusefi.io.tcp.ServerSocketReference;
|
import com.rusefi.io.tcp.ServerSocketReference;
|
||||||
import com.rusefi.io.tcp.TcpIoStream;
|
import com.rusefi.io.tcp.TcpIoStream;
|
||||||
import com.rusefi.proxy.client.LocalApplicationProxy;
|
import com.rusefi.proxy.client.LocalApplicationProxy;
|
||||||
|
@ -20,6 +22,8 @@ import org.putgemin.VerticalFlowLayout;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
@ -50,6 +54,8 @@ public class RemoteTab {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
private StreamStatusControl streamStatusControl = null;
|
||||||
|
|
||||||
private final JButton disconnect = new JButton("Disconnect");
|
private final JButton disconnect = new JButton("Disconnect");
|
||||||
|
|
||||||
private final Executor listDownloadExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("online list downloader"));
|
private final Executor listDownloadExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("online list downloader"));
|
||||||
|
@ -67,6 +73,15 @@ public class RemoteTab {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Timer timer = new Timer(Timeouts.SECOND, new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
if (streamStatusControl != null)
|
||||||
|
streamStatusControl.update();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
timer.start();
|
||||||
|
|
||||||
JTextField applicationPort = new JTextField() {
|
JTextField applicationPort = new JTextField() {
|
||||||
@Override
|
@Override
|
||||||
public Dimension getPreferredSize() {
|
public Dimension getPreferredSize() {
|
||||||
|
@ -101,7 +116,7 @@ public class RemoteTab {
|
||||||
if (currentState == null) {
|
if (currentState == null) {
|
||||||
requestListDownload();
|
requestListDownload();
|
||||||
} else {
|
} else {
|
||||||
setConnectedStatus(currentState.getApplicationRequest().getTargetUser());
|
setConnectedStatus(currentState.getApplicationRequest().getTargetUser(), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,12 +187,12 @@ public class RemoteTab {
|
||||||
RemoteTabController.INSTANCE.setState(RemoteTabController.State.CONNECTING);
|
RemoteTabController.INSTANCE.setState(RemoteTabController.State.CONNECTING);
|
||||||
setStatus("Connecting to " + publicSession.getUserDetails().getUserName());
|
setStatus("Connecting to " + publicSession.getUserDetails().getUserName());
|
||||||
|
|
||||||
LocalApplicationProxy.ConnectionListener connectionListener = localApplicationProxy -> {
|
LocalApplicationProxy.ConnectionListener connectionListener = (localApplicationProxy, authenticatorToProxyStream) -> {
|
||||||
RemoteTabController.INSTANCE.setConnected(localApplicationProxy);
|
RemoteTabController.INSTANCE.setConnected(localApplicationProxy);
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
setConnectedStatus(publicSession.getUserDetails());
|
setConnectedStatus(publicSession.getUserDetails(), authenticatorToProxyStream);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
@ -187,17 +202,24 @@ public class RemoteTab {
|
||||||
}, "Authenticator").start();
|
}, "Authenticator").start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setConnectedStatus(UserDetails userDetails) {
|
private void setConnectedStatus(UserDetails userDetails, StreamStatistics authenticatorToProxyStream) {
|
||||||
|
if (authenticatorToProxyStream != null) {
|
||||||
|
streamStatusControl = new StreamStatusControl(authenticatorToProxyStream);
|
||||||
|
}
|
||||||
|
|
||||||
setStatus("Connected to " + userDetails.getUserName(),
|
setStatus("Connected to " + userDetails.getUserName(),
|
||||||
new JLabel("You can now connect your TunerStudio to IP address localhost and port " + getLocalPort()),
|
new JLabel("You can now connect your TunerStudio to IP address localhost and port " + getLocalPort()),
|
||||||
disconnect);
|
disconnect, streamStatusControl == null ? null : streamStatusControl.getContent());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setStatus(String text, JComponent... extra) {
|
private void setStatus(String text, JComponent... extra) {
|
||||||
list.removeAll();
|
list.removeAll();
|
||||||
list.add(new JLabel(text));
|
list.add(new JLabel(text));
|
||||||
for (JComponent component : extra)
|
for (JComponent component : extra) {
|
||||||
list.add(component);
|
if (component != null) {
|
||||||
|
list.add(component);
|
||||||
|
}
|
||||||
|
}
|
||||||
AutoupdateUtil.trueLayout(list);
|
AutoupdateUtil.trueLayout(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
package com.rusefi.ts_plugin;
|
||||||
|
|
||||||
|
import com.rusefi.io.serial.StreamStatistics;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
|
||||||
|
public class StreamStatusControl {
|
||||||
|
private final StreamStatistics authenticatorToProxyStream;
|
||||||
|
|
||||||
|
private final JLabel content = new JLabel();
|
||||||
|
|
||||||
|
public StreamStatusControl(StreamStatistics statistics) {
|
||||||
|
this.authenticatorToProxyStream = statistics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
content.setText("In " + authenticatorToProxyStream.getBytesIn() + " Out " + authenticatorToProxyStream.getBytesOut());
|
||||||
|
}
|
||||||
|
|
||||||
|
public JComponent getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue