Commit 8397285b authored by Pawel Wodkowski's avatar Pawel Wodkowski Committed by Jim Harris
Browse files

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: default avatarPawel 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: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
parent 439641f7
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -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.
+10 −4
Original line number Diff line number Diff line
@@ -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");

	if (id >= 0) {
		spdk_json_write_named_int32(w, "id", id);
	}

	if (method) {
		spdk_json_write_named_string(w, "method", method);
	}

	return w;
}
+1 −1
Original line number Diff line number Diff line
@@ -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);