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
|
18 import java.util.Arrays;
|
0
|
19 import java.util.HashMap;
|
15
|
20 import java.util.concurrent.ArrayBlockingQueue;
|
|
21 import java.util.concurrent.BlockingQueue;
|
|
22 import java.util.concurrent.ConcurrentHashMap;
|
0
|
23
|
174
|
24 import com.five_ten_sg.connectbot.ConsoleActivity;
|
|
25 import com.five_ten_sg.connectbot.bean.HostBean;
|
|
26
|
|
27
|
0
|
28 public class TerminalMonitor {
|
|
29 public final static String TAG = "ConnectBot.TerminalMonitor";
|
|
30
|
172
|
31 public static final char MONITOR_CMD_INIT = 0;
|
|
32 public static final char MONITOR_CMD_ACTIVATE = 1;
|
|
33 public static final char MONITOR_CMD_KEYSTATE = 2;
|
|
34 public static final char MONITOR_CMD_CURSORMOVE = 3;
|
|
35 public static final char MONITOR_CMD_SCREENCHANGE = 4;
|
|
36 public static final char MONITOR_CMD_FIELDVALUE = 5;
|
|
37 public static final char MONITOR_CMD_SETFIELD = 5;
|
|
38 public static final char MONITOR_CMD_GETFIELD = 6;
|
|
39 public static final char MONITOR_CMD_SCREENWATCH = 7;
|
|
40 public static final char MONITOR_CMD_DEPRESS = 8;
|
|
41 public static final char MONITOR_CMD_SHOWURL = 9;
|
|
42 public static final char MONITOR_CMD_SWITCHSESSION = 10;
|
205
|
43 public static final char MONITOR_CMD_CURSORREQUEST = 11;
|
0
|
44
|
229
|
45 public static final char CURSOR_REQUESTED = 0;
|
|
46 public static final char CURSOR_SCREEN_CHANGE = 1;
|
|
47 public static final char CURSOR_USER_KEY = 2;
|
|
48
|
0
|
49 private static final int MONITORPORT = 6000;
|
|
50 private static final String LOCALHOST = "127.0.0.1";
|
|
51
|
|
52 private Context parent = null;
|
|
53 private vt320 buffer = null;
|
|
54 private View view = null;
|
174
|
55 private HostBean host = null;
|
0
|
56 private String init = null;
|
|
57 private int start_line = 0; // monitor part of the screen for changes
|
|
58 private int end_line = 500; // ""
|
|
59 private int start_column = 0; // ""
|
|
60 private int end_column = 500; // ""
|
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
diff
changeset
|
61 private boolean modified = false; // used to delay screen change notifications
|
229
|
62 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>
diff
changeset
|
63 private int to_line = 0; // ""
|
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
diff
changeset
|
64 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>
diff
changeset
|
65 private HashMap<Integer, Integer> keymap = null; // map MS VK_ keys to vt320 virtual keys
|
0
|
66 private IBinder bound = null;
|
|
67 private Socket monitor_socket = null;
|
|
68 private InputStream monitor_in = null;
|
|
69 private OutputStream monitor_out = null;
|
|
70 private MyReader monitor_reader = null;
|
15
|
71 private BlockingQueue<char[]> pending_commands = new ArrayBlockingQueue<char[]>(100);
|
0
|
72 private MyServiceConnection monitor_connection = new MyServiceConnection();
|
|
73
|
|
74 class MyReader extends Thread {
|
|
75 private InputStream monitor_in;
|
|
76 private byte[] b;
|
|
77 private boolean is_closing = false;
|
|
78
|
|
79 public MyReader(InputStream monitor_in) {
|
|
80 this.monitor_in = monitor_in;
|
|
81 b = new byte[100];
|
|
82 Log.i(TAG, "MyReader constructor");
|
|
83 }
|
|
84
|
|
85 public void closing() {
|
|
86 is_closing = true;
|
|
87 }
|
|
88
|
|
89 private char[] forceRead(int len) throws IOException {
|
|
90 int len2 = len * 2;
|
|
91 int off = 0;
|
|
92
|
|
93 if (b.length < len2) b = new byte[len2];
|
|
94
|
|
95 while (off < len2) {
|
|
96 int l = monitor_in.read(b, off, len2 - off);
|
|
97
|
|
98 if (l < 0) throw new IOException("eof");
|
|
99
|
|
100 off += l;
|
|
101 }
|
|
102
|
|
103 return bytesToChars(b, len2);
|
|
104 }
|
|
105
|
|
106 public void run() {
|
|
107 while (true) {
|
|
108 try {
|
|
109 char[] len = forceRead(1);
|
|
110 char[] packet = forceRead(len[0]);
|
|
111 char cmd = packet[0];
|
|
112 Log.i(TAG, String.format("received %d command", (int)cmd));
|
|
113
|
|
114 switch (cmd) {
|
|
115 case MONITOR_CMD_SETFIELD:
|
153
|
116 if (packet.length >= 3)
|
0
|
117 setField(packet[1], packet[2], packet, 3);
|
112
|
118
|
0
|
119 break;
|
|
120
|
|
121 case MONITOR_CMD_GETFIELD:
|
|
122 if (packet.length == 4)
|
|
123 getField(packet[1], packet[2], packet[3]);
|
112
|
124
|
0
|
125 break;
|
|
126
|
|
127 case MONITOR_CMD_SCREENWATCH:
|
|
128 if (packet.length == 4)
|
|
129 screenWatch(packet[1], packet[2], packet[3]);
|
112
|
130
|
0
|
131 break;
|
|
132
|
|
133 case MONITOR_CMD_DEPRESS:
|
|
134 if (packet.length == 2)
|
|
135 depress(packet[1]);
|
112
|
136
|
0
|
137 break;
|
|
138
|
155
|
139 case MONITOR_CMD_SHOWURL:
|
|
140 if (packet.length > 1)
|
|
141 showUrl(packet, 1);
|
|
142
|
|
143 break;
|
|
144
|
173
|
145 case MONITOR_CMD_SWITCHSESSION:
|
172
|
146 if (packet.length == 1)
|
|
147 switchSession();
|
|
148
|
|
149 break;
|
|
150
|
205
|
151 case MONITOR_CMD_CURSORREQUEST:
|
|
152 if (packet.length == 1)
|
|
153 cursorRequest();
|
|
154
|
|
155 break;
|
|
156
|
0
|
157 default:
|
|
158 break;
|
|
159 }
|
|
160 }
|
|
161 catch (IOException e) {
|
|
162 if (!is_closing) Log.e(TAG, "exception in MyReader.run()", e);
|
|
163
|
|
164 break;
|
|
165 }
|
|
166 }
|
|
167 }
|
|
168 }
|
|
169
|
|
170 class MyServiceConnection implements ServiceConnection {
|
|
171 public void onServiceConnected(ComponentName className, IBinder service) {
|
|
172 bound = service;
|
|
173 Log.i(TAG, "bound to service");
|
|
174
|
|
175 try {
|
|
176 InetAddress serverAddr = InetAddress.getByName(LOCALHOST);
|
|
177 monitor_socket = new Socket(serverAddr, MONITORPORT);
|
|
178 monitor_in = monitor_socket.getInputStream();
|
|
179 monitor_out = monitor_socket.getOutputStream();
|
|
180 Log.i(TAG, "connected to monitor socket, send init " + init);
|
|
181 monitor_reader = new MyReader(monitor_in);
|
|
182 monitor_reader.start();
|
|
183 String x = " " + init;
|
|
184 monitorWrite(MONITOR_CMD_INIT, x.toCharArray());
|
15
|
185 char [] c;
|
112
|
186
|
15
|
187 while (true) {
|
|
188 c = pending_commands.poll();
|
112
|
189
|
15
|
190 if (c == null) break;
|
112
|
191
|
15
|
192 monitorWrite(c[1], c);
|
|
193 }
|
0
|
194 }
|
|
195 catch (IOException e) {
|
|
196 Log.e(TAG, "exception in onServiceConnected()", e);
|
|
197 }
|
|
198 }
|
|
199 public void onServiceDisconnected(ComponentName classNam) {
|
|
200 bound = null;
|
|
201 Log.i(TAG, "unbound from service");
|
|
202 }
|
|
203 };
|
|
204
|
|
205
|
172
|
206 public TerminalMonitor(Context parent, vt320 buffer, View view, HostBean host, String init) {
|
0
|
207 this.parent = parent;
|
|
208 this.buffer = buffer;
|
|
209 this.view = view;
|
172
|
210 this.host = host;
|
0
|
211 this.init = init;
|
|
212 // setup the windows->android keymapping
|
19
|
213 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731
|
112
|
214 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>
diff
changeset
|
215 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>
diff
changeset
|
216 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>
diff
changeset
|
217 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>
diff
changeset
|
218 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>
diff
changeset
|
219 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>
diff
changeset
|
220 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>
diff
changeset
|
221 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>
diff
changeset
|
222 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>
diff
changeset
|
223 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>
diff
changeset
|
224 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>
diff
changeset
|
225 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>
diff
changeset
|
226 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>
diff
changeset
|
227 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>
diff
changeset
|
228 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>
diff
changeset
|
229 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>
diff
changeset
|
230 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>
diff
changeset
|
231 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>
diff
changeset
|
232 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>
diff
changeset
|
233 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>
diff
changeset
|
234 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>
diff
changeset
|
235 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>
diff
changeset
|
236 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>
diff
changeset
|
237 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>
diff
changeset
|
238 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>
diff
changeset
|
239 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>
diff
changeset
|
240 keymap.put(0x7b, vt320.KEY_F12); // vk_f12
|
176
|
241 keymap.put(0x7c, vt320.KEY_F13); // vk_f13
|
|
242 keymap.put(0x7d, vt320.KEY_F14); // vk_f14
|
|
243 keymap.put(0x7e, vt320.KEY_F15); // vk_f15
|
|
244 keymap.put(0x7f, vt320.KEY_F16); // vk_f16
|
|
245 keymap.put(0x80, vt320.KEY_F17); // vk_f17
|
|
246 keymap.put(0x81, vt320.KEY_F18); // vk_f18
|
|
247 keymap.put(0x82, vt320.KEY_F19); // vk_f19
|
|
248 keymap.put(0x83, vt320.KEY_F20); // vk_f20
|
|
249 keymap.put(0x84, vt320.KEY_F21); // vk_f21
|
|
250 keymap.put(0x85, vt320.KEY_F22); // vk_f22
|
|
251 keymap.put(0x86, vt320.KEY_F23); // vk_f23
|
|
252 keymap.put(0x87, vt320.KEY_F24); // vk_f24
|
0
|
253 // bind to the monitor service
|
|
254 Intent intent = new Intent("com.five_ten_sg.connectbot.monitor.MonitorService");
|
|
255 parent.bindService(intent, monitor_connection, Context.BIND_AUTO_CREATE);
|
|
256 Log.i(TAG, "constructor");
|
|
257 }
|
|
258
|
|
259
|
|
260 public void Disconnect() {
|
|
261 if (monitor_reader != null) monitor_reader.closing();
|
|
262
|
|
263 try {
|
|
264 if (monitor_out != null) monitor_out.close();
|
|
265
|
|
266 if (monitor_in != null) monitor_in.close();
|
|
267
|
|
268 if (monitor_socket != null) monitor_socket.close();
|
|
269
|
|
270 Log.i(TAG, "disconnected from monitor socket");
|
|
271 }
|
|
272 catch (IOException e) {
|
|
273 Log.e(TAG, "exception in Disconnect() closing sockets", e);
|
|
274 }
|
|
275
|
|
276 monitor_reader = null;
|
|
277 monitor_out = null;
|
|
278 monitor_in = null;
|
|
279 monitor_socket = null;
|
|
280
|
|
281 if (bound != null) parent.unbindService(monitor_connection);
|
|
282
|
|
283 monitor_connection = null;
|
|
284 }
|
|
285
|
|
286
|
|
287 public char[] bytesToChars(byte[] b, int len) {
|
|
288 char[] c = new char[len >> 1];
|
|
289 int bp = 0;
|
|
290
|
|
291 for (int i = 0; i < c.length; i++) {
|
|
292 byte b1 = b[bp++];
|
|
293 byte b2 = b[bp++];
|
|
294 c[i] = (char)(((b1 & 0x00FF) << 8) + (b2 & 0x00FF));
|
|
295 }
|
|
296
|
|
297 return c;
|
|
298 }
|
|
299
|
|
300
|
|
301 public byte[] charsToBytes(char[] c) {
|
|
302 byte[] b = new byte[c.length << 1];
|
|
303 int bp = 0;
|
|
304
|
|
305 for (int i = 0; i < c.length; i++) {
|
|
306 b[bp++] = (byte)((c[i] & 0xff00) >> 8);
|
|
307 b[bp++] = (byte)(c[i] & 0x00ff);
|
|
308 }
|
|
309
|
|
310 return b;
|
|
311 }
|
|
312
|
|
313
|
|
314 public synchronized void monitorWrite(char cmd, char[] c) {
|
|
315 try {
|
|
316 if (monitor_out != null) {
|
|
317 c[0] = (char)(c.length - 1); // number of chars following
|
|
318 c[1] = cmd;
|
|
319 //Log.i(TAG, String.format("sending %d command", (int)cmd));
|
|
320 monitor_out.write(charsToBytes(c));
|
|
321 }
|
15
|
322 else {
|
|
323 c[1] = cmd;
|
|
324 pending_commands.put(c);
|
|
325 }
|
|
326 }
|
|
327 catch (InterruptedException e) {
|
|
328 Log.e(TAG, "exception in monitorWrite()", e);
|
0
|
329 }
|
|
330 catch (IOException e) {
|
|
331 Log.i(TAG, "exception in monitorWrite(), monitor died or closed the socket", e);
|
|
332
|
|
333 try {
|
|
334 monitor_out.close();
|
|
335 }
|
|
336 catch (IOException ee) {
|
|
337 Log.e(TAG, "exception in monitorWrite() closing output stream", ee);
|
|
338 }
|
|
339
|
|
340 monitor_out = null;
|
|
341 }
|
|
342 };
|
|
343
|
227
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
diff
changeset
|
344 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>
diff
changeset
|
345 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>
diff
changeset
|
346 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>
diff
changeset
|
347 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>
diff
changeset
|
348 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>
diff
changeset
|
349 };
|
2dd627df4dfb
delay testChanged() by 10ms for async transports; sendScreen resets watch area to the entire screen
Carl Byington <carl@five-ten-sg.com>
diff
changeset
|
350
|
0
|
351 public void sendScreen(char cmd) {
|
|
352 char lines = (char)(buffer.height & 0x0000ffff);
|
|
353 char columns = (char)(buffer.width & 0x0000ffff);
|
|
354 char[] arg = new char[4 + lines * columns];
|
|
355 arg[2] = lines;
|
|
356 arg[3] = columns;
|
|
357 int base = 4;
|
112
|
358
|
0
|
359 for (int i = 0; i < lines; i++) {
|
|
360 System.arraycopy(buffer.charArray[buffer.screenBase + i], 0, arg, base, columns);
|
|
361 base += columns;
|
|
362 }
|
112
|
363
|
0
|
364 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>
diff
changeset
|
365 resetWatch();
|
0
|
366 }
|
|
367
|
|
368 public synchronized void activate() {
|
|
369 sendScreen(MONITOR_CMD_ACTIVATE);
|
235
|
370 cursorMoved(CURSOR_SCREEN_CHANGE);
|
0
|
371 }
|
|
372
|
148
|
373 public synchronized void keyState(boolean down) {
|
0
|
374 char[] arg = new char[3];
|
148
|
375 arg[2] = (char)((down) ? 1 : 0);
|
147
|
376 monitorWrite(MONITOR_CMD_KEYSTATE, arg);
|
0
|
377 }
|
|
378
|
|
379 public synchronized void cursorMove(int l, int c) {
|
229
|
380 if ((to_line != l) || (to_column != c)) moved = true;
|
17
02717d15de9b
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
diff
changeset
|
381 to_line = l;
|
16
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
diff
changeset
|
382 to_column = c;
|
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
diff
changeset
|
383 }
|
48a8daea9221
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
diff
changeset
|
384
|
229
|
385 public void cursorMoved(char why) {
|
|
386 char[] arg = new char[5];
|
18
49fc5fba28f3
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
diff
changeset
|
387 arg[2] = (char)(to_line & 0x0000ffff);
|
49fc5fba28f3
delay sending cursor move notifications until the host is quiet
Carl Byington <carl@five-ten-sg.com>
diff
changeset
|
388 arg[3] = (char)(to_column & 0x0000ffff);
|
229
|
389 arg[4] = why;
|
0
|
390 monitorWrite(MONITOR_CMD_CURSORMOVE, arg);
|
229
|
391 moved = false;
|
|
392 }
|
|
393
|
|
394 public void testMoved() {
|
|
395 if (moved) cursorMoved(CURSOR_USER_KEY);
|
0
|
396 }
|
|
397
|
|
398 public synchronized void testChanged() {
|
|
399 if (modified) {
|
|
400 modified = false;
|
|
401 sendScreen(MONITOR_CMD_SCREENCHANGE);
|
229
|
402 cursorMoved(CURSOR_SCREEN_CHANGE);
|
|
403 }
|
|
404 else {
|
|
405 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>
diff
changeset
|
406 }
|
0
|
407 }
|
|
408
|
|
409 public synchronized void screenChanged(int llow, int lhigh, int clow, int chigh) {
|
|
410 if ((start_line <= lhigh) && (llow <= end_line) && (start_column <= chigh) && (clow <= end_column)) {
|
|
411 modified = true;
|
|
412 }
|
|
413 }
|
|
414
|
|
415 public synchronized void screenChanged(int l, int c) {
|
|
416 screenChanged(l, l, c, c);
|
|
417 }
|
|
418
|
|
419 public synchronized void setField(int l, int c, char[] data, int offset) {
|
|
420 Log.i(TAG, "setField()");
|
250
|
421 int len = data.length - offset;
|
|
422 char[] da = new char[len];
|
|
423 System.arraycopy(data, offset, da, 0, len);
|
|
424 if ((l > 60000) || (c > 60000)) {
|
|
425 l = -1;
|
|
426 c = -1;
|
|
427 }
|
|
428 else {
|
|
429 // ignore setfield outside screen boundaries
|
|
430 if ((l >= buffer.height) || (c+len >= buffer.width)) return;
|
|
431 }
|
100
|
432 buffer.setField(l, c, da);
|
0
|
433 }
|
|
434
|
155
|
435 public synchronized void showUrl(char [] data, int offset) {
|
|
436 Log.i(TAG, "setField()");
|
|
437 char[] da = new char[data.length - offset];
|
210
|
438 System.arraycopy(data, offset, da, 0, data.length-offset);
|
155
|
439 String url = new String(da);
|
|
440 Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
|
441 parent.startActivity(intent);
|
|
442 }
|
|
443
|
0
|
444 public synchronized void getField(int l, int c, int len) {
|
|
445 Log.i(TAG, "getField()");
|
|
446 char[] arg2 = new char[4 + len];
|
|
447 arg2[2] = (char)(l & 0x0000ffff);
|
|
448 arg2[3] = (char)(c & 0x0000ffff);
|
|
449 int base = 4;
|
250
|
450 if ((l >= buffer.height) || (c+len >= buffer.width)) {
|
|
451 Arrays.fill(arg2, base, len-1, ' ');
|
|
452 }
|
|
453 else {
|
|
454 System.arraycopy(buffer.charArray[buffer.screenBase + l], c, arg2, base, len);
|
|
455 }
|
0
|
456 monitorWrite(MONITOR_CMD_FIELDVALUE, arg2);
|
|
457 }
|
|
458
|
|
459 public synchronized void screenWatch(int l, int c, int len) {
|
|
460 Log.i(TAG, "screenWatch()");
|
|
461 start_line = l;
|
|
462 end_line = l;
|
|
463 start_column = c;
|
|
464 end_column = c + len - 1;
|
|
465 }
|
|
466
|
|
467 public synchronized void depress(int vk_key) {
|
|
468 Log.i(TAG, String.format("depress() %d", vk_key));
|
|
469 Integer x = keymap.get(new Integer(vk_key));
|
175
2a7199ad90be
send cursor movement caused by user keystrokes to the monitor
Carl Byington <carl@five-ten-sg.com>
diff
changeset
|
470 if (x != null) buffer.keyDepressed(x, ' ', 0);
|
0
|
471 }
|
172
|
472
|
|
473 public synchronized void switchSession() {
|
|
474 Log.i(TAG, "switchSession()");
|
|
475 Intent intent = new Intent(parent, ConsoleActivity.class);
|
|
476 intent.setAction(Intent.ACTION_VIEW);
|
|
477 intent.setData(host.getUri());
|
|
478 parent.startActivity(intent);
|
|
479 }
|
|
480
|
205
|
481
|
|
482 public synchronized void cursorRequest() {
|
|
483 Log.i(TAG, "cursorRequest()");
|
229
|
484 cursorMoved(CURSOR_REQUESTED);
|
205
|
485 }
|
|
486
|
0
|
487 }
|