global: add the object.serial property for globals

Make sure the lower 32 bits of the serial are never SPA_ID_INVALID. This
makes it possible for applications that need a unique 32 bits number to
use the lower bits while still having an invalid 32 bit serial number.
This commit is contained in:
Wim Taymans 2021-11-22 16:30:00 +01:00
parent 59c4975750
commit 53548aee75
2 changed files with 10 additions and 1 deletions

View file

@ -135,7 +135,12 @@ int pw_global_register(struct pw_global *global)
spa_list_append(&context->global_list, &global->link);
global->registered = true;
global->serial = ++serial;
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);

View file

@ -64,6 +64,10 @@ extern "C" {
/** object properties */
#define PW_KEY_OBJECT_PATH "object.path" /**< unique path to construct the object */
#define PW_KEY_OBJECT_ID "object.id" /**< a global object id */
#define PW_KEY_OBJECT_SERIAL "object.serial" /**< a 64 bit object serial number. This is a number
* incremented for each object that is created.
* The lower 32 bits are guaranteed to never be
* SPA_ID_INVALID. */
#define PW_KEY_OBJECT_LINGER "object.linger" /**< the object lives on even after the client
* that created it has been destroyed */
#define PW_KEY_OBJECT_REGISTER "object.register" /**< If the object should be registered. */