comparison src/com/five_ten_sg/connectbot/transport/Local.java @ 31:139394237973 tn5250

start tn5250 integration
author Carl Byington <carl@five-ten-sg.com>
date Tue, 10 Jun 2014 12:00:07 -0700
parents 6aaefb22d876
children 77ac18bc1b2f
comparison
equal deleted inserted replaced
30:d738f6b876fe 31:139394237973
39 * 39 *
40 */ 40 */
41 public class Local extends AbsTransport { 41 public class Local extends AbsTransport {
42 private static final String TAG = "ConnectBot.Local"; 42 private static final String TAG = "ConnectBot.Local";
43 private static final String PROTOCOL = "local"; 43 private static final String PROTOCOL = "local";
44
45 private static final String DEFAULT_URI = "local:#Local"; 44 private static final String DEFAULT_URI = "local:#Local";
46 45
47 private FileDescriptor shellFd; 46 private FileDescriptor shellFd;
48 47 private FileInputStream is;
49 private FileInputStream is;
50 private FileOutputStream os; 48 private FileOutputStream os;
51 49
52 /** 50 /**
53 * 51 *
54 */ 52 */
55 public Local() { 53 public Local() {
56 } 54 }
57 55
58 /**
59 * @param host
60 * @param bridge
61 * @param manager
62 */
63 public Local(HostBean host, TerminalBridge bridge, TerminalManager manager) {
64 super(host, bridge, manager);
65 }
66 56
67 public static String getProtocolName() { 57 public static String getProtocolName() {
68 return PROTOCOL; 58 return PROTOCOL;
69 } 59 }
70 60
71 @Override 61
72 public void close() { 62 public Uri getUri(String input) {
73 try { 63 Uri uri = Uri.parse(DEFAULT_URI);
74 if (os != null) { 64
75 os.close(); 65 if (input != null && input.length() > 0) {
76 os = null; 66 uri = uri.buildUpon().fragment(input).build();
77 } 67 }
78 68
79 if (is != null) { 69 return uri;
80 is.close(); 70 }
81 is = null; 71
82 }
83 }
84 catch (IOException e) {
85 Log.e(TAG, "Couldn't close shell", e);
86 }
87 }
88 72
89 @Override 73 @Override
90 public void connect() { 74 public void connect() {
91 int[] pids = new int[1]; 75 int[] pids = new int[1];
92 76
113 is = new FileInputStream(shellFd); 97 is = new FileInputStream(shellFd);
114 os = new FileOutputStream(shellFd); 98 os = new FileOutputStream(shellFd);
115 bridge.onConnected(); 99 bridge.onConnected();
116 } 100 }
117 101
118 @Override
119 public void flush() throws IOException {
120 os.flush();
121 }
122
123 @Override
124 public String getDefaultNickname(String username, String hostname, int port) {
125 return DEFAULT_URI;
126 }
127
128 @Override
129 public int getDefaultPort() {
130 return 0;
131 }
132
133 @Override
134 public boolean isConnected() {
135 return is != null && os != null;
136 }
137
138 @Override
139 public boolean isSessionOpen() {
140 return is != null && os != null;
141 }
142
143 @Override
144 public boolean isAuthenticated() {
145 return isConnected();
146 }
147 102
148 @Override 103 @Override
149 public boolean willBlock() { 104 public boolean willBlock() {
150 if (is == null) return true; 105 if (is == null) return true;
151 try { 106 try {
164 119
165 return is.read(buffer, start, len); 120 return is.read(buffer, start, len);
166 } 121 }
167 122
168 @Override 123 @Override
169 public void setDimensions(int columns, int rows, int width, int height) {
170 try {
171 Exec.setPtyWindowSize(shellFd, rows, columns, width, height);
172 }
173 catch (Exception e) {
174 Log.e(TAG, "Couldn't resize pty", e);
175 }
176 }
177
178 @Override
179 public void write(byte[] buffer) throws IOException { 124 public void write(byte[] buffer) throws IOException {
180 if (os != null) 125 if (os != null)
181 os.write(buffer); 126 os.write(buffer);
182 } 127 }
183 128
185 public void write(int c) throws IOException { 130 public void write(int c) throws IOException {
186 if (os != null) 131 if (os != null)
187 os.write(c); 132 os.write(c);
188 } 133 }
189 134
190 public Uri getUri(String input) { 135 @Override
191 Uri uri = Uri.parse(DEFAULT_URI); 136 public void flush() throws IOException {
192 137 os.flush();
193 if (input != null && input.length() > 0) { 138 }
194 uri = uri.buildUpon().fragment(input).build(); 139
195 } 140 @Override
196 141 public void close() {
197 return uri; 142 try {
143 if (os != null) {
144 os.close();
145 os = null;
146 }
147
148 if (is != null) {
149 is.close();
150 is = null;
151 }
152 }
153 catch (IOException e) {
154 Log.e(TAG, "Couldn't close shell", e);
155 }
156 }
157
158 @Override
159 public void setDimensions(int columns, int rows, int width, int height) {
160 try {
161 Exec.setPtyWindowSize(shellFd, rows, columns, width, height);
162 }
163 catch (Exception e) {
164 Log.e(TAG, "Couldn't resize pty", e);
165 }
166 }
167
168 @Override
169 public int getDefaultPort() {
170 return 0;
171 }
172
173 @Override
174 public boolean isConnected() {
175 return is != null && os != null;
176 }
177
178 @Override
179 public boolean isSessionOpen() {
180 return isConnected();
181 }
182
183 @Override
184 public boolean isAuthenticated() {
185 return isConnected();
186 }
187
188 @Override
189 public String getDefaultNickname(String username, String hostname, int port) {
190 return DEFAULT_URI;
191 }
192
193 @Override
194 public void getSelectionArgs(Uri uri, Map<String, String> selection) {
195 selection.put(HostDatabase.FIELD_HOST_PROTOCOL, PROTOCOL);
196 selection.put(HostDatabase.FIELD_HOST_NICKNAME, uri.getFragment());
198 } 197 }
199 198
200 @Override 199 @Override
201 public HostBean createHost(Uri uri) { 200 public HostBean createHost(Uri uri) {
202 HostBean host = new HostBean(); 201 HostBean host = new HostBean();
212 } 211 }
213 212
214 return host; 213 return host;
215 } 214 }
216 215
217 @Override
218 public void getSelectionArgs(Uri uri, Map<String, String> selection) {
219 selection.put(HostDatabase.FIELD_HOST_PROTOCOL, PROTOCOL);
220 selection.put(HostDatabase.FIELD_HOST_NICKNAME, uri.getFragment());
221 }
222
223 public String getFormatHint(Context context) { 216 public String getFormatHint(Context context) {
224 return context.getString(R.string.hostpref_nickname_title); 217 return context.getString(R.string.hostpref_nickname_title);
225 } 218 }
226 219
227 @Override 220 @Override