diff options
author | Remko Tronçon <git@el-tramo.be> | 2010-10-31 08:58:20 (GMT) |
---|---|---|
committer | Remko Tronçon <git@el-tramo.be> | 2010-10-31 09:02:04 (GMT) |
commit | 966571644a51763b4a8da9c2c648f25301a4fb80 (patch) | |
tree | 5abc663374c5857973376ba476b67ac5bfd4af26 | |
parent | 544cbf6443a8f6c075b1dd5f064c818e7505dcc1 (diff) | |
download | swift-contrib-966571644a51763b4a8da9c2c648f25301a4fb80.zip swift-contrib-966571644a51763b4a8da9c2c648f25301a4fb80.tar.bz2 |
Make Timer one-shot.
-rw-r--r-- | SwifTools/Idle/ActualIdleDetector.cpp | 2 | ||||
-rw-r--r-- | Swiften/Network/BoostTimer.cpp | 2 | ||||
-rw-r--r-- | Swiften/Network/Timer.h | 17 | ||||
-rw-r--r-- | Swiften/StreamStack/WhitespacePingLayer.cpp | 2 |
4 files changed, 21 insertions, 2 deletions
diff --git a/SwifTools/Idle/ActualIdleDetector.cpp b/SwifTools/Idle/ActualIdleDetector.cpp index 111f4e2..59df632 100644 --- a/SwifTools/Idle/ActualIdleDetector.cpp +++ b/SwifTools/Idle/ActualIdleDetector.cpp @@ -26,7 +26,9 @@ ActualIdleDetector::~ActualIdleDetector() { } void ActualIdleDetector::handleTimerTick() { + timer->stop(); setIdle(querier->getIdleTimeSeconds() >= getIdleTimeSeconds()); + timer->start(); } } diff --git a/Swiften/Network/BoostTimer.cpp b/Swiften/Network/BoostTimer.cpp index 65e7712..ab6fbe0 100644 --- a/Swiften/Network/BoostTimer.cpp +++ b/Swiften/Network/BoostTimer.cpp @@ -32,8 +32,6 @@ void BoostTimer::handleTimerTick(const boost::system::error_code& error) { } else { eventLoop->postEvent(boost::bind(boost::ref(onTick)), shared_from_this()); - timer.expires_from_now(boost::posix_time::milliseconds(timeout)); - timer.async_wait(boost::bind(&BoostTimer::handleTimerTick, shared_from_this(), boost::asio::placeholders::error)); } } diff --git a/Swiften/Network/Timer.h b/Swiften/Network/Timer.h index 278a8fb..d44a00d 100644 --- a/Swiften/Network/Timer.h +++ b/Swiften/Network/Timer.h @@ -9,15 +9,32 @@ #include "Swiften/Base/boost_bsignals.h" namespace Swift { + /** + * A class for triggering an event after a given period. + */ class Timer { public: typedef boost::shared_ptr<Timer> ref; virtual ~Timer(); + /** + * Starts the timer. + * + * After the given period, onTick() will be called. + */ virtual void start() = 0; + + /** + * Cancels the timer. + * + * If the timer was started, onTick() will no longer be called. + */ virtual void stop() = 0; + /** + * Emitted when the timer expires. + */ boost::signal<void ()> onTick; }; } diff --git a/Swiften/StreamStack/WhitespacePingLayer.cpp b/Swiften/StreamStack/WhitespacePingLayer.cpp index 2adfcea..a99f300 100644 --- a/Swiften/StreamStack/WhitespacePingLayer.cpp +++ b/Swiften/StreamStack/WhitespacePingLayer.cpp @@ -29,7 +29,9 @@ void WhitespacePingLayer::handleDataRead(const ByteArray& data) { } void WhitespacePingLayer::handleTimerTick() { + timer->stop(); onWriteData(" "); + timer->start(); } void WhitespacePingLayer::setActive() { |