blob: 8f01f3c2cd016fb14efe3f969769117e55d1f1c5 [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
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +00003 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
DRCc5dc0382011-05-13 21:42:14 +000020package com.tigervnc.rfb;
Constantin Kaplinsky90d8a502008-04-14 09:45:50 +000021
DRCc5dc0382011-05-13 21:42:14 +000022import com.tigervnc.rdr.*;
Brian Hinze7681412011-05-17 21:00:34 +000023import java.util.*;
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000024
DRCc5dc0382011-05-13 21:42:14 +000025public class CMsgWriterV3 extends CMsgWriter {
26
27 public CMsgWriterV3(ConnParams cp_, OutStream os_) { super(cp_, os_); }
28
Brian Hinz28aa3a82012-04-05 02:08:49 +000029 synchronized public void writeClientInit(boolean shared) {
DRCc5dc0382011-05-13 21:42:14 +000030 os.writeU8(shared?1:0);
31 endMsg();
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000032 }
33
Brian Hinz28aa3a82012-04-05 02:08:49 +000034 synchronized public void startMsg(int type) {
DRCc5dc0382011-05-13 21:42:14 +000035 os.writeU8(type);
36 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000037
Brian Hinz28aa3a82012-04-05 02:08:49 +000038 synchronized public void endMsg() {
DRCc5dc0382011-05-13 21:42:14 +000039 os.flush();
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000040 }
Brian Hinze7681412011-05-17 21:00:34 +000041
Brian Hinz28aa3a82012-04-05 02:08:49 +000042 synchronized public void writeSetDesktopSize(int width, int height,
Brian Hinze7681412011-05-17 21:00:34 +000043 ScreenSet layout)
44 {
45 if (!cp.supportsSetDesktopSize)
46 throw new Exception("Server does not support SetDesktopSize");
47
48 startMsg(MsgTypes.msgTypeSetDesktopSize);
49 os.pad(1);
50
51 os.writeU16(width);
52 os.writeU16(height);
53
54 os.writeU8(layout.num_screens());
55 os.pad(1);
56
57 for (Iterator iter = layout.screens.iterator(); iter.hasNext(); ) {
58 Screen refScreen = (Screen)iter.next();
59 os.writeU32(refScreen.id);
60 os.writeU16(refScreen.dimensions.tl.x);
61 os.writeU16(refScreen.dimensions.tl.y);
62 os.writeU16(refScreen.dimensions.width());
63 os.writeU16(refScreen.dimensions.height());
64 os.writeU32(refScreen.flags);
65 }
66
67 endMsg();
68 }
Brian Hinzaf15db22012-02-12 20:44:29 +000069
Brian Hinz28aa3a82012-04-05 02:08:49 +000070 synchronized public void writeFence(int flags, int len, byte[] data)
Brian Hinzaf15db22012-02-12 20:44:29 +000071 {
72 if (!cp.supportsFence)
73 throw new Exception("Server does not support fences");
74 if (len > 64)
75 throw new Exception("Too large fence payload");
76 if ((flags & ~fenceTypes.fenceFlagsSupported) != 0)
77 throw new Exception("Unknown fence flags");
78
79 startMsg(MsgTypes.msgTypeClientFence);
80 os.pad(3);
81
82 os.writeU32(flags);
83
84 os.writeU8(len);
85 os.writeBytes(data, 0, len);
86
87 endMsg();
88 }
89
Brian Hinz28aa3a82012-04-05 02:08:49 +000090 synchronized public void writeEnableContinuousUpdates(boolean enable,
Brian Hinzaf15db22012-02-12 20:44:29 +000091 int x, int y, int w, int h)
92 {
93 if (!cp.supportsContinuousUpdates)
94 throw new Exception("Server does not support continuous updates");
95
96 startMsg(MsgTypes.msgTypeEnableContinuousUpdates);
97
98 os.writeU8((enable?1:0));
99
100 os.writeU16(x);
101 os.writeU16(y);
102 os.writeU16(w);
103 os.writeU16(h);
104
105 endMsg();
106 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +0000107}