Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

VNCSConnectionST.h 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2009-2011 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 <set>
  28. #include <rfb/SConnection.h>
  29. #include <rfb/SMsgWriter.h>
  30. #include <rfb/TransImageGetter.h>
  31. #include <rfb/VNCServerST.h>
  32. #include <rfb/Timer.h>
  33. struct RTTInfo;
  34. namespace rfb {
  35. class Encoder;
  36. class VNCSConnectionST : public SConnection,
  37. public WriteSetCursorCallback,
  38. public Timer::Callback {
  39. public:
  40. VNCSConnectionST(VNCServerST* server_, network::Socket* s, bool reverse);
  41. virtual ~VNCSConnectionST();
  42. // Methods called from VNCServerST. None of these methods ever knowingly
  43. // throw an exception.
  44. // Unless otherwise stated, the SConnectionST may not be valid after any of
  45. // these methods are called, since they catch exceptions and may have
  46. // called close() which deletes the object.
  47. // init() must be called to initialise the protocol. If it fails it
  48. // returns false, and close() will have been called.
  49. bool init();
  50. // close() shuts down the socket to the client and deletes the
  51. // SConnectionST object.
  52. void close(const char* reason);
  53. // processMessages() processes incoming messages from the client, invoking
  54. // various callbacks as a result. It continues to process messages until
  55. // reading might block. shutdown() will be called on the connection's
  56. // Socket if an error occurs, via the close() call.
  57. void processMessages();
  58. // Called when the underlying pixelbuffer is resized or replaced.
  59. void pixelBufferChange();
  60. // Wrappers to make these methods "safe" for VNCServerST.
  61. void writeFramebufferUpdateOrClose();
  62. void screenLayoutChangeOrClose(rdr::U16 reason);
  63. void setCursorOrClose();
  64. void bellOrClose();
  65. void serverCutTextOrClose(const char *str, int len);
  66. void setDesktopNameOrClose(const char *name);
  67. // checkIdleTimeout() returns the number of milliseconds left until the
  68. // idle timeout expires. If it has expired, the connection is closed and
  69. // zero is returned. Zero is also returned if there is no idle timeout.
  70. int checkIdleTimeout();
  71. // The following methods never throw exceptions nor do they ever delete the
  72. // SConnectionST object.
  73. // getComparerState() returns if this client would like the framebuffer
  74. // comparer to be enabled.
  75. bool getComparerState();
  76. // renderedCursorChange() is called whenever the server-side rendered
  77. // cursor changes shape or position. It ensures that the next update will
  78. // clean up the old rendered cursor and if necessary draw the new rendered
  79. // cursor.
  80. void renderedCursorChange();
  81. // needRenderedCursor() returns true if this client needs the server-side
  82. // rendered cursor. This may be because it does not support local cursor
  83. // or because the current cursor position has not been set by this client.
  84. bool needRenderedCursor();
  85. network::Socket* getSock() { return sock; }
  86. void add_changed(const Region& region) { updates.add_changed(region); }
  87. void add_copied(const Region& dest, const Point& delta) {
  88. updates.add_copied(dest, delta);
  89. }
  90. const char* getPeerEndpoint() const {return peerEndpoint.buf;}
  91. // approveConnectionOrClose() is called some time after
  92. // VNCServerST::queryConnection() has returned with PENDING to accept or
  93. // reject the connection. The accept argument should be true for
  94. // acceptance, or false for rejection, in which case a string reason may
  95. // also be given.
  96. void approveConnectionOrClose(bool accept, const char* reason);
  97. char* getStartTime();
  98. void setStatus(int status);
  99. int getStatus();
  100. private:
  101. // SConnection callbacks
  102. // These methods are invoked as callbacks from processMsg(). Note that
  103. // none of these methods should call any of the above methods which may
  104. // delete the SConnectionST object.
  105. virtual void authSuccess();
  106. virtual void queryConnection(const char* userName);
  107. virtual void clientInit(bool shared);
  108. virtual void setPixelFormat(const PixelFormat& pf);
  109. virtual void pointerEvent(const Point& pos, int buttonMask);
  110. virtual void keyEvent(rdr::U32 key, bool down);
  111. virtual void clientCutText(const char* str, int len);
  112. virtual void framebufferUpdateRequest(const Rect& r, bool incremental);
  113. virtual void setDesktopSize(int fb_width, int fb_height,
  114. const ScreenSet& layout);
  115. virtual void fence(rdr::U32 flags, unsigned len, const char data[]);
  116. virtual void enableContinuousUpdates(bool enable,
  117. int x, int y, int w, int h);
  118. virtual void supportsLocalCursor();
  119. virtual void supportsFence();
  120. virtual void supportsContinuousUpdates();
  121. // setAccessRights() allows a security package to limit the access rights
  122. // of a VNCSConnectioST to the server. These access rights are applied
  123. // such that the actual rights granted are the minimum of the server's
  124. // default access settings and the connection's access settings.
  125. virtual void setAccessRights(AccessRights ar) {accessRights=ar;}
  126. // WriteSetCursorCallback
  127. virtual void writeSetCursorCallback();
  128. // Timer callbacks
  129. virtual bool handleTimeout(Timer* t);
  130. // Internal methods
  131. // Congestion control
  132. void writeRTTPing();
  133. void handleRTTPong(const struct RTTInfo &rttInfo);
  134. bool isCongested();
  135. void updateCongestion();
  136. // writeFramebufferUpdate() attempts to write a framebuffer update to the
  137. // client.
  138. void writeFramebufferUpdate();
  139. void screenLayoutChange(rdr::U16 reason);
  140. void setCursor();
  141. void setDesktopName(const char *name);
  142. void setSocketTimeouts();
  143. network::Socket* sock;
  144. CharArray peerEndpoint;
  145. bool inProcessMessages;
  146. bool pendingSyncFence, syncFence;
  147. rdr::U32 fenceFlags;
  148. unsigned fenceDataLen;
  149. char *fenceData;
  150. unsigned baseRTT;
  151. unsigned congWindow;
  152. int ackedOffset, sentOffset;
  153. unsigned minRTT;
  154. bool seenCongestion;
  155. unsigned pingCounter;
  156. Timer congestionTimer;
  157. VNCServerST* server;
  158. SimpleUpdateTracker updates;
  159. TransImageGetter image_getter;
  160. Region requested;
  161. bool drawRenderedCursor, removeRenderedCursor;
  162. Rect renderedCursorRect;
  163. bool continuousUpdates;
  164. Region cuRegion;
  165. Encoder* encoders[encodingMax+1];
  166. Timer updateTimer;
  167. std::set<rdr::U32> pressedKeys;
  168. time_t lastEventTime;
  169. time_t pointerEventTime;
  170. Point pointerEventPos;
  171. AccessRights accessRights;
  172. CharArray closeReason;
  173. time_t startTime;
  174. };
  175. }
  176. #endif