1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-05 15:25:49 +02:00

bug 225853: [terminal][api][breaking] Abstract base class TerminalConnectorImpl should provide more default functionality

https://bugs.eclipse.org/bugs/show_bug.cgi?id=225853

Applied patch by Martin Oberhuber
This commit is contained in:
Michael Scharf 2008-04-05 00:24:14 +00:00
parent 440d7fea44
commit 48ef25f7c3
7 changed files with 128 additions and 112 deletions

View file

@ -15,6 +15,7 @@
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Martin Oberhuber (Wind River) - fixed copyright headers and beautified
* Martin Oberhuber (Wind River) - [206892] Don't connect if already connecting * Martin Oberhuber (Wind River) - [206892] Don't connect if already connecting
* Martin Oberhuber (Wind River) - [208029] COM port not released after quick disconnect/reconnect * Martin Oberhuber (Wind River) - [208029] COM port not released after quick disconnect/reconnect
* Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.serial; package org.eclipse.tm.internal.terminal.serial;
@ -38,7 +39,6 @@ import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnect
public class SerialConnector extends TerminalConnectorImpl { public class SerialConnector extends TerminalConnectorImpl {
private OutputStream fOutputStream; private OutputStream fOutputStream;
private InputStream fInputStream; private InputStream fInputStream;
private ITerminalControl fControl;
private SerialPort fSerialPort; private SerialPort fSerialPort;
private CommPortIdentifier fSerialPortIdentifier; private CommPortIdentifier fSerialPortIdentifier;
private SerialPortHandler fTerminalSerialPortHandler; private SerialPortHandler fTerminalSerialPortHandler;
@ -60,7 +60,7 @@ public class SerialConnector extends TerminalConnectorImpl {
} }
} }
public void connect(ITerminalControl control) { public void connect(ITerminalControl control) {
Logger.log("entered."); //$NON-NLS-1$ super.connect(control);
synchronized(this) { synchronized(this) {
if (fConnectWorker!=null || fDisconnectGoingOn) { if (fConnectWorker!=null || fDisconnectGoingOn) {
//avoid multiple background connect/disconnect threads at the same time //avoid multiple background connect/disconnect threads at the same time
@ -68,7 +68,6 @@ public class SerialConnector extends TerminalConnectorImpl {
} }
fConnectWorker = new SerialConnectWorker(this, control); fConnectWorker = new SerialConnectWorker(this, control);
} }
fControl=control;
fControl.setState(TerminalState.CONNECTING); fControl.setState(TerminalState.CONNECTING);
fConnectWorker.start(); fConnectWorker.start();
} }
@ -80,8 +79,7 @@ public class SerialConnector extends TerminalConnectorImpl {
fConnectWorker = null; fConnectWorker = null;
} }
} }
public void disconnect() { public void doDisconnect() {
Logger.log("entered."); //$NON-NLS-1$
synchronized(this) { synchronized(this) {
//avoid multiple background connect/disconnect threads at the same time //avoid multiple background connect/disconnect threads at the same time
if (fConnectWorker!=null) { if (fConnectWorker!=null) {
@ -140,9 +138,9 @@ public class SerialConnector extends TerminalConnectorImpl {
} }
} }
if (getOutputStream() != null) { if (getTerminalToRemoteStream() != null) {
try { try {
getOutputStream().close(); getTerminalToRemoteStream().close();
} catch (Exception exception) { } catch (Exception exception) {
Logger.logException(exception); Logger.logException(exception);
} }
@ -159,12 +157,11 @@ public class SerialConnector extends TerminalConnectorImpl {
} }
}.start(); }.start();
fControl.setState(TerminalState.CLOSED);
} }
public InputStream getInputStream() { public InputStream getInputStream() {
return fInputStream; return fInputStream;
} }
public OutputStream getOutputStream() { public OutputStream getTerminalToRemoteStream() {
return fOutputStream; return fOutputStream;
} }
private void setInputStream(InputStream inputStream) { private void setInputStream(InputStream inputStream) {
@ -173,13 +170,9 @@ public class SerialConnector extends TerminalConnectorImpl {
private void setOutputStream(OutputStream outputStream) { private void setOutputStream(OutputStream outputStream) {
fOutputStream = outputStream; fOutputStream = outputStream;
} }
public boolean isLocalEcho() {
return false;
}
public void setTerminalSize(int newWidth, int newHeight) { public void setTerminalSize(int newWidth, int newHeight) {
// TODO // TODO
} }
protected SerialPort getSerialPort() { protected SerialPort getSerialPort() {
return fSerialPort; return fSerialPort;
} }

View file

@ -9,6 +9,7 @@
* Michael Scharf (Wind River) - initial API and implementation * Michael Scharf (Wind River) - initial API and implementation
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Martin Oberhuber (Wind River) - fixed copyright headers and beautified
* Martin Oberhuber (Wind River) - [225792] Rename SshConnector.getTelnetSettings() to getSshSettings() * Martin Oberhuber (Wind River) - [225792] Rename SshConnector.getTelnetSettings() to getSshSettings()
* Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.ssh; package org.eclipse.tm.internal.terminal.ssh;
@ -19,7 +20,6 @@ import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage;
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl; import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
import org.eclipse.tm.internal.terminal.provisional.api.Logger; import org.eclipse.tm.internal.terminal.provisional.api.Logger;
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl; import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnectorImpl;
import com.jcraft.jsch.ChannelShell; import com.jcraft.jsch.ChannelShell;
@ -28,7 +28,6 @@ import com.jcraft.jsch.JSch;
public class SshConnector extends TerminalConnectorImpl { public class SshConnector extends TerminalConnectorImpl {
private OutputStream fOutputStream; private OutputStream fOutputStream;
private InputStream fInputStream; private InputStream fInputStream;
private ITerminalControl fControl;
private JSch fJsch; private JSch fJsch;
private ChannelShell fChannel; private ChannelShell fChannel;
private SshConnection fConnection; private SshConnection fConnection;
@ -45,13 +44,11 @@ public class SshConnector extends TerminalConnectorImpl {
fJsch=new JSch(); fJsch=new JSch();
} }
public void connect(ITerminalControl control) { public void connect(ITerminalControl control) {
Logger.log("entered."); //$NON-NLS-1$ super.connect(control);
fControl=control;
fConnection = new SshConnection(this,control); fConnection = new SshConnection(this,control);
fConnection.start(); fConnection.start();
} }
synchronized public void disconnect() { synchronized public void doDisconnect() {
Logger.log("entered."); //$NON-NLS-1$
fConnection.disconnect(); fConnection.disconnect();
if (getInputStream() != null) { if (getInputStream() != null) {
try { try {
@ -61,17 +58,13 @@ public class SshConnector extends TerminalConnectorImpl {
} }
} }
if (getOutputStream() != null) { if (getTerminalToRemoteStream() != null) {
try { try {
getOutputStream().close(); getTerminalToRemoteStream().close();
} catch (Exception exception) { } catch (Exception exception) {
Logger.logException(exception); Logger.logException(exception);
} }
} }
setState(TerminalState.CLOSED);
}
public boolean isLocalEcho() {
return false;
} }
public void setTerminalSize(int newWidth, int newHeight) { public void setTerminalSize(int newWidth, int newHeight) {
if(fChannel!=null && (newWidth!=fWidth || newHeight!=fHeight)) { if(fChannel!=null && (newWidth!=fWidth || newHeight!=fHeight)) {
@ -84,7 +77,7 @@ public class SshConnector extends TerminalConnectorImpl {
public InputStream getInputStream() { public InputStream getInputStream() {
return fInputStream; return fInputStream;
} }
public OutputStream getOutputStream() { public OutputStream getTerminalToRemoteStream() {
return fOutputStream; return fOutputStream;
} }
void setInputStream(InputStream inputStream) { void setInputStream(InputStream inputStream) {
@ -93,10 +86,6 @@ public class SshConnector extends TerminalConnectorImpl {
void setOutputStream(OutputStream outputStream) { void setOutputStream(OutputStream outputStream) {
fOutputStream = outputStream; fOutputStream = outputStream;
} }
public void setState(TerminalState state) {
fControl.setState(state);
}
/** /**
* Return the SSH Settings. * Return the SSH Settings.
* *
@ -114,7 +103,6 @@ public class SshConnector extends TerminalConnectorImpl {
} }
public void load(ISettingsStore store) { public void load(ISettingsStore store) {
fSettings.load(store); fSettings.load(store);
} }
public void save(ISettingsStore store) { public void save(ISettingsStore store) {
fSettings.save(store); fSettings.save(store);

View file

@ -11,8 +11,9 @@
* Helmut Haigermoser and Ted Williams. * Helmut Haigermoser and Ted Williams.
* *
* Contributors: * Contributors:
* Michael Scharf (Wind River) - extracted from TerminalControl * Michael Scharf (Wind River) - extracted from TerminalControl
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified * Martin Oberhuber (Wind River) - fixed copyright headers and beautified
* Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.telnet; package org.eclipse.tm.internal.terminal.telnet;
@ -44,19 +45,14 @@ public class TelnetConnector extends TerminalConnectorImpl {
public TelnetConnector(TelnetSettings settings) { public TelnetConnector(TelnetSettings settings) {
fSettings=settings; fSettings=settings;
} }
public void initialize() throws Exception {
}
public void connect(ITerminalControl control) { public void connect(ITerminalControl control) {
Logger.log("entered."); //$NON-NLS-1$ super.connect(control);
fControl=control;
fWidth=-1; fWidth=-1;
fHeight=-1; fHeight=-1;
TelnetConnectWorker worker = new TelnetConnectWorker(this,control); TelnetConnectWorker worker = new TelnetConnectWorker(this,control);
worker.start(); worker.start();
} }
public void disconnect() { public void doDisconnect() {
Logger.log("entered."); //$NON-NLS-1$
if (getSocket() != null) { if (getSocket() != null) {
try { try {
getSocket().close(); getSocket().close();
@ -64,7 +60,7 @@ public class TelnetConnector extends TerminalConnectorImpl {
Logger.logException(exception); Logger.logException(exception);
} }
} }
if (getInputStream() != null) { if (getInputStream() != null) {
try { try {
getInputStream().close(); getInputStream().close();
@ -72,16 +68,15 @@ public class TelnetConnector extends TerminalConnectorImpl {
Logger.logException(exception); Logger.logException(exception);
} }
} }
if (getOutputStream() != null) { if (getTerminalToRemoteStream() != null) {
try { try {
getOutputStream().close(); getTerminalToRemoteStream().close();
} catch (Exception exception) { } catch (Exception exception) {
Logger.logException(exception); Logger.logException(exception);
} }
} }
cleanSocket(); cleanSocket();
setState(TerminalState.CLOSED);
} }
public boolean isLocalEcho() { public boolean isLocalEcho() {
if(fTelnetConnection!=null) if(fTelnetConnection!=null)
@ -99,7 +94,7 @@ public class TelnetConnector extends TerminalConnectorImpl {
public InputStream getInputStream() { public InputStream getInputStream() {
return fInputStream; return fInputStream;
} }
public OutputStream getOutputStream() { public OutputStream getTerminalToRemoteStream() {
return fOutputStream; return fOutputStream;
} }
private void setInputStream(InputStream inputStream) { private void setInputStream(InputStream inputStream) {
@ -111,7 +106,7 @@ public class TelnetConnector extends TerminalConnectorImpl {
Socket getSocket() { Socket getSocket() {
return fSocket; return fSocket;
} }
/** /**
* sets the socket to null * sets the socket to null
*/ */
@ -120,7 +115,7 @@ public class TelnetConnector extends TerminalConnectorImpl {
setInputStream(null); setInputStream(null);
setOutputStream(null); setOutputStream(null);
} }
void setSocket(Socket socket) throws IOException { void setSocket(Socket socket) throws IOException {
if(socket==null) { if(socket==null) {
cleanSocket(); cleanSocket();
@ -132,18 +127,16 @@ public class TelnetConnector extends TerminalConnectorImpl {
} }
public void setTelnetConnection(TelnetConnection connection) { public void setTelnetConnection(TelnetConnection connection) {
fTelnetConnection=connection; fTelnetConnection=connection;
} }
public void displayTextInTerminal(String text) { public void displayTextInTerminal(String text) {
fControl.displayTextInTerminal(text); fControl.displayTextInTerminal(text);
} }
public OutputStream getRemoteToTerminalOutputStream () { public OutputStream getRemoteToTerminalOutputStream () {
return fControl.getRemoteToTerminalOutputStream(); return fControl.getRemoteToTerminalOutputStream();
} }
public void setState(TerminalState state) { public void setState(TerminalState state) {
fControl.setState(state); fControl.setState(state);
} }
public ITelnetSettings getTelnetSettings() { public ITelnetSettings getTelnetSettings() {
return fSettings; return fSettings;
@ -156,7 +149,6 @@ public class TelnetConnector extends TerminalConnectorImpl {
} }
public void load(ISettingsStore store) { public void load(ISettingsStore store) {
fSettings.load(store); fSettings.load(store);
} }
public void save(ISettingsStore store) { public void save(ISettingsStore store) {
fSettings.save(store); fSettings.save(store);

View file

@ -1,12 +1,13 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Michael Scharf (Wind River) - initial API and implementation * Michael Scharf (Wind River) - initial API and implementation
* Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.connector; package org.eclipse.tm.internal.terminal.connector;
@ -36,7 +37,7 @@ public class TerminalConnectorTest extends TestCase {
public void put(String key, String value) { public void put(String key, String value) {
} }
} }
public static class TerminalControlMock implements ITerminalControl { public static class TerminalControlMock implements ITerminalControl {
@ -83,13 +84,14 @@ public class TerminalConnectorTest extends TestCase {
fHeight=newHeight; fHeight=newHeight;
} }
public void connect(ITerminalControl control) { public void connect(ITerminalControl control) {
fControl=control; super.connect(control);
fControl = control;
} }
public void disconnect() { public void doDisconnect() {
fDisconnect=true; fDisconnect=true;
} }
public OutputStream getOutputStream() { public OutputStream getTerminalToRemoteStream() {
return null; return null;
} }
@ -126,7 +128,7 @@ public class TerminalConnectorTest extends TestCase {
public TerminalConnectorImpl makeConnector() throws Exception { public TerminalConnectorImpl makeConnector() throws Exception {
// TODO Auto-generated method stub // TODO Auto-generated method stub
return fConnector; return fConnector;
} }
} }
public void testGetInitializationErrorMessage() { public void testGetInitializationErrorMessage() {
TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName"); TerminalConnector c=new TerminalConnector(new SimpleFactory(new ConnectorMock()),"xID","xName");
@ -139,7 +141,7 @@ public class TerminalConnectorTest extends TestCase {
}}),"xID","xName"); }}),"xID","xName");
c.connect(new TerminalControlMock()); c.connect(new TerminalControlMock());
assertEquals("FAILED",c.getInitializationErrorMessage()); assertEquals("FAILED",c.getInitializationErrorMessage());
} }
public void testGetIdAndName() { public void testGetIdAndName() {
@ -172,7 +174,7 @@ public class TerminalConnectorTest extends TestCase {
assertFalse(c.isInitialized()); assertFalse(c.isInitialized());
c.connect(new TerminalControlMock()); c.connect(new TerminalControlMock());
assertTrue(c.isInitialized()); assertTrue(c.isInitialized());
} }
public void testDisconnect() { public void testDisconnect() {
@ -226,7 +228,7 @@ public class TerminalConnectorTest extends TestCase {
assertNull(mock.fSaveStore); assertNull(mock.fSaveStore);
c.connect(new TerminalControlMock()); c.connect(new TerminalControlMock());
c.save(s); c.save(s);
assertSame(s,mock.fSaveStore); assertSame(s,mock.fSaveStore);
} }
public void testMakeSettingsPage() { public void testMakeSettingsPage() {
@ -239,7 +241,7 @@ public class TerminalConnectorTest extends TestCase {
ConnectorMock mock=new ConnectorMock(); ConnectorMock mock=new ConnectorMock();
TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName"); TerminalConnector c=new TerminalConnector(new SimpleFactory(mock),"xID","xName");
c.setTerminalSize(100, 200); c.setTerminalSize(100, 200);
} }
public void testGetAdapter() { public void testGetAdapter() {

View file

@ -1,12 +1,13 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* Michael Scharf (Wind River) - initial API and implementation * Michael Scharf (Wind River) - initial API and implementation
* Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.speedtest; package org.eclipse.tm.internal.terminal.speedtest;
@ -27,12 +28,11 @@ public class SpeedTestConnector extends TerminalConnectorImpl {
final SpeedTestSettings fSettings=new SpeedTestSettings(); final SpeedTestSettings fSettings=new SpeedTestSettings();
InputStream fInputStream; InputStream fInputStream;
OutputStream fOutputStream; OutputStream fOutputStream;
ITerminalControl fControl;
SpeedTestConnection fConnection; SpeedTestConnection fConnection;
public SpeedTestConnector() { public SpeedTestConnector() {
} }
synchronized public void connect(ITerminalControl control) { synchronized public void connect(ITerminalControl control) {
fControl=control; super.connect(control);
fControl.setState(TerminalState.CONNECTING); fControl.setState(TerminalState.CONNECTING);
String file=fSettings.getInputFile(); String file=fSettings.getInputFile();
try { try {
@ -48,7 +48,7 @@ public class SpeedTestConnector extends TerminalConnectorImpl {
fConnection.start(); fConnection.start();
} }
synchronized public void disconnect() { synchronized public void doDisconnect() {
if(fConnection!=null){ if(fConnection!=null){
fConnection.interrupt(); fConnection.interrupt();
fConnection=null; fConnection=null;
@ -69,13 +69,12 @@ public class SpeedTestConnector extends TerminalConnectorImpl {
} }
} }
fOutputStream=null; fOutputStream=null;
fControl.setState(TerminalState.CLOSED);
} }
synchronized public InputStream getInputStream() { synchronized public InputStream getInputStream() {
return fInputStream; return fInputStream;
} }
synchronized public OutputStream getOutputStream() { synchronized public OutputStream getTerminalToRemoteStream() {
return fOutputStream; return fOutputStream;
} }
@ -87,13 +86,8 @@ public class SpeedTestConnector extends TerminalConnectorImpl {
//throw new RuntimeException("XXX problems\nSpeedTest\nXXX!"); //throw new RuntimeException("XXX problems\nSpeedTest\nXXX!");
} }
public boolean isLocalEcho() {
return false;
}
public void load(ISettingsStore store) { public void load(ISettingsStore store) {
fSettings.load(store); fSettings.load(store);
} }
public ISettingsPage makeSettingsPage() { public ISettingsPage makeSettingsPage() {
@ -102,7 +96,6 @@ public class SpeedTestConnector extends TerminalConnectorImpl {
public void save(ISettingsStore store) { public void save(ISettingsStore store) {
fSettings.save(store); fSettings.save(store);
} }
public void setTerminalSize(int newWidth, int newHeight) { public void setTerminalSize(int newWidth, int newHeight) {

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* Michael Scharf (Wind River) - initial API and implementation * Michael Scharf (Wind River) - initial API and implementation
* Michael Scharf (Wind River) - [200541] Extract from TerminalConnectorExtension.TerminalConnectorProxy * Michael Scharf (Wind River) - [200541] Extract from TerminalConnectorExtension.TerminalConnectorProxy
* Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.connector; package org.eclipse.tm.internal.terminal.connector;
@ -123,23 +124,15 @@ public class TerminalConnector implements ITerminalConnector {
fException=e; fException=e;
fConnector=new TerminalConnectorImpl(){ fConnector=new TerminalConnectorImpl(){
public void connect(ITerminalControl control) { public void connect(ITerminalControl control) {
// super.connect(control);
control.setState(TerminalState.CLOSED); control.setState(TerminalState.CLOSED);
control.setMsg(getInitializationErrorMessage()); control.setMsg(getInitializationErrorMessage());
} }
public void disconnect() { public OutputStream getTerminalToRemoteStream() {
}
public OutputStream getOutputStream() {
return null; return null;
} }
public String getSettingsSummary() { public String getSettingsSummary() {
return null; return null;
}
public void load(ISettingsStore store) {
}
public ISettingsPage makeSettingsPage() {
return null;
}
public void save(ISettingsStore store) {
}}; }};
// that's the place where we log the exception // that's the place where we log the exception
Logger.logException(e); Logger.logException(e);
@ -160,7 +153,7 @@ public class TerminalConnector implements ITerminalConnector {
getConnectorImpl().disconnect(); getConnectorImpl().disconnect();
} }
public OutputStream getTerminalToRemoteStream() { public OutputStream getTerminalToRemoteStream() {
return getConnectorImpl().getOutputStream(); return getConnectorImpl().getTerminalToRemoteStream();
} }
public String getSettingsSummary() { public String getSettingsSummary() {
if(fConnector!=null) if(fConnector!=null)

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Michael Scharf (Wind River) - initial API and implementation * Michael Scharf (Wind River) - initial API and implementation
* Martin Oberhuber (Wind River) - [225853][api] Provide more default functionality in TerminalConnectorImpl
*******************************************************************************/ *******************************************************************************/
package org.eclipse.tm.internal.terminal.provisional.api.provider; package org.eclipse.tm.internal.terminal.provisional.api.provider;
@ -15,6 +16,8 @@ import java.io.OutputStream;
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage; import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage;
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore; import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl; import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
import org.eclipse.tm.internal.terminal.provisional.api.Logger;
import org.eclipse.tm.internal.terminal.provisional.api.TerminalState;
/** /**
* Abstract base class for all terminal connector implementations to be * Abstract base class for all terminal connector implementations to be
@ -25,6 +28,12 @@ import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
*/ */
public abstract class TerminalConnectorImpl { public abstract class TerminalConnectorImpl {
/**
* The TerminalControl associated with this connector.
* Required for advertising state changes when needed.
*/
protected ITerminalControl fControl;
/** /**
* Initialize this connector. This is called once after the constructor, in * Initialize this connector. This is called once after the constructor, in
* order to perform any required initializations such as loading required * order to perform any required initializations such as loading required
@ -39,22 +48,44 @@ public abstract class TerminalConnectorImpl {
/** /**
* Connect using the current state of the settings. * Connect using the current state of the settings.
* @param control Used to inform the UI about state changes and messages from the connection. *
* This method is designed to be overridden by actual implementations, in
* order to open the streams required for communicating with the remote
* side. Extenders must call <code>super.connect(control)</code> as the
* first thing they are doing.
*
* @param control Used to inform the UI about state changes and messages
* from the connection.
*/ */
abstract public void connect(ITerminalControl control); public void connect(ITerminalControl control) {
Logger.log("entered."); //$NON-NLS-1$
fControl = control;
}
/** /**
* Disconnect if connected. Else do nothing. * Disconnect if connected. Else do nothing. Has to set the state of the
* Has to set the state of the {@link ITerminalControl} * {@link ITerminalControl} when finished disconnecting.
*/ */
abstract public void disconnect(); public final void disconnect() {
Logger.log("entered."); //$NON-NLS-1$
doDisconnect();
fControl.setState(TerminalState.CLOSED);
}
/**
* Disconnect if connected. Else do nothing. Clients should override to
* perform any extra work needed for disconnecting.
*/
protected void doDisconnect() {
// Do nothing by default
}
/** /**
* @return the terminal to remote stream (bytes written to this stream will * @return the terminal to remote stream (bytes written to this stream will
* be sent to the remote site). For the stream in the other direction (remote to * be sent to the remote site). For the stream in the other direction (remote to
* terminal see {@link ITerminalControl#getRemoteToTerminalOutputStream()} * terminal see {@link ITerminalControl#getRemoteToTerminalOutputStream()}
*/ */
abstract public OutputStream getOutputStream(); abstract public OutputStream getTerminalToRemoteStream();
/** /**
* @return A string that represents the settings of the connection. This representation * @return A string that represents the settings of the connection. This representation
@ -63,41 +94,65 @@ public abstract class TerminalConnectorImpl {
abstract public String getSettingsSummary(); abstract public String getSettingsSummary();
/** /**
* @return true if a local echo is needed. * Test if local echo is needed. The default implementation returns
* TODO:Michael Scharf: this should be handed within the connection.... * <code>false</code>. Override to modify this behavior.
*
* @return true if a local echo is needed. TODO:Michael Scharf: this should
* be handed within the connection....
*/ */
public boolean isLocalEcho() { public boolean isLocalEcho() {
return false; return false;
} }
/** /**
* @return a new page that can be used in a dialog to setup this connection. * Return a settings page for configuring this connector, or
* The dialog should persist its settings with the {@link #load(ISettingsStore)} * <code>null</code> if it cannot be configured.
* and {@link #save(ISettingsStore)} methods.
* *
* The dialog should persist its settings with the
* {@link #load(ISettingsStore)} and {@link #save(ISettingsStore)} methods.
*
* @return a new page that can be used in a dialog to setup this connection,
* or <code>null</code>.
*/ */
abstract public ISettingsPage makeSettingsPage(); public ISettingsPage makeSettingsPage() {
return null;
}
/** /**
* Load the state of this connection. Is typically called before * Load the state or settings of this connection. Is typically called before
* {@link #connect(ITerminalControl)}. * {@link #connect(ITerminalControl)}.
* *
* @param store a string based data store. Short keys like "foo" can be used to * Connectors that have nothing to configure do not need to implement this.
* store the state of the connection. * Those terminals that do have configuration (which they expose via
* {@link #makeSettingsPage()} need to override this method to load
* settings.
*
* @param store a string based data store. Short keys like "foo" can be used
* to store the state of the connection.
*/ */
abstract public void load(ISettingsStore store); public void load(ISettingsStore store) {
// do nothing by default
}
/** /**
* When the view or dialog containing the terminal is closed, the state of * When the view or dialog containing the terminal is closed, the state of
* the connection is saved into the settings store <code>store</code> * the connection is saved into the settings store <code>store</code>.
*
* Connectors that have no state or settings to persist do not need to
* override this. Others should override to persist their settings.
* *
* @param store the store for persisting settings. * @param store the store for persisting settings.
*/ */
abstract public void save(ISettingsStore store); public void save(ISettingsStore store) {
// do nothing by default
}
/** /**
* Notify the remote site that the size of the terminal has changed. * Notify the remote site that the size of the terminal has changed.
* *
* Concrete connectors should override this if they have the possibility to
* inform the remote about changed terminal size.
*
* @param newWidth the new width in characters. * @param newWidth the new width in characters.
* @param newHeight the new height in characters. * @param newHeight the new height in characters.
*/ */