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

pass SfxRequest around by std::unique_ptr

- remove a couple of copies in the process
- need to use std::function instead of LINK to handle the unique_ptr

Change-Id: Ic760d2fc639bf2e11d5bddbfbb6f2d5f15b78fe3
Reviewed-on: https://gerrit.libreoffice.org/60397
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst b40f41d0
...@@ -95,7 +95,7 @@ friend class SfxPopupMenuManager; ...@@ -95,7 +95,7 @@ friend class SfxPopupMenuManager;
friend class SfxHelp; friend class SfxHelp;
DECL_DLLPRIVATE_LINK( EventHdl_Impl, Timer *, void ); DECL_DLLPRIVATE_LINK( EventHdl_Impl, Timer *, void );
DECL_DLLPRIVATE_LINK( PostMsgHandler, SfxRequest *, void ); void PostMsgHandler(std::unique_ptr<SfxRequest>);
SAL_DLLPRIVATE void Call_Impl( SfxShell& rShell, const SfxSlot &rSlot, SfxRequest &rReq, bool bRecord ); SAL_DLLPRIVATE void Call_Impl( SfxShell& rShell, const SfxSlot &rSlot, SfxRequest &rReq, bool bRecord );
SAL_DLLPRIVATE void Update_Impl_( bool,bool,bool,SfxWorkWindow*); SAL_DLLPRIVATE void Update_Impl_( bool,bool,bool,SfxWorkWindow*);
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include <tools/link.hxx> #include <tools/link.hxx>
#include <tools/ref.hxx> #include <tools/ref.hxx>
#include <functional>
#include <memory>
class SfxRequest; class SfxRequest;
...@@ -39,7 +41,7 @@ class SfxRequest; ...@@ -39,7 +41,7 @@ class SfxRequest;
class SfxHintPoster : public SvRefBase class SfxHintPoster : public SvRefBase
{ {
private: private:
Link<SfxRequest*,void> m_Link; std::function<void (std::unique_ptr<SfxRequest>)> m_Link;
DECL_LINK( DoEvent_Impl, void*, void ); DECL_LINK( DoEvent_Impl, void*, void );
...@@ -47,10 +49,10 @@ protected: ...@@ -47,10 +49,10 @@ protected:
virtual ~SfxHintPoster() override; virtual ~SfxHintPoster() override;
public: public:
SfxHintPoster(const Link<SfxRequest*,void>& rLink); SfxHintPoster(const std::function<void (std::unique_ptr<SfxRequest>)>& rLink);
void Post( SfxRequest* pHint ); void Post( std::unique_ptr<SfxRequest> pHint );
void SetEventHdl(const Link<SfxRequest*,void>& rLink); void SetEventHdl(const std::function<void (std::unique_ptr<SfxRequest>)>& rLink);
}; };
#endif #endif
......
...@@ -410,9 +410,7 @@ void SfxDispatcher::Construct_Impl() ...@@ -410,9 +410,7 @@ void SfxDispatcher::Construct_Impl()
for (SfxObjectBars_Impl & rObjBar : xImp->aObjBars) for (SfxObjectBars_Impl & rObjBar : xImp->aObjBars)
rObjBar.eId = ToolbarId::None; rObjBar.eId = ToolbarId::None;
Link<SfxRequest*,void> aGenLink( LINK(this, SfxDispatcher, PostMsgHandler) ); xImp->xPoster = new SfxHintPoster(std::bind(&SfxDispatcher::PostMsgHandler, this, std::placeholders::_1));
xImp->xPoster = new SfxHintPoster(aGenLink);
xImp->aIdle.SetPriority(TaskPriority::HIGH_IDLE ); xImp->aIdle.SetPriority(TaskPriority::HIGH_IDLE );
xImp->aIdle.SetInvokeHandler( LINK(this, SfxDispatcher, EventHdl_Impl ) ); xImp->aIdle.SetInvokeHandler( LINK(this, SfxDispatcher, EventHdl_Impl ) );
...@@ -445,7 +443,7 @@ SfxDispatcher::~SfxDispatcher() ...@@ -445,7 +443,7 @@ SfxDispatcher::~SfxDispatcher()
// So that no timer by Reschedule in PlugComm strikes the LeaveRegistrations // So that no timer by Reschedule in PlugComm strikes the LeaveRegistrations
xImp->aIdle.Stop(); xImp->aIdle.Stop();
xImp->xPoster->SetEventHdl( Link<SfxRequest*,void>() ); xImp->xPoster->SetEventHdl( std::function<void (std::unique_ptr<SfxRequest>)>() );
// Notify the stack variables in Call_Impl // Notify the stack variables in Call_Impl
if ( xImp->pInCallAliveFlag ) if ( xImp->pInCallAliveFlag )
...@@ -866,7 +864,7 @@ void SfxDispatcher::Execute_(SfxShell& rShell, const SfxSlot& rSlot, ...@@ -866,7 +864,7 @@ void SfxDispatcher::Execute_(SfxShell& rShell, const SfxSlot& rSlot,
{ {
if ( bool(eCallMode & SfxCallMode::RECORD) ) if ( bool(eCallMode & SfxCallMode::RECORD) )
rReq.AllowRecording( true ); rReq.AllowRecording( true );
pDispat->xImp->xPoster->Post(new SfxRequest(rReq)); pDispat->xImp->xPoster->Post(o3tl::make_unique<SfxRequest>(rReq));
return; return;
} }
} }
...@@ -1104,7 +1102,7 @@ const SfxPoolItem* SfxDispatcher::ExecuteList(sal_uInt16 nSlot, SfxCallMode eCal ...@@ -1104,7 +1102,7 @@ const SfxPoolItem* SfxDispatcher::ExecuteList(sal_uInt16 nSlot, SfxCallMode eCal
/** Helper method to receive the asynchronously executed <SfxRequest>s. /** Helper method to receive the asynchronously executed <SfxRequest>s.
*/ */
IMPL_LINK(SfxDispatcher, PostMsgHandler, SfxRequest*, pReq, void) void SfxDispatcher::PostMsgHandler(std::unique_ptr<SfxRequest> pReq)
{ {
DBG_ASSERT( !xImp->bFlushing, "recursive call to dispatcher" ); DBG_ASSERT( !xImp->bFlushing, "recursive call to dispatcher" );
SFX_STACK(SfxDispatcher::PostMsgHandler); SFX_STACK(SfxDispatcher::PostMsgHandler);
...@@ -1130,13 +1128,11 @@ IMPL_LINK(SfxDispatcher, PostMsgHandler, SfxRequest*, pReq, void) ...@@ -1130,13 +1128,11 @@ IMPL_LINK(SfxDispatcher, PostMsgHandler, SfxRequest*, pReq, void)
else else
{ {
if ( xImp->bLocked ) if ( xImp->bLocked )
xImp->aReqArr.emplace_back(new SfxRequest(*pReq)); xImp->aReqArr.emplace_back(std::move(pReq));
else else
xImp->xPoster->Post(new SfxRequest(*pReq)); xImp->xPoster->Post(std::move(pReq));
} }
} }
delete pReq;
} }
void SfxDispatcher::SetMenu_Impl() void SfxDispatcher::SetMenu_Impl()
...@@ -1957,7 +1953,7 @@ void SfxDispatcher::Lock( bool bLock ) ...@@ -1957,7 +1953,7 @@ void SfxDispatcher::Lock( bool bLock )
if ( !bLock ) if ( !bLock )
{ {
for(size_t i = 0; i < xImp->aReqArr.size(); ++i) for(size_t i = 0; i < xImp->aReqArr.size(); ++i)
xImp->xPoster->Post(xImp->aReqArr[i].release()); xImp->xPoster->Post(std::move(xImp->aReqArr[i]));
xImp->aReqArr.clear(); xImp->aReqArr.clear();
} }
} }
......
...@@ -21,10 +21,11 @@ ...@@ -21,10 +21,11 @@
#include <arrdecl.hxx> #include <arrdecl.hxx>
#include <sfx2/app.hxx> #include <sfx2/app.hxx>
#include <sfx2/request.hxx>
#include <sfxtypes.hxx> #include <sfxtypes.hxx>
SfxHintPoster::SfxHintPoster(const Link<SfxRequest*,void>& rLink) SfxHintPoster::SfxHintPoster(const std::function<void (std::unique_ptr<SfxRequest>)>& rLink)
: m_Link(rLink) : m_Link(rLink)
{ {
} }
...@@ -33,19 +34,20 @@ SfxHintPoster::~SfxHintPoster() ...@@ -33,19 +34,20 @@ SfxHintPoster::~SfxHintPoster()
{ {
} }
void SfxHintPoster::Post( SfxRequest* pHintToPost ) void SfxHintPoster::Post( std::unique_ptr<SfxRequest> pHintToPost )
{ {
Application::PostUserEvent( ( LINK(this, SfxHintPoster, DoEvent_Impl) ), pHintToPost ); Application::PostUserEvent( ( LINK(this, SfxHintPoster, DoEvent_Impl) ), pHintToPost.release() );
AddFirstRef(); AddFirstRef();
} }
IMPL_LINK( SfxHintPoster, DoEvent_Impl, void *, pPostedHint, void ) IMPL_LINK( SfxHintPoster, DoEvent_Impl, void *, pPostedHint, void )
{ {
m_Link.Call( static_cast<SfxRequest*>(pPostedHint) ); if (m_Link)
m_Link( std::unique_ptr<SfxRequest>(static_cast<SfxRequest*>(pPostedHint)) );
ReleaseRef(); ReleaseRef();
} }
void SfxHintPoster::SetEventHdl(const Link<SfxRequest*,void>& rLink) void SfxHintPoster::SetEventHdl(const std::function<void (std::unique_ptr<SfxRequest>)>& rLink)
{ {
m_Link = rLink; m_Link = rLink;
} }
......
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