summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-09-12 18:29:39 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-09-13 19:19:52 (GMT)
commitef1052bbdb315aaa1c6254098ea05638d9a25b2f (patch)
tree482277f649f6c0fc00027514ea8986861fe33437 /Swiften/Network
parent3ae8cccfe9c6bfed5dda5f024a5cb046ccfc9793 (diff)
downloadswift-ef1052bbdb315aaa1c6254098ea05638d9a25b2f.zip
swift-ef1052bbdb315aaa1c6254098ea05638d9a25b2f.tar.bz2
Added presence notifier.
Diffstat (limited to 'Swiften/Network')
-rw-r--r--Swiften/Network/DummyTimerFactory.cpp30
1 files changed, 12 insertions, 18 deletions
diff --git a/Swiften/Network/DummyTimerFactory.cpp b/Swiften/Network/DummyTimerFactory.cpp
index 466dd38..105b103 100644
--- a/Swiften/Network/DummyTimerFactory.cpp
+++ b/Swiften/Network/DummyTimerFactory.cpp
@@ -15,19 +15,26 @@ namespace Swift {
class DummyTimerFactory::DummyTimer : public Timer {
public:
- DummyTimer(int timeout) : timeout(timeout), isRunning(false) {
+ DummyTimer(int timeout, DummyTimerFactory* factory) : timeout(timeout), factory(factory), isRunning(false), startTime(~0) {
}
virtual void start() {
isRunning = true;
+ startTime = factory->currentTime;
}
virtual void stop() {
isRunning = false;
}
+
+ int getAlarmTime() const {
+ return startTime + timeout;
+ }
int timeout;
+ DummyTimerFactory* factory;
bool isRunning;
+ int startTime;
};
@@ -35,31 +42,18 @@ DummyTimerFactory::DummyTimerFactory() : currentTime(0) {
}
boost::shared_ptr<Timer> DummyTimerFactory::createTimer(int milliseconds) {
- boost::shared_ptr<DummyTimer> timer(new DummyTimer(milliseconds));
+ boost::shared_ptr<DummyTimer> timer(new DummyTimer(milliseconds, this));
timers.push_back(timer);
return timer;
}
-static bool hasZeroTimeout(boost::shared_ptr<DummyTimerFactory::DummyTimer> timer) {
- return timer->timeout == 0;
-}
-
void DummyTimerFactory::setTime(int time) {
assert(time > currentTime);
- int increment = time - currentTime;
- std::vector< boost::shared_ptr<DummyTimer> > notifyTimers(timers.begin(), timers.end());
- foreach(boost::shared_ptr<DummyTimer> timer, notifyTimers) {
- if (increment >= timer->timeout) {
- if (timer->isRunning) {
- timer->onTick();
- }
- timer->timeout = 0;
- }
- else {
- timer->timeout -= increment;
+ foreach(boost::shared_ptr<DummyTimer> timer, timers) {
+ if (timer->getAlarmTime() > currentTime && timer->getAlarmTime() <= time && timer->isRunning) {
+ timer->onTick();
}
}
- timers.erase(std::remove_if(timers.begin(), timers.end(), hasZeroTimeout), timers.end());
currentTime = time;
}