1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +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) - [206892] Don't connect if already connecting
* 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;
@ -38,7 +39,6 @@ import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnect
public class SerialConnector extends TerminalConnectorImpl {
private OutputStream fOutputStream;
private InputStream fInputStream;
private ITerminalControl fControl;
private SerialPort fSerialPort;
private CommPortIdentifier fSerialPortIdentifier;
private SerialPortHandler fTerminalSerialPortHandler;
@ -60,7 +60,7 @@ public class SerialConnector extends TerminalConnectorImpl {
}
}
public void connect(ITerminalControl control) {
Logger.log("entered."); //$NON-NLS-1$
super.connect(control);
synchronized(this) {
if (fConnectWorker!=null || fDisconnectGoingOn) {
//avoid multiple background connect/disconnect threads at the same time
@ -68,7 +68,6 @@ public class SerialConnector extends TerminalConnectorImpl {
}
fConnectWorker = new SerialConnectWorker(this, control);
}
fControl=control;
fControl.setState(TerminalState.CONNECTING);
fConnectWorker.start();
}
@ -80,8 +79,7 @@ public class SerialConnector extends TerminalConnectorImpl {
fConnectWorker = null;
}
}
public void disconnect() {
Logger.log("entered."); //$NON-NLS-1$
public void doDisconnect() {
synchronized(this) {
//avoid multiple background connect/disconnect threads at the same time
if (fConnectWorker!=null) {
@ -140,9 +138,9 @@ public class SerialConnector extends TerminalConnectorImpl {
}
}
if (getOutputStream() != null) {
if (getTerminalToRemoteStream() != null) {
try {
getOutputStream().close();
getTerminalToRemoteStream().close();
} catch (Exception exception) {
Logger.logException(exception);
}
@ -159,12 +157,11 @@ public class SerialConnector extends TerminalConnectorImpl {
}
}.start();
fControl.setState(TerminalState.CLOSED);
}
public InputStream getInputStream() {
return fInputStream;
}
public OutputStream getOutputStream() {
public OutputStream getTerminalToRemoteStream() {
return fOutputStream;
}
private void setInputStream(InputStream inputStream) {
@ -173,13 +170,9 @@ public class SerialConnector extends TerminalConnectorImpl {
private void setOutputStream(OutputStream outputStream) {
fOutputStream = outputStream;
}
public boolean isLocalEcho() {
return false;
}
public void setTerminalSize(int newWidth, int newHeight) {
// TODO
}
protected SerialPort getSerialPort() {
return fSerialPort;
}

View file

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

View file

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

View file

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

View file

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

View file

@ -8,6 +8,7 @@
* Contributors:
* Michael Scharf (Wind River) - initial API and implementation
* 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;
@ -123,23 +124,15 @@ public class TerminalConnector implements ITerminalConnector {
fException=e;
fConnector=new TerminalConnectorImpl(){
public void connect(ITerminalControl control) {
// super.connect(control);
control.setState(TerminalState.CLOSED);
control.setMsg(getInitializationErrorMessage());
}
public void disconnect() {
}
public OutputStream getOutputStream() {
public OutputStream getTerminalToRemoteStream() {
return null;
}
public String getSettingsSummary() {
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
Logger.logException(e);
@ -160,7 +153,7 @@ public class TerminalConnector implements ITerminalConnector {
getConnectorImpl().disconnect();
}
public OutputStream getTerminalToRemoteStream() {
return getConnectorImpl().getOutputStream();
return getConnectorImpl().getTerminalToRemoteStream();
}
public String getSettingsSummary() {
if(fConnector!=null)

View file

@ -7,6 +7,7 @@
*
* Contributors:
* 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;
@ -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.ISettingsStore;
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
@ -25,6 +28,12 @@ import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
*/
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
* 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.
* @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.
* Has to set the state of the {@link ITerminalControl}
* Disconnect if connected. Else do nothing. Has to set the state of the
* {@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
* be sent to the remote site). For the stream in the other direction (remote to
* 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
@ -63,41 +94,65 @@ public abstract class TerminalConnectorImpl {
abstract public String getSettingsSummary();
/**
* @return true if a local echo is needed.
* TODO:Michael Scharf: this should be handed within the connection....
* Test if local echo is needed. The default implementation returns
* <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() {
return false;
}
/**
* @return a new page that can be used in a dialog to setup this connection.
* The dialog should persist its settings with the {@link #load(ISettingsStore)}
* and {@link #save(ISettingsStore)} methods.
* Return a settings page for configuring this connector, or
* <code>null</code> if it cannot be configured.
*
* 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)}.
*
* @param store a string based data store. Short keys like "foo" can be used to
* store the state of the connection.
* Connectors that have nothing to configure do not need to implement this.
* 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
* 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.
*/
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.
*
* 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 newHeight the new height in characters.
*/