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.1KB

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