summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2016-09-14 13:48:02 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2017-01-17 16:22:57 +0100
commit59b84bc78dff2adb265d9fa8edb4c42794cf9771 (patch)
tree929a0dd7e3d16dfc9d49dac3470fd11546819504
parent1531152eff8061d63be5d98641fcafaa1da05167 (diff)
Change Idle to be a Timer subclass
Drops a lot of duplicated code, as Idle is just a convenience class for instant, mostly low priority timers. Change-Id: I847592e92e86d15ab1cab168bf0e667322e48048
-rw-r--r--basctl/source/basicide/baside2b.cxx2
-rw-r--r--editeng/source/editeng/impedit5.cxx2
-rw-r--r--framework/source/layoutmanager/layoutmanager.cxx3
-rw-r--r--include/tools/link.hxx1
-rw-r--r--include/vcl/idle.hxx36
-rw-r--r--include/vcl/timer.hxx46
-rw-r--r--sc/source/core/tool/refreshtimer.cxx2
-rw-r--r--solenv/gdb/libreoffice/vcl.py26
-rw-r--r--vcl/source/app/idle.cxx20
-rw-r--r--vcl/source/app/timer.cxx38
-rw-r--r--vcl/source/control/edit.cxx2
-rw-r--r--vcl/source/edit/textdata.cxx4
-rw-r--r--vcl/source/window/paint.cxx2
-rw-r--r--vcl/source/window/window.cxx2
14 files changed, 92 insertions, 94 deletions
diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx
index 12ccf1cc3286..a7d88ef8c3fd 100644
--- a/basctl/source/basicide/baside2b.cxx
+++ b/basctl/source/basicide/baside2b.cxx
@@ -1325,7 +1325,7 @@ void EditorWindow::DestroyProgress()
void EditorWindow::ForceSyntaxTimeout()
{
aSyntaxIdle.Stop();
- aSyntaxIdle.GetIdleHdl().Call(&aSyntaxIdle);
+ aSyntaxIdle.Invoke();
}
// BreakPointWindow
diff --git a/editeng/source/editeng/impedit5.cxx b/editeng/source/editeng/impedit5.cxx
index 0d300818c02a..f0892252e756 100644
--- a/editeng/source/editeng/impedit5.cxx
+++ b/editeng/source/editeng/impedit5.cxx
@@ -809,7 +809,7 @@ void IdleFormattter::ForceTimeout()
if ( IsActive() )
{
Stop();
- ((Link<Idle *, void>&)GetIdleHdl()).Call( this );
+ Invoke();
}
}
diff --git a/framework/source/layoutmanager/layoutmanager.cxx b/framework/source/layoutmanager/layoutmanager.cxx
index b6303be61138..d78a4a75120b 100644
--- a/framework/source/layoutmanager/layoutmanager.cxx
+++ b/framework/source/layoutmanager/layoutmanager.cxx
@@ -2668,8 +2668,7 @@ throw( uno::RuntimeException, std::exception )
m_bMustDoLayout = true;
if ( !m_aAsyncLayoutTimer.IsActive() )
{
- const Link<Timer *, void>& aLink = m_aAsyncLayoutTimer.GetTimeoutHdl();
- aLink.Call( &m_aAsyncLayoutTimer );
+ m_aAsyncLayoutTimer.Invoke();
}
if ( m_nLockCount == 0 )
m_aAsyncLayoutTimer.Start();
diff --git a/include/tools/link.hxx b/include/tools/link.hxx
index 8b65be4755dd..de76c25dd6e9 100644
--- a/include/tools/link.hxx
+++ b/include/tools/link.hxx
@@ -102,6 +102,7 @@ public:
{ return function_ == other.function_ && instance_ == other.instance_; };
void *GetInstance() const { return instance_; }
+ Stub* GetFunction() const { return function_; }
private:
Stub * function_;
diff --git a/include/vcl/idle.hxx b/include/vcl/idle.hxx
index 9f491e1ad9f7..85ea758096a9 100644
--- a/include/vcl/idle.hxx
+++ b/include/vcl/idle.hxx
@@ -20,12 +20,19 @@
#ifndef INCLUDED_VCL_IDLE_HXX
#define INCLUDED_VCL_IDLE_HXX
-#include <tools/link.hxx>
-#include <vcl/scheduler.hxx>
+#include <vcl/timer.hxx>
-class VCL_DLLPUBLIC Idle : public Task
+/**
+ * An idle is a timer to be scheduled immediately.
+ *
+ * It's - more or less - just a convenience class.
+ */
+class VCL_DLLPUBLIC Idle : public Timer
{
- Link<Idle *, void> maIdleHdl; // Callback Link
+private:
+ // Delete all timeout specific functions, we don't want in an Idle
+ void SetTimeout( sal_uInt64 nTimeoutMs ) = delete;
+ sal_uInt64 GetTimeout() const = delete;
protected:
virtual bool ReadyForSchedule( bool bIdle, sal_uInt64 nTimeNow ) const override;
@@ -34,18 +41,23 @@ protected:
public:
Idle( const sal_Char *pDebugName = nullptr );
- Idle( const Idle& rIdle );
- virtual void Start() override;
+ virtual void Start() override;
- /// Make it possible to associate a callback with this idle handler
- /// of course, you can also sub-class and override 'Invoke'
- void SetIdleHdl( const Link<Idle *, void>& rLink ) { maIdleHdl = rLink; }
- const Link<Idle *, void>& GetIdleHdl() const { return maIdleHdl; }
- virtual void Invoke() override;
- Idle& operator=( const Idle& rIdle );
+ /**
+ * Convenience function for more readable code
+ *
+ * TODO: actually rename it and it's instances to SetInvokeHandler
+ */
+ inline void SetIdleHdl( const Link<Idle *, void>& rLink );
};
+inline void Idle::SetIdleHdl( const Link<Idle*, void> &rLink )
+{
+ SetInvokeHandler( Link<Timer*, void>( rLink.GetInstance(),
+ reinterpret_cast< Link<Timer*, void>::Stub* >( rLink.GetFunction()) ) );
+}
+
#endif // INCLUDED_VCL_IDLE_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/vcl/timer.hxx b/include/vcl/timer.hxx
index 19a882f02555..07fb9a873259 100644
--- a/include/vcl/timer.hxx
+++ b/include/vcl/timer.hxx
@@ -26,9 +26,9 @@
class VCL_DLLPUBLIC Timer : public Task
{
protected:
- Link<Timer *, void> maTimeoutHdl; // Callback Link
- sal_uInt64 mnTimeout;
- bool mbAuto;
+ Link<Timer *, void> maInvokeHandler; ///< Callback Link
+ sal_uInt64 mnTimeout;
+ bool mbAuto;
virtual void SetDeletionFlags() override;
virtual bool ReadyForSchedule( bool bIdle, sal_uInt64 nTimeNow ) const override;
@@ -37,29 +37,45 @@ protected:
public:
Timer( const sal_Char *pDebugName = nullptr );
- Timer( const Timer& rTimer );
- /// Make it possible to associate a callback with this timer handler
- /// of course, you can also sub-class and override 'Invoke'
- void SetTimeoutHdl( const Link<Timer *, void>& rLink ) { maTimeoutHdl = rLink; }
- const Link<Timer *, void>& GetTimeoutHdl() const { return maTimeoutHdl; }
+ /**
+ * Calls the maInvokeHandler with the parameter this.
+ */
+ virtual void Invoke() override;
+ /**
+ * Calls the maInvokeHandler with the parameter.
+ *
+ * Convenience Invoke function, mainly used to call with nullptr.
+ *
+ * @param arg parameter for the Link::Call function
+ */
+ void Invoke( Timer *arg );
+ void SetInvokeHandler( const Link<Timer *, void>& rLink ) { maInvokeHandler = rLink; }
+ bool HasInvokeHandler() const { return maInvokeHandler.IsSet(); };
+
+ /**
+ * Convenience function for more readable code
+ *
+ * TODO: actually use SetInvokeHandler and drop it
+ */
+ inline void SetTimeoutHdl( const Link<Timer *, void>& rLink );
+
void SetTimeout( sal_uInt64 nTimeoutMs );
sal_uInt64 GetTimeout() const { return mnTimeout; }
- virtual void Invoke() override;
- void Timeout() { Invoke(); }
- Timer& operator=( const Timer& rTimer );
virtual void Start() override;
};
+inline void Timer::SetTimeoutHdl( const Link<Timer *, void>& rLink )
+{
+ SetInvokeHandler( rLink );
+}
+
/// An auto-timer is a multi-shot timer re-emitting itself at
/// interval until destroyed.
class VCL_DLLPUBLIC AutoTimer : public Timer
{
public:
- AutoTimer( const sal_Char *pDebugName = nullptr );
- AutoTimer( const AutoTimer& rTimer );
-
- AutoTimer& operator=( const AutoTimer& rTimer );
+ AutoTimer( const sal_Char *pDebugName = nullptr );
};
#endif // INCLUDED_VCL_TIMER_HXX
diff --git a/sc/source/core/tool/refreshtimer.cxx b/sc/source/core/tool/refreshtimer.cxx
index cb83c4c3f840..954c132d25c3 100644
--- a/sc/source/core/tool/refreshtimer.cxx
+++ b/sc/source/core/tool/refreshtimer.cxx
@@ -120,7 +120,7 @@ void ScRefreshTimer::Invoke()
{
// now we COULD make the call in another thread ...
::osl::MutexGuard aGuard( (*ppControl)->GetMutex() );
- maTimeoutHdl.Call( this );
+ Timer::Invoke();
// restart from now on, don't execute immediately again if timed out
// a second time during refresh
if ( IsActive() )
diff --git a/solenv/gdb/libreoffice/vcl.py b/solenv/gdb/libreoffice/vcl.py
index 28ba3ebebc07..62dc3a06f09b 100644
--- a/solenv/gdb/libreoffice/vcl.py
+++ b/solenv/gdb/libreoffice/vcl.py
@@ -26,19 +26,27 @@ class ImplSchedulerDataPrinter(object):
def as_string(self, gdbobj):
if gdbobj['mpTask']:
- sched = gdbobj['mpTask'].dereference()
- if gdbobj['mpTask'].dynamic_cast( self.timer_type_ptr ):
- sched_type = "Timer"
- elif gdbobj['mpTask'].dynamic_cast( self.idle_type_ptr ):
- sched_type = "Idle"
+ task = gdbobj['mpTask'].dereference()
+ timer = gdbobj['mpTask'].dynamic_cast( self.timer_type_ptr )
+ idle = gdbobj['mpTask'].dynamic_cast( self.idle_type_ptr )
+ if idle:
+ task_type = "Idle"
+ elif timer:
+ task_type = "Timer"
else:
- assert sched_type, "Task object neither Timer nor Idle"
- res = "{:7s}{:10s} active: {:6s}".format( sched_type, str(sched['mePriority']), str(sched['mbActive']) )
- name = sched['mpDebugName']
+ task_type = "Task"
+ res = "{:7s}{:10s} active: {:6s}".format( task_type, str(task['mePriority']), str(task['mbActive']) )
+ name = task['mpDebugName']
if not name:
res = res + " (task debug name not set)"
else:
- res = "{} '{}' ({})".format(res, str(name.string()), str(sched.dynamic_type))
+ res = "{} '{}' ({})".format(res, str(name.string()), str(task.dynamic_type))
+ val_type = gdb.lookup_type(str( task.dynamic_type )).pointer()
+ timer = gdbobj['mpTask'].cast( val_type )
+ if (task_type == "Timer"):
+ res = "{}: {}ms".format(res, timer['mnTimeout'])
+ else:
+ assert 1 == timer['mnTimeout'], "Idle with timeout == {}".format( timer['mnTimeout'] )
return res
else:
assert gdbobj['mbDelete'], "No task set and not marked for deletion!"
diff --git a/vcl/source/app/idle.cxx b/vcl/source/app/idle.cxx
index 52b8d980218f..895000a9f504 100644
--- a/vcl/source/app/idle.cxx
+++ b/vcl/source/app/idle.cxx
@@ -20,25 +20,9 @@
#include <vcl/idle.hxx>
#include "saltimer.hxx"
-void Idle::Invoke()
+Idle::Idle( const sal_Char *pDebugName )
+ : Timer( pDebugName )
{
- maIdleHdl.Call( this );
-}
-
-Idle& Idle::operator=( const Idle& rIdle )
-{
- Task::operator=(rIdle);
- maIdleHdl = rIdle.maIdleHdl;
- return *this;
-}
-
-Idle::Idle( const sal_Char *pDebugName ) : Task( pDebugName )
-{
-}
-
-Idle::Idle( const Idle& rIdle ) : Task(rIdle)
-{
- maIdleHdl = rIdle.maIdleHdl;
}
void Idle::Start()
diff --git a/vcl/source/app/timer.cxx b/vcl/source/app/timer.cxx
index 96485ae90ebd..77704db3835b 100644
--- a/vcl/source/app/timer.cxx
+++ b/vcl/source/app/timer.cxx
@@ -53,25 +53,22 @@ sal_uInt64 Timer::UpdateMinPeriod( sal_uInt64 nMinPeriod, sal_uInt64 nTimeNow )
}
}
-Timer::Timer(const sal_Char *pDebugName) :
- Task(pDebugName),
- mnTimeout(Scheduler::ImmediateTimeoutMs),
- mbAuto(false)
+Timer::Timer(const sal_Char *pDebugName)
+ : Task( pDebugName )
+ , mnTimeout( Scheduler::ImmediateTimeoutMs )
+ , mbAuto( false )
{
mePriority = TaskPriority::HIGHEST;
}
-Timer::Timer( const Timer& rTimer ) :
- Task(rTimer),
- mnTimeout(rTimer.mnTimeout),
- mbAuto(rTimer.mbAuto)
+void Timer::Invoke()
{
- maTimeoutHdl = rTimer.maTimeoutHdl;
+ maInvokeHandler.Call( this );
}
-void Timer::Invoke()
+void Timer::Invoke( Timer *arg )
{
- maTimeoutHdl.Call( this );
+ maInvokeHandler.Call( arg );
}
void Timer::Start()
@@ -88,29 +85,10 @@ void Timer::SetTimeout( sal_uInt64 nNewTimeout )
StartTimer( mnTimeout );
}
-Timer& Timer::operator=( const Timer& rTimer )
-{
- Task::operator=(rTimer);
- maTimeoutHdl = rTimer.maTimeoutHdl;
- mnTimeout = rTimer.mnTimeout;
- mbAuto = rTimer.mbAuto;
- return *this;
-}
-
AutoTimer::AutoTimer( const sal_Char *pDebugName )
: Timer( pDebugName )
{
mbAuto = true;
}
-AutoTimer::AutoTimer( const AutoTimer& rTimer ) : Timer( rTimer )
-{
- mbAuto = true;
-}
-
-AutoTimer& AutoTimer::operator=( const AutoTimer& rTimer )
-{
- Timer::operator=( rTimer );
- return *this;
-}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index 610e492ef56c..8ee93fb9b2c8 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -1909,7 +1909,7 @@ void Edit::LoseFocus()
{
//notify an update latest when the focus is lost
mpUpdateDataTimer->Stop();
- mpUpdateDataTimer->Timeout();
+ mpUpdateDataTimer->Invoke();
}
if ( !mpSubEdit )
diff --git a/vcl/source/edit/textdata.cxx b/vcl/source/edit/textdata.cxx
index ceb42d053019..6b8abdfbec83 100644
--- a/vcl/source/edit/textdata.cxx
+++ b/vcl/source/edit/textdata.cxx
@@ -293,7 +293,7 @@ void IdleFormatter::DoIdleFormat( TextView* pV, sal_uInt16 nMaxRestarts )
if ( mnRestarts > nMaxRestarts )
{
mnRestarts = 0;
- ((Link<Idle *, void>&)GetIdleHdl()).Call( this );
+ Invoke();
}
else
{
@@ -307,7 +307,7 @@ void IdleFormatter::ForceTimeout()
{
Stop();
mnRestarts = 0;
- ((Link<Idle *, void>&)GetIdleHdl()).Call( this );
+ Invoke();
}
}
diff --git a/vcl/source/window/paint.cxx b/vcl/source/window/paint.cxx
index e0e1a936f5d9..8e8dfcc64a5d 100644
--- a/vcl/source/window/paint.cxx
+++ b/vcl/source/window/paint.cxx
@@ -660,7 +660,7 @@ IMPL_LINK_NOARG(Window, ImplHandleResizeTimerHdl, Idle *, void)
if( mpWindowImpl->mpFrameData->maPaintIdle.IsActive() )
{
mpWindowImpl->mpFrameData->maPaintIdle.Stop();
- mpWindowImpl->mpFrameData->maPaintIdle.GetIdleHdl().Call( nullptr );
+ mpWindowImpl->mpFrameData->maPaintIdle.Invoke( nullptr );
}
}
}
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 2757800751f5..46d949ae611f 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -2407,7 +2407,7 @@ Size Window::GetSizePixel() const
{
VclPtr<vcl::Window> xWindow( const_cast<Window*>(this) );
mpWindowImpl->mpFrameData->maResizeIdle.Stop();
- mpWindowImpl->mpFrameData->maResizeIdle.GetIdleHdl().Call( nullptr );
+ mpWindowImpl->mpFrameData->maResizeIdle.Invoke( nullptr );
if( xWindow->IsDisposed() )
return Size(0,0);
}