blob: a730698d167c617f13db7a7e48b98dae03894ef3 [file] [log] [blame]
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Brian Hinzaf15db22012-02-12 20:44:29 +00002 * Copyright 2009-2011 Pierre Ossman for Cendio AB
Brian Hinzb213da62012-04-11 22:00:55 +00003 * Copyright (C) 2011 Brian P. Hinz
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +00004 *
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; if not, write to the Free Software
Brian Hinzb213da62012-04-11 22:00:55 +000017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000018 * USA.
19 */
20
DRCc5dc0382011-05-13 21:42:14 +000021package com.tigervnc.rfb;
Constantin Kaplinsky90d8a502008-04-14 09:45:50 +000022
DRCc5dc0382011-05-13 21:42:14 +000023import com.tigervnc.rdr.*;
Brian Hinze7681412011-05-17 21:00:34 +000024import java.util.*;
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000025
DRCc5dc0382011-05-13 21:42:14 +000026public class CMsgWriterV3 extends CMsgWriter {
27
28 public CMsgWriterV3(ConnParams cp_, OutStream os_) { super(cp_, os_); }
29
Brian Hinz28aa3a82012-04-05 02:08:49 +000030 synchronized public void writeClientInit(boolean shared) {
DRCc5dc0382011-05-13 21:42:14 +000031 os.writeU8(shared?1:0);
32 endMsg();
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000033 }
34
Brian Hinz28aa3a82012-04-05 02:08:49 +000035 synchronized public void startMsg(int type) {
DRCc5dc0382011-05-13 21:42:14 +000036 os.writeU8(type);
37 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000038
Brian Hinz28aa3a82012-04-05 02:08:49 +000039 synchronized public void endMsg() {
DRCc5dc0382011-05-13 21:42:14 +000040 os.flush();
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000041 }
Brian Hinze7681412011-05-17 21:00:34 +000042
Brian Hinz28aa3a82012-04-05 02:08:49 +000043 synchronized public void writeSetDesktopSize(int width, int height,
Brian Hinze7681412011-05-17 21:00:34 +000044 ScreenSet layout)
45 {
46 if (!cp.supportsSetDesktopSize)
47 throw new Exception("Server does not support SetDesktopSize");
48
49 startMsg(MsgTypes.msgTypeSetDesktopSize);
50 os.pad(1);
51
52 os.writeU16(width);
53 os.writeU16(height);
54
55 os.writeU8(layout.num_screens());
56 os.pad(1);
57
Brian Hinzd93a26d2012-12-14 22:40:02 +000058 for (Iterator<Screen> iter = layout.screens.iterator(); iter.hasNext(); ) {
Brian Hinze7681412011-05-17 21:00:34 +000059 Screen refScreen = (Screen)iter.next();
60 os.writeU32(refScreen.id);
61 os.writeU16(refScreen.dimensions.tl.x);
62 os.writeU16(refScreen.dimensions.tl.y);
63 os.writeU16(refScreen.dimensions.width());
64 os.writeU16(refScreen.dimensions.height());
65 os.writeU32(refScreen.flags);
66 }
67
68 endMsg();
69 }
Brian Hinzaf15db22012-02-12 20:44:29 +000070
Brian Hinz28aa3a82012-04-05 02:08:49 +000071 synchronized public void writeFence(int flags, int len, byte[] data)
Brian Hinzaf15db22012-02-12 20:44:29 +000072 {
73 if (!cp.supportsFence)
74 throw new Exception("Server does not support fences");
75 if (len > 64)
76 throw new Exception("Too large fence payload");
77 if ((flags & ~fenceTypes.fenceFlagsSupported) != 0)
78 throw new Exception("Unknown fence flags");
79
80 startMsg(MsgTypes.msgTypeClientFence);
81 os.pad(3);
82
83 os.writeU32(flags);
84
85 os.writeU8(len);
86 os.writeBytes(data, 0, len);
87
88 endMsg();
89 }
90
Brian Hinz28aa3a82012-04-05 02:08:49 +000091 synchronized public void writeEnableContinuousUpdates(boolean enable,
Brian Hinzaf15db22012-02-12 20:44:29 +000092 int x, int y, int w, int h)
93 {
94 if (!cp.supportsContinuousUpdates)
95 throw new Exception("Server does not support continuous updates");
96
97 startMsg(MsgTypes.msgTypeEnableContinuousUpdates);
98
99 os.writeU8((enable?1:0));
100
101 os.writeU16(x);
102 os.writeU16(y);
103 os.writeU16(w);
104 os.writeU16(h);
105
106 endMsg();
107 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +0000108}