proxy: use 0 as the core resource

Make it possible to insert and object with a fixed id for the proxy.
Make it possible to choose an id for a resource.
This commit is contained in:
Wim Taymans 2017-03-14 16:15:09 +01:00
parent 3e472c2dae
commit ff659ad1a7
3 changed files with 24 additions and 8 deletions

View file

@ -46,20 +46,25 @@ pinos_resource_new (PinosClient *client,
this->type = type;
this->object = object;
this->destroy = destroy;
this->id = id;
pinos_signal_init (&this->destroy_signal);
if (!pinos_map_insert_at (&client->objects, this->id, this)) {
pinos_log_debug ("resource %p: id %u in use for client %p", this, id, client);
free (impl);
return NULL;
}
if (id == SPA_ID_INVALID) {
this->id = pinos_map_insert_new (&client->objects, this);
} else if (!pinos_map_insert_at (&client->objects, id, this))
goto in_use;
this->id = id;
pinos_log_debug ("resource %p: new for client %p id %u", this, client, this->id);
pinos_signal_emit (&client->resource_added, client, this);
return this;
in_use:
pinos_log_debug ("resource %p: id %u in use for client %p", this, id, client);
free (impl);
return NULL;
}
void