diff options
author | Noel Grandin <noelgrandin@collabora.co.uk> | 2023-03-15 10:07:13 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2023-03-15 09:22:33 +0000 |
commit | 5f661a23346858c6162356d92a9f026f288ce31d (patch) | |
tree | 09b97fc38a7a863e8423305c70a49e919f6d5c4b /vcl | |
parent | e149f038b6179ac94a613676fb0b1b475541313b (diff) |
BaseMutex->std::mutex in CWinClipboard
Change-Id: Icabb28d58af5a1e2c5f44513fbbe18da3fd69b03
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148908
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/win/dtrans/WinClipboard.cxx | 55 | ||||
-rw-r--r-- | vcl/win/dtrans/WinClipboard.hxx | 13 |
2 files changed, 27 insertions, 41 deletions
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<uno::XComponentContext>& rxContext, const OUString& aClipboardName) - : WeakComponentImplHelper<XSystemClipboard, XFlushableClipboard, XServiceInfo>(m_aMutex) - , m_xContext(rxContext) + : m_xContext(rxContext) , m_itsName(aClipboardName) , m_pCurrentClipContent(nullptr) { @@ -95,7 +94,7 @@ uno::Reference<datatransfer::XTransferable> SAL_CALL CWinClipboard::getContents( { osl::MutexGuard aGuard(m_aContentMutex); - if (rBHelper.bDisposed) + if (m_bDisposed) throw lang::DisposedException("object is already disposed", static_cast<XClipboardEx*>(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<XClipboardEx*>(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<XClipboardEx*>(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<XClipboardEx*>(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<XClipboardEx*>(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<XClipboardEx*>(this)); @@ -237,7 +236,7 @@ sal_Int8 SAL_CALL CWinClipboard::getRenderingCapabilities() void SAL_CALL CWinClipboard::addClipboardListener( const uno::Reference<datatransfer::clipboard::XClipboardListener>& listener) { - if (rBHelper.bDisposed) + if (m_bDisposed) throw lang::DisposedException("object is already disposed", static_cast<XClipboardEx*>(this)); @@ -246,13 +245,14 @@ void SAL_CALL CWinClipboard::addClipboardListener( throw lang::IllegalArgumentException("empty reference", static_cast<XClipboardEx*>(this), 1); - rBHelper.aLC.addInterface(cppu::UnoType<decltype(listener)>::get(), listener); + std::unique_lock aGuard(m_aMutex); + maClipboardListeners.addInterface(aGuard, listener); } void SAL_CALL CWinClipboard::removeClipboardListener( const uno::Reference<datatransfer::clipboard::XClipboardListener>& listener) { - if (rBHelper.bDisposed) + if (m_bDisposed) throw lang::DisposedException("object is already disposed", static_cast<XClipboardEx*>(this)); @@ -261,50 +261,35 @@ void SAL_CALL CWinClipboard::removeClipboardListener( throw lang::IllegalArgumentException("empty reference", static_cast<XClipboardEx*>(this), 1); - rBHelper.aLC.removeInterface(cppu::UnoType<decltype(listener)>::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<datatransfer::clipboard::XClipboardListener>::get()); - if (!pICHelper) + if (!maClipboardListeners.getLength(aGuard)) return; try { - cppu::OInterfaceIteratorHelper iter(*pICHelper); uno::Reference<datatransfer::XTransferable> rXTransf(getContents()); datatransfer::clipboard::ClipboardEvent aClipbEvent(static_cast<XClipboard*>(this), rXTransf); - - while (iter.hasMoreElements()) - { - try - { - uno::Reference<datatransfer::clipboard::XClipboardListener> 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 <rtl/ustring.hxx> #include <sal/types.h> -#include <cppuhelper/basemutex.hxx> -#include <cppuhelper/compbase.hxx> +#include <comphelper/compbase.hxx> +#include <comphelper/interfacecontainer4.hxx> #include <com/sun/star/datatransfer/XTransferable.hpp> #include <com/sun/star/datatransfer/clipboard/XClipboardEx.hpp> #include <com/sun/star/datatransfer/clipboard/XClipboardOwner.hpp> @@ -48,10 +48,9 @@ // by this class! class CWinClipboard final - : public cppu::BaseMutex, - public cppu::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard, - css::datatransfer::clipboard::XFlushableClipboard, - css::lang::XServiceInfo> + : public comphelper::WeakComponentImplHelper<css::datatransfer::clipboard::XSystemClipboard, + css::datatransfer::clipboard::XFlushableClipboard, + css::lang::XServiceInfo> { friend STDMETHODIMP_(ULONG) CXNotifyingDataObject::Release(); @@ -62,6 +61,8 @@ class CWinClipboard final com::sun::star::uno::Reference<com::sun::star::datatransfer::XTransferable> m_foreignContent; osl::Mutex m_aContentMutex; osl::Mutex m_aContentCacheMutex; + comphelper::OInterfaceContainerHelper4<css::datatransfer::clipboard::XClipboardListener> + maClipboardListeners; void notifyAllClipboardListener(); void onReleaseDataObject(CXNotifyingDataObject* theCaller); |