mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-08 13:30:08 -05:00
global: separate create and register
That way we can place the global in the wrapped object before we emit the new_global object and have things work better.
This commit is contained in:
parent
155243a27c
commit
d50037c2f7
8 changed files with 88 additions and 61 deletions
|
|
@ -209,10 +209,13 @@ void pw_client_register(struct pw_client *client,
|
||||||
|
|
||||||
pw_log_debug("client %p: register parent %d", client, parent ? parent->id : SPA_ID_INVALID);
|
pw_log_debug("client %p: register parent %d", client, parent ? parent->id : SPA_ID_INVALID);
|
||||||
spa_list_append(&core->client_list, &client->link);
|
spa_list_append(&core->client_list, &client->link);
|
||||||
client->global = pw_core_add_global(core, owner, parent, core->type.client, PW_VERSION_CLIENT,
|
|
||||||
|
client->global = pw_global_new(core, core->type.client, PW_VERSION_CLIENT,
|
||||||
client_bind_func, client);
|
client_bind_func, client);
|
||||||
if (client->global != NULL)
|
if (client->global != NULL) {
|
||||||
|
pw_global_register(client->global, owner, parent);
|
||||||
client->info.id = client->global->id;
|
client->info.id = client->global->id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pw_core *pw_client_get_core(struct pw_client *client)
|
struct pw_core *pw_client_get_core(struct pw_client *client)
|
||||||
|
|
|
||||||
|
|
@ -388,15 +388,15 @@ struct pw_core *pw_core_new(struct pw_loop *main_loop, struct pw_properties *pro
|
||||||
|
|
||||||
this->sc_pagesize = sysconf(_SC_PAGESIZE);
|
this->sc_pagesize = sysconf(_SC_PAGESIZE);
|
||||||
|
|
||||||
this->global = pw_core_add_global(this,
|
this->global = pw_global_new(this,
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
this->type.core,
|
this->type.core,
|
||||||
PW_VERSION_CORE,
|
PW_VERSION_CORE,
|
||||||
core_bind_func,
|
core_bind_func,
|
||||||
this);
|
this);
|
||||||
if (this->global != NULL)
|
if (this->global != NULL) {
|
||||||
|
pw_global_register(this->global, NULL, NULL);
|
||||||
this->info.id = this->global->id;
|
this->info.id = this->global->id;
|
||||||
|
}
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,10 +122,12 @@ void pw_factory_register(struct pw_factory *factory,
|
||||||
{
|
{
|
||||||
struct pw_core *core = factory->core;
|
struct pw_core *core = factory->core;
|
||||||
spa_list_append(&core->factory_list, &factory->link);
|
spa_list_append(&core->factory_list, &factory->link);
|
||||||
factory->global = pw_core_add_global(core, owner, parent,
|
factory->global = pw_global_new(core,
|
||||||
core->type.factory, 0, factory_bind_func, factory);
|
core->type.factory, 0, factory_bind_func, factory);
|
||||||
if (factory->global != NULL)
|
if (factory->global != NULL) {
|
||||||
|
pw_global_register(factory->global, owner, parent);
|
||||||
factory->info.id = factory->global->id;
|
factory->info.id = factory->global->id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void *pw_factory_get_user_data(struct pw_factory *factory)
|
void *pw_factory_get_user_data(struct pw_factory *factory)
|
||||||
|
|
|
||||||
|
|
@ -48,24 +48,19 @@ uint32_t pw_global_get_permissions(struct pw_global *global, struct pw_client *c
|
||||||
return perms;
|
return perms;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Create and add a new global to the core
|
/** Create a new global
|
||||||
*
|
*
|
||||||
* \param core a core
|
* \param core a core object
|
||||||
* \param owner an optional owner of the global
|
|
||||||
* \param type the type of the global
|
* \param type the type of the global
|
||||||
* \param n_ifaces number of interfaces
|
* \param version the version of the type
|
||||||
* \param ifaces interface information
|
|
||||||
* \param object the associated object
|
|
||||||
* \param bind a function to bind to this global
|
* \param bind a function to bind to this global
|
||||||
* \param[out] global a result global
|
* \param object the associated object
|
||||||
* \return true on success
|
* \return a result global
|
||||||
*
|
*
|
||||||
* \memberof pw_core
|
* \memberof pw_global
|
||||||
*/
|
*/
|
||||||
struct pw_global *
|
struct pw_global *
|
||||||
pw_core_add_global(struct pw_core *core,
|
pw_global_new(struct pw_core *core,
|
||||||
struct pw_client *owner,
|
|
||||||
struct pw_global *parent,
|
|
||||||
uint32_t type,
|
uint32_t type,
|
||||||
uint32_t version,
|
uint32_t version,
|
||||||
pw_bind_func_t bind,
|
pw_bind_func_t bind,
|
||||||
|
|
@ -73,7 +68,6 @@ pw_core_add_global(struct pw_core *core,
|
||||||
{
|
{
|
||||||
struct global_impl *impl;
|
struct global_impl *impl;
|
||||||
struct pw_global *this;
|
struct pw_global *this;
|
||||||
struct pw_resource *registry;
|
|
||||||
|
|
||||||
impl = calloc(1, sizeof(struct global_impl));
|
impl = calloc(1, sizeof(struct global_impl));
|
||||||
if (impl == NULL)
|
if (impl == NULL)
|
||||||
|
|
@ -82,40 +76,62 @@ pw_core_add_global(struct pw_core *core,
|
||||||
this = &impl->this;
|
this = &impl->this;
|
||||||
|
|
||||||
this->core = core;
|
this->core = core;
|
||||||
this->owner = owner;
|
|
||||||
this->type = type;
|
this->type = type;
|
||||||
this->version = version;
|
this->version = version;
|
||||||
this->bind = bind;
|
this->bind = bind;
|
||||||
this->object = object;
|
this->object = object;
|
||||||
|
|
||||||
this->id = pw_map_insert_new(&core->globals, this);
|
pw_log_debug("global %p: new %s", this,
|
||||||
|
spa_type_map_get_type(core->type.map, this->type));
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** register a global to the core registry
|
||||||
|
*
|
||||||
|
* \param global a global to add
|
||||||
|
* \param owner an optional owner client of the global
|
||||||
|
* \param parent an optional parent of the global
|
||||||
|
* \return 0 on success < 0 errno value on failure
|
||||||
|
*
|
||||||
|
* \memberof pw_global
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
pw_global_register(struct pw_global *global,
|
||||||
|
struct pw_client *owner,
|
||||||
|
struct pw_global *parent)
|
||||||
|
{
|
||||||
|
struct pw_resource *registry;
|
||||||
|
struct pw_core *core = global->core;
|
||||||
|
|
||||||
|
global->owner = owner;
|
||||||
if (owner)
|
if (owner)
|
||||||
parent = owner->global;
|
parent = owner->global;
|
||||||
if (parent == NULL)
|
if (parent == NULL)
|
||||||
parent = core->global;
|
parent = core->global;
|
||||||
if (parent == NULL)
|
if (parent == NULL)
|
||||||
parent = this;
|
parent = global;
|
||||||
this->parent = parent;
|
global->parent = parent;
|
||||||
|
|
||||||
spa_list_append(&core->global_list, &this->link);
|
global->id = pw_map_insert_new(&core->globals, global);
|
||||||
|
|
||||||
spa_hook_list_call(&core->listener_list, struct pw_core_events, global_added, this);
|
spa_list_append(&core->global_list, &global->link);
|
||||||
|
|
||||||
pw_log_debug("global %p: new %u %s, owner %p", this, this->id,
|
spa_hook_list_call(&core->listener_list, struct pw_core_events, global_added, global);
|
||||||
spa_type_map_get_type(core->type.map, this->type), owner);
|
|
||||||
|
pw_log_debug("global %p: add %u owner %p parent %p", global, global->id, owner, parent);
|
||||||
|
|
||||||
spa_list_for_each(registry, &core->registry_resource_list, link) {
|
spa_list_for_each(registry, &core->registry_resource_list, link) {
|
||||||
uint32_t permissions = pw_global_get_permissions(this, registry->client);
|
uint32_t permissions = pw_global_get_permissions(global, registry->client);
|
||||||
if (PW_PERM_IS_R(permissions))
|
if (PW_PERM_IS_R(permissions))
|
||||||
pw_registry_resource_global(registry,
|
pw_registry_resource_global(registry,
|
||||||
this->id,
|
global->id,
|
||||||
this->parent->id,
|
global->parent->id,
|
||||||
permissions,
|
permissions,
|
||||||
this->type,
|
global->type,
|
||||||
this->version);
|
global->version);
|
||||||
}
|
}
|
||||||
return this;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct pw_core *pw_global_get_core(struct pw_global *global)
|
struct pw_core *pw_global_get_core(struct pw_global *global)
|
||||||
|
|
@ -123,7 +139,6 @@ struct pw_core *pw_global_get_core(struct pw_global *global)
|
||||||
return global->core;
|
return global->core;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct pw_client *pw_global_get_owner(struct pw_global *global)
|
struct pw_client *pw_global_get_owner(struct pw_global *global)
|
||||||
{
|
{
|
||||||
return global->owner;
|
return global->owner;
|
||||||
|
|
|
||||||
|
|
@ -61,16 +61,19 @@ typedef int (*pw_bind_func_t) (struct pw_global *global, /**< the global to bind
|
||||||
uint32_t version, /**< client interface version */
|
uint32_t version, /**< client interface version */
|
||||||
uint32_t id /**< client proxy id */);
|
uint32_t id /**< client proxy id */);
|
||||||
|
|
||||||
/** Add a new global object to the core registry */
|
/** Create a new global object */
|
||||||
struct pw_global *
|
struct pw_global *
|
||||||
pw_core_add_global(struct pw_core *core,
|
pw_global_new(struct pw_core *core,
|
||||||
struct pw_client *owner,
|
|
||||||
struct pw_global *parent,
|
|
||||||
uint32_t type,
|
uint32_t type,
|
||||||
uint32_t version,
|
uint32_t version,
|
||||||
pw_bind_func_t bind,
|
pw_bind_func_t bind,
|
||||||
void *object);
|
void *object);
|
||||||
|
|
||||||
|
/** Register a global object to the core registry */
|
||||||
|
int pw_global_register(struct pw_global *global,
|
||||||
|
struct pw_client *owner,
|
||||||
|
struct pw_global *parent);
|
||||||
|
|
||||||
/** Get the permissions of the global for a given client */
|
/** Get the permissions of the global for a given client */
|
||||||
uint32_t pw_global_get_permissions(struct pw_global *global, struct pw_client *client);
|
uint32_t pw_global_get_permissions(struct pw_global *global, struct pw_client *client);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1207,10 +1207,12 @@ void pw_link_register(struct pw_link *link,
|
||||||
|
|
||||||
spa_list_append(&core->link_list, &link->link);
|
spa_list_append(&core->link_list, &link->link);
|
||||||
|
|
||||||
link->global = pw_core_add_global(core, owner, parent, core->type.link, PW_VERSION_LINK,
|
link->global = pw_global_new(core, core->type.link, PW_VERSION_LINK,
|
||||||
link_bind_func, link);
|
link_bind_func, link);
|
||||||
if (link->global != NULL)
|
if (link->global != NULL) {
|
||||||
|
pw_global_register(link->global, owner, parent);
|
||||||
link->info.id = link->global->id;
|
link->info.id = link->global->id;
|
||||||
|
}
|
||||||
|
|
||||||
input_node = link->input->node;
|
input_node = link->input->node;
|
||||||
output_node = link->output->node;
|
output_node = link->output->node;
|
||||||
|
|
|
||||||
|
|
@ -219,12 +219,13 @@ struct pw_module *pw_module_load(struct pw_core *core, const char *name, const c
|
||||||
this->info.props = NULL;
|
this->info.props = NULL;
|
||||||
|
|
||||||
spa_list_append(&core->module_list, &this->link);
|
spa_list_append(&core->module_list, &this->link);
|
||||||
this->global = pw_core_add_global(core, NULL, core->global,
|
this->global = pw_global_new(core, core->type.module, PW_VERSION_MODULE,
|
||||||
core->type.module, PW_VERSION_MODULE,
|
|
||||||
module_bind_func, this);
|
module_bind_func, this);
|
||||||
|
|
||||||
if (this->global != NULL)
|
if (this->global != NULL) {
|
||||||
|
pw_global_register(this->global, NULL, core->global);
|
||||||
this->info.id = this->global->id;
|
this->info.id = this->global->id;
|
||||||
|
}
|
||||||
|
|
||||||
if ((res = init_func(this, args)) < 0)
|
if ((res = init_func(this, args)) < 0)
|
||||||
goto init_failed;
|
goto init_failed;
|
||||||
|
|
|
||||||
|
|
@ -343,11 +343,12 @@ void pw_node_register(struct pw_node *this,
|
||||||
pw_loop_invoke(this->data_loop, do_node_add, 1, NULL, 0, false, this);
|
pw_loop_invoke(this->data_loop, do_node_add, 1, NULL, 0, false, this);
|
||||||
|
|
||||||
spa_list_append(&core->node_list, &this->link);
|
spa_list_append(&core->node_list, &this->link);
|
||||||
this->global = pw_core_add_global(core, owner, parent,
|
this->global = pw_global_new(core, core->type.node, PW_VERSION_NODE,
|
||||||
core->type.node, PW_VERSION_NODE,
|
|
||||||
node_bind_func, this);
|
node_bind_func, this);
|
||||||
if (this->global != NULL)
|
if (this->global != NULL) {
|
||||||
|
pw_global_register(this->global, owner, parent);
|
||||||
this->info.id = this->global->id;
|
this->info.id = this->global->id;
|
||||||
|
}
|
||||||
|
|
||||||
spa_hook_list_call(&this->listener_list, struct pw_node_events, initialized);
|
spa_hook_list_call(&this->listener_list, struct pw_node_events, initialized);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue