annotate src/com/five_ten_sg/connectbot/transport/TN5250.java @ 82:d8da9f32074c

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