blob: 2939aa10869e5b9d2e2863478dab5e5e7a509e72 [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 <stdio.h>
19#include <rdr/InStream.h>
20#include <rfb/Exception.h>
21#include <rfb/util.h>
22#include <rfb/SMsgHandler.h>
23#include <rfb/SMsgReader.h>
24
25using namespace rfb;
26
27SMsgReader::SMsgReader(SMsgHandler* handler_, rdr::InStream* is_)
28 : handler(handler_), is(is_)
29{
30}
31
32SMsgReader::~SMsgReader()
33{
34}
35
36void SMsgReader::endMsg()
37{
38}
39
40void SMsgReader::readSetPixelFormat()
41{
42 is->skip(3);
43 PixelFormat pf;
44 pf.read(is);
45 endMsg();
46 handler->setPixelFormat(pf);
47}
48
49void SMsgReader::readSetEncodings()
50{
51 is->skip(1);
52 int nEncodings = is->readU16();
53 rdr::U32* encodings = new rdr::U32[nEncodings];
54 for (int i = 0; i < nEncodings; i++)
55 encodings[i] = is->readU32();
56 endMsg();
57 handler->setEncodings(nEncodings, encodings);
58 delete [] encodings;
59}
60
61void SMsgReader::readFramebufferUpdateRequest()
62{
63 bool inc = is->readU8();
64 int x = is->readU16();
65 int y = is->readU16();
66 int w = is->readU16();
67 int h = is->readU16();
68 endMsg();
69 handler->framebufferUpdateRequest(Rect(x, y, x+w, y+h), inc);
70}
71
72void SMsgReader::readKeyEvent()
73{
74 bool down = is->readU8();
75 is->skip(2);
76 rdr::U32 key = is->readU32();
77 endMsg();
78 handler->keyEvent(key, down);
79}
80
81void SMsgReader::readPointerEvent()
82{
83 int mask = is->readU8();
84 int x = is->readU16();
85 int y = is->readU16();
86 endMsg();
87 handler->pointerEvent(x, y, mask);
88}
89
90
91void SMsgReader::readClientCutText()
92{
93 is->skip(3);
94 int len = is->readU32();
95 if (len > 256*1024) {
96 is->skip(len);
97 fprintf(stderr,"cut text too long (%d bytes) - ignoring\n",len);
98 return;
99 }
100 CharArray ca(len+1);
101 ca.buf[len] = 0;
102 is->readBytes(ca.buf, len);
103 endMsg();
104 handler->clientCutText(ca.buf, len);
105}