framework/source/uifactory/uielementfactorymanager.cxx | 95 ++++++++--------- toolkit/source/controls/grid/gridcolumn.cxx | 51 ++++----- toolkit/source/controls/grid/gridcolumn.hxx | 19 +-- 3 files changed, 78 insertions(+), 87 deletions(-)
New commits: commit 174b39754e45f4df0e0123336f3ed298bf81ebc4 Author: Noel Grandin <[email protected]> AuthorDate: Fri Dec 24 20:37:14 2021 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Mon Dec 27 07:34:29 2021 +0100 use comphelper::WeakComponentImplHelper in GridColumn Change-Id: Ibadee8190f254f8af1f76a69a5671010e6dd0016 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127459 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/toolkit/source/controls/grid/gridcolumn.cxx b/toolkit/source/controls/grid/gridcolumn.cxx index fa2119d434bc..6d94ecb9a72b 100644 --- a/toolkit/source/controls/grid/gridcolumn.cxx +++ b/toolkit/source/controls/grid/gridcolumn.cxx @@ -39,8 +39,7 @@ namespace toolkit GridColumn::GridColumn() - :GridColumn_Base( m_aMutex ) - ,m_nIndex(-1) + :m_nIndex(-1) ,m_nDataColumnIndex(-1) ,m_nColumnWidth(4) ,m_nMaxWidth(0) @@ -53,9 +52,7 @@ namespace toolkit GridColumn::GridColumn( GridColumn const & i_copySource ) - :cppu::BaseMutex() - ,GridColumn_Base( m_aMutex ) - ,m_aIdentifier( i_copySource.m_aIdentifier ) + :m_aIdentifier( i_copySource.m_aIdentifier ) ,m_nIndex( -1 ) ,m_nDataColumnIndex( i_copySource.m_nDataColumnIndex ) ,m_nColumnWidth( i_copySource.m_nColumnWidth ) @@ -76,7 +73,7 @@ namespace toolkit void GridColumn::broadcast_changed( char const * const i_asciiAttributeName, const Any& i_oldValue, const Any& i_newValue, - ::comphelper::ComponentGuard& i_Guard ) + std::unique_lock<std::mutex>& i_Guard ) { Reference< XInterface > const xSource( static_cast< ::cppu::OWeakObject* >( this ) ); GridColumnEvent const aEvent( @@ -84,31 +81,28 @@ namespace toolkit i_oldValue, i_newValue, m_nIndex ); - ::cppu::OInterfaceContainerHelper* pIter = rBHelper.getContainer( cppu::UnoType<XGridColumnListener>::get() ); - - i_Guard.clear(); - if( pIter ) - pIter->notifyEach( &XGridColumnListener::columnChanged, aEvent ); + i_Guard.unlock(); + maGridColumnListeners.notifyEach( &XGridColumnListener::columnChanged, aEvent ); } css::uno::Any SAL_CALL GridColumn::getIdentifier() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); return m_aIdentifier; } void SAL_CALL GridColumn::setIdentifier(const css::uno::Any & value) { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); m_aIdentifier = value; } ::sal_Int32 SAL_CALL GridColumn::getColumnWidth() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); return m_nColumnWidth; } @@ -121,7 +115,7 @@ namespace toolkit ::sal_Int32 SAL_CALL GridColumn::getMaxWidth() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); return m_nMaxWidth; } @@ -134,7 +128,7 @@ namespace toolkit ::sal_Int32 SAL_CALL GridColumn::getMinWidth() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); return m_nMinWidth; } @@ -147,7 +141,7 @@ namespace toolkit OUString SAL_CALL GridColumn::getTitle() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); return m_sTitle; } @@ -160,7 +154,7 @@ namespace toolkit OUString SAL_CALL GridColumn::getHelpText() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); return m_sHelpText; } @@ -173,7 +167,7 @@ namespace toolkit sal_Bool SAL_CALL GridColumn::getResizeable() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); return m_bResizeable; } @@ -186,7 +180,7 @@ namespace toolkit ::sal_Int32 SAL_CALL GridColumn::getFlexibility() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); return m_nFlexibility; } @@ -201,7 +195,7 @@ namespace toolkit HorizontalAlignment SAL_CALL GridColumn::getHorizontalAlign() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); return m_eHorizontalAlign; } @@ -214,19 +208,20 @@ namespace toolkit void SAL_CALL GridColumn::addGridColumnListener( const Reference< XGridColumnListener >& xListener ) { - rBHelper.addListener( cppu::UnoType<XGridColumnListener>::get(), xListener ); + std::unique_lock aGuard( m_aMutex ); + maGridColumnListeners.addInterface( xListener ); } void SAL_CALL GridColumn::removeGridColumnListener( const Reference< XGridColumnListener >& xListener ) { - rBHelper.removeListener( cppu::UnoType<XGridColumnListener>::get(), xListener ); + std::unique_lock aGuard( m_aMutex ); + maGridColumnListeners.removeInterface( xListener ); } - void SAL_CALL GridColumn::disposing() + void GridColumn::disposing(std::unique_lock<std::mutex>&) { - ::osl::MutexGuard aGuard( m_aMutex ); m_aIdentifier.clear(); m_sTitle.clear(); m_sHelpText.clear(); @@ -235,21 +230,21 @@ namespace toolkit ::sal_Int32 SAL_CALL GridColumn::getIndex() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); return m_nIndex; } void GridColumn::setIndex( sal_Int32 const i_index ) { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); m_nIndex = i_index; } ::sal_Int32 SAL_CALL GridColumn::getDataColumnIndex() { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard( m_aMutex ); return m_nDataColumnIndex; } diff --git a/toolkit/source/controls/grid/gridcolumn.hxx b/toolkit/source/controls/grid/gridcolumn.hxx index e533a72e5ce5..cd3a8c5cd531 100644 --- a/toolkit/source/controls/grid/gridcolumn.hxx +++ b/toolkit/source/controls/grid/gridcolumn.hxx @@ -25,19 +25,17 @@ #include <com/sun/star/lang/XUnoTunnel.hpp> #include <com/sun/star/style/HorizontalAlignment.hpp> -#include <cppuhelper/basemutex.hxx> -#include <cppuhelper/compbase.hxx> -#include <comphelper/componentguard.hxx> +#include <comphelper/compbase.hxx> +#include <comphelper/interfacecontainer4.hxx> namespace toolkit { -typedef ::cppu::WeakComponentImplHelper < css::awt::grid::XGridColumn +typedef comphelper::WeakComponentImplHelper < css::awt::grid::XGridColumn , css::lang::XServiceInfo , css::lang::XUnoTunnel > GridColumn_Base; -class GridColumn :public ::cppu::BaseMutex - ,public GridColumn_Base +class GridColumn final : public GridColumn_Base { public: GridColumn(); @@ -70,7 +68,7 @@ public: virtual void SAL_CALL removeGridColumnListener( const css::uno::Reference< css::awt::grid::XGridColumnListener >& xListener ) override; // OComponentHelper - virtual void SAL_CALL disposing() override; + virtual void disposing(std::unique_lock<std::mutex>&) override; // XCloneable (base of XGridColumn) virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone( ) override; @@ -92,13 +90,15 @@ private: char const * const i_asciiAttributeName, const css::uno::Any& i_oldValue, const css::uno::Any& i_newValue, - ::comphelper::ComponentGuard& i_Guard + std::unique_lock<std::mutex>& i_Guard ); template< class TYPE > void impl_set( TYPE & io_attribute, TYPE const & i_newValue, char const * i_attributeName ) { - ::comphelper::ComponentGuard aGuard( *this, rBHelper ); + std::unique_lock aGuard(m_aMutex); + if (m_bDisposed) + throw css::lang::DisposedException( OUString(), static_cast<cppu::OWeakObject*>(this) ); if ( io_attribute == i_newValue ) return; @@ -118,6 +118,7 @@ private: OUString m_sTitle; OUString m_sHelpText; css::style::HorizontalAlignment m_eHorizontalAlign; + comphelper::OInterfaceContainerHelper4<css::awt::grid::XGridColumnListener> maGridColumnListeners; }; } commit 5437632edfa35d45b3b91c818f00b8967c5a5888 Author: Noel Grandin <[email protected]> AuthorDate: Fri Dec 24 21:08:37 2021 +0200 Commit: Noel Grandin <[email protected]> CommitDate: Mon Dec 27 07:34:16 2021 +0100 use comphelper::WeakComponentImplHelper in UIElementFactoryManager Change-Id: I048e5671df230c498a2425d60f64208089fd044b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127489 Tested-by: Jenkins Reviewed-by: Noel Grandin <[email protected]> diff --git a/framework/source/uifactory/uielementfactorymanager.cxx b/framework/source/uifactory/uielementfactorymanager.cxx index 918fef603451..39b34246651f 100644 --- a/framework/source/uifactory/uielementfactorymanager.cxx +++ b/framework/source/uifactory/uielementfactorymanager.cxx @@ -42,8 +42,7 @@ #include <sal/log.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/propertyvalue.hxx> -#include <cppuhelper/basemutex.hxx> -#include <cppuhelper/compbase.hxx> +#include <comphelper/compbase.hxx> #include <cppuhelper/supportsservice.hxx> using namespace com::sun::star::uno; @@ -341,14 +340,13 @@ bool ConfigurationAccess_FactoryManager::impl_getElementProps( const Any& aEleme namespace { -typedef ::cppu::WeakComponentImplHelper< +typedef comphelper::WeakComponentImplHelper< css::lang::XServiceInfo, css::ui::XUIElementFactoryManager> UIElementFactoryManager_BASE; -class UIElementFactoryManager : private cppu::BaseMutex, - public UIElementFactoryManager_BASE +class UIElementFactoryManager : public UIElementFactoryManager_BASE { - virtual void SAL_CALL disposing() override; + virtual void disposing(std::unique_lock<std::mutex>&) override; public: explicit UIElementFactoryManager( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); @@ -383,7 +381,6 @@ private: }; UIElementFactoryManager::UIElementFactoryManager( const Reference< XComponentContext >& rxContext ) : - UIElementFactoryManager_BASE(m_aMutex), m_bConfigRead( false ), m_xContext(rxContext), m_pConfigAccess( @@ -392,7 +389,7 @@ UIElementFactoryManager::UIElementFactoryManager( const Reference< XComponentCon "/org.openoffice.Office.UI.Factories/Registered/UIElementFactories")) {} -void SAL_CALL UIElementFactoryManager::disposing() +void UIElementFactoryManager::disposing(std::unique_lock<std::mutex>&) { m_pConfigAccess.clear(); } @@ -405,28 +402,28 @@ Reference< XUIElement > SAL_CALL UIElementFactoryManager::createUIElement( Reference< XFrame > xFrame; OUString aModuleId; { // SAFE - osl::MutexGuard g(rBHelper.rMutex); - if (rBHelper.bDisposed) { - throw css::lang::DisposedException( - "disposed", static_cast<OWeakObject *>(this)); - } + std::unique_lock g(m_aMutex); + if (m_bDisposed) { + throw css::lang::DisposedException( + "disposed", static_cast<OWeakObject *>(this)); + } - if ( !m_bConfigRead ) - { - m_bConfigRead = true; - m_pConfigAccess->readConfigurationData(); - } + if ( !m_bConfigRead ) + { + m_bConfigRead = true; + m_pConfigAccess->readConfigurationData(); + } - // Retrieve the frame instance from the arguments to determine the module identifier. This must be provided - // to the search function. An empty module identifier is provided if the frame is missing or the module id cannot - // retrieve from it. - for ( auto const & arg : Args ) - { - if ( arg.Name == "Frame") - arg.Value >>= xFrame; - if (arg.Name == "Module") - arg.Value >>= aModuleId; - } + // Retrieve the frame instance from the arguments to determine the module identifier. This must be provided + // to the search function. An empty module identifier is provided if the frame is missing or the module id cannot + // retrieve from it. + for ( auto const & arg : Args ) + { + if ( arg.Name == "Frame") + arg.Value >>= xFrame; + if (arg.Name == "Module") + arg.Value >>= aModuleId; + } } // SAFE Reference< XModuleManager2 > xManager = ModuleManager::create( m_xContext ); @@ -452,8 +449,8 @@ Reference< XUIElement > SAL_CALL UIElementFactoryManager::createUIElement( Sequence< Sequence< PropertyValue > > SAL_CALL UIElementFactoryManager::getRegisteredFactories() { // SAFE - osl::MutexGuard g(rBHelper.rMutex); - if (rBHelper.bDisposed) { + std::unique_lock g(m_aMutex); + if (m_bDisposed) { throw css::lang::DisposedException( "disposed", static_cast<OWeakObject *>(this)); } @@ -471,24 +468,22 @@ Reference< XUIElementFactory > SAL_CALL UIElementFactoryManager::getFactory( con { OUString aServiceSpecifier; { // SAFE - osl::MutexGuard g(rBHelper.rMutex); - if (rBHelper.bDisposed) { - throw css::lang::DisposedException( - "disposed", static_cast<OWeakObject *>(this)); - } - - if ( !m_bConfigRead ) - { - m_bConfigRead = true; - m_pConfigAccess->readConfigurationData(); - } - - OUString aType; - OUString aName; + std::unique_lock g(m_aMutex); + if (m_bDisposed) { + throw css::lang::DisposedException( + "disposed", static_cast<OWeakObject *>(this)); + } - RetrieveTypeNameFromResourceURL( aResourceURL, aType, aName ); + if ( !m_bConfigRead ) + { + m_bConfigRead = true; + m_pConfigAccess->readConfigurationData(); + } - aServiceSpecifier = m_pConfigAccess->getFactorySpecifierFromTypeNameModule( aType, aName, aModuleId ); + OUString aType; + OUString aName; + RetrieveTypeNameFromResourceURL( aResourceURL, aType, aName ); + aServiceSpecifier = m_pConfigAccess->getFactorySpecifierFromTypeNameModule( aType, aName, aModuleId ); } // SAFE if ( !aServiceSpecifier.isEmpty() ) try @@ -509,8 +504,8 @@ Reference< XUIElementFactory > SAL_CALL UIElementFactoryManager::getFactory( con void SAL_CALL UIElementFactoryManager::registerFactory( const OUString& aType, const OUString& aName, const OUString& aModuleId, const OUString& aFactoryImplementationName ) { // SAFE - osl::MutexGuard g(rBHelper.rMutex); - if (rBHelper.bDisposed) { + std::unique_lock g(m_aMutex); + if (m_bDisposed) { throw css::lang::DisposedException( "disposed", static_cast<OWeakObject *>(this)); } @@ -528,8 +523,8 @@ void SAL_CALL UIElementFactoryManager::registerFactory( const OUString& aType, c void SAL_CALL UIElementFactoryManager::deregisterFactory( const OUString& aType, const OUString& aName, const OUString& aModuleId ) { // SAFE - osl::MutexGuard g(rBHelper.rMutex); - if (rBHelper.bDisposed) { + std::unique_lock g(m_aMutex); + if (m_bDisposed) { throw css::lang::DisposedException( "disposed", static_cast<OWeakObject *>(this)); }
