From 73eea244432fe118950d920e632e0ff13a950dc6 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 11 Dec 2019 17:19:12 +0100 Subject: [PATCH] impl-client: improve constructor Pass the protocol in constructor Keep the link in the server protocol list private to the prototol. --- src/modules/module-protocol-native.c | 31 +++++++++++++--------------- src/pipewire/impl-client.c | 8 +++++++ src/pipewire/impl-client.h | 9 +++++--- src/pipewire/impl-node.h | 2 +- src/pipewire/private.h | 1 - 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/modules/module-protocol-native.c b/src/modules/module-protocol-native.c index fc0bfe7f1..3e91415af 100644 --- a/src/modules/module-protocol-native.c +++ b/src/modules/module-protocol-native.c @@ -108,6 +108,8 @@ struct client_data { struct pw_impl_client *client; struct spa_hook client_listener; + struct spa_list protocol_link; + struct spa_source *source; struct pw_protocol_native_connection *connection; struct spa_hook conn_listener; @@ -261,7 +263,7 @@ connection_data(void *data, int fd, uint32_t mask) if (res >= 0) { int mask = this->source->mask; SPA_FLAG_CLEAR(mask, SPA_IO_OUT); - pw_loop_update_io(client->protocol->context->main_loop, + pw_loop_update_io(client->context->main_loop, this->source, mask); } else if (res != EAGAIN) { pw_log_error("client %p: could not flush: %s", @@ -279,10 +281,10 @@ static void client_free(void *data) struct client_data *this = data; struct pw_impl_client *client = this->client; - spa_list_remove(&client->protocol_link); + spa_list_remove(&this->protocol_link); if (this->source) - pw_loop_destroy_source(client->protocol->context->main_loop, this->source); + pw_loop_destroy_source(client->context->main_loop, this->source); if (this->connection) pw_protocol_native_connection_destroy(this->connection); @@ -356,15 +358,13 @@ static struct client_data *client_new(struct server *s, int fd) pw_properties_setf(props, PW_KEY_MODULE_ID, "%d", d->module->global->id); client = pw_impl_client_new(protocol->context, - props, - sizeof(struct client_data)); + protocol, props, sizeof(struct client_data)); if (client == NULL) goto exit; this = pw_impl_client_get_user_data(client); - client->protocol = protocol; - spa_list_append(&s->this.client_list, &client->protocol_link); + spa_list_append(&s->this.client_list, &this->protocol_link); this->client = client; this->source = pw_loop_add_io(pw_context_get_main_loop(context), @@ -868,13 +868,13 @@ error_free: static void destroy_server(struct pw_protocol_server *server) { struct server *s = SPA_CONTAINER_OF(server, struct server, this); - struct pw_impl_client *client, *tmp; + struct client_data *data, *tmp; spa_list_remove(&server->link); spa_hook_remove(&s->hook); - spa_list_for_each_safe(client, tmp, &server->client_list, protocol_link) - pw_impl_client_destroy(client); + spa_list_for_each_safe(data, tmp, &server->client_list, protocol_link) + pw_impl_client_destroy(data->client); if (s->source) { spa_hook_remove(&s->hook); @@ -893,23 +893,20 @@ static void on_before_hook(void *_data) { struct server *server = _data; struct pw_protocol_server *this = &server->this; - struct pw_impl_client *client, *tmp; - struct client_data *data; + struct client_data *data, *tmp; int res; - spa_list_for_each_safe(client, tmp, &this->client_list, protocol_link) { - data = client->user_data; - + spa_list_for_each_safe(data, tmp, &this->client_list, protocol_link) { res = pw_protocol_native_connection_flush(data->connection); if (res == -EAGAIN) { int mask = data->source->mask; SPA_FLAG_SET(mask, SPA_IO_OUT); - pw_loop_update_io(client->protocol->context->main_loop, + pw_loop_update_io(data->client->context->main_loop, data->source, mask); } else if (res < 0) { pw_log_warn("client %p: could not flush: %s", data->client, spa_strerror(res)); - pw_impl_client_destroy(client); + pw_impl_client_destroy(data->client); } } diff --git a/src/pipewire/impl-client.c b/src/pipewire/impl-client.c index 4e2b55428..b517355be 100644 --- a/src/pipewire/impl-client.c +++ b/src/pipewire/impl-client.c @@ -281,6 +281,7 @@ static const struct pw_context_events context_events = { */ SPA_EXPORT struct pw_impl_client *pw_impl_client_new(struct pw_context *context, + struct pw_protocol *protocol, struct pw_properties *properties, size_t user_data_size) { @@ -299,6 +300,7 @@ struct pw_impl_client *pw_impl_client_new(struct pw_context *context, pw_log_debug(NAME" %p: new", this); this->context = context; + this->protocol = protocol; if (properties == NULL) properties = pw_properties_new(NULL, NULL); @@ -428,6 +430,12 @@ struct pw_context *pw_impl_client_get_context(struct pw_impl_client *client) return client->context; } +SPA_EXPORT +struct pw_protocol *pw_impl_client_get_protocol(struct pw_impl_client *client) +{ + return client->protocol; +} + SPA_EXPORT struct pw_resource *pw_impl_client_get_core_resource(struct pw_impl_client *client) { diff --git a/src/pipewire/impl-client.h b/src/pipewire/impl-client.h index d79996a42..a7f0464a6 100644 --- a/src/pipewire/impl-client.h +++ b/src/pipewire/impl-client.h @@ -110,9 +110,10 @@ struct pw_impl_client_events { /** Create a new client. This is mainly used by protocols. */ struct pw_impl_client * -pw_impl_client_new(struct pw_context *context, /**< the context object */ - struct pw_properties *properties, /**< client properties */ - size_t user_data_size /**< extra user data size */); +pw_impl_client_new(struct pw_context *context, /**< the context object */ + struct pw_protocol *prototol, /**< the client protocol */ + struct pw_properties *properties, /**< client properties */ + size_t user_data_size /**< extra user data size */); /** Destroy a previously created client */ void pw_impl_client_destroy(struct pw_impl_client *client); @@ -139,6 +140,8 @@ const struct pw_properties *pw_impl_client_get_properties(struct pw_impl_client /** Get the context used to create this client */ struct pw_context *pw_impl_client_get_context(struct pw_impl_client *client); +/** Get the protocol used to create this client */ +struct pw_protocol *pw_impl_client_get_protocol(struct pw_impl_client *client); /** Get the client context resource */ struct pw_resource *pw_impl_client_get_core_resource(struct pw_impl_client *client); diff --git a/src/pipewire/impl-node.h b/src/pipewire/impl-node.h index 0e9f7a327..1ee2b7909 100644 --- a/src/pipewire/impl-node.h +++ b/src/pipewire/impl-node.h @@ -99,7 +99,7 @@ struct pw_impl_node_events { /** Create a new node \memberof pw_impl_node */ struct pw_impl_node * -pw_impl_node_new(struct pw_context *context, /**< the context */ +pw_impl_node_new(struct pw_context *context, /**< the context */ struct pw_properties *properties, /**< extra properties */ size_t user_data_size /**< user data size */); diff --git a/src/pipewire/private.h b/src/pipewire/private.h index 4d6a85b95..6926f9bdb 100644 --- a/src/pipewire/private.h +++ b/src/pipewire/private.h @@ -117,7 +117,6 @@ struct pw_impl_client { struct spa_hook_list listener_list; struct pw_protocol *protocol; /**< protocol in use */ - struct spa_list protocol_link; /**< link in the protocol client_list */ int recv_seq; /**< last received sequence number */ int send_seq; /**< last sender sequence number */