1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00
falk-werner_webfuse/lib/webfuse/impl/timer/timer.c
2020-06-28 19:43:08 +02:00

68 lines
1.3 KiB
C

#include "webfuse/impl/timer/timer_intern.h"
#include "webfuse/impl/timer/manager_intern.h"
#include "webfuse/impl/timer/timepoint.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
struct wf_timer *
wf_impl_timer_create(
struct wf_timer_manager * manager,
wf_timer_on_timer_fn * on_timer,
void * user_data)
{
struct wf_timer * timer = malloc(sizeof(struct wf_timer));
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
wf_impl_timer_dispose(
struct wf_timer * timer)
{
free(timer);
}
void wf_impl_timer_start(
struct wf_timer * timer,
int timeout_ms)
{
timer->timeout = wf_impl_timer_timepoint_in_msec(timeout_ms);
wf_impl_timer_manager_addtimer(timer->manager, timer);
}
void wf_impl_timer_cancel(
struct wf_timer * timer)
{
wf_impl_timer_manager_removetimer(timer->manager, timer);
timer->timeout = 0;
}
bool wf_impl_timer_is_timeout(
struct wf_timer * timer)
{
return wf_impl_timer_timepoint_is_elapsed(timer->timeout);
}
void wf_impl_timer_trigger(
struct wf_timer * timer)
{
if (0 != timer->on_timer)
{
timer->prev = NULL;
timer->next = NULL;
timer->on_timer(timer, timer->user_data);
}
}