From 966571644a51763b4a8da9c2c648f25301a4fb80 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Sun, 31 Oct 2010 09:58:20 +0100
Subject: Make Timer one-shot.


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() {
-- 
cgit v0.10.2-6-g49f6