blob: ab3680a943c64fd2d0c849c839ec8048cbcc6a16 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossmanc754cce2011-11-14 15:44:11 +00002 * Copyright 2009-2011 Pierre Ossman for Cendio AB
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +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#include <rdr/OutStream.h>
20#include <rfb/msgTypes.h>
Pierre Ossmanc754cce2011-11-14 15:44:11 +000021#include <rfb/fenceTypes.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000022#include <rfb/Exception.h>
23#include <rfb/ConnParams.h>
24#include <rfb/CMsgWriterV3.h>
25
26using namespace rfb;
27
28CMsgWriterV3::CMsgWriterV3(ConnParams* cp, rdr::OutStream* os)
29 : CMsgWriter(cp, os)
30{
31}
32
33CMsgWriterV3::~CMsgWriterV3()
34{
35}
36
37void CMsgWriterV3::writeClientInit(bool shared)
38{
39 os->writeU8(shared);
40 endMsg();
41}
42
43void CMsgWriterV3::startMsg(int type)
44{
45 os->writeU8(type);
46}
47
48void CMsgWriterV3::endMsg()
49{
50 os->flush();
51}
Pierre Ossmane7a41d52009-03-23 16:48:35 +000052
53void CMsgWriterV3::writeSetDesktopSize(int width, int height,
54 const ScreenSet& layout)
55{
56 if (!cp->supportsSetDesktopSize)
57 throw Exception("Server does not support SetDesktopSize");
58
59 startMsg(msgTypeSetDesktopSize);
60 os->pad(1);
61
62 os->writeU16(width);
63 os->writeU16(height);
64
65 os->writeU8(layout.num_screens());
66 os->pad(1);
67
68 ScreenSet::const_iterator iter;
69 for (iter = layout.begin();iter != layout.end();++iter) {
70 os->writeU32(iter->id);
71 os->writeU16(iter->dimensions.tl.x);
72 os->writeU16(iter->dimensions.tl.y);
73 os->writeU16(iter->dimensions.width());
74 os->writeU16(iter->dimensions.height());
75 os->writeU32(iter->flags);
76 }
77
78 endMsg();
79}
Pierre Ossmanc754cce2011-11-14 15:44:11 +000080
81void CMsgWriterV3::writeFence(rdr::U32 flags, unsigned len, const char data[])
82{
83 if (!cp->supportsFence)
84 throw Exception("Server does not support fences");
85 if (len > 64)
86 throw Exception("Too large fence payload");
87 if ((flags & ~fenceFlagsSupported) != 0)
88 throw Exception("Unknown fence flags");
89
90 startMsg(msgTypeClientFence);
91 os->pad(3);
92
93 os->writeU32(flags);
94
95 os->writeU8(len);
96 os->writeBytes(data, len);
97
98 endMsg();
99}