OLD | NEW |
| (Empty) |
1 // Copyright 2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 | |
16 // SystemMonitor receives session messages and power management messages. | |
17 | |
18 #ifndef OMAHA_CORE_SYSTEM_MONITOR_H_ | |
19 #define OMAHA_CORE_SYSTEM_MONITOR_H_ | |
20 | |
21 #include <atlbase.h> | |
22 #include <atlwin.h> | |
23 #include "base/basictypes.h" | |
24 #include "base/scoped_ptr.h" | |
25 #include "omaha/base/registry_monitor_manager.h" | |
26 | |
27 namespace omaha { | |
28 | |
29 class SystemMonitorObserver { | |
30 public: | |
31 virtual ~SystemMonitorObserver() {} | |
32 | |
33 // Called when 'LastChecked' registry value is deleted. | |
34 virtual void LastCheckedDeleted() = 0; | |
35 | |
36 // Called when there are no other clients that are registered besides Omaha. | |
37 virtual void NoRegisteredClients() = 0; | |
38 }; | |
39 | |
40 class SystemMonitor | |
41 : public CWindowImpl<SystemMonitor, | |
42 CWindow, | |
43 CWinTraits<WS_OVERLAPPED, WS_EX_TOOLWINDOW> > { | |
44 public: | |
45 explicit SystemMonitor(bool is_machine); | |
46 ~SystemMonitor(); | |
47 | |
48 HRESULT Initialize(bool monitor_registry); | |
49 | |
50 void set_observer(SystemMonitorObserver* observer) { | |
51 ::InterlockedExchangePointer(reinterpret_cast<void**>(&observer_), | |
52 observer); | |
53 } | |
54 | |
55 BEGIN_MSG_MAP(SystemMonitor) | |
56 MESSAGE_HANDLER(WM_POWERBROADCAST, OnPowerBroadcast) | |
57 MESSAGE_HANDLER(WM_QUERYENDSESSION, OnQueryEndSession) | |
58 MESSAGE_HANDLER(WM_ENDSESSION, OnEndSession) | |
59 MESSAGE_HANDLER(WM_WTSSESSION_CHANGE, OnWTSSessionChange) | |
60 END_MSG_MAP() | |
61 | |
62 private: | |
63 // Notifies the system monitor that a power-management event has occurred. | |
64 LRESULT OnPowerBroadcast(UINT msg, WPARAM wparam, | |
65 LPARAM lparam, BOOL& handled); | |
66 | |
67 // Notifies the system monitor a shutdown has been requested. | |
68 LRESULT OnQueryEndSession(UINT msg, WPARAM wparam, | |
69 LPARAM lparam, BOOL& handled); | |
70 | |
71 // Notifies the system monitor whether the session is ending. | |
72 LRESULT OnEndSession(UINT msg, WPARAM wparam, | |
73 LPARAM lparam, BOOL& handled); | |
74 | |
75 // Notifies the system monitor about changes in the session state. | |
76 LRESULT OnWTSSessionChange(UINT msg, WPARAM wparam, | |
77 LPARAM lparam, BOOL& handled); | |
78 | |
79 static void RegistryValueChangeCallback(const TCHAR* key_name, | |
80 const TCHAR* value_name, | |
81 RegistryChangeType change_type, | |
82 const void* new_value_data, | |
83 void* user_data); | |
84 | |
85 static void RegistryKeyChangeCallback(const TCHAR* key_name, | |
86 void* user_data); | |
87 | |
88 scoped_ptr<RegistryMonitor> registry_monitor_; | |
89 bool is_machine_; | |
90 SystemMonitorObserver* observer_; | |
91 | |
92 DISALLOW_EVIL_CONSTRUCTORS(SystemMonitor); | |
93 }; | |
94 | |
95 } // namespace omaha | |
96 | |
97 #endif // OMAHA_CORE_SYSTEM_MONITOR_H_ | |
98 | |
OLD | NEW |