mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
global: add registering signal
Add a new signal that can be used to register child objects
This commit is contained in:
parent
23dbf76e85
commit
592cdfe90d
2 changed files with 45 additions and 26 deletions
|
|
@ -29,8 +29,9 @@
|
||||||
#include <pipewire/global.h>
|
#include <pipewire/global.h>
|
||||||
|
|
||||||
/** \cond */
|
/** \cond */
|
||||||
struct global_impl {
|
struct impl {
|
||||||
struct pw_global this;
|
struct pw_global this;
|
||||||
|
bool registered;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** \endcond */
|
/** \endcond */
|
||||||
|
|
@ -64,10 +65,10 @@ pw_global_new(struct pw_core *core,
|
||||||
struct pw_properties *properties,
|
struct pw_properties *properties,
|
||||||
void *object)
|
void *object)
|
||||||
{
|
{
|
||||||
struct global_impl *impl;
|
struct impl *impl;
|
||||||
struct pw_global *this;
|
struct pw_global *this;
|
||||||
|
|
||||||
impl = calloc(1, sizeof(struct global_impl));
|
impl = calloc(1, sizeof(struct impl));
|
||||||
if (impl == NULL)
|
if (impl == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
@ -78,12 +79,13 @@ pw_global_new(struct pw_core *core,
|
||||||
this->version = version;
|
this->version = version;
|
||||||
this->object = object;
|
this->object = object;
|
||||||
this->properties = properties;
|
this->properties = properties;
|
||||||
this->id = SPA_ID_INVALID;
|
this->id = pw_map_insert_new(&core->globals, this);
|
||||||
|
|
||||||
spa_hook_list_init(&this->listener_list);
|
spa_hook_list_init(&this->listener_list);
|
||||||
|
|
||||||
pw_log_debug("global %p: new %s", this,
|
pw_log_debug("global %p: new %s %d", this,
|
||||||
spa_type_map_get_type(core->type.map, this->type));
|
spa_type_map_get_type(core->type.map, this->type),
|
||||||
|
this->id);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -102,6 +104,7 @@ pw_global_register(struct pw_global *global,
|
||||||
struct pw_client *owner,
|
struct pw_client *owner,
|
||||||
struct pw_global *parent)
|
struct pw_global *parent)
|
||||||
{
|
{
|
||||||
|
struct impl *impl = SPA_CONTAINER_OF(global, struct impl, this);
|
||||||
struct pw_resource *registry;
|
struct pw_resource *registry;
|
||||||
struct pw_core *core = global->core;
|
struct pw_core *core = global->core;
|
||||||
|
|
||||||
|
|
@ -114,12 +117,8 @@ pw_global_register(struct pw_global *global,
|
||||||
parent = global;
|
parent = global;
|
||||||
global->parent = parent;
|
global->parent = parent;
|
||||||
|
|
||||||
global->id = pw_map_insert_new(&core->globals, global);
|
|
||||||
|
|
||||||
spa_list_append(&core->global_list, &global->link);
|
spa_list_append(&core->global_list, &global->link);
|
||||||
|
impl->registered = true;
|
||||||
pw_log_debug("global %p: add %u owner %p parent %p", global, global->id, owner, parent);
|
|
||||||
spa_hook_list_call(&core->listener_list, struct pw_core_events, global_added, global);
|
|
||||||
|
|
||||||
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(global, registry->client);
|
uint32_t permissions = pw_global_get_permissions(global, registry->client);
|
||||||
|
|
@ -134,6 +133,37 @@ pw_global_register(struct pw_global *global,
|
||||||
global->properties ?
|
global->properties ?
|
||||||
&global->properties->dict : NULL);
|
&global->properties->dict : NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
spa_hook_list_call(&global->listener_list, struct pw_global_events, registering);
|
||||||
|
|
||||||
|
pw_log_debug("global %p: add %u owner %p parent %p", global, global->id, owner, parent);
|
||||||
|
spa_hook_list_call(&core->listener_list, struct pw_core_events, global_added, global);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int global_unregister(struct pw_global *global)
|
||||||
|
{
|
||||||
|
struct impl *impl = SPA_CONTAINER_OF(global, struct impl, this);
|
||||||
|
struct pw_core *core = global->core;
|
||||||
|
struct pw_resource *registry;
|
||||||
|
|
||||||
|
if (!impl->registered)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
spa_list_remove(&global->link);
|
||||||
|
spa_hook_list_call(&core->listener_list, struct pw_core_events,
|
||||||
|
global_removed, global);
|
||||||
|
|
||||||
|
impl->registered = false;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -230,24 +260,13 @@ pw_global_bind(struct pw_global *global, struct pw_client *client, uint32_t perm
|
||||||
void pw_global_destroy(struct pw_global *global)
|
void pw_global_destroy(struct pw_global *global)
|
||||||
{
|
{
|
||||||
struct pw_core *core = global->core;
|
struct pw_core *core = global->core;
|
||||||
struct pw_resource *registry;
|
|
||||||
|
global_unregister(global);
|
||||||
|
|
||||||
pw_log_debug("global %p: destroy %u", global, global->id);
|
pw_log_debug("global %p: destroy %u", global, global->id);
|
||||||
spa_hook_list_call(&global->listener_list, struct pw_global_events, destroy);
|
spa_hook_list_call(&global->listener_list, struct pw_global_events, destroy);
|
||||||
|
|
||||||
if (global->id != SPA_ID_INVALID) {
|
pw_map_remove(&core->globals, global->id);
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
pw_map_remove(&core->globals, global->id);
|
|
||||||
|
|
||||||
spa_list_remove(&global->link);
|
|
||||||
spa_hook_list_call(&core->listener_list, struct pw_core_events, global_removed, global);
|
|
||||||
}
|
|
||||||
|
|
||||||
pw_log_debug("global %p: free", global);
|
pw_log_debug("global %p: free", global);
|
||||||
spa_hook_list_call(&global->listener_list, struct pw_global_events, free);
|
spa_hook_list_call(&global->listener_list, struct pw_global_events, free);
|
||||||
|
|
|
||||||
|
|
@ -60,9 +60,9 @@ struct pw_global_events {
|
||||||
#define PW_VERSION_GLOBAL_EVENTS 0
|
#define PW_VERSION_GLOBAL_EVENTS 0
|
||||||
uint32_t version;
|
uint32_t version;
|
||||||
|
|
||||||
|
void (*registering) (void *data);
|
||||||
/** The global is destroyed */
|
/** The global is destroyed */
|
||||||
void (*destroy) (void *data);
|
void (*destroy) (void *data);
|
||||||
|
|
||||||
/** The global is freed */
|
/** The global is freed */
|
||||||
void (*free) (void *data);
|
void (*free) (void *data);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue