comparison src/com/five_ten_sg/connectbot/transport/TN5250.java @ 29:017eeed8332c tn5250

start tn5250 integration
author Carl Byington <carl@five-ten-sg.com>
date Tue, 03 Jun 2014 16:02:29 -0700
parents cfcb8d9859a8
children d738f6b876fe
comparison
equal deleted inserted replaced
28:ad194aedeaab 29:017eeed8332c
33 33
34 import com.five_ten_sg.connectbot.R; 34 import com.five_ten_sg.connectbot.R;
35 import com.five_ten_sg.connectbot.bean.HostBean; 35 import com.five_ten_sg.connectbot.bean.HostBean;
36 import com.five_ten_sg.connectbot.bean.PortForwardBean; 36 import com.five_ten_sg.connectbot.bean.PortForwardBean;
37 import com.five_ten_sg.connectbot.service.TerminalBridge; 37 import com.five_ten_sg.connectbot.service.TerminalBridge;
38 import com.five_ten_sg.connectbot.service.TerminalKeyListener;
38 import com.five_ten_sg.connectbot.service.TerminalManager; 39 import com.five_ten_sg.connectbot.service.TerminalManager;
39 import com.five_ten_sg.connectbot.util.HostDatabase; 40 import com.five_ten_sg.connectbot.util.HostDatabase;
40
41 import android.content.Context; 41 import android.content.Context;
42 import android.net.Uri; 42 import android.net.Uri;
43 import android.util.Log; 43 import android.util.Log;
44 import de.mud.terminal.vt320;
44 45
45 46
46 /** 47 /**
47 * @author Carl Byington 48 * @author Carl Byington
48 * 49 *
54 private Screen5250 screen52; 55 private Screen5250 screen52;
55 56
56 private tnvt handler = null; 57 private tnvt handler = null;
57 private Socket socket; 58 private Socket socket;
58 59
59 private InputStream is;
60 private OutputStream os;
61 private int width; 60 private int width;
62 private int height; 61 private int height;
63 62
64 private boolean connected = false; 63 private boolean connected = false;
65 64
73 super(); 72 super();
74 } 73 }
75 74
76 public TN5250(HostBean host, TerminalBridge bridge, TerminalManager manager) { 75 public TN5250(HostBean host, TerminalBridge bridge, TerminalManager manager) {
77 super(host, bridge, manager); 76 super(host, bridge, manager);
78 handler = new tnvt(screen52, true, false, bridge, manager);
79 } 77 }
80 78
81 79
82 /** 80 /**
83 * @return protocol part of the URI 81 * @return protocol part of the URI
128 * session is started, must call back to {@link TerminalBridge#onConnected()}. 126 * session is started, must call back to {@link TerminalBridge#onConnected()}.
129 * After that call a session may be opened. 127 * After that call a session may be opened.
130 */ 128 */
131 @Override 129 @Override
132 public void connect() { 130 public void connect() {
131 screen52 = new Screen5250;
132 handler = new tnvt(screen52, true, false, bridge, manager);
133 connected = handler.connect(host.getHostname(), host.getPort()); 133 connected = handler.connect(host.getHostname(), host.getPort());
134 if (connected) { 134 if (connected) bridge.onConnected();
135 is = handler.bin;
136 os = handler.bout;
137 bridge.onConnected();
138 }
139 } 135 }
140 136
141 137
142 /** 138 /**
143 * Checks if read() will block. If there are no bytes remaining in 139 * Checks if read() will block. If there are no bytes remaining in
144 * the underlying transport, return true. 140 * the underlying transport, return true.
145 */ 141 */
146 @Override 142 @Override
147 public boolean willBlock() { 143 public boolean willBlock() {
148 if (is == null) return true; 144 // we don't use a relay thread between the transport and the vt320 buffer
149 try { 145 return true;
150 return is.available() == 0;
151 } catch (Exception e) {
152 return true;
153 }
154 } 146 }
155 147
156 /** 148 /**
157 * Reads from the transport. Transport must support reading into a byte array 149 * Reads from the transport. Transport must support reading into a byte array
158 * <code>buffer</code> at the start of <code>offset</code> and a maximum of 150 * <code>buffer</code> at the start of <code>offset</code> and a maximum of
163 * @param length maximum number of bytes to read 155 * @param length maximum number of bytes to read
164 * @return number of bytes read 156 * @return number of bytes read
165 * @throws IOException when remote host disconnects 157 * @throws IOException when remote host disconnects
166 */ 158 */
167 public int read(byte[] buffer, int offset, int length) throws IOException { 159 public int read(byte[] buffer, int offset, int length) throws IOException {
160 // we don't use a relay thread between the transport and the vt320 buffer
168 return 0; 161 return 0;
169 } 162 }
170 163
171 164
172 /** 165 /**
194 public void flush() throws IOException { 187 public void flush() throws IOException {
195 } 188 }
196 189
197 /** 190 /**
198 * Closes the connection to the terminal. Note that the resulting failure to read 191 * Closes the connection to the terminal. Note that the resulting failure to read
199 * should call {@link TerminalBridge#dispatchDisconnect(boolean)}. 192 * should call {@link TerminalBridge#dispatchDisconnect(boolean)}. !!!
200 */ 193 */
201 public void close() { 194 public void close() {
202 handler.disconnect(); 195 handler.disconnect();
203 connected = false; 196 connected = false;
204 } 197 }
417 410
418 @Override 411 @Override
419 public boolean usesNetwork() { 412 public boolean usesNetwork() {
420 return true; 413 return true;
421 } 414 }
415
416
417 @Override
418 public boolean needsRelay() {
419 // we don't use a relay thread between the transport and the vt320 buffer
420 return false;
421 }
422
423
424 @Override
425 public TerminalKeyListener(TerminalManager manager, TerminalBridge bridge, vt320 buffer, String encoding) {
426 return new TerminalKeyListener(manager, bridge, buffer, encoding);
427 }
428
422 } 429 }