Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Pierre Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 2 | * Copyright 2009-2011 Pierre Ossman for Cendio AB |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 3 | * |
| 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 Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 21 | #include <rfb/fenceTypes.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 22 | #include <rfb/Exception.h> |
| 23 | #include <rfb/ConnParams.h> |
| 24 | #include <rfb/CMsgWriterV3.h> |
| 25 | |
| 26 | using namespace rfb; |
| 27 | |
| 28 | CMsgWriterV3::CMsgWriterV3(ConnParams* cp, rdr::OutStream* os) |
| 29 | : CMsgWriter(cp, os) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | CMsgWriterV3::~CMsgWriterV3() |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | void CMsgWriterV3::writeClientInit(bool shared) |
| 38 | { |
| 39 | os->writeU8(shared); |
| 40 | endMsg(); |
| 41 | } |
| 42 | |
| 43 | void CMsgWriterV3::startMsg(int type) |
| 44 | { |
| 45 | os->writeU8(type); |
| 46 | } |
| 47 | |
| 48 | void CMsgWriterV3::endMsg() |
| 49 | { |
| 50 | os->flush(); |
| 51 | } |
Pierre Ossman | e7a41d5 | 2009-03-23 16:48:35 +0000 | [diff] [blame] | 52 | |
| 53 | void 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 Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 80 | |
| 81 | void 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 | } |
Pierre Ossman | c898d9a | 2011-11-14 16:22:23 +0000 | [diff] [blame^] | 100 | |
| 101 | void CMsgWriterV3::writeEnableContinuousUpdates(bool enable, |
| 102 | int x, int y, int w, int h) |
| 103 | { |
| 104 | if (!cp->supportsContinuousUpdates) |
| 105 | throw Exception("Server does not support continuous updates"); |
| 106 | |
| 107 | startMsg(msgTypeEnableContinuousUpdates); |
| 108 | |
| 109 | os->writeU8(!!enable); |
| 110 | |
| 111 | os->writeU16(x); |
| 112 | os->writeU16(y); |
| 113 | os->writeU16(w); |
| 114 | os->writeU16(h); |
| 115 | |
| 116 | endMsg(); |
| 117 | } |