Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | #include <rfb/PixelFormat.h> |
| 19 | #include <rfb/msgTypes.h> |
| 20 | #include <rfb/Exception.h> |
| 21 | #include <rdr/InStream.h> |
| 22 | #include <rfb/CMsgReaderV3.h> |
| 23 | #include <rfb/CMsgHandler.h> |
| 24 | #include <rfb/util.h> |
Adam Tkac | 20e0d71 | 2008-11-14 14:48:21 +0000 | [diff] [blame] | 25 | #include <stdio.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 26 | |
| 27 | using namespace rfb; |
| 28 | |
| 29 | CMsgReaderV3::CMsgReaderV3(CMsgHandler* handler, rdr::InStream* is) |
| 30 | : CMsgReader(handler, is), nUpdateRectsLeft(0) |
| 31 | { |
| 32 | } |
| 33 | |
| 34 | CMsgReaderV3::~CMsgReaderV3() |
| 35 | { |
| 36 | } |
| 37 | |
| 38 | void CMsgReaderV3::readServerInit() |
| 39 | { |
| 40 | int width = is->readU16(); |
| 41 | int height = is->readU16(); |
| 42 | handler->setDesktopSize(width, height); |
| 43 | PixelFormat pf; |
| 44 | pf.read(is); |
| 45 | handler->setPixelFormat(pf); |
| 46 | CharArray name(is->readString()); |
| 47 | handler->setName(name.buf); |
| 48 | handler->serverInit(); |
| 49 | } |
| 50 | |
| 51 | void CMsgReaderV3::readMsg() |
| 52 | { |
| 53 | if (nUpdateRectsLeft == 0) { |
| 54 | |
| 55 | int type = is->readU8(); |
| 56 | switch (type) { |
| 57 | case msgTypeFramebufferUpdate: readFramebufferUpdate(); break; |
| 58 | case msgTypeSetColourMapEntries: readSetColourMapEntries(); break; |
| 59 | case msgTypeBell: readBell(); break; |
| 60 | case msgTypeServerCutText: readServerCutText(); break; |
| 61 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 62 | default: |
| 63 | fprintf(stderr, "unknown message type %d\n", type); |
| 64 | throw Exception("unknown message type"); |
| 65 | } |
| 66 | |
| 67 | } else { |
| 68 | |
| 69 | int x = is->readU16(); |
| 70 | int y = is->readU16(); |
| 71 | int w = is->readU16(); |
| 72 | int h = is->readU16(); |
| 73 | unsigned int encoding = is->readU32(); |
| 74 | |
| 75 | switch (encoding) { |
| 76 | case pseudoEncodingDesktopSize: |
| 77 | handler->setDesktopSize(w, h); |
| 78 | break; |
Peter Åstrand | c39e078 | 2009-01-15 12:21:42 +0000 | [diff] [blame] | 79 | case pseudoEncodingDesktopName: |
| 80 | readSetDesktopName(x, y, w, h); |
| 81 | break; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 82 | case pseudoEncodingCursor: |
| 83 | readSetCursor(w, h, Point(x,y)); |
| 84 | break; |
| 85 | case pseudoEncodingLastRect: |
| 86 | nUpdateRectsLeft = 1; // this rectangle is the last one |
| 87 | break; |
| 88 | default: |
| 89 | readRect(Rect(x, y, x+w, y+h), encoding); |
| 90 | break; |
| 91 | }; |
| 92 | |
| 93 | nUpdateRectsLeft--; |
| 94 | if (nUpdateRectsLeft == 0) handler->framebufferUpdateEnd(); |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | void CMsgReaderV3::readFramebufferUpdate() |
| 99 | { |
| 100 | is->skip(1); |
| 101 | nUpdateRectsLeft = is->readU16(); |
| 102 | handler->framebufferUpdateStart(); |
| 103 | } |