Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

VNCServerWin32.h 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. #ifndef __VNCSERVER_WIN32_H__
  19. #define __VNCSERVER_WIN32_H__
  20. #include <winsock2.h>
  21. #include <network/TcpSocket.h>
  22. #include <rfb/VNCServerST.h>
  23. #include <rfb_win32/RegConfig.h>
  24. #include <rfb_win32/SDisplay.h>
  25. #include <rfb_win32/SocketManager.h>
  26. #include <rfb_win32/TCharArray.h>
  27. #include <winvnc/QueryConnectDialog.h>
  28. #include <winvnc/ManagedListener.h>
  29. namespace os {
  30. class Mutex;
  31. class Condition;
  32. class Thread;
  33. }
  34. namespace winvnc {
  35. class STrayIconThread;
  36. class VNCServerWin32 : rfb::VNCServerST::QueryConnectionHandler,
  37. rfb::win32::SocketManager::AddressChangeNotifier,
  38. rfb::win32::RegConfig::Callback,
  39. rfb::win32::EventHandler {
  40. public:
  41. VNCServerWin32();
  42. virtual ~VNCServerWin32();
  43. // Run the server in the current thread
  44. int run();
  45. // Cause the run() call to return
  46. // THREAD-SAFE
  47. void stop();
  48. // Determine whether a viewer is active
  49. // THREAD-SAFE
  50. bool isServerInUse() const {return isDesktopStarted;}
  51. // Connect out to the specified VNC Viewer
  52. // THREAD-SAFE
  53. bool addNewClient(const char* client);
  54. // Disconnect all connected clients
  55. // THREAD-SAFE
  56. bool disconnectClients(const char* reason=0);
  57. // Call used to notify VNCServerST of user accept/reject query completion
  58. // CALLED FROM AcceptConnectDialog THREAD
  59. void queryConnectionComplete();
  60. // Where to read the configuration settings from
  61. static const TCHAR* RegConfigPath;
  62. bool getClientsInfo(rfb::ListConnInfo* LCInfo);
  63. bool setClientsStatus(rfb::ListConnInfo* LCInfo);
  64. protected:
  65. // VNCServerST::QueryConnectionHandler interface
  66. // Callback used to prompt user to accept or reject a connection.
  67. // CALLBACK IN VNCServerST "HOST" THREAD
  68. virtual void queryConnection(network::Socket* sock,
  69. const char* userName);
  70. // SocketManager::AddressChangeNotifier interface
  71. // Used to keep tray icon up to date
  72. virtual void processAddressChange();
  73. // RegConfig::Callback interface
  74. // Called via the EventManager whenever RegConfig sees the registry change
  75. virtual void regConfigChanged();
  76. // EventHandler interface
  77. // Used to perform queued commands
  78. virtual void processEvent(HANDLE event);
  79. protected:
  80. // Perform a particular internal function in the server thread
  81. typedef enum {NoCommand, DisconnectClients, AddClient, QueryConnectionComplete, SetClientsStatus, GetClientsInfo} Command;
  82. bool queueCommand(Command cmd, const void* data, int len, bool wait=true);
  83. Command command;
  84. const void* commandData;
  85. int commandDataLen;
  86. os::Mutex* commandLock;
  87. os::Condition* commandSig;
  88. rfb::win32::Handle commandEvent;
  89. rfb::win32::Handle sessionEvent;
  90. // VNCServerWin32 Server-internal state
  91. rfb::win32::SDisplay desktop;
  92. rfb::VNCServerST vncServer;
  93. os::Mutex* runLock;
  94. DWORD thread_id;
  95. bool runServer;
  96. bool isDesktopStarted;
  97. rfb::win32::SocketManager sockMgr;
  98. rfb::win32::RegConfig config;
  99. ManagedListener rfbSock;
  100. STrayIconThread* trayIcon;
  101. QueryConnectDialog* queryConnectDialog;
  102. };
  103. };
  104. #endif