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