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