项目地址
使用范例
接口使用顺序
- 1 调用 init_
- 2 启动定时器 begin_
- 3 停止定时器 end_
ITimerPP类接口
class ITimerPP
{
public:
using uint = unsigned int;
enum TimerType
{
/// 单次执行
TIMER_TYPE_ONE_SHORT = 0,
/// 周期执行
TIMER_TYPE_PERIODIC = 1,
};
public:
virtual ~ITimerPP() { }
virtual int init_(const TimerType&& tt, ITimerCallBack* pcb) = 0;
virtual int begin_(const uint&& interval_ms) = 0;
virtual int end_() = 0;
};
实现超时处理函数即可
class demoTimerCallback : public oct_tk::ITimerCallBack
{
public:
virtual void timer_call_back_()
{
static int index = 0;
std::cout << "\n index=" << ++index << "=";
}
};
创建定时器
demoTimerCallback tc;
std::unique_ptr<ITimerPP> demo_timer = oct_tk::new_itimer_();
ITimerPP* ptimer = demo_timer.get();
ptimer->init_(oct_tk::ITimerPP::TIMER_TYPE_PERIODIC, &tc);
ptimer->begin_(40);
std::this_thread::sleep_for(std::chrono::seconds(1 * 30));
ptimer->end_();
NOTE
- 完整范例可在项目中 example中 main.cc中获取
更新日志
- 2023-03-11
- 重新封装windows多媒体定时器。 完整代码如下(copy即可使用)
TimerImp.h
#ifndef TIMER_IMP_H_
#define TIMER_IMP_H_
#include <functional>
#include <string>
#include <atomic>
namespace oct_tm
{
class NonCopyable
{
protected:
NonCopyable() {}
virtual