1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2026-03-02 04:09:18 +00:00

feat(API wrapper): separates implementation from public API

* moves implementation to impl subdirectory
* adds prefix _impl to implementation symbols
* removes double compilation for shared and static libraries
* fixes include guards
* fixes usage of extern "C"
This commit is contained in:
Falk Werner
2019-03-26 15:35:33 +01:00
committed by GitHub
parent 48185776b6
commit 1c9d1c8420
146 changed files with 3043 additions and 2390 deletions

View File

@@ -0,0 +1,84 @@
#include "wsfs/adapter/impl/time/timeout_manager_intern.h"
#include <stddef.h>
#include "wsfs/adapter/impl/time/timer_intern.h"
#include "wsfs/adapter/impl/time/timepoint.h"
void wsfs_impl_timeout_manager_init(
struct wsfs_impl_timeout_manager * manager)
{
manager->timers = NULL;
}
void wsfs_impl_timeout_manager_cleanup(
struct wsfs_impl_timeout_manager * manager)
{
struct wsfs_impl_timer * timer = manager->timers;
while (NULL != timer)
{
struct wsfs_impl_timer * next = timer->next;
wsfs_impl_timer_trigger(timer);
timer = next;
}
manager->timers = NULL;
}
void wsfs_impl_timeout_manager_check(
struct wsfs_impl_timeout_manager * manager)
{
struct wsfs_impl_timer * timer = manager->timers;
while (NULL != timer)
{
struct wsfs_impl_timer * next = timer->next;
if (wsfs_impl_timer_is_timeout(timer))
{
wsfs_impl_timeout_manager_removetimer(manager, timer);
wsfs_impl_timer_trigger(timer);
}
timer = next;
}
}
void wsfs_impl_timeout_manager_addtimer(
struct wsfs_impl_timeout_manager * manager,
struct wsfs_impl_timer * timer)
{
if (NULL != manager->timers)
{
manager->timers->prev = timer;
}
timer->next = manager->timers;
timer->prev = NULL;
manager->timers = timer;
}
void wsfs_impl_timeout_manager_removetimer(
struct wsfs_impl_timeout_manager * manager,
struct wsfs_impl_timer * timer)
{
struct wsfs_impl_timer * prev = timer->prev;
struct wsfs_impl_timer * next = timer->next;
if (NULL != prev)
{
prev->next = next;
}
if (NULL != next)
{
next->prev = prev;
}
if (manager->timers == timer)
{
manager->timers = next;
}
}

View File

@@ -0,0 +1,29 @@
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
#define WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_H
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_impl_timer;
struct wsfs_impl_timeout_manager
{
struct wsfs_impl_timer * timers;
};
extern void wsfs_impl_timeout_manager_init(
struct wsfs_impl_timeout_manager * manager);
extern void wsfs_impl_timeout_manager_cleanup(
struct wsfs_impl_timeout_manager * manager);
extern void wsfs_impl_timeout_manager_check(
struct wsfs_impl_timeout_manager * manager);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,24 @@
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
#define WSFS_ADAPTER_IMPL_TIME_TIMEOUT_MANAGER_INTERN_H
#include "wsfs/adapter/impl/time/timeout_manager.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern void wsfs_impl_timeout_manager_addtimer(
struct wsfs_impl_timeout_manager * manager,
struct wsfs_impl_timer * timer);
extern void wsfs_impl_timeout_manager_removetimer(
struct wsfs_impl_timeout_manager * manager,
struct wsfs_impl_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,31 @@
#include "wsfs/adapter/impl/time/timepoint.h"
#include <time.h>
#define WSFS_MSEC_PER_SEC ((wsfs_impl_timepoint) 1000)
#define WSFS_NSEC_PER_MSEC ((wsfs_impl_timepoint) 1000 * 1000)
wsfs_impl_timepoint wsfs_impl_timepoint_now(void)
{
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
wsfs_impl_timepoint const now = (tp.tv_sec * WSFS_MSEC_PER_SEC) + (tp.tv_nsec / WSFS_NSEC_PER_MSEC);
return now;
}
wsfs_impl_timepoint wsfs_impl_timepoint_in_msec(wsfs_impl_timediff value)
{
wsfs_impl_timepoint const now = wsfs_impl_timepoint_now();
wsfs_impl_timepoint result = now + ((wsfs_impl_timepoint) value);
return result;
}
bool wsfs_impl_timepoint_is_elapsed(wsfs_impl_timepoint tp)
{
wsfs_impl_timepoint const now = wsfs_impl_timepoint_now();
wsfs_impl_timediff const diff = (wsfs_impl_timediff) (tp - now);
return (0 > diff);
}

View File

@@ -0,0 +1,31 @@
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMEPOINT_H
#define WSFS_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 wsfs_impl_timepoint;
typedef int64_t wsfs_impl_timediff;
extern wsfs_impl_timepoint wsfs_impl_timepoint_now(void);
extern wsfs_impl_timepoint wsfs_impl_timepoint_in_msec(
wsfs_impl_timediff value);
extern bool wsfs_impl_timepoint_is_elapsed(
wsfs_impl_timepoint timepoint);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,65 @@
#include "wsfs/adapter/impl/time/timer_intern.h"
#include "wsfs/adapter/impl/time/timeout_manager_intern.h"
#include <stddef.h>
#include <string.h>
void wsfs_impl_timer_init(
struct wsfs_impl_timer * timer,
struct wsfs_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 wsfs_impl_timer_cleanup(
struct wsfs_impl_timer * timer)
{
memset(timer, 0, sizeof(struct wsfs_impl_timer));
}
void wsfs_impl_timer_start(
struct wsfs_impl_timer * timer,
wsfs_impl_timepoint absolute_timeout,
wsfs_impl_timer_timeout_fn * handler,
void * user_data)
{
timer->timeout = absolute_timeout;
timer->timeout_handler = handler;
timer->user_data = user_data;
wsfs_impl_timeout_manager_addtimer(timer->manager, timer);
}
void wsfs_impl_timer_cancel(
struct wsfs_impl_timer * timer)
{
wsfs_impl_timeout_manager_removetimer(timer->manager, timer);
timer->timeout = 0;
timer->timeout_handler = NULL;
timer->user_data = NULL;
}
bool wsfs_impl_timer_is_timeout(
struct wsfs_impl_timer * timer)
{
return wsfs_impl_timepoint_is_elapsed(timer->timeout);
}
void wsfs_impl_timer_trigger(
struct wsfs_impl_timer * timer)
{
if (NULL != timer->timeout_handler)
{
timer->prev = NULL;
timer->next = NULL;
timer->timeout_handler(timer);
}
}

View File

@@ -0,0 +1,48 @@
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_H
#define WSFS_ADAPTER_IMPL_TIME_TIMER_H
#include "wsfs/adapter/impl/time/timepoint.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wsfs_impl_timer;
struct wsfs_impl_timeout_manager;
typedef void wsfs_impl_timer_timeout_fn(struct wsfs_impl_timer * timer);
struct wsfs_impl_timer
{
struct wsfs_impl_timeout_manager * manager;
wsfs_impl_timepoint timeout;
wsfs_impl_timer_timeout_fn * timeout_handler;
void * user_data;
struct wsfs_impl_timer * next;
struct wsfs_impl_timer * prev;
};
extern void wsfs_impl_timer_init(
struct wsfs_impl_timer * timer,
struct wsfs_impl_timeout_manager * manager);
extern void wsfs_impl_timer_cleanup(
struct wsfs_impl_timer * timer);
extern void wsfs_impl_timer_start(
struct wsfs_impl_timer * timer,
wsfs_impl_timepoint absolute_timeout,
wsfs_impl_timer_timeout_fn * handler,
void * user_data);
extern void wsfs_impl_timer_cancel(
struct wsfs_impl_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,25 @@
#ifndef WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H
#define WSFS_ADAPTER_IMPL_TIME_TIMER_INTERN_H
#ifndef __cplusplus
#include <stdbool.h>
#endif
#include "wsfs/adapter/impl/time/timer.h"
#ifdef __cplusplus
extern "C"
{
#endif
extern bool wsfs_impl_timer_is_timeout(
struct wsfs_impl_timer * timer);
extern void wsfs_impl_timer_trigger(
struct wsfs_impl_timer * timer);
#ifdef __cplusplus
}
#endif
#endif