blob: eddeccf05491a6a6b022d06bde0ac2da0bd28ee1 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossmanc754cce2011-11-14 15:44:11 +00002 * Copyright 2009-2011 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 */
Adam Tkac20e0d712008-11-14 14:48:21 +000019
20#include <stdio.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000021#include <rfb/PixelFormat.h>
22#include <rfb/msgTypes.h>
23#include <rfb/Exception.h>
24#include <rdr/InStream.h>
25#include <rfb/SMsgReaderV3.h>
26#include <rfb/SMsgHandler.h>
Pierre Ossman34bb0612009-03-21 21:16:14 +000027#include <rfb/ScreenSet.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000028
29using namespace rfb;
30
31SMsgReaderV3::SMsgReaderV3(SMsgHandler* handler, rdr::InStream* is)
32 : SMsgReader(handler, is)
33{
34}
35
36SMsgReaderV3::~SMsgReaderV3()
37{
38}
39
40void SMsgReaderV3::readClientInit()
41{
42 bool shared = is->readU8();
43 handler->clientInit(shared);
44}
45
46void SMsgReaderV3::readMsg()
47{
48 int msgType = is->readU8();
49 switch (msgType) {
50 case msgTypeSetPixelFormat: readSetPixelFormat(); break;
51 case msgTypeSetEncodings: readSetEncodings(); break;
52 case msgTypeFramebufferUpdateRequest: readFramebufferUpdateRequest(); break;
53 case msgTypeKeyEvent: readKeyEvent(); break;
54 case msgTypePointerEvent: readPointerEvent(); break;
55 case msgTypeClientCutText: readClientCutText(); break;
Pierre Ossmanc5e25602009-03-20 12:59:05 +000056 case msgTypeSetDesktopSize: readSetDesktopSize(); break;
Pierre Ossmanc754cce2011-11-14 15:44:11 +000057 case msgTypeClientFence: readFence(); break;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000058
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000059 default:
60 fprintf(stderr, "unknown message type %d\n", msgType);
61 throw Exception("unknown message type");
62 }
63}
Pierre Ossmanc5e25602009-03-20 12:59:05 +000064
65void SMsgReaderV3::readSetDesktopSize()
66{
67 int width, height;
68 int screens, i;
Pierre Ossman34bb0612009-03-21 21:16:14 +000069 rdr::U32 id, flags;
70 int sx, sy, sw, sh;
71 ScreenSet layout;
Pierre Ossmanc5e25602009-03-20 12:59:05 +000072
73 is->skip(1);
74
75 width = is->readU16();
76 height = is->readU16();
77
78 screens = is->readU8();
79 is->skip(1);
80
Pierre Ossman34bb0612009-03-21 21:16:14 +000081 for (i = 0;i < screens;i++) {
82 id = is->readU32();
83 sx = is->readU16();
84 sy = is->readU16();
85 sw = is->readU16();
86 sh = is->readU16();
87 flags = is->readU32();
Pierre Ossmanc5e25602009-03-20 12:59:05 +000088
Pierre Ossman34bb0612009-03-21 21:16:14 +000089 layout.add_screen(Screen(id, sx, sy, sw, sh, flags));
90 }
91
92 handler->setDesktopSize(width, height, layout);
Pierre Ossmanc5e25602009-03-20 12:59:05 +000093}
94
Pierre Ossmanc754cce2011-11-14 15:44:11 +000095void SMsgReaderV3::readFence()
96{
97 rdr::U32 flags;
98 rdr::U8 len;
99 char data[64];
100
101 is->skip(3);
102
103 flags = is->readU32();
104
105 len = is->readU8();
106 if (len > sizeof(data)) {
107 fprintf(stderr, "Ignoring fence with too large payload\n");
108 is->skip(len);
109 return;
110 }
111
112 is->readBytes(data, len);
113
114 handler->fence(flags, len, data);
115}