annotate src/main/java/com/glavsoft/rfb/protocol/state/InitState.java @ 0:daa24f8a557b

TightVNC original
author YU
date Thu, 11 Sep 2014 07:30:03 +0900
parents
children 7bee64adbbfd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
daa24f8a557b TightVNC original
YU
parents:
diff changeset
1 // Copyright (C) 2010, 2011, 2012, 2013 GlavSoft LLC.
daa24f8a557b TightVNC original
YU
parents:
diff changeset
2 // All rights reserved.
daa24f8a557b TightVNC original
YU
parents:
diff changeset
3 //
daa24f8a557b TightVNC original
YU
parents:
diff changeset
4 //-------------------------------------------------------------------------
daa24f8a557b TightVNC original
YU
parents:
diff changeset
5 // This file is part of the TightVNC software. Please visit our Web site:
daa24f8a557b TightVNC original
YU
parents:
diff changeset
6 //
daa24f8a557b TightVNC original
YU
parents:
diff changeset
7 // http://www.tightvnc.com/
daa24f8a557b TightVNC original
YU
parents:
diff changeset
8 //
daa24f8a557b TightVNC original
YU
parents:
diff changeset
9 // This program is free software; you can redistribute it and/or modify
daa24f8a557b TightVNC original
YU
parents:
diff changeset
10 // it under the terms of the GNU General Public License as published by
daa24f8a557b TightVNC original
YU
parents:
diff changeset
11 // the Free Software Foundation; either version 2 of the License, or
daa24f8a557b TightVNC original
YU
parents:
diff changeset
12 // (at your option) any later version.
daa24f8a557b TightVNC original
YU
parents:
diff changeset
13 //
daa24f8a557b TightVNC original
YU
parents:
diff changeset
14 // This program is distributed in the hope that it will be useful,
daa24f8a557b TightVNC original
YU
parents:
diff changeset
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
daa24f8a557b TightVNC original
YU
parents:
diff changeset
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
daa24f8a557b TightVNC original
YU
parents:
diff changeset
17 // GNU General Public License for more details.
daa24f8a557b TightVNC original
YU
parents:
diff changeset
18 //
daa24f8a557b TightVNC original
YU
parents:
diff changeset
19 // You should have received a copy of the GNU General Public License along
daa24f8a557b TightVNC original
YU
parents:
diff changeset
20 // with this program; if not, write to the Free Software Foundation, Inc.,
daa24f8a557b TightVNC original
YU
parents:
diff changeset
21 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
daa24f8a557b TightVNC original
YU
parents:
diff changeset
22 //-------------------------------------------------------------------------
daa24f8a557b TightVNC original
YU
parents:
diff changeset
23 //
daa24f8a557b TightVNC original
YU
parents:
diff changeset
24
daa24f8a557b TightVNC original
YU
parents:
diff changeset
25 package com.glavsoft.rfb.protocol.state;
daa24f8a557b TightVNC original
YU
parents:
diff changeset
26
daa24f8a557b TightVNC original
YU
parents:
diff changeset
27 import com.glavsoft.exceptions.AuthenticationFailedException;
daa24f8a557b TightVNC original
YU
parents:
diff changeset
28 import com.glavsoft.exceptions.FatalException;
daa24f8a557b TightVNC original
YU
parents:
diff changeset
29 import com.glavsoft.exceptions.TransportException;
daa24f8a557b TightVNC original
YU
parents:
diff changeset
30 import com.glavsoft.exceptions.UnsupportedProtocolVersionException;
daa24f8a557b TightVNC original
YU
parents:
diff changeset
31 import com.glavsoft.exceptions.UnsupportedSecurityTypeException;
daa24f8a557b TightVNC original
YU
parents:
diff changeset
32 import com.glavsoft.rfb.encoding.ServerInitMessage;
daa24f8a557b TightVNC original
YU
parents:
diff changeset
33 import com.glavsoft.rfb.protocol.ProtocolContext;
daa24f8a557b TightVNC original
YU
parents:
diff changeset
34 import com.glavsoft.rfb.protocol.ProtocolSettings;
daa24f8a557b TightVNC original
YU
parents:
diff changeset
35
daa24f8a557b TightVNC original
YU
parents:
diff changeset
36 import java.util.logging.Logger;
daa24f8a557b TightVNC original
YU
parents:
diff changeset
37
daa24f8a557b TightVNC original
YU
parents:
diff changeset
38 /**
daa24f8a557b TightVNC original
YU
parents:
diff changeset
39 * ClientInit
daa24f8a557b TightVNC original
YU
parents:
diff changeset
40 *
daa24f8a557b TightVNC original
YU
parents:
diff changeset
41 * Once the client and server are sure that they're happy to talk to one
daa24f8a557b TightVNC original
YU
parents:
diff changeset
42 * another, the client sends an initialisation message. At present this
daa24f8a557b TightVNC original
YU
parents:
diff changeset
43 * message onl@!,@!,y consists of a boolean indicating whether the server should try
daa24f8a557b TightVNC original
YU
parents:
diff changeset
44 * to share the desktop by leaving other clients connected, or give exclusive
daa24f8a557b TightVNC original
YU
parents:
diff changeset
45 * access to this client by disconnecting all other clients.
daa24f8a557b TightVNC original
YU
parents:
diff changeset
46 *
daa24f8a557b TightVNC original
YU
parents:
diff changeset
47 * 1 - U8 - shared-flag
daa24f8a557b TightVNC original
YU
parents:
diff changeset
48 *
daa24f8a557b TightVNC original
YU
parents:
diff changeset
49 * Shared-flag is non-zero (true) if the server should try to share the desktop by leaving
daa24f8a557b TightVNC original
YU
parents:
diff changeset
50 * other clients connected, zero (false) if it should give exclusive access to this client by
daa24f8a557b TightVNC original
YU
parents:
diff changeset
51 * disconnecting all other clients.
daa24f8a557b TightVNC original
YU
parents:
diff changeset
52 *
daa24f8a557b TightVNC original
YU
parents:
diff changeset
53 * ServerInit
daa24f8a557b TightVNC original
YU
parents:
diff changeset
54 *
daa24f8a557b TightVNC original
YU
parents:
diff changeset
55 * After receiving the ClientInit message, the server sends a ServerInit message. This
daa24f8a557b TightVNC original
YU
parents:
diff changeset
56 * tells the client the width and height of the server’s framebuffer, its pixel format and the
daa24f8a557b TightVNC original
YU
parents:
diff changeset
57 * name associated with the desktop.
daa24f8a557b TightVNC original
YU
parents:
diff changeset
58 */
daa24f8a557b TightVNC original
YU
parents:
diff changeset
59 public class InitState extends ProtocolState {
daa24f8a557b TightVNC original
YU
parents:
diff changeset
60
daa24f8a557b TightVNC original
YU
parents:
diff changeset
61 public InitState(ProtocolContext context) {
daa24f8a557b TightVNC original
YU
parents:
diff changeset
62 super(context);
daa24f8a557b TightVNC original
YU
parents:
diff changeset
63 }
daa24f8a557b TightVNC original
YU
parents:
diff changeset
64
daa24f8a557b TightVNC original
YU
parents:
diff changeset
65 @Override
daa24f8a557b TightVNC original
YU
parents:
diff changeset
66 public boolean next() throws UnsupportedProtocolVersionException, TransportException,
daa24f8a557b TightVNC original
YU
parents:
diff changeset
67 UnsupportedSecurityTypeException, AuthenticationFailedException, FatalException {
daa24f8a557b TightVNC original
YU
parents:
diff changeset
68 clientAndServerInit();
daa24f8a557b TightVNC original
YU
parents:
diff changeset
69 return false;
daa24f8a557b TightVNC original
YU
parents:
diff changeset
70 }
daa24f8a557b TightVNC original
YU
parents:
diff changeset
71
daa24f8a557b TightVNC original
YU
parents:
diff changeset
72 protected void clientAndServerInit() throws TransportException {
daa24f8a557b TightVNC original
YU
parents:
diff changeset
73 ServerInitMessage serverInitMessage = getServerInitMessage();
daa24f8a557b TightVNC original
YU
parents:
diff changeset
74 ProtocolSettings settings = context.getSettings();
daa24f8a557b TightVNC original
YU
parents:
diff changeset
75 settings.enableAllEncodingCaps();
daa24f8a557b TightVNC original
YU
parents:
diff changeset
76 completeContextData(serverInitMessage);
daa24f8a557b TightVNC original
YU
parents:
diff changeset
77 }
daa24f8a557b TightVNC original
YU
parents:
diff changeset
78
daa24f8a557b TightVNC original
YU
parents:
diff changeset
79 protected void completeContextData(ServerInitMessage serverInitMessage) {
daa24f8a557b TightVNC original
YU
parents:
diff changeset
80 context.setPixelFormat(serverInitMessage.getPixelFormat());
daa24f8a557b TightVNC original
YU
parents:
diff changeset
81 context.setFbWidth(serverInitMessage.getFrameBufferWidth());
daa24f8a557b TightVNC original
YU
parents:
diff changeset
82 context.setFbHeight(serverInitMessage.getFrameBufferHeight());
daa24f8a557b TightVNC original
YU
parents:
diff changeset
83 context.setRemoteDesktopName(serverInitMessage.getName());
daa24f8a557b TightVNC original
YU
parents:
diff changeset
84 Logger.getLogger(getClass().getName()).fine(serverInitMessage.toString());
daa24f8a557b TightVNC original
YU
parents:
diff changeset
85 }
daa24f8a557b TightVNC original
YU
parents:
diff changeset
86
daa24f8a557b TightVNC original
YU
parents:
diff changeset
87 protected ServerInitMessage getServerInitMessage() throws TransportException {
daa24f8a557b TightVNC original
YU
parents:
diff changeset
88 writer.write(context.getSettings().getSharedFlag());
daa24f8a557b TightVNC original
YU
parents:
diff changeset
89 return new ServerInitMessage(reader);
daa24f8a557b TightVNC original
YU
parents:
diff changeset
90 }
daa24f8a557b TightVNC original
YU
parents:
diff changeset
91
daa24f8a557b TightVNC original
YU
parents:
diff changeset
92
daa24f8a557b TightVNC original
YU
parents:
diff changeset
93 }