blob: d0cfc89f9726fce4fc9da763086f7748c455ead1 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* 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>
25
26using namespace rfb;
27
28CMsgReaderV3::CMsgReaderV3(CMsgHandler* handler, rdr::InStream* is)
29 : CMsgReader(handler, is), nUpdateRectsLeft(0)
30{
31}
32
33CMsgReaderV3::~CMsgReaderV3()
34{
35}
36
37void CMsgReaderV3::readServerInit()
38{
39 int width = is->readU16();
40 int height = is->readU16();
41 handler->setDesktopSize(width, height);
42 PixelFormat pf;
43 pf.read(is);
44 handler->setPixelFormat(pf);
45 CharArray name(is->readString());
46 handler->setName(name.buf);
47 handler->serverInit();
48}
49
50void CMsgReaderV3::readMsg()
51{
52 if (nUpdateRectsLeft == 0) {
53
54 int type = is->readU8();
55 switch (type) {
56 case msgTypeFramebufferUpdate: readFramebufferUpdate(); break;
57 case msgTypeSetColourMapEntries: readSetColourMapEntries(); break;
58 case msgTypeBell: readBell(); break;
59 case msgTypeServerCutText: readServerCutText(); break;
60
61 case msgTypeFileListData:
62 case msgTypeFileDownloadData:
63 case msgTypeFileUploadCancel:
64 case msgTypeFileDownloadFailed:
65 case msgTypeFileDirSizeData:
66 case msgTypeFileLastRequestFailed:
67 handler->processFTMsg(type); break;
68
69 default:
70 fprintf(stderr, "unknown message type %d\n", type);
71 throw Exception("unknown message type");
72 }
73
74 } else {
75
76 int x = is->readU16();
77 int y = is->readU16();
78 int w = is->readU16();
79 int h = is->readU16();
80 unsigned int encoding = is->readU32();
81
82 switch (encoding) {
83 case pseudoEncodingDesktopSize:
84 handler->setDesktopSize(w, h);
85 break;
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
102void CMsgReaderV3::readFramebufferUpdate()
103{
104 is->skip(1);
105 nUpdateRectsLeft = is->readU16();
106 handler->framebufferUpdateStart();
107}