changeset 29:017eeed8332c tn5250

start tn5250 integration
author Carl Byington <carl@five-ten-sg.com>
date Tue, 03 Jun 2014 16:02:29 -0700
parents ad194aedeaab
children d738f6b876fe
files src/com/five_ten_sg/connectbot/service/TerminalBridge.java src/com/five_ten_sg/connectbot/transport/AbsTransport.java src/com/five_ten_sg/connectbot/transport/TN5250.java src/org/tn5250j/framework/tn5250/tnvt.java
diffstat 4 files changed, 61 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/TerminalBridge.java	Tue Jun 03 12:38:59 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalBridge.java	Tue Jun 03 16:02:29 2014 -0700
@@ -307,12 +307,6 @@
         resetColors();
         buffer.setDisplay(this);
         selectionArea = new SelectionArea();
-        keyListener   = new TerminalKeyListener(manager, this, buffer, host.getEncoding());
-
-        String monitor_init = host.getMonitor();
-        if ((monitor_init != null) && (monitor_init.length() > 0)) {
-            monitor = new TerminalMonitor(manager, buffer, keyListener, parent, monitor_init);
-        }
     }
 
     public PromptHelper getPromptHelper() {
@@ -323,11 +317,17 @@
      * Spawn thread to open connection and start login process.
      */
     protected void startConnection() {
-        transport = TransportFactory.getTransport(host.getProtocol());
+        transport   = TransportFactory.getTransport(host.getProtocol());
+        keyListener = transport.getTerminalKeyListener(manager, this, buffer, host.getEncoding());
+
+        String monitor_init = host.getMonitor();
+        if ((monitor_init != null) && (monitor_init.length() > 0)) {
+            monitor = new TerminalMonitor(manager, buffer, keyListener, parent, monitor_init);
+        }
+
         transport.setBridge(this);
         transport.setManager(manager);
         transport.setHost(host);
-        // TODO make this more abstract so we don't litter on AbsTransport
         transport.setCompression(host.getCompression());
         transport.setHttpproxy(host.getHttpproxy());
         transport.setUseAuthAgent(host.getUseAuthAgent());
@@ -441,11 +441,15 @@
             buffer.setBackspace(vt320.DELETE_IS_DEL);
 
         // create thread to relay incoming connection data to buffer
-        relay = new Relay(this, transport, buffer, host.getEncoding());
-        Thread relayThread = new Thread(relay);
-        relayThread.setDaemon(true);
-        relayThread.setName("Relay");
-        relayThread.start();
+        // only if needed by the transport
+        if (transport.needsRelay()) {
+            relay = new Relay(this, transport, buffer, host.getEncoding());
+            Thread relayThread = new Thread(relay);
+            relayThread.setDaemon(true);
+            relayThread.setName("Relay");
+            relayThread.start();
+        }
+
         // force font-size to make sure we resizePTY as needed
         setFontSize(fontSize);
         // finally send any post-login string, if requested
@@ -675,7 +679,7 @@
             Log.e(TAG, "Problem while trying to resize screen or PTY", e);
         }
 
-        // redraw local output if we don't have a sesson to receive our resize request
+        // redraw local output if we don't have a session to receive our resize request
         if (transport == null) {
             synchronized (localOutput) {
                 buffer.reset();
--- a/src/com/five_ten_sg/connectbot/transport/AbsTransport.java	Tue Jun 03 12:38:59 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/transport/AbsTransport.java	Tue Jun 03 16:02:29 2014 -0700
@@ -24,9 +24,11 @@
 import com.five_ten_sg.connectbot.bean.HostBean;
 import com.five_ten_sg.connectbot.bean.PortForwardBean;
 import com.five_ten_sg.connectbot.service.TerminalBridge;
+import com.five_ten_sg.connectbot.service.TerminalKeyListener;
 import com.five_ten_sg.connectbot.service.TerminalManager;
 import android.content.Context;
 import android.net.Uri;
+import de.mud.terminal.vt320;
 
 /**
  * @author Kenny Root
@@ -285,7 +287,23 @@
     public abstract String getFormatHint(Context context);
 
     /**
-     * @return
+     * @return do we use the network
      */
     public abstract boolean usesNetwork();
+
+    /**
+     * @return do we need a relay object to read from the transport
+     *         and send the data into the vt320 buffer
+     */
+    public boolean needsRelay() {
+        return true;
+    }
+
+    /**
+     * @return a key listener
+     */
+    public TerminalKeyListener(TerminalManager manager, TerminalBridge bridge, vt320 buffer, String encoding) {
+        return new TerminalKeyListener(manager, bridge, buffer, encoding);
+    }
+
 }
--- a/src/com/five_ten_sg/connectbot/transport/TN5250.java	Tue Jun 03 12:38:59 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/transport/TN5250.java	Tue Jun 03 16:02:29 2014 -0700
@@ -35,12 +35,13 @@
 import com.five_ten_sg.connectbot.bean.HostBean;
 import com.five_ten_sg.connectbot.bean.PortForwardBean;
 import com.five_ten_sg.connectbot.service.TerminalBridge;
+import com.five_ten_sg.connectbot.service.TerminalKeyListener;
 import com.five_ten_sg.connectbot.service.TerminalManager;
 import com.five_ten_sg.connectbot.util.HostDatabase;
-
 import android.content.Context;
 import android.net.Uri;
 import android.util.Log;
+import de.mud.terminal.vt320;
 
 
 /**
@@ -56,8 +57,6 @@
     private tnvt   handler = null;
     private Socket socket;
 
-    private InputStream is;
-    private OutputStream os;
     private int width;
     private int height;
 
@@ -75,7 +74,6 @@
 
    public TN5250(HostBean host, TerminalBridge bridge, TerminalManager manager) {
        super(host, bridge, manager);
-       handler = new tnvt(screen52, true, false, bridge, manager);
    }
 
 
@@ -130,12 +128,10 @@
     */
    @Override
    public void connect() {
+        screen52  = new Screen5250;
+        handler   = new tnvt(screen52, true, false, bridge, manager);
         connected = handler.connect(host.getHostname(), host.getPort());
-        if (connected) {
-            is = handler.bin;
-            os = handler.bout;
-            bridge.onConnected();
-        }
+        if (connected) bridge.onConnected();
     }
 
 
@@ -145,12 +141,8 @@
      */
     @Override
     public boolean willBlock() {
-        if (is == null) return true;
-        try {
-            return is.available() == 0;
-        } catch (Exception e) {
-            return true;
-        }
+        // we don't use a relay thread between the transport and the vt320 buffer
+        return true;
     }
 
     /**
@@ -165,6 +157,7 @@
      * @throws IOException when remote host disconnects
      */
     public int read(byte[] buffer, int offset, int length) throws IOException {
+        // we don't use a relay thread between the transport and the vt320 buffer
         return 0;
     }
 
@@ -196,7 +189,7 @@
 
     /**
      * Closes the connection to the terminal. Note that the resulting failure to read
-     * should call {@link TerminalBridge#dispatchDisconnect(boolean)}.
+     * should call {@link TerminalBridge#dispatchDisconnect(boolean)}.  !!!
      */
     public void close() {
         handler.disconnect();
@@ -419,4 +412,18 @@
     public boolean usesNetwork() {
         return true;
     }
+
+
+    @Override
+    public boolean needsRelay() {
+        // we don't use a relay thread between the transport and the vt320 buffer
+        return false;
+    }
+
+
+    @Override
+    public TerminalKeyListener(TerminalManager manager, TerminalBridge bridge, vt320 buffer, String encoding) {
+        return new TerminalKeyListener(manager, bridge, buffer, encoding);
+    }
+
 }
--- a/src/org/tn5250j/framework/tn5250/tnvt.java	Tue Jun 03 12:38:59 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/tnvt.java	Tue Jun 03 16:02:29 2014 -0700
@@ -1359,7 +1359,7 @@
             pos |= bk.getNextByte() & 0xff;
             int hPos = bk.getNextByte() << 8 & 0xff00; // home position
             hPos |= bk.getNextByte() & 0xff;
-            if (rows != screen52.getRows())
+            if ((rows != screen52.getRows()) || (cols != screen52.getColumns()))
                 screen52.setRowsCols(rows, cols);
             screen52.clearAll(); // initialize what we currenty have
             if (sfParser != null && sfParser.isGuisExists())