2 * Copyright (c) 2009 Nicira Networks.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
20 /* This is an implementation of the JSON-RPC 1.0 specification defined at
21 * http://json-rpc.org/wiki/specification. */
30 /* API for a JSON-RPC stream. */
32 struct jsonrpc *jsonrpc_open(struct stream *);
33 void jsonrpc_close(struct jsonrpc *);
35 void jsonrpc_run(struct jsonrpc *);
36 void jsonrpc_wait(struct jsonrpc *);
38 void jsonrpc_error(struct jsonrpc *, int error);
39 int jsonrpc_get_status(const struct jsonrpc *);
40 size_t jsonrpc_get_backlog(const struct jsonrpc *);
41 const char *jsonrpc_get_name(const struct jsonrpc *);
43 int jsonrpc_send(struct jsonrpc *, struct jsonrpc_msg *);
44 int jsonrpc_recv(struct jsonrpc *, struct jsonrpc_msg **);
45 void jsonrpc_recv_wait(struct jsonrpc *);
47 int jsonrpc_send_block(struct jsonrpc *, struct jsonrpc_msg *);
48 int jsonrpc_recv_block(struct jsonrpc *, struct jsonrpc_msg **);
49 int jsonrpc_transact_block(struct jsonrpc *, struct jsonrpc_msg *,
50 struct jsonrpc_msg **);
53 enum jsonrpc_msg_type {
54 JSONRPC_REQUEST, /* Request. */
55 JSONRPC_NOTIFY, /* Notification. */
56 JSONRPC_REPLY, /* Successful reply. */
57 JSONRPC_ERROR /* Error reply. */
61 enum jsonrpc_msg_type type;
62 char *method; /* Request or notification only. */
63 struct json *params; /* Request or notification only. */
64 struct json *result; /* Successful reply only. */
65 struct json *error; /* Error reply only. */
66 struct json *id; /* Request or reply only. */
69 struct jsonrpc_msg *jsonrpc_create_request(const char *method,
71 struct jsonrpc_msg *jsonrpc_create_notify(const char *method,
73 struct jsonrpc_msg *jsonrpc_create_reply(struct json *result,
74 const struct json *id);
75 struct jsonrpc_msg *jsonrpc_create_error(struct json *error,
76 const struct json *id);
78 const char *jsonrpc_msg_type_to_string(enum jsonrpc_msg_type);
79 char *jsonrpc_msg_is_valid(const struct jsonrpc_msg *);
80 void jsonrpc_msg_destroy(struct jsonrpc_msg *);
82 char *jsonrpc_msg_from_json(struct json *, struct jsonrpc_msg **);
83 struct json *jsonrpc_msg_to_json(struct jsonrpc_msg *);
85 #endif /* jsonrpc.h */