1 /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. 2 * Copyright 2009-2019 Pierre Ossman for Cendio AB 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> 45 #include <rfb/screenTypes.h> 46 #include <rfb/util.h> 47 48 namespace network { class Socket; } 49 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 62 virtual void start(VNCServer* vs) = 0; 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 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; 78 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 85 // setScreenLayout() requests to reconfigure the framebuffer and/or 86 // the layout of screens. setScreenLayout(int __unused_attr fb_width,int __unused_attr fb_height,const ScreenSet & __unused_attr layout)87 virtual unsigned int setScreenLayout(int __unused_attr fb_width, 88 int __unused_attr fb_height, 89 const ScreenSet& __unused_attr layout) { 90 return resultProhibited; 91 } 92 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. 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(). handleClipboardRequest()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. handleClipboardAnnounce(bool __unused_attr available)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. handleClipboardData(const char * __unused_attr data)114 virtual void handleClipboardData(const char* __unused_attr data) {} 115 116 protected: ~SDesktop()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: SStaticDesktop(const Point & size)126 SStaticDesktop(const Point& size) : server(0), buffer(0) { 127 PixelFormat pf; 128 const rdr::U8 black[4] = { 0, 0, 0, 0 }; 129 buffer = new ManagedPixelBuffer(pf, size.x, size.y); 130 if (buffer) 131 buffer->fillRect(buffer->getRect(), black); 132 } SStaticDesktop(const Point & size,const PixelFormat & pf)133 SStaticDesktop(const Point& size, const PixelFormat& pf) : buffer(0) { 134 const rdr::U8 black[4] = { 0, 0, 0, 0 }; 135 buffer = new ManagedPixelBuffer(pf, size.x, size.y); 136 if (buffer) 137 buffer->fillRect(buffer->getRect(), black); 138 } ~SStaticDesktop()139 virtual ~SStaticDesktop() { 140 if (buffer) delete buffer; 141 } 142 start(VNCServer * vs)143 virtual void start(VNCServer* vs) { 144 server = vs; 145 server->setPixelBuffer(buffer); 146 } stop()147 virtual void stop() { 148 server->setPixelBuffer(0); 149 server = 0; 150 } queryConnection(network::Socket * sock,const char * userName)151 virtual void queryConnection(network::Socket* sock, 152 const char* userName) { 153 server->approveConnection(sock, true, NULL); 154 } 155 156 protected: 157 VNCServer* server; 158 ManagedPixelBuffer* buffer; 159 }; 160 161 }; 162 163 #endif // __RFB_SDESKTOP_H__ 164