diff options
Diffstat (limited to 'plugins/org.eclipse.tcf.rse')
8 files changed, 228 insertions, 300 deletions
diff --git a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/ITCFSessionProvider.java b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/ITCFSessionProvider.java index 871ac84d2..d115a1897 100644 --- a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/ITCFSessionProvider.java +++ b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/ITCFSessionProvider.java @@ -11,7 +11,6 @@ package org.eclipse.tcf.internal.rse; -import org.eclipse.rse.services.files.RemoteFileException; import org.eclipse.tcf.protocol.IChannel; public interface ITCFSessionProvider { @@ -24,6 +23,7 @@ public interface ITCFSessionProvider { public String getSessionUserId(); public String getSessionPassword(); public String getSessionHostName(); - public boolean isSubscribed(); - public void subscribe() throws RemoteFileException; + public void onStreamsConnecting(); + public void onStreamsID(String id); + public void onStreamsConnected(); } diff --git a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/TCFConnectorService.java b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/TCFConnectorService.java index c2ef862b5..499c1c033 100644 --- a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/TCFConnectorService.java +++ b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/TCFConnectorService.java @@ -15,9 +15,9 @@ *******************************************************************************/ package org.eclipse.tcf.internal.rse; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; @@ -29,7 +29,7 @@ import org.eclipse.rse.core.model.SystemSignonInformation; import org.eclipse.rse.core.subsystems.CommunicationsEvent; import org.eclipse.rse.services.files.RemoteFileException; import org.eclipse.rse.ui.subsystems.StandardConnectorService; -import org.eclipse.tcf.core.AbstractPeer; +import org.eclipse.tcf.core.TransientPeer; import org.eclipse.tcf.protocol.IChannel; import org.eclipse.tcf.protocol.IPeer; import org.eclipse.tcf.protocol.IService; @@ -40,7 +40,6 @@ import org.eclipse.tcf.services.ILocator; import org.eclipse.tcf.services.IStreams; import org.eclipse.tcf.services.ISysMonitor; import org.eclipse.tcf.services.ITerminals; -import org.eclipse.tcf.util.TCFTask; public class TCFConnectorService extends StandardConnectorService implements ITCFSessionProvider{ @@ -59,30 +58,33 @@ public class TCFConnectorService extends StandardConnectorService implements ITC private boolean poll_timer_started; - private boolean bSubscribed = false; + private boolean streams_subscribed = false; + private boolean streams_connecting = false; + private final HashSet<String> stream_ids = new HashSet<String>(); /* subscribe the stream service on this TCP connection */ - private IStreams.StreamsListener streamListener = new IStreams.StreamsListener() { - public void created(String stream_type, String stream_id, - String context_id) { + private final IStreams.StreamsListener streams_listener = new IStreams.StreamsListener() { + public void created(String stream_type, String stream_id, String context_id) { + if (streams_connecting) { + stream_ids.add(stream_id); + } + else { + getService(IStreams.class).disconnect(stream_id, new IStreams.DoneDisconnect() { + public void doneDisconnect(IToken token, Exception error) { + if (error != null) channel.terminate(error); + } + }); + } } - /** - * Called when a stream is disposed. - * - * @param stream_type - * - source type of the stream. - * @param stream_id - * - ID of the stream. - */ + public void disposed(String stream_type, String stream_id) { + stream_ids.remove(stream_id); } }; public TCFConnectorService(IHost host, int port) { - super(Messages.TCFConnectorService_Name, - Messages.TCFConnectorService_Description, host, - port); + super(Messages.TCFConnectorService_Name, Messages.TCFConnectorService_Description, host, port); getTCFPropertySet(); } @@ -104,7 +106,6 @@ public class TCFConnectorService extends StandardConnectorService implements ITC /** * @return true if the associated connector service requires a password. */ - public final boolean requiresPassword() { return false; } @@ -119,8 +120,17 @@ public class TCFConnectorService extends StandardConnectorService implements ITC synchronized (res) { Protocol.invokeLater(new Runnable() { public void run() { - if (!connectTCFChannel(res, monitor)) - add_to_wait_list(this); + try { + if (!connectTCFChannel(res, monitor)) + add_to_wait_list(this); + } + catch (Throwable x) { + synchronized (res) { + if (x instanceof Exception) res[0] = (Exception)x; + else res[0] = new Exception(x); + res.notify(); + } + } } }); res.wait(); @@ -130,16 +140,13 @@ public class TCFConnectorService extends StandardConnectorService implements ITC } @Override - protected void internalDisconnect(final IProgressMonitor monitor) - throws Exception { + protected void internalDisconnect(final IProgressMonitor monitor) throws Exception { assert !Protocol.isDispatchThread(); final Exception[] res = new Exception[1]; // Fire comm event to signal state about to change fireCommunicationsEvent(CommunicationsEvent.BEFORE_DISCONNECT); monitor.beginTask("Disconnecting " + getHostName(), 1); //$NON-NLS-1$ try { - /* First UnSubscribe TCP channel */ - unsubscribe(); /* Disconnecting TCP channel */ synchronized (res) { Protocol.invokeLater(new Runnable() { @@ -240,7 +247,7 @@ public class TCFConnectorService extends StandardConnectorService implements ITC attrs.put(IPeer.ATTR_TRANSPORT_NAME, transport); attrs.put(IPeer.ATTR_IP_HOST, host); attrs.put(IPeer.ATTR_IP_PORT, port_str); - peer = new AbstractPeer(attrs); + peer = new TransientPeer(attrs); } channel = peer.openChannel(); channel.addChannelListener(new IChannel.IChannelListener() { @@ -263,9 +270,10 @@ public class TCFConnectorService extends StandardConnectorService implements ITC else { run_wait_list(); } - bSubscribed = false; channel = null; channel_error = null; + streams_subscribed = false; + stream_ids.clear(); } }); @@ -332,61 +340,33 @@ public class TCFConnectorService extends StandardConnectorService implements ITC return password; } - public boolean isSubscribed() { - return bSubscribed; - } - - public void unsubscribe() throws IOException { - if (bSubscribed) { - new TCFTask<Object>() { - public void run() { - IStreams streams = getService(IStreams.class); - streams.unsubscribe(ITerminals.NAME, streamListener, - new IStreams.DoneUnsubscribe() { - public void doneUnsubscribe(IToken token, - Exception error) { - done(this); - } - }); - } - }.getIO(); - bSubscribed = false; + public void onStreamsConnecting() { + if (!streams_subscribed) { + streams_subscribed = true; + IStreams streams = getService(IStreams.class); + if (streams != null) { + streams.subscribe(ITerminals.NAME, streams_listener, new IStreams.DoneSubscribe() { + public void doneSubscribe(IToken token, Exception error) { + if (error != null) channel.terminate(error); + } + }); + } } - + streams_connecting = true; } - public void subscribe() throws RemoteFileException { - try { - new TCFTask<Object>() { - public void run() { - if (bSubscribed) { - done(this); - } - else { - bSubscribed = true; - IStreams streams = getService(IStreams.class); - streams.subscribe(ITerminals.NAME, streamListener, - new IStreams.DoneSubscribe() { - public void doneSubscribe(IToken token, - Exception error) { - if (error != null) { - bSubscribed = false; - error(error); - } - else - done(this); - } - - }); - }} - }.getIO(); + public void onStreamsID(String id) { + stream_ids.remove(id); + } + public void onStreamsConnected() { + streams_connecting = false; + for (String id : stream_ids) { + getService(IStreams.class).disconnect(id, new IStreams.DoneDisconnect() { + public void doneDisconnect(IToken token, Exception error) { + if (error != null) channel.terminate(error); + } + }); } - catch (Exception e) { - e.printStackTrace();//$NON-NLS-1$ - throw new RemoteFileException( - "Error When Subscribe Terminal streams!", e); //$NON-NLS-1$ - } - } } diff --git a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFServiceCommandShell.java b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFServiceCommandShell.java index b07429a60..afe05f922 100644 --- a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFServiceCommandShell.java +++ b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFServiceCommandShell.java @@ -202,5 +202,4 @@ public class TCFServiceCommandShell extends ServiceCommandShell { super.writeToShell(cmd); } - } diff --git a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFShellSubSystemConfiguration.java b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFShellSubSystemConfiguration.java index cf372e2df..d9301512b 100644 --- a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFShellSubSystemConfiguration.java +++ b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFShellSubSystemConfiguration.java @@ -32,8 +32,7 @@ import org.eclipse.tcf.internal.rse.*; import org.eclipse.tcf.internal.rse.terminals.TCFTerminalService; -public class TCFShellSubSystemConfiguration extends - ShellServiceSubSystemConfiguration { +public class TCFShellSubSystemConfiguration extends ShellServiceSubSystemConfiguration { public TCFShellSubSystemConfiguration() { super(); @@ -44,25 +43,22 @@ public class TCFShellSubSystemConfiguration extends * Do not populate it yet though! * @see org.eclipse.rse.core.subsystems.SubSystemConfiguration#createSubSystemInternal(IHost) */ - public ISubSystem createSubSystemInternal(IHost host) - { - TCFConnectorService connectorService = (TCFConnectorService)getConnectorService(host); - ISubSystem subsys = new ShellServiceSubSystem(host, connectorService, createShellService(host)); - return subsys; + public ISubSystem createSubSystemInternal(IHost host) { + TCFConnectorService connectorService = (TCFConnectorService)getConnectorService(host); + ISubSystem subsys = new ShellServiceSubSystem(host, connectorService, createShellService(host)); + return subsys; } public IConnectorService getConnectorService(IHost host) { return TCFConnectorServiceManager.getInstance().getConnectorService(host, getServiceImplType()); -} + } - public void setConnectorService(IHost host, - IConnectorService connectorService) { + public void setConnectorService(IHost host, IConnectorService connectorService) { TCFConnectorServiceManager.getInstance().setConnectorService(host, getServiceImplType(), connectorService); } - public Class<ITCFService> getServiceImplType() - { - return ITCFService.class; + public Class<ITCFService> getServiceImplType() { + return ITCFService.class; } public IServiceCommandShell createRemoteCommandShell(IRemoteCmdSubSystem cmdSS, IHostShell hostShell) { @@ -71,9 +67,6 @@ public class TCFShellSubSystemConfiguration extends public IShellService createShellService(IHost host) { TCFConnectorService cserv = (TCFConnectorService)getConnectorService(host); - return (IShellService) (new TCFTerminalService(cserv)).getAdapter(IShellService.class); } - - } diff --git a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalInputStream.java b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalInputStream.java index 30e3eca39..a38703cf3 100644 --- a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalInputStream.java +++ b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalInputStream.java @@ -18,15 +18,15 @@ import org.eclipse.tcf.services.IStreams; import org.eclipse.tcf.util.TCFTask; public class TCFTerminalInputStream extends InputStream { - private IStreams streams; - private boolean connected = true;;/* The stream is connected or not */ - String is_id; - private int value; + private final TCFTerminalShell terminal; + private final IStreams streams; + private final String is_id; + private boolean connected = true; /* The stream is connected or not */ private boolean bEof = false;; - public TCFTerminalInputStream(final IStreams streams, final String is_id) throws IOException{ - if (streams == null) - throw new IOException("TCP streams is null");//$NON-NLS-1$ + public TCFTerminalInputStream(TCFTerminalShell terminal, IStreams streams, String is_id) throws IOException{ + if (streams == null) throw new IOException("TCP streams is null");//$NON-NLS-1$ + this.terminal = terminal; this.streams = streams; this.is_id = is_id; } @@ -34,12 +34,10 @@ public class TCFTerminalInputStream extends InputStream { /* read must be synchronized */ @Override public synchronized int read() throws IOException { - if (!connected) - throw new IOException("istream is not connected");//$NON-NLS-1$ - if (bEof) - return -1; + if (!connected) throw new IOException("istream is not connected");//$NON-NLS-1$ + if (bEof) return -1; try { - new TCFTask<Object>() { + return new TCFTask<Integer>() { public void run() { streams.read(is_id, 1, new IStreams.DoneRead() { public void doneRead(IToken token, Exception error, int lostSize, @@ -50,45 +48,30 @@ public class TCFTerminalInputStream extends InputStream { } bEof = eos; if (data != null) { - value = (int)data[0]; + done(data[0] & 0xff); + } + else { + done(-1); } - else - value = -1; - done(this); } }); } }.getIO(); } - catch (Exception e) { - e.printStackTrace();//$NON-NLS-1$ - throw new IOException(e.getMessage());//$NON-NLS-1$ - } - return value; - } - - private static class Buffer { - byte[] buf; - Buffer() { + catch (IOException e) { + if (!connected) return -1; + throw e; } } - private Buffer buffer; public synchronized int read(byte b[], final int off, final int len) throws IOException { - - - if (!connected) - throw new IOException("istream is not connected");//$NON-NLS-1$ + if (!connected) throw new IOException("istream is not connected");//$NON-NLS-1$ if (bEof) return -1; - if (b == null) { - throw new NullPointerException(); - } else if (off < 0 || len < 0 || len > b.length - off) { - throw new IndexOutOfBoundsException(); - } else if (len == 0) { - return 0; - } + if (b == null) throw new NullPointerException(); + if (off < 0 || len < 0 || len > b.length - off) throw new IndexOutOfBoundsException(); + if (len == 0) return 0; try { - new TCFTask<Buffer>() { + byte[] data = new TCFTask<byte[]>() { public void run() { streams.read(is_id, len, new IStreams.DoneRead() { public void doneRead(IToken token, Exception error, int lostSize, @@ -98,43 +81,42 @@ public class TCFTerminalInputStream extends InputStream { return; } bEof = eos; - if (data != null) { - buffer = new Buffer(); - buffer.buf = data; - - } - done(buffer); + done(data); } }); } }.getIO(); - if (buffer.buf != null) { - int length = buffer.buf.length; - System.arraycopy(buffer.buf, 0, b, off, length); + if (data != null) { + int length = data.length; + System.arraycopy(data, 0, b, off, length); return length; } - else if (bEof) - return -1; - else return 0; - } catch (Exception ee) { - throw new IOException(ee.getMessage());//$NON-NLS-1$ + if (bEof) return -1; + return 0; + } + catch (IOException e) { + if (!connected) return -1; + throw e; } } public void close() throws IOException { if (!connected) return; + connected = false; new TCFTask<Object>() { public void run() { streams.disconnect(is_id, new IStreams.DoneDisconnect() { public void doneDisconnect(IToken token, Exception error) { - connected = false; + if (error != null) { + error(error); + return; + } + terminal.onInputStreamClosed(); done(this); } }); } }.getIO(); - connected = false; } - } diff --git a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalOutputStream.java b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalOutputStream.java index b6150090b..0680467f1 100644 --- a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalOutputStream.java +++ b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalOutputStream.java @@ -19,87 +19,66 @@ import org.eclipse.tcf.services.IStreams; import org.eclipse.tcf.util.TCFTask; public class TCFTerminalOutputStream extends OutputStream { - + private final TCFTerminalShell terminal; private final IStreams streams; + private final String os_id; private boolean connected = true; - private boolean write_eof; - String os_id; - public TCFTerminalOutputStream(final IStreams streams, final String os_id) throws IOException{ + public TCFTerminalOutputStream(TCFTerminalShell terminal, IStreams streams, String os_id) throws IOException{ if (streams == null) throw new IOException("istream is null");//$NON-NLS-1$ + this.terminal = terminal; this.streams = streams; this.os_id = os_id; - write_eof = false; } @Override public synchronized void write(final byte b[], final int off, final int len) throws IOException { /* If eof is written, we can't write anything into the stream */ - if (!connected || write_eof) - throw new IOException("stream is not connected or write_eof already!");//$NON-NLS-1$ - try { - new TCFTask<Object>() { - public void run() { - streams.write(os_id, b, off, len, new IStreams.DoneWrite() { - public void doneWrite(IToken token, Exception error) { - if (error != null) error(error); - done(this); - } - }); - - } - }.getIO(); - } - catch (Exception e) - { - throw new IOException(e.getMessage());//$NON-NLS-1$ - } + if (!connected) throw new IOException("stream is not connected!");//$NON-NLS-1$ + new TCFTask<Object>() { + public void run() { + streams.write(os_id, b, off, len, new IStreams.DoneWrite() { + public void doneWrite(IToken token, Exception error) { + if (error != null) error(error); + else done(this); + } + }); + } + }.getIO(); } @Override public synchronized void write(int b) throws IOException { - - try { - final byte[] buf = new byte[1]; - buf[0] = (byte)b; - this.write(buf, 0, 1); - } - catch(IOException ioe) { - throw new IOException(ioe.getMessage());//$NON-NLS-1$ - } - + byte[] buf = new byte[1]; + buf[0] = (byte)b; + write(buf, 0, 1); } /* close must be called --Need to reconsider it in the future*/ public void close() throws IOException { - if (!connected) - return; - try { - new TCFTask<Object>() { - public void run() { - streams.eos(os_id, new IStreams.DoneEOS() { - public void doneEOS(IToken token, Exception error) { - write_eof = true; - done(this); - } - }); - } - }.getIO(); - new TCFTask<Object>() { - public void run() { - streams.disconnect(os_id, new IStreams.DoneDisconnect() { - public void doneDisconnect(IToken token, Exception error) { - connected = false; - done(this); + if (!connected) return; + connected = false; + new TCFTask<Object>() { + public void run() { + streams.eos(os_id, new IStreams.DoneEOS() { + public void doneEOS(IToken token, Exception error) { + if (error != null) { + error(error); + return; } - }); - - } - }.getIO(); - } - catch(Exception e) { - throw new IOException(e.getMessage()); //$NON-NLS-1$ - } + streams.disconnect(os_id, new IStreams.DoneDisconnect() { + public void doneDisconnect(IToken token, Exception error) { + if (error != null) { + error(error); + return; + } + terminal.onOutputStreamClosed(); + done(this); + } + }); + } + }); + } + }.getIO(); } - } diff --git a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalShell.java b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalShell.java index ab9e5b151..039eaeef7 100644 --- a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalShell.java +++ b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/shells/TCFTerminalShell.java @@ -14,12 +14,13 @@ package org.eclipse.tcf.internal.rse.shells; import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; -import java.util.Map; import org.eclipse.core.runtime.IStatus; import org.eclipse.rse.core.model.IPropertySet; @@ -56,27 +57,26 @@ public class TCFTerminalShell extends AbstractTerminalShell { private String fContextID; private String in_id; private String out_id; - private boolean connected = false; - private ITerminals terminal; + private boolean connected; + private boolean exited; + private ITerminals terminals; + private IStreams streams; private int status; private IPropertySet tcfPropertySet = null; - private static String defaultEncoding = new java.io.InputStreamReader(new java.io.ByteArrayInputStream(new byte[0])).getEncoding(); + private static String defaultEncoding = new InputStreamReader(new ByteArrayInputStream(new byte[0])).getEncoding(); private ITerminals.TerminalsListener listeners = new ITerminals.TerminalsListener(){ public void exited(String terminalId, int exitCode) { - - if(!terminalContext.getID().equals(terminalId)) - return; - terminal.removeListener(listeners); - TCFTerminalShell.this.connected = false; + if(!terminalContext.getID().equals(terminalId)) return; + terminals.removeListener(listeners); + connected = false; + exited = true; } - public void winSizeChanged(String terminalId, int newWidth, - int newHeight) { - + public void winSizeChanged(String terminalId, int newWidth, int newHeight) { } }; @@ -120,7 +120,8 @@ public class TCFTerminalShell extends AbstractTerminalShell { status = readUntil(command_prompt,fInputStream); write("\n"); //$NON-NLS-1$ } - } else { + } + else { status = ITCFSessionProvider.SUCCESS_CODE; } } @@ -157,20 +158,19 @@ public class TCFTerminalShell extends AbstractTerminalShell { public int getLoginStatus() { return this.status; } - } public void write(String value) { try { fOutputStream.write(value.getBytes()); - } catch (Exception e) { + } + catch (Exception e) { e.printStackTrace(); } } - private int login(String username, String password) throws InterruptedException - { - long millisToEnd = System.currentTimeMillis() + ITCFSessionProvider.TCP_CONNECT_TIMEOUT*1000; + private int login(String username, String password) throws InterruptedException { + long millisToEnd = System.currentTimeMillis() + ITCFSessionProvider.TCP_CONNECT_TIMEOUT * 1000; LoginThread checkLogin = new LoginThread(username, password); status = ITCFSessionProvider.ERROR_CODE; checkLogin.start(); @@ -204,7 +204,6 @@ public class TCFTerminalShell extends AbstractTerminalShell { final String encoding, final String[] environment, String initialWorkingDirectory, String commandToRun) throws SystemMessageException { - Map<String, Object> map_ids; Exception nestedException = null; try { fSessionProvider = sessionProvider; @@ -214,22 +213,22 @@ public class TCFTerminalShell extends AbstractTerminalShell { if (fChannel == null || fChannel.getState() != IChannel.STATE_OPEN) throw new Exception("TCP channel is not connected!");//$NON-NLS-1$ - if (((TCFConnectorService)sessionProvider).isSubscribed() == false) - ((TCFConnectorService)sessionProvider).subscribe(); - assert (((TCFConnectorService)sessionProvider).isSubscribed()); new TCFRSETask<ITerminals.TerminalContext>() { public void run() { - terminal = ((TCFConnectorService)sessionProvider).getService(ITerminals.class); - terminal.launch(ptyType, encoding, environment, new ITerminals.DoneLaunch() { - public void doneLaunch(IToken token, Exception error, - ITerminals.TerminalContext ctx) { + terminals = ((TCFConnectorService)sessionProvider).getService(ITerminals.class); + streams = ((TCFConnectorService)sessionProvider).getService(IStreams.class); + fSessionProvider.onStreamsConnecting(); + terminals.launch(ptyType, encoding, environment, new ITerminals.DoneLaunch() { + public void doneLaunch(IToken token, Exception error, ITerminals.TerminalContext ctx) { if (ctx != null) { terminalContext = ctx; - terminal.addListener(listeners); + terminals.addListener(listeners); } - + fSessionProvider.onStreamsID(ctx.getStdInID()); + fSessionProvider.onStreamsID(ctx.getStdOutID()); + fSessionProvider.onStreamsConnected(); if (error != null) error(error); else done(ctx); } @@ -243,24 +242,19 @@ public class TCFTerminalShell extends AbstractTerminalShell { fContextID = terminalContext.getID(); fWidth = terminalContext.getWidth(); fHeight = terminalContext.getHeight(); - map_ids = terminalContext.getProperties(); - in_id = (String)map_ids.get(ITerminals.PROP_STDOUT_ID); - out_id = (String)map_ids.get(ITerminals.PROP_STDIN_ID); + in_id = terminalContext.getStdOutID(); + out_id = terminalContext.getStdInID(); String user = fSessionProvider.getSessionUserId(); String password = fSessionProvider.getSessionPassword(); status = ITCFSessionProvider.ERROR_CODE; - IStreams streams = new TCFRSETask<IStreams>() { - public void run() { - done(((TCFConnectorService)sessionProvider).getService(IStreams.class)); - } - }.getS(null, Messages.TCFTerminalService_Name); - fOutputStream = new TCFTerminalOutputStream(streams, out_id); - fInputStream = new TCFTerminalInputStream(streams, in_id); + fOutputStream = new TCFTerminalOutputStream(this, streams, out_id); + fInputStream = new TCFTerminalInputStream(this, streams, in_id); if (fEncoding != null) { fOutputStreamWriter = new BufferedWriter(new OutputStreamWriter(fOutputStream, encoding)); - } else { + } + else { // default encoding == System.getProperty("file.encoding") // TODO should try to determine remote encoding if possible fOutputStreamWriter = new BufferedWriter(new OutputStreamWriter(fOutputStream)); @@ -269,21 +263,15 @@ public class TCFTerminalShell extends AbstractTerminalShell { try { status = login(user, password); } - finally - { - if ((status == ITCFSessionProvider.CONNECT_CLOSED)) - { + finally { + if ((status == ITCFSessionProvider.CONNECT_CLOSED)) { //Give one time chance of retrying.... } - } //give another chance of retrying if ((status == ITCFSessionProvider.CONNECT_CLOSED)) { - ((TCFConnectorService)sessionProvider).unsubscribe(); - ((TCFConnectorService)sessionProvider).subscribe(); - assert (((TCFConnectorService)sessionProvider).isSubscribed()); status = login(user, password); } @@ -300,8 +288,7 @@ public class TCFTerminalShell extends AbstractTerminalShell { } } - catch (Exception e) - { + catch (Exception e) { e.printStackTrace(); nestedException = e; } @@ -316,7 +303,8 @@ public class TCFTerminalShell extends AbstractTerminalShell { ICommonMessageIds.MSG_EXCEPTION_OCCURRED, IStatus.ERROR, CommonMessages.MSG_EXCEPTION_OCCURRED, nestedException); - } else { + } + else { String strErr; if (status == ITCFSessionProvider.CONNECT_CLOSED) strErr = "Connection closed!";//$NON-NLS-1$ @@ -342,7 +330,8 @@ public class TCFTerminalShell extends AbstractTerminalShell { if (isActive()) { if ("#break".equals(command)) { //$NON-NLS-1$ command = "\u0003"; // Unicode 3 == Ctrl+C //$NON-NLS-1$ - } else { + } + else { command += "\r\n"; //$NON-NLS-1$ } fOutputStreamWriter.write(command); @@ -367,16 +356,13 @@ public class TCFTerminalShell extends AbstractTerminalShell { new TCFRSETask<Object>() { public void run() { terminalContext.exit(new ITerminals.DoneCommand(){ - public void doneCommand(IToken token, - Exception error) { - if (error != null) - error(error); - else { - done(this); - } + public void doneCommand(IToken token, Exception error) { + if (error != null) error(error); + else done(this); } }); - }}.getS(null, Messages.TCFShellService_Name); //seems no need block here. need further modification. + } + }.getS(null, Messages.TCFShellService_Name); //seems no need block here. need further modification. } catch (SystemMessageException e) { e.printStackTrace(); @@ -392,7 +378,7 @@ public class TCFTerminalShell extends AbstractTerminalShell { } public boolean isActive() { - if (fChannel != null && !(fChannel.getState() == IChannel.STATE_CLOSED) && connected) { + if (fChannel != null && fChannel.getState() != IChannel.STATE_CLOSED && connected) { return true; } exit(); @@ -415,25 +401,22 @@ public class TCFTerminalShell extends AbstractTerminalShell { new TCFRSETask<Object>() { public void run() { if (fChannel != null && connected) { - terminal.setWinSize(fContextID, fWidth, fHeight, new ITerminals.DoneCommand(){ - + terminals.setWinSize(fContextID, fWidth, fHeight, new ITerminals.DoneCommand(){ public void doneCommand(IToken token, Exception error) { - if (error != null) - error(error); - else - done(this); - - }}); - + if (error != null) error(error); + else done(this); + } + }); } else { done(this); } - }}.getS(null, Messages.TCFShellService_Name); + } + }.getS(null, Messages.TCFShellService_Name); } catch (SystemMessageException e) { e.printStackTrace(); - } //$NON-NLS-1$; + } } public String getDefaultEncoding() { @@ -441,4 +424,23 @@ public class TCFTerminalShell extends AbstractTerminalShell { return defaultEncoding; } + void onInputStreamClosed() { + in_id = null; + if (out_id == null && !exited) { + terminalContext.exit(new ITerminals.DoneCommand(){ + public void doneCommand(IToken token, Exception error) { + } + }); + } + } + + void onOutputStreamClosed() { + out_id = null; + if (in_id == null && !exited) { + terminalContext.exit(new ITerminals.DoneCommand(){ + public void doneCommand(IToken token, Exception error) { + } + }); + } + } } diff --git a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/terminals/TCFTerminalService.java b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/terminals/TCFTerminalService.java index 044cd8b31..50be055bb 100644 --- a/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/terminals/TCFTerminalService.java +++ b/plugins/org.eclipse.tcf.rse/src/org/eclipse/tcf/internal/rse/terminals/TCFTerminalService.java @@ -23,34 +23,27 @@ import org.eclipse.tcf.internal.rse.shells.TCFTerminalShell; public class TCFTerminalService extends AbstractTerminalService implements ITCFService{ private final ITCFSessionProvider fSessionProvider; - /** - * Return the TCF property set, and fill it with default values if it has - * not been created yet. Extender may override in order to set different - * default values. - * - * @return a property set holding properties understood by the TCF - * connector service. - */ public ITerminalShell launchTerminal(String ptyType, String encoding, String[] environment, String initialWorkingDirectory, String commandToRun, IProgressMonitor monitor) throws SystemMessageException { - TCFTerminalShell hostShell = new TCFTerminalShell(fSessionProvider, ptyType, encoding, environment, initialWorkingDirectory, commandToRun); - return hostShell; + return new TCFTerminalShell(fSessionProvider, ptyType, encoding, + environment, initialWorkingDirectory, commandToRun); } - public TCFTerminalService(ITCFSessionProvider sessionProvider) { fSessionProvider = sessionProvider; } public ITCFSessionProvider getSessionProvider() { - return fSessionProvider; - } + return fSessionProvider; + } + @Override public String getName() { return Messages.TCFTerminalService_Name; } + @Override public String getDescription() { return Messages.TCFTerminalService_Description; |