Mercurial > hg > Members > riono > TreeVNC_ja_comment
annotate src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java @ 378:60abae693629
Compare SerialNumber flag
author | innparusu |
---|---|
date | Tue, 01 Sep 2015 15:04:10 +0900 |
parents | b6665f7f18d1 |
children | aef5cbdd84ab |
rev | line source |
---|---|
32 | 1 package jp.ac.u_ryukyu.treevnc; |
28 | 2 |
3 import java.io.IOException; | |
206 | 4 import java.io.OutputStream; |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
5 import java.io.UnsupportedEncodingException; |
291 | 6 import java.net.*; |
28 | 7 import java.nio.ByteBuffer; |
109 | 8 import java.nio.ByteOrder; |
369 | 9 import java.util.Enumeration; |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
10 import java.util.Iterator; |
28 | 11 import java.util.LinkedList; |
12 import java.util.concurrent.atomic.AtomicInteger; | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
13 import java.util.zip.DataFormatException; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
14 import java.util.zip.Deflater; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
15 import java.util.zip.Inflater; |
150 | 16 |
28 | 17 import com.glavsoft.exceptions.TransportException; |
107 | 18 import com.glavsoft.rfb.client.ClientToServerMessage; |
96 | 19 import com.glavsoft.rfb.encoding.EncodingType; |
264 | 20 import com.glavsoft.rfb.encoding.decoder.FramebufferUpdateRectangle; |
28 | 21 import com.glavsoft.rfb.protocol.Protocol; |
22 import com.glavsoft.rfb.protocol.ProtocolContext; | |
23 import com.glavsoft.transport.Reader; | |
24 import com.glavsoft.transport.Writer; | |
153 | 25 import com.glavsoft.viewer.ViewerInterface; |
174 | 26 import com.glavsoft.viewer.swing.ConnectionParams; |
28 | 27 |
124 | 28 |
207 | 29 public class TreeRFBProto { |
231 | 30 |
223 | 31 final static int FramebufferUpdateRequest = 3; |
32 final static int CheckDelay = 11; | |
33 protected final static int FramebufferUpdate = 0; | |
34 protected ProtocolContext context; | |
35 private int clients = 0; | |
36 public MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); | |
37 private RequestScreenThread rThread; | |
38 public int acceptPort = 0; | |
174 | 39 private String myAddress; |
223 | 40 private long counter = 0; // packet serial number |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
41 public ServerSocket servSock; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
42 private static final int INFLATE_BUFSIZE = 1024 * 100; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
43 private Inflater inflater = new Inflater(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
44 private Deflater deflater = new Deflater(); |
174 | 45 ViewerInterface viewer; |
341 | 46 private short id = 0; // my tree node id ( = 0 in root ), -1 means no parent |
174 | 47 private TreeVncCommandChannelListener acceptThread; |
48 private TreeRootFinderListener getCast; | |
176 | 49 private CreateConnectionParam cp; |
205
614db20d8fab
try to separate Network management
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
50 private TreeVNCNetwork nets = new TreeVNCNetwork(); |
223 | 51 private TreeVncRootSelectionPanel rootSelectionPanel; |
52 private String vncInterface; | |
231 | 53 public LinkedList<TreeVNCNode> nodeList; |
267 | 54 |
55 protected boolean readyReconnect = false; | |
56 private boolean cuiVersion; | |
57 private boolean permitChangeScreen = true; | |
58 private boolean leader; | |
59 private boolean hasViewer = false; | |
60 private boolean normalTermination; | |
61 private boolean isTreeManager; | |
62 public boolean showTreeNode = false; | |
240 | 63 public boolean checkDelay = false; |
241 | 64 public boolean addSerialNum = false; |
257 | 65 public boolean fixingSize = false; |
267 | 66 public boolean filterSingleDisplay = false; |
67 | |
257 | 68 public int frameSizeWidth; |
69 public int frameSizeHeight; | |
70 public int fixingSizeWidth; | |
71 public int fixingSizeHeight; | |
72 | |
306 | 73 private int singleWidth = 0; |
74 private int singleHeight = 0; | |
301 | 75 |
293 | 76 private DatagramSocket socket = null; |
275 | 77 |
306 | 78 private byte[] originalInitData = null; |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
79 private boolean childrenMulticast = true; |
306 | 80 |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
81 public TreeRFBProto(boolean isTreeManager, ViewerInterface viewer) { |
223 | 82 rThread = new RequestScreenThread(this); |
83 nets.setMyRfb(this); | |
84 this.isTreeManager = isTreeManager; | |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
85 this.viewer = viewer; |
302 | 86 // this.socket = createSocket(); |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
87 if(isTreeManager()) { |
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
88 getCast = new TreeRootFinderListener(viewer); |
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
89 Thread treeRootFindThread = new Thread(getCast, "tree-root-find-listener"); |
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
90 treeRootFindThread.start(); |
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
91 } |
223 | 92 } |
93 | |
94 public boolean isTreeManager() { | |
95 return isTreeManager; | |
96 } | |
207 | 97 |
378 | 98 public boolean isAddSerialNum() { |
99 return addSerialNum; | |
100 } | |
101 | |
223 | 102 public ProtocolContext getContext() { |
103 return context; | |
104 } | |
105 | |
106 /** | |
107 * handle new client accept | |
108 * it also handle TreeVNC Command | |
109 * @param newCli | |
110 * @param os | |
111 * @param is | |
112 * @throws IOException | |
113 * @throws TransportException | |
114 */ | |
330 | 115 public void newClient(final Socket newCli,final Writer os, final Reader is) { |
223 | 116 final int myId = clients; |
117 final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient(); | |
118 final AtomicInteger writerRunning = new AtomicInteger(); | |
119 writerRunning.set(1); | |
120 /** | |
121 * Timeout thread. If a client is suspended, it has top of queue | |
122 * indefinitely, which caused memory overflow. After the timeout, we | |
123 * poll the queue and discard it. Start long wait if writer is running. | |
124 */ | |
125 final Runnable timer = new Runnable() { | |
126 public void run() { | |
127 int count = 0; | |
128 for (;;) { | |
129 long timeout = 50000 / 8; | |
130 try { | |
131 synchronized (this) { | |
132 int state, flag; | |
133 writerRunning.set(0); | |
134 wait(timeout); | |
135 flag = 0; | |
136 while ((state = writerRunning.get()) == 0) { | |
137 c.poll(); // discard, should be timeout | |
138 count++; | |
139 if (flag == 0) { | |
140 System.out.println("Discarding " + myId | |
141 + " count=" + count); | |
142 flag = 1; | |
143 } | |
144 wait(10); // if this is too short, writer cannot | |
145 // take the poll, if this is too | |
146 // long, memory will overflow... | |
147 } | |
148 if (flag == 1) | |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
327
diff
changeset
|
149 System.out.println("Resuming " + myId + " count=" + count); |
223 | 150 if (state != 1) { |
151 System.out.println("Client died " + myId); | |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
327
diff
changeset
|
152 System.out.println("task stop"); |
330 | 153 |
154 String rootHostName = null; | |
155 int rootHostPort = 0; | |
156 String myHostName = null; | |
157 int myHostPort = 0; | |
158 | |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
327
diff
changeset
|
159 if (isTreeManager) { |
330 | 160 try { |
161 rootHostName = InetAddress.getLocalHost().getHostAddress(); | |
162 rootHostPort = getAcceptPort(); | |
163 myHostName = rootHostName; | |
164 myHostPort = rootHostPort; | |
165 } catch (UnknownHostException e) { | |
166 e.printStackTrace(); | |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
167 System.out.println("cannot resolve localhost"); |
330 | 168 } |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
327
diff
changeset
|
169 } else { |
330 | 170 rootHostName = getConnectionParam().getHostName(); |
171 rootHostPort = getConnectionParam().getPort(); | |
172 myHostName = getMyAddress(); | |
173 myHostPort = getAcceptPort(); | |
174 } | |
175 TreeVncProtocol echo = new TreeVncProtocol(rootHostName, rootHostPort); | |
176 clients = myId; | |
334 | 177 echo.lostChild(myHostName, myHostPort, myId); |
223 | 178 break; |
179 } | |
180 } | |
181 } catch (InterruptedException e) { | |
325 | 182 e.printStackTrace(); |
183 System.out.println("timer thread interrupt."); | |
223 | 184 } |
185 } | |
186 } | |
187 }; | |
188 new Thread(timer, "timer-discard-multicastqueue").start(); | |
189 /** | |
190 * handle command from lower node | |
191 */ | |
192 final Runnable reader = new Runnable() { | |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
193 public void run() { |
223 | 194 for (;;) { |
195 try { | |
196 final byte b[] = new byte[4096]; | |
197 final int c = is.readByte(b); | |
198 if (c <= 0) | |
199 throw new IOException(); | |
290
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
200 // case of root node. |
223 | 201 if (isTreeManager()) { |
202 if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { | |
335 | 203 viewer.setVisible(false); |
223 | 204 if (permitChangeScreen()) { |
205 ByteBuffer buf = ByteBuffer.wrap(b); | |
206 buf.order(ByteOrder.BIG_ENDIAN); | |
325 | 207 buf.get(); // padding |
257 | 208 buf.get(); |
209 short id = buf.getShort(); | |
210 int length = buf.getInt(); | |
325 | 211 if (length == 0) |
212 continue; | |
257 | 213 byte[] byteAddress = new byte[length]; |
214 buf.get(byteAddress); | |
325 | 215 String newHostName = new String(byteAddress, "UTF-8"); |
257 | 216 int frameSizeWidth = buf.getInt(); |
217 int frameSizeHeight = buf.getInt(); | |
340 | 218 int port = buf.getInt(); |
219 System.out.println("Root server change request :" + newHostName + " : " + port); | |
359 | 220 changeVNCServer(viewer, newHostName, port, frameSizeWidth, frameSizeHeight, id); |
223 | 221 } else { |
222 continue; | |
223 } | |
290
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
224 } else if (b[0] == ClientToServerMessage.READY_SHARE_SOUND) { |
293 | 225 int rtpPort = selectPort(ConnectionParams.DEFAULT_RTP_PORT); |
226 InetAddress hostname = InetAddress.getLocalHost(); | |
227 ReceiveSound receiveSound = new ReceiveSound(socket); | |
228 Thread receiveSoundThread = new Thread(receiveSound, "receive-sound"); | |
229 receiveSoundThread.start(); | |
230 | 230 } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { |
231 ByteBuffer buf = ByteBuffer.wrap(b); | |
232 buf.order(ByteOrder.BIG_ENDIAN); | |
234 | 233 buf.getShort(); |
234 Long time = buf.getLong(); | |
235 int port = buf.getInt(); | |
236 int addressLength = buf.getInt(); | |
237 byte[] byteAddress = new byte[addressLength]; | |
238 buf.get(byteAddress); | |
239 String address = new String(byteAddress, "UTF-8"); | |
235 | 240 int nodeNum = getNodeNum(port, address); |
230 | 241 Long delay = System.currentTimeMillis() - time; |
244 | 242 double halfDelay = (double) delay / 2; |
252 | 243 System.out.println(System.currentTimeMillis() + " : receive checkDelay : nodeNum" + nodeNum + ", port : " + port + ", address : " + address + ", delay : " + halfDelay); |
223 | 244 } |
325 | 245 // case of client node. |
223 | 246 } else if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { |
295 | 247 ClientToServerMessage serverChangeRequest = new ClientToServerMessage() { |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
248 @Override |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
249 public void send(Writer writer) |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
250 throws TransportException { |
325 | 251 writer.write(b, 0, c); |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
252 } |
223 | 253 }; |
295 | 254 context.sendMessage(serverChangeRequest); |
301 | 255 } else if (b[0] == ClientToServerMessage.REQUEST_SINGLE_DISPLAY_SIZE) { |
295 | 256 ClientToServerMessage requestSingeDisplayWidth = new ClientToServerMessage() { |
280
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
257 @Override |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
258 public void send(Writer writer) |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
259 throws TransportException { |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
260 writer.write(b, 0, c); |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
261 } |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
262 }; |
295 | 263 context.sendMessage(requestSingeDisplayWidth); |
290
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
264 } else if (b[0] == ClientToServerMessage.READY_SHARE_SOUND) { |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
265 ClientToServerMessage readyShareSound = new ClientToServerMessage() { |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
266 @Override |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
267 public void send(Writer writer) |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
268 throws TransportException { |
325 | 269 writer.write(b, 0, c); |
290
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
270 } |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
271 }; |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
272 context.sendMessage(readyShareSound); |
230 | 273 } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { |
274 ClientToServerMessage checkDelayReply = new ClientToServerMessage() { | |
275 @Override | |
276 public void send(Writer writer) | |
277 throws TransportException { | |
325 | 278 writer.write(b, 0, c); |
230 | 279 } |
280 }; | |
281 context.sendMessage(checkDelayReply); | |
223 | 282 } |
283 } catch (Exception e) { | |
284 try { | |
285 writerRunning.set(2); | |
286 os.close(); | |
287 is.close(); | |
288 break; | |
367 | 289 } catch (Exception e1) { |
290 System.out.println("cannot close ClientToServerMessage "+e1); | |
291 | |
223 | 292 } |
367 | 293 System.out.println("cannot read ClientToServerMessage "+e); |
294 | |
223 | 295 return; |
296 } | |
325 | 297 |
298 /* | |
299 // あとで検討 | |
300 } catch (TransportException e) { | |
301 | |
302 } | |
303 */ | |
223 | 304 } |
305 } | |
306 }; | |
307 /** | |
308 * send packets to a client (one thread for each client ) | |
309 */ | |
310 Runnable sender = new Runnable() { | |
311 public void run() { | |
312 writerRunning.set(1); | |
313 try { | |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
314 requestThreadNotify(); // send full screen request via fullScreenRequestThread |
239 | 315 |
223 | 316 // after this, we discard upward packet. |
239 | 317 new Thread(reader, "upward-packet-processing").start(); |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
318 |
223 | 319 for (;;) { |
320 LinkedList<ByteBuffer> bufs = c.poll(); | |
321 int inputIndex = 0; | |
322 ByteBuffer header = bufs.get(inputIndex); | |
323 if (header == null) | |
324 continue; | |
325 writeToClient(os, bufs, inputIndex); | |
326 writerRunning.set(1); // yes my client is awaking. | |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
327 if (!childrenMulticast) { |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
328 for (;;) { |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
329 LinkedList<ByteBuffer> flag = c.poll(); |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
330 if (flag.size() == 0) { |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
331 break; |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
332 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
333 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
334 } |
223 | 335 } |
336 } catch (Exception e) { | |
337 try { | |
338 writerRunning.set(2); | |
339 os.close(); | |
340 } catch (IOException e1) { | |
341 System.out.println("root writer close faild :" + e1); | |
342 } | |
343 System.out.println("root writer faild :" + e); | |
344 /* if socket closed cliList.remove(newCli); */ | |
345 } | |
346 } | |
347 public void writeToClient(final Writer os, | |
348 LinkedList<ByteBuffer> bufs, int inputIndex) | |
349 throws TransportException { | |
354 | 350 while (inputIndex < bufs.size()) { |
223 | 351 ByteBuffer b = bufs.get(inputIndex++); |
352 os.write(b.array(), b.position(), b.limit()); | |
353 } | |
354 os.flush(); | |
355 multicastqueue.heapAvailable(); | |
356 } | |
357 }; | |
358 clients++; | |
359 new Thread(sender, "writer-to-lower-node").start(); | |
360 } | |
157
7cea8789387b
thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
153
diff
changeset
|
361 |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
362 public boolean permitChangeScreen() { |
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
363 return permitChangeScreen; |
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
364 } |
223 | 365 |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
366 |
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
367 public void setPermitChangeScreen(boolean v) { |
223 | 368 permitChangeScreen = v; |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
369 } |
223 | 370 |
371 public void requestThreadNotify() { | |
372 rThread.reStart(); | |
373 } | |
374 | |
375 | |
28 | 376 public void setProtocolContext(Protocol workingProtocol) { |
377 context = workingProtocol; | |
378 } | |
29 | 379 |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
380 public Socket accept() throws IOException { |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
381 return servSock.accept(); |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
382 } |
31 | 383 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
384 public int selectPort(int p) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
385 int port = p; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
386 while (true) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
387 try { |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
388 servSock = new ServerSocket(port); |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
389 acceptPort = port; |
181 | 390 myAddress = "127.0.0.1"; |
207 | 391 nets.getNetworkInterfaces(); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
392 break; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
393 } catch (BindException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
394 port++; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
395 continue; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
396 } catch (IOException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
397 |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
398 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
399 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
400 System.out.println("accept port = " + port); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
401 return port; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
402 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
403 |
33
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
404 |
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
405 |
331
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
330
diff
changeset
|
406 public void writeFramebufferUpdateRequest(int x, int y, int w, int h, boolean incremental) { |
223 | 407 byte[] b = new byte[10]; |
408 | |
409 b[0] = (byte) FramebufferUpdateRequest; // 3 is FrameBufferUpdateRequest | |
410 b[1] = (byte) (incremental ? 1 : 0); | |
411 b[2] = (byte) ((x >> 8) & 0xff); | |
412 b[3] = (byte) (x & 0xff); | |
413 b[4] = (byte) ((y >> 8) & 0xff); | |
414 b[5] = (byte) (y & 0xff); | |
415 b[6] = (byte) ((w >> 8) & 0xff); | |
416 b[7] = (byte) (w & 0xff); | |
417 b[8] = (byte) ((h >> 8) & 0xff); | |
418 b[9] = (byte) (h & 0xff); | |
419 } | |
33
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
420 |
223 | 421 public void setViewer(ViewerInterface v) { |
422 viewer = v; | |
423 } | |
424 | |
425 public ViewerInterface getViewer() { | |
426 return viewer; | |
427 } | |
428 | |
429 | |
430 void sendInitData(OutputStream os) throws IOException { | |
431 os.write(context.getInitData()); | |
432 } | |
433 | |
434 | |
435 public void setTerminationType(boolean setType) { | |
436 normalTermination = setType; | |
437 } | |
438 | |
439 public boolean getTerminationType() { | |
440 return normalTermination; | |
441 } | |
43 | 442 |
206 | 443 |
223 | 444 public void addHostToSelectionPanel(int port, String hostname,String myHostName) { |
445 if (rootSelectionPanel != null) { | |
446 rootSelectionPanel.checkBox(Integer.toString(port) + ":" + hostname + ":" + myHostName); | |
447 rootSelectionPanel.setButton(); | |
448 rootSelectionPanel.visible(); | |
449 } | |
450 } | |
43 | 451 |
223 | 452 public void createRootSelectionPanel(CreateConnectionParam cp) { |
453 rootSelectionPanel = new TreeVncRootSelectionPanel(); | |
454 rootSelectionPanel.setCp(cp); | |
455 } | |
456 | |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
457 public void close() { |
223 | 458 // none |
459 } | |
460 | |
461 public int getAcceptPort() { | |
462 return acceptPort; | |
463 } | |
464 | |
465 public boolean getReadyReconnect() { | |
466 return readyReconnect; | |
467 } | |
65 | 468 |
469 | |
223 | 470 public boolean getCuiVersion() { |
471 return cuiVersion; | |
472 } | |
66 | 473 |
223 | 474 public void setCuiVersion(boolean flag) { |
475 cuiVersion = flag; | |
476 } | |
477 | |
478 public void readCheckDelay(Reader reader) throws TransportException { | |
479 | |
480 } | |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
481 |
223 | 482 public synchronized void vncConnected(boolean ready) { |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
483 enableChildrenTransmission(); |
369 | 484 readyReconnect = ready; |
485 if (ready) { | |
486 notifyAll(); | |
223 | 487 } |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
488 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
489 |
369 | 490 public void printNetworkInterface() { |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
491 Socket vncSocket = viewer.getVNCSocket(); |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
492 NetworkInterface ni = nets.getInterface(vncSocket); |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
493 if (ni!=null) { |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
494 vncInterface = ni.getName(); |
369 | 495 System.out.print("VNCNetworkInterface :" + vncInterface); |
370 | 496 if(false) { |
497 Enumeration<InetAddress> addresses = ni.getInetAddresses(); | |
498 while (addresses.hasMoreElements()) { | |
499 InetAddress adr = addresses.nextElement(); | |
500 System.out.print(" " + adr); | |
501 } | |
369 | 502 } |
503 System.out.println(); | |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
504 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
505 } |
94
75879c316796
synchronized wait for Rfb initialization in change server.
oc
parents:
89
diff
changeset
|
506 |
202 | 507 |
325 | 508 public synchronized void waitForVNCConnection() { |
369 | 509 while (!readyReconnect) { |
325 | 510 try { |
511 wait(); | |
512 } catch (InterruptedException e) { | |
513 e.printStackTrace(); | |
514 System.out.println("interrupt wait for vnc connection."); | |
515 } | |
223 | 516 } |
517 } | |
96 | 518 |
519 | |
223 | 520 public void sendDesktopSizeChange(short id) { |
521 LinkedList<ByteBuffer> desktopSize = new LinkedList<ByteBuffer>(); | |
522 int width = context.getFbWidth(); | |
523 int height = context.getFbHeight(); | |
304 | 524 byte[] initData = null; |
525 | |
526 if (filterSingleDisplay) { | |
353 | 527 originalInitData = createOriginalInitData(singleWidth, singleHeight, context.getRemoteDesktopName()); |
350 | 528 // desktopSize.add(new ChengeDesktopSize(singleWidth, singleHeight, EncodingType.INIT_DATA, originalInitData, id).getMessage()); |
529 desktopSize.add(new ChengeDesktopSize(width, height, EncodingType.INIT_DATA, context.getInitData(), id).getMessage()); | |
305 | 530 } else { |
531 desktopSize.add(new ChengeDesktopSize(width, height, EncodingType.INIT_DATA, context.getInitData(), id).getMessage()); | |
304 | 532 } |
242 | 533 addSerialNumber(desktopSize); |
223 | 534 multicastqueue.put(desktopSize); |
535 } | |
98 | 536 |
306 | 537 public byte[] createOriginalInitData(int singleWidth, int singleHeight, String remoteDesktopName) { |
538 TreeVncCommandChannelListener treeVncCommandChannelListener = new TreeVncCommandChannelListener(this, acceptPort); | |
539 byte[] originalInitData = treeVncCommandChannelListener.createOriginalInitData(singleWidth, singleHeight, remoteDesktopName); | |
540 return originalInitData; | |
541 } | |
542 | |
223 | 543 public void addSerialNumber(LinkedList<ByteBuffer> bufs) { |
242 | 544 ByteBuffer serialNum = multicastqueue.allocate(4+8); // addSerialNum flag + SerialNum |
243 | 545 if (this.addSerialNum) { |
546 serialNum.putInt(1); | |
547 } else { | |
548 serialNum.putInt(0); | |
549 } | |
223 | 550 serialNum.putLong(counter++); |
551 serialNum.flip(); | |
552 bufs.addFirst(serialNum); | |
553 } | |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
554 |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
555 |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
556 public void resetDecoder() { |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
557 context.resetDecoder(); |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
558 } |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
559 |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
560 public void stopReceiverTask() { |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
561 if (context!=null) { |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
562 context.cleanUpSession(null); |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
563 context.getRfb().clearChildrenTransmission(); |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
564 } |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
565 // cleanup zlib decoder for new VNCServer |
202 | 566 if (isTreeManager()) |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
567 inflater = new Inflater(); |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
568 } |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
569 |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
570 public void clearChildrenTransmission() { |
355 | 571 // discarding does not work now. |
572 | |
573 /* | |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
574 // set discard flag |
354 | 575 childrenMulticast = false; |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
576 // put gurd erement to restart multicastqueue. |
354 | 577 multicastqueue.put(new LinkedList<ByteBuffer>()); |
355 | 578 */ |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
579 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
580 |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
581 public void enableChildrenTransmission() { |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
582 // a child senderTask may skip this flag |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
583 // durling write waiting. in this case, remaining bufferes are sent. |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
584 childrenMulticast = true; |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
585 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
586 |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
587 public String getMyAddress() { |
174 | 588 return myAddress; |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
589 } |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
590 |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
591 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
592 * gzip byte arrays |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
593 * |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
594 * @param deflater |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
595 * @param inputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
596 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
597 * @param inputIndex |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
598 * @param outputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
599 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
600 * @return byte length in last byte array |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
601 * @throws IOException |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
602 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
603 public int zip(Deflater deflater, LinkedList<ByteBuffer> inputs, |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
604 int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
605 int len = 0; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
606 ByteBuffer c1 = multicastqueue.allocate(INFLATE_BUFSIZE); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
607 while (inputIndex < inputs.size()) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
608 ByteBuffer b1 = inputs.get(inputIndex++); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
609 deflater.setInput(b1.array(), b1.position(), b1.remaining()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
610 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
611 * If we finish() stream and reset() it, Deflater start new gzip |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
612 * stream, this makes continuous zlib reader unhappy. if we remove |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
613 * finish(), Deflater.deflate() never flushes its output. The |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
614 * original zlib deflate has flush flag. I'm pretty sure this a kind |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
615 * of bug of Java library. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
616 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
617 if (inputIndex == inputs.size()) |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
618 deflater.finish(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
619 int len1 = 0; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
620 do { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
621 len1 = deflater.deflate(c1.array(), c1.position(), |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
622 c1.remaining()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
623 if (len1 > 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
624 len += len1; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
625 c1.position(c1.position() + len1); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
626 if (c1.remaining() == 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
627 c1.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
628 outputs.addLast(c1); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
629 c1 = multicastqueue.allocate(INFLATE_BUFSIZE); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
630 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
631 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
632 } while (len1 > 0 || !deflater.needsInput()); // &&!deflater.finished()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
633 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
634 if (c1.position() != 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
635 c1.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
636 outputs.addLast(c1); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
637 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
638 deflater.reset(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
639 return len; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
640 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
641 |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
642 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
643 * gunzip byte arrays |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
644 * |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
645 * @param inflater |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
646 * @param inputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
647 * byte data[] |
182 | 648 * @param bytes |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
649 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
650 * @return number of total bytes |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
651 * @throws IOException |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
652 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
653 public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs, |
335 | 654 int inputIndex, byte[] bytes, int bufSize) throws DataFormatException { |
182 | 655 int position = 0; |
656 int limit = bytes.length; | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
657 while (inputIndex < inputs.size()) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
658 ByteBuffer input = inputs.get(inputIndex++); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
659 inflater.setInput(input.array(), input.position(), input.limit()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
660 // if (inputIndex==inputs.size()) if inflater/deflater has symmetry, |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
661 // we need this |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
662 // inflater.end(); but this won't work |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
663 do { |
318 | 664 int len0; |
665 len0 = inflater.inflate(bytes, position, limit-position); | |
666 if (len0 > 0) { | |
667 position += len0; | |
668 if (position > limit) throw new DataFormatException(); | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
669 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
670 } while (!inflater.needsInput()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
671 } |
182 | 672 return position; |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
673 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
674 |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
675 /** |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
676 * Multicast framebufferUpdate to children. |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
677 * read FrameBuffferUpdate. If it is ZLE, make it ZLEE which is self contained compressed packet. |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
678 * put the packet to the multicastqueue. Then normal rendering engine read the same stream using is.reset(). |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
679 * @param dataLen |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
680 * @param reader |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
681 * @throws TransportException |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
682 * @throws UnsupportedEncodingException |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
683 */ |
264 | 684 public void readSendData(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect) |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
685 throws TransportException, UnsupportedEncodingException { |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
686 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
687 ByteBuffer header = multicastqueue.allocate(16); |
242 | 688 ByteBuffer serial = multicastqueue.allocate(4+8); |
378 | 689 if (!isTreeManager() && addSerialNum) { |
242 | 690 reader.readBytes(serial.array(),0,4+8); |
691 serial.limit(4+8); | |
182 | 692 } |
185 | 693 reader.mark(dataLen); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
694 reader.readBytes(header.array(), 0, 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
695 header.limit(16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
696 if (header.get(0) == FramebufferUpdate) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
697 int encoding = header.getInt(12); |
239 | 698 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
699 if (encoding == EncodingType.ZRLE.getId() |
229
5eb8aa65f387
fix checkdelay number-of-rectangle, and send checkdelay to lower node.
oc
parents:
227
diff
changeset
|
700 || encoding == EncodingType.ZLIB.getId()) { |
186
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
701 // recompress into ZREE |
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
702 // uncompressed result is remain in bytes |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
703 ByteBuffer len = multicastqueue.allocate(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
704 reader.readBytes(len.array(), 0, 4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
705 len.limit(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
706 ByteBuffer inputData = multicastqueue.allocate(dataLen - 20); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
707 reader.readBytes(inputData.array(), 0, inputData.capacity()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
708 inputData.limit(dataLen - 20); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
709 LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
710 inputs.add(inputData); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
711 header.putInt(12, EncodingType.ZRLEE.getId()); // means |
223 | 712 // recompress |
713 // every time | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
714 // using new Deflecter every time is incompatible with the |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
715 // protocol, clients have to be modified. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
716 Deflater nDeflater = deflater; // new Deflater(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
717 LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>(); |
373 | 718 try { |
182 | 719 unzip(inflater, inputs, 0, bytes, INFLATE_BUFSIZE); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
720 // dump32(inputs); |
182 | 721 out.add(ByteBuffer.wrap(bytes)); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
722 int len2 = zip(nDeflater, out, 0, bufs); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
723 ByteBuffer blen = multicastqueue.allocate(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
724 blen.putInt(len2); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
725 blen.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
726 bufs.addFirst(blen); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
727 bufs.addFirst(header); |
242 | 728 addSerialNumber(bufs); |
270 | 729 if (filterSingleDisplay) { |
275 | 730 if (rect.x < singleWidth) { |
270 | 731 multicastqueue.put(bufs); |
732 } | |
733 } else { | |
734 multicastqueue.put(bufs); | |
735 } | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
736 } catch (IOException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
737 throw new TransportException(e); |
335 | 738 } catch (DataFormatException e) { |
739 throw new TransportException(e); | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
740 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
741 return; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
742 } |
233 | 743 |
186
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
744 // ZRLEE is already compressed |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
745 bufs.add(header); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
746 if (dataLen > 16) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
747 ByteBuffer b = multicastqueue.allocate(dataLen - 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
748 reader.readBytes(b.array(), 0, dataLen - 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
749 b.limit(dataLen - 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
750 bufs.add(b); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
751 } |
242 | 752 this.addSerialNumber(bufs); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
753 multicastqueue.put(bufs); |
233 | 754 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
755 return; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
756 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
757 // It may be compressed. We can inflate here to avoid repeating clients |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
758 // decompressing here, |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
759 // but it may generate too many large data. It is better to do it in |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
760 // each client. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
761 // But we have do inflation for all input data, so we have to do it |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
762 // here. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
763 } |
124 | 764 |
223 | 765 public void setId(short id) { |
766 this.id = id; | |
767 } | |
169 | 768 |
223 | 769 public short getId() { |
770 return id; | |
771 } | |
169 | 772 |
174 | 773 public void setMyAddress(String myHostName) { |
774 this.myAddress = myHostName; | |
223 | 775 |
174 | 776 } |
777 | |
778 public void setLeader(boolean leader) { | |
779 this.leader = leader; | |
780 } | |
781 | |
782 public boolean isLeader() { | |
783 return leader; | |
784 } | |
785 | |
203 | 786 public void setTreeManager(String intf, TreeManagement clients) { |
223 | 787 nets.setTreeManager(intf, clients); |
174 | 788 } |
223 | 789 |
203 | 790 public TreeManagement getTreeManager(String intf) { |
231 | 791 TreeManagement tm = nets.getTreeManager(intf); |
792 this.nodeList = tm.getList(); | |
793 return tm; | |
174 | 794 } |
795 | |
796 /** | |
290
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
797 * change VNCServer is called when host change. |
359 | 798 * |
275 | 799 * @param vncProxyService |
174 | 800 * @param hostName |
801 * HostAddress | |
359 | 802 * @param width |
803 * FrameWidth | |
804 * @param height | |
805 * FrameHeight | |
351 | 806 * @param newVNCServerId |
174 | 807 */ |
359 | 808 public void changeVNCServer(ViewerInterface vncProxyService, String hostName, int port, int width, int height, short newVNCServerId) |
325 | 809 throws IOException { |
257 | 810 |
359 | 811 this.frameSizeWidth = width; |
812 this.frameSizeHeight = height; | |
813 singleWidth = frameSizeWidth; | |
814 singleHeight = frameSizeHeight; | |
815 | |
351 | 816 if (newVNCServerId == -1) { |
339
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
817 // change to the tree vnc root on other network. |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
818 // send whereToConnect. |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
819 cp = new CreateConnectionParam(this); |
340 | 820 cp.setHostName(hostName, port, myAddress); |
339
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
821 cp.sendWhereToConnect(viewer); |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
822 stopReceiverTask(); |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
823 return; |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
824 } |
342 | 825 // serverChangeの処理 |
369 | 826 vncProxyService.inhelitClients(vncProxyService, hostName, newVNCServerId); |
317 | 827 // after connecting VNC server, rfb send SEND_INIT_DATA command and wakes me up if necessary |
322 | 828 // stop reader stop |
174 | 829 } |
830 | |
831 /** | |
832 * start accepting children | |
833 * run rootFinderListener if necessary | |
834 */ | |
176 | 835 public void createConnectionAndStart(ViewerInterface v) { |
223 | 836 selectPort(ConnectionParams.DEFAULT_VNC_ROOT); |
176 | 837 startTreeVncCommandListener(); |
174 | 838 } |
839 | |
223 | 840 public void startTreeVncCommandListener() { |
176 | 841 acceptThread = new TreeVncCommandChannelListener(this, getAcceptPort()); |
223 | 842 Thread thread = new Thread(acceptThread, "TreeVNC-accept"); |
843 thread.start(); | |
176 | 844 } |
845 | |
174 | 846 public TreeVncCommandChannelListener getAcceptThread() { |
847 return acceptThread; | |
848 } | |
849 | |
176 | 850 public void setConnectionParam(CreateConnectionParam createConnectionParam) { |
851 cp = createConnectionParam; | |
852 } | |
853 | |
854 public CreateConnectionParam getConnectionParam() { | |
855 return cp; | |
856 } | |
857 | |
178
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
858 public boolean hasViewer() { |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
859 return hasViewer; |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
860 } |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
861 |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
862 public void setHasViewer(boolean b) { |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
863 hasViewer = b; |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
864 } |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
865 |
223 | 866 public void setShowTree(boolean showTree) { |
240 | 867 this.showTreeNode = showTree; |
868 } | |
869 | |
870 public void setCheckDelay(boolean checkDelay) { | |
871 this.checkDelay = checkDelay; | |
223 | 872 } |
194 | 873 |
241 | 874 public void setAddSerialNum(boolean addSerialNum) { |
875 this.addSerialNum = addSerialNum; | |
876 } | |
877 | |
235 | 878 public int getNodeNum(int port, String address) { |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
879 int nodeNum = 0; |
235 | 880 |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
881 for (Iterator<TreeVNCNode> i = nodeList.iterator(); i.hasNext();) { |
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
882 TreeVNCNode tvn = (TreeVNCNode)i.next(); |
235 | 883 if (port == tvn.port && address.equals(tvn.hostname)) { |
884 nodeNum = tvn.treeNum; | |
885 return nodeNum; | |
886 } | |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
887 } |
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
888 return nodeNum; |
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
889 } |
241 | 890 |
257 | 891 public void setFixingSize(boolean fixingSize) { |
892 this.fixingSize = fixingSize; | |
256 | 893 } |
267 | 894 |
895 public void setFilterSingleDisplay(boolean filterSingleDisplay) { | |
896 this.filterSingleDisplay = filterSingleDisplay; | |
897 } | |
281 | 898 |
293 | 899 private DatagramSocket createSocket() { |
900 | |
901 try { | |
902 if (socket == null) { | |
903 this.socket = new DatagramSocket(ConnectionParams.DEFAULT_RTP_PORT, InetAddress.getLocalHost()); | |
904 } | |
905 } catch (SocketException e) { | |
906 e.printStackTrace(); | |
907 } catch (UnknownHostException e) { | |
908 e.printStackTrace(); | |
909 } | |
910 return socket; | |
911 } | |
306 | 912 |
913 public void setSingleDisplaySize(int singleWidth, int singleHeight) { | |
914 this.singleWidth = singleWidth; | |
915 this.singleHeight = singleHeight; | |
916 } | |
917 | |
358 | 918 |
306 | 919 public int getSingleWidth() { |
920 return singleWidth; | |
921 } | |
922 | |
923 public int getSingleHeight() { | |
924 return singleHeight; | |
925 } | |
339
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
926 |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
927 public boolean hasParent() { |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
928 return id != -1; |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
929 } |
240 | 930 } |