12a18e699SShuo Chen// excerpts from http://code.google.com/p/muduo/
22a18e699SShuo Chen//
32a18e699SShuo Chen// Use of this source code is governed by a BSD-style license
42a18e699SShuo Chen// that can be found in the License file.
52a18e699SShuo Chen//
62a18e699SShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com)
72a18e699SShuo Chen
82a18e699SShuo Chen#ifndef MUDUO_NET_TIMER_H
92a18e699SShuo Chen#define MUDUO_NET_TIMER_H
102a18e699SShuo Chen
112a18e699SShuo Chen#include <boost/noncopyable.hpp>
122a18e699SShuo Chen
132a18e699SShuo Chen#include "datetime/Timestamp.h"
142a18e699SShuo Chen#include "Callbacks.h"
152a18e699SShuo Chen
162a18e699SShuo Chennamespace muduo
172a18e699SShuo Chen{
182a18e699SShuo Chen
192a18e699SShuo Chen///
202a18e699SShuo Chen/// Internal class for timer event.
212a18e699SShuo Chen///
222a18e699SShuo Chenclass Timer : boost::noncopyable
232a18e699SShuo Chen{
242a18e699SShuo Chen public:
252a18e699SShuo Chen  Timer(const TimerCallback& cb, Timestamp when, double interval)
262a18e699SShuo Chen    : callback_(cb),
272a18e699SShuo Chen      expiration_(when),
282a18e699SShuo Chen      interval_(interval),
292a18e699SShuo Chen      repeat_(interval > 0.0)
302a18e699SShuo Chen  { }
312a18e699SShuo Chen
322a18e699SShuo Chen  void run() const
332a18e699SShuo Chen  {
342a18e699SShuo Chen    callback_();
352a18e699SShuo Chen  }
362a18e699SShuo Chen
372a18e699SShuo Chen  Timestamp expiration() const  { return expiration_; }
382a18e699SShuo Chen  bool repeat() const { return repeat_; }
392a18e699SShuo Chen
402a18e699SShuo Chen  void restart(Timestamp now);
412a18e699SShuo Chen
422a18e699SShuo Chen private:
432a18e699SShuo Chen  const TimerCallback callback_;
442a18e699SShuo Chen  Timestamp expiration_;
452a18e699SShuo Chen  const double interval_;
462a18e699SShuo Chen  const bool repeat_;
472a18e699SShuo Chen};
482a18e699SShuo Chen
492a18e699SShuo Chen}
502a18e699SShuo Chen#endif  // MUDUO_NET_TIMER_H
51