2020-06-16 21:39:45 +00:00
|
|
|
#include "webfuse_provider/impl/timer/timer_intern.h"
|
|
|
|
#include "webfuse_provider/impl/timer/manager_intern.h"
|
|
|
|
#include "webfuse_provider/impl/timer/timepoint.h"
|
2020-02-29 20:06:40 +00:00
|
|
|
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_timer *
|
|
|
|
wfp_timer_create(
|
|
|
|
struct wfp_timer_manager * manager,
|
|
|
|
wfp_timer_on_timer_fn * on_timer,
|
2020-02-29 20:06:40 +00:00
|
|
|
void * user_data)
|
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
struct wfp_timer * timer = malloc(sizeof(struct wfp_timer));
|
2020-02-29 20:06:40 +00:00
|
|
|
timer->manager = manager;
|
|
|
|
timer->timeout = 0;
|
|
|
|
timer->on_timer = on_timer;
|
|
|
|
timer->user_data = user_data;
|
|
|
|
timer->prev = NULL;
|
|
|
|
timer->next = NULL;
|
|
|
|
|
|
|
|
return timer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_timer_dispose(
|
|
|
|
struct wfp_timer * timer)
|
2020-02-29 20:06:40 +00:00
|
|
|
{
|
|
|
|
free(timer);
|
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
void wfp_timer_start(
|
|
|
|
struct wfp_timer * timer,
|
2020-02-29 20:06:40 +00:00
|
|
|
int timeout_ms)
|
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
timer->timeout = wfp_timer_timepoint_in_msec(timeout_ms);
|
2020-02-29 20:06:40 +00:00
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_timer_manager_addtimer(timer->manager, timer);
|
2020-02-29 20:06:40 +00:00
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
void wfp_timer_cancel(
|
|
|
|
struct wfp_timer * timer)
|
2020-02-29 20:06:40 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
wfp_timer_manager_removetimer(timer->manager, timer);
|
2020-02-29 20:06:40 +00:00
|
|
|
|
|
|
|
timer->timeout = 0;
|
|
|
|
}
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
bool wfp_timer_is_timeout(
|
|
|
|
struct wfp_timer * timer)
|
2020-02-29 20:06:40 +00:00
|
|
|
{
|
2020-06-16 21:57:41 +00:00
|
|
|
return wfp_timer_timepoint_is_elapsed(timer->timeout);
|
2020-02-29 20:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-16 21:57:41 +00:00
|
|
|
void wfp_timer_trigger(
|
|
|
|
struct wfp_timer * timer)
|
2020-02-29 20:06:40 +00:00
|
|
|
{
|
|
|
|
if (0 != timer->on_timer)
|
|
|
|
{
|
|
|
|
timer->prev = NULL;
|
|
|
|
timer->next = NULL;
|
|
|
|
|
|
|
|
timer->on_timer(timer, timer->user_data);
|
|
|
|
}
|
|
|
|
}
|