OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef REMOTING_HOST_HOST_SERVICE_WIN_H_ | |
6 #define REMOTING_HOST_HOST_SERVICE_WIN_H_ | |
7 | |
8 #include <windows.h> | |
9 | |
10 #include "base/file_path.h" | |
11 #include "base/memory/singleton.h" | |
12 #include "base/observer_list.h" | |
13 #include "base/synchronization/waitable_event.h" | |
14 | |
15 #include "remoting/host/wts_console_monitor_win.h" | |
16 | |
17 class CommandLine; | |
18 class MessageLoop; | |
19 | |
20 namespace remoting { | |
21 | |
22 class WtsConsoleObserver; | |
23 | |
24 class HostService : public WtsConsoleMonitor { | |
25 public: | |
26 static HostService* GetInstance(); | |
27 | |
28 // This function parses the command line and selects the action routine. | |
29 bool InitWithCommandLine(const CommandLine* command_line); | |
30 | |
31 // Invoke the choosen action routine. | |
32 int Run(); | |
33 | |
34 // WtsConsoleMonitor implementation | |
35 virtual void AddWtsConsoleObserver(WtsConsoleObserver* observer) OVERRIDE; | |
36 virtual void RemoveWtsConsoleObserver( | |
37 WtsConsoleObserver* observer) OVERRIDE; | |
38 | |
39 private: | |
40 HostService(); | |
41 ~HostService(); | |
42 | |
43 // Notifies the service of changes in session state. | |
44 void OnSessionChange(); | |
45 | |
46 // This is a common entry point to the main service loop called by both | |
47 // RunAsService() and RunInConsole(). | |
48 void RunMessageLoop(); | |
49 | |
50 // This function handshakes with the service control manager and starts | |
51 // the service. | |
52 int RunAsService(); | |
53 | |
54 // This function starts the service in interactive mode (i.e. as a plain | |
55 // console application). | |
56 int RunInConsole(); | |
57 | |
58 static BOOL WINAPI ConsoleControlHandler(DWORD event); | |
59 | |
60 // The control handler of the service. | |
61 static DWORD WINAPI ServiceControlHandler(DWORD control, | |
62 DWORD event_type, | |
63 LPVOID event_data, | |
64 LPVOID context); | |
65 | |
66 // The main service entry point. | |
67 static VOID WINAPI ServiceMain(DWORD argc, WCHAR* argv[]); | |
68 | |
69 static LRESULT CALLBACK SessionChangeNotificationProc(HWND hwnd, | |
70 UINT message, | |
71 WPARAM wparam, | |
72 LPARAM lparam); | |
73 | |
74 // Current physical console session id. | |
75 uint32 console_session_id_; | |
76 | |
77 // The list of observers receiving notifications about any session attached | |
78 // to the physical console. | |
79 ObserverList<WtsConsoleObserver> console_observers_; | |
80 | |
81 // The host binary name. | |
82 FilePath host_binary_; | |
83 | |
84 // Service message loop. | |
85 MessageLoop* message_loop_; | |
86 | |
87 // The action routine to be executed. | |
88 int (HostService::*run_routine_)(); | |
89 | |
90 // The service name. | |
91 std::wstring service_name_; | |
92 | |
93 // The service status handle. | |
94 SERVICE_STATUS_HANDLE service_status_handle_; | |
95 | |
96 // True if the service is being stopped. | |
97 bool shutting_down_; | |
98 | |
99 // A waitable event that is used to wait until the service is stopped. | |
100 base::WaitableEvent stopped_event_; | |
101 | |
102 // Singleton. | |
103 friend struct DefaultSingletonTraits<HostService>; | |
104 | |
105 DISALLOW_COPY_AND_ASSIGN(HostService); | |
106 }; | |
107 | |
108 } // namespace remoting | |
109 | |
110 #endif // REMOTING_HOST_HOST_SERVICE_WIN_H_ | |
OLD | NEW |