command: add add-spa-lib command

Add a command to add a factory name regex to library mapping.
This commit is contained in:
Wim Taymans 2019-05-31 15:03:56 +02:00
parent b9d9042695
commit 89a86db0c4
2 changed files with 43 additions and 1 deletions

View file

@ -335,7 +335,7 @@ int main(int argc, char *argv[])
* If you plan to autoconnect your stream, you need to provide at least
* media, category and role properties
*
* Pass your events and a use_data pointer as the last arguments. This
* Pass your events and a user_data pointer as the last arguments. This
* will inform you about the stream state. The most important event
* you need to listen to is the process event where you need to consume
* the data provided to you.

View file

@ -38,6 +38,7 @@
/** \cond */
static struct pw_command *parse_command_help(const char *line, char **err);
static struct pw_command *parse_command_add_spa_lib(const char *line, char **err);
static struct pw_command *parse_command_module_load(const char *line, char **err);
static struct pw_command *parse_command_exec(const char *line, char **err);
@ -55,6 +56,7 @@ struct command_parse {
static const struct command_parse parsers[] = {
{"help", "Show this help", parse_command_help},
{"add-spa-lib", "Add a library that provides a spa factory name regex", parse_command_add_spa_lib},
{"load-module", "Load a module", parse_command_module_load},
{"exec", "Execute a program", parse_command_exec},
{NULL, NULL, NULL }
@ -95,6 +97,46 @@ static struct pw_command *parse_command_help(const char *line, char **err)
return NULL;
}
static int
execute_command_add_spa_lib(struct pw_command *command, struct pw_core *core, char **err)
{
int res;
res = pw_core_add_spa_lib(core, command->args[1], command->args[2]);
if (res < 0) {
asprintf(err, "could not add spa library \"%s\"", command->args[1]);
return res;
}
return 0;
}
static struct pw_command *parse_command_add_spa_lib(const char *line, char **err)
{
struct impl *impl;
struct pw_command *this;
impl = calloc(1, sizeof(struct impl));
if (impl == NULL)
goto no_mem;
this = &impl->this;
this->func = execute_command_add_spa_lib;
this->args = pw_split_strv(line, whitespace, 4, &this->n_args);
if (this->n_args < 3)
goto no_library;
return this;
no_library:
asprintf(err, "%s requires <factory-regex> <library-name>", this->args[0]);
pw_free_strv(this->args);
return NULL;
no_mem:
asprintf(err, "no memory");
return NULL;
}
static int
execute_command_module_load(struct pw_command *command, struct pw_core *core, char **err)
{