142bf2220SShuo Chen// excerpts from http://code.google.com/p/muduo/ 242bf2220SShuo Chen// 342bf2220SShuo Chen// Use of this source code is governed by a BSD-style license 442bf2220SShuo Chen// that can be found in the License file. 542bf2220SShuo Chen// 642bf2220SShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com) 742bf2220SShuo Chen 842bf2220SShuo Chen#ifndef MUDUO_NET_TIMER_H 942bf2220SShuo Chen#define MUDUO_NET_TIMER_H 1042bf2220SShuo Chen 1142bf2220SShuo Chen#include <boost/noncopyable.hpp> 1242bf2220SShuo Chen 1342bf2220SShuo Chen#include "datetime/Timestamp.h" 1442bf2220SShuo Chen#include "Callbacks.h" 1542bf2220SShuo Chen 1642bf2220SShuo Chennamespace muduo 1742bf2220SShuo Chen{ 1842bf2220SShuo Chen 1942bf2220SShuo Chen/// 2042bf2220SShuo Chen/// Internal class for timer event. 2142bf2220SShuo Chen/// 2242bf2220SShuo Chenclass Timer : boost::noncopyable 2342bf2220SShuo Chen{ 2442bf2220SShuo Chen public: 2542bf2220SShuo Chen Timer(const TimerCallback& cb, Timestamp when, double interval) 2642bf2220SShuo Chen : callback_(cb), 2742bf2220SShuo Chen expiration_(when), 2842bf2220SShuo Chen interval_(interval), 2942bf2220SShuo Chen repeat_(interval > 0.0) 3042bf2220SShuo Chen { } 3142bf2220SShuo Chen 3242bf2220SShuo Chen void run() const 3342bf2220SShuo Chen { 3442bf2220SShuo Chen callback_(); 3542bf2220SShuo Chen } 3642bf2220SShuo Chen 3742bf2220SShuo Chen Timestamp expiration() const { return expiration_; } 3842bf2220SShuo Chen bool repeat() const { return repeat_; } 3942bf2220SShuo Chen 4042bf2220SShuo Chen void restart(Timestamp now); 4142bf2220SShuo Chen 4242bf2220SShuo Chen private: 4342bf2220SShuo Chen const TimerCallback callback_; 4442bf2220SShuo Chen Timestamp expiration_; 4542bf2220SShuo Chen const double interval_; 4642bf2220SShuo Chen const bool repeat_; 4742bf2220SShuo Chen}; 4842bf2220SShuo Chen 4942bf2220SShuo Chen} 5042bf2220SShuo Chen#endif // MUDUO_NET_TIMER_H 51