From 029da5abce6e1ef6eddf351650fe7d6fe3746f0b Mon Sep 17 00:00:00 2001 From: Preston Hunt Date: Fri, 3 Jul 2015 10:51:46 -0700 Subject: ipc: add request_id to json If the request contains a "request_id", copy it back into the response. There is no interpretation of the request_id value by mpv; the only purpose is to make it easier on the requester by providing an ability to match up responses with requests. Because the IPC mechanism sends events continously, it's possible for the response to a request to arrive several events after the request was made. This can make it very difficult on the requester to determine which response goes to which request. --- input/ipc.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'input') diff --git a/input/ipc.c b/input/ipc.c index b49d64b8d4..ec219da31f 100644 --- a/input/ipc.c +++ b/input/ipc.c @@ -257,6 +257,8 @@ static char *json_execute_command(struct client_arg *arg, void *ta_parent, goto error; } + mpv_node *reqid_node = mpv_node_map_get(&msg_node, "request_id"); + mpv_node *cmd_node = mpv_node_map_get(&msg_node, "command"); if (!cmd_node || (cmd_node->format != MPV_FORMAT_NODE_ARRAY) || @@ -470,6 +472,14 @@ static char *json_execute_command(struct client_arg *arg, void *ta_parent, } error: + /* If the request contains a "request_id", copy it back into the response. + * This makes it easier on the requester to match up the IPC results with + * the original requests. + */ + if (reqid_node) { + mpv_node_map_add(ta_parent, &reply_node, "request_id", reqid_node); + } + mpv_node_map_add_string(ta_parent, &reply_node, "error", mpv_error_string(rc)); char *output = talloc_strdup(ta_parent, ""); -- cgit v1.2.3