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