Mercurial > hg > Applications > TreeVNC
annotate src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java @ 283:d18c3f901be7
fix setting singleWidth for -d option
author | oc |
---|---|
date | Sun, 11 Jan 2015 05:12:05 +0900 |
parents | 6b232caa07fb |
children | 61938de1dd06 |
rev | line source |
---|---|
32 | 1 package jp.ac.u_ryukyu.treevnc; |
28 | 2 |
3 import java.io.IOException; | |
206 | 4 import java.io.OutputStream; |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
5 import java.io.UnsupportedEncodingException; |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
6 import java.net.BindException; |
201 | 7 import java.net.NetworkInterface; |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
8 import java.net.ServerSocket; |
28 | 9 import java.net.Socket; |
174 | 10 import java.net.UnknownHostException; |
28 | 11 import java.nio.ByteBuffer; |
109 | 12 import java.nio.ByteOrder; |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
13 import java.util.Iterator; |
28 | 14 import java.util.LinkedList; |
15 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
|
16 import java.util.zip.DataFormatException; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
17 import java.util.zip.Deflater; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
18 import java.util.zip.Inflater; |
150 | 19 |
28 | 20 import com.glavsoft.exceptions.TransportException; |
107 | 21 import com.glavsoft.rfb.client.ClientToServerMessage; |
96 | 22 import com.glavsoft.rfb.encoding.EncodingType; |
264 | 23 import com.glavsoft.rfb.encoding.decoder.FramebufferUpdateRectangle; |
28 | 24 import com.glavsoft.rfb.protocol.Protocol; |
25 import com.glavsoft.rfb.protocol.ProtocolContext; | |
26 import com.glavsoft.transport.Reader; | |
27 import com.glavsoft.transport.Writer; | |
153 | 28 import com.glavsoft.viewer.ViewerInterface; |
174 | 29 import com.glavsoft.viewer.swing.ConnectionParams; |
28 | 30 |
124 | 31 |
207 | 32 public class TreeRFBProto { |
231 | 33 |
223 | 34 final static int FramebufferUpdateRequest = 3; |
35 final static int CheckDelay = 11; | |
36 protected final static int FramebufferUpdate = 0; | |
37 protected ProtocolContext context; | |
38 private int clients = 0; | |
39 public MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); | |
40 private RequestScreenThread rThread; | |
41 public int acceptPort = 0; | |
174 | 42 private String myAddress; |
223 | 43 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
|
44 public ServerSocket servSock; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
45 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
|
46 private Inflater inflater = new Inflater(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
47 private Deflater deflater = new Deflater(); |
174 | 48 ViewerInterface viewer; |
223 | 49 private short id; // my tree node id ( = 0 in root ) |
174 | 50 private TreeVncCommandChannelListener acceptThread; |
51 private TreeRootFinderListener getCast; | |
176 | 52 private CreateConnectionParam cp; |
187 | 53 private short reconnectingId; // Change Server Request to id's node VNC server |
205
614db20d8fab
try to separate Network management
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
54 private TreeVNCNetwork nets = new TreeVNCNetwork(); |
223 | 55 private TreeVncRootSelectionPanel rootSelectionPanel; |
56 private String vncInterface; | |
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 firstTime = true; | |
64 private boolean hasViewer = false; | |
65 private boolean reconnecting; | |
66 private boolean normalTermination; | |
67 private boolean isTreeManager; | |
68 public boolean showTreeNode = false; | |
240 | 69 public boolean checkDelay = false; |
241 | 70 public boolean addSerialNum = false; |
257 | 71 public boolean fixingSize = false; |
267 | 72 public boolean filterSingleDisplay = false; |
73 | |
257 | 74 public int frameSizeWidth; |
75 public int frameSizeHeight; | |
76 public int fixingSizeWidth; | |
77 public int fixingSizeHeight; | |
78 | |
275 | 79 public int singleWidth = 0; |
80 | |
223 | 81 public TreeRFBProto(boolean isTreeManager) { |
82 rThread = new RequestScreenThread(this); | |
83 nets.setMyRfb(this); | |
84 this.isTreeManager = isTreeManager; | |
85 } | |
86 | |
87 public boolean isTreeManager() { | |
88 return isTreeManager; | |
89 } | |
207 | 90 |
223 | 91 public ProtocolContext getContext() { |
92 return context; | |
93 } | |
94 | |
95 /** | |
96 * handle new client accept | |
97 * it also handle TreeVNC Command | |
98 * @param newCli | |
99 * @param os | |
100 * @param is | |
101 * @throws IOException | |
102 * @throws TransportException | |
103 */ | |
104 public void newClient(final Socket newCli,final Writer os, final Reader is) { | |
124 | 105 |
223 | 106 final int myId = clients; |
107 final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient(); | |
108 final AtomicInteger writerRunning = new AtomicInteger(); | |
109 writerRunning.set(1); | |
110 /** | |
111 * Timeout thread. If a client is suspended, it has top of queue | |
112 * indefinitely, which caused memory overflow. After the timeout, we | |
113 * poll the queue and discard it. Start long wait if writer is running. | |
114 */ | |
115 final Runnable timer = new Runnable() { | |
116 public void run() { | |
117 int count = 0; | |
118 for (;;) { | |
119 long timeout = 50000 / 8; | |
120 try { | |
121 synchronized (this) { | |
122 int state, flag; | |
123 writerRunning.set(0); | |
124 wait(timeout); | |
125 flag = 0; | |
126 while ((state = writerRunning.get()) == 0) { | |
127 c.poll(); // discard, should be timeout | |
128 count++; | |
129 if (flag == 0) { | |
130 System.out.println("Discarding " + myId | |
131 + " count=" + count); | |
132 flag = 1; | |
133 } | |
134 wait(10); // if this is too short, writer cannot | |
135 // take the poll, if this is too | |
136 // long, memory will overflow... | |
137 } | |
138 if (flag == 1) | |
139 System.out.println("Resuming " + myId | |
140 + " count=" + count); | |
141 if (state != 1) { | |
142 System.out.println("Client died " + myId); | |
143 break; | |
144 } | |
145 } | |
146 } catch (InterruptedException e) { | |
147 } | |
148 } | |
149 } | |
150 }; | |
151 new Thread(timer, "timer-discard-multicastqueue").start(); | |
152 /** | |
153 * handle command from lower node | |
154 */ | |
155 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
|
156 public void run() { |
223 | 157 for (;;) { |
158 try { | |
159 final byte b[] = new byte[4096]; | |
160 final int c = is.readByte(b); | |
161 if (c <= 0) | |
162 throw new IOException(); | |
163 if (isTreeManager()) { | |
164 if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { | |
165 if (permitChangeScreen()) { | |
166 ByteBuffer buf = ByteBuffer.wrap(b); | |
167 buf.order(ByteOrder.BIG_ENDIAN); | |
257 | 168 buf.get(); |
169 buf.get(); | |
170 short id = buf.getShort(); | |
171 int length = buf.getInt(); | |
223 | 172 if (length == 0) |
257 | 173 continue; |
174 byte[] byteAddress = new byte[length]; | |
175 buf.get(byteAddress); | |
176 String newHostName = new String(byteAddress, "UTF-8"); | |
177 int frameSizeWidth = buf.getInt(); | |
178 int frameSizeHeight = buf.getInt(); | |
283 | 179 singleWidth = frameSizeWidth; |
223 | 180 System.out.println("Root server change request :" + newHostName); |
181 // please remove these numbers. | |
182 if (viewer != null) { | |
257 | 183 changeVNCServer(viewer, newHostName, frameSizeWidth, frameSizeHeight, id); |
223 | 184 } |
185 } else { | |
186 continue; | |
187 } | |
280
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
188 } else if (b[0] == ClientToServerMessage.REQUEST_SINGLE_DISPLAY_WIDTH) { |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
189 ByteBuffer buf = ByteBuffer.wrap(b); |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
190 buf.order(ByteOrder.BIG_ENDIAN); |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
191 buf.get(); |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
192 // ここにエンコーディングタイプがSendSingleDisplayWidthなframebufferUpdateを送信する処理を書く |
281 | 193 sendSingleDisplayWidth(singleWidth); |
230 | 194 } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { |
195 ByteBuffer buf = ByteBuffer.wrap(b); | |
196 buf.order(ByteOrder.BIG_ENDIAN); | |
234 | 197 buf.getShort(); |
198 Long time = buf.getLong(); | |
199 int port = buf.getInt(); | |
200 int addressLength = buf.getInt(); | |
201 byte[] byteAddress = new byte[addressLength]; | |
202 buf.get(byteAddress); | |
203 String address = new String(byteAddress, "UTF-8"); | |
235 | 204 int nodeNum = getNodeNum(port, address); |
230 | 205 Long delay = System.currentTimeMillis() - time; |
244 | 206 double halfDelay = (double) delay / 2; |
252 | 207 System.out.println(System.currentTimeMillis() + " : receive checkDelay : nodeNum" + nodeNum + ", port : " + port + ", address : " + address + ", delay : " + halfDelay); |
248
e6abf4b0c92e
add numberOfRectangle in checkDelay
Miwa Oshiro <e115747@ie.u-ryukyu.ac.jp>
parents:
245
diff
changeset
|
208 |
239 | 209 // checkNodeNum(); |
210 // readSendData(check); | |
248
e6abf4b0c92e
add numberOfRectangle in checkDelay
Miwa Oshiro <e115747@ie.u-ryukyu.ac.jp>
parents:
245
diff
changeset
|
211 |
223 | 212 } |
213 } else if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { | |
214 ClientToServerMessage sc = new ClientToServerMessage() { | |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
215 @Override |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
216 public void send(Writer writer) |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
217 throws TransportException { |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
218 writer.write(b,0,c); |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
219 } |
223 | 220 }; |
221 context.sendMessage(sc); | |
280
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
222 } else if (b[0] == ClientToServerMessage.REQUEST_SINGLE_DISPLAY_WIDTH) { |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
223 ClientToServerMessage sc = new ClientToServerMessage() { |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
224 @Override |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
225 public void send(Writer writer) |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
226 throws TransportException { |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
227 writer.write(b, 0, c); |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
228 } |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
229 }; |
230 | 230 } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { |
231 ClientToServerMessage checkDelayReply = new ClientToServerMessage() { | |
232 @Override | |
233 public void send(Writer writer) | |
234 throws TransportException { | |
235 writer.write(b,0,c); | |
236 } | |
237 }; | |
238 context.sendMessage(checkDelayReply); | |
223 | 239 } |
240 } catch (Exception e) { | |
241 try { | |
242 writerRunning.set(2); | |
243 os.close(); | |
244 is.close(); | |
245 break; | |
246 } catch (IOException e1) { | |
247 } catch (TransportException e1) { | |
248 e1.printStackTrace(); | |
249 } | |
250 return; | |
251 } | |
252 } | |
253 } | |
254 }; | |
255 /** | |
256 * send packets to a client (one thread for each client ) | |
257 */ | |
258 Runnable sender = new Runnable() { | |
259 public void run() { | |
260 writerRunning.set(1); | |
261 try { | |
262 requestThreadNotify(); | |
239 | 263 |
223 | 264 // after this, we discard upward packet. |
239 | 265 new Thread(reader, "upward-packet-processing").start(); |
266 | |
223 | 267 for (;;) { |
268 LinkedList<ByteBuffer> bufs = c.poll(); | |
239 | 269 |
223 | 270 int inputIndex = 0; |
271 ByteBuffer header = bufs.get(inputIndex); | |
272 if (header == null) | |
273 continue; | |
274 writeToClient(os, bufs, inputIndex); | |
275 writerRunning.set(1); // yes my client is awaking. | |
276 } | |
277 } catch (Exception e) { | |
278 try { | |
279 writerRunning.set(2); | |
280 os.close(); | |
281 } catch (IOException e1) { | |
282 System.out.println("root writer close faild :" + e1); | |
283 } | |
284 System.out.println("root writer faild :" + e); | |
285 /* if socket closed cliList.remove(newCli); */ | |
286 } | |
287 } | |
288 public void writeToClient(final Writer os, | |
289 LinkedList<ByteBuffer> bufs, int inputIndex) | |
290 throws TransportException { | |
291 while (inputIndex < bufs.size()) { | |
292 ByteBuffer b = bufs.get(inputIndex++); | |
293 os.write(b.array(), b.position(), b.limit()); | |
294 } | |
295 os.flush(); | |
296 bufs = null; | |
297 multicastqueue.heapAvailable(); | |
298 } | |
299 }; | |
300 clients++; | |
301 new Thread(sender, "writer-to-lower-node").start(); | |
302 } | |
157
7cea8789387b
thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
153
diff
changeset
|
303 |
281 | 304 public void sendSingleDisplayWidth(int singleDisplayWidth) throws UnsupportedEncodingException { |
305 LinkedList<ByteBuffer> linkedListSendSingleDisplayWidth = new LinkedList<ByteBuffer>(); | |
306 SendSingleDisplayWidth sendSingleDisplayWidth = new SendSingleDisplayWidth(); | |
307 linkedListSendSingleDisplayWidth.add(sendSingleDisplayWidth.singleDisplayWidth(0, 0, singleDisplayWidth, 0)); | |
308 addSerialNumber(linkedListSendSingleDisplayWidth); | |
309 multicastqueue.put(linkedListSendSingleDisplayWidth); | |
310 System.out.println(singleDisplayWidth + " : send single display width"); | |
311 } | |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
312 |
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
313 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
|
314 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
|
315 } |
223 | 316 |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
317 |
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
318 public void setPermitChangeScreen(boolean v) { |
223 | 319 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
|
320 } |
223 | 321 |
322 public void requestThreadNotify() { | |
323 rThread.reStart(); | |
324 } | |
325 | |
326 | |
28 | 327 public void setProtocolContext(Protocol workingProtocol) { |
328 context = workingProtocol; | |
329 } | |
29 | 330 |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
331 public Socket accept() throws IOException { |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
332 return servSock.accept(); |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
333 } |
31 | 334 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
335 public int selectPort(int p) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
336 int port = p; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
337 while (true) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
338 try { |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
339 servSock = new ServerSocket(port); |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
340 acceptPort = port; |
181 | 341 myAddress = "127.0.0.1"; |
207 | 342 nets.getNetworkInterfaces(); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
343 break; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
344 } catch (BindException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
345 port++; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
346 continue; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
347 } catch (IOException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
348 |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
349 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
350 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
351 System.out.println("accept port = " + port); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
352 return port; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
353 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
354 |
33
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
355 |
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
356 |
223 | 357 public void writeFramebufferUpdateRequest(int x, int y, int w, int h, |
358 boolean incremental) throws TransportException { | |
359 byte[] b = new byte[10]; | |
360 | |
361 b[0] = (byte) FramebufferUpdateRequest; // 3 is FrameBufferUpdateRequest | |
362 b[1] = (byte) (incremental ? 1 : 0); | |
363 b[2] = (byte) ((x >> 8) & 0xff); | |
364 b[3] = (byte) (x & 0xff); | |
365 b[4] = (byte) ((y >> 8) & 0xff); | |
366 b[5] = (byte) (y & 0xff); | |
367 b[6] = (byte) ((w >> 8) & 0xff); | |
368 b[7] = (byte) (w & 0xff); | |
369 b[8] = (byte) ((h >> 8) & 0xff); | |
370 b[9] = (byte) (h & 0xff); | |
371 } | |
33
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
372 |
223 | 373 public void setViewer(ViewerInterface v) { |
374 viewer = v; | |
375 } | |
376 | |
377 public ViewerInterface getViewer() { | |
378 return viewer; | |
379 } | |
380 | |
381 | |
382 void sendInitData(OutputStream os) throws IOException { | |
383 os.write(context.getInitData()); | |
384 } | |
385 | |
386 | |
387 public void setTerminationType(boolean setType) { | |
388 normalTermination = setType; | |
389 } | |
390 | |
391 public boolean getTerminationType() { | |
392 return normalTermination; | |
393 } | |
43 | 394 |
206 | 395 |
223 | 396 public void addHostToSelectionPanel(int port, String hostname,String myHostName) { |
397 if (rootSelectionPanel != null) { | |
398 rootSelectionPanel.checkBox(Integer.toString(port) + ":" + hostname + ":" + myHostName); | |
399 rootSelectionPanel.setButton(); | |
400 rootSelectionPanel.visible(); | |
401 } | |
402 } | |
43 | 403 |
223 | 404 public void createRootSelectionPanel(CreateConnectionParam cp) { |
405 rootSelectionPanel = new TreeVncRootSelectionPanel(); | |
406 rootSelectionPanel.setCp(cp); | |
407 } | |
408 | |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
409 public void close() { |
223 | 410 // none |
411 } | |
412 | |
413 public int getAcceptPort() { | |
414 return acceptPort; | |
415 } | |
416 | |
417 public boolean getReadyReconnect() { | |
418 return readyReconnect; | |
419 } | |
65 | 420 |
421 | |
223 | 422 public boolean getCuiVersion() { |
423 return cuiVersion; | |
424 } | |
66 | 425 |
223 | 426 public void setCuiVersion(boolean flag) { |
427 cuiVersion = flag; | |
428 } | |
429 | |
430 public void readCheckDelay(Reader reader) throws TransportException { | |
431 | |
432 } | |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
433 |
223 | 434 public synchronized void vncConnected(boolean ready) { |
435 if (ready && reconnecting) { | |
436 Socket vncSocket = viewer.getVNCSocket(); | |
437 NetworkInterface ni = nets.getInterface(vncSocket); | |
438 if (ni!=null) { | |
439 vncInterface = ni.getName(); | |
440 System.out.println("VNCNetworkInterface :" + vncInterface); | |
441 } | |
442 sendDesktopSizeChange(reconnectingId); | |
443 reconnecting = false; | |
444 if (reconnectingId == 0) { | |
445 viewer.setVisible(false); | |
446 } | |
447 } | |
448 if (reconnectingId!=0) { | |
449 readyReconnect = ready; | |
450 if (ready) { | |
451 notifyAll(); | |
452 } | |
453 } | |
454 } | |
94
75879c316796
synchronized wait for Rfb initialization in change server.
oc
parents:
89
diff
changeset
|
455 |
202 | 456 |
223 | 457 public synchronized void waitForVNCConnection() throws InterruptedException { |
458 if (reconnectingId!=0) { | |
459 while (!readyReconnect) { | |
460 wait(); | |
461 } | |
462 } | |
463 } | |
96 | 464 |
465 | |
223 | 466 public void sendDesktopSizeChange(short id) { |
467 LinkedList<ByteBuffer> desktopSize = new LinkedList<ByteBuffer>(); | |
468 int width = context.getFbWidth(); | |
469 int height = context.getFbHeight(); | |
277 | 470 desktopSize.add(new ChengeDesktopSize(width, height, EncodingType.INIT_DATA, context.getInitData(),id).getMessage()); |
242 | 471 addSerialNumber(desktopSize); |
223 | 472 multicastqueue.put(desktopSize); |
473 } | |
98 | 474 |
475 | |
223 | 476 public void addSerialNumber(LinkedList<ByteBuffer> bufs) { |
242 | 477 ByteBuffer serialNum = multicastqueue.allocate(4+8); // addSerialNum flag + SerialNum |
243 | 478 if (this.addSerialNum) { |
479 serialNum.putInt(1); | |
480 } else { | |
481 serialNum.putInt(0); | |
482 } | |
223 | 483 serialNum.putLong(counter++); |
484 serialNum.flip(); | |
485 bufs.addFirst(serialNum); | |
486 } | |
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
|
487 |
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
|
488 |
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
|
489 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
|
490 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
|
491 } |
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
|
492 |
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
|
493 public void stopReceiverTask() { |
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
|
494 if (context!=null) |
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
|
495 context.cleanUpSession(null); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
496 // cleanup zlib decoder for new VNCServer |
202 | 497 if (isTreeManager()) |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
498 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
|
499 } |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
500 |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
501 public String getMyAddress() { |
174 | 502 return myAddress; |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
503 } |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
504 |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
505 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
506 * gzip byte arrays |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
507 * |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
508 * @param deflater |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
509 * @param inputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
510 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
511 * @param inputIndex |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
512 * @param outputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
513 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
514 * @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
|
515 * @throws IOException |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
516 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
517 public int zip(Deflater deflater, LinkedList<ByteBuffer> inputs, |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
518 int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
519 int len = 0; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
520 ByteBuffer c1 = multicastqueue.allocate(INFLATE_BUFSIZE); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
521 while (inputIndex < inputs.size()) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
522 ByteBuffer b1 = inputs.get(inputIndex++); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
523 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
|
524 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
525 * 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
|
526 * 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
|
527 * 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
|
528 * 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
|
529 * of bug of Java library. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
530 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
531 if (inputIndex == inputs.size()) |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
532 deflater.finish(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
533 int len1 = 0; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
534 do { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
535 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
|
536 c1.remaining()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
537 if (len1 > 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
538 len += len1; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
539 c1.position(c1.position() + len1); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
540 if (c1.remaining() == 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
541 c1.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
542 outputs.addLast(c1); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
543 c1 = multicastqueue.allocate(INFLATE_BUFSIZE); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
544 } |
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 } 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
|
547 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
548 if (c1.position() != 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
549 c1.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
550 outputs.addLast(c1); |
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 deflater.reset(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
553 return len; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
554 } |
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 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
557 * gunzip byte arrays |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
558 * |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
559 * @param inflater |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
560 * @param inputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
561 * byte data[] |
182 | 562 * @param bytes |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
563 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
564 * @return number of total bytes |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
565 * @throws IOException |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
566 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
567 public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs, |
182 | 568 int inputIndex, byte[] bytes, int bufSize) |
223 | 569 throws DataFormatException { |
182 | 570 int position = 0; |
571 int limit = bytes.length; | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
572 while (inputIndex < inputs.size()) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
573 ByteBuffer input = inputs.get(inputIndex++); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
574 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
|
575 // 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
|
576 // we need this |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
577 // 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
|
578 do { |
182 | 579 int len0 = inflater.inflate(bytes, position, |
580 limit-position); | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
581 if (len0 > 0) { |
223 | 582 position += len0; |
182 | 583 if (position > limit) { |
223 | 584 throw new DataFormatException(); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
585 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
586 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
587 } while (!inflater.needsInput()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
588 } |
182 | 589 return position; |
118
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 |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
592 /** |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
593 * 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
|
594 * put the packet to the multicastqueue. Then normal rendering engine read the same stream using is.reset(). |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
595 * @param dataLen |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
596 * @param reader |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
597 * @throws TransportException |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
598 * @throws UnsupportedEncodingException |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
599 */ |
264 | 600 public void readSendData(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect) |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
601 throws TransportException, UnsupportedEncodingException { |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
602 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
603 ByteBuffer header = multicastqueue.allocate(16); |
242 | 604 ByteBuffer serial = multicastqueue.allocate(4+8); |
202 | 605 if (!isTreeManager()) { |
242 | 606 reader.readBytes(serial.array(),0,4+8); |
607 serial.limit(4+8); | |
182 | 608 } |
185 | 609 reader.mark(dataLen); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
610 reader.readBytes(header.array(), 0, 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
611 header.limit(16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
612 if (header.get(0) == FramebufferUpdate) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
613 int encoding = header.getInt(12); |
239 | 614 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
615 if (encoding == EncodingType.ZRLE.getId() |
229
5eb8aa65f387
fix checkdelay number-of-rectangle, and send checkdelay to lower node.
oc
parents:
227
diff
changeset
|
616 || encoding == EncodingType.ZLIB.getId()) { |
186
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
617 // recompress into ZREE |
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
618 // 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
|
619 ByteBuffer len = multicastqueue.allocate(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
620 reader.readBytes(len.array(), 0, 4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
621 len.limit(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
622 ByteBuffer inputData = multicastqueue.allocate(dataLen - 20); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
623 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
|
624 inputData.limit(dataLen - 20); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
625 LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
626 inputs.add(inputData); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
627 header.putInt(12, EncodingType.ZRLEE.getId()); // means |
223 | 628 // recompress |
629 // every time | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
630 // 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
|
631 // protocol, clients have to be modified. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
632 Deflater nDeflater = deflater; // new Deflater(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
633 LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
634 try { |
182 | 635 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
|
636 // dump32(inputs); |
182 | 637 out.add(ByteBuffer.wrap(bytes)); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
638 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
|
639 ByteBuffer blen = multicastqueue.allocate(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
640 blen.putInt(len2); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
641 blen.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
642 bufs.addFirst(blen); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
643 bufs.addFirst(header); |
242 | 644 addSerialNumber(bufs); |
270 | 645 if (filterSingleDisplay) { |
275 | 646 if (rect.x < singleWidth) { |
270 | 647 multicastqueue.put(bufs); |
648 } | |
649 } else { | |
650 multicastqueue.put(bufs); | |
651 } | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
652 } catch (DataFormatException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
653 throw new TransportException(e); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
654 } catch (IOException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
655 throw new TransportException(e); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
656 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
657 return; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
658 } |
233 | 659 |
186
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
660 // ZRLEE is already compressed |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
661 bufs.add(header); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
662 if (dataLen > 16) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
663 ByteBuffer b = multicastqueue.allocate(dataLen - 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
664 reader.readBytes(b.array(), 0, dataLen - 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
665 b.limit(dataLen - 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
666 bufs.add(b); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
667 } |
242 | 668 this.addSerialNumber(bufs); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
669 multicastqueue.put(bufs); |
233 | 670 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
671 return; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
672 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
673 // It may be compressed. We can inflate here to avoid repeating clients |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
674 // decompressing here, |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
675 // but it may generate too many large data. It is better to do it in |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
676 // each client. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
677 // But we have do inflation for all input data, so we have to do it |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
678 // here. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
679 } |
124 | 680 |
223 | 681 public void setId(short id) { |
682 this.id = id; | |
683 } | |
169 | 684 |
223 | 685 public short getId() { |
686 return id; | |
687 } | |
169 | 688 |
174 | 689 public void setMyAddress(String myHostName) { |
690 this.myAddress = myHostName; | |
223 | 691 |
174 | 692 } |
693 | |
694 public void setLeader(boolean leader) { | |
695 this.leader = leader; | |
696 } | |
697 | |
698 public boolean isLeader() { | |
699 return leader; | |
700 } | |
701 | |
203 | 702 public void setTreeManager(String intf, TreeManagement clients) { |
223 | 703 nets.setTreeManager(intf, clients); |
174 | 704 } |
223 | 705 |
203 | 706 public TreeManagement getTreeManager(String intf) { |
231 | 707 TreeManagement tm = nets.getTreeManager(intf); |
708 this.nodeList = tm.getList(); | |
709 return tm; | |
174 | 710 } |
711 | |
712 /** | |
713 * chnageVNCServer is called when host change. | |
714 * | |
275 | 715 * @param vncProxyService |
174 | 716 * @param hostName |
717 * HostAddress | |
718 * @param width | |
719 * FrameWidth | |
720 * @param height | |
721 * FrameHeight | |
275 | 722 * @param id |
723 * @throws InterruptedException | |
174 | 724 */ |
725 public void changeVNCServer(ViewerInterface vncProxyService, String hostName, int width, int height, short id) | |
223 | 726 throws UnknownHostException, IOException, InterruptedException { |
257 | 727 |
728 this.frameSizeWidth = width; | |
729 this.frameSizeHeight = height; | |
283 | 730 singleWidth = frameSizeWidth; |
257 | 731 |
223 | 732 // stop reader stop |
174 | 733 stopReceiverTask(); |
192 | 734 reconnectingId = id; |
223 | 735 vncProxyService.inhelitClients(vncProxyService, hostName); |
187 | 736 // after connecting VNC server, rfb send SEND_INIT_DATA command and wakes me up if necessary |
223 | 737 reconnecting = true; |
738 if (reconnectingId!=0) { | |
739 waitForVNCConnection(); | |
740 } | |
174 | 741 } |
742 | |
743 /** | |
744 * start accepting children | |
745 * run rootFinderListener if necessary | |
746 */ | |
176 | 747 public void createConnectionAndStart(ViewerInterface v) { |
223 | 748 selectPort(ConnectionParams.DEFAULT_VNC_ROOT); |
176 | 749 startTreeVncCommandListener(); |
223 | 750 if(isTreeManager() && firstTime) { |
751 getCast = new TreeRootFinderListener(v); | |
239 | 752 Thread treeRootFindThread = new Thread(getCast, "tree-root-find-listener"); |
753 treeRootFindThread.start(); | |
223 | 754 firstTime = false; |
755 } | |
174 | 756 } |
757 | |
223 | 758 public void startTreeVncCommandListener() { |
176 | 759 acceptThread = new TreeVncCommandChannelListener(this, getAcceptPort()); |
223 | 760 Thread thread = new Thread(acceptThread, "TreeVNC-accept"); |
761 thread.start(); | |
176 | 762 } |
763 | |
174 | 764 public TreeVncCommandChannelListener getAcceptThread() { |
765 return acceptThread; | |
766 } | |
767 | |
176 | 768 public void setConnectionParam(CreateConnectionParam createConnectionParam) { |
769 cp = createConnectionParam; | |
770 } | |
771 | |
772 public CreateConnectionParam getConnectionParam() { | |
773 return cp; | |
774 } | |
775 | |
178
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
776 public boolean hasViewer() { |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
777 return hasViewer; |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
778 } |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
779 |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
780 public void setHasViewer(boolean b) { |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
781 hasViewer = b; |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
782 } |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
783 |
186
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
784 public void setReconnecting(boolean b) { |
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
785 reconnecting = b; |
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
786 } |
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
787 |
223 | 788 public int getReconnectingId() { |
789 return reconnectingId; | |
790 } | |
791 | |
792 public void setShowTree(boolean showTree) { | |
240 | 793 this.showTreeNode = showTree; |
794 } | |
795 | |
796 public void setCheckDelay(boolean checkDelay) { | |
797 this.checkDelay = checkDelay; | |
223 | 798 } |
194 | 799 |
241 | 800 public void setAddSerialNum(boolean addSerialNum) { |
801 this.addSerialNum = addSerialNum; | |
802 } | |
803 | |
235 | 804 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
|
805 int nodeNum = 0; |
235 | 806 |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
807 for (Iterator<TreeVNCNode> i = nodeList.iterator(); i.hasNext();) { |
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
808 TreeVNCNode tvn = (TreeVNCNode)i.next(); |
235 | 809 if (port == tvn.port && address.equals(tvn.hostname)) { |
810 nodeNum = tvn.treeNum; | |
811 return nodeNum; | |
812 } | |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
813 } |
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
814 return nodeNum; |
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
815 } |
241 | 816 |
257 | 817 public void setFixingSize(boolean fixingSize) { |
818 this.fixingSize = fixingSize; | |
256 | 819 } |
267 | 820 |
821 public void setFilterSingleDisplay(boolean filterSingleDisplay) { | |
822 this.filterSingleDisplay = filterSingleDisplay; | |
823 } | |
281 | 824 |
240 | 825 } |