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 | */ |
Adam Tkac | 20e0d71 | 2008-11-14 14:48:21 +0000 | [diff] [blame] | 19 | |
| 20 | #include <stdio.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 21 | #include <rfb/PixelFormat.h> |
| 22 | #include <rfb/msgTypes.h> |
| 23 | #include <rfb/Exception.h> |
| 24 | #include <rdr/InStream.h> |
| 25 | #include <rfb/SMsgReaderV3.h> |
| 26 | #include <rfb/SMsgHandler.h> |
Pierre Ossman | 34bb061 | 2009-03-21 21:16:14 +0000 | [diff] [blame] | 27 | #include <rfb/ScreenSet.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 28 | |
| 29 | using namespace rfb; |
| 30 | |
| 31 | SMsgReaderV3::SMsgReaderV3(SMsgHandler* handler, rdr::InStream* is) |
| 32 | : SMsgReader(handler, is) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | SMsgReaderV3::~SMsgReaderV3() |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | void SMsgReaderV3::readClientInit() |
| 41 | { |
| 42 | bool shared = is->readU8(); |
| 43 | handler->clientInit(shared); |
| 44 | } |
| 45 | |
| 46 | void SMsgReaderV3::readMsg() |
| 47 | { |
| 48 | int msgType = is->readU8(); |
| 49 | switch (msgType) { |
| 50 | case msgTypeSetPixelFormat: readSetPixelFormat(); break; |
| 51 | case msgTypeSetEncodings: readSetEncodings(); break; |
| 52 | case msgTypeFramebufferUpdateRequest: readFramebufferUpdateRequest(); break; |
| 53 | case msgTypeKeyEvent: readKeyEvent(); break; |
| 54 | case msgTypePointerEvent: readPointerEvent(); break; |
| 55 | case msgTypeClientCutText: readClientCutText(); break; |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 56 | case msgTypeSetDesktopSize: readSetDesktopSize(); break; |
Pierre Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 57 | case msgTypeClientFence: readFence(); break; |
Pierre Ossman | c898d9a | 2011-11-14 16:22:23 +0000 | [diff] [blame^] | 58 | case msgTypeEnableContinuousUpdates: readEnableContinuousUpdates(); break; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 59 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 60 | default: |
| 61 | fprintf(stderr, "unknown message type %d\n", msgType); |
| 62 | throw Exception("unknown message type"); |
| 63 | } |
| 64 | } |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 65 | |
| 66 | void SMsgReaderV3::readSetDesktopSize() |
| 67 | { |
| 68 | int width, height; |
| 69 | int screens, i; |
Pierre Ossman | 34bb061 | 2009-03-21 21:16:14 +0000 | [diff] [blame] | 70 | rdr::U32 id, flags; |
| 71 | int sx, sy, sw, sh; |
| 72 | ScreenSet layout; |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 73 | |
| 74 | is->skip(1); |
| 75 | |
| 76 | width = is->readU16(); |
| 77 | height = is->readU16(); |
| 78 | |
| 79 | screens = is->readU8(); |
| 80 | is->skip(1); |
| 81 | |
Pierre Ossman | 34bb061 | 2009-03-21 21:16:14 +0000 | [diff] [blame] | 82 | for (i = 0;i < screens;i++) { |
| 83 | id = is->readU32(); |
| 84 | sx = is->readU16(); |
| 85 | sy = is->readU16(); |
| 86 | sw = is->readU16(); |
| 87 | sh = is->readU16(); |
| 88 | flags = is->readU32(); |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 89 | |
Pierre Ossman | 34bb061 | 2009-03-21 21:16:14 +0000 | [diff] [blame] | 90 | layout.add_screen(Screen(id, sx, sy, sw, sh, flags)); |
| 91 | } |
| 92 | |
| 93 | handler->setDesktopSize(width, height, layout); |
Pierre Ossman | c5e2560 | 2009-03-20 12:59:05 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Pierre Ossman | c754cce | 2011-11-14 15:44:11 +0000 | [diff] [blame] | 96 | void SMsgReaderV3::readFence() |
| 97 | { |
| 98 | rdr::U32 flags; |
| 99 | rdr::U8 len; |
| 100 | char data[64]; |
| 101 | |
| 102 | is->skip(3); |
| 103 | |
| 104 | flags = is->readU32(); |
| 105 | |
| 106 | len = is->readU8(); |
| 107 | if (len > sizeof(data)) { |
| 108 | fprintf(stderr, "Ignoring fence with too large payload\n"); |
| 109 | is->skip(len); |
| 110 | return; |
| 111 | } |
| 112 | |
| 113 | is->readBytes(data, len); |
| 114 | |
| 115 | handler->fence(flags, len, data); |
| 116 | } |
Pierre Ossman | c898d9a | 2011-11-14 16:22:23 +0000 | [diff] [blame^] | 117 | |
| 118 | void SMsgReaderV3::readEnableContinuousUpdates() |
| 119 | { |
| 120 | bool enable; |
| 121 | int x, y, w, h; |
| 122 | |
| 123 | enable = is->readU8(); |
| 124 | |
| 125 | x = is->readU16(); |
| 126 | y = is->readU16(); |
| 127 | w = is->readU16(); |
| 128 | h = is->readU16(); |
| 129 | |
| 130 | handler->enableContinuousUpdates(enable, x, y, w, h); |
| 131 | } |