1// excerpts from http://code.google.com/p/muduo/
2//
3// Use of this source code is governed by a BSD-style license
4// that can be found in the License file.
5//
6// Author: Shuo Chen (chenshuo at chenshuo dot com)
7
8#ifndef MUDUO_NET_TIMER_H
9#define MUDUO_NET_TIMER_H
10
11#include <boost/noncopyable.hpp>
12
13#include "datetime/Timestamp.h"
14#include "Callbacks.h"
15
16namespace muduo
17{
18
19///
20/// Internal class for timer event.
21///
22class Timer : boost::noncopyable
23{
24 public:
25  Timer(const TimerCallback& cb, Timestamp when, double interval)
26    : callback_(cb),
27      expiration_(when),
28      interval_(interval),
29      repeat_(interval > 0.0)
30  { }
31
32  void run() const
33  {
34    callback_();
35  }
36
37  Timestamp expiration() const  { return expiration_; }
38  bool repeat() const { return repeat_; }
39
40  void restart(Timestamp now);
41
42 private:
43  const TimerCallback callback_;
44  Timestamp expiration_;
45  const double interval_;
46  const bool repeat_;
47};
48
49}
50#endif  // MUDUO_NET_TIMER_H
51