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.

VNCSConnectionST.h 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. //
  20. // VNCSConnectionST is our derived class of SConnection for VNCServerST - there
  21. // is one for each connected client. We think of VNCSConnectionST as part of
  22. // the VNCServerST implementation, so its methods are allowed full access to
  23. // members of VNCServerST.
  24. //
  25. #ifndef __RFB_VNCSCONNECTIONST_H__
  26. #define __RFB_VNCSCONNECTIONST_H__
  27. #include <map>
  28. #include <rfb/Congestion.h>
  29. #include <rfb/EncodeManager.h>
  30. #include <rfb/SConnection.h>
  31. #include <rfb/Timer.h>
  32. namespace rfb {
  33. class VNCServerST;
  34. class VNCSConnectionST : public SConnection,
  35. public Timer::Callback {
  36. public:
  37. VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse);
  38. virtual ~VNCSConnectionST();
  39. // SConnection methods
  40. virtual bool accessCheck(AccessRights ar) const;
  41. virtual void close(const char* reason);
  42. // Methods called from VNCServerST. None of these methods ever knowingly
  43. // throw an exception.
  44. // init() must be called to initialise the protocol. If it fails it
  45. // returns false, and close() will have been called.
  46. bool init();
  47. // processMessages() processes incoming messages from the client, invoking
  48. // various callbacks as a result. It continues to process messages until
  49. // reading might block. shutdown() will be called on the connection's
  50. // Socket if an error occurs, via the close() call.
  51. void processMessages();
  52. // flushSocket() pushes any unwritten data on to the network.
  53. void flushSocket();
  54. // Called when the underlying pixelbuffer is resized or replaced.
  55. void pixelBufferChange();
  56. // Wrappers to make these methods "safe" for VNCServerST.
  57. void writeFramebufferUpdateOrClose();
  58. void screenLayoutChangeOrClose(rdr::U16 reason);
  59. void setCursorOrClose();
  60. void bellOrClose();
  61. void serverCutTextOrClose(const char *str);
  62. void setDesktopNameOrClose(const char *name);
  63. void setLEDStateOrClose(unsigned int state);
  64. void approveConnectionOrClose(bool accept, const char* reason);
  65. // The following methods never throw exceptions
  66. // getComparerState() returns if this client would like the framebuffer
  67. // comparer to be enabled.
  68. bool getComparerState();
  69. // renderedCursorChange() is called whenever the server-side rendered
  70. // cursor changes shape or position. It ensures that the next update will
  71. // clean up the old rendered cursor and if necessary draw the new rendered
  72. // cursor.
  73. void renderedCursorChange();
  74. // needRenderedCursor() returns true if this client needs the server-side
  75. // rendered cursor. This may be because it does not support local cursor
  76. // or because the current cursor position has not been set by this client.
  77. bool needRenderedCursor();
  78. network::Socket* getSock() { return sock; }
  79. // Change tracking
  80. void add_changed(const Region& region) { updates.add_changed(region); }
  81. void add_copied(const Region& dest, const Point& delta) {
  82. updates.add_copied(dest, delta);
  83. }
  84. private:
  85. // SConnection callbacks
  86. // These methods are invoked as callbacks from processMsg()
  87. virtual void authSuccess();
  88. virtual void authFailure(const char* reason);
  89. virtual void queryConnection(const char* userName);
  90. virtual void clientInit(bool shared);
  91. virtual void setPixelFormat(const PixelFormat& pf);
  92. virtual void pointerEvent(const Point& pos, int buttonMask);
  93. virtual void keyEvent(rdr::U32 keysym, rdr::U32 keycode, bool down);
  94. virtual void clientCutText(const char* str);
  95. virtual void framebufferUpdateRequest(const Rect& r, bool incremental);
  96. virtual void setDesktopSize(int fb_width, int fb_height,
  97. const ScreenSet& layout);
  98. virtual void fence(rdr::U32 flags, unsigned len, const char data[]);
  99. virtual void enableContinuousUpdates(bool enable,
  100. int x, int y, int w, int h);
  101. virtual void supportsLocalCursor();
  102. virtual void supportsFence();
  103. virtual void supportsContinuousUpdates();
  104. virtual void supportsLEDState();
  105. // Timer callbacks
  106. virtual bool handleTimeout(Timer* t);
  107. // Internal methods
  108. bool isShiftPressed();
  109. // Congestion control
  110. void writeRTTPing();
  111. bool isCongested();
  112. // writeFramebufferUpdate() attempts to write a framebuffer update to the
  113. // client.
  114. void writeFramebufferUpdate();
  115. void writeNoDataUpdate();
  116. void writeDataUpdate();
  117. void writeLosslessRefresh();
  118. void screenLayoutChange(rdr::U16 reason);
  119. void setCursor();
  120. void setDesktopName(const char *name);
  121. void setLEDState(unsigned int state);
  122. void setSocketTimeouts();
  123. private:
  124. network::Socket* sock;
  125. CharArray peerEndpoint;
  126. bool reverseConnection;
  127. bool inProcessMessages;
  128. bool pendingSyncFence, syncFence;
  129. rdr::U32 fenceFlags;
  130. unsigned fenceDataLen;
  131. char *fenceData;
  132. Congestion congestion;
  133. Timer congestionTimer;
  134. Timer losslessTimer;
  135. VNCServerST* server;
  136. SimpleUpdateTracker updates;
  137. Region requested;
  138. bool updateRenderedCursor, removeRenderedCursor;
  139. Region damagedCursorRegion;
  140. bool continuousUpdates;
  141. Region cuRegion;
  142. EncodeManager encodeManager;
  143. std::map<rdr::U32, rdr::U32> pressedKeys;
  144. Timer idleTimer;
  145. time_t pointerEventTime;
  146. Point pointerEventPos;
  147. bool clientHasCursor;
  148. Timer authFailureTimer;
  149. CharArray authFailureMsg;
  150. CharArray closeReason;
  151. };
  152. }
  153. #endif