annotate src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java @ 256:dfec8bc1eb8e

fix --retina option
author oc
date Tue, 18 Nov 2014 14:10:53 +0900 (2014-11-18)
parents a931be447973
children 11b59b223222
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
57
17b702648079 version2.7.2 original version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 0
diff changeset
1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC.
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 // All rights reserved.
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 //-------------------------------------------------------------------------
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // This file is part of the TightVNC software. Please visit our Web site:
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 // http://www.tightvnc.com/
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 // This program is free software; you can redistribute it and/or modify
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 // it under the terms of the GNU General Public License as published by
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 // the Free Software Foundation; either version 2 of the License, or
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 // (at your option) any later version.
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 // This program is distributed in the hope that it will be useful,
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 // GNU General Public License for more details.
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 // You should have received a copy of the GNU General Public License along
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 // with this program; if not, write to the Free Software Foundation, Inc.,
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 //-------------------------------------------------------------------------
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 //
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 package com.glavsoft.rfb.protocol;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 import com.glavsoft.drawing.Renderer;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 import com.glavsoft.exceptions.CommonException;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 import com.glavsoft.exceptions.ProtocolException;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 import com.glavsoft.exceptions.TransportException;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 import com.glavsoft.rfb.ClipboardController;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 import com.glavsoft.rfb.IRepaintController;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 import com.glavsoft.rfb.client.FramebufferUpdateRequestMessage;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 import com.glavsoft.rfb.client.SetPixelFormatMessage;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 import com.glavsoft.rfb.encoding.EncodingType;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 import com.glavsoft.rfb.encoding.PixelFormat;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 import com.glavsoft.rfb.encoding.decoder.Decoder;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 import com.glavsoft.rfb.encoding.decoder.DecodersContainer;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 import com.glavsoft.rfb.encoding.decoder.FramebufferUpdateRectangle;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 import com.glavsoft.rfb.encoding.decoder.RichCursorDecoder;
66
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
41 import com.glavsoft.rfb.encoding.decoder.ZRLEESender;
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 import com.glavsoft.transport.Reader;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 import java.io.PrintWriter;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 import java.io.StringWriter;
167
1d3fa20b86bb update remoteDesktopName.
oc
parents: 166
diff changeset
46 import java.io.UnsupportedEncodingException;
255
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
47 import java.util.Timer;
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
48 import java.util.TimerTask;
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 import java.util.logging.Logger;
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
230
f4ea9ff04741 reply checkdelay
oc
parents: 229
diff changeset
51 import jp.ac.u_ryukyu.treevnc.CheckDelayReply;
239
d655db005535 create sendCheckDelay Socket.
oc
parents: 237
diff changeset
52 import jp.ac.u_ryukyu.treevnc.SendCheckDelay;
207
b31903e5b02d rename myRFBProto
oc
parents: 206
diff changeset
53 import jp.ac.u_ryukyu.treevnc.TreeRFBProto;
206
2b3eb4a9492f MyRfbProto reorganization
oc
parents: 204
diff changeset
54 import jp.ac.u_ryukyu.treevnc.TreeVncProtocol;
231
0e0e6744432c get new nodeList for checkDelay.
oc
parents: 230
diff changeset
55
35
1b81deb0abb3 write a little part reconnection.
one
parents: 28
diff changeset
56
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
57 public class ReceiverTask implements Runnable {
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
58 private static final byte FRAMEBUFFER_UPDATE = 0;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
59 private static final byte SET_COLOR_MAP_ENTRIES = 1;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
60 private static final byte BELL = 2;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
61 private static final byte SERVER_CUT_TEXT = 3;
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
62
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
63
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
64 private static Logger logger = Logger.getLogger("com.glavsoft.rfb.protocol.ReceiverTask");
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
65 private final Reader reader;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
66 private volatile boolean isRunning = false;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
67 private Renderer renderer;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
68 private final IRepaintController repaintController;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
69 private final ClipboardController clipboardController;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
70 protected final DecodersContainer decoders;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
71 protected FramebufferUpdateRequestMessage fullscreenFbUpdateIncrementalRequest;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
72 protected final ProtocolContext context;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
73 protected PixelFormat pixelFormat;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
74 protected boolean needSendPixelFormat;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
75 private TreeRFBProto rfb;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
76 private long checkCounter = 0;
239
d655db005535 create sendCheckDelay Socket.
oc
parents: 237
diff changeset
77 private boolean firstTime = true;
248
e6abf4b0c92e add numberOfRectangle in checkDelay
Miwa Oshiro <e115747@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
78 public int numberOfRectangles = 0;
255
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
79 private Timer timer = null;
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
80
255
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
81
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
82 public ReceiverTask(Reader reader,
35
1b81deb0abb3 write a little part reconnection.
one
parents: 28
diff changeset
83 IRepaintController repaintController, ClipboardController clipboardController,
1b81deb0abb3 write a little part reconnection.
one
parents: 28
diff changeset
84 DecodersContainer decoders, ProtocolContext context,
207
b31903e5b02d rename myRFBProto
oc
parents: 206
diff changeset
85 TreeRFBProto _rfb) {
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
86 rfb = _rfb;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
87 this.reader = reader;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
88 this.repaintController = repaintController;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
89 this.clipboardController = clipboardController;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
90 this.context = context;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
91 this.decoders = decoders;
178
34b7558aeffa remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 176
diff changeset
92
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
93 Decoder decoder = new ZRLEESender(rfb);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
94 decoders.setDecoderByType(EncodingType.ZLIB, decoder);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
95 decoders.setDecoderByType(EncodingType.ZRLE, decoder);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
96 decoders.setDecoderByType(EncodingType.ZRLEE, decoder);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
97
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
98 if(!rfb.getCuiVersion())
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
99 renderer = repaintController.createRenderer(reader, context.getFbWidth(), context.getFbHeight(),context.getPixelFormat());
255
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
100 fullscreenFbUpdateIncrementalRequest = new FramebufferUpdateRequestMessage(0, 0, context.getFbWidth(), context.getFbHeight(), true);
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
101 if(rfb.isTreeManager()) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
102 fullscreenFbUpdateIncrementalRequest.sendFullScreenRequest();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
103 connectionFinished();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
104 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
105 }
178
34b7558aeffa remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 176
diff changeset
106
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
107 @Override
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
108 public void run() {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
109 isRunning = true;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
110 while (isRunning) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
111 try {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
112 if(! rfb.isTreeManager()) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
113 // client has 8byte packet sequence number
242
a640cd7001e1 fix checkdelay, and fix serial number option
oc
parents: 241
diff changeset
114 // add serial number flag (4byte)
a640cd7001e1 fix checkdelay, and fix serial number option
oc
parents: 241
diff changeset
115 reader.mark(20+8+4);
a640cd7001e1 fix checkdelay, and fix serial number option
oc
parents: 241
diff changeset
116 getLost(reader); //check seq consistency
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
117 } else {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
118 reader.mark(20);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
119 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
120 byte messageId = reader.readByte();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
121 switch (messageId) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
122 case FRAMEBUFFER_UPDATE:
239
d655db005535 create sendCheckDelay Socket.
oc
parents: 237
diff changeset
123 // logger.fine("Server message: FramebufferUpdate (0)");
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
124 framebufferUpdateMessage();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
125 break;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
126 case SET_COLOR_MAP_ENTRIES:
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
127 logger.severe("Server message SetColorMapEntries is not implemented. Skip.");
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
128 setColorMapEntries();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
129 break;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
130 case BELL:
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
131 logger.fine("Server message: Bell");
239
d655db005535 create sendCheckDelay Socket.
oc
parents: 237
diff changeset
132 // System.out.print("\0007");
d655db005535 create sendCheckDelay Socket.
oc
parents: 237
diff changeset
133 // System.out.flush();
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
134 break;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
135 case SERVER_CUT_TEXT:
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
136 logger.fine("Server message: CutText (3)");
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
137 serverCutText();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
138 break;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
139 default:
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
140 logger.severe("Unsupported server message. Id = " + messageId);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
141 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
142 } catch (TransportException e) {
133
70cbec526039 connection handling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 125
diff changeset
143 logger.severe("Close session: " + e.getMessage());
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
144 if(!rfb.isTreeManager() && !(rfb.getTerminationType())) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
145 System.out.println("task stop");
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
146 TreeVncProtocol echo = new TreeVncProtocol(rfb.getConnectionParam().getHostName(), rfb.getConnectionParam().getPort());
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
147 int counter = 3;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
148 while(counter-- > 0) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
149 try {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
150 if (rfb.isLeader()) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
151 echo.lostParent(rfb.getMyAddress(),rfb.getAcceptPort());
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
152 }
145
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 135
diff changeset
153 break;
133
70cbec526039 connection handling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 125
diff changeset
154 } catch (Exception e1) {
70cbec526039 connection handling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 125
diff changeset
155 logger.severe("Cannot send lostHost: " + e1.getMessage());
145
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 135
diff changeset
156 sleep(3000);
133
70cbec526039 connection handling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 125
diff changeset
157 }
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
158 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
159 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
160 stopTask();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
161 } catch (ProtocolException e) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
162 logger.severe(e.getMessage());
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
163 if (isRunning) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
164 context.cleanUpSession(e.getMessage() + "\nConnection closed.");
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
165 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
166 stopTask();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
167 } catch (CommonException e) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
168 logger.severe(e.getMessage());
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
169 if (isRunning) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
170 context.cleanUpSession("Connection closed..");
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
171 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
172 stopTask();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
173 } catch (Throwable te) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
174 StringWriter sw = new StringWriter();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
175 PrintWriter pw = new PrintWriter(sw);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
176 te.printStackTrace(pw);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
177 logger.severe(te.getMessage());
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
178 if (isRunning) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
179 context.cleanUpSession(te.getMessage() + "\n" + sw.toString());
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
180 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
181 stopTask();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
182 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
183 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
184 }
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
185
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
186 private void sleep(int i) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
187 try {
145
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 135
diff changeset
188 Thread.sleep(i);
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 135
diff changeset
189 } catch (InterruptedException e) {
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 135
diff changeset
190 // nothing.
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 135
diff changeset
191 }
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 135
diff changeset
192 }
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 135
diff changeset
193
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 135
diff changeset
194
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 135
diff changeset
195 private void setColorMapEntries() throws TransportException {
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
196 reader.readByte(); // padding
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
197 reader.readUInt16(); // first color index
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
198 int length = reader.readUInt16();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
199 while (length-- > 0) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
200 reader.readUInt16(); // R
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
201 reader.readUInt16(); // G
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
202 reader.readUInt16(); // B
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
203 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
204 }
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
205
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
206 private void serverCutText() throws TransportException {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
207 reader.readByte(); // padding
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
208 reader.readInt16(); // padding
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
209 int length = reader.readInt32() & Integer.MAX_VALUE;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
210 clipboardController.updateSystemClipboard(reader.readBytes(length));
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
211 }
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
212
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
213 public void framebufferUpdateMessage() throws CommonException, UnsupportedEncodingException {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
214 reader.readByte(); // padding
248
e6abf4b0c92e add numberOfRectangle in checkDelay
Miwa Oshiro <e115747@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
215
e6abf4b0c92e add numberOfRectangle in checkDelay
Miwa Oshiro <e115747@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
216 this.numberOfRectangles = reader.readUInt16();
250
45cb40bf0d74 put framebufferUpdate size
oc
parents: 248
diff changeset
217
45cb40bf0d74 put framebufferUpdate size
oc
parents: 248
diff changeset
218 if(numberOfRectangles != 1)
45cb40bf0d74 put framebufferUpdate size
oc
parents: 248
diff changeset
219 System.out.println("numberofrectangle : " + numberOfRectangles);
248
e6abf4b0c92e add numberOfRectangle in checkDelay
Miwa Oshiro <e115747@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
220
255
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
221 if(rfb.isTreeManager() && firstTime) {
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
222 if(rfb.checkDelay) {
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
223 SendCheckDelay sendCheckDelay = new SendCheckDelay(rfb);
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
224 Thread sendCheckDelayThread = new Thread(sendCheckDelay, "send-check-delay");
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
225 sendCheckDelayThread.start();
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
226 this.firstTime = false;
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
227 }
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
228
256
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
229 if(rfb.fixRetinaDisplay) {
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
230 timer = new Timer(true);
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
231 timer.schedule(new TimerTask() {
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
232 @Override
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
233 public void run() {
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
234 context.setFbWidth(1280);
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
235 context.setFbHeight(800);
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
236 context.sendMessage(new FramebufferUpdateRequestMessage(0, 0, context.getFbWidth(), context.getFbHeight(), true));
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
237 }
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
238 }, 0, 100);
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
239 }
239
d655db005535 create sendCheckDelay Socket.
oc
parents: 237
diff changeset
240 }
248
e6abf4b0c92e add numberOfRectangle in checkDelay
Miwa Oshiro <e115747@ie.u-ryukyu.ac.jp>
parents: 246
diff changeset
241
250
45cb40bf0d74 put framebufferUpdate size
oc
parents: 248
diff changeset
242 while (numberOfRectangles-- > 0) {
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
243 FramebufferUpdateRectangle rect = new FramebufferUpdateRectangle();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
244 rect.fill(reader);
250
45cb40bf0d74 put framebufferUpdate size
oc
parents: 248
diff changeset
245
252
eee9a8f53dbc change check delay log
oc
parents: 250
diff changeset
246 long time = System.currentTimeMillis();
256
dfec8bc1eb8e fix --retina option
oc
parents: 255
diff changeset
247 if(rfb.isTreeManager() && rfb.checkDelay)
252
eee9a8f53dbc change check delay log
oc
parents: 250
diff changeset
248 System.out.println(time + " : size : " + rect.width * rect.height);
250
45cb40bf0d74 put framebufferUpdate size
oc
parents: 248
diff changeset
249
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
250 Decoder decoder = decoders.getDecoderByType(rect.getEncodingType());
250
45cb40bf0d74 put framebufferUpdate size
oc
parents: 248
diff changeset
251 logger.finest(rect.toString() + (0 == numberOfRectangles ? "\n---" : ""));
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
252 if (decoder != null) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
253 decoder.decode(reader, renderer, rect); // TreeVNC processing here
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
254 if(!(rfb.getCuiVersion()))
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
255 repaintController.repaintBitmap(rect);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
256 } else if (rect.getEncodingType() == EncodingType.RICH_CURSOR) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
257 RichCursorDecoder.getInstance().decode(reader, renderer, rect);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
258 if(repaintController!=null)
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
259 repaintController.repaintCursor();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
260 } else if (rect.getEncodingType() == EncodingType.CURSOR_POS) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
261 renderer.decodeCursorPosition(rect);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
262 repaintController.repaintCursor();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
263 } else if (rect.getEncodingType() == EncodingType.DESKTOP_SIZE || rect.getEncodingType() == EncodingType.INIT_DATA ) {
255
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
264 fullscreenFbUpdateIncrementalRequest = new FramebufferUpdateRequestMessage(0, 0, rect.width, rect.height, false);
106
01c0fd20c0b4 share screen enable cui flag.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 103
diff changeset
265 rfb.setCuiVersion(false);
171
fab76dd9c3cd avoid deadLock on surface.
oc
parents: 170
diff changeset
266 boolean visible = true;
164
86289e56263c Send initData in server change
oc
parents: 145
diff changeset
267 if (rect.getEncodingType() == EncodingType.INIT_DATA) {
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
268 int length = reader.readInt32();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
269 byte[] initData = new byte[length];
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
270 reader.read(initData);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
271 String name = new String(initData, 24, length - 24, "UTF-8");
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
272 rfb.getContext().setRemoteDesktopName(name);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
273 rfb.getContext().setInitData(initData);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
274 repaintController.updateRemoteDesktopName(rfb.getContext());
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
275 reader.reset();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
276 rfb.readSendData(length + 20, reader, null ); // size of UpdateRectangleMessage with initData.
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
277 short id = (short) rect.x;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
278 visible = (id != rfb.getId());
164
86289e56263c Send initData in server change
oc
parents: 145
diff changeset
279 }
171
fab76dd9c3cd avoid deadLock on surface.
oc
parents: 170
diff changeset
280 synchronized (renderer.getLock()) {
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
281 if(!(rfb.getCuiVersion()))
255
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
282 renderer = repaintController.createRenderer(reader, rect.width, rect.height, context.getPixelFormat());
171
fab76dd9c3cd avoid deadLock on surface.
oc
parents: 170
diff changeset
283 }
fab76dd9c3cd avoid deadLock on surface.
oc
parents: 170
diff changeset
284 if (rect.getEncodingType() == EncodingType.INIT_DATA) {
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
285 repaintController.setVisible(visible);
171
fab76dd9c3cd avoid deadLock on surface.
oc
parents: 170
diff changeset
286 }
255
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
287 context.sendMessage(new FramebufferUpdateRequestMessage(0, 0, rect.width, rect.height, false));
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
288 // repaintController.repaintCursor();
227
2cb2279ca95c send checkdelay time.
Miwa Oshiro <e115747@ie.u-ryukyu.ac.jp>
parents: 226
diff changeset
289 } else if (rect.getEncodingType() == EncodingType.CHECK_DELAY) {
242
a640cd7001e1 fix checkdelay, and fix serial number option
oc
parents: 241
diff changeset
290 int checkDelaySize = 24;
229
5eb8aa65f387 fix checkdelay number-of-rectangle, and send checkdelay to lower node.
oc
parents: 228
diff changeset
291 reader.reset();
237
0815ed7f54a7 clean code.
oc
parents: 234
diff changeset
292 rfb.readSendData(checkDelaySize, reader, null);
234
8479ad028ec7 fix checkdelay send and get.
oc
parents: 233
diff changeset
293 int port = rfb.acceptPort;
8479ad028ec7 fix checkdelay send and get.
oc
parents: 233
diff changeset
294 String address = rfb.getMyAddress();
8479ad028ec7 fix checkdelay send and get.
oc
parents: 233
diff changeset
295 sendCheckDelayReply(rect.time, port, address);
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
296 } else
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
297 throw new CommonException("Unprocessed encoding: " + rect.toString());
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
298 }
239
d655db005535 create sendCheckDelay Socket.
oc
parents: 237
diff changeset
299
d655db005535 create sendCheckDelay Socket.
oc
parents: 237
diff changeset
300 if (!rfb.isTreeManager()) {
d655db005535 create sendCheckDelay Socket.
oc
parents: 237
diff changeset
301 return;
d655db005535 create sendCheckDelay Socket.
oc
parents: 237
diff changeset
302 }
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
303 synchronized (this) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
304 if (needSendPixelFormat) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
305 needSendPixelFormat = false;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
306 context.setPixelFormat(pixelFormat);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
307 context.sendMessage(new SetPixelFormatMessage(pixelFormat));
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
308 logger.fine("sent: "+pixelFormat);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
309 context.sendRefreshMessage();
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
310 logger.fine("sent: nonincremental fb update");
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
311 } else {
255
a931be447973 add framebufferUpdateRecuest timer
oc
parents: 254
diff changeset
312 context.sendMessage(new FramebufferUpdateRequestMessage(0, 0, context.getFbWidth(), context.getFbHeight(), false));
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
313 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
314 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
315 }
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
316
234
8479ad028ec7 fix checkdelay send and get.
oc
parents: 233
diff changeset
317 private void sendCheckDelayReply(long time, int port, String address) throws UnsupportedEncodingException {
8479ad028ec7 fix checkdelay send and get.
oc
parents: 233
diff changeset
318 context.sendMessage(new CheckDelayReply(time, port, address));
230
f4ea9ff04741 reply checkdelay
oc
parents: 229
diff changeset
319 }
f4ea9ff04741 reply checkdelay
oc
parents: 229
diff changeset
320
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
321 public synchronized void queueUpdatePixelFormat(PixelFormat pf) {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
322 pixelFormat = pf;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
323 needSendPixelFormat = true;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
324 // context.sendMessage(new FramebufferUpdateRequestMessage(0, 0, 1, 1, false));
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
325 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
326
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
327 public void stopTask() {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
328 isRunning = false;
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
329 }
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
330
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
331 private void connectionFinished() {
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
332 rfb.vncConnected(true);
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
333 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
334
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
335 private void getLost(Reader reader) throws Exception {
242
a640cd7001e1 fix checkdelay, and fix serial number option
oc
parents: 241
diff changeset
336 int addSerialNumFlag = reader.readInt32();
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
337 long num = reader.readInt64();
243
0ed7719c1800 fix serial number option.
oc
parents: 242
diff changeset
338 if (addSerialNumFlag == 1) {
0ed7719c1800 fix serial number option.
oc
parents: 242
diff changeset
339 rfb.setAddSerialNum(true);
0ed7719c1800 fix serial number option.
oc
parents: 242
diff changeset
340 if(num != ++checkCounter) {
0ed7719c1800 fix serial number option.
oc
parents: 242
diff changeset
341 System.out.println("LostData" + (num - checkCounter));
0ed7719c1800 fix serial number option.
oc
parents: 242
diff changeset
342 checkCounter = num;
0ed7719c1800 fix serial number option.
oc
parents: 242
diff changeset
343 }
224
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
344 }
ccbc3a951961 fix indent, update mm.
oc
parents: 215
diff changeset
345 }
0
4689cc86d6cb create TreeViewer2 Repository
Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
346 }