diff options
Diffstat (limited to 'src/FbTk')
-rw-r--r-- | src/FbTk/Timer.cc | 8 | ||||
-rw-r--r-- | src/FbTk/Timer.hh | 14 |
2 files changed, 20 insertions, 2 deletions
diff --git a/src/FbTk/Timer.cc b/src/FbTk/Timer.cc index 13bfc05..9b3fe8c 100644 --- a/src/FbTk/Timer.cc +++ b/src/FbTk/Timer.cc | |||
@@ -285,11 +285,15 @@ Command<void> *DelayedCmd::parse(const std::string &command, | |||
285 | REGISTER_COMMAND_PARSER(delay, DelayedCmd::parse, void); | 285 | REGISTER_COMMAND_PARSER(delay, DelayedCmd::parse, void); |
286 | 286 | ||
287 | DelayedCmd::DelayedCmd(const RefCount<Slot<void> > &cmd, unsigned int timeout) { | 287 | DelayedCmd::DelayedCmd(const RefCount<Slot<void> > &cmd, unsigned int timeout) { |
288 | timeval to; // defaults to 200ms | 288 | initTimer(timeout); |
289 | m_timer.setCommand(cmd); | ||
290 | } | ||
291 | |||
292 | void DelayedCmd::initTimer(unsigned int timeout) { | ||
293 | timeval to; | ||
289 | to.tv_sec = timeout/1000000; | 294 | to.tv_sec = timeout/1000000; |
290 | to.tv_usec = timeout % 1000000; | 295 | to.tv_usec = timeout % 1000000; |
291 | m_timer.setTimeout(to); | 296 | m_timer.setTimeout(to); |
292 | m_timer.setCommand(cmd); | ||
293 | m_timer.fireOnce(true); | 297 | m_timer.fireOnce(true); |
294 | } | 298 | } |
295 | 299 | ||
diff --git a/src/FbTk/Timer.hh b/src/FbTk/Timer.hh index 4b5a10e..376eac0 100644 --- a/src/FbTk/Timer.hh +++ b/src/FbTk/Timer.hh | |||
@@ -66,6 +66,9 @@ public: | |||
66 | void setTimeout(const timeval &val); | 66 | void setTimeout(const timeval &val); |
67 | void setTimeout(unsigned int secs, unsigned int usecs); | 67 | void setTimeout(unsigned int secs, unsigned int usecs); |
68 | void setCommand(const RefCount<Slot<void> > &cmd); | 68 | void setCommand(const RefCount<Slot<void> > &cmd); |
69 | template<typename Functor> | ||
70 | void setFunctor(const Functor &functor) | ||
71 | { setCommand(RefCount<Slot<void> >(new SlotImpl<Functor, void>(functor))); } | ||
69 | void setInterval(int val) { m_interval = val; } | 72 | void setInterval(int val) { m_interval = val; } |
70 | /// start timing | 73 | /// start timing |
71 | void start(); | 74 | void start(); |
@@ -111,10 +114,21 @@ private: | |||
111 | class DelayedCmd: public Command<void> { | 114 | class DelayedCmd: public Command<void> { |
112 | public: | 115 | public: |
113 | DelayedCmd(const RefCount<Slot<void> > &cmd, unsigned int timeout = 200000); | 116 | DelayedCmd(const RefCount<Slot<void> > &cmd, unsigned int timeout = 200000); |
117 | |||
118 | // this constructor has inverted order of parameters to avoid ambiguity with the previous | ||
119 | // constructor | ||
120 | template<typename Functor> | ||
121 | DelayedCmd(unsigned int timeout, const Functor &functor) { | ||
122 | initTimer(timeout); | ||
123 | m_timer.setFunctor(functor); | ||
124 | } | ||
125 | |||
114 | void execute(); | 126 | void execute(); |
115 | static Command<void> *parse(const std::string &command, | 127 | static Command<void> *parse(const std::string &command, |
116 | const std::string &args, bool trusted); | 128 | const std::string &args, bool trusted); |
117 | private: | 129 | private: |
130 | void initTimer(unsigned int timeout); | ||
131 | |||
118 | Timer m_timer; | 132 | Timer m_timer; |
119 | }; | 133 | }; |
120 | 134 | ||