jsonrpc_client: make ID and method optional when starting request

In JSON RPC the ID is optional. Method is mandatory but user might want
to produce the name later or by using
spdk_json_write_named_string_fmt(). This patch also changes the argument
order.

Change-Id: Ifbd35b8c93e684d15731c4ba1d18bf68d1e8a068
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-on: https://review.gerrithub.io/429254
Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Pawel Wodkowski 2018-10-12 15:26:51 +02:00 committed by Jim Harris
parent 439641f772
commit 8397285b50
3 changed files with 16 additions and 11 deletions

View File

@ -182,16 +182,15 @@ void spdk_jsonrpc_send_error_response_fmt(struct spdk_jsonrpc_request *request,
* on the request after writing the desired request object to the spdk_json_write_ctx.
*
* \param request JSON-RPC request.
* \param method Name of the RPC method.
* \param id ID index for the request.
* \param id ID index for the request. If < 0 skip ID.
* \param method Name of the RPC method. If NULL caller will have to create "method" key.
*
* \return JSON write context to write the parameter object to, or NULL if no
* parameter is necessary.
*/
struct spdk_json_write_ctx *spdk_jsonrpc_begin_request(
struct spdk_jsonrpc_client_request *request,
const char *method,
int32_t id);
struct spdk_json_write_ctx *
spdk_jsonrpc_begin_request(struct spdk_jsonrpc_client_request *request, int32_t id,
const char *method);
/**
* Complete a JSON-RPC request.

View File

@ -167,8 +167,8 @@ jsonrpc_client_write_cb(void *cb_ctx, const void *data, size_t size)
}
struct spdk_json_write_ctx *
spdk_jsonrpc_begin_request(struct spdk_jsonrpc_client_request *request, const char *method,
int32_t id)
spdk_jsonrpc_begin_request(struct spdk_jsonrpc_client_request *request, int32_t id,
const char *method)
{
struct spdk_json_write_ctx *w;
@ -179,8 +179,14 @@ spdk_jsonrpc_begin_request(struct spdk_jsonrpc_client_request *request, const ch
spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "jsonrpc", "2.0");
spdk_json_write_named_int32(w, "id", id);
spdk_json_write_named_string(w, "method", method);
if (id >= 0) {
spdk_json_write_named_int32(w, "id", id);
}
if (method) {
spdk_json_write_named_string(w, "method", method);
}
return w;
}

View File

@ -70,7 +70,7 @@ spdk_jsonrpc_client_check_rpc_method(struct spdk_jsonrpc_client *client, char *m
return -ENOMEM;
}
w = spdk_jsonrpc_begin_request(request, "get_rpc_methods", 1);
w = spdk_jsonrpc_begin_request(request, 1, "get_rpc_methods");
spdk_jsonrpc_end_request(request, w);
spdk_jsonrpc_client_send_request(client, request);
spdk_jsonrpc_client_free_request(request);