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