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