diff --git a/include/json-ipc.h b/include/json-ipc.h index 1ba141c..eac2f22 100644 --- a/include/json-ipc.h +++ b/include/json-ipc.h @@ -51,6 +51,7 @@ void jsonipc_error_cleanup(struct jsonipc_error*); struct jsonipc_request* jsonipc_request_parse_new(json_t* root, struct jsonipc_error* err); struct jsonipc_request* jsonipc_request_new(const char* method, json_t* params); +struct jsonipc_request* jsonipc_event_new(const char* method, json_t* params); json_t* jsonipc_request_pack(struct jsonipc_request*, json_error_t* err); void jsonipc_request_destroy(struct jsonipc_request*); diff --git a/src/json-ipc.c b/src/json-ipc.c index 7a4c643..7ebf094 100644 --- a/src/json-ipc.c +++ b/src/json-ipc.c @@ -89,17 +89,28 @@ failure: return NULL; } -static int request_id = 1; -struct jsonipc_request* jsonipc_request_new(const char* method, json_t* params) +struct jsonipc_request* jsonipc_request__new(const char* method, json_t* params, + json_t* id) { struct jsonipc_request* ipc = calloc(1, sizeof(*ipc)); ipc->method = method; ipc->params = params; json_incref(ipc->params); - ipc->id = json_integer(request_id++); + ipc->id = id; return ipc; } +static int request_id = 1; +struct jsonipc_request* jsonipc_request_new(const char* method, json_t* params) +{ + return jsonipc_request__new(method, params, json_integer(request_id++)); +} + +struct jsonipc_request* jsonipc_event_new(const char* method, json_t* params) +{ + return jsonipc_request__new(method, params, NULL); +} + json_t* jsonipc_request_pack(struct jsonipc_request* self, json_error_t* err) { return json_pack_ex(err, 0, "{s:s, s:O*, s:O*}",