Timer.h revision 40161064
140161064SShuo Chen// excerpts from http://code.google.com/p/muduo/ 240161064SShuo Chen// 340161064SShuo Chen// Use of this source code is governed by a BSD-style license 440161064SShuo Chen// that can be found in the License file. 540161064SShuo Chen// 640161064SShuo Chen// Author: Shuo Chen (chenshuo at chenshuo dot com) 740161064SShuo Chen 840161064SShuo Chen#ifndef MUDUO_NET_TIMER_H 940161064SShuo Chen#define MUDUO_NET_TIMER_H 1040161064SShuo Chen 1140161064SShuo Chen#include <boost/noncopyable.hpp> 1240161064SShuo Chen 1340161064SShuo Chen#include "datetime/Timestamp.h" 1440161064SShuo Chen#include "Callbacks.h" 1540161064SShuo Chen 1640161064SShuo Chennamespace muduo 1740161064SShuo Chen{ 1840161064SShuo Chen 1940161064SShuo Chen/// 2040161064SShuo Chen/// Internal class for timer event. 2140161064SShuo Chen/// 2240161064SShuo Chenclass Timer : boost::noncopyable 2340161064SShuo Chen{ 2440161064SShuo Chen public: 2540161064SShuo Chen Timer(const TimerCallback& cb, Timestamp when, double interval) 2640161064SShuo Chen : callback_(cb), 2740161064SShuo Chen expiration_(when), 2840161064SShuo Chen interval_(interval), 2940161064SShuo Chen repeat_(interval > 0.0) 3040161064SShuo Chen { } 3140161064SShuo Chen 3240161064SShuo Chen void run() const 3340161064SShuo Chen { 3440161064SShuo Chen callback_(); 3540161064SShuo Chen } 3640161064SShuo Chen 3740161064SShuo Chen Timestamp expiration() const { return expiration_; } 3840161064SShuo Chen bool repeat() const { return repeat_; } 3940161064SShuo Chen 4040161064SShuo Chen void restart(Timestamp now); 4140161064SShuo Chen 4240161064SShuo Chen private: 4340161064SShuo Chen const TimerCallback callback_; 4440161064SShuo Chen Timestamp expiration_; 4540161064SShuo Chen const double interval_; 4640161064SShuo Chen const bool repeat_; 4740161064SShuo Chen}; 4840161064SShuo Chen 4940161064SShuo Chen} 5040161064SShuo Chen#endif // MUDUO_NET_TIMER_H 51