Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2002-2005 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 | |
| 19 | ///////////////////////////////////////////////////////////////////////////// |
| 20 | |
| 21 | // SDesktop is an interface implemented by back-ends, on which callbacks are |
| 22 | // made by the VNCServer as appropriate for pointer and keyboard events, etc. |
| 23 | // SDesktop objects are always created before the VNCServer - the SDesktop |
| 24 | // will be passed a pointer to the VNCServer in the start() call. If a more |
| 25 | // implementation-specific pointer to the VNCServer is required then this |
| 26 | // can be provided to the SDesktop via an implementation-specific method. |
| 27 | // |
| 28 | // An SDesktop usually has an associated PixelBuffer which it tells the |
| 29 | // VNCServer via the VNCServer's setPixelBuffer() method. It can do this at |
| 30 | // any time, but the PixelBuffer MUST be valid by the time the call to start() |
| 31 | // returns. The PixelBuffer may be set to null again if desired when stop() is |
| 32 | // called. Note that start() and stop() are guaranteed to be called |
| 33 | // alternately; there should never be two calls to start() without an |
| 34 | // intervening stop() and vice-versa. |
| 35 | // |
| 36 | |
| 37 | #ifndef __RFB_SDESKTOP_H__ |
| 38 | #define __RFB_SDESKTOP_H__ |
| 39 | |
| 40 | #include <rfb/PixelBuffer.h> |
| 41 | #include <rfb/VNCServer.h> |
| 42 | #include <rfb/InputHandler.h> |
| 43 | #include <rfb/Exception.h> |
Pierre Ossman | 04e62db | 2009-03-23 16:57:07 +0000 | [diff] [blame] | 44 | #include <rfb/screenTypes.h> |
Steve Kondik | 0c81bbb | 2017-07-10 08:56:00 -0700 | [diff] [blame] | 45 | #include <rfb/util.h> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 46 | |
Pierre Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 47 | namespace network { class Socket; } |
| 48 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 49 | namespace rfb { |
| 50 | |
| 51 | class VNCServer; |
| 52 | |
| 53 | class SDesktop : public InputHandler { |
| 54 | public: |
| 55 | // start() is called by the server when the first client authenticates |
| 56 | // successfully, and can be used to begin any expensive tasks which are not |
| 57 | // needed when there are no clients. A valid PixelBuffer must have been |
| 58 | // set via the VNCServer's setPixelBuffer() method by the time this call |
| 59 | // returns. |
| 60 | |
Pierre Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 61 | virtual void start(VNCServer* vs) = 0; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 62 | |
| 63 | // stop() is called by the server when there are no longer any |
| 64 | // authenticated clients, and therefore the desktop can cease any |
| 65 | // expensive tasks. No further calls to the VNCServer passed to start() |
| 66 | // can be made once stop has returned. |
| 67 | |
Pierre Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 68 | virtual void stop() = 0; |
| 69 | |
| 70 | // queryConnection() is called when a connection has been |
| 71 | // successfully authenticated. The sock and userName arguments |
| 72 | // identify the socket and the name of the authenticated user, if |
| 73 | // any. At some point later VNCServer::approveConnection() should |
| 74 | // be called to either accept or reject the client. |
| 75 | virtual void queryConnection(network::Socket* sock, |
| 76 | const char* userName) = 0; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 77 | |
Pierre Ossman | 10688ef | 2018-09-29 11:24:19 +0200 | [diff] [blame] | 78 | // terminate() is called by the server when it wishes to terminate |
| 79 | // itself, e.g. because it was configured to terminate when no one is |
| 80 | // using it. |
| 81 | |
| 82 | virtual void terminate() = 0; |
| 83 | |
Pierre Ossman | 04e62db | 2009-03-23 16:57:07 +0000 | [diff] [blame] | 84 | // setScreenLayout() requests to reconfigure the framebuffer and/or |
| 85 | // the layout of screens. |
Steve Kondik | 0c81bbb | 2017-07-10 08:56:00 -0700 | [diff] [blame] | 86 | virtual unsigned int setScreenLayout(int __unused_attr fb_width, |
| 87 | int __unused_attr fb_height, |
| 88 | const ScreenSet& __unused_attr layout) { |
Pierre Ossman | 04e62db | 2009-03-23 16:57:07 +0000 | [diff] [blame] | 89 | return resultProhibited; |
| 90 | } |
| 91 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 92 | // InputHandler interface |
| 93 | // pointerEvent(), keyEvent() and clientCutText() are called in response to |
| 94 | // the relevant RFB protocol messages from clients. |
| 95 | // See InputHandler for method signatures. |
| 96 | protected: |
| 97 | virtual ~SDesktop() {} |
| 98 | }; |
| 99 | |
| 100 | // -=- SStaticDesktop |
| 101 | // Trivial implementation of the SDesktop interface, which provides |
| 102 | // dummy input handlers and event processing routine, and exports |
| 103 | // a plain black desktop of the specified format. |
| 104 | class SStaticDesktop : public SDesktop { |
| 105 | public: |
| 106 | SStaticDesktop(const Point& size) : server(0), buffer(0) { |
| 107 | PixelFormat pf; |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 108 | const rdr::U8 black[4] = { 0, 0, 0, 0 }; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 109 | buffer = new ManagedPixelBuffer(pf, size.x, size.y); |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 110 | if (buffer) |
| 111 | buffer->fillRect(buffer->getRect(), black); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 112 | } |
| 113 | SStaticDesktop(const Point& size, const PixelFormat& pf) : buffer(0) { |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 114 | const rdr::U8 black[4] = { 0, 0, 0, 0 }; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 115 | buffer = new ManagedPixelBuffer(pf, size.x, size.y); |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 116 | if (buffer) |
| 117 | buffer->fillRect(buffer->getRect(), black); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 118 | } |
| 119 | virtual ~SStaticDesktop() { |
| 120 | if (buffer) delete buffer; |
| 121 | } |
| 122 | |
| 123 | virtual void start(VNCServer* vs) { |
| 124 | server = vs; |
| 125 | server->setPixelBuffer(buffer); |
| 126 | } |
| 127 | virtual void stop() { |
| 128 | server->setPixelBuffer(0); |
| 129 | server = 0; |
| 130 | } |
Pierre Ossman | eef6c9a | 2018-10-05 17:11:25 +0200 | [diff] [blame] | 131 | virtual void queryConnection(network::Socket* sock, |
| 132 | const char* userName) { |
| 133 | server->approveConnection(sock, true, NULL); |
| 134 | } |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 135 | |
| 136 | protected: |
| 137 | VNCServer* server; |
| 138 | ManagedPixelBuffer* buffer; |
| 139 | }; |
| 140 | |
| 141 | }; |
| 142 | |
| 143 | #endif // __RFB_SDESKTOP_H__ |