global: place object.serial in object info

Make a method to return or allocate the serial for a global.
When the global is unregistered, a new serial is calculated.
Place the serial in the object info and the global info.
This commit is contained in:
Wim Taymans 2021-11-22 17:13:10 +01:00
parent 53548aee75
commit e7f9046bb8
15 changed files with 51 additions and 6 deletions

View file

@ -304,6 +304,8 @@ int endpoint_stream_init(struct endpoint_stream *this,
pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u",
pw_global_get_id(this->global));
pw_properties_setf(this->props, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(this->global));
this->info.version = PW_VERSION_ENDPOINT_STREAM_INFO;
this->info.id = pw_global_get_id(this->global);

View file

@ -305,6 +305,7 @@ int endpoint_init(struct endpoint *this,
struct pw_properties *properties)
{
static const char * const keys[] = {
PW_KEY_OBJECT_SERIAL,
PW_KEY_FACTORY_ID,
PW_KEY_CLIENT_ID,
PW_KEY_DEVICE_ID,
@ -333,6 +334,8 @@ int endpoint_init(struct endpoint *this,
pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u",
pw_global_get_id(this->global));
pw_properties_setf(this->props, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(this->global));
this->info.version = PW_VERSION_ENDPOINT_INFO;
this->info.id = pw_global_get_id(this->global);

View file

@ -322,6 +322,8 @@ int endpoint_link_init(struct endpoint_link *this,
pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u",
pw_global_get_id(this->global));
pw_properties_setf(this->props, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(this->global));
this->info.version = PW_VERSION_ENDPOINT_LINK_INFO;
this->info.id = pw_global_get_id(this->global);

View file

@ -276,6 +276,7 @@ int session_init(struct session *this,
struct pw_properties *properties)
{
static const char * const keys[] = {
PW_KEY_OBJECT_SERIAL,
PW_KEY_FACTORY_ID,
PW_KEY_CLIENT_ID,
NULL
@ -295,6 +296,8 @@ int session_init(struct session *this,
pw_properties_setf(this->props, PW_KEY_OBJECT_ID, "%u",
pw_global_get_id(this->global));
pw_properties_setf(this->props, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(this->global));
this->info.version = PW_VERSION_SESSION_INFO;
this->info.id = pw_global_get_id(this->global);

View file

@ -102,6 +102,7 @@ pw_global_new(struct pw_context *context,
pw_log_error("%p: can't allocate new id: %m", this);
goto error_free;
}
this->serial = SPA_ID_INVALID;
spa_list_init(&this->resource_list);
spa_hook_list_init(&this->listener_list);
@ -118,6 +119,16 @@ error_cleanup:
return NULL;
}
SPA_EXPORT
uint64_t pw_global_get_serial(struct pw_global *global)
{
if (global->serial == SPA_ID_INVALID)
global->serial = serial++;
if ((uint32_t)serial == SPA_ID_INVALID)
serial++;
return global->serial;
}
/** register a global to the context registry
*
* \param global a global to add
@ -135,12 +146,6 @@ int pw_global_register(struct pw_global *global)
spa_list_append(&context->global_list, &global->link);
global->registered = true;
global->serial = serial++;
if ((uint32_t)serial == SPA_ID_INVALID)
serial++;
pw_properties_setf(global->properties,
PW_KEY_OBJECT_SERIAL, "%"PRIu64, global->serial);
spa_list_for_each(registry, &context->registry_resource_list, link) {
uint32_t permissions = pw_global_get_permissions(global, registry->client);
@ -178,6 +183,7 @@ static int global_unregister(struct pw_global *global)
spa_list_remove(&global->link);
global->registered = false;
global->serial = SPA_ID_INVALID;
pw_log_debug("%p: unregistered %u", global, global->id);
pw_context_emit_global_removed(context, global);

View file

@ -127,6 +127,9 @@ void *pw_global_get_object(struct pw_global *global);
/** Get the unique id of the global */
uint32_t pw_global_get_id(struct pw_global *global);
/** Get the serial number of the global */
uint64_t pw_global_get_serial(struct pw_global *global);
/** Add a resource to a global */
int pw_global_add_resource(struct pw_global *global, struct pw_resource *resource);

View file

@ -475,6 +475,7 @@ int pw_impl_client_register(struct pw_impl_client *client,
struct pw_properties *properties)
{
static const char * const keys[] = {
PW_KEY_OBJECT_SERIAL,
PW_KEY_MODULE_ID,
PW_KEY_PROTOCOL,
PW_KEY_SEC_PID,
@ -505,6 +506,8 @@ int pw_impl_client_register(struct pw_impl_client *client,
client->info.id = client->global->id;
pw_properties_setf(client->properties, PW_KEY_OBJECT_ID, "%d", client->info.id);
pw_properties_setf(client->properties, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(client->global));
client->info.props = &client->properties->dict;
pw_global_add_listener(client->global, &client->global_listener, &global_events, client);

View file

@ -581,6 +581,7 @@ int pw_impl_core_register(struct pw_impl_core *core,
struct pw_properties *properties)
{
static const char * const keys[] = {
PW_KEY_OBJECT_SERIAL,
PW_KEY_USER_NAME,
PW_KEY_HOST_NAME,
PW_KEY_CORE_NAME,
@ -608,6 +609,8 @@ int pw_impl_core_register(struct pw_impl_core *core,
core->info.id = core->global->id;
pw_properties_setf(core->properties, PW_KEY_OBJECT_ID, "%d", core->info.id);
pw_properties_setf(core->properties, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(core->global));
core->info.props = &core->properties->dict;
pw_global_update_keys(core->global, core->info.props, keys);

View file

@ -556,6 +556,7 @@ int pw_impl_device_register(struct pw_impl_device *device,
struct pw_properties *properties)
{
static const char * const keys[] = {
PW_KEY_OBJECT_SERIAL,
PW_KEY_OBJECT_PATH,
PW_KEY_MODULE_ID,
PW_KEY_FACTORY_ID,
@ -588,6 +589,8 @@ int pw_impl_device_register(struct pw_impl_device *device,
device->info.id = device->global->id;
pw_properties_setf(device->properties, PW_KEY_OBJECT_ID, "%d", device->info.id);
pw_properties_setf(device->properties, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(device->global));
device->info.props = &device->properties->dict;
pw_global_update_keys(device->global, device->info.props, keys);

View file

@ -178,6 +178,7 @@ int pw_impl_factory_register(struct pw_impl_factory *factory,
struct pw_properties *properties)
{
static const char * const keys[] = {
PW_KEY_OBJECT_SERIAL,
PW_KEY_MODULE_ID,
PW_KEY_FACTORY_NAME,
PW_KEY_FACTORY_TYPE_NAME,
@ -204,6 +205,8 @@ int pw_impl_factory_register(struct pw_impl_factory *factory,
factory->info.id = factory->global->id;
pw_properties_setf(factory->properties, PW_KEY_OBJECT_ID, "%d", factory->info.id);
pw_properties_setf(factory->properties, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(factory->global));
pw_properties_set(factory->properties, PW_KEY_FACTORY_NAME, factory->info.name);
pw_properties_setf(factory->properties, PW_KEY_FACTORY_TYPE_NAME, "%s", factory->info.type);
pw_properties_setf(factory->properties, PW_KEY_FACTORY_TYPE_VERSION, "%d", factory->info.version);

View file

@ -1343,6 +1343,7 @@ int pw_impl_link_register(struct pw_impl_link *link,
struct pw_properties *properties)
{
static const char * const keys[] = {
PW_KEY_OBJECT_SERIAL,
PW_KEY_OBJECT_PATH,
PW_KEY_MODULE_ID,
PW_KEY_FACTORY_ID,
@ -1382,6 +1383,8 @@ int pw_impl_link_register(struct pw_impl_link *link,
link->info.id = link->global->id;
pw_properties_setf(link->properties, PW_KEY_OBJECT_ID, "%d", link->info.id);
pw_properties_setf(link->properties, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(link->global));
pw_properties_setf(link->properties, PW_KEY_LINK_OUTPUT_NODE, "%u", link->info.output_node_id);
pw_properties_setf(link->properties, PW_KEY_LINK_OUTPUT_PORT, "%u", link->info.output_port_id);
pw_properties_setf(link->properties, PW_KEY_LINK_INPUT_NODE, "%u", link->info.input_node_id);

View file

@ -546,6 +546,9 @@ int pw_impl_metadata_register(struct pw_impl_metadata *metadata,
spa_list_append(&context->metadata_list, &metadata->link);
metadata->registered = true;
pw_properties_setf(metadata->properties, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(metadata->global));
pw_global_update_keys(metadata->global, &metadata->properties->dict, keys);
pw_global_add_listener(metadata->global, &metadata->global_listener, &global_events, metadata);

View file

@ -247,6 +247,8 @@ pw_context_load_module(struct pw_context *context,
this->info.id = this->global->id;
pw_properties_setf(this->properties, PW_KEY_OBJECT_ID, "%d", this->info.id);
pw_properties_setf(this->properties, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(this->global));
this->info.props = &this->properties->dict;
pw_impl_module_emit_initialized(this);

View file

@ -675,6 +675,7 @@ int pw_impl_node_register(struct pw_impl_node *this,
struct pw_properties *properties)
{
static const char * const keys[] = {
PW_KEY_OBJECT_SERIAL,
PW_KEY_OBJECT_PATH,
PW_KEY_MODULE_ID,
PW_KEY_FACTORY_ID,
@ -720,6 +721,8 @@ int pw_impl_node_register(struct pw_impl_node *this,
this->info.id = this->global->id;
pw_properties_setf(this->properties, PW_KEY_OBJECT_ID, "%d", this->info.id);
pw_properties_setf(this->properties, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(this->global));
this->info.props = &this->properties->dict;
pw_global_update_keys(this->global, &this->properties->dict, keys);

View file

@ -883,6 +883,7 @@ int pw_impl_port_register(struct pw_impl_port *port,
struct pw_properties *properties)
{
static const char * const keys[] = {
PW_KEY_OBJECT_SERIAL,
PW_KEY_OBJECT_PATH,
PW_KEY_FORMAT_DSP,
PW_KEY_NODE_ID,
@ -918,6 +919,8 @@ int pw_impl_port_register(struct pw_impl_port *port,
port->info.id = port->global->id;
pw_properties_setf(port->properties, PW_KEY_NODE_ID, "%d", node->global->id);
pw_properties_setf(port->properties, PW_KEY_OBJECT_ID, "%d", port->info.id);
pw_properties_setf(port->properties, PW_KEY_OBJECT_SERIAL, "%"PRIu64,
pw_global_get_serial(port->global));
port->info.props = &port->properties->dict;
pw_global_update_keys(port->global, &port->properties->dict, keys);