changeset 42:7ac846a07ed4 tn5250

start tn5250 integration
author Carl Byington <carl@five-ten-sg.com>
date Wed, 11 Jun 2014 09:14:31 -0700
parents 9621ac4dd5eb
children 6b0f1ece1d91
files AndroidManifest.xml TODO src/com/five_ten_sg/connectbot/service/TerminalBridge.java src/com/five_ten_sg/connectbot/service/TerminalKeyListener.java src/com/five_ten_sg/connectbot/transport/AbsTransport.java src/org/tn5250j/framework/tn5250/Screen5250.java src/org/tn5250j/framework/tn5250/tnvt.java
diffstat 7 files changed, 132 insertions(+), 148 deletions(-) [+]
line wrap: on
line diff
--- a/AndroidManifest.xml	Tue Jun 10 17:40:09 2014 -0700
+++ b/AndroidManifest.xml	Wed Jun 11 09:14:31 2014 -0700
@@ -17,7 +17,7 @@
 -->
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 	package="com.five_ten_sg.connectbot"
-	android:versionName="1.7.2-1"
+	android:versionName="1.8.0-1"
 	android:versionCode="1"
 	android:installLocation="auto">
 
--- a/TODO	Tue Jun 10 17:40:09 2014 -0700
+++ b/TODO	Wed Jun 11 09:14:31 2014 -0700
@@ -31,16 +31,19 @@
 # reinstall all jsocks and ssh2 patches from vxconnectbot since the split
 (cd ../vxconnectbot; git diff -w 598fb427f96712191cc264df14688d82db3dd664) | less
 
+==================================
+
+merge tn5250j
+svn checkout svn://svn.code.sf.net/p/tn5250j/code/branches/new-tabs-jse1.6 tn5250j
 
 ==================================
 TODO:
 
+possible merge of irssi?
+
 https://github.com/irssiconnectbot/irssiconnectbot
 1.7.1-395 - a year ago
 
 
 
-merge tn5250j
-svn checkout svn://svn.code.sf.net/p/tn5250j/code/branches/new-tabs-jse1.6 tn5250j
-after 5250 merge, go up to version 1.8.0-1
 
--- a/src/com/five_ten_sg/connectbot/service/TerminalBridge.java	Tue Jun 10 17:40:09 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalBridge.java	Wed Jun 11 09:14:31 2014 -0700
@@ -96,7 +96,6 @@
     private Relay relay;
 
     private final String emulation;
-    private final int scrollback;
 
     public Bitmap bitmap = null;
     public vt320  buffer = null;
@@ -120,11 +119,10 @@
     // TODO add support for the new clipboard API
     private ClipboardManager clipboard;
 
-    public int charWidth = -1;
-    public int charHeight = -1;
-    private int charTop = -1;
-
-    private float fontSize = -1;
+    public  int   charWidth  = -1;
+    public  int   charHeight = -1;
+    private int   charTop    = -1;
+    private float fontSize   = -1;
 
     private final List<FontSizeChangedListener> fontSizeChangedListeners;
 
@@ -160,7 +158,6 @@
         manager = null;
         defaultPaint = new Paint();
         selectionArea = new SelectionArea();
-        scrollback = 1;
         localOutput = new LinkedList<String>();
         fontSizeChangedListeners = new LinkedList<FontSizeChangedListener>();
         transport   = null;
@@ -169,16 +166,13 @@
     }
 
     /**
-     * Create new terminal bridge with following parameters. We will immediately
-     * launch thread to start SSH connection and handle any hostkey verification
-     * and password authentication.
+     * Create new terminal bridge with following parameters.
      */
     public TerminalBridge(final TerminalManager manager, final HostBean host) throws IOException {
         float hostFontSize;
         this.manager = manager;
         this.host = host;
         emulation = manager.getEmulation();
-        scrollback = manager.getScrollback();
         // create prompt helper to relay password and hostkey requests up to gui
         promptHelper = new PromptHelper(this);
         // create our default paint
@@ -191,121 +185,19 @@
         Integer defaultFontSize = Integer.parseInt(manager.prefs.getString(PreferenceConstants.DEFAULT_FONT_SIZE, "-1"));
         Log.i(TAG, "fontSize: " + this.fontSize + ", defaultFontSize: " + defaultFontSize);
 
-        if (this.fontSize == -1) {
+        if (fontSize == -1) {
             if (defaultFontSize > 0 && host.getFontSize() == -1)
                 hostFontSize = defaultFontSize;
             else
                 hostFontSize = host.getFontSize();
         }
         else
-            hostFontSize = this.fontSize;
+            hostFontSize = fontSize;
 
-        if (hostFontSize <= 0)
-            hostFontSize = DEFAULT_FONT_SIZE;
+        if (hostFontSize <= 0) hostFontSize = DEFAULT_FONT_SIZE;
 
         setFontSize(hostFontSize);
-        // create terminal buffer and handle outgoing data
-        // this is probably status reply information
-        buffer = new vt320() {
-            @Override
-            public void debug(String s) {
-                Log.d(TAG, s);
-            }
-            @Override
-            public void write(byte[] b) {
-                try {
-                    if (b != null && transport != null)
-                        if (monitor != null) monitor.hostData(b);
-
-                    transport.write(b);
-                }
-                catch (IOException e) {
-                    Log.e(TAG, "Problem writing outgoing data in vt320() thread", e);
-                }
-            }
-            @Override
-            public void write(int b) {
-                try {
-                    if (transport != null)
-                        if (monitor != null) monitor.hostData(b);
-
-                    transport.write(b);
-                }
-                catch (IOException e) {
-                    Log.e(TAG, "Problem writing outgoing data in vt320() thread", e);
-                }
-            }
-            // We don't use telnet sequences.
-            @Override
-            public void sendTelnetCommand(byte cmd) {
-            }
-            // We don't want remote to resize our window.
-            @Override
-            public void setWindowSize(int c, int r) {
-            }
-            // test for changed screen contents
-            @Override
-            public void testChanged() {
-                if (monitor != null) monitor.testChanged();
-            }
-            // play beep noise
-            @Override
-            public void beep() {
-                if (parent.isShown())
-                    manager.playBeep();
-                else
-                    manager.sendActivityNotification(host);
-            }
-            // monitor placement of new characters
-            @Override
-            public void putChar(int c, int l, char ch, int attributes) {
-                if (monitor != null) monitor.screenChanged(l, c);
-
-                super.putChar(c, l, ch, attributes);
-            }
-            @Override
-            public void insertChar(int c, int l, char ch, int attributes) {
-                if (monitor != null) monitor.screenChanged(l, l, c, width - 1);
-
-                super.insertChar(c, l, ch, attributes);
-            }
-            @Override
-            public void insertLine(int l, int n, boolean scrollDown) {
-                if (monitor != null) {
-                    if (scrollDown) monitor.screenChanged(l, height - 1, 0, width - 1);
-                    else            monitor.screenChanged(0, l, 0, width - 1);
-                }
-
-                super.insertLine(l, n, scrollDown);
-            }
-            @Override
-            public void deleteLine(int l) {
-                if (monitor != null) monitor.screenChanged(l, height - 1, 0, width - 1);
-
-                super.deleteLine(l);
-            }
-            @Override
-            public void deleteChar(int c, int l) {
-                if (monitor != null) monitor.screenChanged(l, l, c, width - 1);
-
-                super.deleteChar(c, l);
-            }
-            @Override
-            public void setCursorPosition(int c, int l) {
-                if (monitor != null) monitor.cursorMove(l, c);
-
-                super.setCursorPosition(c, l);
-            }
-        };
-
-        // Don't keep any scrollback if a session is not being opened.
-        if (host.getWantSession())
-            buffer.setBufferSize(scrollback);
-        else
-            buffer.setBufferSize(0);
-
         resetColors();
-        buffer.setDisplay(this);
         selectionArea = new SelectionArea();
     }
 
@@ -318,8 +210,8 @@
      */
     protected void startConnection() {
         transport   = TransportFactory.getTransport(host.getProtocol());
-        transport.setLinks(manager, this, host, buffer, emulation);
-
+        transport.setLinks(manager, this, host, emulation);
+        buffer      = transport.getTransportBuffer();
         keyListener = transport.getTerminalKeyListener();
 
         String monitor_init = host.getMonitor();
@@ -365,7 +257,8 @@
      * @return charset in use by bridge
      */
     public Charset getCharset() {
-        return relay.getCharset();
+        if (relay != null) return relay.getCharset();
+
     }
 
     /**
@@ -374,8 +267,7 @@
      * @param encoding the canonical name of the character encoding
      */
     public void setCharset(String encoding) {
-        if (relay != null)
-            relay.setCharset(encoding);
+        if (relay != null) relay.setCharset(encoding);
 
         keyListener.setCharset(encoding);
     }
@@ -427,9 +319,8 @@
     public void onConnected() {
         disconnected = false;
         buffer.reset();
-        // We no longer need our local output.
-        localOutput.clear();
         buffer.setAnswerBack(emulation);
+        localOutput.clear();    // We no longer need our local output.
 
         if (HostDatabase.DELKEY_BACKSPACE.equals(host.getDelKey()))
             buffer.setBackspace(vt320.DELETE_IS_BACKSPACE);
@@ -664,8 +555,10 @@
 
         try {
             // request a terminal pty resize
-            synchronized (buffer) {
-                buffer.setScreenSize(columns, rows, true);
+            if (buffer != null) {
+                synchronized (buffer) {
+                    buffer.setScreenSize(columns, rows, true);
+                }
             }
 
             if (transport != null)
--- a/src/com/five_ten_sg/connectbot/service/TerminalKeyListener.java	Tue Jun 10 17:40:09 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalKeyListener.java	Wed Jun 11 09:14:31 2014 -0700
@@ -472,7 +472,7 @@
                     return (handleShortcut(v, hwbuttonShortcut));
 
                 case KeyEvent.KEYCODE_VOLUME_UP:
-                    // check to see which shortcut the camera button triggers
+                    // check to see which shortcut the volume button triggers
                     hwbuttonShortcut = manager.prefs.getString(
                                            PreferenceConstants.VOLUP,
                                            PreferenceConstants.HWBUTTON_CTRL);
@@ -486,7 +486,7 @@
                     return (handleShortcut(v, hwbuttonShortcut));
 
                 case KeyEvent.KEYCODE_SEARCH:
-                    // check to see which shortcut the camera button triggers
+                    // check to see which shortcut the search button triggers
                     hwbuttonShortcut = manager.prefs.getString(
                                            PreferenceConstants.SEARCH,
                                            PreferenceConstants.HWBUTTON_ESC);
@@ -913,10 +913,6 @@
                     // copy selected area to clipboard
                     String copiedText = selectionArea.copyFrom(buffer);
                     clipboard.setText(copiedText);
-                    // XXX STOPSHIP
-//                  manager.notifyUser(manager.getString(
-//                          R.string.console_copy_done,
-//                          copiedText.length()));
                     selectingForCopy = false;
                     selectionArea.reset();
                 }
--- a/src/com/five_ten_sg/connectbot/transport/AbsTransport.java	Tue Jun 10 17:40:09 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/transport/AbsTransport.java	Wed Jun 11 09:14:31 2014 -0700
@@ -41,6 +41,99 @@
     vt320           buffer;
     String          emulation;
 
+    class vt320Default extends vt320 {
+        @Override
+        public void debug(String s) {
+            Log.d(TAG, s);
+        }
+        @Override
+        public void write(byte[] b) {
+            try {
+                if (b != null && transport != null)
+                    if (bridge.monitor != null) bridge.monitor.hostData(b);
+
+                transport.write(b);
+            }
+            catch (IOException e) {
+                Log.e(TAG, "Problem writing outgoing data in vt320() thread", e);
+            }
+        }
+        @Override
+        public void write(int b) {
+            try {
+                if (transport != null)
+                    if (bridge.monitor != null) bridge.monitor.hostData(b);
+
+                transport.write(b);
+            }
+            catch (IOException e) {
+                Log.e(TAG, "Problem writing outgoing data in vt320() thread", e);
+            }
+        }
+        // We don't use telnet sequences.
+        @Override
+        public void sendTelnetCommand(byte cmd) {
+        }
+        // We don't want remote to resize our window.
+        @Override
+        public void setWindowSize(int c, int r) {
+        }
+        // test for changed screen contents
+        @Override
+        public void testChanged() {
+            if (bridge.monitor != null) bridge.monitor.testChanged();
+        }
+        // play beep noise
+        @Override
+        public void beep() {
+            if (bridge.parent.isShown())
+                manager.playBeep();
+            else
+                manager.sendActivityNotification(host);
+        }
+        // bridge.monitor placement of new characters
+        @Override
+        public void putChar(int c, int l, char ch, int attributes) {
+            if (bridge.monitor != null) bridge.monitor.screenChanged(l, c);
+
+            super.putChar(c, l, ch, attributes);
+        }
+        @Override
+        public void insertChar(int c, int l, char ch, int attributes) {
+            if (bridge.monitor != null) bridge.monitor.screenChanged(l, l, c, width - 1);
+
+            super.insertChar(c, l, ch, attributes);
+        }
+        @Override
+        public void insertLine(int l, int n, boolean scrollDown) {
+            if (bridge.monitor != null) {
+                if (scrollDown) bridge.monitor.screenChanged(l, height - 1, 0, width - 1);
+                else            bridge.monitor.screenChanged(0, l, 0, width - 1);
+            }
+
+            super.insertLine(l, n, scrollDown);
+        }
+        @Override
+        public void deleteLine(int l) {
+            if (bridge.monitor != null) bridge.monitor.screenChanged(l, height - 1, 0, width - 1);
+
+            super.deleteLine(l);
+        }
+        @Override
+        public void deleteChar(int c, int l) {
+            if (bridge.monitor != null) bridge.monitor.screenChanged(l, l, c, width - 1);
+
+            super.deleteChar(c, l);
+        }
+        @Override
+        public void setCursorPosition(int c, int l) {
+            if (bridge.monitor != null) bridge.monitor.cursorMove(l, c);
+
+            super.setCursorPosition(c, l);
+        }
+    };
+
+
     public AbsTransport() {}
 
     /**
@@ -144,11 +237,18 @@
         return emulation;
     }
 
-    public void setLinks(TerminalManager manager, TerminalBridge bridge, HostBean host, vt320 buffer, String emulation) {
+    public vt320 getTransportbuffer() {
+        buffer = vt320Default();
+        int scrollback = (host.getWantSession()) ?  manager.getScrollback() : 0;
+        buffer.setBufferSize(scrollback);
+        buffer.setDisplay(bridge);
+        return buffer;
+    }
+
+    public void setLinks(TerminalManager manager, TerminalBridge bridge, HostBean host, String emulation) {
         this.manager   = manager;
         this.bridge    = bridge;
         this.host      = host;
-        this.buffer    = buffer;
         this.emulation = emulation;
     }
 
@@ -288,7 +388,7 @@
      * @return a key listener
      */
     public TerminalKeyListener getTerminalKeyListener() {
-        return new TerminalKeyListener(manager, bridge, buffer,  host.getEncoding());
+        return new TerminalKeyListener(manager, bridge, buffer, host.getEncoding());
     }
 
 }
--- a/src/org/tn5250j/framework/tn5250/Screen5250.java	Tue Jun 10 17:40:09 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/Screen5250.java	Wed Jun 11 09:14:31 2014 -0700
@@ -940,13 +940,9 @@
      *
      * @see #sendAid
      *
-     * Added synchronized to fix a StringOutOfBounds error - Luc Gorren LDC
      */
     public synchronized void sendKeys(String text) {
 
-        //      if (text == null) {
-        //         return;
-        //      }
         this.keybuf.append(text);
 
         if (isStatusErrorCode() && !resetRequired) {
@@ -970,11 +966,8 @@
 
                 oia.setKeysBuffered(true);
 
-                if (bufferedKeys == null) {
-                    bufferedKeys = text;
-                    return;
-                }
-                bufferedKeys += text;
+                if (bufferedKeys == null) bufferedKeys = text;
+                else                      bufferedKeys += text;
                 return;
             }
 
--- a/src/org/tn5250j/framework/tn5250/tnvt.java	Tue Jun 10 17:40:09 2014 -0700
+++ b/src/org/tn5250j/framework/tn5250/tnvt.java	Wed Jun 11 09:14:31 2014 -0700
@@ -343,7 +343,6 @@
 
     public final boolean disconnect() {
 
-        // Added by LUC - LDC to fix a null pointer exception.
         if (!connected) {
             screen52.getOIA().setInputInhibited(ScreenOIA.INPUTINHIBITED_SYSTEM_WAIT,
                     ScreenOIA.OIA_LEVEL_INPUT_INHIBITED,"X - Disconnected");