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.

VNCServerST.h 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. // -=- VNCServerST.h
  20. // Single-threaded VNCServer implementation
  21. #ifndef __RFB_VNCSERVERST_H__
  22. #define __RFB_VNCSERVERST_H__
  23. #include <sys/time.h>
  24. #include <rfb/SDesktop.h>
  25. #include <rfb/VNCServer.h>
  26. #include <rfb/Blacklist.h>
  27. #include <rfb/Cursor.h>
  28. #include <rfb/Timer.h>
  29. #include <rfb/ScreenSet.h>
  30. namespace rfb {
  31. class VNCSConnectionST;
  32. class ComparingUpdateTracker;
  33. class ListConnInfo;
  34. class PixelBuffer;
  35. class KeyRemapper;
  36. class VNCServerST : public VNCServer,
  37. public Timer::Callback {
  38. public:
  39. // -=- Constructors
  40. // Create a server exporting the supplied desktop.
  41. VNCServerST(const char* name_, SDesktop* desktop_);
  42. virtual ~VNCServerST();
  43. // Methods overridden from SocketServer
  44. // addSocket
  45. // Causes the server to allocate an RFB-protocol management
  46. // structure for the socket & initialise it.
  47. virtual void addSocket(network::Socket* sock, bool outgoing=false);
  48. // removeSocket
  49. // Clean up any resources associated with the Socket
  50. virtual void removeSocket(network::Socket* sock);
  51. // getSockets() gets a list of sockets. This can be used to generate an
  52. // fd_set for calling select().
  53. virtual void getSockets(std::list<network::Socket*>* sockets);
  54. // processSocketReadEvent
  55. // Read more RFB data from the Socket. If an error occurs during
  56. // processing then shutdown() is called on the Socket, causing
  57. // removeSocket() to be called by the caller at a later time.
  58. virtual void processSocketReadEvent(network::Socket* sock);
  59. // processSocketWriteEvent
  60. // Flush pending data from the Socket on to the network.
  61. virtual void processSocketWriteEvent(network::Socket* sock);
  62. // Methods overridden from VNCServer
  63. virtual void blockUpdates();
  64. virtual void unblockUpdates();
  65. virtual void setPixelBuffer(PixelBuffer* pb, const ScreenSet& layout);
  66. virtual void setPixelBuffer(PixelBuffer* pb);
  67. virtual void setScreenLayout(const ScreenSet& layout);
  68. virtual const PixelBuffer* getPixelBuffer() const { return pb; }
  69. virtual void requestClipboard();
  70. virtual void announceClipboard(bool available);
  71. virtual void sendClipboardData(const char* data);
  72. virtual void approveConnection(network::Socket* sock, bool accept,
  73. const char* reason);
  74. virtual void closeClients(const char* reason) {closeClients(reason, 0);}
  75. virtual SConnection* getConnection(network::Socket* sock);
  76. virtual void add_changed(const Region &region);
  77. virtual void add_copied(const Region &dest, const Point &delta);
  78. virtual void setCursor(int width, int height, const Point& hotspot,
  79. const rdr::U8* data);
  80. virtual void setCursorPos(const Point& p);
  81. virtual void setName(const char* name_);
  82. virtual void setLEDState(unsigned state);
  83. virtual void bell();
  84. // VNCServerST-only methods
  85. // Methods to get the currently set server state
  86. const ScreenSet& getScreenLayout() const { return screenLayout; }
  87. const Cursor* getCursor() const { return cursor; }
  88. const Point& getCursorPos() const { return cursorPos; }
  89. const char* getName() const { return name.buf; }
  90. unsigned getLEDState() const { return ledState; }
  91. // Event handlers
  92. void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down);
  93. void pointerEvent(VNCSConnectionST* client, const Point& pos, int buttonMask);
  94. void handleClipboardRequest(VNCSConnectionST* client);
  95. void handleClipboardAnnounce(VNCSConnectionST* client, bool available);
  96. void handleClipboardData(VNCSConnectionST* client, const char* data);
  97. unsigned int setDesktopSize(VNCSConnectionST* requester,
  98. int fb_width, int fb_height,
  99. const ScreenSet& layout);
  100. // closeClients() closes all RFB sessions, except the specified one (if
  101. // any), and logs the specified reason for closure.
  102. void closeClients(const char* reason, network::Socket* sock);
  103. // queryConnection() does some basic checks and then passes on the
  104. // request to the desktop.
  105. void queryConnection(VNCSConnectionST* client, const char* userName);
  106. // clientReady() is called by a VNCSConnectionST instance when the
  107. // client has completed the handshake and is ready for normal
  108. // communication.
  109. void clientReady(VNCSConnectionST* client, bool shared);
  110. // Estimated time until the next time new updates will be pushed
  111. // to clients
  112. int msToNextUpdate();
  113. // Part of the framebuffer that has been modified but is not yet
  114. // ready to be sent to clients
  115. Region getPendingRegion();
  116. // getRenderedCursor() returns an up to date version of the server
  117. // side rendered cursor buffer
  118. const RenderedCursor* getRenderedCursor();
  119. protected:
  120. // Timer callbacks
  121. virtual bool handleTimeout(Timer* t);
  122. // - Internal methods
  123. void startDesktop();
  124. void stopDesktop();
  125. // - Check how many of the clients are authenticated.
  126. int authClientCount();
  127. bool needRenderedCursor();
  128. void startFrameClock();
  129. void stopFrameClock();
  130. void writeUpdate();
  131. bool getComparerState();
  132. protected:
  133. Blacklist blacklist;
  134. Blacklist* blHosts;
  135. SDesktop* desktop;
  136. bool desktopStarted;
  137. int blockCounter;
  138. PixelBuffer* pb;
  139. ScreenSet screenLayout;
  140. unsigned int ledState;
  141. CharArray name;
  142. std::list<VNCSConnectionST*> clients;
  143. VNCSConnectionST* pointerClient;
  144. VNCSConnectionST* clipboardClient;
  145. std::list<VNCSConnectionST*> clipboardRequestors;
  146. std::list<network::Socket*> closingSockets;
  147. ComparingUpdateTracker* comparer;
  148. Point cursorPos;
  149. Cursor* cursor;
  150. RenderedCursor renderedCursor;
  151. bool renderedCursorInvalid;
  152. KeyRemapper* keyRemapper;
  153. Timer idleTimer;
  154. Timer disconnectTimer;
  155. Timer connectTimer;
  156. Timer frameTimer;
  157. };
  158. };
  159. #endif