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