pw-link: do argument check before sync

This commit is contained in:
Barnabás Pőcze 2024-01-04 18:25:50 +01:00 committed by Wim Taymans
parent e362a66880
commit 8cf5bbf658

View file

@ -453,6 +453,9 @@ static int create_link_proxies(struct data *data)
struct object *n, *p;
struct object *in_node = NULL, *out_node = NULL;
spa_assert(data->opt_output);
spa_assert(data->opt_input);
spa_list_for_each(n, &data->objects, link) {
if (n->type != OBJECT_NODE)
continue;
@ -523,6 +526,8 @@ static int do_unlink_ports(struct data *data)
bool found_any = false;
struct object *in_node = NULL, *out_node = NULL;
spa_assert(data->opt_output);
if (data->opt_input != NULL) {
/* 2 args, check if they are node names */
spa_list_for_each(n, &data->objects, link) {
@ -966,10 +971,22 @@ static int run(int argc, char *argv[])
if (optind < argc)
data.opt_input = argv[optind++];
if (data.opt_mode == MODE_CONNECT && (data.opt_output == NULL || data.opt_input == NULL)) {
switch (data.opt_mode) {
case MODE_LIST:
break;
case MODE_DISCONNECT:
if (data.opt_output == NULL) {
fprintf(stderr, "missing link-id or output and input port names to disconnect\n");
return -1;
}
break;
case MODE_CONNECT:
if (data.opt_output == NULL || data.opt_input == NULL) {
fprintf(stderr, "missing output and input port names to connect\n");
return -1;
}
break;
}
data.loop = pw_main_loop_new(NULL);
if (data.loop == NULL) {
@ -1031,10 +1048,6 @@ static int run(int argc, char *argv[])
do_list(&data);
break;
case MODE_DISCONNECT:
if (data.opt_output == NULL) {
fprintf(stderr, "missing link-id or output and input port names to disconnect\n");
return -1;
}
if ((res = do_unlink_ports(&data)) < 0) {
fprintf(stderr, "failed to unlink ports: %s\n", spa_strerror(res));
return -1;