diff options
author | Noel Grandin <noelgrandin@gmail.com> | 2021-12-20 19:59:46 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-01-03 20:54:39 +0100 |
commit | 7d87312ab6b39c3c03e93d305a1e6d7f0b78f9a7 (patch) | |
tree | 512dccadfb297e6b52adc74ee7f45edbc98af7d1 /sfx2 | |
parent | 3bb2cec6f9b81724f5a5e98065122da1f502e6ff (diff) |
osl::Mutex->std::mutex in SfxStatusDispatcher
Change-Id: Icfd23cb898da6d2fc6de9f5e57c906044b9a28de
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127900
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/unoctitm.hxx | 15 | ||||
-rw-r--r-- | sfx2/source/control/unoctitm.cxx | 60 |
2 files changed, 44 insertions, 31 deletions
diff --git a/sfx2/inc/unoctitm.hxx b/sfx2/inc/unoctitm.hxx index 6eb9e7147945..1a53091b2b74 100644 --- a/sfx2/inc/unoctitm.hxx +++ b/sfx2/inc/unoctitm.hxx @@ -21,14 +21,14 @@ #include <memory> #include <com/sun/star/frame/XNotifyingDispatch.hpp> #include <com/sun/star/lang/XUnoTunnel.hpp> -#include <comphelper/multiinterfacecontainer3.hxx> +#include <comphelper/multiinterfacecontainer4.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/interfacecontainer.hxx> #include <cppuhelper/weakref.hxx> #include <svl/lstner.hxx> #include <sfx2/ctrlitem.hxx> -#include <osl/mutex.hxx> +#include <mutex> namespace com::sun::star::frame { class XFrame; } namespace com::sun::star::frame { class XNotifyingDispatch; } @@ -39,13 +39,14 @@ class SfxBindings; class SfxDispatcher; class SfxSlot; -typedef comphelper::OMultiTypeInterfaceContainerHelperVar3<css::frame::XStatusListener, OUString> +typedef comphelper::OMultiTypeInterfaceContainerHelperVar4<OUString, css::frame::XStatusListener> SfxStatusDispatcher_Impl_ListenerContainer; class SfxStatusDispatcher : public cppu::WeakImplHelper<css::frame::XNotifyingDispatch> { - ::osl::Mutex aMutex; - SfxStatusDispatcher_Impl_ListenerContainer aListeners; +protected: + std::mutex maMutex; + SfxStatusDispatcher_Impl_ListenerContainer maListeners; public: @@ -61,8 +62,8 @@ public: // Something else void ReleaseAll(); - SfxStatusDispatcher_Impl_ListenerContainer& GetListeners() - { return aListeners; } + void sendStatusChanged(const OUString& rURL, const css::frame::FeatureStateEvent& rEvent); + std::vector<OUString> getContainedTypes() { return maListeners.getContainedTypes(); }; }; class SfxSlotServer; diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index cecfb4c639e1..5ae4e87f77e4 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -124,7 +124,29 @@ void SfxStatusDispatcher::ReleaseAll() { css::lang::EventObject aObject; aObject.Source = static_cast<cppu::OWeakObject*>(this); - aListeners.disposeAndClear( aObject ); + std::unique_lock aGuard(maMutex); + maListeners.disposeAndClear( aGuard, aObject ); +} + +void SfxStatusDispatcher::sendStatusChanged(const OUString& rURL, const css::frame::FeatureStateEvent& rEvent) +{ + std::unique_lock aGuard(maMutex); + ::comphelper::OInterfaceContainerHelper4<css::frame::XStatusListener>* pContnr = maListeners.getContainer(rURL); + if (!pContnr) + return; + ::comphelper::OInterfaceIteratorHelper4 aIt(*pContnr); + aGuard.unlock(); + while (aIt.hasMoreElements()) + { + try + { + aIt.next()->statusChanged(rEvent); + } + catch (const css::uno::RuntimeException&) + { + aIt.remove(); + } + } } void SAL_CALL SfxStatusDispatcher::dispatch( const css::util::URL&, const css::uno::Sequence< css::beans::PropertyValue >& ) @@ -139,13 +161,15 @@ void SAL_CALL SfxStatusDispatcher::dispatchWithNotification( } SfxStatusDispatcher::SfxStatusDispatcher() - : aListeners( aMutex ) { } void SAL_CALL SfxStatusDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener > & aListener, const css::util::URL& aURL) { - aListeners.addInterface( aURL.Complete, aListener ); + { + std::unique_lock aGuard(maMutex); + maListeners.addInterface( aURL.Complete, aListener ); + } if ( aURL.Complete == ".uno:LifeTime" ) { css::frame::FeatureStateEvent aEvent; @@ -159,7 +183,8 @@ void SAL_CALL SfxStatusDispatcher::addStatusListener(const css::uno::Reference< void SAL_CALL SfxStatusDispatcher::removeStatusListener( const css::uno::Reference< css::frame::XStatusListener > & aListener, const css::util::URL& aURL ) { - aListeners.removeInterface( aURL.Complete, aListener ); + std::unique_lock aGuard(maMutex); + maListeners.removeInterface( aURL.Complete, aListener ); } @@ -273,7 +298,10 @@ void SAL_CALL SfxOfficeDispatch::dispatchWithNotification( const css::util::URL& void SAL_CALL SfxOfficeDispatch::addStatusListener(const css::uno::Reference< css::frame::XStatusListener > & aListener, const css::util::URL& aURL) { - GetListeners().addInterface( aURL.Complete, aListener ); + { + std::unique_lock aGuard(maMutex); + maListeners.addInterface( aURL.Complete, aListener ); + } if ( pImpl ) { // ControllerItem is the Impl class @@ -382,9 +410,7 @@ SfxDispatchController_Impl::~SfxDispatchController_Impl() pDispatch->pImpl = nullptr; // force all listeners to release the dispatch object - css::lang::EventObject aObject; - aObject.Source = static_cast<cppu::OWeakObject*>(pDispatch); - pDispatch->GetListeners().disposeAndClear( aObject ); + pDispatch->ReleaseAll(); } } @@ -794,21 +820,7 @@ void SfxDispatchController_Impl::addStatusListener(const css::uno::Reference< cs void SfxDispatchController_Impl::sendStatusChanged(const OUString& rURL, const css::frame::FeatureStateEvent& rEvent) { - ::comphelper::OInterfaceContainerHelper3<css::frame::XStatusListener>* pContnr = pDispatch->GetListeners().getContainer(rURL); - if (!pContnr) - return; - ::comphelper::OInterfaceIteratorHelper3 aIt(*pContnr); - while (aIt.hasMoreElements()) - { - try - { - aIt.next()->statusChanged(rEvent); - } - catch (const css::uno::RuntimeException&) - { - aIt.remove(); - } - } + pDispatch->sendStatusChanged(rURL, rEvent); } void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem* pState, SfxSlotServer const * pSlotServ ) @@ -889,7 +901,7 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt InterceptLOKStateChangeEvent(nSID, pDispatcher->GetFrame(), aEvent, pState); } - const std::vector<OUString> aContainedTypes = pDispatch->GetListeners().getContainedTypes(); + const std::vector<OUString> aContainedTypes = pDispatch->getContainedTypes(); for (const OUString& rName: aContainedTypes) { if (rName == aDispatchURL.Main || rName == aDispatchURL.Complete) |