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