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