Tag: cws_src680_dba30 User: fs Date: 06/03/21 10:23:51 Modified: /dba/dbaccess/source/core/dataaccess/ ModelImpl.hxx
Log: RESYNC: (1.8-1.10); FILE MERGED File Changes: Directory: /dba/dbaccess/source/core/dataaccess/ ================================================ File [changed]: ModelImpl.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.hxx?r1=1.3.2.4&r2=1.3.2.5 Delta lines: +109 -7 --------------------- --- ModelImpl.hxx 30 Sep 2005 06:10:03 -0000 1.3.2.4 +++ ModelImpl.hxx 21 Mar 2006 18:23:49 -0000 1.3.2.5 @@ -179,6 +179,27 @@ class OSharedConnectionManager; //============================================================ +//= SharedMutex +//============================================================ +class SharedMutex +{ +private: + oslInterlockedCount m_refCount; + ::osl::Mutex m_aMutex; + +public: + SharedMutex(); + + void SAL_CALL acquire(); + void SAL_CALL release(); + + inline ::osl::Mutex& getMutex() { return m_aMutex; } + +private: + ~SharedMutex(); +}; + +//============================================================ //= ODatabaseModelImpl //============================================================ DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >,TStorages); @@ -193,10 +214,11 @@ ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDataSource> m_xDataSource; DocumentStorageAccess* m_pStorageAccess; + ::rtl::Reference< SharedMutex > m_xMutex; public: - enum + enum ObjectType { E_FORM = 0, E_REPORT = 1, @@ -213,8 +235,6 @@ ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xCommandDefinitions; ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xTableDefinitions; - ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xForms; - ::com::sun::star::uno::WeakReference< ::com::sun::star::container::XNameAccess > m_xReports; /// the URL the document was loaded from ::rtl::OUString m_sFileURL; @@ -412,6 +432,7 @@ ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > createNewModel_deliverOwnership(); struct ResetModelAccess { friend class ODatabaseDocument; private: ResetModelAccess() { } }; + /** resets the model to NULL Only to be called when the model is being disposed @@ -424,7 +445,7 @@ ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentSubStorageSupplier > getDocumentSubStorageSupplier(); -// void clear(); + inline ::rtl::Reference< SharedMutex > getSharedMutex() const { return m_xMutex; } /** @see osl_incrementInterlockedCount. */ @@ -437,6 +458,87 @@ /// returns a all known data source settings, including their default values static const AsciiPropertyValue* getDefaultDataSourceSettings(); +}; + +/** a small base class for UNO components whose functionality depends on a ODatabaseModelImpl +*/ +class ModelDependentComponent +{ +protected: + ::rtl::Reference< ODatabaseModelImpl > m_pImpl; + ::rtl::Reference< SharedMutex > m_xMutex; + +protected: + ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model ); + + /** returns the component itself + */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getThis() = 0; + + inline ::osl::Mutex& getMutex() + { + return m_xMutex->getMutex(); + } + +public: + struct GuardAccess { friend class ModelMethodGuard; private: GuardAccess() { } }; + + /** returns the mutex used for thread safety + + @throws ::com::sun::star::lang::DisposedException + if m_pImpl is <NULL/>. Usually, you will set this member in your derived + component's <code>dispose</code> method to <NULL/>. + */ + inline ::osl::Mutex& getMutex( GuardAccess ) + { + return getMutex(); + } + inline ::rtl::Reference< ODatabaseModelImpl > getImpl( GuardAccess ) + { + return m_pImpl; + } + + void checkDisposed() + { + if ( !m_pImpl.is() ) + throw ::com::sun::star::lang::DisposedException( ::rtl::OUString::createFromAscii( "Component is already disposed." ), getThis() ); + } +}; + +/** a guard for public methods of objects dependent on a ODatabaseModelImpl instance + + Just put this guard onto the stack at the beginning of your method. Don't bother yourself + with a MutexGuard, checks for being disposed, and the like. +*/ +class ModelMethodGuard :public ::osl::ResettableMutexGuard +{ +private: + typedef ::osl::ResettableMutexGuard BaseMutexGuard; + +public: + /** constructs the guard + + @param _component + the component whose functionality depends on a ODatabaseModelImpl instance + + @throws ::com::sun::star::lang::DisposedException + If the given component is already disposed + */ + ModelMethodGuard( ModelDependentComponent& _component ) + :BaseMutexGuard( _component.getMutex( ModelDependentComponent::GuardAccess() ) ) + { + _component.checkDisposed(); + } + + inline void clear() + { + BaseMutexGuard::clear(); + } + + inline void reset() + { + BaseMutexGuard::reset(); + } }; //........................................................................ --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
