mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Reuse Anrduino remote connections when fetching.
Change-Id: I776cf031f34b51ed504709d367b6b0352c868815
This commit is contained in:
parent
49bf118c8f
commit
409b39b10a
1 changed files with 28 additions and 4 deletions
|
@ -11,6 +11,8 @@
|
||||||
package org.eclipse.cdt.arduino.core.internal.remote;
|
package org.eclipse.cdt.arduino.core.internal.remote;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.eclipse.cdt.arduino.core.Board;
|
import org.eclipse.cdt.arduino.core.Board;
|
||||||
import org.eclipse.cdt.arduino.core.IArduinoBoardManager;
|
import org.eclipse.cdt.arduino.core.IArduinoBoardManager;
|
||||||
|
@ -19,27 +21,50 @@ import org.eclipse.cdt.arduino.core.internal.Activator;
|
||||||
import org.eclipse.cdt.serial.SerialPort;
|
import org.eclipse.cdt.serial.SerialPort;
|
||||||
import org.eclipse.remote.core.IRemoteCommandShellService;
|
import org.eclipse.remote.core.IRemoteCommandShellService;
|
||||||
import org.eclipse.remote.core.IRemoteConnection;
|
import org.eclipse.remote.core.IRemoteConnection;
|
||||||
|
import org.eclipse.remote.core.IRemoteConnectionChangeListener;
|
||||||
import org.eclipse.remote.core.IRemoteConnectionPropertyService;
|
import org.eclipse.remote.core.IRemoteConnectionPropertyService;
|
||||||
import org.eclipse.remote.core.IRemoteProcess;
|
import org.eclipse.remote.core.IRemoteProcess;
|
||||||
|
import org.eclipse.remote.core.RemoteConnectionChangeEvent;
|
||||||
import org.eclipse.remote.serial.core.SerialPortCommandShell;
|
import org.eclipse.remote.serial.core.SerialPortCommandShell;
|
||||||
|
|
||||||
public class ArduinoRemoteConnection implements IRemoteConnectionPropertyService, IRemoteCommandShellService, IArduinoRemoteConnection {
|
public class ArduinoRemoteConnection implements IRemoteConnectionPropertyService, IRemoteCommandShellService,
|
||||||
|
IArduinoRemoteConnection, IRemoteConnectionChangeListener {
|
||||||
|
|
||||||
private final IArduinoBoardManager boardManager = Activator.getService(IArduinoBoardManager.class);
|
private final IArduinoBoardManager boardManager = Activator.getService(IArduinoBoardManager.class);
|
||||||
private final IRemoteConnection remoteConnection;
|
private final IRemoteConnection remoteConnection;
|
||||||
private SerialPort serialPort;
|
private SerialPort serialPort;
|
||||||
private SerialPortCommandShell commandShell;
|
private SerialPortCommandShell commandShell;
|
||||||
|
|
||||||
|
private static final Map<IRemoteConnection, ArduinoRemoteConnection> connectionMap = new HashMap<>();
|
||||||
|
|
||||||
public ArduinoRemoteConnection(IRemoteConnection remoteConnection) {
|
public ArduinoRemoteConnection(IRemoteConnection remoteConnection) {
|
||||||
this.remoteConnection = remoteConnection;
|
this.remoteConnection = remoteConnection;
|
||||||
|
remoteConnection.addConnectionChangeListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connectionChanged(RemoteConnectionChangeEvent event) {
|
||||||
|
if (event.getType() == RemoteConnectionChangeEvent.CONNECTION_REMOVED) {
|
||||||
|
synchronized (connectionMap) {
|
||||||
|
connectionMap.remove(event.getConnection());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Factory implements IRemoteConnection.Service.Factory {
|
public static class Factory implements IRemoteConnection.Service.Factory {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public <T extends IRemoteConnection.Service> T getService(IRemoteConnection remoteConnection, Class<T> service) {
|
public <T extends IRemoteConnection.Service> T getService(IRemoteConnection remoteConnection,
|
||||||
|
Class<T> service) {
|
||||||
if (IArduinoRemoteConnection.class.equals(service)) {
|
if (IArduinoRemoteConnection.class.equals(service)) {
|
||||||
return (T) new ArduinoRemoteConnection(remoteConnection);
|
synchronized (connectionMap) {
|
||||||
|
ArduinoRemoteConnection connection = connectionMap.get(remoteConnection);
|
||||||
|
if (connection == null) {
|
||||||
|
connection = new ArduinoRemoteConnection(remoteConnection);
|
||||||
|
connectionMap.put(remoteConnection, connection);
|
||||||
|
}
|
||||||
|
return (T) connection;
|
||||||
|
}
|
||||||
} else if (IRemoteConnectionPropertyService.class.equals(service)
|
} else if (IRemoteConnectionPropertyService.class.equals(service)
|
||||||
|| IRemoteCommandShellService.class.equals(service)) {
|
|| IRemoteCommandShellService.class.equals(service)) {
|
||||||
return (T) remoteConnection.getService(IArduinoRemoteConnection.class);
|
return (T) remoteConnection.getService(IArduinoRemoteConnection.class);
|
||||||
|
@ -78,7 +103,6 @@ public class ArduinoRemoteConnection implements IRemoteConnectionPropertyService
|
||||||
return remoteConnection.getAttribute(PORT_NAME);
|
return remoteConnection.getAttribute(PORT_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IRemoteProcess getCommandShell(int flags) throws IOException {
|
public IRemoteProcess getCommandShell(int flags) throws IOException {
|
||||||
if (serialPort != null && serialPort.isOpen()) {
|
if (serialPort != null && serialPort.isOpen()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue