From bbdd5a24f59f5b301b7d70c15134637fc8ec6143 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Sun, 29 Mar 2020 17:40:33 +0200 Subject: [PATCH] integrated libwf_timer and libwf_jsonrpc into libwebfuse-core --- CMakeLists.txt | 2 - cmake/unit_tests.cmake | 43 ++---- cmake/webfuse_adapter.cmake | 4 +- cmake/webfuse_core.cmake | 10 ++ cmake/webfuse_provider.cmake | 4 +- cmake/wf_jsonrpc.cmake | 24 --- cmake/wf_timer.cmake | 18 --- lib/webfuse/adapter/impl/operation/close.c | 2 +- lib/webfuse/adapter/impl/operation/getattr.c | 2 +- lib/webfuse/adapter/impl/operation/lookup.c | 2 +- lib/webfuse/adapter/impl/operation/open.c | 2 +- lib/webfuse/adapter/impl/operation/read.c | 2 +- lib/webfuse/adapter/impl/operation/readdir.c | 2 +- lib/webfuse/adapter/impl/server_protocol.c | 6 +- lib/webfuse/adapter/impl/server_protocol.h | 4 +- lib/webfuse/adapter/impl/session.c | 6 +- lib/webfuse/adapter/impl/session.h | 4 +- lib/webfuse/core/json_util.c | 23 +-- .../impl => webfuse/core/jsonrpc}/error.c | 8 +- .../impl => webfuse/core/jsonrpc}/error.h | 10 +- .../impl => webfuse/core/jsonrpc}/method.c | 6 +- .../impl => webfuse/core/jsonrpc}/method.h | 10 +- .../core}/jsonrpc/method_invoke_fn.h | 2 - .../impl => webfuse/core/jsonrpc}/proxy.c | 63 ++++---- .../wf => webfuse/core}/jsonrpc/proxy.h | 15 +- .../core}/jsonrpc/proxy_finished_fn.h | 0 lib/webfuse/core/jsonrpc/proxy_intern.h | 48 ++++++ .../impl => webfuse/core/jsonrpc}/request.c | 22 +-- .../wf => webfuse/core}/jsonrpc/request.h | 15 +- .../impl => webfuse/core/jsonrpc}/response.c | 16 +- .../wf => webfuse/core}/jsonrpc/response.h | 3 +- .../core/jsonrpc/response_intern.h} | 16 +- .../wf => webfuse/core}/jsonrpc/send_fn.h | 1 - .../impl => webfuse/core/jsonrpc}/server.c | 57 ++++--- .../wf => webfuse/core}/jsonrpc/server.h | 13 +- .../impl => webfuse/core/timer}/manager.c | 24 +-- .../wf => webfuse/core}/timer/manager.h | 8 +- lib/webfuse/core/timer/manager_intern.h | 26 ++++ .../wf => webfuse/core}/timer/on_timer_fn.h | 0 .../impl => webfuse/core/timer}/timepoint.c | 12 +- .../impl => webfuse/core/timer}/timepoint.h | 10 +- .../timer/impl => webfuse/core/timer}/timer.c | 26 ++-- .../include/wf => webfuse/core}/timer/timer.h | 11 +- lib/webfuse/core/timer/timer_intern.h | 40 +++++ lib/webfuse/provider/impl/client_protocol.c | 8 +- lib/wf/jsonrpc/include/wf/jsonrpc.h | 14 -- lib/wf/jsonrpc/include/wf/jsonrpc/api.h | 8 - lib/wf/jsonrpc/include/wf/jsonrpc/status.h | 11 -- lib/wf/jsonrpc/src/wf/jsonrpc/api.c | 144 ------------------ lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h | 84 ---------- lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h | 53 ------- lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h | 41 ----- .../src/wf/jsonrpc/impl/unused_param.h | 10 -- lib/wf/timer/include/wf/timer.h | 9 -- lib/wf/timer/include/wf/timer/api.h | 8 - lib/wf/timer/src/wf/timer/api.c | 59 ------- lib/wf/timer/src/wf/timer/impl/manager.h | 36 ----- lib/wf/timer/src/wf/timer/impl/timer.h | 59 ------- lib/wf/timer/test/wf/timer/test_timepoint.cc | 38 ----- .../webfuse/tests/core}/jsonrpc/mock_timer.cc | 4 +- .../tests/core}/jsonrpc/mock_timer.hpp | 3 +- .../core}/jsonrpc/mock_timer_callback.cc | 2 +- .../core}/jsonrpc/mock_timer_callback.hpp | 2 +- .../tests/core}/jsonrpc/test_is_request.cc | 2 +- .../tests/core}/jsonrpc/test_is_response.cc | 2 +- .../webfuse/tests/core}/jsonrpc/test_proxy.cc | 16 +- .../tests/core}/jsonrpc/test_request.cc | 8 +- .../tests/core}/jsonrpc/test_response.cc | 48 +++--- .../core}/jsonrpc/test_response_parser.cc | 14 +- .../tests/core}/jsonrpc/test_server.cc | 8 +- .../tests/core/timer/test_timepoint.cc | 38 +++++ .../webfuse/tests/core}/timer/test_timer.cc | 4 +- .../jsonrpc => test/webfuse/utils}/wrap.hpp | 0 73 files changed, 426 insertions(+), 929 deletions(-) delete mode 100644 cmake/wf_jsonrpc.cmake delete mode 100644 cmake/wf_timer.cmake rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/error.c (73%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/error.h (63%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/method.c (77%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/method.h (70%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/method_invoke_fn.h (92%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/proxy.c (74%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/proxy.h (80%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/proxy_finished_fn.h (100%) create mode 100644 lib/webfuse/core/jsonrpc/proxy_intern.h rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/request.c (76%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/request.h (64%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/response.c (73%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/response.h (74%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl/response.h => webfuse/core/jsonrpc/response_intern.h} (57%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/send_fn.h (90%) rename lib/{wf/jsonrpc/src/wf/jsonrpc/impl => webfuse/core/jsonrpc}/server.c (59%) rename lib/{wf/jsonrpc/include/wf => webfuse/core}/jsonrpc/server.h (69%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/manager.c (73%) rename lib/{wf/timer/include/wf => webfuse/core}/timer/manager.h (72%) create mode 100644 lib/webfuse/core/timer/manager_intern.h rename lib/{wf/timer/include/wf => webfuse/core}/timer/on_timer_fn.h (100%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/timepoint.c (59%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/timepoint.h (57%) rename lib/{wf/timer/src/wf/timer/impl => webfuse/core/timer}/timer.c (61%) rename lib/{wf/timer/include/wf => webfuse/core}/timer/timer.h (72%) create mode 100644 lib/webfuse/core/timer/timer_intern.h delete mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc.h delete mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc/api.h delete mode 100644 lib/wf/jsonrpc/include/wf/jsonrpc/status.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/api.c delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h delete mode 100644 lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h delete mode 100644 lib/wf/timer/include/wf/timer.h delete mode 100644 lib/wf/timer/include/wf/timer/api.h delete mode 100644 lib/wf/timer/src/wf/timer/api.c delete mode 100644 lib/wf/timer/src/wf/timer/impl/manager.h delete mode 100644 lib/wf/timer/src/wf/timer/impl/timer.h delete mode 100644 lib/wf/timer/test/wf/timer/test_timepoint.cc rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer.cc (90%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer.hpp (94%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer_callback.cc (90%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/mock_timer_callback.hpp (89%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_is_request.cc (98%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_is_response.cc (98%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_proxy.cc (97%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_request.cc (95%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_response.cc (69%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_response_parser.cc (80%) rename {lib/wf/jsonrpc/test/wf => test/webfuse/tests/core}/jsonrpc/test_server.cc (97%) create mode 100644 test/webfuse/tests/core/timer/test_timepoint.cc rename {lib/wf/timer/test/wf => test/webfuse/tests/core}/timer/test_timer.cc (97%) rename {lib/wf/jsonrpc/test/wf/jsonrpc => test/webfuse/utils}/wrap.hpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index cfe430b..5e3f18c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -37,8 +37,6 @@ add_compile_options( "-pthread" ) -include(wf_timer) -include(wf_jsonrpc) include(webfuse_core) include(webfuse_adapter) include(webfuse_provider) diff --git a/cmake/unit_tests.cmake b/cmake/unit_tests.cmake index 1722301..8f21188 100644 --- a/cmake/unit_tests.cmake +++ b/cmake/unit_tests.cmake @@ -7,17 +7,17 @@ include(GoogleTest) pkg_check_modules(GMOCK gmock) add_executable(alltests - lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc - lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc - lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc - lib/wf/timer/test/wf/timer/test_timepoint.cc - lib/wf/timer/test/wf/timer/test_timer.cc + test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc + test/webfuse/tests/core/jsonrpc/mock_timer.cc + test/webfuse/tests/core/jsonrpc/test_is_request.cc + test/webfuse/tests/core/jsonrpc/test_request.cc + test/webfuse/tests/core/jsonrpc/test_is_response.cc + test/webfuse/tests/core/jsonrpc/test_response.cc + test/webfuse/tests/core/jsonrpc/test_server.cc + test/webfuse/tests/core/jsonrpc/test_proxy.cc + test/webfuse/tests/core/jsonrpc/test_response_parser.cc + test/webfuse/tests/core/timer/test_timepoint.cc + test/webfuse/tests/core/timer/test_timer.cc test/webfuse/utils/tempdir.cc test/webfuse/utils/file_utils.cc test/webfuse/utils/die_if.cc @@ -50,19 +50,6 @@ add_executable(alltests 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 -Wl,--wrap=wf_timer_manager_create -Wl,--wrap=wf_timer_manager_dispose @@ -75,8 +62,6 @@ target_link_libraries(alltests PUBLIC webfuse-adapter-static webfuse-provider-static webfuse-core - wf_jsonrpc - wf_timer ${FUSE3_LIBRARIES} ${LWS_LIBRARIES} ${JANSSON_LIBRARIES} @@ -85,8 +70,8 @@ target_link_libraries(alltests PUBLIC ${GTEST_LIBRARIES} ) -target_include_directories(alltests PUBLIC test lib ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) -target_compile_options(alltests PUBLIC ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) +target_include_directories(alltests PUBLIC test lib ${FUSE3_INCLUDE_DIRS} ${GMOCK_INCLUDE_DIRS} ${GTEST_INCLUDE_DIRS}) +target_compile_options(alltests PUBLIC ${FUSE3_CFLAGS_OTHER} ${GMOCK_CFLAGS} ${GTEST_CFLAGS}) enable_testing() gtest_discover_tests(alltests TEST_PREFIX alltests:) @@ -102,7 +87,7 @@ add_custom_target(coverage add_dependencies(coverage alltests) 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) diff --git a/cmake/webfuse_adapter.cmake b/cmake/webfuse_adapter.cmake index f6e777c..fab0f55 100644 --- a/cmake/webfuse_adapter.cmake +++ b/cmake/webfuse_adapter.cmake @@ -26,8 +26,6 @@ add_library(webfuse-adapter-static STATIC target_include_directories(webfuse-adapter-static PRIVATE lib - lib/wf/timer/include - lib/wf/jsonrpc/include ${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 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" "prefix=\"${CMAKE_INSTALL_PREFIX}\" diff --git a/cmake/webfuse_core.cmake b/cmake/webfuse_core.cmake index dab6223..fb25b75 100644 --- a/cmake/webfuse_core.cmake +++ b/cmake/webfuse_core.cmake @@ -9,6 +9,16 @@ add_library(webfuse-core STATIC lib/webfuse/core/base64.c lib/webfuse/core/lws_log.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) diff --git a/cmake/webfuse_provider.cmake b/cmake/webfuse_provider.cmake index 4cf285d..fbfa104 100644 --- a/cmake/webfuse_provider.cmake +++ b/cmake/webfuse_provider.cmake @@ -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) target_include_directories(webfuse-provider-static PRIVATE lib - lib/wf/timer/include - lib/wf/jsonrpc/include ) 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") 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" "prefix=\"${CMAKE_INSTALL_PREFIX}\" diff --git a/cmake/wf_jsonrpc.cmake b/cmake/wf_jsonrpc.cmake deleted file mode 100644 index fae8d74..0000000 --- a/cmake/wf_jsonrpc.cmake +++ /dev/null @@ -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) diff --git a/cmake/wf_timer.cmake b/cmake/wf_timer.cmake deleted file mode 100644 index 8bdecf2..0000000 --- a/cmake/wf_timer.cmake +++ /dev/null @@ -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) diff --git a/lib/webfuse/adapter/impl/operation/close.c b/lib/webfuse/adapter/impl/operation/close.c index dcb65fb..5f6e49b 100644 --- a/lib/webfuse/adapter/impl/operation/close.c +++ b/lib/webfuse/adapter/impl/operation/close.c @@ -4,7 +4,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" void wf_impl_operation_close( diff --git a/lib/webfuse/adapter/impl/operation/getattr.c b/lib/webfuse/adapter/impl/operation/getattr.c index 767b06c..ae64a25 100644 --- a/lib/webfuse/adapter/impl/operation/getattr.c +++ b/lib/webfuse/adapter/impl/operation/getattr.c @@ -7,7 +7,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" diff --git a/lib/webfuse/adapter/impl/operation/lookup.c b/lib/webfuse/adapter/impl/operation/lookup.c index 596f7e4..4b64320 100644 --- a/lib/webfuse/adapter/impl/operation/lookup.c +++ b/lib/webfuse/adapter/impl/operation/lookup.c @@ -10,7 +10,7 @@ #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/json_util.h" #include "webfuse/core/util.h" diff --git a/lib/webfuse/adapter/impl/operation/open.c b/lib/webfuse/adapter/impl/operation/open.c index 0c10c45..8e21100 100644 --- a/lib/webfuse/adapter/impl/operation/open.c +++ b/lib/webfuse/adapter/impl/operation/open.c @@ -4,7 +4,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" #include "webfuse/core/status.h" #include "webfuse/core/json_util.h" diff --git a/lib/webfuse/adapter/impl/operation/read.c b/lib/webfuse/adapter/impl/operation/read.c index 8fa5bee..7896b30 100644 --- a/lib/webfuse/adapter/impl/operation/read.c +++ b/lib/webfuse/adapter/impl/operation/read.c @@ -5,7 +5,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/base64.h" #include "webfuse/core/json_util.h" diff --git a/lib/webfuse/adapter/impl/operation/readdir.c b/lib/webfuse/adapter/impl/operation/readdir.c index f188084..804a80e 100644 --- a/lib/webfuse/adapter/impl/operation/readdir.c +++ b/lib/webfuse/adapter/impl/operation/readdir.c @@ -8,7 +8,7 @@ #include #include -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/proxy.h" #include "webfuse/core/util.h" #include "webfuse/core/json_util.h" diff --git a/lib/webfuse/adapter/impl/server_protocol.c b/lib/webfuse/adapter/impl/server_protocol.c index ee5cbb0..7caf0bc 100644 --- a/lib/webfuse/adapter/impl/server_protocol.c +++ b/lib/webfuse/adapter/impl/server_protocol.c @@ -11,9 +11,9 @@ #include "webfuse/adapter/impl/credentials.h" #include "webfuse/core/status_intern.h" -#include "wf/jsonrpc/request.h" -#include "wf/timer/manager.h" -#include "wf/timer/timer.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/timer/manager.h" +#include "webfuse/core/timer/timer.h" static int wf_impl_server_protocol_callback( struct lws * wsi, diff --git a/lib/webfuse/adapter/impl/server_protocol.h b/lib/webfuse/adapter/impl/server_protocol.h index df98c8f..269e3be 100644 --- a/lib/webfuse/adapter/impl/server_protocol.h +++ b/lib/webfuse/adapter/impl/server_protocol.h @@ -4,8 +4,8 @@ #include "webfuse/adapter/impl/authenticators.h" #include "webfuse/adapter/impl/mountpoint_factory.h" #include "webfuse/adapter/impl/session_manager.h" -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/server.h" #ifndef __cplusplus #include diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c index 778d155..6bacd10 100644 --- a/lib/webfuse/adapter/impl/session.c +++ b/lib/webfuse/adapter/impl/session.c @@ -8,9 +8,9 @@ #include "webfuse/core/container_of.h" #include "webfuse/core/util.h" -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/response.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/response.h" #include #include diff --git a/lib/webfuse/adapter/impl/session.h b/lib/webfuse/adapter/impl/session.h index 82b042f..1046a2e 100644 --- a/lib/webfuse/adapter/impl/session.h +++ b/lib/webfuse/adapter/impl/session.h @@ -13,8 +13,8 @@ using std::size_t; #include "webfuse/adapter/impl/filesystem.h" #include "webfuse/core/slist.h" -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/server.h" #ifdef __cplusplus extern "C" diff --git a/lib/webfuse/core/json_util.c b/lib/webfuse/core/json_util.c index 48fe956..535e07e 100644 --- a/lib/webfuse/core/json_util.c +++ b/lib/webfuse/core/json_util.c @@ -1,5 +1,4 @@ #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) { @@ -14,25 +13,6 @@ int wf_impl_json_get_int(json_t const * object, char const * key, int default_va 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_impl_jsonrpc_get_status( json_t const * error) @@ -40,8 +20,7 @@ wf_impl_jsonrpc_get_status( wf_status status = WF_GOOD; if (NULL != error) { - int code = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT); - status = wf_impl_jsonrc_code_to_status(code); + status = wf_impl_json_get_int(error, "code", WF_BAD_FORMAT); } return status; diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c b/lib/webfuse/core/jsonrpc/error.c similarity index 73% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c rename to lib/webfuse/core/jsonrpc/error.c index eba2e86..ad74a58 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.c +++ b/lib/webfuse/core/jsonrpc/error.c @@ -1,7 +1,7 @@ -#include "wf/jsonrpc/impl/error.h" +#include "webfuse/core/jsonrpc/error.h" json_t * -wf_jsonrpc_impl_error( +wf_jsonrpc_error( int code, char const * message) { @@ -13,13 +13,13 @@ wf_jsonrpc_impl_error( } void -wf_jsonrpc_impl_propate_error( +wf_jsonrpc_propate_error( wf_jsonrpc_proxy_finished_fn * finised, void * user_data, int code, 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); json_decref(error); diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h b/lib/webfuse/core/jsonrpc/error.h similarity index 63% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h rename to lib/webfuse/core/jsonrpc/error.h index fda0f89..2edfd92 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/error.h +++ b/lib/webfuse/core/jsonrpc/error.h @@ -1,8 +1,8 @@ -#ifndef WF_JSONRPC_IMPL_ERROR_H -#define WF_JSONRPC_IMPL_ERROR_H +#ifndef WF_JSONRPC_ERROR_H +#define WF_JSONRPC_ERROR_H #include -#include "wf/jsonrpc/proxy_finished_fn.h" +#include "webfuse/core/jsonrpc/proxy_finished_fn.h" #ifdef __cplusplus extern "C" @@ -10,12 +10,12 @@ extern "C" #endif extern json_t * -wf_jsonrpc_impl_error( +wf_jsonrpc_error( int code, char const * message); extern void -wf_jsonrpc_impl_propate_error( +wf_jsonrpc_propate_error( wf_jsonrpc_proxy_finished_fn * finised, void * user_data, int code, diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c b/lib/webfuse/core/jsonrpc/method.c similarity index 77% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c rename to lib/webfuse/core/jsonrpc/method.c index ef0d16c..a184dca 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.c +++ b/lib/webfuse/core/jsonrpc/method.c @@ -1,8 +1,8 @@ -#include "wf/jsonrpc/impl/method.h" +#include "webfuse/core/jsonrpc/method.h" #include #include -struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create( +struct wf_jsonrpc_method * wf_jsonrpc_method_create( char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, void * user_data) @@ -16,7 +16,7 @@ struct wf_jsonrpc_method * wf_jsonrpc_impl_method_create( return method; } -void wf_jsonrpc_impl_method_dispose( +void wf_jsonrpc_method_dispose( struct wf_jsonrpc_method * method) { free(method->name); diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h b/lib/webfuse/core/jsonrpc/method.h similarity index 70% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h rename to lib/webfuse/core/jsonrpc/method.h index d0e42f0..e196bff 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/method.h +++ b/lib/webfuse/core/jsonrpc/method.h @@ -1,7 +1,7 @@ -#ifndef WF_JSONRPC_IMPL_METHOD_H -#define WF_JSONRPC_IMPL_METHOD_H +#ifndef WF_JSONRPC_METHOD_H +#define WF_JSONRPC_METHOD_H -#include "wf/jsonrpc/method_invoke_fn.h" +#include "webfuse/core/jsonrpc/method_invoke_fn.h" #ifdef __cplusplus extern "C" @@ -17,13 +17,13 @@ struct wf_jsonrpc_method }; extern struct wf_jsonrpc_method * -wf_jsonrpc_impl_method_create( +wf_jsonrpc_method_create( char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, void * user_data); extern void -wf_jsonrpc_impl_method_dispose( +wf_jsonrpc_method_dispose( struct wf_jsonrpc_method * method); #ifdef __cplusplus diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h b/lib/webfuse/core/jsonrpc/method_invoke_fn.h similarity index 92% rename from lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h rename to lib/webfuse/core/jsonrpc/method_invoke_fn.h index d7a9cc8..046dfb6 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/method_invoke_fn.h +++ b/lib/webfuse/core/jsonrpc/method_invoke_fn.h @@ -1,7 +1,6 @@ #ifndef WF_JSONRPC_METHOD_INVOKE_FN_H #define WF_JSONRPC_METHOD_INVOKE_FN_H -#include #include #ifdef __cplusplus @@ -17,7 +16,6 @@ typedef void wf_jsonrpc_method_invoke_fn( json_t * params, void * user_data); - #ifdef __cplusplus } #endif diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c b/lib/webfuse/core/jsonrpc/proxy.c similarity index 74% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c rename to lib/webfuse/core/jsonrpc/proxy.c index 99b3f03..67fd6d8 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.c +++ b/lib/webfuse/core/jsonrpc/proxy.c @@ -1,34 +1,34 @@ -#include "wf/jsonrpc/impl/proxy.h" -#include "wf/jsonrpc/impl/response.h" -#include "wf/jsonrpc/impl/error.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/proxy_intern.h" +#include "webfuse/core/jsonrpc/response_intern.h" +#include "webfuse/core/jsonrpc/error.h" +#include "webfuse/core/status.h" -#include +#include "webfuse/core/timer/timer.h" #include #include struct wf_jsonrpc_proxy * -wf_jsonrpc_impl_proxy_create( +wf_jsonrpc_proxy_create( struct wf_timer_manager * manager, int timeout, wf_jsonrpc_send_fn * send, void * user_data) { 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; } -void wf_jsonrpc_impl_proxy_dispose( +void wf_jsonrpc_proxy_dispose( struct wf_jsonrpc_proxy * proxy) { - wf_jsonrpc_impl_proxy_cleanup(proxy); + wf_jsonrpc_proxy_cleanup(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_jsonrpc_proxy * proxy = proxy_ptr; @@ -44,11 +44,11 @@ static void wf_jsonrpc_impl_proxy_on_timeout( proxy->request.finished = NULL; 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, int id, char const * param_info, @@ -98,7 +98,7 @@ static json_t * wf_jsonrpc_impl_request_create( return request; } -void wf_jsonrpc_impl_proxy_init( +void wf_jsonrpc_proxy_init( struct wf_jsonrpc_proxy * proxy, struct wf_timer_manager * timeout_manager, int timeout, @@ -110,10 +110,10 @@ void wf_jsonrpc_impl_proxy_init( proxy->user_data = user_data; proxy->request.is_pending = false; 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) { if (proxy->request.is_pending) @@ -127,19 +127,19 @@ void wf_jsonrpc_impl_proxy_cleanup( proxy->request.id = 0; 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); } -void wf_jsonrpc_impl_proxy_invoke( +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 + ... ) { if (!proxy->request.is_pending) @@ -150,7 +150,10 @@ void wf_jsonrpc_impl_proxy_invoke( proxy->request.id = 42; 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))); if (!is_send) @@ -161,7 +164,7 @@ void wf_jsonrpc_impl_proxy_invoke( proxy->request.id = 0; 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) @@ -171,18 +174,22 @@ void wf_jsonrpc_impl_proxy_invoke( } 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, char const * method_name, 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) { 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, json_t * message) { 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)) { @@ -212,6 +219,6 @@ void wf_jsonrpc_impl_proxy_onresult( finished(user_data, response.result, response.error); } - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); } diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h b/lib/webfuse/core/jsonrpc/proxy.h similarity index 80% rename from lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h rename to lib/webfuse/core/jsonrpc/proxy.h index 66fd1a5..8a69936 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/proxy.h +++ b/lib/webfuse/core/jsonrpc/proxy.h @@ -12,9 +12,8 @@ using std::size_t; #endif #include -#include -#include -#include +#include "webfuse/core/jsonrpc/send_fn.h" +#include "webfuse/core/jsonrpc/proxy_finished_fn.h" #ifdef __cplusplus extern "C" { @@ -23,14 +22,14 @@ extern "C" { struct wf_jsonrpc_proxy; struct wf_timer_manager; -extern WF_JSONRPC_API struct wf_jsonrpc_proxy * +extern struct wf_jsonrpc_proxy * wf_jsonrpc_proxy_create( struct wf_timer_manager * manager, int timeout, wf_jsonrpc_send_fn * send, void * user_data); -extern WF_JSONRPC_API void wf_jsonrpc_proxy_dispose( +extern void wf_jsonrpc_proxy_dispose( 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 ... params //------------------------------------------------------------------------------ -extern WF_JSONRPC_API void wf_jsonrpc_proxy_invoke( +extern void wf_jsonrpc_proxy_invoke( struct wf_jsonrpc_proxy * proxy, wf_jsonrpc_proxy_finished_fn * finished, 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, char const * method_name, char const * param_info, ... ); -extern WF_JSONRPC_API void wf_jsonrpc_proxy_onresult( +extern void wf_jsonrpc_proxy_onresult( struct wf_jsonrpc_proxy * proxy, json_t * message); diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/proxy_finished_fn.h b/lib/webfuse/core/jsonrpc/proxy_finished_fn.h similarity index 100% rename from lib/wf/jsonrpc/include/wf/jsonrpc/proxy_finished_fn.h rename to lib/webfuse/core/jsonrpc/proxy_finished_fn.h diff --git a/lib/webfuse/core/jsonrpc/proxy_intern.h b/lib/webfuse/core/jsonrpc/proxy_intern.h new file mode 100644 index 0000000..3186e14 --- /dev/null +++ b/lib/webfuse/core/jsonrpc/proxy_intern.h @@ -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 diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c b/lib/webfuse/core/jsonrpc/request.c similarity index 76% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c rename to lib/webfuse/core/jsonrpc/request.c index 071ec4b..30212bd 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.c +++ b/lib/webfuse/core/jsonrpc/request.c @@ -1,5 +1,5 @@ -#include "wf/jsonrpc/impl/request.h" -#include "wf/jsonrpc/impl/error.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/error.h" #include struct wf_jsonrpc_request @@ -10,7 +10,7 @@ struct wf_jsonrpc_request }; bool -wf_jsonrpc_impl_is_request( +wf_jsonrpc_is_request( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -23,7 +23,7 @@ wf_jsonrpc_impl_is_request( struct wf_jsonrpc_request * -wf_jsonrpc_impl_request_create( +wf_jsonrpc_request_create( int id, wf_jsonrpc_send_fn * send, void * user_data) @@ -37,14 +37,14 @@ wf_jsonrpc_impl_request_create( } void -wf_jsonrpc_impl_request_dispose( +wf_jsonrpc_request_dispose( struct wf_jsonrpc_request * request) { free(request); } void * -wf_jsonrpc_impl_request_get_userdata( +wf_jsonrpc_request_get_userdata( struct wf_jsonrpc_request * request) { return request->user_data; @@ -52,7 +52,7 @@ wf_jsonrpc_impl_request_get_userdata( void -wf_jsonrpc_impl_respond( +wf_jsonrpc_respond( struct wf_jsonrpc_request * request, json_t * result) { @@ -62,20 +62,20 @@ wf_jsonrpc_impl_respond( request->send(response, request->user_data); 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, int code, char const * message) { 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)); request->send(response, request->user_data); json_decref(response); - wf_jsonrpc_impl_request_dispose(request); + wf_jsonrpc_request_dispose(request); } diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/request.h b/lib/webfuse/core/jsonrpc/request.h similarity index 64% rename from lib/wf/jsonrpc/include/wf/jsonrpc/request.h rename to lib/webfuse/core/jsonrpc/request.h index 73295e6..234ec62 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/request.h +++ b/lib/webfuse/core/jsonrpc/request.h @@ -12,8 +12,7 @@ using std::size_t; #endif #include -#include -#include "wf/jsonrpc/send_fn.h" +#include "webfuse/core/jsonrpc/send_fn.h" #ifdef __cplusplus extern "C" @@ -22,26 +21,26 @@ extern "C" struct wf_jsonrpc_request; -extern WF_JSONRPC_API bool wf_jsonrpc_is_request( +extern bool wf_jsonrpc_is_request( json_t * message); -extern WF_JSONRPC_API struct wf_jsonrpc_request * +extern struct wf_jsonrpc_request * wf_jsonrpc_request_create( int id, wf_jsonrpc_send_fn * send, void * user_data); -extern WF_JSONRPC_API void wf_jsonrpc_request_dispose( +extern void wf_jsonrpc_request_dispose( 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); -extern WF_JSONRPC_API void wf_jsonrpc_respond( +extern void wf_jsonrpc_respond( struct wf_jsonrpc_request * request, json_t * result); -extern WF_JSONRPC_API void wf_jsonrpc_respond_error( +extern void wf_jsonrpc_respond_error( struct wf_jsonrpc_request * request, int code, char const * message); diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c b/lib/webfuse/core/jsonrpc/response.c similarity index 73% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c rename to lib/webfuse/core/jsonrpc/response.c index f9fe180..69f7033 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.c +++ b/lib/webfuse/core/jsonrpc/response.c @@ -1,9 +1,9 @@ -#include "wf/jsonrpc/impl/response.h" -#include "wf/jsonrpc/impl/error.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/response_intern.h" +#include "webfuse/core/jsonrpc/error.h" +#include "webfuse/core/status.h" bool -wf_jsonrpc_impl_is_response( +wf_jsonrpc_is_response( json_t * message) { json_t * id = json_object_get(message, "id"); @@ -16,7 +16,7 @@ wf_jsonrpc_impl_is_response( void -wf_jsonrpc_impl_response_init( +wf_jsonrpc_response_init( struct wf_jsonrpc_response * result, json_t * response) { @@ -27,7 +27,7 @@ wf_jsonrpc_impl_response_init( json_t * id_holder = json_object_get(response, "id"); 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; } @@ -47,13 +47,13 @@ wf_jsonrpc_impl_response_init( } 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 -wf_jsonrpc_impl_response_cleanup( +wf_jsonrpc_response_cleanup( struct wf_jsonrpc_response * response) { if (NULL != response->result) diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/response.h b/lib/webfuse/core/jsonrpc/response.h similarity index 74% rename from lib/wf/jsonrpc/include/wf/jsonrpc/response.h rename to lib/webfuse/core/jsonrpc/response.h index abe2011..0bf0561 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/response.h +++ b/lib/webfuse/core/jsonrpc/response.h @@ -6,14 +6,13 @@ #endif #include -#include #ifdef __cplusplus extern "C" { #endif -extern WF_JSONRPC_API bool wf_jsonrpc_is_response( +extern bool wf_jsonrpc_is_response( json_t * message); #ifdef __cplusplus diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h b/lib/webfuse/core/jsonrpc/response_intern.h similarity index 57% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h rename to lib/webfuse/core/jsonrpc/response_intern.h index 3e1e02e..137a615 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/response.h +++ b/lib/webfuse/core/jsonrpc/response_intern.h @@ -1,16 +1,15 @@ -#ifndef WF_JSONRPC_IMPL_RESPONSE_H -#define WF_JSONRPC_IMPL_RESPONSE_H +#ifndef WF_JSONRPC_RESPONSE_INTERN_H +#define WF_JSONRPC_RESPONSE_INTERN_H + +#include "webfuse/core/jsonrpc/response.h" #ifndef __cplusplus -#include #include #else #include using std::size_t; #endif -#include - #ifdef __cplusplus extern "C" { #endif @@ -22,14 +21,11 @@ struct wf_jsonrpc_response int id; }; -extern bool wf_jsonrpc_impl_is_response( - json_t * message); - -extern void wf_jsonrpc_impl_response_init( +extern void wf_jsonrpc_response_init( struct wf_jsonrpc_response * response, json_t * message); -extern void wf_jsonrpc_impl_response_cleanup( +extern void wf_jsonrpc_response_cleanup( struct wf_jsonrpc_response * response); #ifdef __cplusplus diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h b/lib/webfuse/core/jsonrpc/send_fn.h similarity index 90% rename from lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h rename to lib/webfuse/core/jsonrpc/send_fn.h index 9ea9ef4..2892687 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/send_fn.h +++ b/lib/webfuse/core/jsonrpc/send_fn.h @@ -6,7 +6,6 @@ #endif #include -#include #ifdef __cplusplus extern "C" diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c b/lib/webfuse/core/jsonrpc/server.c similarity index 59% rename from lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c rename to lib/webfuse/core/jsonrpc/server.c index b3e27c8..03e30ae 100644 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.c +++ b/lib/webfuse/core/jsonrpc/server.c @@ -1,8 +1,8 @@ -#include "wf/jsonrpc/impl/server.h" -#include "wf/jsonrpc/impl/method.h" -#include "wf/jsonrpc/impl/request.h" -#include "wf/jsonrpc/impl/unused_param.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/method.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/status.h" +#include "webfuse/core/util.h" #include #include @@ -13,80 +13,79 @@ struct wf_jsonrpc_server }; static void -wf_jsonrpc_impl_server_init( +wf_jsonrpc_server_init( struct wf_jsonrpc_server * server); static void -wf_jsonrpc_impl_server_cleanup( +wf_jsonrpc_server_cleanup( struct wf_jsonrpc_server * 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)); - wf_jsonrpc_impl_server_init(server); + wf_jsonrpc_server_init(server); return server; } void -wf_jsonrpc_impl_server_dispose( +wf_jsonrpc_server_dispose( struct wf_jsonrpc_server * server) { - wf_jsonrpc_impl_server_cleanup(server); + wf_jsonrpc_server_cleanup(server); free(server); } - -static void wf_jsonrpc_impl_server_init( +static void wf_jsonrpc_server_init( struct wf_jsonrpc_server * server) { server->methods = NULL; } -static void wf_jsonrpc_impl_server_cleanup( +static void wf_jsonrpc_server_cleanup( struct wf_jsonrpc_server * server) { struct wf_jsonrpc_method * current = server->methods; while (NULL != current) { struct wf_jsonrpc_method * next = current->next; - wf_jsonrpc_impl_method_dispose(current); + wf_jsonrpc_method_dispose(current); current = next; } server->methods = NULL; } -void wf_jsonrpc_impl_server_add( +void wf_jsonrpc_server_add( struct wf_jsonrpc_server * server, char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, 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; 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, - char const * WF_JSONRPC_UNUSED_PARAM(method_name), - json_t * WF_JSONRPC_UNUSED_PARAM(params), - void * WF_JSONRPC_UNUSED_PARAM(user_data)) + char const * WF_UNUSED_PARAM(method_name), + json_t * WF_UNUSED_PARAM(params), + 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, .name = "", - .invoke = &wf_jsonrpc_impl_server_invalid_method_invoke, + .invoke = &wf_jsonrpc_server_invalid_method_invoke, .user_data = NULL }; static struct wf_jsonrpc_method const * -wf_jsonrpc_impl_server_get_method( +wf_jsonrpc_server_get_method( struct wf_jsonrpc_server * server, char const * method_name) { @@ -101,10 +100,10 @@ wf_jsonrpc_impl_server_get_method( 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, json_t * request_data, wf_jsonrpc_send_fn * send, @@ -120,8 +119,8 @@ void wf_jsonrpc_impl_server_process( { char const * method_name = json_string_value(method_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_method const * method = wf_jsonrpc_impl_server_get_method(server, method_name); + struct wf_jsonrpc_request * request = wf_jsonrpc_request_create(id, send, user_data); + struct wf_jsonrpc_method const * method = wf_jsonrpc_server_get_method(server, method_name); method->invoke(request, method_name, params, method->user_data); } diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/server.h b/lib/webfuse/core/jsonrpc/server.h similarity index 69% rename from lib/wf/jsonrpc/include/wf/jsonrpc/server.h rename to lib/webfuse/core/jsonrpc/server.h index c4850a5..143f121 100644 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/server.h +++ b/lib/webfuse/core/jsonrpc/server.h @@ -9,9 +9,8 @@ #endif #include -#include -#include -#include +#include "webfuse/core/jsonrpc/method_invoke_fn.h" +#include "webfuse/core/jsonrpc/send_fn.h" #ifdef __cplusplus extern "C" @@ -20,20 +19,20 @@ extern "C" struct wf_jsonrpc_server; -extern WF_JSONRPC_API struct wf_jsonrpc_server * +extern struct wf_jsonrpc_server * wf_jsonrpc_server_create(void); -extern WF_JSONRPC_API void +extern void wf_jsonrpc_server_dispose( 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, char const * method_name, wf_jsonrpc_method_invoke_fn * invoke, void * user_data); -extern WF_JSONRPC_API void wf_jsonrpc_server_process( +extern void wf_jsonrpc_server_process( struct wf_jsonrpc_server * server, json_t * request, wf_jsonrpc_send_fn * send, diff --git a/lib/wf/timer/src/wf/timer/impl/manager.c b/lib/webfuse/core/timer/manager.c similarity index 73% rename from lib/wf/timer/src/wf/timer/impl/manager.c rename to lib/webfuse/core/timer/manager.c index f198502..99540e9 100644 --- a/lib/wf/timer/src/wf/timer/impl/manager.c +++ b/lib/webfuse/core/timer/manager.c @@ -1,6 +1,6 @@ -#include "wf/timer/impl/manager.h" -#include "wf/timer/impl/timer.h" -#include "wf/timer/impl/timepoint.h" +#include "webfuse/core/timer/manager_intern.h" +#include "webfuse/core/timer/timer_intern.h" +#include "webfuse/core/timer/timepoint.h" #include #include @@ -11,7 +11,7 @@ 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)); manager->timers = NULL; @@ -20,7 +20,7 @@ wf_timer_impl_manager_create(void) } void -wf_timer_impl_manager_dispose( +wf_timer_manager_dispose( struct wf_timer_manager * manager) { struct wf_timer * timer = manager->timers; @@ -28,7 +28,7 @@ wf_timer_impl_manager_dispose( { struct wf_timer * next = timer->next; - wf_timer_impl_trigger(timer); + wf_timer_trigger(timer); 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 * timer = manager->timers; @@ -44,17 +44,17 @@ void wf_timer_impl_manager_check( { 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_impl_trigger(timer); + wf_timer_manager_removetimer(manager, timer); + wf_timer_trigger(timer); } timer = next; } } -void wf_timer_impl_manager_addtimer( +void wf_timer_manager_addtimer( struct wf_timer_manager * manager, struct wf_timer * timer) { @@ -68,7 +68,7 @@ void wf_timer_impl_manager_addtimer( manager->timers = timer; } -void wf_timer_impl_manager_removetimer( +void wf_timer_manager_removetimer( struct wf_timer_manager * manager, struct wf_timer * timer) { diff --git a/lib/wf/timer/include/wf/timer/manager.h b/lib/webfuse/core/timer/manager.h similarity index 72% rename from lib/wf/timer/include/wf/timer/manager.h rename to lib/webfuse/core/timer/manager.h index e0febc0..870a2d0 100644 --- a/lib/wf/timer/include/wf/timer/manager.h +++ b/lib/webfuse/core/timer/manager.h @@ -1,8 +1,6 @@ #ifndef WF_TIMER_MANAGER_H #define WF_TIMER_MANAGER_H -#include - #ifdef __cplusplus extern "C" { @@ -10,14 +8,14 @@ extern "C" struct wf_timer_manager; -extern WF_TIMER_API struct wf_timer_manager * +extern struct wf_timer_manager * wf_timer_manager_create(void); -extern WF_TIMER_API void +extern void wf_timer_manager_dispose( struct wf_timer_manager * manager); -extern WF_TIMER_API void +extern void wf_timer_manager_check( struct wf_timer_manager * manager); diff --git a/lib/webfuse/core/timer/manager_intern.h b/lib/webfuse/core/timer/manager_intern.h new file mode 100644 index 0000000..473df2b --- /dev/null +++ b/lib/webfuse/core/timer/manager_intern.h @@ -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 diff --git a/lib/wf/timer/include/wf/timer/on_timer_fn.h b/lib/webfuse/core/timer/on_timer_fn.h similarity index 100% rename from lib/wf/timer/include/wf/timer/on_timer_fn.h rename to lib/webfuse/core/timer/on_timer_fn.h diff --git a/lib/wf/timer/src/wf/timer/impl/timepoint.c b/lib/webfuse/core/timer/timepoint.c similarity index 59% rename from lib/wf/timer/src/wf/timer/impl/timepoint.c rename to lib/webfuse/core/timer/timepoint.c index 877b9c9..09fc025 100644 --- a/lib/wf/timer/src/wf/timer/impl/timepoint.c +++ b/lib/webfuse/core/timer/timepoint.c @@ -1,11 +1,11 @@ -#include "wf/timer/impl/timepoint.h" +#include "webfuse/core/timer/timepoint.h" #include #define WF_TIMER_MSEC_PER_SEC ((wf_timer_timepoint) 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; clock_gettime(CLOCK_MONOTONIC, &tp); @@ -14,17 +14,17 @@ wf_timer_timepoint wf_timer_impl_timepoint_now(void) 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); 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); return (0 > diff); diff --git a/lib/wf/timer/src/wf/timer/impl/timepoint.h b/lib/webfuse/core/timer/timepoint.h similarity index 57% rename from lib/wf/timer/src/wf/timer/impl/timepoint.h rename to lib/webfuse/core/timer/timepoint.h index 584aa92..cb78197 100644 --- a/lib/wf/timer/src/wf/timer/impl/timepoint.h +++ b/lib/webfuse/core/timer/timepoint.h @@ -1,5 +1,5 @@ -#ifndef WF_TIMER_IMPL_TIMEPOINT_H -#define WF_TIMER_IMPL_TIMEPOINT_H +#ifndef WF_TIMER_TIMEPOINT_H +#define WF_TIMER_TIMEPOINT_H #ifndef __cplusplus #include @@ -16,12 +16,12 @@ extern "C" typedef uint64_t wf_timer_timepoint; 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); -extern bool wf_timer_impl_timepoint_is_elapsed( +extern bool wf_timer_timepoint_is_elapsed( wf_timer_timepoint timepoint); #ifdef __cplusplus diff --git a/lib/wf/timer/src/wf/timer/impl/timer.c b/lib/webfuse/core/timer/timer.c similarity index 61% rename from lib/wf/timer/src/wf/timer/impl/timer.c rename to lib/webfuse/core/timer/timer.c index 5559451..1f4d650 100644 --- a/lib/wf/timer/src/wf/timer/impl/timer.c +++ b/lib/webfuse/core/timer/timer.c @@ -1,13 +1,13 @@ -#include "wf/timer/impl/timer.h" -#include "wf/timer/impl/manager.h" -#include "wf/timer/impl/timepoint.h" +#include "webfuse/core/timer/timer_intern.h" +#include "webfuse/core/timer/manager_intern.h" +#include "webfuse/core/timer/timepoint.h" #include #include #include struct wf_timer * -wf_timer_impl_create( +wf_timer_create( struct wf_timer_manager * manager, wf_timer_on_timer_fn * on_timer, void * user_data) @@ -24,37 +24,37 @@ wf_timer_impl_create( } void -wf_timer_impl_dispose( +wf_timer_dispose( struct wf_timer * timer) { free(timer); } -void wf_timer_impl_start( +void wf_timer_start( struct wf_timer * timer, 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) { - wf_timer_impl_manager_removetimer(timer->manager, timer); + wf_timer_manager_removetimer(timer->manager, timer); timer->timeout = 0; } -bool wf_timer_impl_is_timeout( +bool wf_timer_is_timeout( 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) { if (0 != timer->on_timer) diff --git a/lib/wf/timer/include/wf/timer/timer.h b/lib/webfuse/core/timer/timer.h similarity index 72% rename from lib/wf/timer/include/wf/timer/timer.h rename to lib/webfuse/core/timer/timer.h index 686eb89..48149bd 100644 --- a/lib/wf/timer/include/wf/timer/timer.h +++ b/lib/webfuse/core/timer/timer.h @@ -1,8 +1,7 @@ #ifndef WF_TIMER_TIMER_H #define WF_TIMER_TIMER_H -#include -#include +#include "webfuse/core/timer/on_timer_fn.h" #ifdef __cplusplus extern "C" @@ -12,22 +11,22 @@ extern "C" struct wf_timer; struct wf_timer_manager; -extern WF_TIMER_API struct wf_timer * +extern struct wf_timer * wf_timer_create( struct wf_timer_manager * manager, wf_timer_on_timer_fn * on_timer, void * user_data); -extern WF_TIMER_API void +extern void wf_timer_dispose( struct wf_timer * timer); -extern WF_TIMER_API void +extern void wf_timer_start( struct wf_timer * timer, int timeout_ms); -extern WF_TIMER_API void +extern void wf_timer_cancel( struct wf_timer * timer); diff --git a/lib/webfuse/core/timer/timer_intern.h b/lib/webfuse/core/timer/timer_intern.h new file mode 100644 index 0000000..c910a3b --- /dev/null +++ b/lib/webfuse/core/timer/timer_intern.h @@ -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 +#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 diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index 4e2b176..a85514a 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -16,11 +16,11 @@ #include "webfuse/provider/impl/url.h" #include "webfuse/core/protocol_names.h" -#include "wf/timer/manager.h" +#include "webfuse/core/timer/manager.h" -#include "wf/jsonrpc/response.h" -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/proxy.h" +#include "webfuse/core/jsonrpc/response.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/proxy.h" #define WF_DEFAULT_TIMEOUT (10 * 1000) diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc.h b/lib/wf/jsonrpc/include/wf/jsonrpc.h deleted file mode 100644 index ab7f1dc..0000000 --- a/lib/wf/jsonrpc/include/wf/jsonrpc.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef WF_JSONRPC_H -#define WF_JSONRPC_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#endif diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/api.h b/lib/wf/jsonrpc/include/wf/jsonrpc/api.h deleted file mode 100644 index 648bf0f..0000000 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/api.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WF_JSONRPC_API_H -#define WF_JSONRPC_API_H - -#ifndef WF_JSONRPC_API -#define WF_JSONRPC_API -#endif - -#endif diff --git a/lib/wf/jsonrpc/include/wf/jsonrpc/status.h b/lib/wf/jsonrpc/include/wf/jsonrpc/status.h deleted file mode 100644 index 85da73d..0000000 --- a/lib/wf/jsonrpc/include/wf/jsonrpc/status.h +++ /dev/null @@ -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 diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/api.c b/lib/wf/jsonrpc/src/wf/jsonrpc/api.c deleted file mode 100644 index 891bcce..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/api.c +++ /dev/null @@ -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); -} diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h deleted file mode 100644 index 60d2f7a..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/proxy.h +++ /dev/null @@ -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 diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h deleted file mode 100644 index 0d510e9..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/request.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef WF_JSONRPC_IMPL_REQUEST_H -#define WF_JSONRPC_IMPL_REQUEST_H - -#ifndef __cplusplus -#include -#include -#include -#else -#include -#include -using std::size_t; -#endif - -#include -#include -#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 diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h deleted file mode 100644 index 82c7421..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/server.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef WF_JSONRPC_IMPL_SERVER_H -#define WF_JSONRPC_IMPL_SERVER_H - -#include -#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 diff --git a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h b/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h deleted file mode 100644 index 41323c8..0000000 --- a/lib/wf/jsonrpc/src/wf/jsonrpc/impl/unused_param.h +++ /dev/null @@ -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 diff --git a/lib/wf/timer/include/wf/timer.h b/lib/wf/timer/include/wf/timer.h deleted file mode 100644 index 341792b..0000000 --- a/lib/wf/timer/include/wf/timer.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef WF_TIMER_H -#define WF_TIMER_H - -#include -#include -#include -#include - -#endif diff --git a/lib/wf/timer/include/wf/timer/api.h b/lib/wf/timer/include/wf/timer/api.h deleted file mode 100644 index c327ba7..0000000 --- a/lib/wf/timer/include/wf/timer/api.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef WF_TIMER_API_H -#define WF_TIMER_API_H - -#ifndef WF_TIMER_API -#define WF_TIMER_API -#endif - -#endif diff --git a/lib/wf/timer/src/wf/timer/api.c b/lib/wf/timer/src/wf/timer/api.c deleted file mode 100644 index d0399a9..0000000 --- a/lib/wf/timer/src/wf/timer/api.c +++ /dev/null @@ -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); -} diff --git a/lib/wf/timer/src/wf/timer/impl/manager.h b/lib/wf/timer/src/wf/timer/impl/manager.h deleted file mode 100644 index c4fc64a..0000000 --- a/lib/wf/timer/src/wf/timer/impl/manager.h +++ /dev/null @@ -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 diff --git a/lib/wf/timer/src/wf/timer/impl/timer.h b/lib/wf/timer/src/wf/timer/impl/timer.h deleted file mode 100644 index 2e18a8b..0000000 --- a/lib/wf/timer/src/wf/timer/impl/timer.h +++ /dev/null @@ -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 -#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 diff --git a/lib/wf/timer/test/wf/timer/test_timepoint.cc b/lib/wf/timer/test/wf/timer/test_timepoint.cc deleted file mode 100644 index 723ff6a..0000000 --- a/lib/wf/timer/test/wf/timer/test_timepoint.cc +++ /dev/null @@ -1,38 +0,0 @@ -#include - -#include "wf/timer/impl/timepoint.h" - -#include -#include - -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)); -} diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc b/test/webfuse/tests/core/jsonrpc/mock_timer.cc similarity index 90% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc rename to test/webfuse/tests/core/jsonrpc/mock_timer.cc index bdfde2b..3cf8e74 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.cc +++ b/test/webfuse/tests/core/jsonrpc/mock_timer.cc @@ -1,5 +1,5 @@ -#include "wf/jsonrpc/mock_timer.hpp" -#include "wf/jsonrpc/wrap.hpp" +#include "webfuse/tests/core/jsonrpc/mock_timer.hpp" +#include "webfuse/utils/wrap.hpp" extern "C" { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp b/test/webfuse/tests/core/jsonrpc/mock_timer.hpp similarity index 94% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp rename to test/webfuse/tests/core/jsonrpc/mock_timer.hpp index 3fde45e..5c95852 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer.hpp +++ b/test/webfuse/tests/core/jsonrpc/mock_timer.hpp @@ -1,7 +1,8 @@ #ifndef WF_JSONRPC_MOCK_TIMERMANAGER_HPP #define WF_JSONRPC_MOCK_TIMERMANAGER_HPP -#include +#include "webfuse/core/timer/timer.h" +#include "webfuse/core/timer/manager.h" #include namespace wf_jsonrpc_test diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc similarity index 90% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc rename to test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc index dd3cc3b..7e62c31 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.cc +++ b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.cc @@ -1,4 +1,4 @@ -#include "wf/jsonrpc/mock_timer_callback.hpp" +#include "webfuse/tests/core/jsonrpc/mock_timer_callback.hpp" extern "C" { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.hpp similarity index 89% rename from lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp rename to test/webfuse/tests/core/jsonrpc/mock_timer_callback.hpp index cdbf2d6..e55b7e1 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/mock_timer_callback.hpp +++ b/test/webfuse/tests/core/jsonrpc/mock_timer_callback.hpp @@ -1,7 +1,7 @@ #ifndef WF_JSONRPC_MOCK_TIMERCALLBACK_HPP #define WF_JSONRPC_MOCK_TIMERCALLBACK_HPP -#include "wf/timer.h" +#include "webfuse/core/timer/on_timer_fn.h" #include namespace wf_jsonrpc_test diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc b/test/webfuse/tests/core/jsonrpc/test_is_request.cc similarity index 98% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc rename to test/webfuse/tests/core/jsonrpc/test_is_request.cc index 55e40c6..4599611 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_request.cc +++ b/test/webfuse/tests/core/jsonrpc/test_is_request.cc @@ -1,5 +1,5 @@ #include -#include "wf/jsonrpc/request.h" +#include "webfuse/core/jsonrpc/request.h" TEST(wf_jsonrpc_is_request, request_with_object_params) { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc b/test/webfuse/tests/core/jsonrpc/test_is_response.cc similarity index 98% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc rename to test/webfuse/tests/core/jsonrpc/test_is_response.cc index 690bb6c..908ddf0 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_is_response.cc +++ b/test/webfuse/tests/core/jsonrpc/test_is_response.cc @@ -1,5 +1,5 @@ #include -#include "wf/jsonrpc/response.h" +#include "webfuse/core/jsonrpc/response.h" TEST(wf_jsonrpc_is_response, valid_result) { diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc b/test/webfuse/tests/core/jsonrpc/test_proxy.cc similarity index 97% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc rename to test/webfuse/tests/core/jsonrpc/test_proxy.cc index 763fa51..bdc8a15 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_proxy.cc +++ b/test/webfuse/tests/core/jsonrpc/test_proxy.cc @@ -1,9 +1,9 @@ #include -#include "wf/jsonrpc/proxy.h" -#include "wf/jsonrpc/status.h" -#include "wf/timer/manager.h" +#include "webfuse/core/jsonrpc/proxy.h" +#include "webfuse/core/status.h" +#include "webfuse/core/timer/manager.h" -#include "wf/jsonrpc/mock_timer.hpp" +#include "webfuse/tests/core/jsonrpc/mock_timer.hpp" #include #include @@ -22,7 +22,7 @@ namespace int jsonrpc_get_status(json_t * error) { 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 @@ -196,7 +196,7 @@ TEST(wf_jsonrpc_proxy, invoke_fails_if_another_request_is_pending) ASSERT_FALSE(finished_context.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_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_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_timer_manager_dispose(timer_manager); @@ -307,7 +307,7 @@ TEST(wf_jsonrpc_proxy, timeout) wf_timer_manager_check(timer_manager); 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_timer_manager_dispose(timer_manager); diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc b/test/webfuse/tests/core/jsonrpc/test_request.cc similarity index 95% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc rename to test/webfuse/tests/core/jsonrpc/test_request.cc index a8f7986..8d37a9f 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_request.cc +++ b/test/webfuse/tests/core/jsonrpc/test_request.cc @@ -1,6 +1,6 @@ #include -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/status.h" namespace { @@ -74,7 +74,7 @@ TEST(wf_jsonrpc_request, respond_error) struct wf_jsonrpc_request * request = 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); @@ -93,7 +93,7 @@ TEST(wf_jsonrpc_request, respond_error) json_t * err_code = json_object_get(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"); ASSERT_TRUE(json_is_string(err_message)); diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc b/test/webfuse/tests/core/jsonrpc/test_response.cc similarity index 69% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc rename to test/webfuse/tests/core/jsonrpc/test_response.cc index b71d7f3..f6ef9e7 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response.cc +++ b/test/webfuse/tests/core/jsonrpc/test_response.cc @@ -1,6 +1,6 @@ #include -#include "wf/jsonrpc/impl/response.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/response_intern.h" +#include "webfuse/core/status.h" 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)); struct wf_jsonrpc_response response; - wf_jsonrpc_impl_response_init(&response, message); + wf_jsonrpc_response_init(&response, message); ASSERT_EQ(nullptr, response.error); ASSERT_TRUE(json_is_integer(response.result)); ASSERT_EQ(47, json_integer_value(response.result)); ASSERT_EQ(11, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -30,14 +30,14 @@ TEST(wf_json_response, init_error) json_object_set_new(message, "id", json_integer(23)); 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_STREQ("Don't Panic!", json_string_value(json_object_get(response.error, "message"))); ASSERT_EQ(nullptr, response.result); ASSERT_EQ(23, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); 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)); 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(12, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } @@ -63,13 +63,13 @@ TEST(wf_json_response, init_fail_missing_id) json_object_set_new(message, "result", json_integer(47)); 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(-1, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); 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")); 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(-1, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); 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)); 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(23, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); 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)); 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(23, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); 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)); 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(23, response.id); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); json_decref(message); } diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc b/test/webfuse/tests/core/jsonrpc/test_response_parser.cc similarity index 80% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc rename to test/webfuse/tests/core/jsonrpc/test_response_parser.cc index e3301fa..f9941c1 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_response_parser.cc +++ b/test/webfuse/tests/core/jsonrpc/test_response_parser.cc @@ -1,7 +1,7 @@ #include #include -#include "wf/jsonrpc/impl/response.h" +#include "webfuse/core/jsonrpc/response_intern.h" 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); if (nullptr != message) { - wf_jsonrpc_impl_response_init(response, message); + wf_jsonrpc_response_init(response, message); json_decref(message); } } @@ -25,21 +25,21 @@ TEST(response_parser, test) ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // empty response_parse_str("{}", &response); ASSERT_NE(nullptr, response.error); ASSERT_EQ(-1, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // no data response_parse_str("{\"id\":42}", &response); ASSERT_NE(nullptr, response.error); ASSERT_EQ(42, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // custom error code 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, response.id); ASSERT_EQ(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); // valid response response_parse_str("{\"result\": true, \"id\": 42}", &response); ASSERT_EQ(nullptr, response.error); ASSERT_EQ(42, response.id); ASSERT_NE(nullptr, response.result); - wf_jsonrpc_impl_response_cleanup(&response); + wf_jsonrpc_response_cleanup(&response); } diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc b/test/webfuse/tests/core/jsonrpc/test_server.cc similarity index 97% rename from lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc rename to test/webfuse/tests/core/jsonrpc/test_server.cc index 894c607..688028f 100644 --- a/lib/wf/jsonrpc/test/wf/jsonrpc/test_server.cc +++ b/test/webfuse/tests/core/jsonrpc/test_server.cc @@ -1,7 +1,7 @@ #include -#include "wf/jsonrpc/server.h" -#include "wf/jsonrpc/request.h" -#include "wf/jsonrpc/status.h" +#include "webfuse/core/jsonrpc/server.h" +#include "webfuse/core/jsonrpc/request.h" +#include "webfuse/core/status.h" namespace { @@ -125,7 +125,7 @@ TEST(wf_jsonrpc_server, invoke_unknown_method) json_t * err_code = json_object_get(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"); ASSERT_TRUE(json_is_string(err_message)); diff --git a/test/webfuse/tests/core/timer/test_timepoint.cc b/test/webfuse/tests/core/timer/test_timepoint.cc new file mode 100644 index 0000000..f55adab --- /dev/null +++ b/test/webfuse/tests/core/timer/test_timepoint.cc @@ -0,0 +1,38 @@ +#include + +#include "webfuse/core/timer/timepoint.h" + +#include +#include + +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)); +} diff --git a/lib/wf/timer/test/wf/timer/test_timer.cc b/test/webfuse/tests/core/timer/test_timer.cc similarity index 97% rename from lib/wf/timer/test/wf/timer/test_timer.cc rename to test/webfuse/tests/core/timer/test_timer.cc index 2141314..d25b1f5 100644 --- a/lib/wf/timer/test/wf/timer/test_timer.cc +++ b/test/webfuse/tests/core/timer/test_timer.cc @@ -4,8 +4,8 @@ #include #include -#include "wf/timer/timer.h" -#include "wf/timer/manager.h" +#include "webfuse/core/timer/timer.h" +#include "webfuse/core/timer/manager.h" using std::size_t; using namespace std::chrono_literals; diff --git a/lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp b/test/webfuse/utils/wrap.hpp similarity index 100% rename from lib/wf/jsonrpc/test/wf/jsonrpc/wrap.hpp rename to test/webfuse/utils/wrap.hpp