Tag: cws_src680_dba202a User: fs Date: 05/11/25 05:37:25 Modified: /dba/dbaccess/source/core/dataaccess/ ModelImpl.cxx, ModelImpl.hxx, databasedocument.cxx, databasedocument.hxx, datasource.cxx, datasource.hxx
Log: #126702# DatabaseDocument and DataSource share a common mutex instances now (held by ModelImpl) / DatabaseDocument::clearConnections more tolerant against re-entrance 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.9&r2=1.9.12.1 Delta lines: +15 -9 -------------------- --- ModelImpl.cxx 24 Oct 2005 08:28:12 -0000 1.9 +++ ModelImpl.cxx 25 Nov 2005 13:37:20 -0000 1.9.12.1 @@ -4,9 +4,9 @@ * * $RCSfile: ModelImpl.cxx,v $ * - * $Revision: 1.9 $ + * $Revision: 1.9.12.1 $ * - * last change: $Author: rt $ $Date: 2005/10/24 08:28:12 $ + * last change: $Author: fs $ $Date: 2005/11/25 13:37:20 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -117,9 +117,6 @@ #ifndef _DBA_CORE_CONNECTION_HXX_ #include "connection.hxx" #endif -#ifndef _COMPHELPER_GUARDING_HXX_ -#include <comphelper/guarding.hxx> -#endif #ifndef _RTL_DIGEST_H_ #include <rtl/digest.h> #endif @@ -472,8 +469,11 @@ //------------------------------------------------------------------------------ void ODatabaseModelImpl::clearConnections() { + OWeakConnectionArray aConnections; + aConnections.swap( m_aConnections ); + Reference< XConnection > xConn; - for (OWeakConnectionArray::iterator i = m_aConnections.begin(); m_aConnections.end() != i; ++i) + for ( OWeakConnectionArray::iterator i = aConnections.begin(); aConnections.end() != i; ++i ) { xConn = *i; if ( xConn.is() ) @@ -488,7 +488,6 @@ } } } - m_aConnections.clear(); m_pSharedConnectionManager = NULL; m_xSharedConnectionManager = NULL; @@ -873,6 +872,13 @@ throw IOException(); } } + +// ----------------------------------------------------------------------------- +ModelDependentComponent::ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model ) + :m_pImpl( _model ) +{ +} + //........................................................................ } // namespace dbaccess //........................................................................ File [changed]: ModelImpl.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/ModelImpl.hxx?r1=1.8&r2=1.8.32.1 Delta lines: +85 -4 -------------------- --- ModelImpl.hxx 8 Sep 2005 10:17:45 -0000 1.8 +++ ModelImpl.hxx 25 Nov 2005 13:37:21 -0000 1.8.32.1 @@ -4,9 +4,9 @@ * * $RCSfile: ModelImpl.hxx,v $ * - * $Revision: 1.8 $ + * $Revision: 1.8.32.1 $ * - * last change: $Author: rt $ $Date: 2005/09/08 10:17:45 $ + * last change: $Author: fs $ $Date: 2005/11/25 13:37:21 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -185,6 +185,7 @@ ::com::sun::star::uno::WeakReference< ::com::sun::star::sdbc::XDataSource> m_xDataSource; DocumentStorageAccess* m_pStorageAccess; + ::osl::Mutex m_aMutex; public: @@ -404,6 +405,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 @@ -416,7 +418,7 @@ ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentSubStorageSupplier > getDocumentSubStorageSupplier(); -// void clear(); + inline ::osl::Mutex& getMutex() { return m_aMutex; } /** @see osl_incrementInterlockedCount. */ @@ -427,6 +429,85 @@ virtual oslInterlockedCount SAL_CALL release(); +}; + +/** a small base class for UNO components whose functionality depends on a ODatabaseModelImpl +*/ +class ModelDependentComponent +{ +protected: + ::rtl::Reference< ODatabaseModelImpl > m_pImpl; + +protected: + ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model ); + + /** returns the component itself + */ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getThis() = 0; + +public: + struct GuardAccess { friend class ModelMethodGuard; private: GuardAccess() { } }; + + /** returns the mutex used for thread safety + + Since our mutex is implemented in the ODatabaseModelImpl, the method will throw + a ::com::sun::star::lang::DisposedException + + @throws ::com::sun::star::lang::DisposedException + if the model is already disposed + */ + inline ::osl::Mutex& getMutex( GuardAccess ) + { + if ( !m_pImpl.is() ) + throw ::com::sun::star::lang::DisposedException( ::rtl::OUString(), getThis() ); + return m_pImpl->getMutex(); + } + inline ::rtl::Reference< ODatabaseModelImpl > getImpl( GuardAccess ) + { + return m_pImpl; + } +}; + +/** 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 ::rtl::Reference< ODatabaseModelImpl > + ,public ::osl::ResettableMutexGuard + // order matters! Need to ensure that m_aImplGuard is destroyed *before* + // m_pKeepModelAlive, since the latter will also destroy the mutex which + // m_aImplGuard refers to. +{ +private: + typedef ::rtl::Reference< ODatabaseModelImpl > BaseModelGuard; + 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 ) + :BaseModelGuard( _component.getImpl( ModelDependentComponent::GuardAccess() ) ) + ,BaseMutexGuard( _component.getMutex( ModelDependentComponent::GuardAccess() ) ) + { + } + + inline void clear() + { + BaseMutexGuard::clear(); + } + + inline void reset() + { + BaseMutexGuard::reset(); + } }; //........................................................................ File [changed]: databasedocument.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/databasedocument.cxx?r1=1.22&r2=1.22.26.1 Delta lines: +145 -142 ----------------------- --- databasedocument.cxx 23 Sep 2005 12:04:55 -0000 1.22 +++ databasedocument.cxx 25 Nov 2005 13:37:21 -0000 1.22.26.1 @@ -4,9 +4,9 @@ * * $RCSfile: databasedocument.cxx,v $ * - * $Revision: 1.22 $ + * $Revision: 1.22.26.1 $ * - * last change: $Author: hr $ $Date: 2005/09/23 12:04:55 $ + * last change: $Author: fs $ $Date: 2005/11/25 13:37:21 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -41,9 +41,6 @@ #ifndef DBACCESS_SHARED_DBASTRINGS_HRC #include "dbastrings.hrc" #endif -#ifndef _COMPHELPER_GUARDING_HXX_ -#include <comphelper/guarding.hxx> -#endif #include <comphelper/documentconstants.hxx> #ifndef _COM_SUN_STAR_EMBED_XTRANSACTEDOBJECT_HPP_ #include <com/sun/star/embed/XTransactedObject.hpp> @@ -109,6 +106,10 @@ #include <tools/debug.hxx> #endif +#ifndef BOOST_BIND_HPP_INCLUDED +#include <boost/bind.hpp> +#endif + namespace css = ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; @@ -163,11 +164,11 @@ } //-------------------------------------------------------------------------- ODatabaseDocument::ODatabaseDocument(const ::rtl::Reference<ODatabaseModelImpl>& _pImpl ) - :ODatabaseDocument_OfficeDocument(m_aMutex) - ,m_pImpl(_pImpl) - ,m_aModifyListeners(m_aMutex) - ,m_aCloseListener(m_aMutex) - ,m_aDocEventListeners(m_aMutex) + :ODatabaseDocument_OfficeDocument( _pImpl->getMutex() ) + ,ModelDependentComponent(_pImpl) + ,m_aModifyListeners( _pImpl->getMutex() ) + ,m_aCloseListener( _pImpl->getMutex() ) + ,m_aDocEventListeners( _pImpl->getMutex() ) { DBG_CTOR(ODatabaseDocument,NULL); @@ -243,8 +244,7 @@ // ATTENTION: The Application controller attaches the same resource to force a reload. sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _aArguments ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); try @@ -333,8 +333,7 @@ // ----------------------------------------------------------------------------- ::rtl::OUString SAL_CALL ODatabaseDocument::getURL( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); return m_pImpl->m_sRealFileURL; @@ -342,8 +341,7 @@ // ----------------------------------------------------------------------------- Sequence< PropertyValue > SAL_CALL ODatabaseDocument::getArgs( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); return m_pImpl->m_aArgs; @@ -351,8 +349,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::connectController( const Reference< XController >& _xController ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); m_pImpl->m_aControllers.push_back(_xController); @@ -360,8 +357,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::disconnectController( const Reference< XController >& _xController ) throw (RuntimeException) { - ClearableMutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); m_pImpl->m_aControllers.erase(::std::find(m_pImpl->m_aControllers.begin(),m_pImpl->m_aControllers.end(),_xController)); @@ -371,8 +367,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::lockControllers( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); ++m_pImpl->m_nControllerLockCount; @@ -380,8 +375,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::unlockControllers( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); --m_pImpl->m_nControllerLockCount; @@ -389,8 +383,7 @@ // ----------------------------------------------------------------------------- sal_Bool SAL_CALL ODatabaseDocument::hasControllersLocked( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); return m_pImpl->m_nControllerLockCount != 0; @@ -398,8 +391,7 @@ // ----------------------------------------------------------------------------- Reference< XController > SAL_CALL ODatabaseDocument::getCurrentController() throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); return m_pImpl->m_xCurrentController.is() ? m_pImpl->m_xCurrentController : ( m_pImpl->m_aControllers.empty() ? Reference< XController >() : *m_pImpl->m_aControllers.begin() ); @@ -407,8 +399,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::setCurrentController( const Reference< XController >& _xController ) throw (NoSuchElementException, RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); m_pImpl->m_xCurrentController = _xController; @@ -416,8 +407,7 @@ // ----------------------------------------------------------------------------- Reference< XInterface > SAL_CALL ODatabaseDocument::getCurrentSelection( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); Reference< XInterface > xRet; @@ -432,8 +422,7 @@ // XStorable sal_Bool SAL_CALL ODatabaseDocument::hasLocation( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); return m_pImpl->m_sRealFileURL.getLength() != 0; @@ -441,8 +430,7 @@ // ----------------------------------------------------------------------------- ::rtl::OUString SAL_CALL ODatabaseDocument::getLocation( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); return m_pImpl->m_sRealFileURL; @@ -450,8 +438,7 @@ // ----------------------------------------------------------------------------- sal_Bool SAL_CALL ODatabaseDocument::isReadonly( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); return m_pImpl->m_bDocumentReadOnly; @@ -459,8 +446,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::store( ) throw (IOException, RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); if ( m_pImpl->m_sFileURL == m_pImpl->m_sRealFileURL ) @@ -468,7 +454,7 @@ else storeAsURL( m_pImpl->m_sRealFileURL, m_pImpl->m_aArgs ); - notifyEvent(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OnSaveDone"))); + impl_notifyEvent( "OnSaveDone", aGuard ); } // ----------------------------------------------------------------------------- void ODatabaseDocument::store(const ::rtl::OUString& _rURL @@ -491,13 +477,13 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::storeAsURL( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (IOException, RuntimeException) { - ClearableMutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); Reference< XSingleServiceFactory > xStorageFactory( m_pImpl->createStorageFactory() ); - if ( xStorageFactory.is() ) - { + if ( !xStorageFactory.is() ) + throw RuntimeException(); + // don't use _rURL - we might be recovering/salvaging a file currently ... // #i45314# / 2005-03-21 / [EMAIL PROTECTED] ::comphelper::MediaDescriptor aDescriptor( _rArguments ); @@ -557,17 +543,15 @@ } lcl_stripLoadArguments( aDescriptor, m_pImpl->m_aArgs ); store(m_pImpl->m_sFileURL,_rArguments); - notifyEvent(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OnSaveAsDone"))); - } - else - throw IOException(); + + impl_notifyEvent( "OnSaveAsDone", aGuard ); } + // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::storeToURL( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (IOException, RuntimeException) { - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); - MutexGuard aGuard(m_aMutex); Reference< XSingleServiceFactory > xStorageFactory( m_pImpl->createStorageFactory() ); Sequence<Any> aParam(2); @@ -627,8 +611,7 @@ // XModifiable sal_Bool SAL_CALL ODatabaseDocument::isModified( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); return m_pImpl->m_bModified; @@ -636,17 +619,21 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::setModified( sal_Bool _bModified ) throw (PropertyVetoException, RuntimeException) { - ResettableMutexGuard _rGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); + + if ( m_pImpl->m_bModified == _bModified ) + return; - if ( m_pImpl->m_bModified != _bModified ) - { m_pImpl->m_bModified = _bModified; - lang::EventObject aEvt(*this); - NOTIFY_LISTERNERS(m_aModifyListeners,XModifyListener,modified) - notifyEvent(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OnModifyChanged"))); - } + lang::EventObject aEvt( *this ); + + aGuard.clear(); + m_aModifyListeners.notifyEach( &XModifyListener::modified, aEvt ); + + aGuard.reset(); + impl_notifyEvent( "OnModifyChanged", aGuard ); } + // ::com::sun::star::document::XEventBroadcaster void SAL_CALL ODatabaseDocument::addEventListener(const css::uno::Reference< css::document::XEventListener >& _xListener ) throw (css::uno::RuntimeException) { @@ -663,9 +650,10 @@ // ::com::sun::star::document::XEventListener void SAL_CALL ODatabaseDocument::notifyEvent( const css::document::EventObject& aEvent ) throw (css::uno::RuntimeException) { + ModelMethodGuard aGuard( *this ); // used only to forward external events (e.g. for doc creation) from the frame loader // to the global event broadcaster and all other interested doc event listener. - notifyEvent(aEvent.EventName); + impl_notifyEvent( aEvent.EventName, aGuard ); } // ----------------------------------------------------------------------------- // ::com::sun::star::view::XPrintable @@ -710,19 +698,24 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseDocument::close( sal_Bool _bDeliverOwnership ) throw (::com::sun::star::util::CloseVetoException, RuntimeException) { - ResettableMutexGuard _rGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); + + lang::EventObject aEvent( *this ); - lang::EventObject aEvt( static_cast< ::cppu::OWeakObject* >( this ) ); { - NOTIFY_LISTERNERS1(m_aCloseListener,com::sun::star::util::XCloseListener,queryClosing,_bDeliverOwnership); + aGuard.clear(); + m_aCloseListener.forEach< XCloseListener >( + boost::bind( &XCloseListener::queryClosing, _1, boost::cref( aEvent ), boost::cref( _bDeliverOwnership ) ) ); + aGuard.reset(); } DBG_ASSERT( m_pImpl->m_aControllers.empty(), "ODatabaseDocument::close: aren't controllers expected to veto the closing?" ); impl_closeControllerFrames( _bDeliverOwnership ); { - NOTIFY_LISTERNERS(m_aCloseListener,com::sun::star::util::XCloseListener,notifyClosing); + aGuard.clear(); + m_aCloseListener.notifyEach( &XCloseListener::notifyClosing, aEvent ); + aGuard.reset(); } dispose(); @@ -742,8 +735,7 @@ // ----------------------------------------------------------------------------- Reference< XNameAccess > SAL_CALL ODatabaseDocument::getFormDocuments( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); Reference< XNameAccess > xContainer = m_pImpl->m_xForms; @@ -764,8 +756,7 @@ // ----------------------------------------------------------------------------- Reference< XNameAccess > SAL_CALL ODatabaseDocument::getReportDocuments( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); Reference< XNameAccess > xContainer = m_pImpl->m_xReports; @@ -966,8 +957,7 @@ // ----------------------------------------------------------------------------- Reference< ::com::sun::star::ui::XUIConfigurationManager > SAL_CALL ODatabaseDocument::getUIConfigurationManager( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); if ( !m_xUIConfigurationManager.is() ) @@ -1011,8 +1001,7 @@ // ----------------------------------------------------------------------------- Reference< XStorage > SAL_CALL ODatabaseDocument::getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(ODatabaseDocument_OfficeDocument::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); Reference< XDocumentSubStorageSupplier > xStorageAccess( m_pImpl->getDocumentSubStorageSupplier() ); return xStorageAccess->getDocumentSubStorage( aStorageName, nMode ); @@ -1024,30 +1013,27 @@ return xStorageAccess->getDocumentSubStoragesNames(); } // ----------------------------------------------------------------------------- -void ODatabaseDocument::notifyEvent(const ::rtl::OUString& _sEventName) +void ODatabaseDocument::impl_notifyEvent( const ::rtl::OUString& _sEventName, ::osl::ClearableMutexGuard& _rGuard ) { try { - ResettableMutexGuard _rGuard(m_aMutex); - if (ODatabaseDocument_OfficeDocument::rBHelper.bDisposed) - throw DisposedException(); - css::document::EventObject aEvt(*this, _sEventName); - /// TODO: this code has to be deleted after as cws will be integrated + Reference< XEventListener > xDocEventBroadcaster; + /// TODO: this code has to be deleted after AS' cws will be integrated try { - Reference< ::com::sun::star::document::XEventListener > xDocEventBroadcaster(m_pImpl->m_xServiceFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.GlobalEventBroadcaster"))), - UNO_QUERY); - if ( xDocEventBroadcaster.is() ) - { - xDocEventBroadcaster->notifyEvent(aEvt); - } + xDocEventBroadcaster = xDocEventBroadcaster.query( m_pImpl->m_xServiceFactory->createInstance( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.frame.GlobalEventBroadcaster" ) ) ) ); } catch(Exception) { OSL_ENSURE(0,"Could not create GlobalEventBroadcaster!"); } - NOTIFY_LISTERNERS(m_aDocEventListeners,css::document::XEventListener,notifyEvent) + + _rGuard.clear(); + if ( xDocEventBroadcaster.is() ) + xDocEventBroadcaster->notifyEvent(aEvt); + m_aDocEventListeners.notifyEach( &css::document::XEventListener::notifyEvent, aEvt ); } catch(Exception&) { @@ -1056,15 +1042,24 @@ //------------------------------------------------------------------------------ void ODatabaseDocument::disposing() { + if ( !m_pImpl.is() ) + { + // this means that we're already disposed + DBG_ASSERT( ODatabaseDocument_OfficeDocument::rBHelper.bDisposed, "ODatabaseDocument::disposing: no impl anymore, but not yet disposed!" ); + return; + } + DBG_ASSERT( m_pImpl->m_aControllers.empty(), "ODatabaseDocument::disposing: there still are controllers!" ); // normally, nobody should explicitly dispose, but only XCloseable::close the document. And controllers // are expected to veto the closing, so when we're here, there shouldn't be any controllers anymore. - if ( m_pImpl.is() ) m_pImpl->m_aControllers.clear(); Reference< XModel > xHoldAlive( this ); { - notifyEvent(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OnUnload"))); + { + ::osl::ClearableMutexGuard aGuard( m_pImpl->getMutex() ); + impl_notifyEvent( "OnUnload", aGuard ); + } css::lang::EventObject aDisposeEvent(static_cast<XWeak*>(this)); m_aModifyListeners.disposeAndClear( aDisposeEvent ); @@ -1150,6 +1145,7 @@ // ----------------------------------------------------------------------------- Reference< XDataSource > SAL_CALL ODatabaseDocument::getDataSource() throw (RuntimeException) { + ModelMethodGuard aGuard( *this ); OSL_ENSURE(m_pImpl.is(),"Impl is NULL"); return m_pImpl->getDataSource(); } @@ -1159,6 +1155,13 @@ if ( m_pImpl.is() ) m_pImpl->disposing(Source); } + +//------------------------------------------------------------------ +Reference< XInterface > ODatabaseDocument::getThis() +{ + return *this; +} + //------------------------------------------------------------------ //........................................................................ } // namespace dbaccess File [changed]: databasedocument.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/databasedocument.hxx?r1=1.6&r2=1.6.26.1 Delta lines: +20 -8 -------------------- --- databasedocument.hxx 23 Sep 2005 12:05:10 -0000 1.6 +++ databasedocument.hxx 25 Nov 2005 13:37:22 -0000 1.6.26.1 @@ -4,9 +4,9 @@ * * $RCSfile: databasedocument.hxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.6.26.1 $ * - * last change: $Author: hr $ $Date: 2005/09/23 12:05:10 $ + * last change: $Author: fs $ $Date: 2005/11/25 13:37:22 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -108,8 +108,8 @@ //, ::com::sun::star::document::XStorageBasedDocument > ODatabaseDocument_OfficeDocument; -class ODatabaseDocument : public ::comphelper::OBaseMutex - ,public ODatabaseDocument_OfficeDocument +class ODatabaseDocument :public ODatabaseDocument_OfficeDocument + ,public ModelDependentComponent { ::com::sun::star::uno::Reference< ::com::sun::star::ui::XUIConfigurationManager> m_xUIConfigurationManager; ::com::sun::star::uno::Reference< ::com::sun::star::document::XEventListener > m_xDocEventBroadcaster; @@ -117,7 +117,6 @@ ::cppu::OInterfaceContainerHelper m_aModifyListeners; ::cppu::OInterfaceContainerHelper m_aCloseListener; ::cppu::OInterfaceContainerHelper m_aDocEventListeners; - ::rtl::Reference<ODatabaseModelImpl> m_pImpl; sal_Bool m_bCommitMasterStorage; void setMeAsParent(const ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess >& _xName); @@ -142,8 +141,18 @@ OnSaveDone => "Save" ended OnSaveAsDone => "SaveAs" ended OnModifyChanged => modified/unmodified + @param _rClearForNotify + a guard to our mutex, which will be cleared (i.e. the mutex released) immediately before + the notification happens */ - void notifyEvent(const ::rtl::OUString& _sEventName); + void impl_notifyEvent( const ::rtl::OUString& _sEventName, ::osl::ClearableMutexGuard& _rClearForNotify ); + + /** notifies the global event broadcaster + */ + inline void impl_notifyEvent( const sal_Char* _pAsciiEventName, ::osl::ClearableMutexGuard& _rClearForNotify ) + { + impl_notifyEvent( ::rtl::OUString::createFromAscii( _pAsciiEventName ), _rClearForNotify ); + } /// write a single XML stream into the package sal_Bool WriteThroughComponent( @@ -187,6 +196,9 @@ , const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& _xStorageToSaveTo); + // ModelDependentComponent overridables + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getThis(); + private: ODatabaseDocument(const ::rtl::Reference<ODatabaseModelImpl>& _pImpl); // Do NOT create those documents directly, always use ODatabaseModelImpl::getModel. Reason is that File [changed]: datasource.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/datasource.cxx?r1=1.64&r2=1.64.12.1 Delta lines: +37 -48 --------------------- --- datasource.cxx 24 Oct 2005 08:28:36 -0000 1.64 +++ datasource.cxx 25 Nov 2005 13:37:22 -0000 1.64.12.1 @@ -4,9 +4,9 @@ * * $RCSfile: datasource.cxx,v $ * - * $Revision: 1.64 $ + * $Revision: 1.64.12.1 $ * - * last change: $Author: rt $ $Date: 2005/10/24 08:28:36 $ + * last change: $Author: fs $ $Date: 2005/11/25 13:37:22 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -45,6 +45,9 @@ #ifndef _TOOLS_DEBUG_HXX #include <tools/debug.hxx> #endif +#ifndef TOOLS_DIAGNOSE_EX_H +#include <tools/diagnose_ex.h> +#endif #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ #include <cppuhelper/typeprovider.hxx> #endif @@ -605,11 +608,11 @@ //-------------------------------------------------------------------------- ODatabaseSource::ODatabaseSource(const ::rtl::Reference<ODatabaseModelImpl>& _pImpl) - :OSubComponent(m_aMutex, Reference< XInterface >()) + :ModelDependentComponent( _pImpl ) + ,OSubComponent( _pImpl->getMutex(), Reference< XInterface >() ) ,OPropertySetHelper(OComponentHelper::rBHelper) - ,m_aBookmarks(*this, m_aMutex) - ,m_pImpl(_pImpl) - ,m_aFlushListeners(m_aMutex) + ,m_aBookmarks( *this, _pImpl->getMutex() ) + ,m_aFlushListeners( _pImpl->getMutex() ) { // some kind of default DBG_CTOR(ODatabaseSource,NULL); @@ -1052,15 +1055,14 @@ //------------------------------------------------------------------------------ void ODatabaseSource::setLoginTimeout(sal_Int32 seconds) throw( SQLException, RuntimeException ) { - ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed); - MutexGuard aGuard(m_aMutex); + ModelMethodGuard aGuard( *this ); m_pImpl->m_nLoginTimeout = seconds; } //------------------------------------------------------------------------------ sal_Int32 ODatabaseSource::getLoginTimeout(void) throw( SQLException, RuntimeException ) { - ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); return m_pImpl->m_nLoginTimeout; } @@ -1089,8 +1091,7 @@ // ----------------------------------------------------------------------------- Reference< XConnection > SAL_CALL ODatabaseSource::connectWithCompletion( const Reference< XInteractionHandler >& _rxHandler,sal_Bool _bIsolated ) throw(SQLException, RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); if (!_rxHandler.is()) { @@ -1126,13 +1127,13 @@ // handle the request try { - MutexRelease aRelease(m_aMutex); + MutexRelease aRelease( m_pImpl->getMutex() ); // release the mutex when calling the handler, it may need to lock the SolarMutex _rxHandler->handle(xRequest); } catch(Exception&) { - DBG_ERROR("ODatabaseSource::connectWithCompletion: caught an exception while calling the handler!"); + DBG_UNHANDLED_EXCEPTION(); } if (!pAuthenticate->wasSelected()) @@ -1183,8 +1184,7 @@ //------------------------------------------------------------------------------ Reference< XConnection > ODatabaseSource::getConnection(const rtl::OUString& user, const rtl::OUString& password,sal_Bool _bIsolated) throw( SQLException, RuntimeException ) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); Reference< XConnection > xConn; if ( _bIsolated ) @@ -1215,15 +1215,15 @@ //------------------------------------------------------------------------------ Reference< XNameAccess > SAL_CALL ODatabaseSource::getBookmarks( ) throw (RuntimeException) { - MutexGuard aGuard(m_aMutex); + ModelMethodGuard aGuard( *this ); return static_cast< XNameContainer* >(&m_aBookmarks); } //------------------------------------------------------------------------------ Reference< XNameAccess > SAL_CALL ODatabaseSource::getQueryDefinitions( ) throw(RuntimeException) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); + Reference< XNameAccess > xContainer = m_pImpl->m_xCommandDefinitions; if ( !xContainer.is() ) { @@ -1236,31 +1236,13 @@ } return xContainer; } -// ----------------------------------------------------------------------------- -class OConnectionNotifier //: public ::std::unary_function<OWeakConnection,void> -{ -public: - OConnectionNotifier() - { - } - - void operator()(OWeakConnection& _xConnection) - { - } -}; -// ----------------------------------------------------------------------------- -void ODatabaseSource::flushTables() -{ - // flush all tables and queries - ::std::for_each(m_pImpl->m_aConnections.begin(),m_pImpl->m_aConnections.end(),OConnectionNotifier()); -} //------------------------------------------------------------------------------ // XTablesSupplier //------------------------------------------------------------------------------ Reference< XNameAccess > ODatabaseSource::getTables() throw( RuntimeException ) { - MutexGuard aGuard(m_aMutex); - ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed); + ModelMethodGuard aGuard( *this ); + Reference< XNameAccess > xContainer = m_pImpl->m_xTableDefinitions; if ( !xContainer.is() ) { @@ -1276,18 +1258,17 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseSource::flush( ) throw (RuntimeException) { + ModelMethodGuard aGuard( *this ); try { - ResettableMutexGuard _rGuard(m_aMutex); - ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed); - SharedModel xModel( impl_getModel( true ) ); Reference< css::frame::XStorable> xStorable( xModel, UNO_QUERY ); if ( xStorable.is() ) xStorable->store(); - css::lang::EventObject aEvt(*this); - NOTIFY_LISTERNERS(m_aFlushListeners,XFlushListener,flushed) + css::lang::EventObject aFlushedEvent(*this); + aGuard.clear(); + m_aFlushListeners.notifyEach( &XFlushListener::flushed, aFlushedEvent ); } catch(Exception&) { @@ -1297,8 +1278,7 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseSource::flushed( const EventObject& rEvent ) throw (RuntimeException) { - ::connectivity::checkDisposed(OComponentHelper::rBHelper.bDisposed); - MutexGuard aGuard(m_aMutex); + ModelMethodGuard aGuard( *this ); // Okay, this is some hack. // @@ -1341,18 +1321,21 @@ // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseSource::elementInserted( const ContainerEvent& Event ) throw (RuntimeException) { + ModelMethodGuard aGuard( *this ); if ( m_pImpl.is() ) m_pImpl->setModified(sal_True); } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseSource::elementRemoved( const ContainerEvent& Event ) throw (RuntimeException) { + ModelMethodGuard aGuard( *this ); if ( m_pImpl.is() ) m_pImpl->setModified(sal_True); } // ----------------------------------------------------------------------------- void SAL_CALL ODatabaseSource::elementReplaced( const ContainerEvent& Event ) throw (RuntimeException) { + ModelMethodGuard aGuard( *this ); if ( m_pImpl.is() ) m_pImpl->setModified(sal_True); } @@ -1372,11 +1355,17 @@ // XDocumentDataSource Reference< XOfficeDatabaseDocument > SAL_CALL ODatabaseSource::getDatabaseDocument() throw (RuntimeException) { + ModelMethodGuard aGuard( *this ); return Reference< XOfficeDatabaseDocument >( impl_getModel( false ), UNO_QUERY ); // by definition, clients of getDatabaseDocument are responsible for the model they obtain, // including responsibility for (attempting to) close the model when they don't need it anymore. // Thus the "false" parameter in the call to impl_getModel: We don't take the ownership // of the model, even if it had to be newly created during this call. +} +// ----------------------------------------------------------------------------- +Reference< XInterface > ODatabaseSource::getThis() +{ + return *this; } // ----------------------------------------------------------------------------- //........................................................................ File [changed]: datasource.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/core/dataaccess/datasource.hxx?r1=1.33&r2=1.33.12.1 Delta lines: +12 -12 --------------------- --- datasource.hxx 24 Oct 2005 08:28:48 -0000 1.33 +++ datasource.hxx 25 Nov 2005 13:37:23 -0000 1.33.12.1 @@ -4,9 +4,9 @@ * * $RCSfile: datasource.hxx,v $ * - * $Revision: 1.33 $ + * $Revision: 1.33.12.1 $ * - * last change: $Author: rt $ $Date: 2005/10/24 08:28:48 $ + * last change: $Author: fs $ $Date: 2005/11/25 13:37:23 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -177,7 +177,7 @@ > ODatabaseSource_Base; -class ODatabaseSource :public ::comphelper::OBaseMutex +class ODatabaseSource :public ModelDependentComponent ,public OSubComponent ,public ::cppu::OPropertySetHelper ,public ::comphelper::OPropertyArrayUsageHelper < ODatabaseSource > @@ -193,7 +193,6 @@ typedef ::utl::SharedUNOComponent< ::com::sun::star::frame::XModel, ::utl::CloseableComponent > SharedModel; - ::rtl::Reference<ODatabaseModelImpl> m_pImpl; OBookmarkContainer m_aBookmarks; ::cppu::OInterfaceContainerHelper m_aFlushListeners; @@ -288,6 +287,10 @@ // XDocumentDataSource virtual ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XOfficeDatabaseDocument > SAL_CALL getDatabaseDocument() throw (::com::sun::star::uno::RuntimeException); +protected: + // ModelDependentComponent overridables + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > getThis(); + private: // helper /** open a connection for the current settings. this is the simple connection we get from the driver @@ -312,9 +315,6 @@ and ownership of the model is not taken. */ SharedModel impl_getModel( bool _bTakeOwnershipIfNewlyCreated ); - -// other stuff - void flushTables(); ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL getConnection( const ::rtl::OUString& user, const ::rtl::OUString& password , sal_Bool _bIsolated) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); ::com::sun::star::uno::Reference< ::com::sun::star::sdbc::XConnection > SAL_CALL connectWithCompletion( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& handler , sal_Bool _bIsolated) throw(::com::sun::star::sdbc::SQLException, ::com::sun::star::uno::RuntimeException); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
