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.

VNCServerWin32.h 4.3KB

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