//
|
// Created by YY on 2021/3/16.
|
//
|
|
#ifndef NDKADV_APPTIMER_H
|
#define NDKADV_APPTIMER_H
|
|
#include <cstdint>
|
#include <functional>
|
#include <thread>
|
#include <chrono>
|
#include <atomic>
|
#include <mutex>
|
#include <condition_variable>
|
#include <string>
|
#include <ctime>
|
|
#define D_SEC(n) ((n)*1000UL)
|
#define D_MIN(n) ((n)*1000UL*60UL)
|
#define D_HOUR(n) ((n)*1000UL*60UL*60UL)
|
|
typedef struct {
|
int var1;
|
int var2;
|
void * var_ptr;
|
int var_length;
|
} apptimer_var_t;
|
|
class CTimer {
|
public:
|
CTimer();
|
virtual ~CTimer();
|
static bool _updateStatus(CTimer *timer);
|
static void _do_task_func(uint32_t msec, CTimer *timer, std::function<void(apptimer_var_t)> callback);
|
bool start(uint32_t msec, std::function<void(apptimer_var_t)> callback);
|
void stop();
|
void copy(int value1, int value2, const void *data, int length);
|
static void clear(CTimer *timer);
|
private:
|
std::mutex cv_mtx;
|
std::condition_variable cv;
|
// std::thread callbackThread;
|
std::thread *pthread;
|
apptimer_var_t var;
|
public:
|
std::atomic_int flag;
|
};
|
|
void AppTimer_init(void);
|
|
void AppTimer_add(void(*cb)(apptimer_var_t), uint32_t msec);
|
|
void AppTimer_add(void(*cb)(apptimer_var_t), uint32_t msec, int value1, int value2 = 0);
|
|
void AppTimer_add(void(*cb)(apptimer_var_t), uint32_t msec, void *data, int lenght);
|
|
void AppTimer_delete(void (*cb) (apptimer_var_t));
|
|
uint32_t AppTimer_GetTickCount(void);
|
|
uint64_t AppTimer_GetGmtTickCount(void);
|
|
std::string FormatTime(const char *fmt);
|
|
std::time_t MktimeString(const char *str, const char *fmt);
|
|
time_t TimeStamp(int year, int mon, int day, int hour, int min, int sec);
|
|
#endif //NDKADV_APPTIMER_H
|