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

added implementation of wfp_client_disconnect

This commit is contained in:
Falk Werner 2020-04-07 20:37:50 +02:00
parent 36f2b82a67
commit 3eb5dc89a7
7 changed files with 61 additions and 5 deletions

View File

@ -89,12 +89,25 @@ extern WFP_API void wfp_client_protocol_init_lws(
/// \see wfp_connected_fn /// \see wfp_connected_fn
/// \see wfp_client_config_set_onconnected /// \see wfp_client_config_set_onconnected
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_protocol_connect( extern WFP_API void wfp_client_protocol_connect(
struct wfp_client_protocol * protocol, struct wfp_client_protocol * protocol,
struct lws_context * context, struct lws_context * context,
char const * url); 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -202,6 +202,12 @@ void wfp_client_protocol_connect(
wfp_impl_client_protocol_connect(protocol, context, url); 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 // client

View File

@ -79,9 +79,7 @@ void wfp_impl_client_connect(
void wfp_impl_client_disconnect( void wfp_impl_client_disconnect(
struct wfp_client * client) struct wfp_client * client)
{ {
(void) client; wfp_impl_client_protocol_disconnect(&client->protocol);
// ToDo: implement me
} }
bool wfp_impl_client_is_connected( bool wfp_impl_client_is_connected(

View File

@ -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);
}
}

View File

@ -53,6 +53,9 @@ extern void wfp_impl_client_protocol_connect(
struct lws_context * context, struct lws_context * context,
char const * url); char const * url);
extern void wfp_impl_client_protocol_disconnect(
struct wfp_client_protocol * protocol);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -67,6 +67,12 @@ private:
{ {
wfp_client_service(context->client); 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; std::mutex shutdown_lock;

View File

@ -52,6 +52,11 @@ public:
server->waitForConnection(); server->waitForConnection();
} }
void Disconnect()
{
wfp_client_protocol_disconnect(protocol);
}
void SendToClient(json_t * request) void SendToClient(json_t * request)
{ {
server->sendMessage(request); server->sendMessage(request);
@ -166,6 +171,16 @@ TEST(client_protocol, connect)
if (HasFatalFailure()) { return; } 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) TEST(client_protocol, connect_with_username_authentication)
{ {
MockProviderClient provider; MockProviderClient provider;
@ -184,7 +199,6 @@ TEST(client_protocol, connect_with_username_authentication)
std::string filesystem; std::string filesystem;
fixture.AwaitAddFilesystem(filesystem); fixture.AwaitAddFilesystem(filesystem);
if (HasFatalFailure()) { return; } if (HasFatalFailure()) { return; }
} }
TEST(client_protocol, getattr) TEST(client_protocol, getattr)
@ -216,4 +230,6 @@ TEST(client_protocol, getattr)
ASSERT_TRUE(json_is_object(response)); ASSERT_TRUE(json_is_object(response));
json_decref(response); json_decref(response);
fixture.Disconnect();
} }