diff options
Diffstat (limited to 'src/tools/pipewire-cli.c')
-rw-r--r-- | src/tools/pipewire-cli.c | 229 |
1 files changed, 81 insertions, 148 deletions
diff --git a/src/tools/pipewire-cli.c b/src/tools/pipewire-cli.c index d623d393..56a3919b 100644 --- a/src/tools/pipewire-cli.c +++ b/src/tools/pipewire-cli.c @@ -35,7 +35,6 @@ #include <pipewire/pipewire.h> #include <pipewire/type.h> #include <pipewire/permission.h> -#include <pipewire/impl-module.h> #include <extensions/session-manager.h> @@ -44,8 +43,8 @@ static const char WHITESPACE[] = " \t"; struct remote_data; struct data { - struct pw_main_loop *loop; - struct pw_impl_core *core; + struct pw_main_loop *main_loop; + struct pw_loop *loop; struct spa_list remotes; struct remote_data *current; @@ -71,12 +70,10 @@ struct remote_data { char *name; uint32_t id; - struct pw_remote *remote; - struct spa_hook remote_listener; - int prompt_pending; - struct pw_core *core; struct spa_hook core_listener; + int prompt_pending; + struct pw_registry *registry; struct spa_hook registry_listener; @@ -242,10 +239,11 @@ static bool do_help(struct data *data, const char *cmd, char *args, char **error static bool do_load_module(struct data *data, const char *cmd, char *args, char **error) { - struct pw_impl_module *module; + struct pw_module *module; char *a[2]; int n; uint32_t id; + struct remote_data *rd = data->current; n = pw_split_ip(args, WHITESPACE, 2, a); if (n < 1) { @@ -253,40 +251,18 @@ static bool do_load_module(struct data *data, const char *cmd, char *args, char return false; } - module = pw_impl_module_load(data->core, a[0], n == 2 ? a[1] : NULL, NULL); + module = pw_core_load_module(rd->core, a[0], n == 2 ? a[1] : NULL, NULL, 0); if (module == NULL) { - asprintf(error, "Could not load module"); + asprintf(error, "Could not load module: %m"); return false; } id = pw_map_insert_new(&data->vars, module); - fprintf(stdout, "%d = @module:%d\n", id, pw_global_get_id(pw_impl_module_get_global(module))); + fprintf(stdout, "%d = @module:%d\n", id, pw_proxy_get_id((struct pw_proxy*)module)); return true; } -static void on_core_info(void *_data, const struct pw_core_info *info) -{ - struct remote_data *rd = _data; - free(rd->name); - rd->name = info->name ? strdup(info->name) : NULL; - fprintf(stdout, "remote %d is named '%s'\n", rd->id, rd->name); -} - -static void show_prompt(struct remote_data *rd) -{ - fprintf(stdout, "%s>>", rd->name); - fflush(stdout); -} - -static void on_core_done(void *_data, uint32_t id, int seq) -{ - struct remote_data *rd = _data; - - if (seq == rd->prompt_pending) - show_prompt(rd); -} - static int print_global(void *obj, void *data) { struct global *global = obj; @@ -370,96 +346,6 @@ static const struct pw_registry_events registry_events = { .global_remove = registry_event_global_remove, }; -static void on_remote_destroy(void *_data) -{ - struct remote_data *rd = _data; - struct data *data = rd->data; - - spa_list_remove(&rd->link); - - pw_map_remove(&data->vars, rd->id); - pw_map_for_each(&rd->globals, destroy_global, rd); - - if (data->current == rd) - data->current = NULL; - free(rd->name); -} - -static const struct pw_core_events remote_core_events = { - PW_VERSION_CORE_EVENTS, - .info = on_core_info, - .done = on_core_done, -}; - -static void on_state_changed(void *_data, enum pw_remote_state old, - enum pw_remote_state state, const char *error) -{ - struct remote_data *rd = _data; - struct data *data = rd->data; - - switch (state) { - case PW_REMOTE_STATE_ERROR: - fprintf(stderr, "remote %d error: %s\n", rd->id, error); - pw_main_loop_quit(data->loop); - break; - - case PW_REMOTE_STATE_CONNECTED: - fprintf(stdout, "remote %d state: \"%s\"\n", rd->id, pw_remote_state_as_string(state)); - rd->core = pw_remote_get_core(rd->remote); - pw_core_add_listener(rd->core, - &rd->core_listener, - &remote_core_events, rd); - rd->registry = pw_core_get_registry(rd->core, PW_VERSION_REGISTRY, 0); - pw_registry_add_listener(rd->registry, - &rd->registry_listener, - ®istry_events, rd); - rd->prompt_pending = pw_core_sync(rd->core, 0, 0); - break; - - default: - fprintf(stdout, "remote %d state: \"%s\"\n", rd->id, pw_remote_state_as_string(state)); - break; - } -} - -static const struct pw_remote_events remote_events = { - PW_VERSION_REMOTE_EVENTS, - .destroy = on_remote_destroy, - .state_changed = on_state_changed, -}; - - -static bool do_connect(struct data *data, const char *cmd, char *args, char **error) -{ - char *a[1]; - int n; - struct pw_remote *remote; - struct pw_properties *props = NULL; - struct remote_data *rd; - - n = pw_split_ip(args, WHITESPACE, 1, a); - if (n == 1) { - props = pw_properties_new(PW_KEY_REMOTE_NAME, a[0], NULL); - } - remote = pw_remote_new(data->core, props, sizeof(struct remote_data)); - - rd = pw_remote_get_user_data(remote); - rd->remote = remote; - rd->data = data; - pw_map_init(&rd->globals, 64, 16); - rd->id = pw_map_insert_new(&data->vars, rd); - spa_list_append(&data->remotes, &rd->link); - - fprintf(stdout, "%d = @remote:%p\n", rd->id, remote); - data->current = rd; - - pw_remote_add_listener(remote, &rd->remote_listener, &remote_events, rd); - if (pw_remote_connect(remote) < 0) - return false; - - return true; -} - static bool do_disconnect(struct data *data, const char *cmd, char *args, char **error) { char *a[1]; @@ -475,8 +361,7 @@ static bool do_disconnect(struct data *data, const char *cmd, char *args, char * goto no_remote; } - pw_remote_disconnect(rd->remote); - pw_remote_destroy(rd->remote); + pw_core_disconnect(rd->core); if (data->current == NULL) { if (spa_list_is_empty(&data->remotes)) { @@ -497,7 +382,7 @@ static bool do_list_remotes(struct data *data, const char *cmd, char *args, char struct remote_data *rd; spa_list_for_each(rd, &data->remotes, link) - fprintf(stdout, "\t%d = @remote:%p '%s'\n", rd->id, rd->remote, rd->name); + fprintf(stdout, "\t%d = @core:%p '%s'\n", rd->id, rd->core, rd->name); return true; } @@ -722,11 +607,26 @@ static void core_event_info(void *object, const struct pw_core_info *info) info_core(pd); pd->global->info_pending = false; } + fprintf(stdout, "remote %d is named '%s'\n", rd->id, rd->name); +} + +static void show_prompt(struct remote_data *rd) +{ + fprintf(stdout, "%s>>", rd->name); + fflush(stdout); +} + +static void core_event_done(void *_data, uint32_t id, int seq) +{ + struct remote_data *rd = _data; + if (seq == rd->prompt_pending) + show_prompt(rd); } static const struct pw_core_events core_events = { PW_VERSION_CORE_EVENTS, - .info = core_event_info + .info = core_event_info, + .done = core_event_done, }; @@ -1092,6 +992,9 @@ static bool do_list_objects(struct data *data, const char *cmd, char *args, char return true; } + + + static bool bind_global(struct remote_data *rd, struct global *global, char **error) { const void *events; @@ -1102,12 +1005,14 @@ static bool bind_global(struct remote_data *rd, struct global *global, char **er struct pw_proxy *proxy; switch (global->type) { +#if 0 case PW_TYPE_INTERFACE_Core: events = &core_events; client_version = PW_VERSION_CORE; destroy = (pw_destroy_t) pw_core_info_free; info_func = info_core; break; +#endif case PW_TYPE_INTERFACE_Module: events = &module_events; client_version = PW_VERSION_MODULE; @@ -1397,6 +1302,7 @@ static bool do_create_link(struct data *data, const char *cmd, char *args, char static bool do_export_node(struct data *data, const char *cmd, char *args, char **error) { +#if 0 struct remote_data *rd = data->current; struct pw_global *global; struct pw_node *node; @@ -1436,6 +1342,7 @@ static bool do_export_node(struct data *data, const char *cmd, char *args, char no_remote: asprintf(error, "Remote %d does not exist", idx); +#endif return false; } @@ -1563,6 +1470,42 @@ static bool do_get_permissions(struct data *data, const char *cmd, char *args, c return true; } +static bool do_connect(struct data *data, const char *cmd, char *args, char **error) +{ + char *a[1]; + int n; + struct pw_core *core; + struct pw_properties *props = NULL; + struct remote_data *rd; + + n = pw_split_ip(args, WHITESPACE, 1, a); + if (n == 1) { + props = pw_properties_new(PW_KEY_REMOTE_NAME, a[0], NULL); + } + core = pw_core_connect(data->loop, props, sizeof(struct remote_data)); + + rd = pw_core_get_user_data(core); + rd->core = core; + rd->data = data; + pw_map_init(&rd->globals, 64, 16); + rd->id = pw_map_insert_new(&data->vars, rd); + spa_list_append(&data->remotes, &rd->link); + + fprintf(stdout, "%d = @core:%p\n", rd->id, core); + data->current = rd; + + pw_core_add_listener(core, &rd->core_listener, &core_events, rd); + + rd->registry = pw_core_get_registry(rd->core, PW_VERSION_REGISTRY, 0); + pw_registry_add_listener(rd->registry, + &rd->registry_listener, + ®istry_events, rd); + + rd->prompt_pending = pw_core_sync(rd->core, 0, 0); + + return true; +} + static bool parse(struct data *data, char *buf, size_t size, char **error) { char *a[2]; @@ -1615,7 +1558,7 @@ static void do_input(void *data, int fd, uint32_t mask) } if (r == 0) { fprintf(stdout, "\n"); - pw_main_loop_quit(d->loop); + pw_main_loop_quit(d->main_loop); return; } buf[r] = '\0'; @@ -1625,7 +1568,7 @@ static void do_input(void *data, int fd, uint32_t mask) free(error); } if (d->current == NULL) - pw_main_loop_quit(d->loop); + pw_main_loop_quit(d->main_loop); else { struct remote_data *rd = d->current; if (rd->core) @@ -1637,42 +1580,32 @@ static void do_input(void *data, int fd, uint32_t mask) static void do_quit(void *data, int signal_number) { struct data *d = data; - pw_main_loop_quit(d->loop); + pw_main_loop_quit(d->main_loop); } int main(int argc, char *argv[]) { struct data data = { 0 }; - struct pw_loop *l; - const struct pw_core_info *info; char *error, args[128]; pw_init(&argc, &argv); - data.loop = pw_main_loop_new(NULL); - l = pw_main_loop_get_loop(data.loop); - pw_loop_add_signal(l, SIGINT, do_quit, &data); - pw_loop_add_signal(l, SIGTERM, do_quit, &data); + data.main_loop = pw_main_loop_new(NULL); + data.loop = pw_main_loop_get_loop(data.main_loop); + pw_loop_add_signal(data.loop, SIGINT, do_quit, &data); + pw_loop_add_signal(data.loop, SIGTERM, do_quit, &data); spa_list_init(&data.remotes); pw_map_init(&data.vars, 64, 16); - data.core = pw_impl_core_new(l, pw_properties_new(PW_KEY_CORE_DAEMON, "1", NULL), 0); - info = pw_impl_core_get_info(data.core); - - pw_impl_module_load(data.core, "libpipewire-module-link-factory", NULL, NULL); - - pw_loop_add_io(l, STDIN_FILENO, SPA_IO_IN|SPA_IO_HUP, false, do_input, &data); - - fprintf(stdout, "Welcome to PipeWire \"%s\" version %s. Type 'help' for usage.\n", info->name, info->version); + pw_loop_add_io(data.loop, STDIN_FILENO, SPA_IO_IN|SPA_IO_HUP, false, do_input, &data); - snprintf(args, sizeof(args), "%s", info->name); + args[0] = 0; do_connect(&data, "connect", args, &error); - pw_main_loop_run(data.loop); + pw_main_loop_run(data.main_loop); - pw_impl_core_destroy(data.core); - pw_main_loop_destroy(data.loop); + pw_main_loop_destroy(data.main_loop); return 0; } |