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