Mercurial > 510Connectbot
annotate src/com/five_ten_sg/connectbot/service/TerminalMonitor.java @ 161:490bae26d3a2
Added tag stable-1.8.1 for changeset 4bccac50fd0b
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 24 Jun 2014 08:18:26 -0700 |
parents | 156b53fc4815 |
children | cb9e359ea2bd |
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; | |
18 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
|
19 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
|
20 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
|
21 import java.util.concurrent.ConcurrentHashMap; |
0 | 22 |
23 public class TerminalMonitor { | |
24 public final static String TAG = "ConnectBot.TerminalMonitor"; | |
25 | |
26 public static final char MONITOR_CMD_INIT = 0; | |
27 public static final char MONITOR_CMD_ACTIVATE = 1; | |
147
1350adb077b1
monitor key state tracking
Carl Byington <carl@five-ten-sg.com>
parents:
145
diff
changeset
|
28 public static final char MONITOR_CMD_KEYSTATE = 2; |
0 | 29 public static final char MONITOR_CMD_CURSORMOVE = 3; |
30 public static final char MONITOR_CMD_SCREENCHANGE = 4; | |
31 public static final char MONITOR_CMD_FIELDVALUE = 5; | |
32 public static final char MONITOR_CMD_SETFIELD = 5; | |
33 public static final char MONITOR_CMD_GETFIELD = 6; | |
34 public static final char MONITOR_CMD_SCREENWATCH = 7; | |
35 public static final char MONITOR_CMD_DEPRESS = 8; | |
155 | 36 public static final char MONITOR_CMD_SHOWURL = 9; |
0 | 37 |
38 private static final int MONITORPORT = 6000; | |
39 private static final String LOCALHOST = "127.0.0.1"; | |
40 | |
41 private Context parent = null; | |
42 private vt320 buffer = null; | |
43 private View view = null; | |
44 private String init = null; | |
45 private int start_line = 0; // monitor part of the screen for changes | |
46 private int end_line = 500; // "" | |
47 private int start_column = 0; // "" | |
48 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
|
49 private boolean modified = false; // used to delay screen change notifications |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
50 private boolean moved = false; // used to delay cursor moved notifications |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
51 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
|
52 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
|
53 private HashMap<Integer, Integer> keymap = null; // map MS VK_ keys to vt320 virtual keys |
0 | 54 private IBinder bound = null; |
55 private Socket monitor_socket = null; | |
56 private InputStream monitor_in = null; | |
57 private OutputStream monitor_out = null; | |
58 private MyReader monitor_reader = null; | |
15
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
59 private BlockingQueue<char[]> pending_commands = new ArrayBlockingQueue<char[]>(100); |
0 | 60 private MyServiceConnection monitor_connection = new MyServiceConnection(); |
61 | |
62 class MyReader extends Thread { | |
63 private InputStream monitor_in; | |
64 private byte[] b; | |
65 private boolean is_closing = false; | |
66 | |
67 public MyReader(InputStream monitor_in) { | |
68 this.monitor_in = monitor_in; | |
69 b = new byte[100]; | |
70 Log.i(TAG, "MyReader constructor"); | |
71 } | |
72 | |
73 public void closing() { | |
74 is_closing = true; | |
75 } | |
76 | |
77 private char[] forceRead(int len) throws IOException { | |
78 int len2 = len * 2; | |
79 int off = 0; | |
80 | |
81 if (b.length < len2) b = new byte[len2]; | |
82 | |
83 while (off < len2) { | |
84 int l = monitor_in.read(b, off, len2 - off); | |
85 | |
86 if (l < 0) throw new IOException("eof"); | |
87 | |
88 off += l; | |
89 } | |
90 | |
91 return bytesToChars(b, len2); | |
92 } | |
93 | |
94 public void run() { | |
95 while (true) { | |
96 try { | |
97 char[] len = forceRead(1); | |
98 char[] packet = forceRead(len[0]); | |
99 char cmd = packet[0]; | |
100 Log.i(TAG, String.format("received %d command", (int)cmd)); | |
101 | |
102 switch (cmd) { | |
103 case MONITOR_CMD_SETFIELD: | |
153
3ca280646f2d
allow zero length setfield
Carl Byington <carl@five-ten-sg.com>
parents:
148
diff
changeset
|
104 if (packet.length >= 3) |
0 | 105 setField(packet[1], packet[2], packet, 3); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
106 |
0 | 107 break; |
108 | |
109 case MONITOR_CMD_GETFIELD: | |
110 if (packet.length == 4) | |
111 getField(packet[1], packet[2], packet[3]); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
112 |
0 | 113 break; |
114 | |
115 case MONITOR_CMD_SCREENWATCH: | |
116 if (packet.length == 4) | |
117 screenWatch(packet[1], packet[2], packet[3]); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
118 |
0 | 119 break; |
120 | |
121 case MONITOR_CMD_DEPRESS: | |
122 if (packet.length == 2) | |
123 depress(packet[1]); | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
124 |
0 | 125 break; |
126 | |
155 | 127 case MONITOR_CMD_SHOWURL: |
128 if (packet.length > 1) | |
129 showUrl(packet, 1); | |
130 | |
131 break; | |
132 | |
0 | 133 default: |
134 break; | |
135 } | |
136 } | |
137 catch (IOException e) { | |
138 if (!is_closing) Log.e(TAG, "exception in MyReader.run()", e); | |
139 | |
140 break; | |
141 } | |
142 } | |
143 } | |
144 } | |
145 | |
146 class MyServiceConnection implements ServiceConnection { | |
147 public void onServiceConnected(ComponentName className, IBinder service) { | |
148 bound = service; | |
149 Log.i(TAG, "bound to service"); | |
150 | |
151 try { | |
152 InetAddress serverAddr = InetAddress.getByName(LOCALHOST); | |
153 monitor_socket = new Socket(serverAddr, MONITORPORT); | |
154 monitor_in = monitor_socket.getInputStream(); | |
155 monitor_out = monitor_socket.getOutputStream(); | |
156 Log.i(TAG, "connected to monitor socket, send init " + init); | |
157 monitor_reader = new MyReader(monitor_in); | |
158 monitor_reader.start(); | |
159 String x = " " + init; | |
160 monitorWrite(MONITOR_CMD_INIT, x.toCharArray()); | |
15
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
161 char [] c; |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
162 |
15
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
163 while (true) { |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
164 c = pending_commands.poll(); |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
165 |
15
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
166 if (c == null) break; |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
167 |
15
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
168 monitorWrite(c[1], c); |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
169 } |
0 | 170 } |
171 catch (IOException e) { | |
172 Log.e(TAG, "exception in onServiceConnected()", e); | |
173 } | |
174 } | |
175 public void onServiceDisconnected(ComponentName classNam) { | |
176 bound = null; | |
177 Log.i(TAG, "unbound from service"); | |
178 } | |
179 }; | |
180 | |
181 | |
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
|
182 public TerminalMonitor(Context parent, vt320 buffer, View view, String init) { |
0 | 183 this.parent = parent; |
184 this.buffer = buffer; | |
185 this.view = view; | |
186 this.init = init; | |
187 // 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
|
188 // 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
|
189 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
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 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
|
200 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
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 keymap.put(0x7b, vt320.KEY_F12); // vk_f12 |
0 | 216 // bind to the monitor service |
217 Intent intent = new Intent("com.five_ten_sg.connectbot.monitor.MonitorService"); | |
218 parent.bindService(intent, monitor_connection, Context.BIND_AUTO_CREATE); | |
219 Log.i(TAG, "constructor"); | |
220 } | |
221 | |
222 | |
223 public void Disconnect() { | |
224 if (monitor_reader != null) monitor_reader.closing(); | |
225 | |
226 try { | |
227 if (monitor_out != null) monitor_out.close(); | |
228 | |
229 if (monitor_in != null) monitor_in.close(); | |
230 | |
231 if (monitor_socket != null) monitor_socket.close(); | |
232 | |
233 Log.i(TAG, "disconnected from monitor socket"); | |
234 } | |
235 catch (IOException e) { | |
236 Log.e(TAG, "exception in Disconnect() closing sockets", e); | |
237 } | |
238 | |
239 monitor_reader = null; | |
240 monitor_out = null; | |
241 monitor_in = null; | |
242 monitor_socket = null; | |
243 | |
244 if (bound != null) parent.unbindService(monitor_connection); | |
245 | |
246 monitor_connection = null; | |
247 } | |
248 | |
249 | |
250 public char[] bytesToChars(byte[] b, int len) { | |
251 char[] c = new char[len >> 1]; | |
252 int bp = 0; | |
253 | |
254 for (int i = 0; i < c.length; i++) { | |
255 byte b1 = b[bp++]; | |
256 byte b2 = b[bp++]; | |
257 c[i] = (char)(((b1 & 0x00FF) << 8) + (b2 & 0x00FF)); | |
258 } | |
259 | |
260 return c; | |
261 } | |
262 | |
263 | |
264 public byte[] charsToBytes(char[] c) { | |
265 byte[] b = new byte[c.length << 1]; | |
266 int bp = 0; | |
267 | |
268 for (int i = 0; i < c.length; i++) { | |
269 b[bp++] = (byte)((c[i] & 0xff00) >> 8); | |
270 b[bp++] = (byte)(c[i] & 0x00ff); | |
271 } | |
272 | |
273 return b; | |
274 } | |
275 | |
276 | |
277 public synchronized void monitorWrite(char cmd, char[] c) { | |
278 try { | |
279 if (monitor_out != null) { | |
280 c[0] = (char)(c.length - 1); // number of chars following | |
281 c[1] = cmd; | |
282 //Log.i(TAG, String.format("sending %d command", (int)cmd)); | |
283 monitor_out.write(charsToBytes(c)); | |
284 } | |
15
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
285 else { |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
286 c[1] = cmd; |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
287 pending_commands.put(c); |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
288 } |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
289 } |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
290 catch (InterruptedException e) { |
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
291 Log.e(TAG, "exception in monitorWrite()", e); |
0 | 292 } |
293 catch (IOException e) { | |
294 Log.i(TAG, "exception in monitorWrite(), monitor died or closed the socket", e); | |
295 | |
296 try { | |
297 monitor_out.close(); | |
298 } | |
299 catch (IOException ee) { | |
300 Log.e(TAG, "exception in monitorWrite() closing output stream", ee); | |
301 } | |
302 | |
303 monitor_out = null; | |
304 } | |
305 }; | |
306 | |
307 public void sendScreen(char cmd) { | |
308 char lines = (char)(buffer.height & 0x0000ffff); | |
309 char columns = (char)(buffer.width & 0x0000ffff); | |
310 char[] arg = new char[4 + lines * columns]; | |
311 arg[2] = lines; | |
312 arg[3] = columns; | |
313 int base = 4; | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
314 |
0 | 315 for (int i = 0; i < lines; i++) { |
316 System.arraycopy(buffer.charArray[buffer.screenBase + i], 0, arg, base, columns); | |
317 base += columns; | |
318 } | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
319 |
0 | 320 monitorWrite(cmd, arg); |
321 } | |
322 | |
323 public synchronized void activate() { | |
324 sendScreen(MONITOR_CMD_ACTIVATE); | |
325 } | |
326 | |
148
69333ca1563c
add ptt button p2 preference
Carl Byington <carl@five-ten-sg.com>
parents:
147
diff
changeset
|
327 public synchronized void keyState(boolean down) { |
0 | 328 char[] arg = new char[3]; |
148
69333ca1563c
add ptt button p2 preference
Carl Byington <carl@five-ten-sg.com>
parents:
147
diff
changeset
|
329 arg[2] = (char)((down) ? 1 : 0); |
147
1350adb077b1
monitor key state tracking
Carl Byington <carl@five-ten-sg.com>
parents:
145
diff
changeset
|
330 monitorWrite(MONITOR_CMD_KEYSTATE, arg); |
0 | 331 } |
332 | |
333 public synchronized void cursorMove(int l, int c) { | |
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
334 moved = true; |
17
02717d15de9b
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
335 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
|
336 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
|
337 } |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
338 |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
339 public void cursorMoved() { |
0 | 340 char[] arg = new char[4]; |
18
49fc5fba28f3
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
17
diff
changeset
|
341 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
|
342 arg[3] = (char)(to_column & 0x0000ffff); |
0 | 343 monitorWrite(MONITOR_CMD_CURSORMOVE, arg); |
344 } | |
345 | |
346 public synchronized void testChanged() { | |
347 if (modified) { | |
348 modified = false; | |
349 sendScreen(MONITOR_CMD_SCREENCHANGE); | |
350 } | |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
351 |
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
352 if (moved) { |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
353 moved = false; |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
354 cursorMoved(); |
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
parents:
15
diff
changeset
|
355 } |
0 | 356 } |
357 | |
358 public synchronized void screenChanged(int llow, int lhigh, int clow, int chigh) { | |
359 if ((start_line <= lhigh) && (llow <= end_line) && (start_column <= chigh) && (clow <= end_column)) { | |
360 modified = true; | |
361 } | |
362 } | |
363 | |
364 public synchronized void screenChanged(int l, int c) { | |
365 screenChanged(l, l, c, c); | |
366 } | |
367 | |
368 public synchronized void setField(int l, int c, char[] data, int offset) { | |
369 Log.i(TAG, "setField()"); | |
101 | 370 char[] da = new char[data.length - offset]; |
15
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
371 int i; |
112
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
372 |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
373 for (i = 0; i < da.length; i++) { |
77ac18bc1b2f
cleanup java formatting
Carl Byington <carl@five-ten-sg.com>
parents:
101
diff
changeset
|
374 da[i] = data[i + offset]; |
15
1588e359a972
queue pending monitor commands until socket is open
Carl Byington <carl@five-ten-sg.com>
parents:
0
diff
changeset
|
375 } |
145
4dfa4dd791c1
testing setfield functions
Carl Byington <carl@five-ten-sg.com>
parents:
142
diff
changeset
|
376 |
100 | 377 buffer.setField(l, c, da); |
0 | 378 } |
379 | |
155 | 380 public synchronized void showUrl(char [] data, int offset) { |
381 Log.i(TAG, "setField()"); | |
382 char[] da = new char[data.length - offset]; | |
383 int i; | |
384 | |
385 for (i = 0; i < da.length; i++) { | |
386 da[i] = data[i + offset]; | |
387 } | |
388 String url = new String(da); | |
389 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); | |
390 parent.startActivity(intent); | |
391 } | |
392 | |
0 | 393 public synchronized void getField(int l, int c, int len) { |
394 Log.i(TAG, "getField()"); | |
395 char[] arg2 = new char[4 + len]; | |
396 arg2[2] = (char)(l & 0x0000ffff); | |
397 arg2[3] = (char)(c & 0x0000ffff); | |
398 int base = 4; | |
399 System.arraycopy(buffer.charArray[buffer.screenBase + l], c, arg2, base, len); | |
400 monitorWrite(MONITOR_CMD_FIELDVALUE, arg2); | |
401 } | |
402 | |
403 public synchronized void screenWatch(int l, int c, int len) { | |
404 Log.i(TAG, "screenWatch()"); | |
405 start_line = l; | |
406 end_line = l; | |
407 start_column = c; | |
408 end_column = c + len - 1; | |
409 } | |
410 | |
411 public synchronized void depress(int vk_key) { | |
412 Log.i(TAG, String.format("depress() %d", vk_key)); | |
413 Integer x = keymap.get(new Integer(vk_key)); | |
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
|
414 if (x != null) buffer.keyPressed(x, ' ', 0); |
0 | 415 } |
416 } |