comparison 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
comparison
equal deleted inserted replaced
171:18aceeae6681 172:cb9e359ea2bd
21 import java.util.concurrent.ConcurrentHashMap; 21 import java.util.concurrent.ConcurrentHashMap;
22 22
23 public class TerminalMonitor { 23 public class TerminalMonitor {
24 public final static String TAG = "ConnectBot.TerminalMonitor"; 24 public final static String TAG = "ConnectBot.TerminalMonitor";
25 25
26 public static final char MONITOR_CMD_INIT = 0; 26 public static final char MONITOR_CMD_INIT = 0;
27 public static final char MONITOR_CMD_ACTIVATE = 1; 27 public static final char MONITOR_CMD_ACTIVATE = 1;
28 public static final char MONITOR_CMD_KEYSTATE = 2; 28 public static final char MONITOR_CMD_KEYSTATE = 2;
29 public static final char MONITOR_CMD_CURSORMOVE = 3; 29 public static final char MONITOR_CMD_CURSORMOVE = 3;
30 public static final char MONITOR_CMD_SCREENCHANGE = 4; 30 public static final char MONITOR_CMD_SCREENCHANGE = 4;
31 public static final char MONITOR_CMD_FIELDVALUE = 5; 31 public static final char MONITOR_CMD_FIELDVALUE = 5;
32 public static final char MONITOR_CMD_SETFIELD = 5; 32 public static final char MONITOR_CMD_SETFIELD = 5;
33 public static final char MONITOR_CMD_GETFIELD = 6; 33 public static final char MONITOR_CMD_GETFIELD = 6;
34 public static final char MONITOR_CMD_SCREENWATCH = 7; 34 public static final char MONITOR_CMD_SCREENWATCH = 7;
35 public static final char MONITOR_CMD_DEPRESS = 8; 35 public static final char MONITOR_CMD_DEPRESS = 8;
36 public static final char MONITOR_CMD_SHOWURL = 9; 36 public static final char MONITOR_CMD_SHOWURL = 9;
37 public static final char MONITOR_CMD_SWITCHSESSION = 10;
37 38
38 private static final int MONITORPORT = 6000; 39 private static final int MONITORPORT = 6000;
39 private static final String LOCALHOST = "127.0.0.1"; 40 private static final String LOCALHOST = "127.0.0.1";
40 41
41 private Context parent = null; 42 private Context parent = null;
128 if (packet.length > 1) 129 if (packet.length > 1)
129 showUrl(packet, 1); 130 showUrl(packet, 1);
130 131
131 break; 132 break;
132 133
134 case MONITOR_CMD_SHOWURL:
135 if (packet.length == 1)
136 switchSession();
137
138 break;
139
133 default: 140 default:
134 break; 141 break;
135 } 142 }
136 } 143 }
137 catch (IOException e) { 144 catch (IOException e) {
177 Log.i(TAG, "unbound from service"); 184 Log.i(TAG, "unbound from service");
178 } 185 }
179 }; 186 };
180 187
181 188
182 public TerminalMonitor(Context parent, vt320 buffer, View view, String init) { 189 public TerminalMonitor(Context parent, vt320 buffer, View view, HostBean host, String init) {
183 this.parent = parent; 190 this.parent = parent;
184 this.buffer = buffer; 191 this.buffer = buffer;
185 this.view = view; 192 this.view = view;
193 this.host = host;
186 this.init = init; 194 this.init = init;
187 // setup the windows->android keymapping 195 // setup the windows->android keymapping
188 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731 196 // http://msdn.microsoft.com/en-us/library/windows/desktop/dd375731
189 keymap = new HashMap<Integer, Integer>(); 197 keymap = new HashMap<Integer, Integer>();
190 keymap.put(0x08, vt320.KEY_BACK_SPACE); // vk_back 198 keymap.put(0x08, vt320.KEY_BACK_SPACE); // vk_back
411 public synchronized void depress(int vk_key) { 419 public synchronized void depress(int vk_key) {
412 Log.i(TAG, String.format("depress() %d", vk_key)); 420 Log.i(TAG, String.format("depress() %d", vk_key));
413 Integer x = keymap.get(new Integer(vk_key)); 421 Integer x = keymap.get(new Integer(vk_key));
414 if (x != null) buffer.keyPressed(x, ' ', 0); 422 if (x != null) buffer.keyPressed(x, ' ', 0);
415 } 423 }
424
425 public synchronized void switchSession() {
426 Log.i(TAG, "switchSession()");
427 Intent intent = new Intent(parent, ConsoleActivity.class);
428 intent.setAction(Intent.ACTION_VIEW);
429 intent.setData(host.getUri());
430 parent.startActivity(intent);
431 }
432
416 } 433 }