Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Pierre Ossman | 49f8822 | 2009-03-20 13:02:50 +0000 | [diff] [blame] | 2 | * Copyright 2009 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 <rfb/PixelFormat.h> |
| 20 | #include <rfb/msgTypes.h> |
| 21 | #include <rfb/Exception.h> |
| 22 | #include <rdr/InStream.h> |
| 23 | #include <rfb/CMsgReaderV3.h> |
| 24 | #include <rfb/CMsgHandler.h> |
| 25 | #include <rfb/util.h> |
Adam Tkac | 20e0d71 | 2008-11-14 14:48:21 +0000 | [diff] [blame] | 26 | #include <stdio.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 27 | |
| 28 | using namespace rfb; |
| 29 | |
| 30 | CMsgReaderV3::CMsgReaderV3(CMsgHandler* handler, rdr::InStream* is) |
| 31 | : CMsgReader(handler, is), nUpdateRectsLeft(0) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | CMsgReaderV3::~CMsgReaderV3() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | void CMsgReaderV3::readServerInit() |
| 40 | { |
| 41 | int width = is->readU16(); |
| 42 | int height = is->readU16(); |
| 43 | handler->setDesktopSize(width, height); |
| 44 | PixelFormat pf; |
| 45 | pf.read(is); |
| 46 | handler->setPixelFormat(pf); |
| 47 | CharArray name(is->readString()); |
| 48 | handler->setName(name.buf); |
| 49 | handler->serverInit(); |
| 50 | } |
| 51 | |
| 52 | void CMsgReaderV3::readMsg() |
| 53 | { |
| 54 | if (nUpdateRectsLeft == 0) { |
| 55 | |
| 56 | int type = is->readU8(); |
| 57 | switch (type) { |
| 58 | case msgTypeFramebufferUpdate: readFramebufferUpdate(); break; |
| 59 | case msgTypeSetColourMapEntries: readSetColourMapEntries(); break; |
| 60 | case msgTypeBell: readBell(); break; |
| 61 | case msgTypeServerCutText: readServerCutText(); break; |
| 62 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 63 | default: |
| 64 | fprintf(stderr, "unknown message type %d\n", type); |
| 65 | throw Exception("unknown message type"); |
| 66 | } |
| 67 | |
| 68 | } else { |
| 69 | |
| 70 | int x = is->readU16(); |
| 71 | int y = is->readU16(); |
| 72 | int w = is->readU16(); |
| 73 | int h = is->readU16(); |
| 74 | unsigned int encoding = is->readU32(); |
| 75 | |
| 76 | switch (encoding) { |
| 77 | case pseudoEncodingDesktopSize: |
| 78 | handler->setDesktopSize(w, h); |
| 79 | break; |
Pierre Ossman | 49f8822 | 2009-03-20 13:02:50 +0000 | [diff] [blame] | 80 | case pseudoEncodingExtendedDesktopSize: |
| 81 | readExtendedDesktopSize(x, y, w, h); |
| 82 | break; |
Peter Åstrand | c39e078 | 2009-01-15 12:21:42 +0000 | [diff] [blame] | 83 | case pseudoEncodingDesktopName: |
| 84 | readSetDesktopName(x, y, w, h); |
| 85 | break; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 86 | case pseudoEncodingCursor: |
| 87 | readSetCursor(w, h, Point(x,y)); |
| 88 | break; |
| 89 | case pseudoEncodingLastRect: |
| 90 | nUpdateRectsLeft = 1; // this rectangle is the last one |
| 91 | break; |
| 92 | default: |
| 93 | readRect(Rect(x, y, x+w, y+h), encoding); |
| 94 | break; |
| 95 | }; |
| 96 | |
| 97 | nUpdateRectsLeft--; |
| 98 | if (nUpdateRectsLeft == 0) handler->framebufferUpdateEnd(); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | void CMsgReaderV3::readFramebufferUpdate() |
| 103 | { |
| 104 | is->skip(1); |
| 105 | nUpdateRectsLeft = is->readU16(); |
| 106 | handler->framebufferUpdateStart(); |
| 107 | } |
Pierre Ossman | e49a7bf | 2009-03-20 10:02:31 +0000 | [diff] [blame] | 108 | |
| 109 | void CMsgReaderV3::readSetDesktopName(int x, int y, int w, int h) |
| 110 | { |
| 111 | char* name = is->readString(); |
| 112 | |
| 113 | if (x || y || w || h) { |
| 114 | fprintf(stderr, "Ignoring DesktopName rect with non-zero position/size\n"); |
| 115 | } else { |
| 116 | handler->setName(name); |
| 117 | } |
| 118 | |
| 119 | delete [] name; |
| 120 | } |
| 121 | |
Pierre Ossman | 49f8822 | 2009-03-20 13:02:50 +0000 | [diff] [blame] | 122 | void CMsgReaderV3::readExtendedDesktopSize(int x, int y, int w, int h) |
| 123 | { |
| 124 | unsigned int screens; |
| 125 | |
| 126 | screens = is->readU8(); |
| 127 | is->skip(3); |
| 128 | |
| 129 | // XXX: We just ignore screen info right now |
| 130 | is->skip(16 * screens); |
| 131 | |
| 132 | handler->setExtendedDesktopSize(x, y, w, h); |
| 133 | } |
| 134 | |