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> |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 45 | |
| 46 | namespace rfb { |
| 47 | |
| 48 | class VNCServer; |
| 49 | |
| 50 | class SDesktop : public InputHandler { |
| 51 | public: |
| 52 | // start() is called by the server when the first client authenticates |
| 53 | // successfully, and can be used to begin any expensive tasks which are not |
| 54 | // needed when there are no clients. A valid PixelBuffer must have been |
| 55 | // set via the VNCServer's setPixelBuffer() method by the time this call |
| 56 | // returns. |
| 57 | |
| 58 | virtual void start(VNCServer* vs) {} |
| 59 | |
| 60 | // stop() is called by the server when there are no longer any |
| 61 | // authenticated clients, and therefore the desktop can cease any |
| 62 | // expensive tasks. No further calls to the VNCServer passed to start() |
| 63 | // can be made once stop has returned. |
| 64 | |
| 65 | virtual void stop() {} |
| 66 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 67 | // getFbSize() returns the current dimensions of the framebuffer. |
| 68 | // This can be called even while the SDesktop is not start()ed. |
| 69 | |
| 70 | virtual Point getFbSize() = 0; |
| 71 | |
Pierre Ossman | 04e62db | 2009-03-23 16:57:07 +0000 | [diff] [blame] | 72 | // setScreenLayout() requests to reconfigure the framebuffer and/or |
| 73 | // the layout of screens. |
| 74 | virtual unsigned int setScreenLayout(int fb_width, int fb_height, |
| 75 | const ScreenSet& layout) { |
| 76 | return resultProhibited; |
| 77 | } |
| 78 | |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 79 | // InputHandler interface |
| 80 | // pointerEvent(), keyEvent() and clientCutText() are called in response to |
| 81 | // the relevant RFB protocol messages from clients. |
| 82 | // See InputHandler for method signatures. |
| 83 | protected: |
| 84 | virtual ~SDesktop() {} |
| 85 | }; |
| 86 | |
| 87 | // -=- SStaticDesktop |
| 88 | // Trivial implementation of the SDesktop interface, which provides |
| 89 | // dummy input handlers and event processing routine, and exports |
| 90 | // a plain black desktop of the specified format. |
| 91 | class SStaticDesktop : public SDesktop { |
| 92 | public: |
| 93 | SStaticDesktop(const Point& size) : server(0), buffer(0) { |
| 94 | PixelFormat pf; |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 95 | const rdr::U8 black[4] = { 0, 0, 0, 0 }; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 96 | buffer = new ManagedPixelBuffer(pf, size.x, size.y); |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 97 | if (buffer) |
| 98 | buffer->fillRect(buffer->getRect(), black); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 99 | } |
| 100 | SStaticDesktop(const Point& size, const PixelFormat& pf) : buffer(0) { |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 101 | const rdr::U8 black[4] = { 0, 0, 0, 0 }; |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 102 | buffer = new ManagedPixelBuffer(pf, size.x, size.y); |
Pierre Ossman | 56f99d6 | 2015-06-05 12:57:02 +0200 | [diff] [blame] | 103 | if (buffer) |
| 104 | buffer->fillRect(buffer->getRect(), black); |
Constantin Kaplinsky | a2adc8d | 2006-05-25 05:01:55 +0000 | [diff] [blame] | 105 | } |
| 106 | virtual ~SStaticDesktop() { |
| 107 | if (buffer) delete buffer; |
| 108 | } |
| 109 | |
| 110 | virtual void start(VNCServer* vs) { |
| 111 | server = vs; |
| 112 | server->setPixelBuffer(buffer); |
| 113 | } |
| 114 | virtual void stop() { |
| 115 | server->setPixelBuffer(0); |
| 116 | server = 0; |
| 117 | } |
| 118 | |
| 119 | protected: |
| 120 | VNCServer* server; |
| 121 | ManagedPixelBuffer* buffer; |
| 122 | }; |
| 123 | |
| 124 | }; |
| 125 | |
| 126 | #endif // __RFB_SDESKTOP_H__ |