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>
This commit is contained in:
Noel Grandin
2023-02-22 12:24:31 +02:00
parent fce44263b6
commit 1f49d8ad7a
8 changed files with 81 additions and 28 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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&) \
{ \

View File

@@ -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>

View File

@@ -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();
}

View File

@@ -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& )
{

View File

@@ -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&)
{