Mercurial > hg > trac > TreeVNC > TreeVNC
annotate src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java @ 118:38e461e9b9c9
remove duplicated code in MyRfbProto*
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 26 May 2014 18:30:18 +0900 |
parents | 804b1ce07aa0 |
children | a6dc674546f2 |
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; |
10 | |
59 | 11 import com.glavsoft.core.SettingsChangedEvent; |
11 | 12 import com.glavsoft.rfb.IChangeSettingsListener; |
13 import com.glavsoft.rfb.IRfbSessionListener; | |
14 import com.glavsoft.rfb.protocol.ProtocolSettings; | |
15 import com.glavsoft.viewer.Viewer; | |
16 import com.glavsoft.viewer.cli.Parser; | |
82 | 17 import com.glavsoft.viewer.swing.ConnectionParams; |
11 | 18 import com.glavsoft.viewer.swing.ParametersHandler; |
19 | |
45 | 20 public class VncProxyService extends Viewer implements Runnable, |
21 IRfbSessionListener, IChangeSettingsListener { | |
11 | 22 |
23 /** | |
24 * | |
25 */ | |
26 private static final long serialVersionUID = 1L; | |
27 | |
46 | 28 public static Logger logger = Logger.getLogger("com.glavsoft"); |
29 private boolean forceReconnection; | |
30 private String reconnectionReason; | |
31 private AcceptThread acceptThread; | |
32 private GetBroadCastProxy getCast; | |
92 | 33 private AcceptClient clients; |
40 | 34 public int opendPort; |
47 | 35 static VncProxyService currentVps; |
50
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
36 private int fbWidth = 0; |
69 | 37 private boolean firstTime = true; |
46 | 38 |
82 | 39 private int vncport = ConnectionParams.DEFAULT_RFB_PORT; |
40 | |
11 | 41 public VncProxyService() { |
77 | 42 ProtocolSettings.getDefaultSettings(); |
11 | 43 uiSettings = super.uiSettings; |
44 } | |
45 | 45 |
47 | 46 public VncProxyService(VncProxyService vps, String hostName) { |
47 this(); | |
48 connectionParams.hostName = hostName; | |
60 | 49 myRfb = vps.myRfb; |
47 | 50 forceReconnection = vps.forceReconnection; |
51 reconnectionReason = vps.reconnectionReason; | |
52 acceptThread = vps.acceptThread; | |
53 getCast = vps.getCast; | |
92 | 54 clients = vps.clients; |
47 | 55 opendPort = vps.opendPort; |
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); |
92 | 78 clients = new AcceptClient(); |
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(); |
85 try { | |
86 threadSetAndStart(); | |
87 } catch (UnknownHostException e) { | |
60 | 88 |
46 | 89 } catch (IOException e) { |
90 | |
91 } | |
11 | 92 } |
97 | 93 |
106
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
94 /** |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
95 * start new VNC server receiver with |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
96 * inherited clients |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
97 * @param vs |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
98 * @param hostName |
01c0fd20c0b4
share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
102
diff
changeset
|
99 */ |
97 | 100 private void inhelitClients(VncProxyService vs, String hostName) { |
101 myRfb.setReadyReconnect(false); | |
102 setConnectionParam(hostName,vncport); | |
103 isApplet = true; | |
104 this.setNoConnection(false); | |
105 run(); | |
106 firstTime = false; | |
107 createConnectionAndStart(); | |
108 } | |
45 | 109 |
38 | 110 public void createConnectionAndStart() { |
40 | 111 Thread thread; |
60 | 112 opendPort = myRfb.selectPort(5999); |
113 acceptThread = new AcceptThread(myRfb, opendPort); | |
88 | 114 thread = new Thread(acceptThread, "TreeVNC-accept"); |
38 | 115 thread.start(); |
69 | 116 if(firstTime) { |
117 getCast = new GetBroadCastProxy(this, | |
118 this.connectionParams.getHostName(), | |
119 this.connectionParams.getHostName()); | |
120 thread = new Thread(getCast); | |
121 thread.start(); | |
122 } | |
13 | 123 } |
11 | 124 |
60 | 125 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
|
126 fbWidth = width; |
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
127 proxyStart(argv); |
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
128 } |
60 | 129 |
34 | 130 public void proxyStart(String[] argv) { |
131 // input into arguments Decision | |
132 Parser parser = new Parser(); | |
133 ParametersHandler.completeParserOptions(parser); | |
60 | 134 if (fbWidth == 0) |
50
225e3873d75f
Modified to be able to specify the region of the screen in the argument.
one
parents:
49
diff
changeset
|
135 parser.parse(argv); |
34 | 136 if (parser.isSet(ParametersHandler.ARG_HELP)) { |
137 printUsage(parser.optionsUsage()); | |
138 System.exit(0); | |
139 } | |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
140 initProxy1("localhost"); |
34 | 141 } |
142 | |
11 | 143 @Override |
144 public void destroy() { | |
145 | |
146 } | |
147 | |
148 @Override | |
149 public void windowClosing(WindowEvent e) { | |
150 if (e != null && e.getComponent() != null) { | |
151 e.getWindow().setVisible(false); | |
152 } | |
153 closeApp(); | |
154 } | |
45 | 155 |
38 | 156 private void threadSetAndStart() throws UnknownHostException, IOException { |
92 | 157 CreateThread createThread = new CreateThread(clients); |
38 | 158 Thread thread = new Thread(createThread); |
37 | 159 thread.start(); |
160 } | |
45 | 161 |
38 | 162 protected void socketClose() { |
163 } | |
45 | 164 |
38 | 165 @Override |
166 public void rfbSessionStopped(final String reason) { | |
59 | 167 |
38 | 168 } |
45 | 169 |
60 | 170 |
55 | 171 /** |
60 | 172 * chnageVNCServer is called when host change. |
173 * | |
174 * @param hostName | |
175 * HostAddress | |
176 * @param width | |
177 * FrameWidth | |
178 * @param height | |
179 * FrameHeight | |
94
75879c316796
synchronized wait for Rfb initialization in change server.
oc
parents:
93
diff
changeset
|
180 * @throws InterruptedException |
55 | 181 */ |
60 | 182 public void changeVNCServer(String hostName, int width, int height) |
94
75879c316796
synchronized wait for Rfb initialization in change server.
oc
parents:
93
diff
changeset
|
183 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
|
184 // 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
|
185 myRfb.stopReceiverTask(); |
97 | 186 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
|
187 orderRecconection(hostName); |
59 | 188 } |
189 | |
97 | 190 |
191 | |
59 | 192 @Override |
193 public void settingsChanged(SettingsChangedEvent event) { | |
60 | 194 |
38 | 195 } |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
196 |
69 | 197 public void setFirstTime(boolean flag) { |
198 firstTime = flag; | |
199 } | |
200 | |
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
|
201 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
|
202 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
|
203 myRfb.sendDesktopSizeChange(); |
61
d9cf08c6415c
During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
60
diff
changeset
|
204 } |
93 | 205 |
206 public LinkedList<String> clientList() { | |
207 return clients.getList(); | |
208 } | |
11 | 209 } |