mirror of
https://github.com/falk-werner/webfuse-provider
synced 2024-10-27 20:44:10 +00:00
refactor: removed unused return value for send_fn
This commit is contained in:
parent
c066090df2
commit
fe3e80ed0a
@ -215,7 +215,7 @@ static int wfp_impl_client_protocol_callback(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool wfp_impl_client_protocol_send(
|
static void wfp_impl_client_protocol_send(
|
||||||
json_t * request,
|
json_t * request,
|
||||||
void * user_data)
|
void * user_data)
|
||||||
{
|
{
|
||||||
@ -234,7 +234,7 @@ static bool wfp_impl_client_protocol_send(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return true;
|
// return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wfp_impl_client_protocol_init(
|
void wfp_impl_client_protocol_init(
|
||||||
|
@ -82,9 +82,7 @@ static json_t * wfp_jsonrpc_request_create(
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "fatal: unknown param_type '%c'\n", *param_type);
|
fprintf(stderr, "fatal: unknown param_type '%c'\n", *param_type);
|
||||||
json_decref(params);
|
break;
|
||||||
json_decref(request);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,23 +148,8 @@ void wfp_jsonrpc_proxy_vinvoke(
|
|||||||
wfp_timer_start(proxy->request.timer, proxy->timeout);
|
wfp_timer_start(proxy->request.timer, proxy->timeout);
|
||||||
|
|
||||||
json_t * request = wfp_jsonrpc_request_create(method_name, proxy->request.id, param_info, args);
|
json_t * request = wfp_jsonrpc_request_create(method_name, proxy->request.id, param_info, args);
|
||||||
|
proxy->send(request, proxy->user_data);
|
||||||
bool const is_send = ((NULL != request) && (proxy->send(request, proxy->user_data)));
|
json_decref(request);
|
||||||
if (!is_send)
|
|
||||||
{
|
|
||||||
proxy->request.is_pending = false;
|
|
||||||
proxy->request.finished = NULL;
|
|
||||||
proxy->request.user_data = NULL;
|
|
||||||
proxy->request.id = 0;
|
|
||||||
wfp_timer_cancel(proxy->request.timer);
|
|
||||||
|
|
||||||
wfp_jsonrpc_propate_error(finished, user_data, WFP_BAD, "Bad: requenst is not sent");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (NULL != request)
|
|
||||||
{
|
|
||||||
json_decref(request);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -12,7 +12,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef bool wfp_jsonrpc_send_fn(
|
typedef void wfp_jsonrpc_send_fn(
|
||||||
json_t * request,
|
json_t * request,
|
||||||
void * user_data);
|
void * user_data);
|
||||||
|
|
||||||
|
@ -28,12 +28,10 @@ namespace
|
|||||||
struct SendContext
|
struct SendContext
|
||||||
{
|
{
|
||||||
json_t * response;
|
json_t * response;
|
||||||
bool result;
|
|
||||||
bool is_called;
|
bool is_called;
|
||||||
|
|
||||||
explicit SendContext(bool result_ = true)
|
explicit SendContext()
|
||||||
: response(nullptr)
|
: response(nullptr)
|
||||||
, result(result_)
|
|
||||||
, is_called(false)
|
, is_called(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -47,7 +45,7 @@ namespace
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
bool jsonrpc_send(
|
void jsonrpc_send(
|
||||||
json_t * request,
|
json_t * request,
|
||||||
void * user_data)
|
void * user_data)
|
||||||
{
|
{
|
||||||
@ -55,8 +53,6 @@ namespace
|
|||||||
context->is_called = true;
|
context->is_called = true;
|
||||||
context->response = request;
|
context->response = request;
|
||||||
json_incref(request);
|
json_incref(request);
|
||||||
|
|
||||||
return context->result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct FinishedContext
|
struct FinishedContext
|
||||||
@ -152,28 +148,6 @@ TEST(wfp_jsonrpc_proxy, invoke)
|
|||||||
ASSERT_FALSE(nullptr == finished_context.error);
|
ASSERT_FALSE(nullptr == finished_context.error);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(wfp_jsonrpc_proxy, invoke_calls_finish_if_send_fails)
|
|
||||||
{
|
|
||||||
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
|
|
||||||
|
|
||||||
SendContext send_context(false);
|
|
||||||
void * send_data = reinterpret_cast<void*>(&send_context);
|
|
||||||
struct wfp_jsonrpc_proxy * proxy = wfp_jsonrpc_proxy_create(timer_manager, WFP_DEFAULT_TIMEOUT, &jsonrpc_send, send_data);
|
|
||||||
|
|
||||||
FinishedContext finished_context;
|
|
||||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
|
||||||
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "si", "bar", 42);
|
|
||||||
|
|
||||||
ASSERT_TRUE(send_context.is_called);
|
|
||||||
ASSERT_TRUE(json_is_object(send_context.response));
|
|
||||||
|
|
||||||
ASSERT_TRUE(finished_context.is_called);
|
|
||||||
ASSERT_FALSE(nullptr == finished_context.error);
|
|
||||||
|
|
||||||
wfp_jsonrpc_proxy_dispose(proxy);
|
|
||||||
wfp_timer_manager_dispose(timer_manager);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(wfp_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
|
TEST(wfp_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
|
||||||
{
|
{
|
||||||
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
|
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
|
||||||
@ -202,7 +176,7 @@ TEST(wfp_jsonrpc_proxy, invoke_fails_if_another_request_is_pending)
|
|||||||
wfp_timer_manager_dispose(timer_manager);
|
wfp_timer_manager_dispose(timer_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(wfp_jsonrpc_proxy, invoke_fails_if_request_is_invalid)
|
TEST(wfp_jsonrpc_proxy, invoke_invalid_request)
|
||||||
{
|
{
|
||||||
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
|
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
|
||||||
|
|
||||||
@ -214,10 +188,9 @@ TEST(wfp_jsonrpc_proxy, invoke_fails_if_request_is_invalid)
|
|||||||
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
void * finished_data = reinterpret_cast<void*>(&finished_context);
|
||||||
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "?", "error");
|
wfp_jsonrpc_proxy_invoke(proxy, &jsonrpc_finished, finished_data, "foo", "?", "error");
|
||||||
|
|
||||||
ASSERT_FALSE(send_context.is_called);
|
ASSERT_TRUE(send_context.is_called);
|
||||||
|
|
||||||
ASSERT_TRUE(finished_context.is_called);
|
ASSERT_FALSE(finished_context.is_called);
|
||||||
ASSERT_EQ(WFP_BAD, jsonrpc_get_status(finished_context.error));
|
|
||||||
|
|
||||||
wfp_jsonrpc_proxy_dispose(proxy);
|
wfp_jsonrpc_proxy_dispose(proxy);
|
||||||
wfp_timer_manager_dispose(timer_manager);
|
wfp_timer_manager_dispose(timer_manager);
|
||||||
@ -371,7 +344,7 @@ TEST(wfp_jsonrpc_proxy, notify)
|
|||||||
wfp_timer_manager_dispose(timer_manager);
|
wfp_timer_manager_dispose(timer_manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(wfp_jsonrpc_proxy, notify_dont_send_invalid_request)
|
TEST(wfp_jsonrpc_proxy, notify_send_invalid_request)
|
||||||
{
|
{
|
||||||
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
|
struct wfp_timer_manager * timer_manager = wfp_timer_manager_create();
|
||||||
|
|
||||||
@ -381,7 +354,7 @@ TEST(wfp_jsonrpc_proxy, notify_dont_send_invalid_request)
|
|||||||
|
|
||||||
wfp_jsonrpc_proxy_notify(proxy, "foo", "?");
|
wfp_jsonrpc_proxy_notify(proxy, "foo", "?");
|
||||||
|
|
||||||
ASSERT_FALSE(send_context.is_called);
|
ASSERT_TRUE(send_context.is_called);
|
||||||
|
|
||||||
wfp_jsonrpc_proxy_dispose(proxy);
|
wfp_jsonrpc_proxy_dispose(proxy);
|
||||||
wfp_timer_manager_dispose(timer_manager);
|
wfp_timer_manager_dispose(timer_manager);
|
||||||
|
@ -10,15 +10,13 @@ struct Context
|
|||||||
json_t * response;
|
json_t * response;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool jsonrpc_send(
|
void jsonrpc_send(
|
||||||
json_t * request,
|
json_t * request,
|
||||||
void * user_data)
|
void * user_data)
|
||||||
{
|
{
|
||||||
Context * context = reinterpret_cast<Context*>(user_data);
|
Context * context = reinterpret_cast<Context*>(user_data);
|
||||||
context->response = request;
|
context->response = request;
|
||||||
json_incref(request);
|
json_incref(request);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user