summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-10-31 08:58:20 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-10-31 09:02:04 (GMT)
commit966571644a51763b4a8da9c2c648f25301a4fb80 (patch)
tree5abc663374c5857973376ba476b67ac5bfd4af26 /Swiften/Network
parent544cbf6443a8f6c075b1dd5f064c818e7505dcc1 (diff)
downloadswift-966571644a51763b4a8da9c2c648f25301a4fb80.zip
swift-966571644a51763b4a8da9c2c648f25301a4fb80.tar.bz2
Make Timer one-shot.
Diffstat (limited to 'Swiften/Network')
-rw-r--r--Swiften/Network/BoostTimer.cpp2
-rw-r--r--Swiften/Network/Timer.h17
2 files changed, 17 insertions, 2 deletions
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;
};
}