00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00055 #ifndef WINSTL_INCL_WINSTL_REGISTRY_UTIL_HPP_SHARED_HANDLES
00056 #define WINSTL_INCL_WINSTL_REGISTRY_UTIL_HPP_SHARED_HANDLES
00057
00058 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00059 # define WINSTL_VER_WINSTL_REGISTRY_UTIL_HPP_SHARED_HANDLES_MAJOR 2
00060 # define WINSTL_VER_WINSTL_REGISTRY_UTIL_HPP_SHARED_HANDLES_MINOR 0
00061 # define WINSTL_VER_WINSTL_REGISTRY_UTIL_HPP_SHARED_HANDLES_REVISION 5
00062 # define WINSTL_VER_WINSTL_REGISTRY_UTIL_HPP_SHARED_HANDLES_EDIT 29
00063 #endif
00064
00065
00066
00067
00068
00069 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00070 # include <winstl/winstl.h>
00071 #endif
00072 #ifndef WINSTL_INCL_WINSTL_REGISTRY_HPP_REGFWD
00073 # include <winstl/registry/regfwd.hpp>
00074 #endif
00075 #ifndef WINSTL_INCL_WINSTL_REGISTRY_UTIL_HPP_DEFS
00076 # include <winstl/registry/util/defs.hpp>
00077 #endif
00078 #ifndef WINSTL_INCL_WINSTL_REGISTRY_HPP_REG_TRAITS
00079 # include <winstl/registry/reg_traits.hpp>
00080 #endif
00081 #ifndef WINSTL_INCL_WINSTL_REGISTRY_HPP_REG_KEY
00082 # include <winstl/registry/reg_key.hpp>
00083 #endif
00084 #ifndef WINSTL_INCL_SYNCH_WINSTL_HPP_EVENT
00085 # include <winstl/synch/event.hpp>
00086 #endif
00087 #if !defined(STLSOFT_COMPILER_IS_COMO) && \
00088 !defined(STLSOFT_COMPILER_IS_WATCOM)
00089 # ifndef WINSTL_INCL_WINSTL_DL_HPP_DL_CALL
00090 # include <winstl/dl/dl_call.hpp>
00091 # endif
00092 #endif
00093 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00094 # ifndef STLSOFT_INCL_STLSOFT_ERROR_HPP_EXTERNAL_ITERATOR_INVALIDATION
00095 # include <stlsoft/error/external_iterator_invalidation.hpp>
00096 # endif
00097 #endif
00098
00099
00100
00101
00102
00103 #ifndef _WINSTL_NO_NAMESPACE
00104 # if defined(_STLSOFT_NO_NAMESPACE) || \
00105 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00106
00107 namespace winstl
00108 {
00109 # else
00110
00111
00112 namespace stlsoft
00113 {
00114
00115 namespace winstl_project
00116 {
00117
00118 # endif
00119 #endif
00120
00121
00122
00123
00124
00125 #ifndef _STLSOFT_NO_NAMESPACES
00126
00130 namespace registry_util
00131 {
00132 #endif
00133
00137 #ifdef _STLSOFT_NO_NAMESPACES
00138 struct registry_util::shared_handle
00139 #else
00140 struct shared_handle
00141 #endif
00142 {
00145 public:
00146 typedef shared_handle class_type;
00147 typedef HKEY handle_type;
00149
00152 public:
00153 handle_type m_hkey;
00154 private:
00155 ss_sint32_t m_refCount;
00157
00160 public:
00161 ss_explicit_k shared_handle(handle_type hkey)
00162 : m_hkey(hkey)
00163 , m_refCount(1)
00164 {}
00165 protected:
00166 shared_handle(handle_type hkey, ss_sint32_t refCount)
00167 : m_hkey(hkey)
00168 , m_refCount(refCount)
00169 {}
00170 protected:
00171 virtual ~shared_handle() stlsoft_throw_0()
00172 {
00173 WINSTL_MESSAGE_ASSERT("Shared search handle being destroyed with outstanding references!", 0 == m_refCount);
00174
00175 if(NULL != m_hkey)
00176 {
00177 ::RegCloseKey(m_hkey);
00178 }
00179 }
00181
00184 public:
00185 ss_sint32_t AddRef()
00186 {
00187 return ++m_refCount;
00188 }
00189 ss_sint32_t Release()
00190 {
00191 ss_sint32_t rc = --m_refCount;
00192
00193 if(0 == rc)
00194 {
00195 delete this;
00196 }
00197
00198 return rc;
00199 }
00200
00201 virtual void test_reset_and_throw()
00202 {}
00204
00207 private:
00208 shared_handle(class_type const&);
00209 class_type& operator =(class_type const&);
00211 };
00212
00213 #if defined(STLSOFT_CF_EXCEPTION_SUPPORT) && \
00214 !defined(STLSOFT_COMPILER_IS_COMO) && \
00215 !defined(STLSOFT_COMPILER_IS_WATCOM)
00222 struct monitored_shared_handle
00223 : public shared_handle
00224 {
00225 public:
00226 typedef shared_handle parent_class_type;
00227 typedef monitored_shared_handle class_type;
00228
00229 public:
00230 monitored_shared_handle(handle_type hkey, int eventType)
00231 : parent_class_type(hkey, 0)
00232 , m_eventType(eventType)
00233 , m_monitor(true, false)
00234 {
00235 set();
00236
00237 AddRef();
00238 }
00239
00242 private:
00243 virtual void test_reset_and_throw()
00244 {
00245
00246 if(WAIT_OBJECT_0 == ::WaitForSingleObject(m_monitor.handle(), 0))
00247 {
00248
00249
00250
00251
00252 set();
00253
00254
00255 STLSOFT_THROW_X(stlsoft_ns_qual(external_iterator_invalidation)("registry contents changed"));
00256 }
00257 }
00258 private:
00259 void set()
00260 {
00261 try
00262 {
00263 dl_call<LONG>( "ADVAPI32.DLL"
00264 #if defined(WINSTL_OS_IS_WIN64)
00265 , "C:RegNotifyChangeKeyValue"
00266 #elif defined(WINSTL_OS_IS_WIN32)
00267 , "S:RegNotifyChangeKeyValue"
00268 #else
00269 # error Windows operating system not recognised
00270 #endif
00271 , m_hkey
00272 , false
00273 , (int)m_eventType
00274 , m_monitor.handle()
00275 , true);
00276 }
00277 catch(missing_entry_point_exception &)
00278 {
00279 if( 0 != (::GetVersion() & 0x80000000) &&
00280 LOBYTE(LOWORD(GetVersion())) == 4 &&
00281 HIBYTE(LOWORD(GetVersion())) < 10)
00282 {
00283
00284
00285
00286 ;
00287 }
00288 else
00289 {
00290 throw;
00291 }
00292 }
00293 }
00295
00298 private:
00299 const int m_eventType;
00300 event m_monitor;
00302
00305 private:
00306 monitored_shared_handle(class_type const&);
00307 class_type& operator =(class_type const&);
00309 };
00310 #endif
00311
00325 static shared_handle *create_shared_handle(HKEY hkey, ws_bool_t bMonitorExternalInvalidation, int eventType)
00326 {
00327 #if defined(STLSOFT_CF_EXCEPTION_SUPPORT) && \
00328 !defined(STLSOFT_COMPILER_IS_COMO) && \
00329 !defined(STLSOFT_COMPILER_IS_WATCOM)
00330
00331 if(bMonitorExternalInvalidation)
00332 {
00333 return new monitored_shared_handle(hkey, eventType);
00334 }
00335 else
00336 #else
00337 STLSOFT_SUPPRESS_UNUSED(bMonitorExternalInvalidation);
00338 STLSOFT_SUPPRESS_UNUSED(eventType);
00339 #endif
00340 {
00341 return new shared_handle(hkey);
00342 }
00343 }
00344
00345 #ifndef _STLSOFT_NO_NAMESPACES
00346 }
00347 #endif
00348
00349
00350
00351 #ifndef _WINSTL_NO_NAMESPACE
00352 # if defined(_STLSOFT_NO_NAMESPACE) || \
00353 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00354 }
00355 # else
00356 }
00357 }
00358 # endif
00359 #endif
00360
00361
00362
00363 #endif
00364
00365