Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
Pierre Ossman | 615d16b | 2019-05-03 10:53:06 +0200 | [diff] [blame] | 2 | * Copyright 2009-2019 Pierre Ossman for Cendio AB |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 3 | * |
| 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 Ossman | 04e62db | 2009-03-23 16:57:07 +0000 | [diff] [blame] | 45 | #include <rfb/screenTypes.h> |
Steve Kondik | 0c81bbb | 2017-07-10 08:56:00 -0700 | [diff] [blame] | 46 | #include <rfb/util.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 47 | |
Pierre Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 48 | namespace network { class Socket; } |
| 49 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 50 | namespace 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 Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 62 | virtual void start(VNCServer* vs) = 0; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 63 | |
| 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 Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 69 | 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 Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 78 | |
Pierre Ossman | 10688ef | 2018-09-29 11:24:19 +0200 | [diff] [blame] | 79 | // 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 Ossman | 04e62db | 2009-03-23 16:57:07 +0000 | [diff] [blame] | 85 | // setScreenLayout() requests to reconfigure the framebuffer and/or |
| 86 | // the layout of screens. |
Steve Kondik | 0c81bbb | 2017-07-10 08:56:00 -0700 | [diff] [blame] | 87 | virtual unsigned int setScreenLayout(int __unused_attr fb_width, |
| 88 | int __unused_attr fb_height, |
| 89 | const ScreenSet& __unused_attr layout) { |
Pierre Ossman | 04e62db | 2009-03-23 16:57:07 +0000 | [diff] [blame] | 90 | return resultProhibited; |
| 91 | } |
| 92 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 93 | // 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 Ossman | 615d16b | 2019-05-03 10:53:06 +0200 | [diff] [blame] | 97 | |
| 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 Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 116 | 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 Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 128 | const rdr::U8 black[4] = { 0, 0, 0, 0 }; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 129 | buffer = new ManagedPixelBuffer(pf, size.x, size.y); |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 130 | if (buffer) |
| 131 | buffer->fillRect(buffer->getRect(), black); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 132 | } |
| 133 | SStaticDesktop(const Point& size, const PixelFormat& pf) : buffer(0) { |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 134 | const rdr::U8 black[4] = { 0, 0, 0, 0 }; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 135 | buffer = new ManagedPixelBuffer(pf, size.x, size.y); |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 136 | if (buffer) |
| 137 | buffer->fillRect(buffer->getRect(), black); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 138 | } |
| 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 Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 151 | virtual void queryConnection(network::Socket* sock, |
Steve Kondik | c731da1 | 2019-09-06 13:27:47 -0700 | [diff] [blame^] | 152 | __unused_attr const char* userName) { |
Pierre Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 153 | server->approveConnection(sock, true, NULL); |
| 154 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 155 | |
| 156 | protected: |
| 157 | VNCServer* server; |
| 158 | ManagedPixelBuffer* buffer; |
| 159 | }; |
| 160 | |
| 161 | }; |
| 162 | |
| 163 | #endif // __RFB_SDESKTOP_H__ |