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