mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
cli: add create-device command
Add create-device command Add short command aliases
This commit is contained in:
parent
116676e149
commit
128a8e6c3c
1 changed files with 62 additions and 21 deletions
|
|
@ -98,6 +98,7 @@ struct proxy_data {
|
||||||
|
|
||||||
struct command {
|
struct command {
|
||||||
const char *name;
|
const char *name;
|
||||||
|
const char *alias;
|
||||||
const char *description;
|
const char *description;
|
||||||
bool (*func) (struct data *data, const char *cmd, char *args, char **error);
|
bool (*func) (struct data *data, const char *cmd, char *args, char **error);
|
||||||
};
|
};
|
||||||
|
|
@ -195,6 +196,7 @@ static bool do_disconnect(struct data *data, const char *cmd, char *args, char *
|
||||||
static bool do_list_remotes(struct data *data, const char *cmd, char *args, char **error);
|
static bool do_list_remotes(struct data *data, const char *cmd, char *args, char **error);
|
||||||
static bool do_switch_remote(struct data *data, const char *cmd, char *args, char **error);
|
static bool do_switch_remote(struct data *data, const char *cmd, char *args, char **error);
|
||||||
static bool do_info(struct data *data, const char *cmd, char *args, char **error);
|
static bool do_info(struct data *data, const char *cmd, char *args, char **error);
|
||||||
|
static bool do_create_device(struct data *data, const char *cmd, char *args, char **error);
|
||||||
static bool do_create_node(struct data *data, const char *cmd, char *args, char **error);
|
static bool do_create_node(struct data *data, const char *cmd, char *args, char **error);
|
||||||
static bool do_destroy(struct data *data, const char *cmd, char *args, char **error);
|
static bool do_destroy(struct data *data, const char *cmd, char *args, char **error);
|
||||||
static bool do_create_link(struct data *data, const char *cmd, char *args, char **error);
|
static bool do_create_link(struct data *data, const char *cmd, char *args, char **error);
|
||||||
|
|
@ -204,22 +206,23 @@ static bool do_permissions(struct data *data, const char *cmd, char *args, char
|
||||||
static bool do_get_permissions(struct data *data, const char *cmd, char *args, char **error);
|
static bool do_get_permissions(struct data *data, const char *cmd, char *args, char **error);
|
||||||
|
|
||||||
static struct command command_list[] = {
|
static struct command command_list[] = {
|
||||||
{ "help", "Show this help", do_help },
|
{ "help", "h", "Show this help", do_help },
|
||||||
{ "load-module", "Load a module. <module-name> [<module-arguments>]", do_load_module },
|
{ "load-module", "lm", "Load a module. <module-name> [<module-arguments>]", do_load_module },
|
||||||
{ "unload-module", "Unload a module. <module-var>", do_not_implemented },
|
{ "unload-module", "um", "Unload a module. <module-var>", do_not_implemented },
|
||||||
{ "connect", "Connect to a remote. [<remote-name>]", do_connect },
|
{ "connect", "con", "Connect to a remote. [<remote-name>]", do_connect },
|
||||||
{ "disconnect", "Disconnect from a remote. [<remote-var>]", do_disconnect },
|
{ "disconnect", "dis", "Disconnect from a remote. [<remote-var>]", do_disconnect },
|
||||||
{ "list-remotes", "List connected remotes.", do_list_remotes },
|
{ "list-remotes", "lr", "List connected remotes.", do_list_remotes },
|
||||||
{ "switch-remote", "Switch between current remotes. [<remote-var>]", do_switch_remote },
|
{ "switch-remote", "sr", "Switch between current remotes. [<remote-var>]", do_switch_remote },
|
||||||
{ "list-objects", "List objects or current remote. [<interface>]", do_list_objects },
|
{ "list-objects", "ls", "List objects or current remote. [<interface>]", do_list_objects },
|
||||||
{ "info", "Get info about an object. <object-id>|all", do_info },
|
{ "info", "i", "Get info about an object. <object-id>|all", do_info },
|
||||||
{ "create-node", "Create a node from a factory. <factory-name> [<properties>]", do_create_node },
|
{ "create-device", "cd", "Create a device from a factory. <factory-name> [<properties>]", do_create_device },
|
||||||
{ "destroy", "Destroy a global object. <object-id>", do_destroy },
|
{ "create-node", "cn", "Create a node from a factory. <factory-name> [<properties>]", do_create_node },
|
||||||
{ "create-link", "Create a link between nodes. <node-id> <port-id> <node-id> <port-id> [<properties>]", do_create_link },
|
{ "destroy", "d", "Destroy a global object. <object-id>", do_destroy },
|
||||||
{ "export-node", "Export a local node to the current remote. <node-id> [remote-var]", do_export_node },
|
{ "create-link", "cl", "Create a link between nodes. <node-id> <port-id> <node-id> <port-id> [<properties>]", do_create_link },
|
||||||
{ "enum-params", "Enumerate params of an object <object-id> [<param-id-name>]", do_enum_params },
|
{ "export-node", "en", "Export a local node to the current remote. <node-id> [remote-var]", do_export_node },
|
||||||
{ "permissions", "Set permissions for a client <client-id> <object> <permission>", do_permissions },
|
{ "enum-params", "e", "Enumerate params of an object <object-id> [<param-id-name>]", do_enum_params },
|
||||||
{ "get-permissions", "Get permissions of a client <client-id>", do_get_permissions },
|
{ "permissions", "sp", "Set permissions for a client <client-id> <object> <permission>", do_permissions },
|
||||||
|
{ "get-permissions", "gp", "Get permissions of a client <client-id>", do_get_permissions },
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool do_help(struct data *data, const char *cmd, char *args, char **error)
|
static bool do_help(struct data *data, const char *cmd, char *args, char **error)
|
||||||
|
|
@ -1023,6 +1026,43 @@ static bool do_info(struct data *data, const char *cmd, char *args, char **error
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool do_create_device(struct data *data, const char *cmd, char *args, char **error)
|
||||||
|
{
|
||||||
|
struct remote_data *rd = data->current;
|
||||||
|
char *a[2];
|
||||||
|
int n;
|
||||||
|
uint32_t id;
|
||||||
|
struct pw_proxy *proxy;
|
||||||
|
struct pw_properties *props = NULL;
|
||||||
|
struct proxy_data *pd;
|
||||||
|
|
||||||
|
n = pw_split_ip(args, WHITESPACE, 2, a);
|
||||||
|
if (n < 1) {
|
||||||
|
asprintf(error, "%s <factory-name> [<properties>]", cmd);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (n == 2)
|
||||||
|
props = parse_props(a[1]);
|
||||||
|
|
||||||
|
proxy = pw_core_proxy_create_object(rd->core_proxy, a[0],
|
||||||
|
PW_TYPE_INTERFACE_Device,
|
||||||
|
PW_VERSION_DEVICE_PROXY,
|
||||||
|
props ? &props->dict : NULL,
|
||||||
|
sizeof(struct proxy_data));
|
||||||
|
|
||||||
|
pd = pw_proxy_get_user_data(proxy);
|
||||||
|
pd->rd = rd;
|
||||||
|
pd->proxy = proxy;
|
||||||
|
pd->destroy = (pw_destroy_t) pw_device_info_free;
|
||||||
|
pw_proxy_add_object_listener(proxy, &pd->object_listener, &device_events, pd);
|
||||||
|
pw_proxy_add_listener(proxy, &pd->proxy_listener, &proxy_events, pd);
|
||||||
|
|
||||||
|
id = pw_map_insert_new(&data->vars, proxy);
|
||||||
|
fprintf(stdout, "%d = @proxy:%d\n", id, pw_proxy_get_id(proxy));
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool do_create_node(struct data *data, const char *cmd, char *args, char **error)
|
static bool do_create_node(struct data *data, const char *cmd, char *args, char **error)
|
||||||
{
|
{
|
||||||
struct remote_data *rd = data->current;
|
struct remote_data *rd = data->current;
|
||||||
|
|
@ -1316,7 +1356,8 @@ static bool parse(struct data *data, char *buf, size_t size, char **error)
|
||||||
args = n > 1 ? a[1] : "";
|
args = n > 1 ? a[1] : "";
|
||||||
|
|
||||||
for (i = 0; i < SPA_N_ELEMENTS(command_list); i++) {
|
for (i = 0; i < SPA_N_ELEMENTS(command_list); i++) {
|
||||||
if (!strcmp(command_list[i].name, cmd)) {
|
if (!strcmp(command_list[i].name, cmd) ||
|
||||||
|
!strcmp(command_list[i].alias, cmd)) {
|
||||||
return command_list[i].func(data, cmd, args, error);
|
return command_list[i].func(data, cmd, args, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue