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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2009-2016 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 serverCutText(const char* str, int len);
  70. virtual void approveConnection(network::Socket* sock, bool accept,
  71. const char* reason);
  72. virtual void closeClients(const char* reason) {closeClients(reason, 0);}
  73. virtual SConnection* getConnection(network::Socket* sock);
  74. virtual void add_changed(const Region &region);
  75. virtual void add_copied(const Region &dest, const Point &delta);
  76. virtual void setCursor(int width, int height, const Point& hotspot,
  77. const rdr::U8* data);
  78. virtual void setCursorPos(const Point& p);
  79. virtual void setName(const char* name_);
  80. virtual void setLEDState(unsigned state);
  81. virtual void bell();
  82. // VNCServerST-only methods
  83. // Methods to get the currently set server state
  84. const ScreenSet& getScreenLayout() const { return screenLayout; }
  85. const Cursor* getCursor() const { return cursor; }
  86. const Point& getCursorPos() const { return cursorPos; }
  87. const char* getName() const { return name.buf; }
  88. unsigned getLEDState() const { return ledState; }
  89. // Event handlers
  90. void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down);
  91. void pointerEvent(VNCSConnectionST* client, const Point& pos, int buttonMask);
  92. void clientCutText(const char* str, int len);
  93. unsigned int setDesktopSize(VNCSConnectionST* requester,
  94. int fb_width, int fb_height,
  95. const ScreenSet& layout);
  96. // closeClients() closes all RFB sessions, except the specified one (if
  97. // any), and logs the specified reason for closure.
  98. void closeClients(const char* reason, network::Socket* sock);
  99. // queryConnection() does some basic checks and then passes on the
  100. // request to the desktop.
  101. void queryConnection(VNCSConnectionST* client, const char* userName);
  102. // clientReady() is called by a VNCSConnectionST instance when the
  103. // client has completed the handshake and is ready for normal
  104. // communication.
  105. void clientReady(VNCSConnectionST* client, bool shared);
  106. // Estimated time until the next time new updates will be pushed
  107. // to clients
  108. int msToNextUpdate();
  109. // Part of the framebuffer that has been modified but is not yet
  110. // ready to be sent to clients
  111. Region getPendingRegion();
  112. // getRenderedCursor() returns an up to date version of the server
  113. // side rendered cursor buffer
  114. const RenderedCursor* getRenderedCursor();
  115. protected:
  116. // Timer callbacks
  117. virtual bool handleTimeout(Timer* t);
  118. // - Internal methods
  119. void startDesktop();
  120. void stopDesktop();
  121. // - Check how many of the clients are authenticated.
  122. int authClientCount();
  123. bool needRenderedCursor();
  124. void startFrameClock();
  125. void stopFrameClock();
  126. void writeUpdate();
  127. bool getComparerState();
  128. protected:
  129. Blacklist blacklist;
  130. Blacklist* blHosts;
  131. SDesktop* desktop;
  132. bool desktopStarted;
  133. int blockCounter;
  134. PixelBuffer* pb;
  135. ScreenSet screenLayout;
  136. unsigned int ledState;
  137. CharArray name;
  138. std::list<VNCSConnectionST*> clients;
  139. VNCSConnectionST* pointerClient;
  140. std::list<network::Socket*> closingSockets;
  141. ComparingUpdateTracker* comparer;
  142. Point cursorPos;
  143. Cursor* cursor;
  144. RenderedCursor renderedCursor;
  145. bool renderedCursorInvalid;
  146. KeyRemapper* keyRemapper;
  147. Timer idleTimer;
  148. Timer disconnectTimer;
  149. Timer connectTimer;
  150. Timer frameTimer;
  151. };
  152. };
  153. #endif