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