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 5.3KB

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