Mercurial > 510ConnectbotMonitor
annotate src/com/five_ten_sg/connectbot/monitor/MonitorService.java @ 23:2586a4f5c8c3
add mechanism to allow getfield from other threads
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 01 May 2015 11:52:31 -0700 |
parents | 943df7400741 |
children | 4f1cc4f44c41 |
rev | line source |
---|---|
0 | 1 package com.five_ten_sg.connectbot.monitor; |
2 | |
3 import java.io.IOException; | |
4 import java.io.InputStream; | |
5 import java.io.OutputStream; | |
6 import java.net.ServerSocket; | |
7 import java.net.Socket; | |
5 | 8 import java.util.HashMap; |
0 | 9 import java.util.concurrent.ArrayBlockingQueue; |
10 import java.util.concurrent.BlockingQueue; | |
11 import java.util.concurrent.ConcurrentHashMap; | |
12 import java.util.Locale; | |
13 | |
14 import android.app.Activity; | |
15 import android.app.Service; | |
16 import android.content.Context; | |
17 import android.content.Intent; | |
18 import android.content.ServiceConnection; | |
19 import android.net.wifi.WifiManager.WifiLock; | |
20 import android.net.wifi.WifiManager; | |
21 import android.os.Binder; | |
22 import android.os.Bundle; | |
23 import android.os.Handler; | |
24 import android.os.IBinder; | |
25 import android.os.Message; | |
26 import android.os.PowerManager; | |
27 import android.speech.tts.TextToSpeech; | |
28 import android.speech.tts.TextToSpeech.OnInitListener; | |
29 import android.util.Log; | |
30 import android.widget.TextView; | |
31 | |
32 public class MonitorService extends Service implements OnInitListener { | |
33 public final static String TAG = "ConnectBot.MonitorService"; | |
34 | |
16
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
35 public static final char MONITOR_CMD_INIT = 0; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
36 public static final char MONITOR_CMD_ACTIVATE = 1; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
37 public static final char MONITOR_CMD_KEYSTATE = 2; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
38 public static final char MONITOR_CMD_CURSORMOVE = 3; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
39 public static final char MONITOR_CMD_SCREENCHANGE = 4; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
40 public static final char MONITOR_CMD_FIELDVALUE = 5; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
41 public static final char MONITOR_CMD_SETFIELD = 5; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
42 public static final char MONITOR_CMD_GETFIELD = 6; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
43 public static final char MONITOR_CMD_SCREENWATCH = 7; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
44 public static final char MONITOR_CMD_DEPRESS = 8; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
45 public static final char MONITOR_CMD_SHOWURL = 9; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
46 public static final char MONITOR_CMD_SWITCHSESSION = 10; |
18
a94ca5a89fe8
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
47 public static final char MONITOR_CMD_CURSORREQUEST = 11; |
0 | 48 |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
49 public static final char CURSOR_REQUESTED = 0; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
50 public static final char CURSOR_SCREEN_CHANGE = 1; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
51 public static final char CURSOR_USER_KEY = 2; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
52 |
0 | 53 public static final int MONITORPORT = 6000; |
3
2be5bca648ab
switch to static functions
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
54 public static ConcurrentHashMap<Integer,CommunicationThread> clients = new ConcurrentHashMap<Integer,CommunicationThread>(); |
2be5bca648ab
switch to static functions
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
55 public static int currentConnection = -1; |
0 | 56 |
57 private boolean speech = false; | |
58 private TextToSpeech talker = null; | |
5 | 59 private BlockingQueue<String> talkerQueue = null; |
0 | 60 public Handler handler = null; |
61 private ServerSocket serverSocket; | |
62 private Thread serverThread = null; | |
63 private WifiManager.WifiLock wifiLock; | |
64 private PowerManager.WakeLock wakeLock; | |
65 final private IBinder binder = new MonitorBinder(); | |
66 | |
67 | |
68 public class MonitorBinder extends Binder { | |
69 public MonitorService getService() { | |
70 return MonitorService.this; | |
71 } | |
72 } | |
73 | |
74 @Override | |
75 public void onInit(int status) { | |
76 if (status == TextToSpeech.SUCCESS) { | |
77 talker.setLanguage(Locale.US); | |
78 speech = true; | |
79 } | |
80 } | |
81 | |
82 @Override | |
83 public void onCreate() { | |
84 WifiManager wMgr = (WifiManager) getSystemService(Context.WIFI_SERVICE); | |
85 wifiLock = wMgr.createWifiLock(WifiManager.WIFI_MODE_FULL, "MyWifiLock"); | |
86 wifiLock.acquire(); | |
87 | |
88 PowerManager pMgr = (PowerManager) getSystemService(Context.POWER_SERVICE); | |
89 wakeLock = pMgr.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "MyWakeLock"); | |
90 wakeLock.acquire(); | |
91 | |
92 talker = new TextToSpeech(this, this); | |
93 this.serverThread = new Thread(new ServerThread()); | |
94 this.serverThread.start(); | |
95 } | |
96 | |
97 @Override | |
98 public IBinder onBind(Intent intent) { | |
99 startService(new Intent(this, MonitorService.class)); | |
100 return binder; | |
101 } | |
102 | |
103 public void printer(String msg) { | |
104 if (handler != null) handler.sendMessage(handler.obtainMessage(MonitorActivity.MESSAGE_CODE_PRINT, msg)); | |
105 } | |
106 | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
107 public synchronized void setCurrentConnection(int connection) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
108 currentConnection = connection; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
109 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
110 |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
111 public synchronized int nextConnection() { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
112 int c = 1; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
113 while (clients.get(c) != null) c++; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
114 return c; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
115 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
116 |
0 | 117 @Override |
118 public int onStartCommand(Intent intent, int flags, int startId) { | |
119 Log.i(TAG, "service onStartCommand()"); | |
120 return START_STICKY; | |
121 } | |
122 | |
123 @Override | |
124 public void onDestroy() { | |
125 try { | |
126 Log.i(TAG, "service onDestroy()"); | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
127 teCloseAll(); |
0 | 128 talker.stop(); |
129 talker.shutdown(); | |
130 wifiLock.release(); | |
131 wakeLock.release(); | |
132 serverSocket.close(); | |
133 } catch (IOException e) { | |
134 Log.e(TAG, "exception in onDestroy()", e); | |
135 } | |
136 super.onDestroy(); | |
137 } | |
138 | |
139 class ServerThread extends Thread { | |
140 public void run() { | |
141 Socket socket = null; | |
142 int connection = 0; | |
143 try { | |
144 serverSocket = new ServerSocket(MONITORPORT); | |
145 } catch (IOException e) { | |
146 Log.e(TAG, "exception in ServerThread.run(), cannot create listening socket", e); | |
147 return; | |
148 } | |
149 while (true) { | |
150 try{ | |
151 socket = serverSocket.accept(); | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
152 connection = nextConnection(); |
0 | 153 CommunicationThread commThread = new CommunicationThread(connection, socket); |
154 clients.put(connection, commThread); | |
155 commThread.start(); | |
156 } catch (IOException e) { | |
157 Log.e(TAG, "exception in ServerThread.run(), listening socket closed", e); | |
158 break; | |
159 } | |
160 } | |
161 } | |
162 } | |
163 | |
164 class triple { | |
165 private int l, c; | |
166 private char[] b; | |
167 public triple(int l, int c, char[] b) { | |
168 this.l = l; | |
169 this.c = c; | |
170 this.b = b; | |
171 } | |
172 } | |
173 | |
174 class CommunicationThread extends Thread { | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
175 public int thread_id; |
0 | 176 public int connection; |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
177 private String initString = null; |
0 | 178 private Socket client_socket; |
179 private InputStream client_in; | |
180 private OutputStream client_out; | |
181 private boolean is_closing = false; | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
182 private Integer getfields_outstanding = 0; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
183 private BlockingQueue<triple> value_queue = new ArrayBlockingQueue<triple>(1); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
184 private BlockingQueue<char[]> packet_queue = new ArrayBlockingQueue<char[]>(10000); |
0 | 185 |
186 public CommunicationThread(int handle, Socket socket) { | |
187 connection = handle; | |
188 client_socket = socket; | |
189 try { | |
190 client_in = client_socket.getInputStream(); | |
191 client_out = client_socket.getOutputStream(); | |
192 } catch (IOException e) { | |
193 Log.e(TAG, "exception in CommunicationThread() constructor, cannot get socket streams", e); | |
194 } | |
195 } | |
196 | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
197 public synchronized void abandon() { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
198 value_queue.offer(new triple(0, 0, new char[0])); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
199 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
200 |
4 | 201 public void speak(byte [] msg, boolean flush, boolean synchronous) { |
202 if (speech) { | |
203 String smsg = bytesToString(msg); | |
204 if (synchronous) { | |
205 HashMap<String, String> myHashParms = new HashMap(); | |
206 myHashParms.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, String.format("connection %d", connection)); | |
207 talker.speak(smsg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, myHashParms); | |
208 try { | |
209 String x = talkerQueue.take(); // wait for completion | |
210 } catch (InterruptedException e) { | |
211 Log.e(TAG, "exception in cm.speak()", e); | |
212 } | |
213 } | |
214 else { | |
215 talker.speak(smsg, (flush) ? TextToSpeech.QUEUE_FLUSH : TextToSpeech.QUEUE_ADD, null); | |
216 } | |
217 } | |
218 } | |
219 | |
220 public String bytesToString(byte[] b) { | |
221 char[] c = new char[b.length]; | |
222 int bp = 0; | |
223 for(int i = 0; i < c.length; i++) { | |
224 byte b1 = 0; | |
225 byte b2 = b[bp++]; | |
226 c[i] = (char) (((b1 & 0x00FF) << 8) + (b2 & 0x00FF)); | |
227 } | |
228 return new String(c); | |
229 } | |
230 | |
0 | 231 public char[] bytesToChars(byte[] b, int len) { |
232 char[] c = new char[len >> 1]; | |
233 int bp = 0; | |
234 for(int i = 0; i < c.length; i++) { | |
235 byte b1 = b[bp++]; | |
236 byte b2 = b[bp++]; | |
237 c[i] = (char) (((b1 & 0x00FF) << 8) + (b2 & 0x00FF)); | |
238 } | |
239 return c; | |
240 } | |
241 | |
242 public byte[] charsToBytes(char[] c) { | |
243 byte[] b = new byte[c.length << 1]; | |
244 int bp = 0; | |
245 for (int i=0; i<c.length; i++) { | |
246 b[bp++] = (byte) ((c[i] & 0xff00) >> 8); | |
247 b[bp++] = (byte) (c[i] & 0x00ff); | |
248 } | |
249 return b; | |
250 } | |
251 | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
252 void cleanup(char[] buf) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
253 int i; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
254 for (i=0; i<buf.length; i++) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
255 if ((int)(buf[i]) < 32) buf[i] = ' '; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
256 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
257 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
258 |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
259 public int cmGetField(char[] c) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
260 int request; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
261 synchronized(getfields_outstanding) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
262 request = getfields_outstanding; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
263 getfields_outstanding = getfields_outstanding + 1; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
264 value_queue.clear(); // we never have more than one outstanding getfield request from the reco thread on the connection |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
265 clientWrite(MONITOR_CMD_GETFIELD, c); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
266 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
267 return request; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
268 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
269 |
0 | 270 public synchronized void clientWrite(char cmd, char[] c) { |
271 try { | |
272 if (client_out != null) { | |
273 c[0] = (char)(c.length - 1); // number of chars following | |
274 c[1] = cmd; | |
275 Log.i(TAG, String.format("sending %d command", (int)cmd)); | |
276 client_out.write(charsToBytes(c)); | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
277 client_out.flush(); |
0 | 278 } |
279 } | |
280 catch (IOException e) { | |
281 Log.e(TAG, "exception in monitorWrite()", e); | |
282 try { | |
283 client_out.close(); | |
284 } | |
285 catch (IOException ee) { | |
286 Log.e(TAG, "exception in monitorWrite() closing socket", ee); | |
287 } | |
288 client_out = null; | |
289 } | |
290 }; | |
291 | |
292 private char[] forceRead(int len) throws IOException { | |
293 int len2 = len*2; | |
294 int off = 0; | |
295 byte[] b = new byte[len2]; | |
296 while (off < len2) { | |
297 int l = client_in.read(b, off, len2-off); | |
298 if (l < 0) { | |
299 is_closing = true; | |
300 throw new IOException("eof"); | |
301 } | |
302 off += l; | |
303 } | |
304 return bytesToChars(b, len2); | |
305 } | |
306 | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
307 public char[] readPacket() throws IOException { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
308 char[] len = forceRead(1); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
309 return forceRead(len[0]); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
310 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
311 |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
312 public char[] nextPacket() throws IOException, InterruptedException { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
313 char[] packet = packet_queue.poll(); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
314 if (packet == null) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
315 packet = readPacket(); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
316 if (packet[0] == MONITOR_CMD_FIELDVALUE) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
317 synchronized(getfields_outstanding) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
318 getfields_outstanding = getfields_outstanding - 1; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
319 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
320 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
321 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
322 return packet; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
323 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
324 |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
325 private triple reformatValue(char[] packet) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
326 int plen = packet.length; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
327 char[] buf = new char[plen-3]; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
328 System.arraycopy(packet, 3, buf, 0, plen-3); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
329 cleanup(buf); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
330 Log.i(TAG, String.format("teFieldValue %d line %d column %d b.len %d", connection, (int)packet[1], (int)packet[2], buf.length)); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
331 return new triple(packet[1], packet[2], buf); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
332 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
333 |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
334 public triple peekValue(int request) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
335 try { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
336 while (true) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
337 char[] packet = readPacket(); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
338 if (packet[0] == MONITOR_CMD_FIELDVALUE) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
339 synchronized(getfields_outstanding) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
340 getfields_outstanding = getfields_outstanding - 1; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
341 if (request == 0) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
342 return reformatValue(packet); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
343 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
344 else { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
345 packet_queue.put(packet); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
346 request = request - 1; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
347 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
348 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
349 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
350 else { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
351 packet_queue.put(packet); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
352 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
353 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
354 } catch (IOException e) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
355 return new triple(0, 0, new char[0]); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
356 } catch (InterruptedException e) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
357 return new triple(0, 0, new char[0]); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
358 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
359 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
360 |
0 | 361 public void run() { |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
362 thread_id = android.os.Process.myTid(); |
0 | 363 Log.i(TAG, String.format("CommunicationThread.run() client %d connected", connection)); |
364 while (true) { | |
365 try { | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
366 char[] packet = nextPacket(); |
0 | 367 char[] buf; |
368 char cmd = packet[0]; | |
369 int plen = packet.length; | |
370 //Log.i(TAG, String.format("received %d command length %d", (int)cmd, plen)); | |
371 switch (cmd) { | |
372 case MONITOR_CMD_INIT: | |
373 buf = new char[plen-1]; | |
374 System.arraycopy(packet, 1, buf, 0, plen-1); | |
375 abandonGetField(connection); | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
376 initString = new String(buf); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
377 teInit(connection, initString); |
0 | 378 break; |
379 case MONITOR_CMD_ACTIVATE: | |
380 abandonGetField(connection); | |
381 buf = new char[plen-3]; | |
382 System.arraycopy(packet, 3, buf, 0, plen-3); | |
383 teActivate(connection, packet[1], packet[2], buf); | |
384 break; | |
2 | 385 case MONITOR_CMD_KEYSTATE: |
386 teKeyState(connection, (packet[1] == 1)); | |
0 | 387 break; |
388 case MONITOR_CMD_CURSORMOVE: | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
389 teCursorMove(connection, packet[1], packet[2], packet[3]); |
0 | 390 break; |
391 case MONITOR_CMD_SCREENCHANGE: | |
392 buf = new char[plen-3]; | |
393 System.arraycopy(packet, 3, buf, 0, plen-3); | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
394 cleanup(buf); |
0 | 395 teScreenChange(connection, packet[1], packet[2], buf); |
396 break; | |
397 case MONITOR_CMD_FIELDVALUE: | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
398 value_queue.clear(); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
399 value_queue.put(reformatValue(packet)); |
0 | 400 break; |
401 default: | |
402 break; | |
403 } | |
404 } catch (IOException e) { | |
405 if (!is_closing) Log.e(TAG, "exception in CommunicationThread.run()", e); | |
406 break; | |
407 } catch (InterruptedException e) { | |
408 Log.e(TAG, "exception in CommunicationThread.run()", e); | |
409 break; | |
410 } | |
411 } | |
412 Log.i(TAG, String.format("shutting down connection %d", connection)); | |
413 try { | |
414 if (client_in != null) client_in.close(); | |
415 if (client_out != null) client_out.close(); | |
416 if (client_socket != null) client_socket.close(); | |
417 } catch (IOException e) { | |
418 Log.e(TAG, "exception in CommunicationThread.run() closing sockets", e); | |
419 } | |
420 client_in = null; | |
421 client_out = null; | |
422 client_socket = null; | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
423 clients.remove(connection); |
0 | 424 } |
425 } | |
426 | |
427 private void abandonGetField(int except) { | |
428 for (CommunicationThread cm : clients.values()) { | |
429 if (cm.connection != except) { | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
430 cm.abandon(); |
0 | 431 } |
432 } | |
433 } | |
434 | |
435 | |
436 //////////////////////////////////////// | |
437 //// these functions run on the reader thread here and call your monitoring code | |
438 | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
439 public void teInit(int connection, String fn) { |
0 | 440 Log.i(TAG, String.format("teInit %d file %s", connection, fn)); |
20
943df7400741
enable some debug logging
Carl Byington <carl@five-ten-sg.com>
parents:
18
diff
changeset
|
441 printer(String.format("init %d %s", connection, fn)); |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
442 setCurrentConnection(connection); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
443 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
444 |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
445 public void teCloseAll() { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
446 Log.i(TAG, String.format("teCloseAll")); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
447 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
448 |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
449 public void teClose(int connection) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
450 Log.i(TAG, String.format("teClose %d", connection)); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
451 setCurrentConnection(-1); |
0 | 452 } |
453 | |
454 public void teActivate(int connection, int lines, int columns, char[] buf) { | |
455 Log.i(TAG, String.format("teActivate %d", connection)); | |
20
943df7400741
enable some debug logging
Carl Byington <carl@five-ten-sg.com>
parents:
18
diff
changeset
|
456 printer(String.format("activate %d lines %d columns %d b.len %d", connection, lines, columns, buf.length)); |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
457 boolean sameinit = false; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
458 CommunicationThread cm = clients.get(currentConnection); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
459 if (cm != null) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
460 sameinit = (cm.initString == fn); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
461 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
462 setCurrentConnection(connection); |
0 | 463 } |
464 | |
2 | 465 public void teKeyState(int connection, boolean down) { |
466 String d = (down) ? "yes" : "no"; | |
467 Log.i(TAG, String.format("teKeyState %d isdown %s", connection, d)); | |
20
943df7400741
enable some debug logging
Carl Byington <carl@five-ten-sg.com>
parents:
18
diff
changeset
|
468 printer(String.format("keystate %d isdown %s", connection, d)); |
0 | 469 } |
470 | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
471 public void teCursorMove(int connection, int l, int c, int why) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
472 Log.i(TAG, String.format("teCursorMove %d line %d column %d why %d", connection, l, c, why)); |
0 | 473 } |
474 | |
475 public void teScreenChange(int connection, int lines, int columns, char[] buf) { | |
476 Log.i(TAG, String.format("teScreenChange %d lines %d columns %d b.len %d", connection, lines, columns, buf.length)); | |
477 } | |
478 | |
479 | |
480 //////////////////////////////////////// | |
481 //// these functions are called from your monitoring code thread | |
482 | |
3
2be5bca648ab
switch to static functions
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
483 public static void teSetField(int connection, int l, int c, char[] buf) { |
0 | 484 int len = buf.length; |
485 Log.i(TAG, String.format("teSetField %d request line %d column %d len %d", connection, l, c, len)); | |
486 CommunicationThread cm = clients.get(connection); | |
487 if (cm != null) { | |
488 char[] arg2 = new char[4 + len]; | |
489 arg2[2] = (char) (l & 0x0000ffff); | |
490 arg2[3] = (char) (c & 0x0000ffff); | |
491 int base = 4; | |
492 System.arraycopy(buf, 0, arg2, base, len); | |
493 cm.clientWrite(MONITOR_CMD_SETFIELD, arg2); | |
494 } | |
495 } | |
496 | |
3
2be5bca648ab
switch to static functions
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
497 public static char[] teGetField(int connection, int l, int c, int len) { |
0 | 498 Log.i(TAG, String.format("teGetField %d request line %d column %d len %d", connection, l, c, len)); |
499 CommunicationThread cm = clients.get(connection); | |
500 if (cm != null) { | |
501 char[] arg = new char[5]; | |
502 arg[2] = (char) (l & 0x0000ffff); | |
503 arg[3] = (char) (c & 0x0000ffff); | |
504 arg[4] = (char) (len & 0x0000ffff); | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
505 int request = cm.cmGetField(arg); |
0 | 506 try { |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
507 int tid = android.os.Process.myTid(); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
508 triple t; |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
509 if (tid == cm.thread_id) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
510 // we are running on the socket reader thread, called via teCursorMove() or teScreenChange() |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
511 // we need to peek command packets from the socket looking for our fieldvalue response |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
512 Log.i(TAG, String.format("java teGetField() peeking value for getfield on reader thread")); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
513 t = cm.peekValue(request); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
514 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
515 else { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
516 // we are running on some other thread, just wait for the reader thread to |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
517 // process the fieldvalue and put it on the queue. |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
518 Log.i(TAG, String.format("java teGetField() waiting for data for getfield on reco thread")); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
519 t = cm.value_queue.take(); // wait for response |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
520 } |
0 | 521 Log.i(TAG, String.format("teGetField %d response line %d column %d len %d", connection, t.l, t.c, t.b.length)); |
522 return t.b; | |
523 } catch (InterruptedException e) { | |
524 Log.e(TAG, "exception in teGetField(), return empty string", e); | |
525 } | |
526 } | |
527 return new char[0]; | |
528 } | |
529 | |
3
2be5bca648ab
switch to static functions
Carl Byington <carl@five-ten-sg.com>
parents:
2
diff
changeset
|
530 public static void teScreenWatch(int connection, int l, int c, int len) { |
0 | 531 Log.i(TAG, String.format("teScreenWatch %d request line %d column %d len %d", connection, l, c, len)); |
532 CommunicationThread cm = clients.get(connection); | |
533 if (cm != null) { | |
534 char[] arg = new char[5]; | |
535 arg[2] = (char) (l & 0x0000ffff); | |
536 arg[3] = (char) (c & 0x0000ffff); | |
537 arg[4] = (char) (len & 0x0000ffff); | |
538 cm.clientWrite(MONITOR_CMD_GETFIELD, arg); | |
539 } | |
540 } | |
541 | |
7 | 542 public static void teSpeak(int connection, byte [] msg, boolean flush, boolean synchronous) { |
4 | 543 CommunicationThread cm = clients.get(connection); |
544 if (cm != null) cm.speak(msg, flush, synchronous); | |
0 | 545 } |
2 | 546 |
547 public static void teDepress(int connection, int vk_key) { | |
548 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 | |
549 Log.i(TAG, String.format("teDepress %d, %d", connection, vk_key)); | |
550 CommunicationThread cm = clients.get(connection); | |
551 if (cm != null) { | |
552 char[] arg = new char[3]; | |
553 arg[2] = (char) (vk_key & 0x0000ffff); | |
554 cm.clientWrite(MONITOR_CMD_DEPRESS, arg); | |
555 } | |
556 } | |
13 | 557 |
558 public static void teShowUrl(int connection, char [] url) { | |
559 int len = url.length; | |
560 CommunicationThread cm = clients.get(connection); | |
561 if (cm != null) { | |
562 char[] arg2 = new char[2 + len]; | |
563 int base = 2; | |
564 System.arraycopy(url, 0, arg2, base, len); | |
565 cm.clientWrite(MONITOR_CMD_SHOWURL, arg2); | |
566 } | |
567 } | |
568 | |
23
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
569 public static void teAbandonGetField(int connection) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
570 Log.i(TAG, String.format("teAbandonGetField %d", connection)); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
571 CommunicationThread cm = clients.get(connection); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
572 if (cm != null) { |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
573 cm.abandon(); |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
574 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
575 } |
2586a4f5c8c3
add mechanism to allow getfield from other threads
Carl Byington <carl@five-ten-sg.com>
parents:
20
diff
changeset
|
576 |
16
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
577 public static void teSwitchSession(int connection) { |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
578 CommunicationThread cm = clients.get(connection); |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
579 if (cm != null) { |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
580 char [] arg2 = new char[2]; |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
581 cm.clientWrite(MONITOR_CMD_SWITCHSESSION, arg2); |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
582 } |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
583 } |
a481d8fb5571
add switch session command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
13
diff
changeset
|
584 |
18
a94ca5a89fe8
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
585 public static void teCursorRequest(int connection) { |
a94ca5a89fe8
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
586 CommunicationThread cm = clients.get(connection); |
a94ca5a89fe8
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
587 if (cm != null) { |
a94ca5a89fe8
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
588 char [] arg2 = new char[2]; |
a94ca5a89fe8
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
589 cm.clientWrite(MONITOR_CMD_CURSORREQUEST, arg2); |
a94ca5a89fe8
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
590 } |
a94ca5a89fe8
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
591 } |
a94ca5a89fe8
add cursor request command to the TE
Carl Byington <carl@five-ten-sg.com>
parents:
16
diff
changeset
|
592 |
0 | 593 } |