Mercurial > 510Connectbot
annotate src/com/five_ten_sg/connectbot/transport/AbsTransport.java @ 33:2a8b52dbc104 tn5250
start tn5250 integration
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Tue, 10 Jun 2014 13:33:06 -0700 |
parents | 139394237973 |
children | 7ac846a07ed4 |
rev | line source |
---|---|
0 | 1 /* |
2 * ConnectBot: simple, powerful, open-source SSH client for Android | |
3 * Copyright 2007 Kenny Root, Jeffrey Sharkey | |
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.util.List; | |
22 import java.util.Map; | |
23 | |
24 import com.five_ten_sg.connectbot.bean.HostBean; | |
25 import com.five_ten_sg.connectbot.bean.PortForwardBean; | |
26 import com.five_ten_sg.connectbot.service.TerminalBridge; | |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
27 import com.five_ten_sg.connectbot.service.TerminalKeyListener; |
0 | 28 import com.five_ten_sg.connectbot.service.TerminalManager; |
29 import android.content.Context; | |
30 import android.net.Uri; | |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
31 import de.mud.terminal.vt320; |
0 | 32 |
33 /** | |
34 * @author Kenny Root | |
35 * | |
36 */ | |
37 public abstract class AbsTransport { | |
38 TerminalManager manager; | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
39 TerminalBridge bridge; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
40 HostBean host; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
41 vt320 buffer; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
42 String emulation; |
0 | 43 |
44 public AbsTransport() {} | |
45 | |
46 /** | |
47 * @return protocol part of the URI | |
48 */ | |
49 public static String getProtocolName() { | |
50 return "unknown"; | |
51 } | |
52 | |
53 /** | |
54 * Encode the current transport into a URI that can be passed via intent calls. | |
55 * @return URI to host | |
56 */ | |
11 | 57 public abstract Uri getUri(String input); |
58 | |
0 | 59 |
60 /** | |
61 * Causes transport to connect to the target host. After connecting but before a | |
62 * session is started, must call back to {@link TerminalBridge#onConnected()}. | |
63 * After that call a session may be opened. | |
64 */ | |
65 public abstract void connect(); | |
66 | |
67 /** | |
68 * Checks if read() will block. If there are no bytes remaining in | |
69 * the underlying transport, return true. | |
70 */ | |
71 public abstract boolean willBlock(); | |
72 | |
73 /** | |
74 * Reads from the transport. Transport must support reading into a byte array | |
75 * <code>buffer</code> at the start of <code>offset</code> and a maximum of | |
76 * <code>length</code> bytes. If the remote host disconnects, throw an | |
77 * {@link IOException}. | |
78 * @param buffer byte buffer to store read bytes into | |
79 * @param offset where to start writing in the buffer | |
80 * @param length maximum number of bytes to read | |
81 * @return number of bytes read | |
82 * @throws IOException when remote host disconnects | |
83 */ | |
84 public abstract int read(byte[] buffer, int offset, int length) throws IOException; | |
85 | |
86 /** | |
87 * Writes to the transport. If the host is not yet connected, simply return without | |
88 * doing anything. An {@link IOException} should be thrown if there is an error after | |
89 * connection. | |
90 * @param buffer bytes to write to transport | |
91 * @throws IOException when there is a problem writing after connection | |
92 */ | |
93 public abstract void write(byte[] buffer) throws IOException; | |
94 | |
95 /** | |
96 * Writes to the transport. See {@link #write(byte[])} for behavior details. | |
97 * @param c character to write to the transport | |
98 * @throws IOException when there is a problem writing after connection | |
99 */ | |
100 public abstract void write(int c) throws IOException; | |
101 | |
102 /** | |
103 * Flushes the write commands to the transport. | |
104 * @throws IOException when there is a problem writing after connection | |
105 */ | |
106 public abstract void flush() throws IOException; | |
107 | |
108 /** | |
109 * Closes the connection to the terminal. Note that the resulting failure to read | |
110 * should call {@link TerminalBridge#dispatchDisconnect(boolean)}. | |
111 */ | |
112 public abstract void close(); | |
113 | |
114 /** | |
115 * Tells the transport what dimensions the display is currently | |
116 * @param columns columns of text | |
117 * @param rows rows of text | |
118 * @param width width in pixels | |
119 * @param height height in pixels | |
120 */ | |
121 public abstract void setDimensions(int columns, int rows, int width, int height); | |
122 | |
123 public void setOptions(Map<String, String> options) { | |
124 // do nothing | |
125 } | |
126 | |
127 public Map<String, String> getOptions() { | |
128 return null; | |
129 } | |
130 | |
131 public void setCompression(boolean compression) { | |
132 // do nothing | |
133 } | |
134 | |
135 public void setHttpproxy(String httpproxy) { | |
136 // do nothing | |
137 } | |
138 | |
139 public void setUseAuthAgent(String useAuthAgent) { | |
140 // do nothing | |
141 } | |
142 | |
143 public String getEmulation() { | |
144 return emulation; | |
145 } | |
146 | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
147 public void setLinks(TerminalManager manager, TerminalBridge bridge, HostBean host, vt320 buffer, String emulation) { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
148 this.manager = manager; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
149 this.bridge = bridge; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
150 this.host = host; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
151 this.buffer = buffer; |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
152 this.emulation = emulation; |
0 | 153 } |
154 | |
155 /** | |
156 * Whether or not this transport type can forward ports. | |
157 * @return true on ability to forward ports | |
158 */ | |
159 public boolean canForwardPorts() { | |
160 return false; | |
161 } | |
162 | |
163 /** | |
164 * Adds the {@link PortForwardBean} to the list. | |
165 * @param portForward the port forward bean to add | |
166 * @return true on successful addition | |
167 */ | |
168 public boolean addPortForward(PortForwardBean portForward) { | |
169 return false; | |
170 } | |
171 | |
172 /** | |
173 * Enables a port forward member. After calling this method, the port forward should | |
174 * be operational iff it could be enabled by the transport. | |
175 * @param portForward member of our current port forwards list to enable | |
176 * @return true on successful port forward setup | |
177 */ | |
178 public boolean enablePortForward(PortForwardBean portForward) { | |
179 return false; | |
180 } | |
181 | |
182 /** | |
183 * Disables a port forward member. After calling this method, the port forward should | |
184 * be non-functioning iff it could be disabled by the transport. | |
185 * @param portForward member of our current port forwards list to enable | |
186 * @return true on successful port forward tear-down | |
187 */ | |
188 public boolean disablePortForward(PortForwardBean portForward) { | |
189 return false; | |
190 } | |
191 | |
192 /** | |
193 * Removes the {@link PortForwardBean} from the available port forwards. | |
194 * @param portForward the port forward bean to remove | |
195 * @return true on successful removal | |
196 */ | |
197 public boolean removePortForward(PortForwardBean portForward) { | |
198 return false; | |
199 } | |
200 | |
201 /** | |
202 * Gets a list of the {@link PortForwardBean} currently used by this transport. | |
203 * @return the list of port forwards | |
204 */ | |
205 public List<PortForwardBean> getPortForwards() { | |
206 return null; | |
207 } | |
208 | |
209 /** | |
210 * Whether or not this transport type can transfer files. | |
211 * @return true on ability to transfer files | |
212 */ | |
213 public boolean canTransferFiles() { | |
214 return false; | |
215 } | |
216 | |
217 /** | |
218 * Downloads the specified remote file to a local folder. | |
219 * @param remoteFile The path to the remote file to be downloaded. Must be non-null. | |
220 * @param localFolder The path to local folder. Null = default external storage folder. | |
221 * @return true on success, false on failure | |
222 */ | |
223 public boolean downloadFile(String remoteFile, String localFolder) { | |
224 return false; | |
225 } | |
226 | |
227 /** | |
228 * Uploads the specified local file to the remote host. | |
229 * @param localFile The path to the local file to be uploaded. Must be non-null. | |
230 * @param remoteFolder The path to the remote directory. Null == default remote directory. | |
231 * @return true on success, false on failure | |
232 */ | |
233 public boolean uploadFile(String localFile, String remoteFile, | |
234 String remoteFolder, String mode) { | |
235 return false; | |
236 } | |
237 | |
238 | |
239 /** | |
240 * @return int default port for protocol | |
241 */ | |
242 public abstract int getDefaultPort(); | |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
243 public abstract boolean isConnected(); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
244 public abstract boolean isSessionOpen(); |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
245 public abstract boolean isAuthenticated(); |
0 | 246 |
247 /** | |
248 * @param username | |
249 * @param hostname | |
250 * @param port | |
251 * @return | |
252 */ | |
253 public abstract String getDefaultNickname(String username, String hostname, int port); | |
254 | |
255 /** | |
256 * @param uri | |
257 * @param selectionKeys | |
258 * @param selectionValues | |
259 */ | |
260 public abstract void getSelectionArgs(Uri uri, Map<String, String> selection); | |
261 | |
262 /** | |
263 * @param uri | |
264 * @return | |
265 */ | |
266 public abstract HostBean createHost(Uri uri); | |
267 | |
268 /** | |
269 * @param context context containing the correct resources | |
270 * @return string that hints at the format for connection | |
271 */ | |
11 | 272 public abstract String getFormatHint(Context context); |
0 | 273 |
274 /** | |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
275 * @return do we use the network |
0 | 276 */ |
277 public abstract boolean usesNetwork(); | |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
278 |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
279 /** |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
280 * @return do we need a relay object to read from the transport |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
281 * and send the data into the vt320 buffer |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
282 */ |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
283 public boolean needsRelay() { |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
284 return true; |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
285 } |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
286 |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
287 /** |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
288 * @return a key listener |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
289 */ |
31
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
290 public TerminalKeyListener getTerminalKeyListener() { |
139394237973
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
30
diff
changeset
|
291 return new TerminalKeyListener(manager, bridge, buffer, host.getEncoding()); |
29
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
292 } |
017eeed8332c
start tn5250 integration
Carl Byington <carl@five-ten-sg.com>
parents:
11
diff
changeset
|
293 |
0 | 294 } |