acl/lib_acl_cpp/include/acl_cpp/event/event_timer.hpp

151 lines
3.8 KiB
C++
Raw Normal View History

#pragma once
2017-06-02 14:47:24 +08:00
#include "../acl_cpp_define.hpp"
#include "../stdlib/noncopyable.hpp"
2014-11-19 00:25:21 +08:00
#include <list>
namespace acl
{
class event_task;
class ACL_CPP_API event_timer : public noncopyable
2014-11-19 00:25:21 +08:00
{
public:
/**
*
* @param keep {bool}
2014-11-19 00:25:21 +08:00
*/
event_timer(bool keep = false);
virtual ~event_timer();
/**
*
*
*
*
*
* 1) 0
* 2)
* 3) del_timer(event_timer*)
2014-11-19 00:25:21 +08:00
*/
virtual void destroy(void) {}
/**
*
2014-11-19 00:25:21 +08:00
* @return {bool}
*/
bool empty(void) const
{
return tasks_.empty();
}
/**
*
2014-11-19 00:25:21 +08:00
* @return {size_t}
*/
size_t length(void) const
{
return length_;
}
/**
*
2014-11-19 00:25:21 +08:00
* @param on {bool}
*/
void keep_timer(bool on);
/**
*
2014-11-19 00:25:21 +08:00
* @return {bool}
*/
bool keep_timer(void) const
{
return keep_;
}
/**
*
* @return {int}
2014-11-19 00:25:21 +08:00
*/
int clear(void);
/**
*
* timer_callback event_timer
*
* @param id {unsigned int} ID
2014-11-19 00:25:21 +08:00
*/
virtual void timer_callback(unsigned int id) = 0;
/****************************************************************/
/* 子类可以调用如下函数添加一些新的定时器任务 ID 号 */
2014-11-19 00:25:21 +08:00
/****************************************************************/
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
/**
* ID号便
*
* @param id {unsigned int} ID号
* @param delay {__int64}
* ID号传回()
* @return {__int64} ID还多久()
2014-11-19 00:25:21 +08:00
*/
__int64 set_task(unsigned int id, __int64 delay);
/**
* ID对应的定时任务
* @param {unsigned int} ID
* @return {__int64} ID还多久()
2014-11-19 00:25:21 +08:00
*/
__int64 del_task(unsigned int id);
#else
long long int set_task(unsigned int id, long long int delay);
long long int del_task(unsigned int id);
#endif
//////////////////////////////////////////////////////////////////////
/**
*
* @return {long lont int}
2014-11-19 00:25:21 +08:00
*/
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
__int64 trigger(void);
__int64 min_delay(void) const
{
return min_delay_;
}
#else
long long int trigger(void);
long long int min_delay(void) const
{
return min_delay_;
}
#endif
protected:
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
__int64 min_delay_;
__int64 present_;
#else
long long int min_delay_;
long long int present_;
#endif
private:
size_t length_;
std::list<event_task*> tasks_;
bool keep_; // 该定时器是否允许自动重启
#if defined(_WIN32) || defined(_WIN64)
2014-11-19 00:25:21 +08:00
__int64 set_task(event_task* task);
#else
long long int set_task(event_task* task);
#endif
/**
*
2014-11-19 00:25:21 +08:00
*/
void set_time(void);
};
} // namespace acl