mirror of
https://github.com/falk-werner/webfuse-provider
synced 2026-03-02 04:09:18 +00:00
refactor: extracted timer function of adapter into separate library
This commit is contained in:
@@ -13,6 +13,9 @@
|
||||
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
|
||||
#include "webfuse/core/status_intern.h"
|
||||
|
||||
#include "wf/timer/manager.h"
|
||||
#include "wf/timer/timer.h"
|
||||
|
||||
static int wf_impl_server_protocol_callback(
|
||||
struct lws * wsi,
|
||||
enum lws_callback_reasons reason,
|
||||
@@ -28,7 +31,7 @@ static int wf_impl_server_protocol_callback(
|
||||
|
||||
struct wf_server_protocol * protocol = ws_protocol->user;
|
||||
|
||||
wf_impl_timeout_manager_check(&protocol->timeout_manager);
|
||||
wf_timer_manager_check(protocol->timer_manager);
|
||||
struct wf_impl_session * session = wf_impl_session_manager_get(&protocol->session_manager, wsi);
|
||||
|
||||
switch (reason)
|
||||
@@ -42,7 +45,7 @@ static int wf_impl_server_protocol_callback(
|
||||
wsi,
|
||||
&protocol->authenticators,
|
||||
&protocol->mountpoint_factory,
|
||||
&protocol->timeout_manager,
|
||||
protocol->timer_manager,
|
||||
protocol->server);
|
||||
|
||||
if (NULL != session)
|
||||
@@ -237,7 +240,7 @@ void wf_impl_server_protocol_init(
|
||||
|
||||
wf_impl_mountpoint_factory_move(mountpoint_factory, &protocol->mountpoint_factory);
|
||||
|
||||
wf_impl_timeout_manager_init(&protocol->timeout_manager);
|
||||
protocol->timer_manager = wf_timer_manager_create();
|
||||
wf_impl_session_manager_init(&protocol->session_manager);
|
||||
wf_impl_authenticators_init(&protocol->authenticators);
|
||||
|
||||
@@ -252,7 +255,7 @@ void wf_impl_server_protocol_cleanup(
|
||||
protocol->is_operational = false;
|
||||
|
||||
jsonrpc_server_dispose(protocol->server);
|
||||
wf_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wf_timer_manager_dispose(protocol->timer_manager);
|
||||
wf_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wf_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
wf_impl_mountpoint_factory_cleanup(&protocol->mountpoint_factory);
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#define WF_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
|
||||
#include "jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
#include "webfuse/adapter/impl/mountpoint_factory.h"
|
||||
#include "webfuse/adapter/impl/session_manager.h"
|
||||
@@ -18,14 +17,15 @@ extern "C"
|
||||
#endif
|
||||
|
||||
struct lws_protocols;
|
||||
struct wf_timer_manager;
|
||||
|
||||
struct wf_server_protocol
|
||||
{
|
||||
struct wf_impl_timeout_manager timeout_manager;
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_mountpoint_factory mountpoint_factory;
|
||||
struct wf_impl_session_manager session_manager;
|
||||
struct jsonrpc_server * server;
|
||||
struct wf_timer_manager * timer_manager;
|
||||
bool is_operational;
|
||||
};
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ static bool wf_impl_session_send(
|
||||
struct wf_impl_session * wf_impl_session_create(
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_timer_manager * timer_manager,
|
||||
struct jsonrpc_server * server,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory)
|
||||
{
|
||||
@@ -59,7 +59,7 @@ struct wf_impl_session * wf_impl_session_create(
|
||||
session->authenticators = authenticators;
|
||||
session->server = server;
|
||||
session->mountpoint_factory = mountpoint_factory;
|
||||
session->rpc = jsonrpc_proxy_create(timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
|
||||
session->rpc = jsonrpc_proxy_create(timer_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
|
||||
wf_slist_init(&session->messages);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ struct wf_message;
|
||||
struct wf_credentials;
|
||||
struct wf_impl_authenticators;
|
||||
struct wf_impl_mountpoint_factory;
|
||||
struct wf_impl_timeout_manager;
|
||||
struct timer_manager;
|
||||
|
||||
struct wf_impl_session
|
||||
{
|
||||
@@ -43,7 +43,7 @@ struct wf_impl_session
|
||||
extern struct wf_impl_session * wf_impl_session_create(
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_timer_manager * timer_manager,
|
||||
struct jsonrpc_server * server,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory);
|
||||
|
||||
|
||||
@@ -28,11 +28,11 @@ struct wf_impl_session * wf_impl_session_manager_add(
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_timer_manager * timer_manager,
|
||||
struct jsonrpc_server * server)
|
||||
{
|
||||
struct wf_impl_session * session = wf_impl_session_create(
|
||||
wsi, authenticators, timeout_manager, server, mountpoint_factory);
|
||||
wsi, authenticators, timer_manager, server, mountpoint_factory);
|
||||
if (NULL != session)
|
||||
{
|
||||
wf_slist_append(&manager->sessions, &session->item);
|
||||
|
||||
@@ -15,7 +15,7 @@ extern "C"
|
||||
#endif
|
||||
|
||||
struct lws;
|
||||
struct wf_impl_timeout_manager;
|
||||
struct wf_timer_manager;
|
||||
struct jsonrpc_server;
|
||||
|
||||
struct wf_impl_session_manager
|
||||
@@ -34,7 +34,7 @@ extern struct wf_impl_session * wf_impl_session_manager_add(
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_mountpoint_factory * mountpoint_factory,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_timer_manager * timer_manager,
|
||||
struct jsonrpc_server * server);
|
||||
|
||||
extern struct wf_impl_session * wf_impl_session_manager_get(
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
#include "webfuse/adapter/impl/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include "webfuse/adapter/impl/time/timer_intern.h"
|
||||
#include "webfuse/adapter/impl/time/timepoint.h"
|
||||
|
||||
void wf_impl_timeout_manager_init(
|
||||
struct wf_impl_timeout_manager * manager)
|
||||
{
|
||||
manager->timers = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_timeout_manager_cleanup(
|
||||
struct wf_impl_timeout_manager * manager)
|
||||
{
|
||||
struct wf_impl_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wf_impl_timer * next = timer->next;
|
||||
|
||||
wf_impl_timer_trigger(timer);
|
||||
|
||||
timer = next;
|
||||
}
|
||||
|
||||
manager->timers = NULL;
|
||||
|
||||
}
|
||||
|
||||
void wf_impl_timeout_manager_check(
|
||||
struct wf_impl_timeout_manager * manager)
|
||||
{
|
||||
struct wf_impl_timer * timer = manager->timers;
|
||||
while (NULL != timer)
|
||||
{
|
||||
struct wf_impl_timer * next = timer->next;
|
||||
|
||||
if (wf_impl_timer_is_timeout(timer))
|
||||
{
|
||||
wf_impl_timeout_manager_removetimer(manager, timer);
|
||||
wf_impl_timer_trigger(timer);
|
||||
}
|
||||
|
||||
timer = next;
|
||||
}
|
||||
}
|
||||
|
||||
void wf_impl_timeout_manager_addtimer(
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
if (NULL != manager->timers)
|
||||
{
|
||||
manager->timers->prev = timer;
|
||||
}
|
||||
|
||||
timer->next = manager->timers;
|
||||
timer->prev = NULL;
|
||||
manager->timers = timer;
|
||||
}
|
||||
|
||||
void wf_impl_timeout_manager_removetimer(
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
struct wf_impl_timer * prev = timer->prev;
|
||||
struct wf_impl_timer * next = timer->next;
|
||||
|
||||
if (NULL != prev)
|
||||
{
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
if (NULL != next)
|
||||
{
|
||||
next->prev = prev;
|
||||
}
|
||||
|
||||
if (manager->timers == timer)
|
||||
{
|
||||
manager->timers = next;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
|
||||
#define WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_timer;
|
||||
struct wf_impl_timeout_manager
|
||||
{
|
||||
struct wf_impl_timer * timers;
|
||||
};
|
||||
|
||||
extern void wf_impl_timeout_manager_init(
|
||||
struct wf_impl_timeout_manager * manager);
|
||||
|
||||
extern void wf_impl_timeout_manager_cleanup(
|
||||
struct wf_impl_timeout_manager * manager);
|
||||
|
||||
extern void wf_impl_timeout_manager_check(
|
||||
struct wf_impl_timeout_manager * manager);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,24 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
#define WF_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
|
||||
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern void wf_impl_timeout_manager_addtimer(
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
extern void wf_impl_timeout_manager_removetimer(
|
||||
struct wf_impl_timeout_manager * manager,
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,31 +0,0 @@
|
||||
#include "webfuse/adapter/impl/time/timepoint.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#define WF_MSEC_PER_SEC ((wf_impl_timepoint) 1000)
|
||||
#define WF_NSEC_PER_MSEC ((wf_impl_timepoint) 1000 * 1000)
|
||||
|
||||
wf_impl_timepoint wf_impl_timepoint_now(void)
|
||||
{
|
||||
struct timespec tp;
|
||||
clock_gettime(CLOCK_MONOTONIC, &tp);
|
||||
|
||||
wf_impl_timepoint const now = (tp.tv_sec * WF_MSEC_PER_SEC) + (tp.tv_nsec / WF_NSEC_PER_MSEC);
|
||||
return now;
|
||||
}
|
||||
|
||||
wf_impl_timepoint wf_impl_timepoint_in_msec(wf_impl_timediff value)
|
||||
{
|
||||
wf_impl_timepoint const now = wf_impl_timepoint_now();
|
||||
wf_impl_timepoint result = now + ((wf_impl_timepoint) value);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool wf_impl_timepoint_is_elapsed(wf_impl_timepoint tp)
|
||||
{
|
||||
wf_impl_timepoint const now = wf_impl_timepoint_now();
|
||||
wf_impl_timediff const diff = (wf_impl_timediff) (tp - now);
|
||||
|
||||
return (0 > diff);
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_TIME_TIMEPOINT_H
|
||||
#define WF_ADAPTER_IMPL_TIME_TIMEPOINT_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
#include <cinttypes>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
typedef uint64_t wf_impl_timepoint;
|
||||
typedef int64_t wf_impl_timediff;
|
||||
|
||||
extern wf_impl_timepoint wf_impl_timepoint_now(void);
|
||||
|
||||
extern wf_impl_timepoint wf_impl_timepoint_in_msec(
|
||||
wf_impl_timediff value);
|
||||
|
||||
extern bool wf_impl_timepoint_is_elapsed(
|
||||
wf_impl_timepoint timepoint);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,65 +0,0 @@
|
||||
#include "webfuse/adapter/impl/time/timer_intern.h"
|
||||
#include "webfuse/adapter/impl/time/timeout_manager_intern.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
void wf_impl_timer_init(
|
||||
struct wf_impl_timer * timer,
|
||||
struct wf_impl_timeout_manager * manager)
|
||||
{
|
||||
timer->manager = manager;
|
||||
timer->timeout = 0;
|
||||
timer->timeout_handler = NULL;
|
||||
timer->user_data = NULL;
|
||||
timer->prev = NULL;
|
||||
timer->next = NULL;
|
||||
}
|
||||
|
||||
void wf_impl_timer_cleanup(
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
memset(timer, 0, sizeof(struct wf_impl_timer));
|
||||
}
|
||||
|
||||
void wf_impl_timer_start(
|
||||
struct wf_impl_timer * timer,
|
||||
wf_impl_timepoint absolute_timeout,
|
||||
wf_impl_timer_timeout_fn * handler,
|
||||
void * user_data)
|
||||
{
|
||||
timer->timeout = absolute_timeout;
|
||||
timer->timeout_handler = handler;
|
||||
timer->user_data = user_data;
|
||||
|
||||
wf_impl_timeout_manager_addtimer(timer->manager, timer);
|
||||
}
|
||||
|
||||
void wf_impl_timer_cancel(
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
wf_impl_timeout_manager_removetimer(timer->manager, timer);
|
||||
|
||||
timer->timeout = 0;
|
||||
timer->timeout_handler = NULL;
|
||||
timer->user_data = NULL;
|
||||
}
|
||||
|
||||
bool wf_impl_timer_is_timeout(
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
return wf_impl_timepoint_is_elapsed(timer->timeout);
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_timer_trigger(
|
||||
struct wf_impl_timer * timer)
|
||||
{
|
||||
if (NULL != timer->timeout_handler)
|
||||
{
|
||||
timer->prev = NULL;
|
||||
timer->next = NULL;
|
||||
|
||||
timer->timeout_handler(timer);
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_TIME_TIMER_H
|
||||
#define WF_ADAPTER_IMPL_TIME_TIMER_H
|
||||
|
||||
#include "webfuse/adapter/impl/time/timepoint.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_timer;
|
||||
struct wf_impl_timeout_manager;
|
||||
|
||||
typedef void wf_impl_timer_timeout_fn(struct wf_impl_timer * timer);
|
||||
|
||||
struct wf_impl_timer
|
||||
{
|
||||
struct wf_impl_timeout_manager * manager;
|
||||
wf_impl_timepoint timeout;
|
||||
wf_impl_timer_timeout_fn * timeout_handler;
|
||||
void * user_data;
|
||||
struct wf_impl_timer * next;
|
||||
struct wf_impl_timer * prev;
|
||||
};
|
||||
|
||||
extern void wf_impl_timer_init(
|
||||
struct wf_impl_timer * timer,
|
||||
struct wf_impl_timeout_manager * manager);
|
||||
|
||||
extern void wf_impl_timer_cleanup(
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
extern void wf_impl_timer_start(
|
||||
struct wf_impl_timer * timer,
|
||||
wf_impl_timepoint absolute_timeout,
|
||||
wf_impl_timer_timeout_fn * handler,
|
||||
void * user_data);
|
||||
|
||||
extern void wf_impl_timer_cancel(
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,25 +0,0 @@
|
||||
#ifndef WF_ADAPTER_IMPL_TIME_TIMER_INTERN_H
|
||||
#define WF_ADAPTER_IMPL_TIME_TIMER_INTERN_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#endif
|
||||
|
||||
#include "webfuse/adapter/impl/time/timer.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
extern bool wf_impl_timer_is_timeout(
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
extern void wf_impl_timer_trigger(
|
||||
struct wf_impl_timer * timer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user