changeset 79:01d939969b10

merge tn5250 branch into default
author Carl Byington <carl@five-ten-sg.com>
date Mon, 16 Jun 2014 08:24:00 -0700
parents b3d0d806cbe2 (diff) 044b1a951925 (current diff)
children ab8d2f6c5847
files src/com/five_ten_sg/connectbot/service/TerminalBridge.java src/com/five_ten_sg/connectbot/service/TerminalMonitor.java
diffstat 2 files changed, 41 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/res/values/version.xml	Sun Jun 15 11:05:06 2014 -0700
+++ b/res/values/version.xml	Mon Jun 16 08:24:00 2014 -0700
@@ -1,4 +1,4 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
-	<string name="msg_version" translatable="false">510 ConnectBot 1.7.2-1 (e11983ee7321+ 2014-04-20)</string>
+	<string name="msg_version" translatable="false">510Connectbot 1.7.2-1 (ab7313512aba+ 2014-05-29)</string>
 </resources>
--- a/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Sun Jun 15 11:05:06 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/TerminalMonitor.java	Mon Jun 16 08:24:00 2014 -0700
@@ -16,6 +16,9 @@
 import java.net.Socket;
 import java.nio.charset.Charset;
 import java.util.HashMap;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ConcurrentHashMap;
 
 public class TerminalMonitor {
     public final static String TAG = "ConnectBot.TerminalMonitor";
@@ -43,13 +46,17 @@
     private int                 end_line     = 500;     // ""
     private int                 start_column = 0;       // ""
     private int                 end_column   = 500;     // ""
-    private boolean             modified     = false;   // ""
+    private boolean             modified     = false;   // used to delay screen change notifications
+    private boolean             moved        = false;   // used to delay cursor moved notifications
+    private int                 to_line      = 0;       // ""
+    private int                 to_column    = 0;       // ""
     private HashMap<Integer,Integer>  keymap = null;
     private IBinder             bound        = null;
     private Socket              monitor_socket = null;
     private InputStream         monitor_in     = null;
     private OutputStream        monitor_out    = null;
     private MyReader            monitor_reader = null;
+    private BlockingQueue<char[]> pending_commands = new ArrayBlockingQueue<char[]>(100);
     private MyServiceConnection monitor_connection = new MyServiceConnection();
 
     class MyReader extends Thread {
@@ -141,6 +148,12 @@
                 monitor_reader.start();
                 String x = "  " + init;
                 monitorWrite(MONITOR_CMD_INIT, x.toCharArray());
+                char [] c;
+                while (true) {
+                    c = pending_commands.poll();
+                    if (c == null) break;
+                    monitorWrite(c[1], c);
+                }
             }
             catch (IOException e) {
                 Log.e(TAG, "exception in onServiceConnected()", e);
@@ -161,7 +174,7 @@
         this.init        = init;
 
         // setup the windows->android keymapping
-        // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx
+        // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731
         // http://developer.android.com/reference/android/view/KeyEvent.html
         keymap      = new HashMap<Integer,Integer>();
         keymap.put(0x08, KeyEvent.KEYCODE_BACK);        // vk_back
@@ -260,6 +273,13 @@
                 //Log.i(TAG, String.format("sending %d command", (int)cmd));
                 monitor_out.write(charsToBytes(c));
             }
+            else {
+                c[1] = cmd;
+                pending_commands.put(c);
+            }
+        }
+        catch (InterruptedException e) {
+            Log.e(TAG, "exception in monitorWrite()", e);
         }
         catch (IOException e) {
             Log.i(TAG, "exception in monitorWrite(), monitor died or closed the socket", e);
@@ -294,7 +314,6 @@
     }
 
     public synchronized void hostData(byte[] b) {
-        if (b == null) return;
         for (int i = 0; i < b.length; i++) {
             hostData((int)b[i] & 0xff);
         }
@@ -307,9 +326,15 @@
     }
 
     public synchronized void cursorMove(int l, int c) {
+        moved = true;
+        to_line = l;
+        to_column = c;
+    }
+
+    public void cursorMoved() {
         char[] arg = new char[4];
-        arg[2] = (char)(l & 0x0000ffff);
-        arg[3] = (char)(c & 0x0000ffff);
+        arg[2] = (char)(to_line & 0x0000ffff);
+        arg[3] = (char)(to_column & 0x0000ffff);
         monitorWrite(MONITOR_CMD_CURSORMOVE, arg);
     }
 
@@ -318,6 +343,10 @@
             modified = false;
             sendScreen(MONITOR_CMD_SCREENCHANGE);
         }
+        if (moved) {
+            moved = false;
+            cursorMoved();
+        }
     }
 
     public synchronized void screenChanged(int llow, int lhigh, int clow, int chigh) {
@@ -332,9 +361,12 @@
 
     public synchronized void setField(int l, int c, char[] data, int offset) {
         Log.i(TAG, "setField()");
-        char[] d = new char[data.length - offset];
-        System.arraycopy(data, offset, d, 0, data.length - offset);
-        buffer.setField(l, c, d);
+        byte[] b = new byte[data.length - offset];
+        int i;
+        for (i=0; i<b.length; i++) {
+            b[i] = (byte)(data[i+offset] & 0x00ff);
+        }
+        buffer.write(b);
     }
 
     public synchronized void getField(int l, int c, int len) {