Mercurial > 510Connectbot
annotate app/src/main/java/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 492:e88d48be89a8
add TCP_NODELAY to the monitor socket
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 15 Feb 2022 13:45:57 -0800 |
parents | 3a83f40439d7 |
children | f698820bffdf |
rev | line source |
---|---|
0 | 1 package com.five_ten_sg.connectbot.service; |
2 | |
3 import android.content.ComponentName; | |
4 import android.content.Context; | |
5 import android.content.Intent; | |
6 import android.content.ServiceConnection; | |
155 | 7 import android.net.Uri; |
0 | 8 import android.os.IBinder; |
9 import android.util.Log; | |
10 import android.view.View; | |
11 import de.mud.terminal.vt320; | |
12 import java.io.IOException; | |
13 import java.io.InputStream; | |
14 import java.io.OutputStream; | |
15 import java.net.InetAddress; | |
16 import java.net.Socket; | |
17 import java.nio.charset.Charset; | |
252
932e34a11e9e
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
251
diff
changeset
|
18 import java.util.Arrays; |
0 | 19 import java.util.HashMap; |
15
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
20 import java.util.concurrent.ArrayBlockingQueue; |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
21 import java.util.concurrent.BlockingQueue; |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
22 import java.util.concurrent.ConcurrentHashMap; |
0 | 23 |
174
b010f9dc801f
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
173
diff
changeset
|
24 import com.five_ten_sg.connectbot.ConsoleActivity; |
b010f9dc801f
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
173
diff
changeset
|
25 import com.five_ten_sg.connectbot.bean.HostBean; |
b010f9dc801f
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
173
diff
changeset
|
26 |
b010f9dc801f
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
173
diff
changeset
|
27 |
0 | 28 public class TerminalMonitor { |
457
105815cce146
minimum version android 5, target and compile version api 28
Carl Byington <carl@five-ten-sg.com>
parents:
438
diff
changeset
|
29 public final static String TAG = "ConnectBot.TermMonitor"; |
0 | 30 |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
31 public static final char MONITOR_CMD_INIT = 0; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
32 public static final char MONITOR_CMD_ACTIVATE = 1; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
33 public static final char MONITOR_CMD_KEYSTATE = 2; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
34 public static final char MONITOR_CMD_CURSORMOVE = 3; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
35 public static final char MONITOR_CMD_SCREENCHANGE = 4; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
36 public static final char MONITOR_CMD_FIELDVALUE = 5; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
37 public static final char MONITOR_CMD_SETFIELD = 5; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
38 public static final char MONITOR_CMD_GETFIELD = 6; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
39 public static final char MONITOR_CMD_SCREENWATCH = 7; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
40 public static final char MONITOR_CMD_DEPRESS = 8; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
41 public static final char MONITOR_CMD_SHOWURL = 9; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
42 public static final char MONITOR_CMD_SWITCHSESSION = 10; |
205
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
43 public static final char MONITOR_CMD_CURSORREQUEST = 11; |
459
a3239022798d
compile 32 and 64 bit arch, bump version
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
44 public static final char MONITOR_CMD_SAYSTRING = 12; |
0 | 45 |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
46 public static final String[] commands = { |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
47 "cmd_init", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
48 "cmd_activate", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
49 "cmd_keystate", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
50 "cmd_cursormove", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
51 "cmd_screenchange", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
52 "cmd_fieldvalue/setfield", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
53 "cmd_getfield", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
54 "cmd_screenwatch", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
55 "cmd_depress", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
56 "cmd_showurl", |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
57 "cmd_switchsession", |
460
4776062555f3
compile 32 and 64 bit arch, bump version
Carl Byington <carl@five-ten-sg.com>
parents:
459
diff
changeset
|
58 "cmd_cursorrequest", |
459
a3239022798d
compile 32 and 64 bit arch, bump version
Carl Byington <carl@five-ten-sg.com>
parents:
457
diff
changeset
|
59 "cmd_saystring" |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
60 }; |
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
61 |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
62 public static final char CURSOR_REQUESTED = 0; |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
63 public static final char CURSOR_SCREEN_CHANGE = 1; |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
64 public static final char CURSOR_USER_KEY = 2; |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
65 |
0 | 66 private static final int MONITORPORT = 6000; |
67 | |
68 private Context parent = null; | |
69 private vt320 buffer = null; | |
70 private View view = null; | |
174
b010f9dc801f
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
173
diff
changeset
|
71 private HostBean host = null; |
470
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
72 private Uri uri = null; |
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
73 private String target = null; |
0 | 74 private String init = null; |
75 private int start_line = 0; // monitor part of the screen for changes | |
76 private int end_line = 500; // "" | |
77 private int start_column = 0; // "" | |
78 private int end_column = 500; // "" | |
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
79 private boolean modified = false; // used to delay screen change notifications |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
80 private boolean moved = false; // used to delay cursor moved notifications |
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
81 private int to_line = 0; // "" |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
82 private int to_column = 0; // "" |
113
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
83 private HashMap<Integer, Integer> keymap = null; // map MS VK_ keys to vt320 virtual keys |
0 | 84 private IBinder bound = null; |
85 private Socket monitor_socket = null; | |
86 private InputStream monitor_in = null; | |
87 private OutputStream monitor_out = null; | |
88 private MyReader monitor_reader = null; | |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
89 private BlockingQueue<char[]> pending_commands = new ArrayBlockingQueue<char[]>(100); |
0 | 90 private MyServiceConnection monitor_connection = new MyServiceConnection(); |
91 | |
92 class MyReader extends Thread { | |
93 private InputStream monitor_in; | |
94 private byte[] b; | |
95 private boolean is_closing = false; | |
96 | |
97 public MyReader(InputStream monitor_in) { | |
98 this.monitor_in = monitor_in; | |
99 b = new byte[100]; | |
100 Log.i(TAG, "MyReader constructor"); | |
101 } | |
102 | |
103 public void closing() { | |
104 is_closing = true; | |
105 } | |
106 | |
107 private char[] forceRead(int len) throws IOException { | |
108 int len2 = len * 2; | |
109 int off = 0; | |
110 | |
111 if (b.length < len2) b = new byte[len2]; | |
112 | |
113 while (off < len2) { | |
114 int l = monitor_in.read(b, off, len2 - off); | |
115 | |
116 if (l < 0) throw new IOException("eof"); | |
117 | |
118 off += l; | |
119 } | |
120 | |
121 return bytesToChars(b, len2); | |
122 } | |
123 | |
124 public void run() { | |
125 while (true) { | |
126 try { | |
127 char[] len = forceRead(1); | |
128 char[] packet = forceRead(len[0]); | |
129 char cmd = packet[0]; | |
425 | 130 Log.i(TAG, String.format("received %s", commands[cmd])); |
0 | 131 |
132 switch (cmd) { | |
133 case MONITOR_CMD_SETFIELD: | |
153
3ca280646f2d
allow zero length setfield
Carl Byington <carl@five-ten-sg.com>
parents:
148
diff
changeset
|
134 if (packet.length >= 3) |
0 | 135 setField(packet[1], packet[2], packet, 3); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
136 |
0 | 137 break; |
138 | |
139 case MONITOR_CMD_GETFIELD: | |
140 if (packet.length == 4) | |
141 getField(packet[1], packet[2], packet[3]); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
142 |
0 | 143 break; |
144 | |
145 case MONITOR_CMD_SCREENWATCH: | |
146 if (packet.length == 4) | |
147 screenWatch(packet[1], packet[2], packet[3]); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
148 |
0 | 149 break; |
150 | |
151 case MONITOR_CMD_DEPRESS: | |
152 if (packet.length == 2) | |
153 depress(packet[1]); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
154 |
0 | 155 break; |
156 | |
155 | 157 case MONITOR_CMD_SHOWURL: |
158 if (packet.length > 1) | |
159 showUrl(packet, 1); | |
160 | |
161 break; | |
162 | |
173
5f26d0ba6abd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
172
diff
changeset
|
163 case MONITOR_CMD_SWITCHSESSION: |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
164 if (packet.length == 1) |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
165 switchSession(); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
166 |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
167 break; |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
168 |
205
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
169 case MONITOR_CMD_CURSORREQUEST: |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
170 if (packet.length == 1) |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
171 cursorRequest(); |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
172 |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
173 break; |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
174 |
0 | 175 default: |
176 break; | |
177 } | |
178 } | |
179 catch (IOException e) { | |
180 if (!is_closing) Log.e(TAG, "exception in MyReader.run()", e); | |
181 | |
182 break; | |
183 } | |
184 } | |
185 } | |
186 } | |
187 | |
188 class MyServiceConnection implements ServiceConnection { | |
189 public void onServiceConnected(ComponentName className, IBinder service) { | |
190 bound = service; | |
191 Log.i(TAG, "bound to service"); | |
477
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
192 DoConnect(); |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
193 } |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
194 public void DoConnect() { |
0 | 195 try { |
470
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
196 InetAddress serverAddr = InetAddress.getByName(target); |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
197 int tries = 0; |
411
8bff0bfaec3a
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
410
diff
changeset
|
198 while (tries < 10) { |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
199 try { |
411
8bff0bfaec3a
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
410
diff
changeset
|
200 Thread.sleep(100); |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
201 monitor_socket = new Socket(serverAddr, MONITORPORT); |
421
660ac2d2003b
break out of infinite loop
Carl Byington <carl@five-ten-sg.com>
parents:
418
diff
changeset
|
202 break; |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
203 } |
412
057854c77217
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
411
diff
changeset
|
204 catch (Exception e) { |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
205 monitor_socket = null; |
410
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
206 Log.e(TAG, "exception connecting to monitor socket", e); |
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
207 tries = tries + 1; |
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
208 } |
e2a56e383bad
wait for monitor socket to be created
Carl Byington <carl@five-ten-sg.com>
parents:
405
diff
changeset
|
209 } |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
210 if (monitor_socket != null) { |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
211 Log.i(TAG, "connected to monitor socket, send init " + init); |
492
e88d48be89a8
add TCP_NODELAY to the monitor socket
Carl Byington <carl@five-ten-sg.com>
parents:
479
diff
changeset
|
212 monitor_socket.setTcpNoDelay(true); |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
213 monitor_in = monitor_socket.getInputStream(); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
214 monitor_out = monitor_socket.getOutputStream(); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
215 monitor_reader = new MyReader(monitor_in); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
216 monitor_reader.start(); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
217 String x = " " + init; |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
218 monitorWrite(MONITOR_CMD_INIT, x.toCharArray()); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
219 char [] c; |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
220 |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
221 while (true) { |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
222 c = pending_commands.poll(); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
223 |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
224 if (c == null) break; |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
225 |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
226 monitorWrite(c[1], c); |
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
227 } |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
228 } |
0 | 229 } |
230 catch (IOException e) { | |
231 Log.e(TAG, "exception in onServiceConnected()", e); | |
232 } | |
233 } | |
234 public void onServiceDisconnected(ComponentName classNam) { | |
235 bound = null; | |
236 Log.i(TAG, "unbound from service"); | |
237 } | |
238 }; | |
239 | |
240 | |
470
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
241 public TerminalMonitor(Context parent, vt320 buffer, View view, HostBean host, String url) { |
0 | 242 this.parent = parent; |
243 this.buffer = buffer; | |
244 this.view = view; | |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
245 this.host = host; |
470
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
246 this.uri = Uri.parse(url); |
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
247 this.target = uri.getHost(); |
2cc170e3fc9b
audible bell checkbox enables/disables bell volume setting; monitor init string is now a url socket://target/initstring
Carl Byington <carl@five-ten-sg.com>
parents:
460
diff
changeset
|
248 this.init = uri.getPath(); |
0 | 249 // setup the windows->android keymapping |
19
b3d0d806cbe2
cleaner url for MS vk_ key documentation
Carl Byington <carl@five-ten-sg.com>
parents:
18
diff
changeset
|
250 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
251 keymap = new HashMap<Integer, Integer>(); |
113
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
252 keymap.put(0x08, vt320.KEY_BACK_SPACE); // vk_back |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
253 keymap.put(0x09, vt320.KEY_TAB); // vk_tab |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
254 keymap.put(0x0d, vt320.KEY_ENTER); // vk_return |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
255 keymap.put(0x1b, vt320.KEY_ESCAPE); // vk_escape |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
256 keymap.put(0x21, vt320.KEY_PAGE_UP); // vk_prior |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
257 keymap.put(0x22, vt320.KEY_PAGE_DOWN); // vk_next |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
258 keymap.put(0x23, vt320.KEY_END); // vk_end |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
259 keymap.put(0x24, vt320.KEY_HOME); // vk_home |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
260 keymap.put(0x25, vt320.KEY_LEFT); // vk_left |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
261 keymap.put(0x26, vt320.KEY_UP); // vk_up |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
262 keymap.put(0x27, vt320.KEY_RIGHT); // vk_right |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
263 keymap.put(0x28, vt320.KEY_DOWN); // vk_down |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
264 keymap.put(0x2d, vt320.KEY_INSERT); // vk_insert |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
265 keymap.put(0x2e, vt320.KEY_DELETE); // vk_delete |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
266 keymap.put(0x70, vt320.KEY_F1); // vk_f1 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
267 keymap.put(0x71, vt320.KEY_F2); // vk_f2 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
268 keymap.put(0x72, vt320.KEY_F3); // vk_f3 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
269 keymap.put(0x73, vt320.KEY_F4); // vk_f4 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
270 keymap.put(0x74, vt320.KEY_F5); // vk_f5 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
271 keymap.put(0x75, vt320.KEY_F6); // vk_f6 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
272 keymap.put(0x76, vt320.KEY_F7); // vk_f7 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
273 keymap.put(0x77, vt320.KEY_F8); // vk_f8 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
274 keymap.put(0x78, vt320.KEY_F9); // vk_f9 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
275 keymap.put(0x79, vt320.KEY_F10); // vk_f10 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
276 keymap.put(0x7a, vt320.KEY_F11); // vk_f11 |
cb3b9b660b3d
depress() keys from the terminal monitor go straight thru buffer.keyPressed() rather than detour though the key listener
Carl Byington <carl@five-ten-sg.com>
parents:
112
diff
changeset
|
277 keymap.put(0x7b, vt320.KEY_F12); // vk_f12 |
176 | 278 keymap.put(0x7c, vt320.KEY_F13); // vk_f13 |
279 keymap.put(0x7d, vt320.KEY_F14); // vk_f14 | |
280 keymap.put(0x7e, vt320.KEY_F15); // vk_f15 | |
281 keymap.put(0x7f, vt320.KEY_F16); // vk_f16 | |
282 keymap.put(0x80, vt320.KEY_F17); // vk_f17 | |
283 keymap.put(0x81, vt320.KEY_F18); // vk_f18 | |
284 keymap.put(0x82, vt320.KEY_F19); // vk_f19 | |
285 keymap.put(0x83, vt320.KEY_F20); // vk_f20 | |
286 keymap.put(0x84, vt320.KEY_F21); // vk_f21 | |
287 keymap.put(0x85, vt320.KEY_F22); // vk_f22 | |
288 keymap.put(0x86, vt320.KEY_F23); // vk_f23 | |
289 keymap.put(0x87, vt320.KEY_F24); // vk_f24 | |
479
3a83f40439d7
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
477
diff
changeset
|
290 if (target.equals("localhost")) { |
477
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
291 // bind to the monitor service for localhost connections |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
292 Intent intent = new Intent("com.five_ten_sg.connectbot.monitor.MonitorService"); |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
293 intent.setPackage("com.five_ten_sg.connectbot.monitor"); |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
294 parent.bindService(intent, monitor_connection, Context.BIND_AUTO_CREATE); |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
295 } |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
296 else { |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
297 // direct socket connection to external device |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
298 monitor_connection.DoConnect(); |
d7461da8145b
only bind to the MonitorService for localhost monitor connections
Carl Byington <carl@five-ten-sg.com>
parents:
470
diff
changeset
|
299 } |
0 | 300 Log.i(TAG, "constructor"); |
301 } | |
302 | |
303 | |
304 public void Disconnect() { | |
305 if (monitor_reader != null) monitor_reader.closing(); | |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
306 |
0 | 307 try { |
308 if (monitor_out != null) monitor_out.close(); | |
309 | |
310 if (monitor_in != null) monitor_in.close(); | |
311 | |
312 if (monitor_socket != null) monitor_socket.close(); | |
313 | |
314 Log.i(TAG, "disconnected from monitor socket"); | |
315 } | |
316 catch (IOException e) { | |
317 Log.e(TAG, "exception in Disconnect() closing sockets", e); | |
318 } | |
319 | |
320 monitor_reader = null; | |
321 monitor_out = null; | |
322 monitor_in = null; | |
323 monitor_socket = null; | |
324 | |
325 if (bound != null) parent.unbindService(monitor_connection); | |
326 | |
327 monitor_connection = null; | |
328 } | |
329 | |
330 | |
331 public char[] bytesToChars(byte[] b, int len) { | |
332 char[] c = new char[len >> 1]; | |
333 int bp = 0; | |
334 | |
335 for (int i = 0; i < c.length; i++) { | |
336 byte b1 = b[bp++]; | |
337 byte b2 = b[bp++]; | |
338 c[i] = (char)(((b1 & 0x00FF) << 8) + (b2 & 0x00FF)); | |
339 } | |
340 | |
341 return c; | |
342 } | |
343 | |
344 | |
345 public byte[] charsToBytes(char[] c) { | |
346 byte[] b = new byte[c.length << 1]; | |
347 int bp = 0; | |
348 | |
349 for (int i = 0; i < c.length; i++) { | |
350 b[bp++] = (byte)((c[i] & 0xff00) >> 8); | |
351 b[bp++] = (byte)(c[i] & 0x00ff); | |
352 } | |
353 | |
354 return b; | |
355 } | |
356 | |
357 | |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
358 public synchronized void monitorWrite(char cmd, char[] c) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
359 try { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
360 if (monitor_out != null) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
361 c[0] = (char)(c.length - 1); // number of chars following |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
362 c[1] = cmd; |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
363 Log.i(TAG, String.format("sending %s", commands[cmd])); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
364 monitor_out.write(charsToBytes(c)); |
424
09c1d3aae3f0
updateDirty before testChanged, try to eliminate sending duplicate screenChanged to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
422
diff
changeset
|
365 monitor_out.flush(); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
366 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
367 else { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
368 c[1] = cmd; |
417
4dcc071e1feb
monitor failure should not kill the TE
Carl Byington <carl@five-ten-sg.com>
parents:
412
diff
changeset
|
369 pending_commands.offer(c); |
402
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
370 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
371 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
372 catch (IOException e) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
373 Log.i(TAG, "exception in monitorWrite(), monitor died or closed the socket", e); |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
374 |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
375 try { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
376 monitor_out.close(); |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
377 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
378 catch (IOException ee) { |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
379 Log.e(TAG, "exception in monitorWrite() closing output stream", ee); |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
380 } |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
381 |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
382 monitor_out = null; |
14aa0621aa7d
Backed out changeset 2f2b5a244a4d
Carl Byington <carl@five-ten-sg.com>
parents:
401
diff
changeset
|
383 } |
0 | 384 }; |
385 | |
227
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
386 public void resetWatch() { |
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
387 start_line = 0; |
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
388 end_line = 500; |
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
389 start_column = 0; |
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
390 end_column = 500; |
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
391 }; |
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
392 |
0 | 393 public void sendScreen(char cmd) { |
394 char lines = (char)(buffer.height & 0x0000ffff); | |
395 char columns = (char)(buffer.width & 0x0000ffff); | |
396 char[] arg = new char[4 + lines * columns]; | |
397 arg[2] = lines; | |
398 arg[3] = columns; | |
399 int base = 4; | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
400 |
0 | 401 for (int i = 0; i < lines; i++) { |
402 System.arraycopy(buffer.charArray[buffer.screenBase + i], 0, arg, base, columns); | |
403 base += columns; | |
404 } | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
405 |
0 | 406 monitorWrite(cmd, arg); |
227
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
parents:
212
diff
changeset
|
407 resetWatch(); |
0 | 408 } |
409 | |
410 public synchronized void activate() { | |
411 sendScreen(MONITOR_CMD_ACTIVATE); | |
235
ea49747c5447
activate needs to send a cursor update
Carl Byington <carl@five-ten-sg.com>
parents:
229
diff
changeset
|
412 cursorMoved(CURSOR_SCREEN_CHANGE); |
0 | 413 } |
414 | |
148
69333ca1563c
add ptt button p2 preference
Carl Byington <carl@five-ten-sg.com>
parents:
147
diff
changeset
|
415 public synchronized void keyState(boolean down) { |
0 | 416 char[] arg = new char[3]; |
148
69333ca1563c
add ptt button p2 preference
Carl Byington <carl@five-ten-sg.com>
parents:
147
diff
changeset
|
417 arg[2] = (char)((down) ? 1 : 0); |
147
1350adb077b1
monitor key state tracking
Carl Byington <carl@five-ten-sg.com>
parents:
145
diff
changeset
|
418 monitorWrite(MONITOR_CMD_KEYSTATE, arg); |
0 | 419 } |
420 | |
421 public synchronized void cursorMove(int l, int c) { | |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
422 if ((to_line != l) || (to_column != c)) moved = true; |
307 | 423 |
17
02717d15de9b
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
424 to_line = l; |
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
425 to_column = c; |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
426 } |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
427 |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
428 public void cursorMoved(char why) { |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
429 char[] arg = new char[5]; |
18
49fc5fba28f3
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
17
diff
changeset
|
430 arg[2] = (char)(to_line & 0x0000ffff); |
49fc5fba28f3
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
17
diff
changeset
|
431 arg[3] = (char)(to_column & 0x0000ffff); |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
432 arg[4] = why; |
0 | 433 monitorWrite(MONITOR_CMD_CURSORMOVE, arg); |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
434 moved = false; |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
435 } |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
436 |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
437 public void testMoved() { |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
438 if (moved) cursorMoved(CURSOR_USER_KEY); |
0 | 439 } |
440 | |
441 public synchronized void testChanged() { | |
442 if (modified) { | |
443 modified = false; | |
444 sendScreen(MONITOR_CMD_SCREENCHANGE); | |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
445 cursorMoved(CURSOR_SCREEN_CHANGE); |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
446 } |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
447 else { |
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
448 if (moved) cursorMoved(CURSOR_SCREEN_CHANGE); |
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
449 } |
0 | 450 } |
451 | |
452 public synchronized void screenChanged(int llow, int lhigh, int clow, int chigh) { | |
453 if ((start_line <= lhigh) && (llow <= end_line) && (start_column <= chigh) && (clow <= end_column)) { | |
454 modified = true; | |
455 } | |
456 } | |
457 | |
458 public synchronized void screenChanged(int l, int c) { | |
459 screenChanged(l, l, c, c); | |
460 } | |
461 | |
462 public synchronized void setField(int l, int c, char[] data, int offset) { | |
250
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
463 int len = data.length - offset; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
464 char[] da = new char[len]; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
465 System.arraycopy(data, offset, da, 0, len); |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
466 Log.i(TAG, String.format("setField(line %d, col %d, value %s)", l, c, new String(da))); |
307 | 467 |
250
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
468 if ((l > 60000) || (c > 60000)) { |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
469 l = -1; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
470 c = -1; |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
471 } |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
472 else { |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
473 // ignore setfield outside screen boundaries |
405
d3c5480e8441
fix broken fillRegenerationBuffer/fillScreenArray attempt to handle missing attributes; fix setfield outside screen boundaries
Carl Byington <carl@five-ten-sg.com>
parents:
404
diff
changeset
|
474 if ((l >= buffer.height) || (c + len > buffer.width)) return; |
250
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
475 } |
307 | 476 |
100 | 477 buffer.setField(l, c, da); |
0 | 478 } |
479 | |
155 | 480 public synchronized void showUrl(char [] data, int offset) { |
481 char[] da = new char[data.length - offset]; | |
307 | 482 System.arraycopy(data, offset, da, 0, data.length - offset); |
155 | 483 String url = new String(da); |
484 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | |
485 parent.startActivity(intent); | |
486 } | |
487 | |
0 | 488 public synchronized void getField(int l, int c, int len) { |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
489 Log.i(TAG, String.format("getField(line %d, col %d, len %d)", l, c, len)); |
0 | 490 char[] arg2 = new char[4 + len]; |
491 arg2[2] = (char)(l & 0x0000ffff); | |
492 arg2[3] = (char)(c & 0x0000ffff); | |
493 int base = 4; | |
307 | 494 |
404
ec74f347ab5f
fix bad args to arrays.fill(); bump version number
Carl Byington <carl@five-ten-sg.com>
parents:
402
diff
changeset
|
495 if ((l >= buffer.height) || (c + len > buffer.width)) { |
ec74f347ab5f
fix bad args to arrays.fill(); bump version number
Carl Byington <carl@five-ten-sg.com>
parents:
402
diff
changeset
|
496 Arrays.fill(arg2, base, base + len, ' '); |
250
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
497 } |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
498 else { |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
499 System.arraycopy(buffer.charArray[buffer.screenBase + l], c, arg2, base, len); |
2bf2724d8610
add range checking on get/set fields
Carl Byington <carl@five-ten-sg.com>
parents:
235
diff
changeset
|
500 } |
307 | 501 |
422
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
502 char[] da = new char[len]; |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
503 System.arraycopy(arg2, base, da, 0, len); |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
504 Log.i(TAG, String.format("getField value %s", new String(da))); |
651aff5a46c7
synchronize font size listeners; log get/set field values
Carl Byington <carl@five-ten-sg.com>
parents:
421
diff
changeset
|
505 |
0 | 506 monitorWrite(MONITOR_CMD_FIELDVALUE, arg2); |
507 } | |
508 | |
509 public synchronized void screenWatch(int l, int c, int len) { | |
425 | 510 Log.i(TAG, String.format("screenWatch(line %d, col %d, len %d)", l, c, len)); |
0 | 511 start_line = l; |
512 end_line = l; | |
513 start_column = c; | |
514 end_column = c + len - 1; | |
515 } | |
516 | |
517 public synchronized void depress(int vk_key) { | |
425 | 518 Log.i(TAG, String.format("depress(%d)", vk_key)); |
0 | 519 Integer x = keymap.get(new Integer(vk_key)); |
307 | 520 |
175
2a7199ad90be
send cursor movement caused by user keystrokes to the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
174
diff
changeset
|
521 if (x != null) buffer.keyDepressed(x, ' ', 0); |
0 | 522 } |
172
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
523 |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
524 public synchronized void switchSession() { |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
525 Log.i(TAG, "switchSession()"); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
526 Intent intent = new Intent(parent, ConsoleActivity.class); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
527 intent.setAction(Intent.ACTION_VIEW); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
528 intent.setData(host.getUri()); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
529 parent.startActivity(intent); |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
530 } |
cb9e359ea2bd
add switch session command from the monitor
Carl Byington <carl@five-ten-sg.com>
parents:
155
diff
changeset
|
531 |
205
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
532 |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
533 public synchronized void cursorRequest() { |
229
594101a0876a
add why argument on cursor updates
Carl Byington <carl@five-ten-sg.com>
parents:
227
diff
changeset
|
534 cursorMoved(CURSOR_REQUESTED); |
205
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
535 } |
f86f1e37b504
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
176
diff
changeset
|
536 |
0 | 537 } |