Tag: cws_dev300_odbmacros3 User: fs Date: 2008-07-24 05:33:23+0000 Modified: dba/dbaccess/source/core/dataaccess/ModelImpl.cxx dba/dbaccess/source/core/dataaccess/ModelImpl.hxx
Log: tweaking the initialization File Changes: Directory: /dba/dbaccess/source/core/dataaccess/ ================================================ File [changed]: ModelImpl.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.cxx?r1=1.25.6.8&r2=1.25.6.9 Delta lines: +56 -23 --------------------- --- ModelImpl.cxx 2008-07-23 11:47:58+0000 1.25.6.8 +++ ModelImpl.cxx 2008-07-24 05:33:20+0000 1.25.6.9 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: ModelImpl.cxx,v $ - * $Revision: 1.25.6.8 $ + * $Revision: 1.25.6.9 $ * * This file is part of OpenOffice.org. * @@ -130,6 +130,33 @@ } //============================================================ +//= VosMutexFacade +//============================================================ +//------------------------------------------------------------------------ +VosMutexFacade::VosMutexFacade( ::osl::Mutex& _rMutex ) + :m_rMutex( _rMutex ) +{ +} + +//------------------------------------------------------------------------ +void SAL_CALL VosMutexFacade::acquire() +{ + m_rMutex.acquire(); +} + +//------------------------------------------------------------------------ +sal_Bool SAL_CALL VosMutexFacade::tryToAcquire() +{ + return m_rMutex.tryToAcquire(); +} + +//------------------------------------------------------------------------ +void SAL_CALL VosMutexFacade::release() +{ + m_rMutex.release(); +} + +//============================================================ //= DocumentStorageAccess //============================================================ DBG_NAME( DocumentStorageAccess ) @@ -204,7 +231,7 @@ } catch( const Exception& ) { - OSL_ENSURE( sal_False, "DocumentStorageAccess::dispose: caught an exception!" ); + DBG_UNHANDLED_EXCEPTION(); } } @@ -304,7 +331,7 @@ :m_xModel() ,m_xDataSource() ,m_pStorageAccess( NULL ) - ,m_xMutex( new SharedMutex ) + ,m_aMutexFacade( m_xMutex->getMutex() ) ,m_aContainer(4) ,m_aStorages() ,m_aMacroMode( *this ) @@ -343,7 +370,7 @@ :m_xModel() ,m_xDataSource() ,m_pStorageAccess( NULL ) - ,m_xMutex( new SharedMutex ) + ,m_aMutexFacade( m_xMutex->getMutex() ) ,m_aContainer(4) ,m_aStorages() ,m_aMacroMode( *this ) @@ -541,6 +568,8 @@ m_pStorageAccess->release(); m_pStorageAccess = NULL; } + + m_eInitState = NotInitialized; } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseModelImpl::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException) @@ -718,7 +747,7 @@ } catch( const Exception& ) { - OSL_ENSURE( sal_False, "ODatabaseModelImpl::disposeStorages: caught an exception!" ); + DBG_UNHANDLED_EXCEPTION(); } } m_aStorages.clear(); @@ -930,7 +959,7 @@ } catch( const Exception& ) { - OSL_ENSURE( sal_False, "ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors: caught an exception!" ); + DBG_UNHANDLED_EXCEPTION(); } return bSuccess; } @@ -942,15 +971,22 @@ try { - Reference<XModifiable> xModi(m_xModel.get(),UNO_QUERY); + if ( !isInitialized() ) + { // don't forward to the model if we are not yet initialized + m_bModified = _bModified; + } + else + { + Reference< XModifiable > xModi( m_xModel.get(), UNO_QUERY ); if ( xModi.is() ) xModi->setModified( _bModified ); else m_bModified = _bModified; } - catch(Exception) + } + catch( const Exception& ) { - OSL_ENSURE(0,"ODatabaseModelImpl::setModified: Exception caught!"); + DBG_UNHANDLED_EXCEPTION(); } } @@ -1207,7 +1243,7 @@ { void lcl_modifyListening( ::sfx2::IModifiableDocument& _rDocument, const Reference< XStorage >& _rxStorage, ::rtl::Reference< ::sfx2::DocumentStorageModifyListener >& _inout_rListener, - bool _bListen ) + ::vos::IMutex& _rMutex, bool _bListen ) { Reference< XModifiable > xModify( _rxStorage, UNO_QUERY ); OSL_ENSURE( xModify.is() || !_rxStorage.is(), "lcl_modifyListening: storage can't notify us!" ); @@ -1226,15 +1262,12 @@ if ( xModify.is() && _bListen ) { // the listener from sfx2 uses SolarMutex internally - _inout_rListener = new ::sfx2::DocumentStorageModifyListener( _rDocument ); + _inout_rListener = new ::sfx2::DocumentStorageModifyListener( _rDocument, _rMutex ); xModify->addModifyListener( _inout_rListener.get() ); } } -} -// ----------------------------------------------------------------------------- -namespace -{ + // ------------------------------------------------------------------------- static void lcl_rebaseScriptStorage_throw( const Reference< XStorageBasedLibraryContainer >& _rxContainer, const Reference< XStorage >& _rxNewRootStorage ) { @@ -1252,13 +1285,13 @@ Reference< XStorage > ODatabaseModelImpl::impl_switchToStorage_throw( const Reference< XStorage >& _rxNewRootStorage ) { // stop listening for modifications at the old storage - lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, false ); + lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, false ); // set new storage m_xDocumentStorage.reset( _rxNewRootStorage, SharedStorage::TakeOwnership ); // start listening for modifications - lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, true ); + lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, true ); // forward new storage to Basic and Dialog library containers lcl_rebaseScriptStorage_throw( m_xBasicLibraries, m_xDocumentStorage.getTyped() ); File [changed]: ModelImpl.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.hxx?r1=1.24.4.2&r2=1.24.4.3 Delta lines: +48 -5 -------------------- --- ModelImpl.hxx 2008-07-23 11:45:13+0000 1.24.4.2 +++ ModelImpl.hxx 2008-07-24 05:33:20+0000 1.24.4.3 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: ModelImpl.hxx,v $ - * $Revision: 1.24.4.2 $ + * $Revision: 1.24.4.3 $ * * This file is part of OpenOffice.org. * @@ -79,7 +79,7 @@ #include <sfx2/docstoragemodifylistener.hxx> #include <tools/string.hxx> #include <unotools/sharedunocomponent.hxx> -#include <vos/ref.hxx> +#include <vos/mutex.hxx> #include <memory> @@ -117,6 +117,9 @@ //============================================================ //= SharedMutex //============================================================ +/** a shared mutex, which deletes itself as soon as the last reference + to it dies. +*/ class SharedMutex { private: @@ -136,6 +139,45 @@ }; //============================================================ +//= SharedMutexHolder +//============================================================ +/** a base class merely holding a SharedMutex instance. Useful if you + need to ensure the SharedMutex is to be initialized before other + of your members, in this case just derive from SharedMutexHolder. +*/ +class SharedMutexHolder +{ +protected: + SharedMutexHolder() : m_xMutex( new SharedMutex ) { } + ~SharedMutexHolder() { } + +protected: + ::rtl::Reference< SharedMutex > m_xMutex; +}; + +//============================================================ +//= VosMutexFacade +//============================================================ +/** a class which provides an IMutex interface to an OSL-based mutex +*/ +class VosMutexFacade : public ::vos::IMutex +{ +public: + /** beware of life time: the mutex you pass here must live as least as long + as the VosMutexFacade instance lives. + */ + VosMutexFacade( ::osl::Mutex& _rMutex ); + + // IMutex + virtual void SAL_CALL acquire(); + virtual sal_Bool SAL_CALL tryToAcquire(); + virtual void SAL_CALL release(); + +private: + ::osl::Mutex& m_rMutex; +}; + +//============================================================ //= ODatabaseModelImpl //============================================================ DECLARE_STL_USTRINGACCESS_MAP(::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >,TStorages); @@ -145,7 +187,8 @@ class ODatabaseContext; class DocumentStorageAccess; class OSharedConnectionManager; -class ODatabaseModelImpl :public ::rtl::IReference +class ODatabaseModelImpl :public SharedMutexHolder + ,public ::rtl::IReference ,public ::sfx2::IMacroDocumentAccess ,public ::sfx2::IModifiableDocument { @@ -170,7 +213,7 @@ ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDataSource > m_xDataSource; DocumentStorageAccess* m_pStorageAccess; - ::rtl::Reference< SharedMutex > m_xMutex; + VosMutexFacade m_aMutexFacade; ::std::vector< TContentPtr > m_aContainer; // one for each ObjectType TStorages m_aStorages; ::sfx2::DocumentMacroMode m_aMacroMode; @@ -607,7 +650,7 @@ throw ::com::sun::star::lang::NotInitializedException( ::rtl::OUString(), getThis() ); } - /** checks whether the component currently being initialized, or already initialized, + /** checks whether the component is currently being initialized, or already initialized, throws a DoubleInitializationException if so only to be called after checkDisposed! --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
