1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
* Copyright 2009-2024 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
/////////////////////////////////////////////////////////////////////////////
// SDesktop is an interface implemented by back-ends, on which callbacks are
// made by the VNCServer as appropriate for pointer and keyboard events, etc.
// SDesktop objects are always created before the VNCServer - the SDesktop
// will be passed a pointer to the VNCServer in the start() call. If a more
// implementation-specific pointer to the VNCServer is required then this
// can be provided to the SDesktop via an implementation-specific method.
//
// An SDesktop usually has an associated PixelBuffer which it tells the
// VNCServer via the VNCServer's setPixelBuffer() method. It can do this at
// any time, but the PixelBuffer MUST be valid by the time the call to start()
// returns. The PixelBuffer may be set to null again if desired when stop() is
// called. Note that start() and stop() are guaranteed to be called
// alternately; there should never be two calls to start() without an
// intervening stop() and vice-versa.
//
#ifndef __RFB_SDESKTOP_H__
#define __RFB_SDESKTOP_H__
#include <rfb/PixelBuffer.h>
#include <rfb/VNCServer.h>
#include <rfb/InputHandler.h>
#include <rfb/screenTypes.h>
namespace network { class Socket; }
namespace rfb {
class SDesktop : public InputHandler {
public:
// init() is called immediately when the VNCServer gets a reference
// to the SDesktop, so that a reverse reference can be set up.
virtual void init(rfb::VNCServer* vs) = 0;
// start() is called by the server when the first client authenticates
// successfully, and can be used to begin any expensive tasks which are not
// needed when there are no clients. A valid PixelBuffer must have been
// set via the VNCServer's setPixelBuffer() method by the time this call
// returns.
virtual void start() {}
// stop() is called by the server when there are no longer any
// authenticated clients, and therefore the desktop can cease any
// expensive tasks.
virtual void stop() {}
// queryConnection() is called when a connection has been
// successfully authenticated. The sock and userName arguments
// identify the socket and the name of the authenticated user, if
// any. At some point later VNCServer::approveConnection() should
// be called to either accept or reject the client.
virtual void queryConnection(network::Socket* sock,
const char* userName) = 0;
// terminate() is called by the server when it wishes to terminate
// itself, e.g. because it was configured to terminate when no one is
// using it.
virtual void terminate() = 0;
// setScreenLayout() requests to reconfigure the framebuffer and/or
// the layout of screens.
virtual unsigned int setScreenLayout(int /*fb_width*/,
int /*fb_height*/,
const ScreenSet& /*layout*/) {
return resultProhibited;
}
// frameTick() is called whenever a frame update has been processed,
// signalling that a good time to render new data
virtual void frameTick(uint64_t msc) { (void)msc; }
// InputHandler interface
// pointerEvent(), keyEvent() and clientCutText() are called in response to
// the relevant RFB protocol messages from clients.
// See InputHandler for method signatures.
// handleClipboardRequest() is called whenever a client requests
// the server to send over its clipboard data. It will only be
// called after the server has first announced a clipboard change
// via VNCServer::announceClipboard().
virtual void handleClipboardRequest() {}
// handleClipboardAnnounce() is called to indicate a change in the
// clipboard on a client. Call VNCServer::requestClipboard() to
// access the actual data.
virtual void handleClipboardAnnounce(bool /*available*/) {}
// handleClipboardData() is called when a client has sent over
// the clipboard data as a result of a previous call to
// VNCServer::requestClipboard(). Note that this function might
// never be called if the clipboard data was no longer available
// when the client received the request.
virtual void handleClipboardData(const char* /*data*/) {}
protected:
virtual ~SDesktop() {}
};
// -=- SStaticDesktop
// Trivial implementation of the SDesktop interface, which provides
// dummy input handlers and event processing routine, and exports
// a plain black desktop of the specified format.
class SStaticDesktop : public SDesktop {
public:
SStaticDesktop(const Point& size)
: server(nullptr), buffer(nullptr)
{
PixelFormat pf;
const uint8_t black[4] = { 0, 0, 0, 0 };
buffer = new ManagedPixelBuffer(pf, size.x, size.y);
if (buffer)
buffer->fillRect(buffer->getRect(), black);
}
SStaticDesktop(const Point& size, const PixelFormat& pf)
: buffer(nullptr)
{
const uint8_t black[4] = { 0, 0, 0, 0 };
buffer = new ManagedPixelBuffer(pf, size.x, size.y);
if (buffer)
buffer->fillRect(buffer->getRect(), black);
}
virtual ~SStaticDesktop() {
if (buffer) delete buffer;
}
virtual void init(VNCServer* vs) {
server = vs;
server->setPixelBuffer(buffer);
}
virtual void queryConnection(network::Socket* sock,
const char* /*userName*/) {
server->approveConnection(sock, true, nullptr);
}
protected:
VNCServer* server;
ManagedPixelBuffer* buffer;
};
};
#endif // __RFB_SDESKTOP_H__
|