From afb60a273f9ed9f1ff17f25f62ef9dd15a4a7c3a Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 19 Jan 2017 12:35:35 +0200 Subject: [PATCH] use rtl::Reference in OComponentEventThread instead of storing both a raw pointer and an uno::Reference Change-Id: I8cd4d04ffb9f40a48d48ade2b171a9a9942cf87f --- forms/source/component/EventThread.cxx | 18 +++++------------- forms/source/component/EventThread.hxx | 8 ++++---- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/forms/source/component/EventThread.cxx b/forms/source/component/EventThread.cxx index e1011b17f26f..f255dbb3868e 100644 --- a/forms/source/component/EventThread.cxx +++ b/forms/source/component/EventThread.cxx @@ -32,17 +32,11 @@ using namespace ::com::sun::star::awt; using namespace ::com::sun::star::lang; OComponentEventThread::OComponentEventThread( ::cppu::OComponentHelper* pCompImpl ) : - m_pCompImpl( pCompImpl ) + m_xComp( pCompImpl ) { osl_atomic_increment(&m_refCount); - // Hold a reference of the Control - { - css::uno::Reference xIFace(static_cast(pCompImpl)); - m_xComp.set(xIFace, css::uno::UNO_QUERY); - } - // and add us at the Control { Reference xEvtLstnr = static_cast(this); @@ -88,7 +82,7 @@ void OComponentEventThread::impl_clearEventQueue() void OComponentEventThread::disposing( const EventObject& evt ) throw ( css::uno::RuntimeException, std::exception) { - if( evt.Source == m_xComp ) + if( evt.Source == static_cast(m_xComp.get()) ) { ::osl::MutexGuard aGuard( m_aMutex ); @@ -101,8 +95,7 @@ void OComponentEventThread::disposing( const EventObject& evt ) throw ( css::uno // Free the Control and set pCompImpl to 0, // so that the thread knows, that it should terminate. - m_xComp = nullptr; - m_pCompImpl = nullptr; + m_xComp.clear(); // Wake up the thread and terminate m_aCond.set(); @@ -158,8 +151,7 @@ void OComponentEventThread::run() while( m_aEvents.size() > 0 ) { // Get the Control and hold on to it so that it cannot be deleted during actionPerformed - Reference xComp = m_xComp; - ::cppu::OComponentHelper *pCompImpl = m_pCompImpl; + rtl::Reference<::cppu::OComponentHelper> xComp = m_xComp; ThreadEvents::iterator firstEvent( m_aEvents.begin() ); std::unique_ptr pEvt(*firstEvent); @@ -183,7 +175,7 @@ void OComponentEventThread::run() xControlAdapter->queryAdapted(), css::uno::UNO_QUERY); if( xComp.is() ) - processEvent( pCompImpl, pEvt.get(), xControl, bFlag ); + processEvent( xComp.get(), pEvt.get(), xControl, bFlag ); } } diff --git a/forms/source/component/EventThread.hxx b/forms/source/component/EventThread.hxx index e8472f54419c..e83b3bbb9592 100644 --- a/forms/source/component/EventThread.hxx +++ b/forms/source/component/EventThread.hxx @@ -29,11 +29,12 @@ #include #include #include - - #include #include #include +#include + + using namespace comphelper; @@ -57,8 +58,7 @@ class OComponentEventThread ThreadObjects m_aControls; // Control for Submit ThreadBools m_aFlags; // Flags for Submit/Reset - ::cppu::OComponentHelper* m_pCompImpl; // Implementation of the Control - css::uno::Reference< css::lang::XComponent> m_xComp; // css::lang::XComponent of the Control + rtl::Reference<::cppu::OComponentHelper> m_xComp; // Implementation of the Control protected: