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

Merge pull request #63 from falk-werner/resolve_todos

Resolve ToDos
This commit is contained in:
Falk Werner 2020-04-07 21:17:52 +02:00 committed by GitHub
commit 70d953be53
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 66 additions and 89 deletions

View File

@ -45,14 +45,6 @@ typedef void wfp_connected_fn(
typedef void wfp_disconnected_fn( typedef void wfp_disconnected_fn(
void * user_data); void * user_data);
//------------------------------------------------------------------------------
/// \brief Callback to signal when a timer event occued.
///
/// \param user_data user defined context
//------------------------------------------------------------------------------
typedef void wfp_ontimer_fn(
void * user_data);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/// \brief Creates a new client configuration. /// \brief Creates a new client configuration.
/// ///
@ -145,18 +137,6 @@ extern WFP_API void wfp_client_config_set_ondisconnected(
struct wfp_client_config * config, struct wfp_client_config * config,
wfp_disconnected_fn * handler); wfp_disconnected_fn * handler);
//------------------------------------------------------------------------------
/// \brief Sets ontimer handler.
///
/// The handler is invoked, when a timer event occured.
///
/// \param config pointer to client configuration
/// \param handler pointer to handler
//------------------------------------------------------------------------------
extern WFP_API void wfp_client_config_set_ontimer(
struct wfp_client_config * config,
wfp_ontimer_fn * handler);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
/// \brief Sets onlookup handler. /// \brief Sets onlookup handler.
/// ///

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

@ -130,9 +130,4 @@ void wf_impl_filesystem_process_request(
{ {
fuse_session_process_buf(filesystem->session, &filesystem->buffer); fuse_session_process_buf(filesystem->session, &filesystem->buffer);
} }
else if (-EINTR != result)
{
// ToDo
}
} }

View File

@ -20,15 +20,12 @@ wf_impl_mountpoint_factory_init(
} }
void void
wf_impl_mountpoint_factory_move( wf_impl_mountpoint_factory_clone(
struct wf_impl_mountpoint_factory * factory, struct wf_impl_mountpoint_factory * factory,
struct wf_impl_mountpoint_factory * other) struct wf_impl_mountpoint_factory * other)
{ {
other->create_mountpoint = factory->create_mountpoint; other->create_mountpoint = factory->create_mountpoint;
other->user_data = factory->user_data; other->user_data = factory->user_data;
factory->create_mountpoint = NULL;
factory->user_data = NULL;
} }
bool bool

View File

@ -26,7 +26,7 @@ wf_impl_mountpoint_factory_init(
void * user_data); void * user_data);
extern void extern void
wf_impl_mountpoint_factory_move( wf_impl_mountpoint_factory_clone(
struct wf_impl_mountpoint_factory * factory, struct wf_impl_mountpoint_factory * factory,
struct wf_impl_mountpoint_factory * other); struct wf_impl_mountpoint_factory * other);

View File

@ -48,9 +48,7 @@ void wf_impl_server_config_clone(
clone->port = config->port; clone->port = config->port;
wf_impl_authenticators_clone(&config->authenticators, &clone->authenticators); wf_impl_authenticators_clone(&config->authenticators, &clone->authenticators);
wf_impl_mountpoint_factory_clone(&config->mountpoint_factory, &clone->mountpoint_factory);
// ToDo: remove this: move is not clone :-/
wf_impl_mountpoint_factory_move(&config->mountpoint_factory, &clone->mountpoint_factory);
} }
struct wf_server_config * wf_impl_server_config_create(void) struct wf_server_config * wf_impl_server_config_create(void)

View File

@ -216,7 +216,7 @@ void wf_impl_server_protocol_init(
{ {
protocol->is_operational = false; protocol->is_operational = false;
wf_impl_mountpoint_factory_move(mountpoint_factory, &protocol->mountpoint_factory); wf_impl_mountpoint_factory_clone(mountpoint_factory, &protocol->mountpoint_factory);
protocol->timer_manager = wf_timer_manager_create(); protocol->timer_manager = wf_timer_manager_create();
wf_impl_session_manager_init(&protocol->session_manager); wf_impl_session_manager_init(&protocol->session_manager);

View File

@ -116,13 +116,6 @@ void wfp_client_config_set_ondisconnected(
wfp_impl_client_config_set_ondisconnected(config, handler); wfp_impl_client_config_set_ondisconnected(config, handler);
} }
void wfp_client_config_set_ontimer(
struct wfp_client_config * config,
wfp_ontimer_fn * handler)
{
wfp_impl_client_config_set_ontimer(config, handler);
}
void wfp_client_config_set_onlookup( void wfp_client_config_set_onlookup(
struct wfp_client_config * config, struct wfp_client_config * config,
wfp_lookup_fn * handler) wfp_lookup_fn * handler)
@ -202,6 +195,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

@ -69,13 +69,6 @@ void wfp_impl_client_config_set_ondisconnected(
config->provider.disconnected = handler; config->provider.disconnected = handler;
} }
void wfp_impl_client_config_set_ontimer(
struct wfp_client_config * config,
wfp_ontimer_fn * handler)
{
config->provider.ontimer = handler;
}
void wfp_impl_client_config_set_onlookup( void wfp_impl_client_config_set_onlookup(
struct wfp_client_config * config, struct wfp_client_config * config,
wfp_lookup_fn * handler) wfp_lookup_fn * handler)

View File

@ -47,10 +47,6 @@ extern void wfp_impl_client_config_set_ondisconnected(
struct wfp_client_config * config, struct wfp_client_config * config,
wfp_disconnected_fn * handler); wfp_disconnected_fn * handler);
extern void wfp_impl_client_config_set_ontimer(
struct wfp_client_config * config,
wfp_ontimer_fn * handler);
extern void wfp_impl_client_config_set_onlookup( extern void wfp_impl_client_config_set_onlookup(
struct wfp_client_config * config, struct wfp_client_config * config,
wfp_lookup_fn * handler); wfp_lookup_fn * handler);

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

@ -66,7 +66,6 @@ void wfp_impl_provider_init(
provider->read = &wfp_impl_read_default; provider->read = &wfp_impl_read_default;
provider->connected = &wfp_impl_connected_default; provider->connected = &wfp_impl_connected_default;
provider->disconnected = &wfp_impl_disconnected_default; provider->disconnected = &wfp_impl_disconnected_default;
provider->ontimer = &wfp_impl_ontimer_default;
provider->get_credentials = NULL; provider->get_credentials = NULL;
} }
@ -82,7 +81,6 @@ void wfp_impl_provider_init_from_prototype(
provider->read = prototype->read; provider->read = prototype->read;
provider->connected = prototype->connected; provider->connected = prototype->connected;
provider->disconnected = prototype->disconnected; provider->disconnected = prototype->disconnected;
provider->ontimer = prototype->ontimer;
provider->get_credentials = prototype->get_credentials; provider->get_credentials = prototype->get_credentials;
} }
@ -119,14 +117,6 @@ void wfp_impl_disconnected_default(
// empty // empty
} }
void wfp_impl_ontimer_default(
void * user_data)
{
(void) user_data;
// empty
}
bool wfp_impl_provider_is_authentication_enabled( bool wfp_impl_provider_is_authentication_enabled(
struct wfp_provider * provider) struct wfp_provider * provider)
{ {

View File

@ -18,7 +18,6 @@ struct wfp_provider
{ {
wfp_connected_fn * connected; wfp_connected_fn * connected;
wfp_disconnected_fn * disconnected; wfp_disconnected_fn * disconnected;
wfp_ontimer_fn * ontimer;
wfp_lookup_fn * lookup; wfp_lookup_fn * lookup;
wfp_getattr_fn * getattr; wfp_getattr_fn * getattr;
wfp_readdir_fn * readdir; wfp_readdir_fn * readdir;
@ -56,9 +55,6 @@ extern void wfp_impl_connected_default(
extern void wfp_impl_disconnected_default( extern void wfp_impl_disconnected_default(
void * user_data); void * user_data);
extern void wfp_impl_ontimer_default(
void * user_data);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -18,13 +18,6 @@ static void webfuse_test_MockProvider_disconnected(
provider->disconnected(); provider->disconnected();
} }
static void webfuse_test_MockProvider_on_timer(
void * user_data)
{
auto * provider = reinterpret_cast<MockProvider*>(user_data);
provider->on_timer();
}
static void webfuse_test_MockProvider_lookup( static void webfuse_test_MockProvider_lookup(
wfp_request * request, wfp_request * request,
ino_t parent, ino_t parent,
@ -100,7 +93,6 @@ static wfp_provider const webfuse_test_MockProvider =
{ {
&webfuse_test_MockProvider_connected, &webfuse_test_MockProvider_connected,
&webfuse_test_MockProvider_disconnected, &webfuse_test_MockProvider_disconnected,
&webfuse_test_MockProvider_on_timer,
&webfuse_test_MockProvider_lookup, &webfuse_test_MockProvider_lookup,
&webfuse_test_MockProvider_getattr, &webfuse_test_MockProvider_getattr,
&webfuse_test_MockProvider_readdir, &webfuse_test_MockProvider_readdir,

View File

@ -21,13 +21,6 @@ static void webfuse_test_iproviderclient_ondisconnected(
self->OnDisconnected(); self->OnDisconnected();
} }
static void webfuse_test_iproviderclient_ontimer(
void * user_data)
{
auto * self = reinterpret_cast<IProviderClient*>(user_data);
self->OnTimer();
}
static void webfuse_test_iproviderclient_onlookup( static void webfuse_test_iproviderclient_onlookup(
struct wfp_request * request, struct wfp_request * request,
ino_t parent, ino_t parent,
@ -207,7 +200,6 @@ void IProviderClient::AttachTo(wfp_client_config * config, bool enableAuthentica
wfp_client_config_set_userdata(config, self); wfp_client_config_set_userdata(config, self);
wfp_client_config_set_onconnected(config, &webfuse_test_iproviderclient_onconnected); wfp_client_config_set_onconnected(config, &webfuse_test_iproviderclient_onconnected);
wfp_client_config_set_ondisconnected(config, &webfuse_test_iproviderclient_ondisconnected); wfp_client_config_set_ondisconnected(config, &webfuse_test_iproviderclient_ondisconnected);
wfp_client_config_set_ontimer(config, &webfuse_test_iproviderclient_ontimer);
wfp_client_config_set_onlookup(config, &webfuse_test_iproviderclient_onlookup); wfp_client_config_set_onlookup(config, &webfuse_test_iproviderclient_onlookup);
wfp_client_config_set_ongetattr(config, &webfuse_test_iproviderclient_ongetattr); wfp_client_config_set_ongetattr(config, &webfuse_test_iproviderclient_ongetattr);

View File

@ -23,7 +23,6 @@ namespace webfuse_test
virtual ~IProviderClient() = default; virtual ~IProviderClient() = default;
virtual void OnConnected() = 0; virtual void OnConnected() = 0;
virtual void OnDisconnected() = 0; virtual void OnDisconnected() = 0;
virtual void OnTimer() = 0;
virtual void Lookup(ino_t parent, char const * name, struct stat * result) = 0; virtual void Lookup(ino_t parent, char const * name, struct stat * result) = 0;
virtual void GetAttr(ino_t inode, struct stat * buffer) = 0; virtual void GetAttr(ino_t inode, struct stat * buffer) = 0;
virtual void ReadDir(ino_t directory, wfp_dirbuffer * buffer) = 0; virtual void ReadDir(ino_t directory, wfp_dirbuffer * buffer) = 0;
@ -41,7 +40,6 @@ namespace webfuse_test
~MockProviderClient() override = default; ~MockProviderClient() override = default;
MOCK_METHOD0( OnConnected, void()); MOCK_METHOD0( OnConnected, void());
MOCK_METHOD0( OnDisconnected, void()); MOCK_METHOD0( OnDisconnected, void());
MOCK_METHOD0( OnTimer, void());
MOCK_METHOD3( Lookup, void(ino_t parent, char const * name, struct stat * result)); MOCK_METHOD3( Lookup, void(ino_t parent, char const * name, struct stat * result));
MOCK_METHOD2( GetAttr, void(ino_t inode, struct stat * buffer)); MOCK_METHOD2( GetAttr, void(ino_t inode, struct stat * buffer));
MOCK_METHOD2( ReadDir, void(ino_t directory, wfp_dirbuffer * buffer)); MOCK_METHOD2( ReadDir, void(ino_t directory, wfp_dirbuffer * buffer));

View File

@ -396,6 +396,7 @@ TEST(wf_jsonrpc_proxy, swallow_timeout_if_no_request_pending)
EXPECT_CALL(timer_api, wf_timer_create(_, _, _)) EXPECT_CALL(timer_api, wf_timer_create(_, _, _))
.Times(1) .Times(1)
.WillOnce(DoAll(SaveArg<1>(&on_timer), SaveArg<2>(&timer_context), Return(nullptr))); .WillOnce(DoAll(SaveArg<1>(&on_timer), SaveArg<2>(&timer_context), Return(nullptr)));
EXPECT_CALL(timer_api, wf_timer_dispose(_)).Times(1);
SendContext send_context; SendContext send_context;
void * send_data = reinterpret_cast<void*>(&send_context); void * send_data = reinterpret_cast<void*>(&send_context);

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