From 5f661a23346858c6162356d92a9f026f288ce31d Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Wed, 15 Mar 2023 10:07:13 +0200 Subject: BaseMutex->std::mutex in CWinClipboard Change-Id: Icabb28d58af5a1e2c5f44513fbbe18da3fd69b03 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148908 Tested-by: Jenkins Reviewed-by: Noel Grandin --- vcl/win/dtrans/WinClipboard.cxx | 55 +++++++++++++++-------------------------- vcl/win/dtrans/WinClipboard.hxx | 13 +++++----- 2 files changed, 27 insertions(+), 41 deletions(-) (limited to 'vcl') diff --git a/vcl/win/dtrans/WinClipboard.cxx b/vcl/win/dtrans/WinClipboard.cxx index c2fa269dfc5d..f82c56784523 100644 --- a/vcl/win/dtrans/WinClipboard.cxx +++ b/vcl/win/dtrans/WinClipboard.cxx @@ -58,8 +58,7 @@ osl::Mutex s_aClipboardSingletonMutex; /*XEventListener,*/ CWinClipboard::CWinClipboard(const uno::Reference& rxContext, const OUString& aClipboardName) - : WeakComponentImplHelper(m_aMutex) - , m_xContext(rxContext) + : m_xContext(rxContext) , m_itsName(aClipboardName) , m_pCurrentClipContent(nullptr) { @@ -95,7 +94,7 @@ uno::Reference SAL_CALL CWinClipboard::getContents( { osl::MutexGuard aGuard(m_aContentMutex); - if (rBHelper.bDisposed) + if (m_bDisposed) throw lang::DisposedException("object is already disposed", static_cast(this)); @@ -139,7 +138,7 @@ IDataObjectPtr CWinClipboard::getIDataObject() { osl::MutexGuard aGuard(m_aContentMutex); - if (rBHelper.bDisposed) + if (m_bDisposed) throw lang::DisposedException("object is already disposed", static_cast(this)); @@ -163,7 +162,7 @@ void SAL_CALL CWinClipboard::setContents( { osl::MutexGuard aGuard(m_aContentMutex); - if (rBHelper.bDisposed) + if (m_bDisposed) throw lang::DisposedException("object is already disposed", static_cast(this)); @@ -189,7 +188,7 @@ void SAL_CALL CWinClipboard::setContents( OUString SAL_CALL CWinClipboard::getName() { - if (rBHelper.bDisposed) + if (m_bDisposed) throw lang::DisposedException("object is already disposed", static_cast(this)); @@ -202,7 +201,7 @@ void SAL_CALL CWinClipboard::flushClipboard() { osl::MutexGuard aGuard(m_aContentMutex); - if (rBHelper.bDisposed) + if (m_bDisposed) throw lang::DisposedException("object is already disposed", static_cast(this)); @@ -224,7 +223,7 @@ void SAL_CALL CWinClipboard::flushClipboard() sal_Int8 SAL_CALL CWinClipboard::getRenderingCapabilities() { - if (rBHelper.bDisposed) + if (m_bDisposed) throw lang::DisposedException("object is already disposed", static_cast(this)); @@ -237,7 +236,7 @@ sal_Int8 SAL_CALL CWinClipboard::getRenderingCapabilities() void SAL_CALL CWinClipboard::addClipboardListener( const uno::Reference& listener) { - if (rBHelper.bDisposed) + if (m_bDisposed) throw lang::DisposedException("object is already disposed", static_cast(this)); @@ -246,13 +245,14 @@ void SAL_CALL CWinClipboard::addClipboardListener( throw lang::IllegalArgumentException("empty reference", static_cast(this), 1); - rBHelper.aLC.addInterface(cppu::UnoType::get(), listener); + std::unique_lock aGuard(m_aMutex); + maClipboardListeners.addInterface(aGuard, listener); } void SAL_CALL CWinClipboard::removeClipboardListener( const uno::Reference& listener) { - if (rBHelper.bDisposed) + if (m_bDisposed) throw lang::DisposedException("object is already disposed", static_cast(this)); @@ -261,50 +261,35 @@ void SAL_CALL CWinClipboard::removeClipboardListener( throw lang::IllegalArgumentException("empty reference", static_cast(this), 1); - rBHelper.aLC.removeInterface(cppu::UnoType::get(), listener); + std::unique_lock aGuard(m_aMutex); + maClipboardListeners.removeInterface(aGuard, listener); } void CWinClipboard::notifyAllClipboardListener() { - if (rBHelper.bDisposed) + if (m_bDisposed) return; - osl::ClearableMutexGuard aGuard(rBHelper.rMutex); - if (rBHelper.bDisposed) + std::unique_lock aGuard(m_aMutex); + if (m_bDisposed) return; - aGuard.clear(); - cppu::OInterfaceContainerHelper* pICHelper = rBHelper.aLC.getContainer( - cppu::UnoType::get()); - if (!pICHelper) + if (!maClipboardListeners.getLength(aGuard)) return; try { - cppu::OInterfaceIteratorHelper iter(*pICHelper); uno::Reference rXTransf(getContents()); datatransfer::clipboard::ClipboardEvent aClipbEvent(static_cast(this), rXTransf); - - while (iter.hasMoreElements()) - { - try - { - uno::Reference xCBListener( - iter.next(), uno::UNO_QUERY); - if (xCBListener.is()) - xCBListener->changedContents(aClipbEvent); - } - catch (uno::RuntimeException&) - { - TOOLS_WARN_EXCEPTION("vcl", ""); - } - } + maClipboardListeners.notifyEach( + aGuard, &datatransfer::clipboard::XClipboardListener::changedContents, aClipbEvent); } catch (const lang::DisposedException&) { OSL_FAIL("Service Manager disposed"); + aGuard.unlock(); // no further clipboard changed notifications unregisterClipboardViewer(); } diff --git a/vcl/win/dtrans/WinClipboard.hxx b/vcl/win/dtrans/WinClipboard.hxx index ac86d0d547b4..779c272c56c9 100644 --- a/vcl/win/dtrans/WinClipboard.hxx +++ b/vcl/win/dtrans/WinClipboard.hxx @@ -21,8 +21,8 @@ #include #include -#include -#include +#include +#include #include #include #include @@ -48,10 +48,9 @@ // by this class! class CWinClipboard final - : public cppu::BaseMutex, - public cppu::WeakComponentImplHelper + : public comphelper::WeakComponentImplHelper { friend STDMETHODIMP_(ULONG) CXNotifyingDataObject::Release(); @@ -62,6 +61,8 @@ class CWinClipboard final com::sun::star::uno::Reference m_foreignContent; osl::Mutex m_aContentMutex; osl::Mutex m_aContentCacheMutex; + comphelper::OInterfaceContainerHelper4 + maClipboardListeners; void notifyAllClipboardListener(); void onReleaseDataObject(CXNotifyingDataObject* theCaller); -- cgit