1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00

integrated libwf_timer and libwf_jsonrpc into libwebfuse-core

This commit is contained in:
Falk Werner 2020-03-29 17:40:33 +02:00
parent 1d4db34ecb
commit bbdd5a24f5
73 changed files with 426 additions and 929 deletions

View File

@ -37,8 +37,6 @@ add_compile_options(
"-pthread" "-pthread"
) )
include(wf_timer)
include(wf_jsonrpc)
include(webfuse_core) include(webfuse_core)
include(webfuse_adapter) include(webfuse_adapter)
include(webfuse_provider) include(webfuse_provider)

View File

@ -7,17 +7,17 @@ include(GoogleTest)
pkg_check_modules(GMOCK gmock) pkg_check_modules(GMOCK gmock)
add_executable(alltests add_executable(alltests
lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc
lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc test/webfuse/tests/core/jsonrpc/mock_timer.cc
lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc test/webfuse/tests/core/jsonrpc/test_is_request.cc
lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc test/webfuse/tests/core/jsonrpc/test_request.cc
lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc test/webfuse/tests/core/jsonrpc/test_is_response.cc
lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc test/webfuse/tests/core/jsonrpc/test_response.cc
lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc test/webfuse/tests/core/jsonrpc/test_server.cc
lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc test/webfuse/tests/core/jsonrpc/test_proxy.cc
lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc test/webfuse/tests/core/jsonrpc/test_response_parser.cc
lib/wf/timer/test/wf/timer/test_timepoint.cc test/webfuse/tests/core/timer/test_timepoint.cc
lib/wf/timer/test/wf/timer/test_timer.cc test/webfuse/tests/core/timer/test_timer.cc
test/webfuse/utils/tempdir.cc test/webfuse/utils/tempdir.cc
test/webfuse/utils/file_utils.cc test/webfuse/utils/file_utils.cc
test/webfuse/utils/die_if.cc test/webfuse/utils/die_if.cc
@ -50,19 +50,6 @@ add_executable(alltests
test/webfuse/tests/integration/provider.cc test/webfuse/tests/integration/provider.cc
) )
target_include_directories(alltests PRIVATE
lib/wf/jsonrpc/include
lib/wf/jsonrpc/src
lib/wf/jsonrpc/test
lib/wf/timer/include
lib/wf/timer/src
${FUSE3_INCLUDE_DIRS}
)
target_compile_options(alltests PUBLIC
${FUSE3_CFLAGS_OTHER}
)
target_link_libraries(alltests PUBLIC target_link_libraries(alltests PUBLIC
-Wl,--wrap=wf_timer_manager_create -Wl,--wrap=wf_timer_manager_create
-Wl,--wrap=wf_timer_manager_dispose -Wl,--wrap=wf_timer_manager_dispose
@ -75,8 +62,6 @@ target_link_libraries(alltests PUBLIC
webfuse-adapter-static webfuse-adapter-static
webfuse-provider-static webfuse-provider-static
webfuse-core webfuse-core
wf_jsonrpc
wf_timer
${FUSE3_LIBRARIES} ${FUSE3_LIBRARIES}
${LWS_LIBRARIES} ${LWS_LIBRARIES}
${JANSSON_LIBRARIES} ${JANSSON_LIBRARIES}
@ -85,8 +70,8 @@ target_link_libraries(alltests PUBLIC
${GTEST_LIBRARIES} ${GTEST_LIBRARIES}
) )
target_include_directories(alltests PUBLIC test lib ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) target_include_directories(alltests PUBLIC test lib ${FUSE3_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS})
target_compile_options(alltests PUBLIC ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) target_compile_options(alltests PUBLIC ${FUSE3_CFLAGS_OTHER} ${GMOCK_CFLAGS} ${GTEST_CFLAGS})
enable_testing() enable_testing()
gtest_discover_tests(alltests TEST_PREFIX alltests:) gtest_discover_tests(alltests TEST_PREFIX alltests:)
@ -102,7 +87,7 @@ add_custom_target(coverage
add_dependencies(coverage alltests) add_dependencies(coverage alltests)
add_custom_target(coverage-report add_custom_target(coverage-report
COMMAND genhtml --branch-coverage --highlight --legend --prefix "${CMAKE_SOURCE_DIR}" coverage/lcov.info --output-directory coverage/report COMMAND genhtml --branch-coverage --highlight --legend coverage/lcov.info --output-directory coverage/report
) )
add_dependencies(coverage-report coverage) add_dependencies(coverage-report coverage)

View File

@ -26,8 +26,6 @@ add_library(webfuse-adapter-static STATIC
target_include_directories(webfuse-adapter-static PRIVATE target_include_directories(webfuse-adapter-static PRIVATE
lib lib
lib/wf/timer/include
lib/wf/jsonrpc/include
${FUSE3_INCLUDE_DIRS} ${FUSE3_INCLUDE_DIRS}
) )
@ -56,7 +54,7 @@ set_target_properties(webfuse-adapter PROPERTIES SOVERSION 0)
set_target_properties(webfuse-adapter PROPERTIES C_VISIBILITY_PRESET hidden) set_target_properties(webfuse-adapter PROPERTIES C_VISIBILITY_PRESET hidden)
set_target_properties(webfuse-adapter PROPERTIES COMPILE_DEFINITIONS "WF_API=WF_EXPORT") set_target_properties(webfuse-adapter PROPERTIES COMPILE_DEFINITIONS "WF_API=WF_EXPORT")
target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core wf_jsonrpc wf_timer) target_link_libraries(webfuse-adapter PRIVATE webfuse-adapter-static webfuse-core)
file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc" file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-adapter.pc"
"prefix=\"${CMAKE_INSTALL_PREFIX}\" "prefix=\"${CMAKE_INSTALL_PREFIX}\"

View File

@ -9,6 +9,16 @@ add_library(webfuse-core STATIC
lib/webfuse/core/base64.c lib/webfuse/core/base64.c
lib/webfuse/core/lws_log.c lib/webfuse/core/lws_log.c
lib/webfuse/core/json_util.c lib/webfuse/core/json_util.c
lib/webfuse/core/timer/manager.c
lib/webfuse/core/timer/timepoint.c
lib/webfuse/core/timer/timer.c
lib/webfuse/core/jsonrpc/proxy.c
lib/webfuse/core/jsonrpc/server.c
lib/webfuse/core/jsonrpc/method.c
lib/webfuse/core/jsonrpc/request.c
lib/webfuse/core/jsonrpc/response.c
lib/webfuse/core/jsonrpc/error.c
) )
set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core) set_target_properties(webfuse-core PROPERTIES OUTPUT_NAME webfuse-core)

View File

@ -22,8 +22,6 @@ set_target_properties(webfuse-provider-static PROPERTIES OUTPUT_NAME webfuse-pro
set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hidden) set_target_properties(webfuse-provider-static PROPERTIES C_VISIBILITY_PRESET hidden)
target_include_directories(webfuse-provider-static PRIVATE target_include_directories(webfuse-provider-static PRIVATE
lib lib
lib/wf/timer/include
lib/wf/jsonrpc/include
) )
add_library(webfuse-provider SHARED add_library(webfuse-provider SHARED
@ -36,7 +34,7 @@ set_target_properties(webfuse-provider PROPERTIES C_VISIBILITY_PRESET hidden)
set_target_properties(webfuse-provider PROPERTIES COMPILE_DEFINITIONS "WFP_API=WFP_EXPORT") set_target_properties(webfuse-provider PROPERTIES COMPILE_DEFINITIONS "WFP_API=WFP_EXPORT")
target_include_directories(webfuse-provider PUBLIC lib) target_include_directories(webfuse-provider PUBLIC lib)
target_link_libraries(webfuse-provider PRIVATE webfuse-provider-static webfuse-core wf_jsonrpc wf_timer) target_link_libraries(webfuse-provider PRIVATE webfuse-provider-static webfuse-core)
file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc" file(WRITE "${PROJECT_BINARY_DIR}/libwebfuse-provider.pc"
"prefix=\"${CMAKE_INSTALL_PREFIX}\" "prefix=\"${CMAKE_INSTALL_PREFIX}\"

View File

@ -1,24 +0,0 @@
# wf_jsonrpc
add_library(wf_jsonrpc STATIC
lib/wf/jsonrpc/src/wf/jsonrpc/api.c
lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c
lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c
lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c
lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c
lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c
lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c
)
target_link_libraries(wf_jsonrpc PUBLIC wf_timer)
target_include_directories(wf_jsonrpc PRIVATE
lib/wf/timer/include
lib/wf/jsonrpc/src
)
target_include_directories(wf_jsonrpc PUBLIC
lib/wf/jsonrpc/include
)
set_target_properties(wf_jsonrpc PROPERTIES C_VISIBILITY_PRESET hidden)

View File

@ -1,18 +0,0 @@
# timer
add_library(wf_timer STATIC
lib/wf/timer/src/wf/timer/api.c
lib/wf/timer/src/wf/timer/impl/manager.c
lib/wf/timer/src/wf/timer/impl/timepoint.c
lib/wf/timer/src/wf/timer/impl/timer.c
)
target_include_directories(wf_timer PRIVATE
lib/wf/timer/src
)
target_include_directories(wf_timer PUBLIC
lib/wf/timer/include
)
set_target_properties(wf_timer PROPERTIES C_VISIBILITY_PRESET hidden)

View File

@ -4,7 +4,7 @@
#include <errno.h> #include <errno.h>
#include <jansson.h> #include <jansson.h>
#include "wf/jsonrpc/proxy.h" #include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/util.h" #include "webfuse/core/util.h"
void wf_impl_operation_close( void wf_impl_operation_close(

View File

@ -7,7 +7,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include "wf/jsonrpc/proxy.h" #include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/json_util.h" #include "webfuse/core/json_util.h"
#include "webfuse/core/util.h" #include "webfuse/core/util.h"

View File

@ -10,7 +10,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "wf/jsonrpc/proxy.h" #include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/json_util.h" #include "webfuse/core/json_util.h"
#include "webfuse/core/util.h" #include "webfuse/core/util.h"

View File

@ -4,7 +4,7 @@
#include <errno.h> #include <errno.h>
#include <jansson.h> #include <jansson.h>
#include "wf/jsonrpc/proxy.h" #include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/util.h" #include "webfuse/core/util.h"
#include "webfuse/core/status.h" #include "webfuse/core/status.h"
#include "webfuse/core/json_util.h" #include "webfuse/core/json_util.h"

View File

@ -5,7 +5,7 @@
#include <limits.h> #include <limits.h>
#include <jansson.h> #include <jansson.h>
#include "wf/jsonrpc/proxy.h" #include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/base64.h" #include "webfuse/core/base64.h"
#include "webfuse/core/json_util.h" #include "webfuse/core/json_util.h"

View File

@ -8,7 +8,7 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include "wf/jsonrpc/proxy.h" #include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/util.h" #include "webfuse/core/util.h"
#include "webfuse/core/json_util.h" #include "webfuse/core/json_util.h"

View File

@ -11,9 +11,9 @@
#include "webfuse/adapter/impl/credentials.h" #include "webfuse/adapter/impl/credentials.h"
#include "webfuse/core/status_intern.h" #include "webfuse/core/status_intern.h"
#include "wf/jsonrpc/request.h" #include "webfuse/core/jsonrpc/request.h"
#include "wf/timer/manager.h" #include "webfuse/core/timer/manager.h"
#include "wf/timer/timer.h" #include "webfuse/core/timer/timer.h"
static int wf_impl_server_protocol_callback( static int wf_impl_server_protocol_callback(
struct lws * wsi, struct lws * wsi,

View File

@ -4,8 +4,8 @@
#include "webfuse/adapter/impl/authenticators.h" #include "webfuse/adapter/impl/authenticators.h"
#include "webfuse/adapter/impl/mountpoint_factory.h" #include "webfuse/adapter/impl/mountpoint_factory.h"
#include "webfuse/adapter/impl/session_manager.h" #include "webfuse/adapter/impl/session_manager.h"
#include "wf/jsonrpc/proxy.h" #include "webfuse/core/jsonrpc/proxy.h"
#include "wf/jsonrpc/server.h" #include "webfuse/core/jsonrpc/server.h"
#ifndef __cplusplus #ifndef __cplusplus
#include <stdbool.h> #include <stdbool.h>

View File

@ -8,9 +8,9 @@
#include "webfuse/core/container_of.h" #include "webfuse/core/container_of.h"
#include "webfuse/core/util.h" #include "webfuse/core/util.h"
#include "wf/jsonrpc/proxy.h" #include "webfuse/core/jsonrpc/proxy.h"
#include "wf/jsonrpc/request.h" #include "webfuse/core/jsonrpc/request.h"
#include "wf/jsonrpc/response.h" #include "webfuse/core/jsonrpc/response.h"
#include <libwebsockets.h> #include <libwebsockets.h>
#include <stddef.h> #include <stddef.h>

View File

@ -13,8 +13,8 @@ using std::size_t;
#include "webfuse/adapter/impl/filesystem.h" #include "webfuse/adapter/impl/filesystem.h"
#include "webfuse/core/slist.h" #include "webfuse/core/slist.h"
#include "wf/jsonrpc/proxy.h" #include "webfuse/core/jsonrpc/proxy.h"
#include "wf/jsonrpc/server.h" #include "webfuse/core/jsonrpc/server.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View File

@ -1,5 +1,4 @@
#include "webfuse/core/json_util.h" #include "webfuse/core/json_util.h"
#include "wf/jsonrpc/status.h"
int wf_impl_json_get_int(json_t const * object, char const * key, int default_value) int wf_impl_json_get_int(json_t const * object, char const * key, int default_value)
{ {
@ -14,25 +13,6 @@ int wf_impl_json_get_int(json_t const * object, char const * key, int default_va
return result; return result;
} }
static wf_status wf_impl_jsonrc_code_to_status(int code)
{
switch (code)
{
case WF_JSONRPC_GOOD:
return WF_GOOD;
case WF_JSONRPC_BAD:
return WF_BAD;
case WF_JSONRPC_BAD_BUSY:
return WF_BAD_BUSY;
case WF_JSONRPC_BAD_TIMEOUT:
return WF_BAD_TIMEOUT;
case WF_JSONRPC_BAD_FORMAT:
return WF_BAD_FORMAT;
default:
return (wf_status) code;
}
}
wf_status wf_status
wf_impl_jsonrpc_get_status( wf_impl_jsonrpc_get_status(
json_t const * error) json_t const * error)
@ -40,8 +20,7 @@ wf_impl_jsonrpc_get_status(
wf_status status = WF_GOOD; wf_status status = WF_GOOD;
if (NULL != error) if (NULL != error)
{ {
int code = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT); status = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT);
status = wf_impl_jsonrc_code_to_status(code);
} }
return status; return status;

View File

@ -1,7 +1,7 @@
#include "wf/jsonrpc/impl/error.h" #include "webfuse/core/jsonrpc/error.h"
json_t * json_t *
wf_jsonrpc_impl_error( wf_jsonrpc_error(
int code, int code,
char const * message) char const * message)
{ {
@ -13,13 +13,13 @@ wf_jsonrpc_impl_error(
} }
void void
wf_jsonrpc_impl_propate_error( wf_jsonrpc_propate_error(
wf_jsonrpc_proxy_finished_fn * finised, wf_jsonrpc_proxy_finished_fn * finised,
void * user_data, void * user_data,
int code, int code,
char const * message) char const * message)
{ {
json_t * error = wf_jsonrpc_impl_error(code, message); json_t * error = wf_jsonrpc_error(code, message);
finised(user_data, NULL, error); finised(user_data, NULL, error);
json_decref(error); json_decref(error);

View File

@ -1,8 +1,8 @@
#ifndef WF_JSONRPC_IMPL_ERROR_H #ifndef WF_JSONRPC_ERROR_H
#define WF_JSONRPC_IMPL_ERROR_H #define WF_JSONRPC_ERROR_H
#include <jansson.h> #include <jansson.h>
#include "wf/jsonrpc/proxy_finished_fn.h" #include "webfuse/core/jsonrpc/proxy_finished_fn.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -10,12 +10,12 @@ extern "C"
#endif #endif
extern json_t * extern json_t *
wf_jsonrpc_impl_error( wf_jsonrpc_error(
int code, int code,
char const * message); char const * message);
extern void extern void
wf_jsonrpc_impl_propate_error( wf_jsonrpc_propate_error(
wf_jsonrpc_proxy_finished_fn * finised, wf_jsonrpc_proxy_finished_fn * finised,
void * user_data, void * user_data,
int code, int code,

View File

@ -1,8 +1,8 @@
#include "wf/jsonrpc/impl/method.h" #include "webfuse/core/jsonrpc/method.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create( struct wf_jsonrpc_method * wf_jsonrpc_method_create(
char const * method_name, char const * method_name,
wf_jsonrpc_method_invoke_fn * invoke, wf_jsonrpc_method_invoke_fn * invoke,
void * user_data) void * user_data)
@ -16,7 +16,7 @@ struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create(
return method; return method;
} }
void wf_jsonrpc_impl_method_dispose( void wf_jsonrpc_method_dispose(
struct wf_jsonrpc_method * method) struct wf_jsonrpc_method * method)
{ {
free(method->name); free(method->name);

View File

@ -1,7 +1,7 @@
#ifndef WF_JSONRPC_IMPL_METHOD_H #ifndef WF_JSONRPC_METHOD_H
#define WF_JSONRPC_IMPL_METHOD_H #define WF_JSONRPC_METHOD_H
#include "wf/jsonrpc/method_invoke_fn.h" #include "webfuse/core/jsonrpc/method_invoke_fn.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -17,13 +17,13 @@ struct wf_jsonrpc_method
}; };
extern struct wf_jsonrpc_method * extern struct wf_jsonrpc_method *
wf_jsonrpc_impl_method_create( wf_jsonrpc_method_create(
char const * method_name, char const * method_name,
wf_jsonrpc_method_invoke_fn * invoke, wf_jsonrpc_method_invoke_fn * invoke,
void * user_data); void * user_data);
extern void extern void
wf_jsonrpc_impl_method_dispose( wf_jsonrpc_method_dispose(
struct wf_jsonrpc_method * method); struct wf_jsonrpc_method * method);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,7 +1,6 @@
#ifndef WF_JSONRPC_METHOD_INVOKE_FN_H #ifndef WF_JSONRPC_METHOD_INVOKE_FN_H
#define WF_JSONRPC_METHOD_INVOKE_FN_H #define WF_JSONRPC_METHOD_INVOKE_FN_H
#include <wf/jsonrpc/api.h>
#include <jansson.h> #include <jansson.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -17,7 +16,6 @@ typedef void wf_jsonrpc_method_invoke_fn(
json_t * params, json_t * params,
void * user_data); void * user_data);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -1,34 +1,34 @@
#include "wf/jsonrpc/impl/proxy.h" #include "webfuse/core/jsonrpc/proxy_intern.h"
#include "wf/jsonrpc/impl/response.h" #include "webfuse/core/jsonrpc/response_intern.h"
#include "wf/jsonrpc/impl/error.h" #include "webfuse/core/jsonrpc/error.h"
#include "wf/jsonrpc/status.h" #include "webfuse/core/status.h"
#include <wf/timer/timer.h> #include "webfuse/core/timer/timer.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
struct wf_jsonrpc_proxy * struct wf_jsonrpc_proxy *
wf_jsonrpc_impl_proxy_create( wf_jsonrpc_proxy_create(
struct wf_timer_manager * manager, struct wf_timer_manager * manager,
int timeout, int timeout,
wf_jsonrpc_send_fn * send, wf_jsonrpc_send_fn * send,
void * user_data) void * user_data)
{ {
struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy)); struct wf_jsonrpc_proxy * proxy = malloc(sizeof(struct wf_jsonrpc_proxy));
wf_jsonrpc_impl_proxy_init(proxy, manager, timeout, send, user_data); wf_jsonrpc_proxy_init(proxy, manager, timeout, send, user_data);
return proxy; return proxy;
} }
void wf_jsonrpc_impl_proxy_dispose( void wf_jsonrpc_proxy_dispose(
struct wf_jsonrpc_proxy * proxy) struct wf_jsonrpc_proxy * proxy)
{ {
wf_jsonrpc_impl_proxy_cleanup(proxy); wf_jsonrpc_proxy_cleanup(proxy);
free(proxy); free(proxy);
} }
static void wf_jsonrpc_impl_proxy_on_timeout( static void wf_jsonrpc_proxy_on_timeout(
struct wf_timer * timer, void * proxy_ptr) struct wf_timer * timer, void * proxy_ptr)
{ {
struct wf_jsonrpc_proxy * proxy = proxy_ptr; struct wf_jsonrpc_proxy * proxy = proxy_ptr;
@ -44,11 +44,11 @@ static void wf_jsonrpc_impl_proxy_on_timeout(
proxy->request.finished = NULL; proxy->request.finished = NULL;
wf_timer_cancel(timer); wf_timer_cancel(timer);
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD_TIMEOUT, "Timeout"); wf_jsonrpc_propate_error(finished, user_data, WF_BAD_TIMEOUT, "Timeout");
} }
} }
static json_t * wf_jsonrpc_impl_request_create( static json_t * wf_jsonrpc_request_create(
char const * method, char const * method,
int id, int id,
char const * param_info, char const * param_info,
@ -98,7 +98,7 @@ static json_t * wf_jsonrpc_impl_request_create(
return request; return request;
} }
void wf_jsonrpc_impl_proxy_init( void wf_jsonrpc_proxy_init(
struct wf_jsonrpc_proxy * proxy, struct wf_jsonrpc_proxy * proxy,
struct wf_timer_manager * timeout_manager, struct wf_timer_manager * timeout_manager,
int timeout, int timeout,
@ -110,10 +110,10 @@ void wf_jsonrpc_impl_proxy_init(
proxy->user_data = user_data; proxy->user_data = user_data;
proxy->request.is_pending = false; proxy->request.is_pending = false;
proxy->request.timer = wf_timer_create(timeout_manager, proxy->request.timer = wf_timer_create(timeout_manager,
&wf_jsonrpc_impl_proxy_on_timeout, proxy); &wf_jsonrpc_proxy_on_timeout, proxy);
} }
void wf_jsonrpc_impl_proxy_cleanup( void wf_jsonrpc_proxy_cleanup(
struct wf_jsonrpc_proxy * proxy) struct wf_jsonrpc_proxy * proxy)
{ {
if (proxy->request.is_pending) if (proxy->request.is_pending)
@ -127,19 +127,19 @@ void wf_jsonrpc_impl_proxy_cleanup(
proxy->request.id = 0; proxy->request.id = 0;
wf_timer_cancel(proxy->request.timer); wf_timer_cancel(proxy->request.timer);
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD, "Bad: cancelled pending request during shutdown"); wf_jsonrpc_propate_error(finished, user_data, WF_BAD, "Bad: cancelled pending request during shutdown");
} }
wf_timer_dispose(proxy->request.timer); wf_timer_dispose(proxy->request.timer);
} }
void wf_jsonrpc_impl_proxy_invoke( void wf_jsonrpc_proxy_invoke(
struct wf_jsonrpc_proxy * proxy, struct wf_jsonrpc_proxy * proxy,
wf_jsonrpc_proxy_finished_fn * finished, wf_jsonrpc_proxy_finished_fn * finished,
void * user_data, void * user_data,
char const * method_name, char const * method_name,
char const * param_info, char const * param_info,
va_list args ...
) )
{ {
if (!proxy->request.is_pending) if (!proxy->request.is_pending)
@ -150,7 +150,10 @@ void wf_jsonrpc_impl_proxy_invoke(
proxy->request.id = 42; proxy->request.id = 42;
wf_timer_start(proxy->request.timer, proxy->timeout); wf_timer_start(proxy->request.timer, proxy->timeout);
json_t * request = wf_jsonrpc_impl_request_create(method_name, proxy->request.id, param_info, args); va_list args;
va_start(args, param_info);
json_t * request = wf_jsonrpc_request_create(method_name, proxy->request.id, param_info, args);
va_end(args);
bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data))); bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data)));
if (!is_send) if (!is_send)
@ -161,7 +164,7 @@ void wf_jsonrpc_impl_proxy_invoke(
proxy->request.id = 0; proxy->request.id = 0;
wf_timer_cancel(proxy->request.timer); wf_timer_cancel(proxy->request.timer);
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD, "Bad: requenst is not sent"); wf_jsonrpc_propate_error(finished, user_data, WF_BAD, "Bad: requenst is not sent");
} }
if (NULL != request) if (NULL != request)
@ -171,18 +174,22 @@ void wf_jsonrpc_impl_proxy_invoke(
} }
else else
{ {
wf_jsonrpc_impl_propate_error(finished, user_data, WF_JSONRPC_BAD_BUSY, "Busy"); wf_jsonrpc_propate_error(finished, user_data, WF_BAD_BUSY, "Busy");
} }
} }
extern void wf_jsonrpc_impl_proxy_notify( extern void wf_jsonrpc_proxy_notify(
struct wf_jsonrpc_proxy * proxy, struct wf_jsonrpc_proxy * proxy,
char const * method_name, char const * method_name,
char const * param_info, char const * param_info,
va_list args ...
) )
{ {
json_t * request = wf_jsonrpc_impl_request_create(method_name, 0, param_info, args); va_list args;
va_start(args, param_info);
json_t * request = wf_jsonrpc_request_create(method_name, 0, param_info, args);
va_end(args);
if (NULL != request) if (NULL != request)
{ {
proxy->send(request, proxy->user_data); proxy->send(request, proxy->user_data);
@ -191,12 +198,12 @@ extern void wf_jsonrpc_impl_proxy_notify(
} }
void wf_jsonrpc_impl_proxy_onresult( void wf_jsonrpc_proxy_onresult(
struct wf_jsonrpc_proxy * proxy, struct wf_jsonrpc_proxy * proxy,
json_t * message) json_t * message)
{ {
struct wf_jsonrpc_response response; struct wf_jsonrpc_response response;
wf_jsonrpc_impl_response_init(&response, message); wf_jsonrpc_response_init(&response, message);
if ((proxy->request.is_pending) && (response.id == proxy->request.id)) if ((proxy->request.is_pending) && (response.id == proxy->request.id))
{ {
@ -212,6 +219,6 @@ void wf_jsonrpc_impl_proxy_onresult(
finished(user_data, response.result, response.error); finished(user_data, response.result, response.error);
} }
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
} }

View File

@ -12,9 +12,8 @@ using std::size_t;
#endif #endif
#include <jansson.h> #include <jansson.h>
#include <wf/jsonrpc/api.h> #include "webfuse/core/jsonrpc/send_fn.h"
#include <wf/jsonrpc/send_fn.h> #include "webfuse/core/jsonrpc/proxy_finished_fn.h"
#include <wf/jsonrpc/proxy_finished_fn.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -23,14 +22,14 @@ extern "C" {
struct wf_jsonrpc_proxy; struct wf_jsonrpc_proxy;
struct wf_timer_manager; struct wf_timer_manager;
extern WF_JSONRPC_API struct wf_jsonrpc_proxy * extern struct wf_jsonrpc_proxy *
wf_jsonrpc_proxy_create( wf_jsonrpc_proxy_create(
struct wf_timer_manager * manager, struct wf_timer_manager * manager,
int timeout, int timeout,
wf_jsonrpc_send_fn * send, wf_jsonrpc_send_fn * send,
void * user_data); void * user_data);
extern WF_JSONRPC_API void wf_jsonrpc_proxy_dispose( extern void wf_jsonrpc_proxy_dispose(
struct wf_jsonrpc_proxy * proxy); struct wf_jsonrpc_proxy * proxy);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -47,7 +46,7 @@ extern WF_JSONRPC_API void wf_jsonrpc_proxy_dispose(
/// \param param_info types of the param (s = string, i = integer, j = json) /// \param param_info types of the param (s = string, i = integer, j = json)
/// \param ... params /// \param ... params
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
extern WF_JSONRPC_API void wf_jsonrpc_proxy_invoke( extern void wf_jsonrpc_proxy_invoke(
struct wf_jsonrpc_proxy * proxy, struct wf_jsonrpc_proxy * proxy,
wf_jsonrpc_proxy_finished_fn * finished, wf_jsonrpc_proxy_finished_fn * finished,
void * user_data, void * user_data,
@ -56,14 +55,14 @@ extern WF_JSONRPC_API void wf_jsonrpc_proxy_invoke(
... ...
); );
extern WF_JSONRPC_API void wf_jsonrpc_proxy_notify( extern void wf_jsonrpc_proxy_notify(
struct wf_jsonrpc_proxy * proxy, struct wf_jsonrpc_proxy * proxy,
char const * method_name, char const * method_name,
char const * param_info, char const * param_info,
... ...
); );
extern WF_JSONRPC_API void wf_jsonrpc_proxy_onresult( extern void wf_jsonrpc_proxy_onresult(
struct wf_jsonrpc_proxy * proxy, struct wf_jsonrpc_proxy * proxy,
json_t * message); json_t * message);

View File

@ -0,0 +1,48 @@
#ifndef WF_JSONRPC_PROXY_INTERN_H
#define WF_JSONRPC_PROXY_INTERN_H
#include "webfuse/core/jsonrpc/proxy.h"
#include "webfuse/core/jsonrpc/proxy_finished_fn.h"
#include "webfuse/core/jsonrpc/send_fn.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wf_timer;
struct wf_jsonrpc_request
{
bool is_pending;
wf_jsonrpc_proxy_finished_fn * finished;
void * user_data;
int id;
struct wf_timer * timer;
};
struct wf_jsonrpc_proxy
{
struct wf_jsonrpc_request request;
int timeout;
wf_jsonrpc_send_fn * send;
void * user_data;
};
extern void
wf_jsonrpc_proxy_init(
struct wf_jsonrpc_proxy * proxy,
struct wf_timer_manager * manager,
int timeout,
wf_jsonrpc_send_fn * send,
void * user_data);
extern void
wf_jsonrpc_proxy_cleanup(
struct wf_jsonrpc_proxy * proxy);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,5 +1,5 @@
#include "wf/jsonrpc/impl/request.h" #include "webfuse/core/jsonrpc/request.h"
#include "wf/jsonrpc/impl/error.h" #include "webfuse/core/jsonrpc/error.h"
#include <stdlib.h> #include <stdlib.h>
struct wf_jsonrpc_request struct wf_jsonrpc_request
@ -10,7 +10,7 @@ struct wf_jsonrpc_request
}; };
bool bool
wf_jsonrpc_impl_is_request( wf_jsonrpc_is_request(
json_t * message) json_t * message)
{ {
json_t * id = json_object_get(message, "id"); json_t * id = json_object_get(message, "id");
@ -23,7 +23,7 @@ wf_jsonrpc_impl_is_request(
struct wf_jsonrpc_request * struct wf_jsonrpc_request *
wf_jsonrpc_impl_request_create( wf_jsonrpc_request_create(
int id, int id,
wf_jsonrpc_send_fn * send, wf_jsonrpc_send_fn * send,
void * user_data) void * user_data)
@ -37,14 +37,14 @@ wf_jsonrpc_impl_request_create(
} }
void void
wf_jsonrpc_impl_request_dispose( wf_jsonrpc_request_dispose(
struct wf_jsonrpc_request * request) struct wf_jsonrpc_request * request)
{ {
free(request); free(request);
} }
void * void *
wf_jsonrpc_impl_request_get_userdata( wf_jsonrpc_request_get_userdata(
struct wf_jsonrpc_request * request) struct wf_jsonrpc_request * request)
{ {
return request->user_data; return request->user_data;
@ -52,7 +52,7 @@ wf_jsonrpc_impl_request_get_userdata(
void void
wf_jsonrpc_impl_respond( wf_jsonrpc_respond(
struct wf_jsonrpc_request * request, struct wf_jsonrpc_request * request,
json_t * result) json_t * result)
{ {
@ -62,20 +62,20 @@ wf_jsonrpc_impl_respond(
request->send(response, request->user_data); request->send(response, request->user_data);
json_decref(response); json_decref(response);
wf_jsonrpc_impl_request_dispose(request); wf_jsonrpc_request_dispose(request);
} }
void wf_jsonrpc_impl_respond_error( void wf_jsonrpc_respond_error(
struct wf_jsonrpc_request * request, struct wf_jsonrpc_request * request,
int code, int code,
char const * message) char const * message)
{ {
json_t * response = json_object(); json_t * response = json_object();
json_object_set_new(response, "error", wf_jsonrpc_impl_error(code, message)); json_object_set_new(response, "error", wf_jsonrpc_error(code, message));
json_object_set_new(response, "id", json_integer(request->id)); json_object_set_new(response, "id", json_integer(request->id));
request->send(response, request->user_data); request->send(response, request->user_data);
json_decref(response); json_decref(response);
wf_jsonrpc_impl_request_dispose(request); wf_jsonrpc_request_dispose(request);
} }

View File

@ -12,8 +12,7 @@ using std::size_t;
#endif #endif
#include <jansson.h> #include <jansson.h>
#include <wf/jsonrpc/api.h> #include "webfuse/core/jsonrpc/send_fn.h"
#include "wf/jsonrpc/send_fn.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -22,26 +21,26 @@ extern "C"
struct wf_jsonrpc_request; struct wf_jsonrpc_request;
extern WF_JSONRPC_API bool wf_jsonrpc_is_request( extern bool wf_jsonrpc_is_request(
json_t * message); json_t * message);
extern WF_JSONRPC_API struct wf_jsonrpc_request * extern struct wf_jsonrpc_request *
wf_jsonrpc_request_create( wf_jsonrpc_request_create(
int id, int id,
wf_jsonrpc_send_fn * send, wf_jsonrpc_send_fn * send,
void * user_data); void * user_data);
extern WF_JSONRPC_API void wf_jsonrpc_request_dispose( extern void wf_jsonrpc_request_dispose(
struct wf_jsonrpc_request * request); struct wf_jsonrpc_request * request);
extern WF_JSONRPC_API void * wf_jsonrpc_request_get_userdata( extern void * wf_jsonrpc_request_get_userdata(
struct wf_jsonrpc_request * request); struct wf_jsonrpc_request * request);
extern WF_JSONRPC_API void wf_jsonrpc_respond( extern void wf_jsonrpc_respond(
struct wf_jsonrpc_request * request, struct wf_jsonrpc_request * request,
json_t * result); json_t * result);
extern WF_JSONRPC_API void wf_jsonrpc_respond_error( extern void wf_jsonrpc_respond_error(
struct wf_jsonrpc_request * request, struct wf_jsonrpc_request * request,
int code, int code,
char const * message); char const * message);

View File

@ -1,9 +1,9 @@
#include "wf/jsonrpc/impl/response.h" #include "webfuse/core/jsonrpc/response_intern.h"
#include "wf/jsonrpc/impl/error.h" #include "webfuse/core/jsonrpc/error.h"
#include "wf/jsonrpc/status.h" #include "webfuse/core/status.h"
bool bool
wf_jsonrpc_impl_is_response( wf_jsonrpc_is_response(
json_t * message) json_t * message)
{ {
json_t * id = json_object_get(message, "id"); json_t * id = json_object_get(message, "id");
@ -16,7 +16,7 @@ wf_jsonrpc_impl_is_response(
void void
wf_jsonrpc_impl_response_init( wf_jsonrpc_response_init(
struct wf_jsonrpc_response * result, struct wf_jsonrpc_response * result,
json_t * response) json_t * response)
{ {
@ -27,7 +27,7 @@ wf_jsonrpc_impl_response_init(
json_t * id_holder = json_object_get(response, "id"); json_t * id_holder = json_object_get(response, "id");
if (!json_is_integer(id_holder)) if (!json_is_integer(id_holder))
{ {
result->error = wf_jsonrpc_impl_error(WF_JSONRPC_BAD_FORMAT, "invalid format: missing id"); result->error = wf_jsonrpc_error(WF_BAD_FORMAT, "invalid format: missing id");
return; return;
} }
@ -47,13 +47,13 @@ wf_jsonrpc_impl_response_init(
} }
else else
{ {
result->error = wf_jsonrpc_impl_error(WF_JSONRPC_BAD_FORMAT, "invalid format: invalid error object"); result->error = wf_jsonrpc_error(WF_BAD_FORMAT, "invalid format: invalid error object");
} }
} }
} }
void void
wf_jsonrpc_impl_response_cleanup( wf_jsonrpc_response_cleanup(
struct wf_jsonrpc_response * response) struct wf_jsonrpc_response * response)
{ {
if (NULL != response->result) if (NULL != response->result)

View File

@ -6,14 +6,13 @@
#endif #endif
#include <jansson.h> #include <jansson.h>
#include <wf/jsonrpc/api.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
extern WF_JSONRPC_API bool wf_jsonrpc_is_response( extern bool wf_jsonrpc_is_response(
json_t * message); json_t * message);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,16 +1,15 @@
#ifndef WF_JSONRPC_IMPL_RESPONSE_H #ifndef WF_JSONRPC_RESPONSE_INTERN_H
#define WF_JSONRPC_IMPL_RESPONSE_H #define WF_JSONRPC_RESPONSE_INTERN_H
#include "webfuse/core/jsonrpc/response.h"
#ifndef __cplusplus #ifndef __cplusplus
#include <stdbool.h>
#include <stddef.h> #include <stddef.h>
#else #else
#include <cstddef> #include <cstddef>
using std::size_t; using std::size_t;
#endif #endif
#include <jansson.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -22,14 +21,11 @@ struct wf_jsonrpc_response
int id; int id;
}; };
extern bool wf_jsonrpc_impl_is_response( extern void wf_jsonrpc_response_init(
json_t * message);
extern void wf_jsonrpc_impl_response_init(
struct wf_jsonrpc_response * response, struct wf_jsonrpc_response * response,
json_t * message); json_t * message);
extern void wf_jsonrpc_impl_response_cleanup( extern void wf_jsonrpc_response_cleanup(
struct wf_jsonrpc_response * response); struct wf_jsonrpc_response * response);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -6,7 +6,6 @@
#endif #endif
#include <jansson.h> #include <jansson.h>
#include <wf/jsonrpc/api.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View File

@ -1,8 +1,8 @@
#include "wf/jsonrpc/impl/server.h" #include "webfuse/core/jsonrpc/server.h"
#include "wf/jsonrpc/impl/method.h" #include "webfuse/core/jsonrpc/method.h"
#include "wf/jsonrpc/impl/request.h" #include "webfuse/core/jsonrpc/request.h"
#include "wf/jsonrpc/impl/unused_param.h" #include "webfuse/core/status.h"
#include "wf/jsonrpc/status.h" #include "webfuse/core/util.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -13,80 +13,79 @@ struct wf_jsonrpc_server
}; };
static void static void
wf_jsonrpc_impl_server_init( wf_jsonrpc_server_init(
struct wf_jsonrpc_server * server); struct wf_jsonrpc_server * server);
static void static void
wf_jsonrpc_impl_server_cleanup( wf_jsonrpc_server_cleanup(
struct wf_jsonrpc_server * server); struct wf_jsonrpc_server * server);
struct wf_jsonrpc_server * struct wf_jsonrpc_server *
wf_jsonrpc_impl_server_create(void) wf_jsonrpc_server_create(void)
{ {
struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server)); struct wf_jsonrpc_server * server = malloc(sizeof(struct wf_jsonrpc_server));
wf_jsonrpc_impl_server_init(server); wf_jsonrpc_server_init(server);
return server; return server;
} }
void void
wf_jsonrpc_impl_server_dispose( wf_jsonrpc_server_dispose(
struct wf_jsonrpc_server * server) struct wf_jsonrpc_server * server)
{ {
wf_jsonrpc_impl_server_cleanup(server); wf_jsonrpc_server_cleanup(server);
free(server); free(server);
} }
static void wf_jsonrpc_server_init(
static void wf_jsonrpc_impl_server_init(
struct wf_jsonrpc_server * server) struct wf_jsonrpc_server * server)
{ {
server->methods = NULL; server->methods = NULL;
} }
static void wf_jsonrpc_impl_server_cleanup( static void wf_jsonrpc_server_cleanup(
struct wf_jsonrpc_server * server) struct wf_jsonrpc_server * server)
{ {
struct wf_jsonrpc_method * current = server->methods; struct wf_jsonrpc_method * current = server->methods;
while (NULL != current) while (NULL != current)
{ {
struct wf_jsonrpc_method * next = current->next; struct wf_jsonrpc_method * next = current->next;
wf_jsonrpc_impl_method_dispose(current); wf_jsonrpc_method_dispose(current);
current = next; current = next;
} }
server->methods = NULL; server->methods = NULL;
} }
void wf_jsonrpc_impl_server_add( void wf_jsonrpc_server_add(
struct wf_jsonrpc_server * server, struct wf_jsonrpc_server * server,
char const * method_name, char const * method_name,
wf_jsonrpc_method_invoke_fn * invoke, wf_jsonrpc_method_invoke_fn * invoke,
void * user_data) void * user_data)
{ {
struct wf_jsonrpc_method * method = wf_jsonrpc_impl_method_create(method_name, invoke, user_data); struct wf_jsonrpc_method * method = wf_jsonrpc_method_create(method_name, invoke, user_data);
method->next = server->methods; method->next = server->methods;
server->methods = method; server->methods = method;
} }
static void wf_jsonrpc_impl_server_invalid_method_invoke( static void wf_jsonrpc_server_invalid_method_invoke(
struct wf_jsonrpc_request * request, struct wf_jsonrpc_request * request,
char const * WF_JSONRPC_UNUSED_PARAM(method_name), char const * WF_UNUSED_PARAM(method_name),
json_t * WF_JSONRPC_UNUSED_PARAM(params), json_t * WF_UNUSED_PARAM(params),
void * WF_JSONRPC_UNUSED_PARAM(user_data)) void * WF_UNUSED_PARAM(user_data))
{ {
wf_jsonrpc_impl_respond_error(request, WF_JSONRPC_BAD_NOTIMPLEMENTED, "not implemented"); wf_jsonrpc_respond_error(request, WF_BAD_NOTIMPLEMENTED, "not implemented");
} }
static struct wf_jsonrpc_method const wf_jsonrpc_impl_server_invalid_method = static struct wf_jsonrpc_method const wf_jsonrpc_server_invalid_method =
{ {
.next = NULL, .next = NULL,
.name = "<invalid>", .name = "<invalid>",
.invoke = &wf_jsonrpc_impl_server_invalid_method_invoke, .invoke = &wf_jsonrpc_server_invalid_method_invoke,
.user_data = NULL .user_data = NULL
}; };
static struct wf_jsonrpc_method const * static struct wf_jsonrpc_method const *
wf_jsonrpc_impl_server_get_method( wf_jsonrpc_server_get_method(
struct wf_jsonrpc_server * server, struct wf_jsonrpc_server * server,
char const * method_name) char const * method_name)
{ {
@ -101,10 +100,10 @@ wf_jsonrpc_impl_server_get_method(
current = current->next; current = current->next;
} }
return &wf_jsonrpc_impl_server_invalid_method; return &wf_jsonrpc_server_invalid_method;
} }
void wf_jsonrpc_impl_server_process( void wf_jsonrpc_server_process(
struct wf_jsonrpc_server * server, struct wf_jsonrpc_server * server,
json_t * request_data, json_t * request_data,
wf_jsonrpc_send_fn * send, wf_jsonrpc_send_fn * send,
@ -120,8 +119,8 @@ void wf_jsonrpc_impl_server_process(
{ {
char const * method_name = json_string_value(method_holder); char const * method_name = json_string_value(method_holder);
int id = json_integer_value(id_holder); int id = json_integer_value(id_holder);
struct wf_jsonrpc_request * request = wf_jsonrpc_impl_request_create(id, send, user_data); struct wf_jsonrpc_request * request = wf_jsonrpc_request_create(id, send, user_data);
struct wf_jsonrpc_method const * method = wf_jsonrpc_impl_server_get_method(server, method_name); struct wf_jsonrpc_method const * method = wf_jsonrpc_server_get_method(server, method_name);
method->invoke(request, method_name, params, method->user_data); method->invoke(request, method_name, params, method->user_data);
} }

View File

@ -9,9 +9,8 @@
#endif #endif
#include <jansson.h> #include <jansson.h>
#include <wf/jsonrpc/api.h> #include "webfuse/core/jsonrpc/method_invoke_fn.h"
#include <wf/jsonrpc/send_fn.h> #include "webfuse/core/jsonrpc/send_fn.h"
#include <wf/jsonrpc/method_invoke_fn.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -20,20 +19,20 @@ extern "C"
struct wf_jsonrpc_server; struct wf_jsonrpc_server;
extern WF_JSONRPC_API struct wf_jsonrpc_server * extern struct wf_jsonrpc_server *
wf_jsonrpc_server_create(void); wf_jsonrpc_server_create(void);
extern WF_JSONRPC_API void extern void
wf_jsonrpc_server_dispose( wf_jsonrpc_server_dispose(
struct wf_jsonrpc_server * server); struct wf_jsonrpc_server * server);
extern WF_JSONRPC_API void wf_jsonrpc_server_add( extern void wf_jsonrpc_server_add(
struct wf_jsonrpc_server * server, struct wf_jsonrpc_server * server,
char const * method_name, char const * method_name,
wf_jsonrpc_method_invoke_fn * invoke, wf_jsonrpc_method_invoke_fn * invoke,
void * user_data); void * user_data);
extern WF_JSONRPC_API void wf_jsonrpc_server_process( extern void wf_jsonrpc_server_process(
struct wf_jsonrpc_server * server, struct wf_jsonrpc_server * server,
json_t * request, json_t * request,
wf_jsonrpc_send_fn * send, wf_jsonrpc_send_fn * send,

View File

@ -1,6 +1,6 @@
#include "wf/timer/impl/manager.h" #include "webfuse/core/timer/manager_intern.h"
#include "wf/timer/impl/timer.h" #include "webfuse/core/timer/timer_intern.h"
#include "wf/timer/impl/timepoint.h" #include "webfuse/core/timer/timepoint.h"
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
@ -11,7 +11,7 @@ struct wf_timer_manager
}; };
struct wf_timer_manager * struct wf_timer_manager *
wf_timer_impl_manager_create(void) wf_timer_manager_create(void)
{ {
struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager)); struct wf_timer_manager * manager = malloc(sizeof(struct wf_timer_manager));
manager->timers = NULL; manager->timers = NULL;
@ -20,7 +20,7 @@ wf_timer_impl_manager_create(void)
} }
void void
wf_timer_impl_manager_dispose( wf_timer_manager_dispose(
struct wf_timer_manager * manager) struct wf_timer_manager * manager)
{ {
struct wf_timer * timer = manager->timers; struct wf_timer * timer = manager->timers;
@ -28,7 +28,7 @@ wf_timer_impl_manager_dispose(
{ {
struct wf_timer * next = timer->next; struct wf_timer * next = timer->next;
wf_timer_impl_trigger(timer); wf_timer_trigger(timer);
timer = next; timer = next;
} }
@ -36,7 +36,7 @@ wf_timer_impl_manager_dispose(
} }
void wf_timer_impl_manager_check( void wf_timer_manager_check(
struct wf_timer_manager * manager) struct wf_timer_manager * manager)
{ {
struct wf_timer * timer = manager->timers; struct wf_timer * timer = manager->timers;
@ -44,17 +44,17 @@ void wf_timer_impl_manager_check(
{ {
struct wf_timer * next = timer->next; struct wf_timer * next = timer->next;
if (wf_timer_impl_is_timeout(timer)) if (wf_timer_is_timeout(timer))
{ {
wf_timer_impl_manager_removetimer(manager, timer); wf_timer_manager_removetimer(manager, timer);
wf_timer_impl_trigger(timer); wf_timer_trigger(timer);
} }
timer = next; timer = next;
} }
} }
void wf_timer_impl_manager_addtimer( void wf_timer_manager_addtimer(
struct wf_timer_manager * manager, struct wf_timer_manager * manager,
struct wf_timer * timer) struct wf_timer * timer)
{ {
@ -68,7 +68,7 @@ void wf_timer_impl_manager_addtimer(
manager->timers = timer; manager->timers = timer;
} }
void wf_timer_impl_manager_removetimer( void wf_timer_manager_removetimer(
struct wf_timer_manager * manager, struct wf_timer_manager * manager,
struct wf_timer * timer) struct wf_timer * timer)
{ {

View File

@ -1,8 +1,6 @@
#ifndef WF_TIMER_MANAGER_H #ifndef WF_TIMER_MANAGER_H
#define WF_TIMER_MANAGER_H #define WF_TIMER_MANAGER_H
#include <wf/timer/api.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
@ -10,14 +8,14 @@ extern "C"
struct wf_timer_manager; struct wf_timer_manager;
extern WF_TIMER_API struct wf_timer_manager * extern struct wf_timer_manager *
wf_timer_manager_create(void); wf_timer_manager_create(void);
extern WF_TIMER_API void extern void
wf_timer_manager_dispose( wf_timer_manager_dispose(
struct wf_timer_manager * manager); struct wf_timer_manager * manager);
extern WF_TIMER_API void extern void
wf_timer_manager_check( wf_timer_manager_check(
struct wf_timer_manager * manager); struct wf_timer_manager * manager);

View File

@ -0,0 +1,26 @@
#ifndef WF_TIMER_MANAGER_INTERN_H
#define WF_TIMER_MANAGER_INTERN_H
#include "webfuse/core/timer/manager.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wf_timer;
extern void wf_timer_manager_addtimer(
struct wf_timer_manager * manager,
struct wf_timer * timer);
extern void wf_timer_manager_removetimer(
struct wf_timer_manager * manager,
struct wf_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,11 +1,11 @@
#include "wf/timer/impl/timepoint.h" #include "webfuse/core/timer/timepoint.h"
#include <time.h> #include <time.h>
#define WF_TIMER_MSEC_PER_SEC ((wf_timer_timepoint) 1000) #define WF_TIMER_MSEC_PER_SEC ((wf_timer_timepoint) 1000)
#define WF_TIMER_NSEC_PER_MSEC ((wf_timer_timepoint) 1000 * 1000) #define WF_TIMER_NSEC_PER_MSEC ((wf_timer_timepoint) 1000 * 1000)
wf_timer_timepoint wf_timer_impl_timepoint_now(void) wf_timer_timepoint wf_timer_timepoint_now(void)
{ {
struct timespec tp; struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp); clock_gettime(CLOCK_MONOTONIC, &tp);
@ -14,17 +14,17 @@ wf_timer_timepoint wf_timer_impl_timepoint_now(void)
return now; return now;
} }
wf_timer_timepoint wf_timer_impl_timepoint_in_msec(wf_timer_timediff value) wf_timer_timepoint wf_timer_timepoint_in_msec(wf_timer_timediff value)
{ {
wf_timer_timepoint const now = wf_timer_impl_timepoint_now(); wf_timer_timepoint const now = wf_timer_timepoint_now();
wf_timer_timepoint result = now + ((wf_timer_timepoint) value); wf_timer_timepoint result = now + ((wf_timer_timepoint) value);
return result; return result;
} }
bool wf_timer_impl_timepoint_is_elapsed(wf_timer_timepoint tp) bool wf_timer_timepoint_is_elapsed(wf_timer_timepoint tp)
{ {
wf_timer_timepoint const now = wf_timer_impl_timepoint_now(); wf_timer_timepoint const now = wf_timer_timepoint_now();
wf_timer_timediff const diff = (wf_timer_timediff) (tp - now); wf_timer_timediff const diff = (wf_timer_timediff) (tp - now);
return (0 > diff); return (0 > diff);

View File

@ -1,5 +1,5 @@
#ifndef WF_TIMER_IMPL_TIMEPOINT_H #ifndef WF_TIMER_TIMEPOINT_H
#define WF_TIMER_IMPL_TIMEPOINT_H #define WF_TIMER_TIMEPOINT_H
#ifndef __cplusplus #ifndef __cplusplus
#include <stdbool.h> #include <stdbool.h>
@ -16,12 +16,12 @@ extern "C"
typedef uint64_t wf_timer_timepoint; typedef uint64_t wf_timer_timepoint;
typedef int64_t wf_timer_timediff; typedef int64_t wf_timer_timediff;
extern wf_timer_timepoint wf_timer_impl_timepoint_now(void); extern wf_timer_timepoint wf_timer_timepoint_now(void);
extern wf_timer_timepoint wf_timer_impl_timepoint_in_msec( extern wf_timer_timepoint wf_timer_timepoint_in_msec(
wf_timer_timediff value); wf_timer_timediff value);
extern bool wf_timer_impl_timepoint_is_elapsed( extern bool wf_timer_timepoint_is_elapsed(
wf_timer_timepoint timepoint); wf_timer_timepoint timepoint);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -1,13 +1,13 @@
#include "wf/timer/impl/timer.h" #include "webfuse/core/timer/timer_intern.h"
#include "wf/timer/impl/manager.h" #include "webfuse/core/timer/manager_intern.h"
#include "wf/timer/impl/timepoint.h" #include "webfuse/core/timer/timepoint.h"
#include <stddef.h> #include <stddef.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
struct wf_timer * struct wf_timer *
wf_timer_impl_create( wf_timer_create(
struct wf_timer_manager * manager, struct wf_timer_manager * manager,
wf_timer_on_timer_fn * on_timer, wf_timer_on_timer_fn * on_timer,
void * user_data) void * user_data)
@ -24,37 +24,37 @@ wf_timer_impl_create(
} }
void void
wf_timer_impl_dispose( wf_timer_dispose(
struct wf_timer * timer) struct wf_timer * timer)
{ {
free(timer); free(timer);
} }
void wf_timer_impl_start( void wf_timer_start(
struct wf_timer * timer, struct wf_timer * timer,
int timeout_ms) int timeout_ms)
{ {
timer->timeout = wf_timer_impl_timepoint_in_msec(timeout_ms); timer->timeout = wf_timer_timepoint_in_msec(timeout_ms);
wf_timer_impl_manager_addtimer(timer->manager, timer); wf_timer_manager_addtimer(timer->manager, timer);
} }
void wf_timer_impl_cancel( void wf_timer_cancel(
struct wf_timer * timer) struct wf_timer * timer)
{ {
wf_timer_impl_manager_removetimer(timer->manager, timer); wf_timer_manager_removetimer(timer->manager, timer);
timer->timeout = 0; timer->timeout = 0;
} }
bool wf_timer_impl_is_timeout( bool wf_timer_is_timeout(
struct wf_timer * timer) struct wf_timer * timer)
{ {
return wf_timer_impl_timepoint_is_elapsed(timer->timeout); return wf_timer_timepoint_is_elapsed(timer->timeout);
} }
void wf_timer_impl_trigger( void wf_timer_trigger(
struct wf_timer * timer) struct wf_timer * timer)
{ {
if (0 != timer->on_timer) if (0 != timer->on_timer)

View File

@ -1,8 +1,7 @@
#ifndef WF_TIMER_TIMER_H #ifndef WF_TIMER_TIMER_H
#define WF_TIMER_TIMER_H #define WF_TIMER_TIMER_H
#include <wf/timer/api.h> #include "webfuse/core/timer/on_timer_fn.h"
#include <wf/timer/on_timer_fn.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -12,22 +11,22 @@ extern "C"
struct wf_timer; struct wf_timer;
struct wf_timer_manager; struct wf_timer_manager;
extern WF_TIMER_API struct wf_timer * extern struct wf_timer *
wf_timer_create( wf_timer_create(
struct wf_timer_manager * manager, struct wf_timer_manager * manager,
wf_timer_on_timer_fn * on_timer, wf_timer_on_timer_fn * on_timer,
void * user_data); void * user_data);
extern WF_TIMER_API void extern void
wf_timer_dispose( wf_timer_dispose(
struct wf_timer * timer); struct wf_timer * timer);
extern WF_TIMER_API void extern void
wf_timer_start( wf_timer_start(
struct wf_timer * timer, struct wf_timer * timer,
int timeout_ms); int timeout_ms);
extern WF_TIMER_API void extern void
wf_timer_cancel( wf_timer_cancel(
struct wf_timer * timer); struct wf_timer * timer);

View File

@ -0,0 +1,40 @@
#ifndef WF_TIMER_TIMER_H
#define WF_TIMER_TIMER_H
#include "webfuse/core/timer/timer.h"
#include "webfuse/core/timer/on_timer_fn.h"
#include "webfuse/core/timer/timepoint.h"
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
struct wf_timer
{
struct wf_timer_manager * manager;
wf_timer_timepoint timeout;
wf_timer_on_timer_fn * on_timer;
void * user_data;
struct wf_timer * next;
struct wf_timer * prev;
};
extern bool wf_timer_is_timeout(
struct wf_timer * timer);
extern void wf_timer_trigger(
struct wf_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -16,11 +16,11 @@
#include "webfuse/provider/impl/url.h" #include "webfuse/provider/impl/url.h"
#include "webfuse/core/protocol_names.h" #include "webfuse/core/protocol_names.h"
#include "wf/timer/manager.h" #include "webfuse/core/timer/manager.h"
#include "wf/jsonrpc/response.h" #include "webfuse/core/jsonrpc/response.h"
#include "wf/jsonrpc/request.h" #include "webfuse/core/jsonrpc/request.h"
#include "wf/jsonrpc/proxy.h" #include "webfuse/core/jsonrpc/proxy.h"
#define WF_DEFAULT_TIMEOUT (10 * 1000) #define WF_DEFAULT_TIMEOUT (10 * 1000)

View File

@ -1,14 +0,0 @@
#ifndef WF_JSONRPC_H
#define WF_JSONRPC_H
#include <wf/jsonrpc/api.h>
#include <wf/jsonrpc/method_invoke_fn.h>
#include <wf/jsonrpc/proxy.h>
#include <wf/jsonrpc/proxy_finished_fn.h>
#include <wf/jsonrpc/request.h>
#include <wf/jsonrpc/response.h>
#include <wf/jsonrpc/send_fn.h>
#include <wf/jsonrpc/server.h>
#include <wf/jsonrpc/status.h>
#endif

View File

@ -1,8 +0,0 @@
#ifndef WF_JSONRPC_API_H
#define WF_JSONRPC_API_H
#ifndef WF_JSONRPC_API
#define WF_JSONRPC_API
#endif
#endif

View File

@ -1,11 +0,0 @@
#ifndef WF_JSONRPC_STATUS_H
#define WF_JSONRPC_STATUS_H
#define WF_JSONRPC_GOOD 0
#define WF_JSONRPC_BAD -1
#define WF_JSONRPC_BAD_NOTIMPLEMENTED -2
#define WF_JSONRPC_BAD_TIMEOUT -3
#define WF_JSONRPC_BAD_BUSY -4
#define WF_JSONRPC_BAD_FORMAT -5
#endif

View File

@ -1,144 +0,0 @@
#include "wf/jsonrpc.h"
#include "wf/jsonrpc/impl/proxy.h"
#include "wf/jsonrpc/impl/request.h"
#include "wf/jsonrpc/impl/response.h"
#include "wf/jsonrpc/impl/server.h"
// proxy
struct wf_jsonrpc_proxy *
wf_jsonrpc_proxy_create(
struct wf_timer_manager * manager,
int timeout,
wf_jsonrpc_send_fn * send,
void * user_data)
{
return wf_jsonrpc_impl_proxy_create(manager, timeout, send, user_data);
}
void wf_jsonrpc_proxy_dispose(
struct wf_jsonrpc_proxy * proxy)
{
wf_jsonrpc_impl_proxy_dispose(proxy);
}
void wf_jsonrpc_proxy_invoke(
struct wf_jsonrpc_proxy * proxy,
wf_jsonrpc_proxy_finished_fn * finished,
void * user_data,
char const * method_name,
char const * param_info,
...
)
{
va_list args;
va_start(args, param_info);
wf_jsonrpc_impl_proxy_invoke(proxy, finished, user_data, method_name, param_info, args);
va_end(args);
}
void wf_jsonrpc_proxy_notify(
struct wf_jsonrpc_proxy * proxy,
char const * method_name,
char const * param_info,
...
)
{
va_list args;
va_start(args, param_info);
wf_jsonrpc_impl_proxy_notify(proxy, method_name, param_info, args);
va_end(args);
}
void wf_jsonrpc_proxy_onresult(
struct wf_jsonrpc_proxy * proxy,
json_t * message)
{
wf_jsonrpc_impl_proxy_onresult(proxy, message);
}
// request
bool wf_jsonrpc_is_request(
json_t * message)
{
return wf_jsonrpc_impl_is_request(message);
}
struct wf_jsonrpc_request * wf_jsonrpc_request_create(
int id,
wf_jsonrpc_send_fn * send,
void * user_data)
{
return wf_jsonrpc_impl_request_create(id, send, user_data);
}
void wf_jsonrpc_request_dispose(
struct wf_jsonrpc_request * request)
{
wf_jsonrpc_impl_request_dispose(request);
}
void * wf_jsonrpc_request_get_userdata(
struct wf_jsonrpc_request * request)
{
return wf_jsonrpc_impl_request_get_userdata(request);
}
void wf_jsonrpc_respond(
struct wf_jsonrpc_request * request,
json_t * result)
{
wf_jsonrpc_impl_respond(request, result);
}
void wf_jsonrpc_respond_error(
struct wf_jsonrpc_request * request,
int code,
char const * message)
{
wf_jsonrpc_impl_respond_error(request, code, message);
}
// response
bool wf_jsonrpc_is_response(
json_t * message)
{
return wf_jsonrpc_impl_is_response(message);
}
// server
struct wf_jsonrpc_server *
wf_jsonrpc_server_create(void)
{
return wf_jsonrpc_impl_server_create();
}
void
wf_jsonrpc_server_dispose(
struct wf_jsonrpc_server * server)
{
wf_jsonrpc_impl_server_dispose(server);
}
void wf_jsonrpc_server_add(
struct wf_jsonrpc_server * server,
char const * method_name,
wf_jsonrpc_method_invoke_fn * invoke,
void * user_data)
{
wf_jsonrpc_impl_server_add(server, method_name, invoke, user_data);
}
void wf_jsonrpc_server_process(
struct wf_jsonrpc_server * server,
json_t * request,
wf_jsonrpc_send_fn * send,
void * user_data)
{
wf_jsonrpc_impl_server_process(server, request, send, user_data);
}

View File

@ -1,84 +0,0 @@
#ifndef WF_JSONRPC_IMPL_PROXY_H
#define WF_JSONRPC_IMPL_PROXY_H
#include "wf/jsonrpc/proxy_finished_fn.h"
#include "wf/jsonrpc/send_fn.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wf_timer_manager;
struct wf_timer;
struct wf_jsonrpc_request
{
bool is_pending;
wf_jsonrpc_proxy_finished_fn * finished;
void * user_data;
int id;
struct wf_timer * timer;
};
struct wf_jsonrpc_proxy
{
struct wf_jsonrpc_request request;
int timeout;
wf_jsonrpc_send_fn * send;
void * user_data;
};
extern void
wf_jsonrpc_impl_proxy_init(
struct wf_jsonrpc_proxy * proxy,
struct wf_timer_manager * manager,
int timeout,
wf_jsonrpc_send_fn * send,
void * user_data);
extern void
wf_jsonrpc_impl_proxy_cleanup(
struct wf_jsonrpc_proxy * proxy);
extern struct wf_jsonrpc_proxy *
wf_jsonrpc_impl_proxy_create(
struct wf_timer_manager * manager,
int timeout,
wf_jsonrpc_send_fn * send,
void * user_data);
extern void
wf_jsonrpc_impl_proxy_dispose(
struct wf_jsonrpc_proxy * proxy);
extern void
wf_jsonrpc_impl_proxy_invoke(
struct wf_jsonrpc_proxy * proxy,
wf_jsonrpc_proxy_finished_fn * finished,
void * user_data,
char const * method_name,
char const * param_info,
va_list args
);
extern void
wf_jsonrpc_impl_proxy_notify(
struct wf_jsonrpc_proxy * proxy,
char const * method_name,
char const * param_info,
va_list args
);
extern void
wf_jsonrpc_impl_proxy_onresult(
struct wf_jsonrpc_proxy * proxy,
json_t * message);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,53 +0,0 @@
#ifndef WF_JSONRPC_IMPL_REQUEST_H
#define WF_JSONRPC_IMPL_REQUEST_H
#ifndef __cplusplus
#include <stdarg.h>
#include <stddef.h>
#include <stdbool.h>
#else
#include <cstdarg>
#include <cstddef>
using std::size_t;
#endif
#include <jansson.h>
#include <wf/jsonrpc/api.h>
#include "wf/jsonrpc/send_fn.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wf_jsonrpc_request;
extern bool wf_jsonrpc_impl_is_request(
json_t * message);
extern struct wf_jsonrpc_request * wf_jsonrpc_impl_request_create(
int id,
wf_jsonrpc_send_fn * send,
void * user_data);
extern void wf_jsonrpc_impl_request_dispose(
struct wf_jsonrpc_request * request);
extern void * wf_jsonrpc_impl_request_get_userdata(
struct wf_jsonrpc_request * request);
extern void wf_jsonrpc_impl_respond(
struct wf_jsonrpc_request * request,
json_t * result);
extern void wf_jsonrpc_impl_respond_error(
struct wf_jsonrpc_request * request,
int code,
char const * message);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,41 +0,0 @@
#ifndef WF_JSONRPC_IMPL_SERVER_H
#define WF_JSONRPC_IMPL_SERVER_H
#include <jansson.h>
#include "wf/jsonrpc/method_invoke_fn.h"
#include "wf/jsonrpc/send_fn.h"
#ifdef __cplusplus
extern "C"
{
#endif
struct wf_jsonrpc_server;
extern struct wf_jsonrpc_server *
wf_jsonrpc_impl_server_create(void);
extern void
wf_jsonrpc_impl_server_dispose(
struct wf_jsonrpc_server * server);
extern void
wf_jsonrpc_impl_server_add(
struct wf_jsonrpc_server * server,
char const * method_name,
wf_jsonrpc_method_invoke_fn * invoke,
void * user_data);
extern void
wf_jsonrpc_impl_server_process(
struct wf_jsonrpc_server * server,
json_t * request,
wf_jsonrpc_send_fn * send,
void * user_data);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,10 +0,0 @@
#ifndef WF_JSONRPC_UTIL_H
#define WF_JSONRPC_UTIL_H
#ifdef __GNUC__
#define WF_JSONRPC_UNUSED_PARAM(param) param __attribute__((unused))
#else
#define WF_JSONRPC_UNUSED_PARAM(param)
#endif
#endif

View File

@ -1,9 +0,0 @@
#ifndef WF_TIMER_H
#define WF_TIMER_H
#include <wf/timer/api.h>
#include <wf/timer/on_timer_fn.h>
#include <wf/timer/timer.h>
#include <wf/timer/manager.h>
#endif

View File

@ -1,8 +0,0 @@
#ifndef WF_TIMER_API_H
#define WF_TIMER_API_H
#ifndef WF_TIMER_API
#define WF_TIMER_API
#endif
#endif

View File

@ -1,59 +0,0 @@
#include "wf/timer.h"
#include "wf/timer/impl/manager.h"
#include "wf/timer/impl/timer.h"
// manager
struct wf_timer_manager *
wf_timer_manager_create(void)
{
return wf_timer_impl_manager_create();
}
void
wf_timer_manager_dispose(
struct wf_timer_manager * manager)
{
wf_timer_impl_manager_dispose(manager);
}
void
wf_timer_manager_check(
struct wf_timer_manager * manager)
{
wf_timer_impl_manager_check(manager);
}
// timer
struct wf_timer *
wf_timer_create(
struct wf_timer_manager * manager,
wf_timer_on_timer_fn * on_timer,
void * user_data)
{
return wf_timer_impl_create(manager, on_timer, user_data);
}
void
wf_timer_dispose(
struct wf_timer * timer)
{
wf_timer_impl_dispose(timer);
}
void
wf_timer_start(
struct wf_timer * timer,
int timeout_ms)
{
wf_timer_impl_start(timer, timeout_ms);
}
void
wf_timer_cancel(
struct wf_timer * timer)
{
wf_timer_impl_cancel(timer);
}

View File

@ -1,36 +0,0 @@
#ifndef WF_TIMER_IMPL_MANAGER_H
#define WF_TIMER_IMPL_MANAGER_H
#ifdef __cplusplus
extern "C"
{
#endif
struct wf_timer;
struct wf_timer_manager;
extern struct wf_timer_manager *
wf_timer_impl_manager_create(void);
extern void
wf_timer_impl_manager_dispose(
struct wf_timer_manager * manager);
extern void
wf_timer_impl_manager_check(
struct wf_timer_manager * manager);
extern void wf_timer_impl_manager_addtimer(
struct wf_timer_manager * manager,
struct wf_timer * timer);
extern void wf_timer_impl_manager_removetimer(
struct wf_timer_manager * manager,
struct wf_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,59 +0,0 @@
#ifndef WF_ADAPTER_IMPL_TIME_TIMER_H
#define WF_ADAPTER_IMPL_TIME_TIMER_H
#include "wf/timer/on_timer_fn.h"
#include "wf/timer/impl/timepoint.h"
#ifndef __cplusplus
#include <stdbool.h>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
struct wf_timer_manager;
struct wf_timer
{
struct wf_timer_manager * manager;
wf_timer_timepoint timeout;
wf_timer_on_timer_fn * on_timer;
void * user_data;
struct wf_timer * next;
struct wf_timer * prev;
};
struct wf_timer *
wf_timer_impl_create(
struct wf_timer_manager * manager,
wf_timer_on_timer_fn * on_timer,
void * user_data);
void
wf_timer_impl_dispose(
struct wf_timer * timer);
extern void wf_timer_impl_start(
struct wf_timer * timer,
int timeout_ms);
extern void wf_timer_impl_cancel(
struct wf_timer * timer);
extern bool wf_timer_impl_is_timeout(
struct wf_timer * timer);
extern void wf_timer_impl_trigger(
struct wf_timer * timer);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,38 +0,0 @@
#include <gtest/gtest.h>
#include "wf/timer/impl/timepoint.h"
#include <thread>
#include <chrono>
using namespace std::chrono_literals;
TEST(wf_timer_timepoint, now)
{
wf_timer_timepoint start = wf_timer_impl_timepoint_now();
std::this_thread::sleep_for(42ms);
wf_timer_timepoint end = wf_timer_impl_timepoint_now();
ASSERT_LT(start, end);
ASSERT_LT(end, start + 500);
}
TEST(wf_timer_timepoint, in_msec)
{
wf_timer_timepoint now = wf_timer_impl_timepoint_now();
wf_timer_timepoint later = wf_timer_impl_timepoint_in_msec(42);
ASSERT_LT(now, later);
ASSERT_LT(later, now + 500);
}
TEST(wf_timer_timepoint, elapsed)
{
wf_timer_timepoint now;
now = wf_timer_impl_timepoint_now();
ASSERT_TRUE(wf_timer_impl_timepoint_is_elapsed(now - 1));
now = wf_timer_impl_timepoint_now();
ASSERT_FALSE(wf_timer_impl_timepoint_is_elapsed(now + 500));
}

View File

@ -1,5 +1,5 @@
#include "wf/jsonrpc/mock_timer.hpp" #include "webfuse/tests/core/jsonrpc/mock_timer.hpp"
#include "wf/jsonrpc/wrap.hpp" #include "webfuse/utils/wrap.hpp"
extern "C" extern "C"
{ {

View File

@ -1,7 +1,8 @@
#ifndef WF_JSONRPC_MOCK_TIMERMANAGER_HPP #ifndef WF_JSONRPC_MOCK_TIMERMANAGER_HPP
#define WF_JSONRPC_MOCK_TIMERMANAGER_HPP #define WF_JSONRPC_MOCK_TIMERMANAGER_HPP
#include <wf/timer.h> #include "webfuse/core/timer/timer.h"
#include "webfuse/core/timer/manager.h"
#include <gmock/gmock.h> #include <gmock/gmock.h>
namespace wf_jsonrpc_test namespace wf_jsonrpc_test

View File

@ -1,4 +1,4 @@
#include "wf/jsonrpc/mock_timer_callback.hpp" #include "webfuse/tests/core/jsonrpc/mock_timer_callback.hpp"
extern "C" extern "C"
{ {

View File

@ -1,7 +1,7 @@
#ifndef WF_JSONRPC_MOCK_TIMERCALLBACK_HPP #ifndef WF_JSONRPC_MOCK_TIMERCALLBACK_HPP
#define WF_JSONRPC_MOCK_TIMERCALLBACK_HPP #define WF_JSONRPC_MOCK_TIMERCALLBACK_HPP
#include "wf/timer.h" #include "webfuse/core/timer/on_timer_fn.h"
#include <gmock/gmock.h> #include <gmock/gmock.h>
namespace wf_jsonrpc_test namespace wf_jsonrpc_test

View File

@ -1,5 +1,5 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "wf/jsonrpc/request.h" #include "webfuse/core/jsonrpc/request.h"
TEST(wf_jsonrpc_is_request, request_with_object_params) TEST(wf_jsonrpc_is_request, request_with_object_params)
{ {

View File

@ -1,5 +1,5 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "wf/jsonrpc/response.h" #include "webfuse/core/jsonrpc/response.h"
TEST(wf_jsonrpc_is_response, valid_result) TEST(wf_jsonrpc_is_response, valid_result)
{ {

View File

@ -1,9 +1,9 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "wf/jsonrpc/proxy.h" #include "webfuse/core/jsonrpc/proxy.h"
#include "wf/jsonrpc/status.h" #include "webfuse/core/status.h"
#include "wf/timer/manager.h" #include "webfuse/core/timer/manager.h"
#include "wf/jsonrpc/mock_timer.hpp" #include "webfuse/tests/core/jsonrpc/mock_timer.hpp"
#include <thread> #include <thread>
#include <chrono> #include <chrono>
@ -22,7 +22,7 @@ namespace
int jsonrpc_get_status(json_t * error) int jsonrpc_get_status(json_t * error)
{ {
json_t * code = json_object_get(error, "code"); json_t * code = json_object_get(error, "code");
return (json_is_integer(code)) ? json_integer_value(code) : WF_JSONRPC_BAD_FORMAT; return (json_is_integer(code)) ? json_integer_value(code) : WF_BAD_FORMAT;
} }
struct SendContext struct SendContext
@ -196,7 +196,7 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
ASSERT_FALSE(finished_context.is_called); ASSERT_FALSE(finished_context.is_called);
ASSERT_TRUE(finished_context2.is_called); ASSERT_TRUE(finished_context2.is_called);
ASSERT_EQ(WF_JSONRPC_BAD_BUSY, jsonrpc_get_status(finished_context2.error)); ASSERT_EQ(WF_BAD_BUSY, jsonrpc_get_status(finished_context2.error));
wf_jsonrpc_proxy_dispose(proxy); wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager); wf_timer_manager_dispose(timer_manager);
@ -217,7 +217,7 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_request_is_invalid)
ASSERT_FALSE(send_context.is_called); ASSERT_FALSE(send_context.is_called);
ASSERT_TRUE(finished_context.is_called); ASSERT_TRUE(finished_context.is_called);
ASSERT_EQ(WF_JSONRPC_BAD, jsonrpc_get_status(finished_context.error)); ASSERT_EQ(WF_BAD, jsonrpc_get_status(finished_context.error));
wf_jsonrpc_proxy_dispose(proxy); wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager); wf_timer_manager_dispose(timer_manager);
@ -307,7 +307,7 @@ TEST(wf_jsonrpc_proxy, timeout)
wf_timer_manager_check(timer_manager); wf_timer_manager_check(timer_manager);
ASSERT_TRUE(finished_context.is_called); ASSERT_TRUE(finished_context.is_called);
ASSERT_EQ(WF_JSONRPC_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error)); ASSERT_EQ(WF_BAD_TIMEOUT, jsonrpc_get_status(finished_context.error));
wf_jsonrpc_proxy_dispose(proxy); wf_jsonrpc_proxy_dispose(proxy);
wf_timer_manager_dispose(timer_manager); wf_timer_manager_dispose(timer_manager);

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "wf/jsonrpc/request.h" #include "webfuse/core/jsonrpc/request.h"
#include "wf/jsonrpc/status.h" #include "webfuse/core/status.h"
namespace namespace
{ {
@ -74,7 +74,7 @@ TEST(wf_jsonrpc_request, respond_error)
struct wf_jsonrpc_request * request = struct wf_jsonrpc_request * request =
wf_jsonrpc_request_create(42, &jsonrpc_send, user_data); wf_jsonrpc_request_create(42, &jsonrpc_send, user_data);
wf_jsonrpc_respond_error(request, WF_JSONRPC_BAD, "Bad"); wf_jsonrpc_respond_error(request, WF_BAD, "Bad");
ASSERT_NE(nullptr, context.response); ASSERT_NE(nullptr, context.response);
@ -93,7 +93,7 @@ TEST(wf_jsonrpc_request, respond_error)
json_t * err_code = json_object_get(err, "code"); json_t * err_code = json_object_get(err, "code");
ASSERT_TRUE(json_is_integer(err_code)); ASSERT_TRUE(json_is_integer(err_code));
ASSERT_EQ(WF_JSONRPC_BAD, json_integer_value(err_code)); ASSERT_EQ(WF_BAD, json_integer_value(err_code));
json_t * err_message = json_object_get(err, "message"); json_t * err_message = json_object_get(err, "message");
ASSERT_TRUE(json_is_string(err_message)); ASSERT_TRUE(json_is_string(err_message));

View File

@ -1,6 +1,6 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "wf/jsonrpc/impl/response.h" #include "webfuse/core/jsonrpc/response_intern.h"
#include "wf/jsonrpc/status.h" #include "webfuse/core/status.h"
TEST(wf_json_response, init_result) TEST(wf_json_response, init_result)
{ {
@ -9,14 +9,14 @@ TEST(wf_json_response, init_result)
json_object_set_new(message, "id", json_integer(11)); json_object_set_new(message, "id", json_integer(11));
struct wf_jsonrpc_response response; struct wf_jsonrpc_response response;
wf_jsonrpc_impl_response_init(&response, message); wf_jsonrpc_response_init(&response, message);
ASSERT_EQ(nullptr, response.error); ASSERT_EQ(nullptr, response.error);
ASSERT_TRUE(json_is_integer(response.result)); ASSERT_TRUE(json_is_integer(response.result));
ASSERT_EQ(47, json_integer_value(response.result)); ASSERT_EQ(47, json_integer_value(response.result));
ASSERT_EQ(11, response.id); ASSERT_EQ(11, response.id);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
json_decref(message); json_decref(message);
} }
@ -30,14 +30,14 @@ TEST(wf_json_response, init_error)
json_object_set_new(message, "id", json_integer(23)); json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response; struct wf_jsonrpc_response response;
wf_jsonrpc_impl_response_init(&response, message); wf_jsonrpc_response_init(&response, message);
ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code")));
ASSERT_STREQ("Don't Panic!", json_string_value(json_object_get(response.error, "message"))); ASSERT_STREQ("Don't Panic!", json_string_value(json_object_get(response.error, "message")));
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id); ASSERT_EQ(23, response.id);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
json_decref(message); json_decref(message);
} }
@ -47,13 +47,13 @@ TEST(wf_json_response, init_fail_missing_result_and_error)
json_object_set_new(message, "id", json_integer(12)); json_object_set_new(message, "id", json_integer(12));
struct wf_jsonrpc_response response; struct wf_jsonrpc_response response;
wf_jsonrpc_impl_response_init(&response, message); wf_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(12, response.id); ASSERT_EQ(12, response.id);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
json_decref(message); json_decref(message);
} }
@ -63,13 +63,13 @@ TEST(wf_json_response, init_fail_missing_id)
json_object_set_new(message, "result", json_integer(47)); json_object_set_new(message, "result", json_integer(47));
struct wf_jsonrpc_response response; struct wf_jsonrpc_response response;
wf_jsonrpc_impl_response_init(&response, message); wf_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(-1, response.id); ASSERT_EQ(-1, response.id);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
json_decref(message); json_decref(message);
} }
@ -80,13 +80,13 @@ TEST(wf_json_response, init_fail_wrong_id_type)
json_object_set_new(message, "id", json_string("42")); json_object_set_new(message, "id", json_string("42"));
struct wf_jsonrpc_response response; struct wf_jsonrpc_response response;
wf_jsonrpc_impl_response_init(&response, message); wf_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(-1, response.id); ASSERT_EQ(-1, response.id);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
json_decref(message); json_decref(message);
} }
@ -99,13 +99,13 @@ TEST(wf_json_response, init_fail_error_missing_code)
json_object_set_new(message, "id", json_integer(23)); json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response; struct wf_jsonrpc_response response;
wf_jsonrpc_impl_response_init(&response, message); wf_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id); ASSERT_EQ(23, response.id);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
json_decref(message); json_decref(message);
} }
@ -119,13 +119,13 @@ TEST(wf_json_response, init_fail_error_wrong_code_type)
json_object_set_new(message, "id", json_integer(23)); json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response; struct wf_jsonrpc_response response;
wf_jsonrpc_impl_response_init(&response, message); wf_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id); ASSERT_EQ(23, response.id);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
json_decref(message); json_decref(message);
} }
@ -136,12 +136,12 @@ TEST(wf_json_response, init_fail_error_wrong_type)
json_object_set_new(message, "id", json_integer(23)); json_object_set_new(message, "id", json_integer(23));
struct wf_jsonrpc_response response; struct wf_jsonrpc_response response;
wf_jsonrpc_impl_response_init(&response, message); wf_jsonrpc_response_init(&response, message);
ASSERT_EQ(WF_JSONRPC_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(WF_BAD_FORMAT, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
ASSERT_EQ(23, response.id); ASSERT_EQ(23, response.id);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
json_decref(message); json_decref(message);
} }

View File

@ -1,7 +1,7 @@
#include <string> #include <string>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "wf/jsonrpc/impl/response.h" #include "webfuse/core/jsonrpc/response_intern.h"
static void response_parse_str( static void response_parse_str(
@ -11,7 +11,7 @@ static void response_parse_str(
json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr); json_t * message = json_loadb(buffer.c_str(), buffer.size(), 0, nullptr);
if (nullptr != message) if (nullptr != message)
{ {
wf_jsonrpc_impl_response_init(response, message); wf_jsonrpc_response_init(response, message);
json_decref(message); json_decref(message);
} }
} }
@ -25,21 +25,21 @@ TEST(response_parser, test)
ASSERT_NE(nullptr, response.error); ASSERT_NE(nullptr, response.error);
ASSERT_EQ(-1, response.id); ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
// empty // empty
response_parse_str("{}", &response); response_parse_str("{}", &response);
ASSERT_NE(nullptr, response.error); ASSERT_NE(nullptr, response.error);
ASSERT_EQ(-1, response.id); ASSERT_EQ(-1, response.id);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
// no data // no data
response_parse_str("{\"id\":42}", &response); response_parse_str("{\"id\":42}", &response);
ASSERT_NE(nullptr, response.error); ASSERT_NE(nullptr, response.error);
ASSERT_EQ(42, response.id); ASSERT_EQ(42, response.id);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
// custom error code // custom error code
response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response); response_parse_str("{\"error\":{\"code\": 42}, \"id\": 42}", &response);
@ -47,12 +47,12 @@ TEST(response_parser, test)
ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code"))); ASSERT_EQ(42, json_integer_value(json_object_get(response.error, "code")));
ASSERT_EQ(42, response.id); ASSERT_EQ(42, response.id);
ASSERT_EQ(nullptr, response.result); ASSERT_EQ(nullptr, response.result);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
// valid response // valid response
response_parse_str("{\"result\": true, \"id\": 42}", &response); response_parse_str("{\"result\": true, \"id\": 42}", &response);
ASSERT_EQ(nullptr, response.error); ASSERT_EQ(nullptr, response.error);
ASSERT_EQ(42, response.id); ASSERT_EQ(42, response.id);
ASSERT_NE(nullptr, response.result); ASSERT_NE(nullptr, response.result);
wf_jsonrpc_impl_response_cleanup(&response); wf_jsonrpc_response_cleanup(&response);
} }

View File

@ -1,7 +1,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "wf/jsonrpc/server.h" #include "webfuse/core/jsonrpc/server.h"
#include "wf/jsonrpc/request.h" #include "webfuse/core/jsonrpc/request.h"
#include "wf/jsonrpc/status.h" #include "webfuse/core/status.h"
namespace namespace
{ {
@ -125,7 +125,7 @@ TEST(wf_jsonrpc_server, invoke_unknown_method)
json_t * err_code = json_object_get(err, "code"); json_t * err_code = json_object_get(err, "code");
ASSERT_TRUE(json_is_integer(err_code)); ASSERT_TRUE(json_is_integer(err_code));
ASSERT_EQ(WF_JSONRPC_BAD_NOTIMPLEMENTED, json_integer_value(err_code)); ASSERT_EQ(WF_BAD_NOTIMPLEMENTED, json_integer_value(err_code));
json_t * err_message = json_object_get(err, "message"); json_t * err_message = json_object_get(err, "message");
ASSERT_TRUE(json_is_string(err_message)); ASSERT_TRUE(json_is_string(err_message));

View File

@ -0,0 +1,38 @@
#include <gtest/gtest.h>
#include "webfuse/core/timer/timepoint.h"
#include <thread>
#include <chrono>
using namespace std::chrono_literals;
TEST(wf_timer_timepoint, now)
{
wf_timer_timepoint start = wf_timer_timepoint_now();
std::this_thread::sleep_for(42ms);
wf_timer_timepoint end = wf_timer_timepoint_now();
ASSERT_LT(start, end);
ASSERT_LT(end, start + 500);
}
TEST(wf_timer_timepoint, in_msec)
{
wf_timer_timepoint now = wf_timer_timepoint_now();
wf_timer_timepoint later = wf_timer_timepoint_in_msec(42);
ASSERT_LT(now, later);
ASSERT_LT(later, now + 500);
}
TEST(wf_timer_timepoint, elapsed)
{
wf_timer_timepoint now;
now = wf_timer_timepoint_now();
ASSERT_TRUE(wf_timer_timepoint_is_elapsed(now - 1));
now = wf_timer_timepoint_now();
ASSERT_FALSE(wf_timer_timepoint_is_elapsed(now + 500));
}

View File

@ -4,8 +4,8 @@
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#include "wf/timer/timer.h" #include "webfuse/core/timer/timer.h"
#include "wf/timer/manager.h" #include "webfuse/core/timer/manager.h"
using std::size_t; using std::size_t;
using namespace std::chrono_literals; using namespace std::chrono_literals;