summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2023-02-22 12:24:31 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2023-02-22 11:47:11 +0000
commit1f49d8ad7a520975f611023f77f3fc9c0e32ed77 (patch)
tree76286d1a5a9a1f5b36ec86b281234485300bd147
parentfce44263b6b59a720dfebb1643430339dc3959f6 (diff)
BaseMutex->std::mutex in ListenerMultiplexerBase
Change-Id: Icd565c83ca3b4afb1a846a637b7943b0498487e4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/147457 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r--forms/source/component/Filter.cxx8
-rw-r--r--include/toolkit/awt/vclxwindow.hxx6
-rw-r--r--include/toolkit/helper/listenermultiplexer.hxx44
-rw-r--r--include/toolkit/helper/macros.hxx18
-rw-r--r--toolkit/source/awt/vclxcontainer.cxx2
-rw-r--r--toolkit/source/awt/vclxwindow.cxx4
-rw-r--r--toolkit/source/controls/tree/treecontrol.cxx18
-rw-r--r--toolkit/source/helper/listenermultiplexer.cxx9
8 files changed, 81 insertions, 28 deletions
diff --git a/forms/source/component/Filter.cxx b/forms/source/component/Filter.cxx
index e3b9d0628067..bd9b640f1ce3 100644
--- a/forms/source/component/Filter.cxx
+++ b/forms/source/component/Filter.cxx
@@ -355,9 +355,7 @@ namespace frm
m_aText = sText;
TextEvent aEvt;
aEvt.Source = *this;
- ::comphelper::OInterfaceIteratorHelper3 aIt(m_aTextListeners);
- while( aIt.hasMoreElements() )
- aIt.next()->textChanged(aEvt);
+ m_aTextListeners.notifyEach(&css::awt::XTextListener::textChanged, aEvt);
}
#endif
}
@@ -530,9 +528,7 @@ namespace frm
setText(aNewText);
TextEvent aEvt;
aEvt.Source = *this;
- ::comphelper::OInterfaceIteratorHelper3 aIt(m_aTextListeners);
- while( aIt.hasMoreElements() )
- aIt.next()->textChanged(aEvt);
+ m_aTextListeners.notifyEach(&css::awt::XTextListener::textChanged, aEvt);
#endif
return true;
}
diff --git a/include/toolkit/awt/vclxwindow.hxx b/include/toolkit/awt/vclxwindow.hxx
index 30073236aa8a..b4b0a82b544b 100644
--- a/include/toolkit/awt/vclxwindow.hxx
+++ b/include/toolkit/awt/vclxwindow.hxx
@@ -42,7 +42,7 @@
#include <vector>
#include <functional>
-namespace comphelper { template <class ListenerT> class OInterfaceContainerHelper3; }
+template <class ListenerT> class ListenerMultiplexerBase;
namespace com::sun::star::accessibility { class XAccessibleContext; }
namespace com::sun::star::awt { class XTopWindowListener; }
namespace com::sun::star::awt { class XVclContainerListener; }
@@ -99,8 +99,8 @@ protected:
bool bWithDefaults = false );
virtual void GetPropertyIds( std::vector< sal_uInt16 > &aIds );
- ::comphelper::OInterfaceContainerHelper3<css::awt::XVclContainerListener>& GetContainerListeners();
- ::comphelper::OInterfaceContainerHelper3<css::awt::XTopWindowListener>& GetTopWindowListeners();
+ ListenerMultiplexerBase<css::awt::XVclContainerListener>& GetContainerListeners();
+ ListenerMultiplexerBase<css::awt::XTopWindowListener>& GetTopWindowListeners();
public:
typedef ::std::function<void ()> Callback;
diff --git a/include/toolkit/helper/listenermultiplexer.hxx b/include/toolkit/helper/listenermultiplexer.hxx
index b562e9e2852c..f2d9db4e625d 100644
--- a/include/toolkit/helper/listenermultiplexer.hxx
+++ b/include/toolkit/helper/listenermultiplexer.hxx
@@ -42,10 +42,9 @@
#include <com/sun/star/awt/tree/XTreeExpansionListener.hpp>
#include <com/sun/star/awt/tree/XTreeEditListener.hpp>
#include <com/sun/star/view/XSelectionChangeListener.hpp>
-#include <cppuhelper/basemutex.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <cppuhelper/weak.hxx>
-#include <comphelper/interfacecontainer3.hxx>
+#include <comphelper/interfacecontainer4.hxx>
#include <toolkit/helper/macros.hxx>
#include <com/sun/star/awt/grid/XGridSelectionListener.hpp>
#include <com/sun/star/awt/tab/XTabPageContainerListener.hpp>
@@ -53,19 +52,20 @@
// class ListenerMultiplexerBase
template <class ListenerT>
-class UNLESS_MERGELIBS(TOOLKIT_DLLPUBLIC) ListenerMultiplexerBase : public cppu::BaseMutex,
- public ::comphelper::OInterfaceContainerHelper3<ListenerT>,
+class UNLESS_MERGELIBS(TOOLKIT_DLLPUBLIC) ListenerMultiplexerBase :
public css::uno::XInterface
{
private:
::cppu::OWeakObject& mrContext;
-
protected:
+ mutable std::mutex m_aMutex;
+ ::comphelper::OInterfaceContainerHelper4<ListenerT> maListeners;
+
::cppu::OWeakObject& GetContext() { return mrContext; }
public:
ListenerMultiplexerBase( ::cppu::OWeakObject& rSource )
- : ::comphelper::OInterfaceContainerHelper3<ListenerT>(m_aMutex), mrContext(rSource)
+ : mrContext(rSource)
{
}
@@ -81,6 +81,38 @@ public:
void SAL_CALL acquire() noexcept override { mrContext.acquire(); }
void SAL_CALL release() noexcept override { mrContext.release(); }
+
+ void addInterface( const css::uno::Reference<ListenerT>& l)
+ {
+ std::unique_lock g(m_aMutex);
+ maListeners.addInterface(g, l);
+ }
+
+ void removeInterface( const css::uno::Reference<ListenerT>& l)
+ {
+ std::unique_lock g(m_aMutex);
+ maListeners.removeInterface(g, l);
+ }
+
+ void disposeAndClear(const css::lang::EventObject& rDisposeEvent)
+ {
+ std::unique_lock g(m_aMutex);
+ maListeners.disposeAndClear(g, rDisposeEvent);
+ }
+
+ sal_Int32 getLength() const
+ {
+ std::unique_lock g(m_aMutex);
+ return maListeners.getLength(g);
+ }
+
+ template <typename EventT>
+ inline void notifyEach(void (SAL_CALL ListenerT::*NotificationMethod)(const EventT&),
+ const EventT& Event) const
+ {
+ std::unique_lock g(m_aMutex);
+ return maListeners.notifyEach(g, NotificationMethod, Event);
+ }
};
// class EventListenerMultiplexer
diff --git a/include/toolkit/helper/macros.hxx b/include/toolkit/helper/macros.hxx
index 42c060673ed9..a959acd8792d 100644
--- a/include/toolkit/helper/macros.hxx
+++ b/include/toolkit/helper/macros.hxx
@@ -87,7 +87,9 @@ void ClassName::disposing( const css::lang::EventObject& ) \
#define IMPL_TABLISTENERMULTIPLEXER_LISTENERMETHOD_BODY_1PARAM( ClassName, InterfaceName, MethodName, ParamType1 ) \
{ \
ParamType1 aMulti( evt ); \
- ::comphelper::OInterfaceIteratorHelper3 aIt(*this); \
+ std::unique_lock g(m_aMutex); \
+ ::comphelper::OInterfaceIteratorHelper4 aIt(g, maListeners); \
+ g.unlock(); \
while( aIt.hasMoreElements() ) \
{ \
css::uno::Reference<InterfaceName> xListener(aIt.next()); \
@@ -99,7 +101,10 @@ void ClassName::disposing( const css::lang::EventObject& ) \
{ \
OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); \
if ( e.Context == xListener || !e.Context.is() ) \
- aIt.remove(); \
+ { \
+ std::unique_lock g2(m_aMutex); \
+ aIt.remove(g2); \
+ } \
} \
catch(const css::uno::RuntimeException&) \
{ \
@@ -112,7 +117,9 @@ void ClassName::disposing( const css::lang::EventObject& ) \
{ \
EventType aMulti( evt ); \
aMulti.Source = &GetContext(); \
- ::comphelper::OInterfaceIteratorHelper3 aIt(*this); \
+ std::unique_lock g(m_aMutex); \
+ ::comphelper::OInterfaceIteratorHelper4 aIt(g, maListeners); \
+ g.unlock(); \
while( aIt.hasMoreElements() ) \
{ \
css::uno::Reference<InterfaceName> xListener(aIt.next()); \
@@ -124,7 +131,10 @@ void ClassName::disposing( const css::lang::EventObject& ) \
{ \
OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" ); \
if ( e.Context == xListener || !e.Context.is() ) \
- aIt.remove(); \
+ { \
+ std::unique_lock g2(m_aMutex); \
+ aIt.remove(g2); \
+ } \
} \
catch(const css::uno::RuntimeException&) \
{ \
diff --git a/toolkit/source/awt/vclxcontainer.cxx b/toolkit/source/awt/vclxcontainer.cxx
index 5927c1f8e0b0..954655397853 100644
--- a/toolkit/source/awt/vclxcontainer.cxx
+++ b/toolkit/source/awt/vclxcontainer.cxx
@@ -19,7 +19,7 @@
#include <awt/vclxcontainer.hxx>
#include <toolkit/helper/vclunohelper.hxx>
-#include <comphelper/interfacecontainer3.hxx>
+#include <toolkit/helper/listenermultiplexer.hxx>
#include <vcl/svapp.hxx>
#include <vcl/window.hxx>
diff --git a/toolkit/source/awt/vclxwindow.cxx b/toolkit/source/awt/vclxwindow.cxx
index f5ebe82f02db..f3985bc12df5 100644
--- a/toolkit/source/awt/vclxwindow.cxx
+++ b/toolkit/source/awt/vclxwindow.cxx
@@ -1345,12 +1345,12 @@ void VCLXWindow::GetPropertyIds( std::vector< sal_uInt16 >& _out_rIds )
return ImplGetPropertyIds( _out_rIds, mpImpl->mbWithDefaultProps );
}
-::comphelper::OInterfaceContainerHelper3<css::awt::XVclContainerListener>& VCLXWindow::GetContainerListeners()
+ListenerMultiplexerBase<css::awt::XVclContainerListener>& VCLXWindow::GetContainerListeners()
{
return mpImpl->getContainerListeners();
}
-::comphelper::OInterfaceContainerHelper3<css::awt::XTopWindowListener>& VCLXWindow::GetTopWindowListeners()
+ListenerMultiplexerBase<css::awt::XTopWindowListener>& VCLXWindow::GetTopWindowListeners()
{
return mpImpl->getTopWindowListeners();
}
diff --git a/toolkit/source/controls/tree/treecontrol.cxx b/toolkit/source/controls/tree/treecontrol.cxx
index 43d353079f43..3fd06588d3d8 100644
--- a/toolkit/source/controls/tree/treecontrol.cxx
+++ b/toolkit/source/controls/tree/treecontrol.cxx
@@ -451,7 +451,9 @@ void UnoTreeControl::createPeer( const uno::Reference< awt::XToolkit > & rxToolk
void SAL_CALL TreeEditListenerMultiplexer::nodeEditing( const Reference< XTreeNode >& Node )
{
- ::comphelper::OInterfaceIteratorHelper3 aIt(*this);
+ std::unique_lock g(m_aMutex);
+ ::comphelper::OInterfaceIteratorHelper4 aIt(g, maListeners);
+ g.unlock();
while( aIt.hasMoreElements() )
{
Reference<XTreeEditListener> xListener(aIt.next());
@@ -463,7 +465,10 @@ void SAL_CALL TreeEditListenerMultiplexer::nodeEditing( const Reference< XTreeNo
{
OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" );
if ( e.Context == xListener || !e.Context.is() )
- aIt.remove();
+ {
+ std::unique_lock g2(m_aMutex);
+ aIt.remove(g2);
+ }
}
catch( const RuntimeException& )
{
@@ -474,7 +479,9 @@ void SAL_CALL TreeEditListenerMultiplexer::nodeEditing( const Reference< XTreeNo
void SAL_CALL TreeEditListenerMultiplexer::nodeEdited( const Reference< XTreeNode >& Node, const OUString& NewText )
{
- ::comphelper::OInterfaceIteratorHelper3 aIt(*this);
+ std::unique_lock g(m_aMutex);
+ ::comphelper::OInterfaceIteratorHelper4 aIt(g, maListeners);
+ g.unlock();
while( aIt.hasMoreElements() )
{
Reference<XTreeEditListener> xListener(aIt.next());
@@ -486,7 +493,10 @@ void SAL_CALL TreeEditListenerMultiplexer::nodeEdited( const Reference< XTreeNod
{
OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" );
if ( e.Context == xListener || !e.Context.is() )
- aIt.remove();
+ {
+ std::unique_lock g2(m_aMutex);
+ aIt.remove(g2);
+ }
}
catch( const RuntimeException& )
{
diff --git a/toolkit/source/helper/listenermultiplexer.cxx b/toolkit/source/helper/listenermultiplexer.cxx
index eeed767ffa48..1c3ac1de52ca 100644
--- a/toolkit/source/helper/listenermultiplexer.cxx
+++ b/toolkit/source/helper/listenermultiplexer.cxx
@@ -147,7 +147,9 @@ IMPL_TABLISTENERMULTIPLEXER_LISTENERMETHOD_BODY_1PARAM( TabListenerMultiplexer,
void TabListenerMultiplexer::changed( sal_Int32 evt, const css::uno::Sequence< css::beans::NamedValue >& evt2 )
{
sal_Int32 aMulti( evt );
- ::comphelper::OInterfaceIteratorHelper3 aIt(*this);
+ std::unique_lock g(m_aMutex);
+ ::comphelper::OInterfaceIteratorHelper4 aIt(g, maListeners);
+ g.unlock();
while( aIt.hasMoreElements() )
{
css::uno::Reference<css::awt::XTabListener> xListener(aIt.next());
@@ -159,7 +161,10 @@ void TabListenerMultiplexer::changed( sal_Int32 evt, const css::uno::Sequence< c
{
OSL_ENSURE( e.Context.is(), "caught DisposedException with empty Context field" );
if ( e.Context == xListener || !e.Context.is() )
- aIt.remove();
+ {
+ std::unique_lock g2(m_aMutex);
+ aIt.remove(g2);
+ }
}
catch(const css::uno::RuntimeException&)
{