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