jsonrpc: Make it easy to get a new JSON-RPC request's id.
authorBen Pfaff <blp@nicira.com>
Wed, 2 Dec 2009 00:32:03 +0000 (16:32 -0800)
committerBen Pfaff <blp@nicira.com>
Wed, 2 Dec 2009 19:19:08 +0000 (11:19 -0800)
lib/jsonrpc.c
lib/jsonrpc.h
ovsdb/jsonrpc-server.c
ovsdb/ovsdb-client.c
tests/test-jsonrpc.c

index 817a35f..bd019f7 100644 (file)
@@ -402,10 +402,14 @@ jsonrpc_create_id(void)
 }
 
 struct jsonrpc_msg *
-jsonrpc_create_request(const char *method, struct json *params)
+jsonrpc_create_request(const char *method, struct json *params,
+                       struct json **idp)
 {
-    return jsonrpc_create(JSONRPC_REQUEST, method, params, NULL, NULL,
-                           jsonrpc_create_id());
+    struct json *id = jsonrpc_create_id();
+    if (idp) {
+        *idp = json_clone(id);
+    }
+    return jsonrpc_create(JSONRPC_REQUEST, method, params, NULL, NULL, id);
 }
 
 struct jsonrpc_msg *
@@ -722,7 +726,7 @@ jsonrpc_session_run(struct jsonrpc_session *s)
             struct jsonrpc_msg *request;
 
             params = json_array_create_empty();
-            request = jsonrpc_create_request("echo", params);
+            request = jsonrpc_create_request("echo", params, NULL);
             json_destroy(request->id);
             request->id = json_string_create("echo");
             jsonrpc_send(s->rpc, request);
index 5d47ac5..93ac2e8 100644 (file)
@@ -67,7 +67,8 @@ struct jsonrpc_msg {
 };
 
 struct jsonrpc_msg *jsonrpc_create_request(const char *method,
-                                           struct json *params);
+                                           struct json *params,
+                                           struct json **idp);
 struct jsonrpc_msg *jsonrpc_create_notify(const char *method,
                                           struct json *params);
 struct jsonrpc_msg *jsonrpc_create_reply(struct json *result,
index 4644970..897f9ae 100644 (file)
@@ -330,7 +330,7 @@ ovsdb_jsonrpc_session_run(struct ovsdb_jsonrpc_session *s)
             struct jsonrpc_msg *request;
 
             params = json_array_create_empty();
-            request = jsonrpc_create_request("echo", params);
+            request = jsonrpc_create_request("echo", params, NULL);
             json_destroy(request->id);
             request->id = json_string_create("echo");
             jsonrpc_send(s->rpc, request);
index 6e00681..65d6d81 100644 (file)
@@ -236,7 +236,8 @@ fetch_schema_from_rpc(struct jsonrpc *rpc)
     struct ovsdb_schema *schema;
     int error;
 
-    request = jsonrpc_create_request("get_schema", json_array_create_empty());
+    request = jsonrpc_create_request("get_schema", json_array_create_empty(),
+                                     NULL);
     error = jsonrpc_transact_block(rpc, request, &reply);
     if (error) {
         ovs_fatal(error, "transaction failed");
@@ -629,7 +630,7 @@ do_transact(int argc UNUSED, char *argv[])
     transaction = parse_json(argv[2]);
 
     rpc = open_jsonrpc(argv[1]);
-    request = jsonrpc_create_request("transact", transaction);
+    request = jsonrpc_create_request("transact", transaction, NULL);
     error = jsonrpc_transact_block(rpc, request, &reply);
     if (error) {
         ovs_fatal(error, "transaction failed");
@@ -795,7 +796,7 @@ do_monitor(int argc, char *argv[])
     json_object_put(monitor_requests, argv[2], monitor_request);
 
     monitor = json_array_create_2(json_null_create(), monitor_requests);
-    request = jsonrpc_create_request("monitor", monitor);
+    request = jsonrpc_create_request("monitor", monitor, NULL);
     request_id = json_clone(request->id);
     jsonrpc_send(rpc, request);
     for (;;) {
index 7f2166f..42d2c39 100644 (file)
@@ -250,7 +250,7 @@ do_request(int argc UNUSED, char *argv[])
 
     method = argv[2];
     params = parse_json(argv[3]);
-    msg = jsonrpc_create_request(method, params);
+    msg = jsonrpc_create_request(method, params, NULL);
     string = jsonrpc_msg_is_valid(msg);
     if (string) {
         ovs_fatal(0, "not a valid JSON-RPC request: %s", string);