Kaydet (Commit) dbc7fc75 authored tarafından Noel Grandin's avatar Noel Grandin

use unique_ptr in OComponentEventThread

and simplify - by passing in a std::unique_ptr to addEvent we avoid the
need to have a virtual clone method

Change-Id: Ie425476a3158c7a66e399c2a9f33d2612dab5cbb
Reviewed-on: https://gerrit.libreoffice.org/67962
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst c70f5f32
......@@ -134,9 +134,6 @@ class OFormSubmitResetThread: public OComponentEventThread
{
protected:
// duplicate an event with respect to its type
virtual EventObject *cloneEvent( const EventObject *pEvt ) const override;
// process an event. while processing the mutex isn't locked, and pCompImpl
// is made sure to remain valid
virtual void processEvent( ::cppu::OComponentHelper* _pCompImpl,
......@@ -150,13 +147,6 @@ public:
};
EventObject* OFormSubmitResetThread::cloneEvent(
const EventObject *pEvt ) const
{
return new css::awt::MouseEvent( *static_cast<const css::awt::MouseEvent *>(pEvt) );
}
void OFormSubmitResetThread::processEvent(
::cppu::OComponentHelper* pCompImpl,
const EventObject *_pEvt,
......@@ -1908,8 +1898,7 @@ void SAL_CALL ODatabaseForm::reset()
m_pThread = new OFormSubmitResetThread(this);
m_pThread->create();
}
EventObject aEvt;
m_pThread->addEvent(&aEvt);
m_pThread->addEvent(std::make_unique<EventObject>());
}
else
{
......@@ -2078,7 +2067,7 @@ void SAL_CALL ODatabaseForm::submit( const Reference<XControl>& Control,
m_pThread = new OFormSubmitResetThread(this);
m_pThread->create();
}
m_pThread->addEvent(&MouseEvt, Control, true);
m_pThread->addEvent(std::make_unique<css::awt::MouseEvent>(MouseEvt), Control, true);
}
else
{
......
......@@ -71,8 +71,6 @@ Any SAL_CALL OComponentEventThread::queryInterface(const Type& _rType)
void OComponentEventThread::impl_clearEventQueue()
{
for ( auto& rEvent : m_aEvents )
delete rEvent;
m_aEvents.clear();
m_aControls.clear();
m_aFlags.clear();
......@@ -101,20 +99,20 @@ void OComponentEventThread::disposing( const EventObject& evt )
}
}
void OComponentEventThread::addEvent( const EventObject* _pEvt )
void OComponentEventThread::addEvent( std::unique_ptr<EventObject> _pEvt )
{
Reference<XControl> xTmp;
addEvent( _pEvt, xTmp );
addEvent( std::move(_pEvt), xTmp );
}
void OComponentEventThread::addEvent( const EventObject* _pEvt,
void OComponentEventThread::addEvent( std::unique_ptr<EventObject> _pEvt,
const Reference<XControl>& rControl,
bool bFlag )
{
::osl::MutexGuard aGuard( m_aMutex );
// Put data into the queue
m_aEvents.push_back( cloneEvent( _pEvt ) );
m_aEvents.push_back( std::move( _pEvt ) );
Reference<XWeak> xWeakControl(rControl, UNO_QUERY);
Reference<XAdapter> xControlAdapter = xWeakControl.is() ? xWeakControl->queryAdapter() : Reference<XAdapter>();
......@@ -152,7 +150,7 @@ void OComponentEventThread::run()
rtl::Reference<::cppu::OComponentHelper> xComp = m_xComp;
ThreadEvents::iterator firstEvent( m_aEvents.begin() );
std::unique_ptr<EventObject> pEvt(*firstEvent);
std::unique_ptr<EventObject> pEvt = std::move(*firstEvent);
m_aEvents.erase( firstEvent );
ThreadObjects::iterator firstControl( m_aControls.begin() );
......
......@@ -48,7 +48,7 @@ class OComponentEventThread
,public css::lang::XEventListener
,public ::cppu::OWeakObject
{
typedef std::vector<css::lang::EventObject*> ThreadEvents;
typedef std::vector<std::unique_ptr<css::lang::EventObject>> ThreadEvents;
typedef std::vector< css::uno::Reference< css::uno::XAdapter> > ThreadObjects;
::osl::Mutex m_aMutex;
......@@ -66,9 +66,6 @@ protected:
virtual void SAL_CALL onTerminated() override;
// The following method is called to duplicate the Event while respecting its type.
virtual css::lang::EventObject* cloneEvent(const css::lang::EventObject* _pEvt) const = 0;
// Edit an Event:
// The mutex is not locked, but pCompImpl stays valid in any case.
// pEvt can be a derrived type, namely the one that cloneEvent returns.
......@@ -88,8 +85,8 @@ public:
explicit OComponentEventThread(::cppu::OComponentHelper* pCompImpl);
virtual ~OComponentEventThread() override;
void addEvent( const css::lang::EventObject* _pEvt );
void addEvent( const css::lang::EventObject* _pEvt, const css::uno::Reference< css::awt::XControl>& rControl,
void addEvent( std::unique_ptr<css::lang::EventObject> _pEvt );
void addEvent( std::unique_ptr<css::lang::EventObject> _pEvt, const css::uno::Reference< css::awt::XControl>& rControl,
bool bFlag = false );
// css::lang::XEventListener
......
......@@ -195,7 +195,7 @@ void OImageButtonControl::mousePressed(const awt::MouseEvent& e)
{
// if there are listeners, start the action in an own thread, to not allow
// them to block us here (we're in the application's main thread)
getImageProducerThread()->OComponentEventThread::addEvent( &e );
getImageProducerThread()->OComponentEventThread::addEvent( std::make_unique<awt::MouseEvent>(e) );
}
else
{
......
......@@ -842,13 +842,6 @@ namespace frm
// OImageProducerThread_Impl
EventObject* OImageProducerThread_Impl::cloneEvent( const EventObject* _pEvt ) const
{
return new EventObject( *_pEvt );
}
void OImageProducerThread_Impl::processEvent( ::cppu::OComponentHelper *pCompImpl,
const EventObject* pEvt,
const Reference<XControl>&,
......
......@@ -255,9 +255,6 @@ namespace frm
{
protected:
// This method was called to duplicate the Event by taking its type into account
virtual css::lang::EventObject* cloneEvent( const css::lang::EventObject* _pEvt ) const override;
// Process an Event.
// The mutex is not locked, pCompImpl stays valid in any case
virtual void processEvent( ::cppu::OComponentHelper *pCompImpl,
......@@ -270,7 +267,7 @@ namespace frm
OComponentEventThread( pControl )
{}
void addEvent() { css::lang::EventObject aEvt; OComponentEventThread::addEvent( &aEvt ); }
void addEvent() { OComponentEventThread::addEvent( std::make_unique<css::lang::EventObject>() ); }
protected:
using OComponentEventThread::addEvent;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment