Mercurial > 510Connectbot
annotate src/com/five_ten_sg/connectbot/transport/TN5250.java @ 88:1c22e6a7efff
convert ctrl keys to virtual keys; use proper android home directory
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Mon, 16 Jun 2014 12:26:51 -0700 |
parents | 1bc2229562f8 |
children | 33eb63352be5 |
rev | line source |
---|---|
11 | 1 /* |
2 * 510ConnectBot | |
3 * Copyright 2014 Carl Byington | |
4 * | |
5 * Licensed under the Apache License, Version 2.0 (the "License"); | |
6 * you may not use this file except in compliance with the License. | |
7 * You may obtain a copy of the License at | |
8 * | |
9 * http://www.apache.org/licenses/LICENSE-2.0 | |
10 * | |
11 * Unless required by applicable law or agreed to in writing, software | |
12 * distributed under the License is distributed on an "AS IS" BASIS, | |
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 * See the License for the specific language governing permissions and | |
15 * limitations under the License. | |
16 */ | |
17 | |
18 package com.five_ten_sg.connectbot.transport; | |
19 | |
20 import java.io.IOException; | |
21 import java.io.InputStream; | |
22 import java.io.OutputStream; | |
23 import java.net.Socket; | |
24 import java.net.SocketException; | |
13 | 25 import java.net.UnknownHostException; |
54
a7e660661e08
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
53
diff
changeset
|
26 import java.util.HashMap; |
11 | 27 import java.util.List; |
28 import java.util.Map; | |
13 | 29 import java.util.regex.Matcher; |
30 import java.util.regex.Pattern; | |
11 | 31 |
12 | 32 import org.tn5250j.framework.tn5250.Screen5250; |
33 import org.tn5250j.framework.tn5250.tnvt; | |
34 | |
13 | 35 import com.five_ten_sg.connectbot.R; |
11 | 36 import com.five_ten_sg.connectbot.bean.HostBean; |
37 import com.five_ten_sg.connectbot.bean.PortForwardBean; | |
38 import com.five_ten_sg.connectbot.service.TerminalBridge; | |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
39 import com.five_ten_sg.connectbot.service.TerminalKeyListener; |
11 | 40 import com.five_ten_sg.connectbot.service.TerminalManager; |
41 import com.five_ten_sg.connectbot.util.HostDatabase; | |
50
2cd3d8091e37
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
49
diff
changeset
|
42 import com.five_ten_sg.connectbot.util.PreferenceConstants; |
11 | 43 import android.content.Context; |
44 import android.net.Uri; | |
13 | 45 import android.util.Log; |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
46 import android.view.KeyCharacterMap; |
50
2cd3d8091e37
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
49
diff
changeset
|
47 import android.view.KeyEvent; |
2cd3d8091e37
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
49
diff
changeset
|
48 import android.view.View; |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
49 import de.mud.terminal.vt320; |
11 | 50 |
51 | |
52 /** | |
53 * @author Carl Byington | |
54 * | |
55 */ | |
56 public class TN5250 extends AbsTransport { | |
57 private static final String PROTOCOL = "tn5250"; | |
58 private static final String TAG = "ConnectBot.tn5250"; | |
59 private static final int DEFAULT_PORT = 23; | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
60 |
11 | 61 private Screen5250 screen52; |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
62 private tnvt handler = null; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
63 private Socket socket; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
64 private boolean connected = false; |
11 | 65 |
12 | 66 static final Pattern hostmask; |
67 static { | |
68 hostmask = Pattern.compile("^([0-9a-z.-]+)(:(\\d+))?$", Pattern.CASE_INSENSITIVE); | |
69 } | |
70 | |
45
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
71 |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
72 class vt320x5250 extends vt320 { |
84
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
73 private HashMap<Integer, Integer> controls; |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
74 private HashMap<Integer, String> mnemonics; |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
75 |
54
a7e660661e08
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
53
diff
changeset
|
76 public vt320x5250() { |
a7e660661e08
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
53
diff
changeset
|
77 this(80,24); |
a7e660661e08
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
53
diff
changeset
|
78 } |
a7e660661e08
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
53
diff
changeset
|
79 |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
80 public vt320x5250(int width, int height) { |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
81 super(width, height); |
84
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
82 controls = new HashMap<Integer, Integer>(); |
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
83 controls.put(0x08, KEY_BACK_SPACE); |
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
84 controls.put(0x09, KEY_TAB); |
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
85 controls.put(0x0d, KEY_ENTER); |
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
86 controls.put(0x1b, KEY_ESCAPE); |
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
87 |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
88 mnemonics = new HashMap<Integer, String>(); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
89 mnemonics.put(KEY_PAUSE , "[attn]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
90 mnemonics.put(KEY_F1 , "[pf1]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
91 mnemonics.put(KEY_F2 , "[pf2]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
92 mnemonics.put(KEY_F3 , "[pf3]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
93 mnemonics.put(KEY_F4 , "[pf4]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
94 mnemonics.put(KEY_F5 , "[pf5]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
95 mnemonics.put(KEY_F6 , "[pf6]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
96 mnemonics.put(KEY_F7 , "[pf7]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
97 mnemonics.put(KEY_F8 , "[pf8]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
98 mnemonics.put(KEY_F9 , "[pf9]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
99 mnemonics.put(KEY_F10 , "[pf10]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
100 mnemonics.put(KEY_F11 , "[pf11]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
101 mnemonics.put(KEY_F12 , "[pf12]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
102 mnemonics.put(KEY_UP , "[up]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
103 mnemonics.put(KEY_DOWN , "[down]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
104 mnemonics.put(KEY_LEFT , "[left]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
105 mnemonics.put(KEY_RIGHT , "[right]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
106 mnemonics.put(KEY_PAGE_DOWN , "[pgdown]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
107 mnemonics.put(KEY_PAGE_UP , "[pgup]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
108 mnemonics.put(KEY_INSERT , "[insert]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
109 mnemonics.put(KEY_DELETE , "[delete]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
110 mnemonics.put(KEY_BACK_SPACE , "[backspace]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
111 mnemonics.put(KEY_HOME , "[home]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
112 mnemonics.put(KEY_END , "[end]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
113 mnemonics.put(KEY_NUM_LOCK , ""); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
114 mnemonics.put(KEY_CAPS_LOCK , ""); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
115 mnemonics.put(KEY_SHIFT , ""); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
116 mnemonics.put(KEY_CONTROL , ""); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
117 mnemonics.put(KEY_ALT , ""); |
57
e0c68988fe2e
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
54
diff
changeset
|
118 mnemonics.put(KEY_ENTER , "[enter]"); |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
119 mnemonics.put(KEY_NUMPAD0 , "0"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
120 mnemonics.put(KEY_NUMPAD1 , "1"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
121 mnemonics.put(KEY_NUMPAD2 , "2"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
122 mnemonics.put(KEY_NUMPAD3 , "3"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
123 mnemonics.put(KEY_NUMPAD4 , "4"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
124 mnemonics.put(KEY_NUMPAD5 , "5"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
125 mnemonics.put(KEY_NUMPAD6 , "6"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
126 mnemonics.put(KEY_NUMPAD7 , "7"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
127 mnemonics.put(KEY_NUMPAD8 , "8"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
128 mnemonics.put(KEY_NUMPAD9 , "9"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
129 mnemonics.put(KEY_DECIMAL , "."); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
130 mnemonics.put(KEY_ADD , "+"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
131 mnemonics.put(KEY_ESCAPE , ""); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
132 mnemonics.put(KEY_TAB , "[tab]"); |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
133 } |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
134 |
45
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
135 @Override |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
136 public void debug(String s) { |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
137 Log.d(TAG, s); |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
138 } |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
139 |
69
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
140 // monitor injecting a field |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
141 @Override |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
142 public void setField(int l, int c, char [] d) { |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
143 screen52.setField(l, c, d); |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
144 } |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
145 |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
146 // terminal key listener sending to local screen |
45
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
147 @Override |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
148 public void write(byte[] b) { |
69
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
149 if (bridge.monitor != null) bridge.monitor.hostData(b); |
49
8887bff45dee
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
47
diff
changeset
|
150 screen52.sendKeys(new String(b)); |
45
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
151 } |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
152 @Override |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
153 public void write(int b) { |
84
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
154 if (controls.containsKey(b)) { |
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
155 keyPressed(controls.get(b), ' ', 0); |
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
156 } |
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
157 else { |
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
158 if (bridge.monitor != null) bridge.monitor.hostData(b); |
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
159 screen52.sendKeys(new String(new byte[] {(byte)b})); |
8f23b05a51f7
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
71
diff
changeset
|
160 } |
45
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
161 } |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
162 @Override |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
163 public void keyPressed(int keyCode, char keyChar, int modifiers) { |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
164 if (mnemonics.containsKey(keyCode)) { |
69
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
165 String s = mnemonics.get(keyCode); |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
166 if (s != "") { |
71
7ae9b0c382ec
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
69
diff
changeset
|
167 if (bridge.monitor != null) bridge.monitor.hostData(s.getBytes()); |
69
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
168 screen52.sendKeys(s); |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
169 } |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
170 } |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
171 } |
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
172 // 5250 writing to the screen |
69
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
173 // test for changed screen contents |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
174 @Override |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
175 public void testChanged() { |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
176 if (bridge.monitor != null) bridge.monitor.testChanged(); |
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
177 } |
45
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
178 @Override |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
179 public void putChar(int c, int l, char ch, int attributes) { |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
180 if (bridge.monitor != null) bridge.monitor.screenChanged(l, c); |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
181 super.putChar(c, l, ch, attributes); |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
182 } |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
183 @Override |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
184 public void setCursorPosition(int c, int l) { |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
185 if (bridge.monitor != null) bridge.monitor.cursorMove(l, c); |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
186 super.setCursorPosition(c, l); |
87
1bc2229562f8
convert ctrl keys to virtual keys; use proper android home directory
Carl Byington <carl@five-ten-sg.com>
parents:
84
diff
changeset
|
187 redraw(); |
45
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
188 } |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
189 }; |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
190 |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
191 |
11 | 192 public TN5250() { |
193 super(); | |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
194 } |
11 | 195 |
196 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
197 /** |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
198 * @return protocol part of the URI |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
199 */ |
11 | 200 public static String getProtocolName() { |
201 return PROTOCOL; | |
202 } | |
203 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
204 |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
205 /** |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
206 * Encode the current transport into a URI that can be passed via intent calls. |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
207 * @return URI to host |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
208 */ |
12 | 209 public Uri getUri(String input) { |
210 Matcher matcher = hostmask.matcher(input); | |
211 | |
212 if (!matcher.matches()) | |
213 return null; | |
214 | |
215 StringBuilder sb = new StringBuilder(); | |
216 sb.append(PROTOCOL) | |
217 .append("://") | |
218 .append(matcher.group(1)); | |
219 String portString = matcher.group(3); | |
220 int port = DEFAULT_PORT; | |
221 | |
222 if (portString != null) { | |
223 try { | |
224 port = Integer.parseInt(portString); | |
225 | |
226 if (port < 1 || port > 65535) { | |
227 port = DEFAULT_PORT; | |
228 } | |
229 } | |
230 catch (NumberFormatException nfe) { | |
231 // Keep the default port | |
232 } | |
233 } | |
234 | |
235 if (port != DEFAULT_PORT) { | |
236 sb.append(':'); | |
237 sb.append(port); | |
238 } | |
239 | |
240 sb.append("/#") | |
241 .append(Uri.encode(input)); | |
242 Uri uri = Uri.parse(sb.toString()); | |
243 return uri; | |
11 | 244 } |
245 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
246 |
11 | 247 /** |
248 * Causes transport to connect to the target host. After connecting but before a | |
249 * session is started, must call back to {@link TerminalBridge#onConnected()}. | |
250 * After that call a session may be opened. | |
251 */ | |
252 @Override | |
253 public void connect() { | |
30
d738f6b876fe
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
29
diff
changeset
|
254 screen52 = new Screen5250(); |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
255 handler = new tnvt(screen52, true, false, bridge, manager); |
68
cc7e3588a0f3
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
57
diff
changeset
|
256 String encryption = host.getEncryption5250(); |
cc7e3588a0f3
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
57
diff
changeset
|
257 if ((encryption == null) || (encryption.length() == 0)) encryption = "NONE"; |
cc7e3588a0f3
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
57
diff
changeset
|
258 handler.setSSLType(encryption); |
32
b086dd794dba
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
31
diff
changeset
|
259 screen52.setVT(handler); |
b086dd794dba
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
31
diff
changeset
|
260 screen52.setBuffer(buffer); |
69
294435151b0c
use 5250 encryption config entry
Carl Byington <carl@five-ten-sg.com>
parents:
68
diff
changeset
|
261 connected = handler.connect(host.getHostname(), host.getPort(), buffer); |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
262 if (connected) bridge.onConnected(); |
11 | 263 } |
264 | |
265 | |
266 /** | |
267 * Checks if read() will block. If there are no bytes remaining in | |
268 * the underlying transport, return true. | |
269 */ | |
270 @Override | |
271 public boolean willBlock() { | |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
272 // we don't use a relay thread between the transport and the vt320 buffer |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
273 return true; |
11 | 274 } |
275 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
276 |
11 | 277 /** |
278 * Reads from the transport. Transport must support reading into a byte array | |
279 * <code>buffer</code> at the start of <code>offset</code> and a maximum of | |
280 * <code>length</code> bytes. If the remote host disconnects, throw an | |
281 * {@link IOException}. | |
282 * @param buffer byte buffer to store read bytes into | |
283 * @param offset where to start writing in the buffer | |
284 * @param length maximum number of bytes to read | |
285 * @return number of bytes read | |
286 * @throws IOException when remote host disconnects | |
287 */ | |
288 public int read(byte[] buffer, int offset, int length) throws IOException { | |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
289 // we don't use a relay thread between the transport and the vt320 buffer |
11 | 290 return 0; |
291 } | |
292 | |
293 | |
294 /** | |
295 * Writes to the transport. If the host is not yet connected, simply return without | |
296 * doing anything. An {@link IOException} should be thrown if there is an error after | |
297 * connection. | |
298 * @param buffer bytes to write to transport | |
299 * @throws IOException when there is a problem writing after connection | |
300 */ | |
301 public void write(byte[] buffer) throws IOException { | |
302 } | |
303 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
304 |
11 | 305 /** |
306 * Writes to the transport. See {@link #write(byte[])} for behavior details. | |
307 * @param c character to write to the transport | |
308 * @throws IOException when there is a problem writing after connection | |
309 */ | |
310 public void write(int c) throws IOException { | |
311 } | |
312 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
313 |
11 | 314 /** |
315 * Flushes the write commands to the transport. | |
316 * @throws IOException when there is a problem writing after connection | |
317 */ | |
318 public void flush() throws IOException { | |
319 } | |
320 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
321 |
11 | 322 /** |
32
b086dd794dba
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
31
diff
changeset
|
323 * Closes the connection to the terminal. |
11 | 324 */ |
325 public void close() { | |
13 | 326 handler.disconnect(); |
11 | 327 connected = false; |
32
b086dd794dba
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
31
diff
changeset
|
328 bridge.dispatchDisconnect(false); |
11 | 329 } |
330 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
331 |
11 | 332 /** |
333 * Tells the transport what dimensions the display is currently | |
334 * @param columns columns of text | |
335 * @param rows rows of text | |
336 * @param width width in pixels | |
337 * @param height height in pixels | |
338 */ | |
339 @Override | |
340 public void setDimensions(int columns, int rows, int width, int height) { | |
341 // do nothing | |
342 } | |
343 | |
344 | |
345 @Override | |
45
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
346 public vt320 getTransportBuffer() { |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
347 buffer = new vt320x5250(); |
47
a3fd10a8c0de
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
46
diff
changeset
|
348 return setupTransportBuffer(); |
45
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
349 } |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
350 |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
351 |
80dcebe51af2
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
43
diff
changeset
|
352 @Override |
11 | 353 public int getDefaultPort() { |
354 return DEFAULT_PORT; | |
355 } | |
356 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
357 |
11 | 358 @Override |
359 public boolean isConnected() { | |
360 return connected; | |
361 } | |
362 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
363 |
11 | 364 @Override |
365 public boolean isSessionOpen() { | |
366 return connected; | |
367 } | |
368 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
369 |
11 | 370 @Override |
371 public boolean isAuthenticated() { | |
372 return connected; | |
373 } | |
374 | |
375 | |
376 @Override | |
377 public String getDefaultNickname(String username, String hostname, int port) { | |
378 if (port == DEFAULT_PORT) { | |
379 return String.format("%s", hostname); | |
380 } | |
381 else { | |
382 return String.format("%s:%d", hostname, port); | |
383 } | |
384 } | |
385 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
386 |
11 | 387 @Override |
388 public void getSelectionArgs(Uri uri, Map<String, String> selection) { | |
389 selection.put(HostDatabase.FIELD_HOST_PROTOCOL, PROTOCOL); | |
390 selection.put(HostDatabase.FIELD_HOST_NICKNAME, uri.getFragment()); | |
391 selection.put(HostDatabase.FIELD_HOST_HOSTNAME, uri.getHost()); | |
392 int port = uri.getPort(); | |
393 | |
394 if (port < 0) | |
395 port = DEFAULT_PORT; | |
396 | |
397 selection.put(HostDatabase.FIELD_HOST_PORT, Integer.toString(port)); | |
398 } | |
399 | |
400 | |
401 @Override | |
402 public HostBean createHost(Uri uri) { | |
403 HostBean host = new HostBean(); | |
404 host.setProtocol(PROTOCOL); | |
405 host.setHostname(uri.getHost()); | |
406 int port = uri.getPort(); | |
407 | |
408 if (port < 0) | |
409 port = DEFAULT_PORT; | |
410 | |
411 host.setPort(port); | |
412 String nickname = uri.getFragment(); | |
413 | |
414 if (nickname == null || nickname.length() == 0) { | |
415 host.setNickname(getDefaultNickname(host.getUsername(), | |
416 host.getHostname(), host.getPort())); | |
417 } | |
418 else { | |
419 host.setNickname(uri.getFragment()); | |
420 } | |
421 | |
422 return host; | |
423 } | |
424 | |
425 | |
12 | 426 public String getFormatHint(Context context) { |
11 | 427 return String.format("%s:%s", |
428 context.getString(R.string.format_hostname), | |
429 context.getString(R.string.format_port)); | |
430 } | |
431 | |
432 | |
433 @Override | |
434 public boolean usesNetwork() { | |
435 return true; | |
436 } | |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
437 |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
438 |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
439 @Override |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
440 public boolean needsRelay() { |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
441 // we don't use a relay thread between the transport and the vt320 buffer |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
442 return false; |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
443 } |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
23
diff
changeset
|
444 |
43
6b0f1ece1d91
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
37
diff
changeset
|
445 public TerminalKeyListener getTerminalKeyListener() { |
53
e872762ec105
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
52
diff
changeset
|
446 return new TerminalKeyListener(manager, bridge, buffer, host.getEncoding()); |
43
6b0f1ece1d91
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
37
diff
changeset
|
447 } |
6b0f1ece1d91
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
37
diff
changeset
|
448 |
11 | 449 } |