![]() |
VR-Forces 4.0.4 Class Documentation
|
00001 /***************************************************************************** 00002 * Copyright (c) 2012 MAK Technologies, Inc. 00003 * All rights reserved. 00004 *****************************************************************************/ 00005 00009 00010 #pragma once 00011 00012 #include <vrvCore/vrvCore.h> 00013 #include <vrvUtil/DtVirtualBaseClass.h> 00014 00015 #ifndef WIN32_LEAN_AND_MEAN 00016 #define UNDEF_WIN32_LEAN_AND_MEAN 00017 #define WIN32_LEAN_AND_MEAN 00018 #endif 00019 00020 #include <boost/thread/shared_mutex.hpp> 00021 00022 #ifdef UNDEF_WIN32_LEAN_AND_MEAN 00023 #undef UNDEF_WIN32_LEAN_AND_MEAN 00024 #undef WIN32_LEAN_AND_MEAN 00025 #endif 00026 00029 #include <vrvCore/DtReadSettingsLock.h> 00030 #include <vrvCore/DtWriteSettingsLock.h> 00031 00032 namespace makVrv 00033 { 00034 00035 class DtSettingsBackup; 00036 00045 class DT_DLL_VRVCORE DtSharedSettings : public DtVirtualBaseClass 00046 { 00047 public: 00048 00050 DtSharedSettings( const DtSharedSettingsManager& manager ); 00051 00053 virtual ~DtSharedSettings(); 00054 00056 inline boost::shared_mutex& mutex() { return myMutex; } 00057 00061 00062 // Forward declarations. 00063 class SignalSafety; 00064 friend class SignalSafety; 00065 00068 class DT_DLL_VRVCORE SafetyKey 00069 { 00070 public: 00071 00072 friend class DtSharedSettings; 00073 friend class SignalSafety; 00074 00075 ~SafetyKey(); 00076 00077 #if _WIN32 //Windows allows the copy ctor to be private 00078 private: 00079 #endif 00080 00081 SafetyKey( const SafetyKey& ); 00082 00083 private: 00084 00085 SafetyKey(); 00086 00087 SafetyKey& operator = ( const SafetyKey& ); 00088 00089 protected: 00090 00091 SafetyKey( DtSharedSettings* ptr ); 00092 00093 DtSharedSettings* myPtr; 00094 00095 }; 00096 00097 //The signal safety class ensures that the manager for getting a 00098 //Signaler is safe, as this requires unlocking the write lock, calling 00099 //the signal, then re-locking the write lock when the function returns 00109 class DT_DLL_VRVCORE SignalSafety : public boost::noncopyable 00110 { 00111 public: 00112 00115 SignalSafety( const SafetyKey& key ); 00116 00119 ~SignalSafety(); 00120 00122 inline const DtSharedSettingsManager& manager() const 00123 { 00124 return mySettings.myManager; 00125 } 00126 00127 protected: 00128 00129 DtSharedSettings& mySettings; 00130 00131 }; 00132 00133 00135 SafetyKey safeToEmitSignals() 00136 { 00137 return SafetyKey(this); 00138 } 00139 00141 inline void setCurrentWriteLock( 00142 boost::unique_lock<boost::shared_mutex>* currentWriteLock) 00143 { 00144 myCurrentWriteLock = currentWriteLock; 00145 } 00146 00149 virtual const DtSettingsBackup* settingsBackup() const; 00150 00153 virtual DtSettingsBackup* settingsBackup(); 00154 00157 virtual void backup(); 00158 00159 private: 00160 00161 const DtSharedSettingsManager& myManager; 00162 boost::shared_mutex myMutex; 00163 00164 //Current write lock used. 00165 boost::unique_lock<boost::shared_mutex>* myCurrentWriteLock; 00166 00167 }; 00168 00169 }