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