OLD | NEW |
| (Empty) |
1 // Copyright 2008-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 // The RegistryMonitor allows a caller to request monitoring | |
17 // for registry value changes across multiple keys. It uses the Windows API | |
18 // function RegNotifyChangeKeyValue to notify when any value in a key changes. | |
19 | |
20 #ifndef OMAHA_COMMON_REGISTRY_MONITOR_MANAGER_H_ | |
21 #define OMAHA_COMMON_REGISTRY_MONITOR_MANAGER_H_ | |
22 | |
23 #include <windows.h> | |
24 #include <atlstr.h> | |
25 #include "base/basictypes.h" | |
26 #include "base/scoped_ptr.h" | |
27 | |
28 namespace omaha { | |
29 | |
30 namespace detail { | |
31 | |
32 class RegistryMonitorImpl; | |
33 | |
34 } // namespace detail | |
35 | |
36 // Called when a registry value changes. 'new_value_data' contains a | |
37 // pointer to the string data for a string value or the value itself for a | |
38 // DWORD value. | |
39 enum RegistryChangeType { | |
40 REGISTRY_CHANGE_TYPE_CREATE = 0, | |
41 REGISTRY_CHANGE_TYPE_UPDATE, | |
42 REGISTRY_CHANGE_TYPE_DELETE, | |
43 }; | |
44 typedef void (*RegistryValueChangeCallback)(const TCHAR* key_name, | |
45 const TCHAR* value_name, | |
46 RegistryChangeType change_type, | |
47 const void* new_value_data, | |
48 void* user_data); | |
49 | |
50 // Called when a registry key changes. Changes include subkeys being | |
51 // created or deleted as well as value changes under that key but not under | |
52 // the subkeys of the key. | |
53 typedef void (*RegistryKeyChangeCallback)(const TCHAR* key_name, | |
54 void* user_data); | |
55 | |
56 class RegistryMonitor { | |
57 public: | |
58 RegistryMonitor(); | |
59 ~RegistryMonitor(); | |
60 | |
61 HRESULT Initialize(); | |
62 | |
63 // Monitors a registry sub key for changes. Registering the same sub key | |
64 // overrides the previous registration. | |
65 HRESULT MonitorKey(HKEY root_key, | |
66 const CString& sub_key, | |
67 RegistryKeyChangeCallback callback, | |
68 void* user_data); | |
69 | |
70 // Adds a registry value to the list of values to monitor for changes. | |
71 // All values must be registered before starting monitoring. Registering | |
72 // the same value is allowed, although not particularly useful. | |
73 HRESULT MonitorValue(HKEY root_key, | |
74 const CString& sub_key, | |
75 const CString& value_name, | |
76 int value_type, | |
77 RegistryValueChangeCallback callback, | |
78 void* user_data); | |
79 | |
80 // Starts monitoring for changes. | |
81 HRESULT StartMonitoring(); | |
82 | |
83 private: | |
84 scoped_ptr<detail::RegistryMonitorImpl> impl_; | |
85 | |
86 DISALLOW_EVIL_CONSTRUCTORS(RegistryMonitor); | |
87 }; | |
88 | |
89 } // namespace omaha | |
90 | |
91 #endif // OMAHA_COMMON_REGISTRY_MONITOR_MANAGER_H_ | |
92 | |
OLD | NEW |