From 3eb5dc89a79d219d70edaaf6c3f046ecf672778a Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Tue, 7 Apr 2020 20:37:50 +0200 Subject: [PATCH] added implementation of wfp_client_disconnect --- include/webfuse/provider/client_protocol.h | 15 ++++++++++++++- lib/webfuse/provider/api.c | 6 ++++++ lib/webfuse/provider/impl/client.c | 4 +--- lib/webfuse/provider/impl/client_protocol.c | 14 ++++++++++++++ lib/webfuse/provider/impl/client_protocol.h | 3 +++ test/webfuse/tests/integration/provider.cc | 6 ++++++ .../tests/provider/test_client_protocol.cc | 18 +++++++++++++++++- 7 files changed, 61 insertions(+), 5 deletions(-) diff --git a/include/webfuse/provider/client_protocol.h b/include/webfuse/provider/client_protocol.h index ab1ba85..8108030 100644 --- a/include/webfuse/provider/client_protocol.h +++ b/include/webfuse/provider/client_protocol.h @@ -89,12 +89,25 @@ extern WFP_API void wfp_client_protocol_init_lws( /// \see wfp_connected_fn /// \see wfp_client_config_set_onconnected //------------------------------------------------------------------------------ -//------------------------------------------------------------------------------ extern WFP_API void wfp_client_protocol_connect( struct wfp_client_protocol * protocol, struct lws_context * context, char const * url); +//------------------------------------------------------------------------------ +/// \brief Disconnects the protocol from a remote webfuse adapter server. +/// +/// \note This call starts to disconnect. A callback is invoked, +/// when the connection is estanlished. +/// +/// \param protocol pointer to protocol +/// +/// \see wfp_connected_fn +/// \see wfp_client_config_set_ondisconnected +//------------------------------------------------------------------------------ +extern WFP_API void wfp_client_protocol_disconnect( + struct wfp_client_protocol * protocol); + #ifdef __cplusplus } #endif diff --git a/lib/webfuse/provider/api.c b/lib/webfuse/provider/api.c index 0c5f164..0c916d2 100644 --- a/lib/webfuse/provider/api.c +++ b/lib/webfuse/provider/api.c @@ -202,6 +202,12 @@ void wfp_client_protocol_connect( wfp_impl_client_protocol_connect(protocol, context, url); } +void wfp_client_protocol_disconnect( + struct wfp_client_protocol * protocol) +{ + wfp_impl_client_protocol_disconnect(protocol); +} + // client diff --git a/lib/webfuse/provider/impl/client.c b/lib/webfuse/provider/impl/client.c index 9f45a5a..e7c6e81 100644 --- a/lib/webfuse/provider/impl/client.c +++ b/lib/webfuse/provider/impl/client.c @@ -79,9 +79,7 @@ void wfp_impl_client_connect( void wfp_impl_client_disconnect( struct wfp_client * client) { - (void) client; - - // ToDo: implement me + wfp_impl_client_protocol_disconnect(&client->protocol); } bool wfp_impl_client_is_connected( diff --git a/lib/webfuse/provider/impl/client_protocol.c b/lib/webfuse/provider/impl/client_protocol.c index a85514a..db78137 100644 --- a/lib/webfuse/provider/impl/client_protocol.c +++ b/lib/webfuse/provider/impl/client_protocol.c @@ -324,3 +324,17 @@ void wfp_impl_client_protocol_connect( } } + +void wfp_impl_client_protocol_disconnect( + struct wfp_client_protocol * protocol) +{ + if (protocol->is_connected) + { + protocol->is_shutdown_requested = true; + lws_callback_on_writable(protocol->wsi); + } + else + { + protocol->provider.disconnected(protocol->user_data); + } +} diff --git a/lib/webfuse/provider/impl/client_protocol.h b/lib/webfuse/provider/impl/client_protocol.h index af5c74b..d6dd8ab 100644 --- a/lib/webfuse/provider/impl/client_protocol.h +++ b/lib/webfuse/provider/impl/client_protocol.h @@ -53,6 +53,9 @@ extern void wfp_impl_client_protocol_connect( struct lws_context * context, char const * url); +extern void wfp_impl_client_protocol_disconnect( + struct wfp_client_protocol * protocol); + #ifdef __cplusplus } #endif diff --git a/test/webfuse/tests/integration/provider.cc b/test/webfuse/tests/integration/provider.cc index ada19b8..e813b4d 100644 --- a/test/webfuse/tests/integration/provider.cc +++ b/test/webfuse/tests/integration/provider.cc @@ -67,6 +67,12 @@ private: { wfp_client_service(context->client); } + + wfp_client_disconnect(context->client); + while (wfp_impl_client_is_connected(context->client)) + { + wfp_client_service(context->client); + } } std::mutex shutdown_lock; diff --git a/test/webfuse/tests/provider/test_client_protocol.cc b/test/webfuse/tests/provider/test_client_protocol.cc index 3563949..2035b0f 100644 --- a/test/webfuse/tests/provider/test_client_protocol.cc +++ b/test/webfuse/tests/provider/test_client_protocol.cc @@ -52,6 +52,11 @@ public: server->waitForConnection(); } + void Disconnect() + { + wfp_client_protocol_disconnect(protocol); + } + void SendToClient(json_t * request) { server->sendMessage(request); @@ -166,6 +171,16 @@ TEST(client_protocol, connect) if (HasFatalFailure()) { return; } } +TEST(client_protocol, disconnect_without_connect) +{ + MockProviderClient provider; + ClientProtocolFixture fixture(provider); + + EXPECT_CALL(provider, OnDisconnected()).Times(1); + + fixture.Disconnect(); +} + TEST(client_protocol, connect_with_username_authentication) { MockProviderClient provider; @@ -184,7 +199,6 @@ TEST(client_protocol, connect_with_username_authentication) std::string filesystem; fixture.AwaitAddFilesystem(filesystem); if (HasFatalFailure()) { return; } - } TEST(client_protocol, getattr) @@ -216,4 +230,6 @@ TEST(client_protocol, getattr) ASSERT_TRUE(json_is_object(response)); json_decref(response); + + fixture.Disconnect(); } \ No newline at end of file