blob: b4104ea749e7e7621f4ef1f44d1853cdd13d8ec2 [file] [log] [blame]
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Pierre Ossman615d16b2019-05-03 10:53:06 +02002 * Copyright 2009-2019 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 */
19
20/////////////////////////////////////////////////////////////////////////////
21
22// SDesktop is an interface implemented by back-ends, on which callbacks are
23// made by the VNCServer as appropriate for pointer and keyboard events, etc.
24// SDesktop objects are always created before the VNCServer - the SDesktop
25// will be passed a pointer to the VNCServer in the start() call. If a more
26// implementation-specific pointer to the VNCServer is required then this
27// can be provided to the SDesktop via an implementation-specific method.
28//
29// An SDesktop usually has an associated PixelBuffer which it tells the
30// VNCServer via the VNCServer's setPixelBuffer() method. It can do this at
31// any time, but the PixelBuffer MUST be valid by the time the call to start()
32// returns. The PixelBuffer may be set to null again if desired when stop() is
33// called. Note that start() and stop() are guaranteed to be called
34// alternately; there should never be two calls to start() without an
35// intervening stop() and vice-versa.
36//
37
38#ifndef __RFB_SDESKTOP_H__
39#define __RFB_SDESKTOP_H__
40
41#include <rfb/PixelBuffer.h>
42#include <rfb/VNCServer.h>
43#include <rfb/InputHandler.h>
44#include <rfb/Exception.h>
Pierre Ossman04e62db2009-03-23 16:57:07 +000045#include <rfb/screenTypes.h>
Steve Kondik0c81bbb2017-07-10 08:56:00 -070046#include <rfb/util.h>
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000047
Pierre Ossmaneef6c9a2018-10-05 17:11:25 +020048namespace network { class Socket; }
49
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000050namespace rfb {
51
52 class VNCServer;
53
54 class SDesktop : public InputHandler {
55 public:
56 // start() is called by the server when the first client authenticates
57 // successfully, and can be used to begin any expensive tasks which are not
58 // needed when there are no clients. A valid PixelBuffer must have been
59 // set via the VNCServer's setPixelBuffer() method by the time this call
60 // returns.
61
Pierre Ossmaneef6c9a2018-10-05 17:11:25 +020062 virtual void start(VNCServer* vs) = 0;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000063
64 // stop() is called by the server when there are no longer any
65 // authenticated clients, and therefore the desktop can cease any
66 // expensive tasks. No further calls to the VNCServer passed to start()
67 // can be made once stop has returned.
68
Pierre Ossmaneef6c9a2018-10-05 17:11:25 +020069 virtual void stop() = 0;
70
71 // queryConnection() is called when a connection has been
72 // successfully authenticated. The sock and userName arguments
73 // identify the socket and the name of the authenticated user, if
74 // any. At some point later VNCServer::approveConnection() should
75 // be called to either accept or reject the client.
76 virtual void queryConnection(network::Socket* sock,
77 const char* userName) = 0;
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000078
Pierre Ossman10688ef2018-09-29 11:24:19 +020079 // terminate() is called by the server when it wishes to terminate
80 // itself, e.g. because it was configured to terminate when no one is
81 // using it.
82
83 virtual void terminate() = 0;
84
Pierre Ossman04e62db2009-03-23 16:57:07 +000085 // setScreenLayout() requests to reconfigure the framebuffer and/or
86 // the layout of screens.
Steve Kondik0c81bbb2017-07-10 08:56:00 -070087 virtual unsigned int setScreenLayout(int __unused_attr fb_width,
88 int __unused_attr fb_height,
89 const ScreenSet& __unused_attr layout) {
Pierre Ossman04e62db2009-03-23 16:57:07 +000090 return resultProhibited;
91 }
92
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +000093 // InputHandler interface
94 // pointerEvent(), keyEvent() and clientCutText() are called in response to
95 // the relevant RFB protocol messages from clients.
96 // See InputHandler for method signatures.
Pierre Ossman615d16b2019-05-03 10:53:06 +020097
98 // handleClipboardRequest() is called whenever a client requests
99 // the server to send over its clipboard data. It will only be
100 // called after the server has first announced a clipboard change
101 // via VNCServer::announceClipboard().
102 virtual void handleClipboardRequest() {}
103
104 // handleClipboardAnnounce() is called to indicate a change in the
105 // clipboard on a client. Call VNCServer::requestClipboard() to
106 // access the actual data.
107 virtual void handleClipboardAnnounce(bool __unused_attr available) {}
108
109 // handleClipboardData() is called when a client has sent over
110 // the clipboard data as a result of a previous call to
111 // VNCServer::requestClipboard(). Note that this function might
112 // never be called if the clipboard data was no longer available
113 // when the client received the request.
114 virtual void handleClipboardData(const char* __unused_attr data) {}
115
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000116 protected:
117 virtual ~SDesktop() {}
118 };
119
120 // -=- SStaticDesktop
121 // Trivial implementation of the SDesktop interface, which provides
122 // dummy input handlers and event processing routine, and exports
123 // a plain black desktop of the specified format.
124 class SStaticDesktop : public SDesktop {
125 public:
126 SStaticDesktop(const Point& size) : server(0), buffer(0) {
127 PixelFormat pf;
Pierre Ossman56f99d62015-06-05 12:57:02 +0200128 const rdr::U8 black[4] = { 0, 0, 0, 0 };
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000129 buffer = new ManagedPixelBuffer(pf, size.x, size.y);
Pierre Ossman56f99d62015-06-05 12:57:02 +0200130 if (buffer)
131 buffer->fillRect(buffer->getRect(), black);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000132 }
133 SStaticDesktop(const Point& size, const PixelFormat& pf) : buffer(0) {
Pierre Ossman56f99d62015-06-05 12:57:02 +0200134 const rdr::U8 black[4] = { 0, 0, 0, 0 };
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000135 buffer = new ManagedPixelBuffer(pf, size.x, size.y);
Pierre Ossman56f99d62015-06-05 12:57:02 +0200136 if (buffer)
137 buffer->fillRect(buffer->getRect(), black);
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000138 }
139 virtual ~SStaticDesktop() {
140 if (buffer) delete buffer;
141 }
142
143 virtual void start(VNCServer* vs) {
144 server = vs;
145 server->setPixelBuffer(buffer);
146 }
147 virtual void stop() {
148 server->setPixelBuffer(0);
149 server = 0;
150 }
Pierre Ossmaneef6c9a2018-10-05 17:11:25 +0200151 virtual void queryConnection(network::Socket* sock,
152 const char* userName) {
153 server->approveConnection(sock, true, NULL);
154 }
Constantin Kaplinskya2adc8d2006-05-25 05:01:55 +0000155
156 protected:
157 VNCServer* server;
158 ManagedPixelBuffer* buffer;
159 };
160
161};
162
163#endif // __RFB_SDESKTOP_H__