mirror of
https://github.com/mpv-player/mpv
synced 2024-11-14 22:48:35 +01:00
node: move a mpv_node helper from ipc.c to shared code
This particular one is needed in a following commit.
This commit is contained in:
parent
4fd3ad8d63
commit
1157f07c5b
17
input/ipc.c
17
input/ipc.c
@ -20,23 +20,12 @@
|
||||
#include "common/msg.h"
|
||||
#include "input/input.h"
|
||||
#include "misc/json.h"
|
||||
#include "misc/node.h"
|
||||
#include "options/m_option.h"
|
||||
#include "options/options.h"
|
||||
#include "options/path.h"
|
||||
#include "player/client.h"
|
||||
|
||||
static mpv_node *mpv_node_map_get(mpv_node *src, const char *key)
|
||||
{
|
||||
if (src->format != MPV_FORMAT_NODE_MAP)
|
||||
return NULL;
|
||||
|
||||
for (int i = 0; i < src->u.list->num; i++)
|
||||
if (!strcmp(key, src->u.list->keys[i]))
|
||||
return &src->u.list->values[i];
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static mpv_node *mpv_node_array_get(mpv_node *src, int index)
|
||||
{
|
||||
if (src->format != MPV_FORMAT_NODE_ARRAY)
|
||||
@ -217,9 +206,9 @@ static char *json_execute_command(struct mpv_handle *client, void *ta_parent,
|
||||
goto error;
|
||||
}
|
||||
|
||||
reqid_node = mpv_node_map_get(&msg_node, "request_id");
|
||||
reqid_node = node_map_get(&msg_node, "request_id");
|
||||
|
||||
mpv_node *cmd_node = mpv_node_map_get(&msg_node, "command");
|
||||
mpv_node *cmd_node = node_map_get(&msg_node, "command");
|
||||
if (!cmd_node ||
|
||||
(cmd_node->format != MPV_FORMAT_NODE_ARRAY) ||
|
||||
!cmd_node->u.list->num)
|
||||
|
13
misc/node.c
13
misc/node.c
@ -81,3 +81,16 @@ void node_map_add_flag(struct mpv_node *dst, const char *key, bool v)
|
||||
{
|
||||
node_map_add(dst, key, MPV_FORMAT_FLAG)->u.flag = v;
|
||||
}
|
||||
|
||||
mpv_node *node_map_get(mpv_node *src, const char *key)
|
||||
{
|
||||
if (src->format != MPV_FORMAT_NODE_MAP)
|
||||
return NULL;
|
||||
|
||||
for (int i = 0; i < src->u.list->num; i++) {
|
||||
if (strcmp(key, src->u.list->keys[i]) == 0)
|
||||
return &src->u.list->values[i];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@ -10,5 +10,6 @@ void node_map_add_string(struct mpv_node *dst, const char *key, const char *val)
|
||||
void node_map_add_int64(struct mpv_node *dst, const char *key, int64_t v);
|
||||
void node_map_add_double(struct mpv_node *dst, const char *key, double v);
|
||||
void node_map_add_flag(struct mpv_node *dst, const char *key, bool v);
|
||||
mpv_node *node_map_get(mpv_node *src, const char *key);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user