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