Mercurial > hg > Members > riono > TreeVNC_ja_comment
annotate src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java @ 142:d2af9edb1803
fix selectRfbSelectPort.
author | oc |
---|---|
date | Thu, 12 Jun 2014 18:04:22 +0900 |
parents | c3761c896607 |
children | 4547543ca73c |
rev | line source |
---|---|
12 | 1 package jp.ac.u_ryukyu.treevnc.server; |
11 | 2 |
3 import java.awt.event.*; | |
4 import java.io.*; | |
38 | 5 import java.net.UnknownHostException; |
6 import java.util.LinkedList; | |
11 | 7 import java.util.logging.Logger; |
8 | |
31 | 9 import jp.ac.u_ryukyu.treevnc.AcceptThread; |
138 | 10 import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol; |
129 | 11 import jp.ac.u_ryukyu.treevnc.client.TreeVncRootSelectionPanel; |
31 | 12 |
59 | 13 import com.glavsoft.core.SettingsChangedEvent; |
11 | 14 import com.glavsoft.rfb.IChangeSettingsListener; |
15 import com.glavsoft.rfb.IRfbSessionListener; | |
16 import com.glavsoft.rfb.protocol.ProtocolSettings; | |
17 import com.glavsoft.viewer.Viewer; | |
18 import com.glavsoft.viewer.cli.Parser; | |
82 | 19 import com.glavsoft.viewer.swing.ConnectionParams; |
11 | 20 import com.glavsoft.viewer.swing.ParametersHandler; |
21 | |
45 | 22 public class VncProxyService extends Viewer implements Runnable, |
23 IRfbSessionListener, IChangeSettingsListener { | |
11 | 24 |
25 /** | |
26 * | |
27 */ | |
28 private static final long serialVersionUID = 1L; | |
29 | |
46 | 30 public static Logger logger = Logger.getLogger("com.glavsoft"); |
31 private boolean forceReconnection; | |
32 private String reconnectionReason; | |
33 private AcceptThread acceptThread; | |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
34 private TreeRootFinderListener getCast; |
92 | 35 private AcceptClient clients; |
47 | 36 static VncProxyService currentVps; |
50
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
37 private int fbWidth = 0; |
69 | 38 private boolean firstTime = true; |
46 | 39 |
82 | 40 private int vncport = ConnectionParams.DEFAULT_RFB_PORT; |
41 | |
11 | 42 public VncProxyService() { |
77 | 43 ProtocolSettings.getDefaultSettings(); |
11 | 44 uiSettings = super.uiSettings; |
45 } | |
45 | 46 |
47 | 47 public VncProxyService(VncProxyService vps, String hostName) { |
48 this(); | |
49 connectionParams.hostName = hostName; | |
60 | 50 myRfb = vps.myRfb; |
47 | 51 forceReconnection = vps.forceReconnection; |
52 reconnectionReason = vps.reconnectionReason; | |
53 acceptThread = vps.acceptThread; | |
54 getCast = vps.getCast; | |
92 | 55 clients = vps.clients; |
47 | 56 } |
57 | |
11 | 58 public static void main(String[] argv) { |
59 String[] mainArgs = argv; | |
60 System.out.println(mainArgs.length); | |
61 // input into arguments Decision | |
60 | 62 |
11 | 63 Parser parser = new Parser(); |
64 ParametersHandler.completeParserOptions(parser); | |
65 | |
66 parser.parse(argv); | |
67 if (parser.isSet(ParametersHandler.ARG_HELP)) { | |
68 printUsage(parser.optionsUsage()); | |
69 System.exit(0); | |
70 } | |
46 | 71 VncProxyService vps = new VncProxyService(); |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
72 vps.initProxy1("localhost"); |
46 | 73 } |
74 | |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
75 private void initProxy1(String hostName) { |
60 | 76 myRfb = new MyRfbProtoProxy(); |
111 | 77 myRfb.setVncProxy(this); |
138 | 78 clients = new AcceptClient(hostName, vncport); |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
79 isApplet = false; |
60 | 80 setIsTreeVNC(true); |
82 | 81 setConnectionParam(hostName,vncport); |
60 | 82 isApplet = true; |
83 run(); | |
46 | 84 createConnectionAndStart(); |
11 | 85 } |
97 | 86 |
106
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
87 /** |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
88 * start new VNC server receiver with |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
89 * inherited clients |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
90 * @param vs |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
91 * @param hostName |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
92 */ |
97 | 93 private void inhelitClients(VncProxyService vs, String hostName) { |
94 myRfb.setReadyReconnect(false); | |
95 setConnectionParam(hostName,vncport); | |
96 isApplet = true; | |
97 this.setNoConnection(false); | |
98 run(); | |
99 firstTime = false; | |
100 createConnectionAndStart(); | |
101 } | |
45 | 102 |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
103 /** |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
104 * start accepting children |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
105 * run rootFinderListener if necessary |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
106 */ |
38 | 107 public void createConnectionAndStart() { |
142 | 108 myRfb.selectPort(ConnectionParams.DEFAULT_VNC_ROOT); |
109 acceptThread = new AcceptThread(myRfb, myRfb.getAcceptPort()); | |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
110 Thread thread = new Thread(acceptThread, "TreeVNC-accept"); |
38 | 111 thread.start(); |
69 | 112 if(firstTime) { |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
113 getCast = new TreeRootFinderListener(this); |
69 | 114 thread = new Thread(getCast); |
115 thread.start(); | |
116 } | |
13 | 117 } |
11 | 118 |
60 | 119 public void proxyStart(String[] argv, int width, int height) { |
50
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
120 fbWidth = width; |
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
121 proxyStart(argv); |
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
122 } |
60 | 123 |
34 | 124 public void proxyStart(String[] argv) { |
125 // input into arguments Decision | |
126 Parser parser = new Parser(); | |
127 ParametersHandler.completeParserOptions(parser); | |
60 | 128 if (fbWidth == 0) |
50
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
129 parser.parse(argv); |
34 | 130 if (parser.isSet(ParametersHandler.ARG_HELP)) { |
131 printUsage(parser.optionsUsage()); | |
132 System.exit(0); | |
133 } | |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
134 initProxy1("localhost"); |
34 | 135 } |
136 | |
11 | 137 @Override |
138 public void destroy() { | |
139 | |
140 } | |
141 | |
142 @Override | |
143 public void windowClosing(WindowEvent e) { | |
144 if (e != null && e.getComponent() != null) { | |
145 e.getWindow().setVisible(false); | |
146 } | |
147 closeApp(); | |
148 } | |
45 | 149 |
38 | 150 protected void socketClose() { |
151 } | |
45 | 152 |
38 | 153 @Override |
154 public void rfbSessionStopped(final String reason) { | |
59 | 155 |
38 | 156 } |
45 | 157 |
60 | 158 |
55 | 159 /** |
60 | 160 * chnageVNCServer is called when host change. |
161 * | |
162 * @param hostName | |
163 * HostAddress | |
164 * @param width | |
165 * FrameWidth | |
166 * @param height | |
167 * FrameHeight | |
94
75879c316796
synchronized wait for Rfb initialization in change server.
oc
parents:
93
diff
changeset
|
168 * @throws InterruptedException |
55 | 169 */ |
60 | 170 public void changeVNCServer(String hostName, int width, int height) |
94
75879c316796
synchronized wait for Rfb initialization in change server.
oc
parents:
93
diff
changeset
|
171 throws UnknownHostException, IOException, InterruptedException { |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
172 // stop reader stop |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
173 myRfb.stopReceiverTask(); |
97 | 174 inhelitClients(this, hostName); |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
175 orderRecconection(hostName); |
59 | 176 } |
177 | |
97 | 178 |
179 | |
59 | 180 @Override |
181 public void settingsChanged(SettingsChangedEvent event) { | |
60 | 182 |
38 | 183 } |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
184 |
69 | 185 public void setFirstTime(boolean flag) { |
186 firstTime = flag; | |
187 } | |
188 | |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
189 public void orderRecconection(String hostName) throws UnknownHostException, IOException, InterruptedException { |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
190 myRfb.waitForReady(this); |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
97
diff
changeset
|
191 myRfb.sendDesktopSizeChange(); |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
192 } |
93 | 193 |
133 | 194 public LinkedList<TreeVNCNode> clientList() { |
93 | 195 return clients.getList(); |
196 } | |
129 | 197 |
198 public void addHostToSelectionPanel(int port, String hostname) { | |
199 if (rootSelectionPanel != null) { | |
200 rootSelectionPanel.checkBox(Integer.toString(port) + ":" + hostname); | |
201 rootSelectionPanel.setButton(); | |
202 rootSelectionPanel.visible(); | |
203 } | |
204 } | |
205 | |
206 public void createRootSelectionPanel() { | |
207 rootSelectionPanel = new TreeVncRootSelectionPanel(); | |
208 } | |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
209 |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
210 public void replyCreateTree(String hostname, int port) { |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
211 clients.replyCreateTree(hostname,port); |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
212 } |
136 | 213 |
214 public void fixLostParent(String hostname, int port) { | |
215 clients.fixLostParent(hostname,port); | |
216 } | |
11 | 217 } |