From bc35d3040707164eb949cd2e1a80df3834828403 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 19 Jan 2018 13:10:11 +0100 Subject: [PATCH] remote: add _get_fd method Add a method to get the fd of the connection. --- src/modules/module-protocol-native.c | 10 ++++++++++ src/pipewire/global.c | 2 ++ src/pipewire/protocol.h | 2 ++ src/pipewire/remote.c | 5 +++++ src/pipewire/remote.h | 3 +++ 5 files changed, 22 insertions(+) diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index d7a095dd8..e1df205b4 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -527,6 +527,15 @@ static int impl_connect(struct pw_protocol_client *client) return -1; } +static int impl_get_fd(struct pw_protocol_client *client) +{ + struct client *impl = SPA_CONTAINER_OF(client, struct client, this); + + if (impl->source == NULL) + return -EIO; + + return impl->source->fd; +} static void on_remote_data(void *data, int fd, enum spa_io mask) @@ -698,6 +707,7 @@ impl_new_client(struct pw_protocol *protocol, impl->properties = properties ? pw_properties_copy(properties) : NULL; this->connect = impl_connect; + this->get_fd = impl_get_fd; this->connect_fd = impl_connect_fd; this->disconnect = impl_disconnect; this->destroy = impl_destroy; diff --git a/src/pipewire/global.c b/src/pipewire/global.c index d28d25c8c..ee70fd9f9 100644 --- a/src/pipewire/global.c +++ b/src/pipewire/global.c @@ -127,6 +127,7 @@ pw_global_register(struct pw_global *global, spa_list_for_each(registry, &core->registry_resource_list, link) { uint32_t permissions = pw_global_get_permissions(global, registry->client); + pw_log_debug("registry %p: global %d %08x", registry, global->id, permissions); if (PW_PERM_IS_R(permissions)) pw_registry_resource_global(registry, global->id, @@ -240,6 +241,7 @@ void pw_global_destroy(struct pw_global *global) if (global->id != SPA_ID_INVALID) { spa_list_for_each(registry, &core->registry_resource_list, link) { uint32_t permissions = pw_global_get_permissions(global, registry->client); + pw_log_debug("registry %p: global %d %08x", registry, global->id, permissions); if (PW_PERM_IS_R(permissions)) pw_registry_resource_global_remove(registry, global->id); } diff --git a/src/pipewire/protocol.h b/src/pipewire/protocol.h index 77d777e09..f0b0c3880 100644 --- a/src/pipewire/protocol.h +++ b/src/pipewire/protocol.h @@ -42,12 +42,14 @@ struct pw_protocol_client { struct pw_remote *remote; /**< the associated remote */ int (*connect) (struct pw_protocol_client *client); + int (*get_fd) (struct pw_protocol_client *client); int (*connect_fd) (struct pw_protocol_client *client, int fd); void (*disconnect) (struct pw_protocol_client *client); void (*destroy) (struct pw_protocol_client *client); }; #define pw_protocol_client_connect(c) ((c)->connect(c)) +#define pw_protocol_client_get_fd(c) ((c)->get_fd(c)) #define pw_protocol_client_connect_fd(c,fd) ((c)->connect_fd(c,fd)) #define pw_protocol_client_disconnect(c) ((c)->disconnect(c)) #define pw_protocol_client_destroy(c) ((c)->destroy(c)) diff --git a/src/pipewire/remote.c b/src/pipewire/remote.c index 07d1a8bd3..6ab0076e0 100644 --- a/src/pipewire/remote.c +++ b/src/pipewire/remote.c @@ -404,6 +404,11 @@ int pw_remote_connect_fd(struct pw_remote *remote, int fd) return do_connect(remote); } +int pw_remote_get_fd(struct pw_remote *remote) +{ + return pw_protocol_client_get_fd(remote->conn); +} + int pw_remote_disconnect(struct pw_remote *remote) { struct pw_proxy *proxy, *t2; diff --git a/src/pipewire/remote.h b/src/pipewire/remote.h index fbd0070cb..4463ca1ba 100644 --- a/src/pipewire/remote.h +++ b/src/pipewire/remote.h @@ -178,6 +178,9 @@ int pw_remote_connect(struct pw_remote *remote); * \return 0 on success, < 0 on error */ int pw_remote_connect_fd(struct pw_remote *remote, int fd); +/** Get the fd of the remote connection or < 0 on error */ +int pw_remote_get_fd(struct pw_remote *remote); + /** Get the core proxy, can only be called when connected */ struct pw_core_proxy * pw_remote_get_core_proxy(struct pw_remote *remote);