blob: b8242a0241a38538528fc1529909dbe2a3d57c7c [file] [log] [blame]
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +00001/* Copyright (C) 2002-2003 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
25using namespace rfb;
26
27CMsgReaderV3::CMsgReaderV3(CMsgHandler* handler, rdr::InStream* is)
28 : CMsgReader(handler, is), nUpdateRectsLeft(0)
29{
30}
31
32CMsgReaderV3::~CMsgReaderV3()
33{
34}
35
36void CMsgReaderV3::readServerInit()
37{
38 int width = is->readU16();
39 int height = is->readU16();
40 handler->setDesktopSize(width, height);
41 PixelFormat pf;
42 pf.read(is);
43 handler->setPixelFormat(pf);
44 char* name = is->readString();
45 handler->setName(name);
46 delete [] name;
47 endMsg();
48 handler->serverInit();
49}
50
51void 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;
Dennis Syrovatsky514555b2005-11-21 14:40:56 +000061 case msgTypeFileListData:
62 handler->processFTMsg(type); break;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +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;
80 case pseudoEncodingCursor:
81 readSetCursor(Point(x, y), Point(w, h));
82 break;
Peter Åstrand462753d2004-11-16 15:23:25 +000083 case pseudoEncodingLastRect:
84 nUpdateRectsLeft = 1; // this rectangle is the last one
85 break;
Constantin Kaplinsky47ed8d32004-10-08 09:43:57 +000086 default:
87 readRect(Rect(x, y, x+w, y+h), encoding);
88 break;
89 };
90
91 nUpdateRectsLeft--;
92 if (nUpdateRectsLeft == 0) handler->framebufferUpdateEnd();
93 }
94}
95
96void CMsgReaderV3::readFramebufferUpdate()
97{
98 is->skip(1);
99 nUpdateRectsLeft = is->readU16();
100 endMsg();
101 handler->framebufferUpdateStart();
102}