summaryrefslogtreecommitdiff
path: root/include
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 /include
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
Diffstat (limited to 'include')
-rw-r--r--include/tools/link.hxx1
-rw-r--r--include/vcl/idle.hxx36
-rw-r--r--include/vcl/timer.hxx46
3 files changed, 56 insertions, 27 deletions
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