You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SDesktop.h 6.2KB

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