comparison app/src/main/java/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 506:b8cc360e1550 stable-1.9.4-5

allow multiple screen watch areas
author Carl Byington <carl@five-ten-sg.com>
date Wed, 16 Nov 2022 12:05:29 -0700
parents f698820bffdf
children d6c107dedb04
comparison
equal deleted inserted replaced
505:bd87ca9eb4b8 506:b8cc360e1550
24 import java.util.concurrent.ConcurrentHashMap; 24 import java.util.concurrent.ConcurrentHashMap;
25 25
26 import com.five_ten_sg.connectbot.ConsoleActivity; 26 import com.five_ten_sg.connectbot.ConsoleActivity;
27 import com.five_ten_sg.connectbot.bean.HostBean; 27 import com.five_ten_sg.connectbot.bean.HostBean;
28 28
29
30 public class TerminalMonitor { 29 public class TerminalMonitor {
31 public final static String TAG = "ConnectBot.TermMonitor"; 30 public final static String TAG = "ConnectBot.TermMonitor";
32 31
33 public static final char MONITOR_CMD_INIT = 0; 32 public static final char MONITOR_CMD_INIT = 0;
34 public static final char MONITOR_CMD_ACTIVATE = 1; 33 public static final char MONITOR_CMD_ACTIVATE = 1;
82 private HostBean host = null; 81 private HostBean host = null;
83 private Uri uri = null; 82 private Uri uri = null;
84 private int port = 0; 83 private int port = 0;
85 private String target = null; 84 private String target = null;
86 private String init = null; 85 private String init = null;
87 private int start_line = 0; // monitor part of the screen for changes 86 private Watch[] watches = null;
88 private int end_line = 500; // ""
89 private int start_column = 0; // ""
90 private int end_column = 500; // ""
91 private boolean modified = false; // used to delay screen change notifications 87 private boolean modified = false; // used to delay screen change notifications
92 private boolean moved = false; // used to delay cursor moved notifications 88 private boolean moved = false; // used to delay cursor moved notifications
93 private int to_line = 0; // "" 89 private int to_line = 0; // ""
94 private int to_column = 0; // "" 90 private int to_column = 0; // ""
95 private HashMap<Integer, Integer> keymap = null; // map MS VK_ keys to vt320 virtual keys 91 private HashMap<Integer, Integer> keymap = null; // map MS VK_ keys to vt320 virtual keys
99 private OutputStream monitor_out = null; 95 private OutputStream monitor_out = null;
100 private MyReader monitor_reader = null; 96 private MyReader monitor_reader = null;
101 private BlockingQueue<char[]> pending_commands = new ArrayBlockingQueue<char[]>(100); 97 private BlockingQueue<char[]> pending_commands = new ArrayBlockingQueue<char[]>(100);
102 private MyServiceConnection monitor_connection = new MyServiceConnection(); 98 private MyServiceConnection monitor_connection = new MyServiceConnection();
103 99
100
101 private class Watch {
102 // monitor part of the screen for changes
103 private int start_line;
104 private int end_line;
105 private int start_column;
106 private int end_column;
107 public Watch(int l, int c, int len) {
108 Log.i(TAG, String.format("screenWatch(line %d, col %d, len %d)", l, c, len));
109 this.start_line = l;
110 this.end_line = l;
111 this.start_column = c;
112 this.end_column = c + len - 1;
113 }
114 public boolean screenChanged(int llow, int lhigh, int clow, int chigh) {
115 return ((start_line <= lhigh) &&
116 (llow <= end_line) &&
117 (start_column <= chigh) &&
118 (clow <= end_column));
119 }
120 }
121
104 class MyReader extends Thread { 122 class MyReader extends Thread {
105 private InputStream monitor_in; 123 private InputStream monitor_in;
106 private byte[] b; 124 private byte[] b;
107 private boolean is_closing = false; 125 private boolean is_closing = false;
108 126
153 getField(packet[1], packet[2], packet[3]); 171 getField(packet[1], packet[2], packet[3]);
154 172
155 break; 173 break;
156 174
157 case MONITOR_CMD_SCREENWATCH: 175 case MONITOR_CMD_SCREENWATCH:
158 if (packet.length == 4) 176 if (packet.length >= 4) {
159 screenWatch(packet[1], packet[2], packet[3]); 177 int n = (packet.length - 1) / 3;
160 178 watches = new Watch[n];
179 for (int i=0; i<n; i++) {
180 int j = 1 + i*3;
181 watches[i] = new Watch(packet[j], packet[j+1], packet[j+2]);
182 }
183 }
161 break; 184 break;
162 185
163 case MONITOR_CMD_DEPRESS: 186 case MONITOR_CMD_DEPRESS:
164 if (packet.length == 2) 187 if (packet.length == 2)
165 depress(packet[1]); 188 depress(packet[1]);
419 monitor_out = null; 442 monitor_out = null;
420 } 443 }
421 }; 444 };
422 445
423 public void resetWatch() { 446 public void resetWatch() {
424 start_line = 0; 447 watches = null;
425 end_line = 500;
426 start_column = 0;
427 end_column = 500;
428 }; 448 };
429 449
430 public void sendScreen(char cmd) { 450 public void sendScreen(char cmd) {
431 char lines = (char)(buffer.height & 0x0000ffff); 451 char lines = (char)(buffer.height & 0x0000ffff);
432 char columns = (char)(buffer.width & 0x0000ffff); 452 char columns = (char)(buffer.width & 0x0000ffff);
485 if (moved) cursorMoved(CURSOR_SCREEN_CHANGE); 505 if (moved) cursorMoved(CURSOR_SCREEN_CHANGE);
486 } 506 }
487 } 507 }
488 508
489 public synchronized void screenChanged(int llow, int lhigh, int clow, int chigh) { 509 public synchronized void screenChanged(int llow, int lhigh, int clow, int chigh) {
490 if ((start_line <= lhigh) && (llow <= end_line) && (start_column <= chigh) && (clow <= end_column)) { 510 if (watches == null) {
491 modified = true; 511 modified = true;
512 return;
513 }
514 for (Watch w : watches) {
515 if (w.screenChanged(llow, lhigh, clow, chigh)) {
516 modified = true;
517 return;
518 }
492 } 519 }
493 } 520 }
494 521
495 public synchronized void screenChanged(int l, int c) { 522 public synchronized void screenChanged(int l, int c) {
496 screenChanged(l, l, c, c); 523 screenChanged(l, l, c, c);
539 char[] da = new char[len]; 566 char[] da = new char[len];
540 System.arraycopy(arg2, base, da, 0, len); 567 System.arraycopy(arg2, base, da, 0, len);
541 Log.i(TAG, String.format("getField value %s", new String(da))); 568 Log.i(TAG, String.format("getField value %s", new String(da)));
542 569
543 monitorWrite(MONITOR_CMD_FIELDVALUE, arg2); 570 monitorWrite(MONITOR_CMD_FIELDVALUE, arg2);
544 }
545
546 public synchronized void screenWatch(int l, int c, int len) {
547 Log.i(TAG, String.format("screenWatch(line %d, col %d, len %d)", l, c, len));
548 start_line = l;
549 end_line = l;
550 start_column = c;
551 end_column = c + len - 1;
552 } 571 }
553 572
554 public synchronized void depress(int vk_key) { 573 public synchronized void depress(int vk_key) {
555 Log.i(TAG, String.format("depress(%04x)", vk_key)); 574 Log.i(TAG, String.format("depress(%04x)", vk_key));
556 Integer x = keymap.get(new Integer(vk_key)); 575 Integer x = keymap.get(new Integer(vk_key));