blob: 05fd94887f01b39a57a708bc410af704193199c3 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossman49f88222009-03-20 13:02:50 +00002 * Copyright 2009 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 <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 Tkac20e0d712008-11-14 14:48:21 +000026#include <stdio.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000027
28using namespace rfb;
29
30CMsgReaderV3::CMsgReaderV3(CMsgHandler* handler, rdr::InStream* is)
31 : CMsgReader(handler, is), nUpdateRectsLeft(0)
32{
33}
34
35CMsgReaderV3::~CMsgReaderV3()
36{
37}
38
39void 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
52void 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 Kaplinskya2adc8d2006-05-25 05:01:55 +000063 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 Ossman49f88222009-03-20 13:02:50 +000080 case pseudoEncodingExtendedDesktopSize:
81 readExtendedDesktopSize(x, y, w, h);
82 break;
Peter Åstrandc39e0782009-01-15 12:21:42 +000083 case pseudoEncodingDesktopName:
84 readSetDesktopName(x, y, w, h);
85 break;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000086 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
102void CMsgReaderV3::readFramebufferUpdate()
103{
104 is->skip(1);
105 nUpdateRectsLeft = is->readU16();
106 handler->framebufferUpdateStart();
107}
Pierre Ossmane49a7bf2009-03-20 10:02:31 +0000108
109void 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 Ossman49f88222009-03-20 13:02:50 +0000122void 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