aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Timer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/Timer.cc')
-rw-r--r--src/FbTk/Timer.cc38
1 files changed, 37 insertions, 1 deletions
diff --git a/src/FbTk/Timer.cc b/src/FbTk/Timer.cc
index 9492ac6..ff568dc 100644
--- a/src/FbTk/Timer.cc
+++ b/src/FbTk/Timer.cc
@@ -24,7 +24,8 @@
24 24
25#include "Timer.hh" 25#include "Timer.hh"
26 26
27#include "Command.hh" 27#include "ObjectRegistry.hh"
28#include "StringUtil.hh"
28 29
29//use GNU extensions 30//use GNU extensions
30#ifndef _GNU_SOURCE 31#ifndef _GNU_SOURCE
@@ -246,6 +247,41 @@ void Timer::addTimer(Timer *timer) {
246 247
247} 248}
248 249
250Command *DelayedCmd::parse(const std::string &command,
251 const std::string &args, bool trusted) {
252
253 std::string cmd_str;
254 int err = StringUtil::getStringBetween(cmd_str, args.c_str(), '{', '}');
255 if (err == 0)
256 return 0;
257
258 RefCount<Command> cmd(ObjectRegistry<Command>::instance().parse(cmd_str, trusted));
259 if (*cmd == 0)
260 return 0;
261
262 int delay = 200000;
263 StringUtil::fromString<int>(args.c_str() + err, delay);
264
265 return new DelayedCmd(cmd, delay);
266}
267
268REGISTER_OBJECT_PARSER(delay, DelayedCmd::parse, Command);
269
270DelayedCmd::DelayedCmd(RefCount<Command> &cmd, unsigned int timeout) {
271 timeval to; // defaults to 200ms
272 to.tv_sec = timeout/1000000;
273 to.tv_usec = timeout % 1000000;
274 m_timer.setTimeout(to);
275 m_timer.setCommand(cmd);
276 m_timer.fireOnce(true);
277}
278
279void DelayedCmd::execute() {
280 if (m_timer.isTiming())
281 m_timer.stop();
282 m_timer.start();
283}
284
249void Timer::removeTimer(Timer *timer) { 285void Timer::removeTimer(Timer *timer) {
250 assert(timer); 286 assert(timer);
251 m_timerlist.remove(timer); 287 m_timerlist.remove(timer);