mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
properties: add _update method and use it
Remove old unused _merge method
This commit is contained in:
parent
59d77818d6
commit
5d30b31cec
10 changed files with 43 additions and 63 deletions
|
|
@ -405,11 +405,11 @@ const struct pw_client_info *pw_client_get_info(struct pw_client *client)
|
|||
int pw_client_update_properties(struct pw_client *client, const struct spa_dict *dict)
|
||||
{
|
||||
struct pw_resource *resource;
|
||||
uint32_t i, changed = 0;
|
||||
int changed;
|
||||
|
||||
for (i = 0; i < dict->n_items; i++)
|
||||
changed += pw_properties_set(client->properties,
|
||||
dict->items[i].key, dict->items[i].value);
|
||||
changed = pw_properties_update(client->properties, dict);
|
||||
|
||||
pw_log_debug("client %p: updated %d properties", client, changed);
|
||||
|
||||
if (!changed)
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -589,10 +589,11 @@ const struct pw_properties *pw_core_get_properties(struct pw_core *core)
|
|||
int pw_core_update_properties(struct pw_core *core, const struct spa_dict *dict)
|
||||
{
|
||||
struct pw_resource *resource;
|
||||
uint32_t i, changed = 0;
|
||||
int changed;
|
||||
|
||||
for (i = 0; i < dict->n_items; i++)
|
||||
changed += pw_properties_set(core->properties, dict->items[i].key, dict->items[i].value);
|
||||
changed = pw_properties_update(core->properties, dict);
|
||||
|
||||
pw_log_debug("core %p: updated %d properties", core, changed);
|
||||
|
||||
if (!changed)
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -212,7 +212,7 @@ static void device_add(void *data, uint32_t id,
|
|||
struct pw_node *node;
|
||||
struct node_data *nd;
|
||||
struct pw_properties *props;
|
||||
int i, res;
|
||||
int res;
|
||||
void *iface;
|
||||
|
||||
if (type != SPA_TYPE_INTERFACE_Node) {
|
||||
|
|
@ -224,8 +224,8 @@ static void device_add(void *data, uint32_t id,
|
|||
support = pw_core_get_support(device->core, &n_support);
|
||||
|
||||
props = pw_properties_copy(device->properties);
|
||||
for (i = 0; info && i < info->n_items; i++)
|
||||
pw_properties_set(props, info->items[i].key, info->items[i].value);
|
||||
if (info)
|
||||
pw_properties_update(props, info);
|
||||
|
||||
node = pw_node_new(device->core,
|
||||
device->info.name,
|
||||
|
|
@ -313,10 +313,9 @@ const struct pw_properties *pw_device_get_properties(struct pw_device *device)
|
|||
int pw_device_update_properties(struct pw_device *device, const struct spa_dict *dict)
|
||||
{
|
||||
struct pw_resource *resource;
|
||||
uint32_t i, changed = 0;
|
||||
int changed;
|
||||
|
||||
for (i = 0; i < dict->n_items; i++)
|
||||
changed += pw_properties_set(device->properties, dict->items[i].key, dict->items[i].value);
|
||||
changed = pw_properties_update(device->properties, dict);
|
||||
|
||||
pw_log_debug("device %p: updated %d properties", device, changed);
|
||||
|
||||
|
|
|
|||
|
|
@ -335,10 +335,11 @@ const struct pw_properties *pw_module_get_properties(struct pw_module *module)
|
|||
int pw_module_update_properties(struct pw_module *module, const struct spa_dict *dict)
|
||||
{
|
||||
struct pw_resource *resource;
|
||||
uint32_t i, changed = 0;
|
||||
int changed;
|
||||
|
||||
for (i = 0; i < dict->n_items; i++)
|
||||
changed += pw_properties_set(module->properties, dict->items[i].key, dict->items[i].value);
|
||||
changed = pw_properties_update(module->properties, dict);
|
||||
|
||||
pw_log_debug("module %p: updated %d properties", module, changed);
|
||||
|
||||
if (!changed)
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -745,10 +745,9 @@ const struct pw_properties *pw_node_get_properties(struct pw_node *node)
|
|||
int pw_node_update_properties(struct pw_node *node, const struct spa_dict *dict)
|
||||
{
|
||||
struct pw_resource *resource;
|
||||
uint32_t i, changed = 0;
|
||||
int changed;
|
||||
|
||||
for (i = 0; i < dict->n_items; i++)
|
||||
changed += pw_properties_set(node->properties, dict->items[i].key, dict->items[i].value);
|
||||
changed = pw_properties_update(node->properties, dict);
|
||||
|
||||
pw_log_debug("node %p: updated %d properties", node, changed);
|
||||
|
||||
|
|
@ -968,8 +967,7 @@ void pw_node_destroy(struct pw_node *node)
|
|||
pw_map_clear(&node->input_port_map);
|
||||
pw_map_clear(&node->output_port_map);
|
||||
|
||||
if (node->properties)
|
||||
pw_properties_free(node->properties);
|
||||
pw_properties_free(node->properties);
|
||||
|
||||
clear_info(node);
|
||||
|
||||
|
|
|
|||
|
|
@ -285,10 +285,9 @@ const struct pw_properties *pw_port_get_properties(struct pw_port *port)
|
|||
int pw_port_update_properties(struct pw_port *port, const struct spa_dict *dict)
|
||||
{
|
||||
struct pw_resource *resource;
|
||||
uint32_t i, changed = 0;
|
||||
int changed;
|
||||
|
||||
for (i = 0; i < dict->n_items; i++)
|
||||
changed += pw_properties_set(port->properties, dict->items[i].key, dict->items[i].value);
|
||||
changed = pw_properties_update(port->properties, dict);
|
||||
|
||||
pw_log_debug("port %p: updated %d properties", port, changed);
|
||||
|
||||
|
|
@ -688,8 +687,7 @@ void pw_port_destroy(struct pw_port *port)
|
|||
|
||||
pw_map_clear(&port->mix_port_map);
|
||||
|
||||
if (port->properties)
|
||||
pw_properties_free(port->properties);
|
||||
pw_properties_free(port->properties);
|
||||
|
||||
free(port);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -196,42 +196,25 @@ struct pw_properties *pw_properties_copy(const struct pw_properties *properties)
|
|||
return copy;
|
||||
}
|
||||
|
||||
/** Merge properties into one
|
||||
/** Update properties
|
||||
*
|
||||
* \param oldprops properties to merge into
|
||||
* \param newprops properties to merge
|
||||
* \return a newly allocated \ref pw_properties
|
||||
* \param props properties to update
|
||||
* \param dict new properties
|
||||
* \return the number of changed properties
|
||||
*
|
||||
* A new \ref pw_properties is allocated and the properties of
|
||||
* \a oldprops and \a newprops are copied into it in that order.
|
||||
* The properties in \a props are updated with \a dict.
|
||||
*
|
||||
* \memberof pw_properties
|
||||
*/
|
||||
struct pw_properties *pw_properties_merge(const struct pw_properties *oldprops,
|
||||
const struct pw_properties *newprops)
|
||||
int pw_properties_update(struct pw_properties *props,
|
||||
const struct spa_dict *dict)
|
||||
{
|
||||
struct pw_properties *res = NULL;
|
||||
int i, changed = 0;
|
||||
|
||||
if (oldprops == NULL) {
|
||||
if (newprops == NULL)
|
||||
res = NULL;
|
||||
else
|
||||
res = pw_properties_copy(newprops);
|
||||
} else if (newprops == NULL) {
|
||||
res = pw_properties_copy(oldprops);
|
||||
} else {
|
||||
const char *key;
|
||||
void *state = NULL;
|
||||
for (i = 0; i < dict->n_items; i++)
|
||||
changed += pw_properties_set(props, dict->items[i].key, dict->items[i].value);
|
||||
|
||||
res = pw_properties_copy(oldprops);
|
||||
if (res == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((key = pw_properties_iterate(newprops, &state))) {
|
||||
pw_properties_set(res, key, pw_properties_get(newprops, key));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return changed;
|
||||
}
|
||||
|
||||
/** Free a properties object
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@ pw_properties_new_string(const char *args);
|
|||
struct pw_properties *
|
||||
pw_properties_copy(const struct pw_properties *properties);
|
||||
|
||||
struct pw_properties *
|
||||
pw_properties_merge(const struct pw_properties *oldprops,
|
||||
const struct pw_properties *newprops);
|
||||
int
|
||||
pw_properties_update(struct pw_properties *oldprops,
|
||||
const struct spa_dict *dict);
|
||||
|
||||
void
|
||||
pw_properties_free(struct pw_properties *properties);
|
||||
|
|
|
|||
|
|
@ -335,10 +335,11 @@ const struct pw_properties *pw_remote_get_properties(struct pw_remote *remote)
|
|||
|
||||
int pw_remote_update_properties(struct pw_remote *remote, const struct spa_dict *dict)
|
||||
{
|
||||
uint32_t i, changed = 0;
|
||||
int changed;
|
||||
|
||||
for (i = 0; i < dict->n_items; i++)
|
||||
changed += pw_properties_set(remote->properties, dict->items[i].key, dict->items[i].value);
|
||||
changed = pw_properties_update(remote->properties, dict);
|
||||
|
||||
pw_log_debug("remote %p: updated %d properties", remote, changed);
|
||||
|
||||
if (!changed)
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1018,10 +1018,9 @@ const struct pw_properties *pw_stream_get_properties(struct pw_stream *stream)
|
|||
int pw_stream_update_properties(struct pw_stream *stream, const struct spa_dict *dict)
|
||||
{
|
||||
struct stream *impl = SPA_CONTAINER_OF(stream, struct stream, this);
|
||||
int i, changed = 0, res = 0;
|
||||
int changed, res = 0;
|
||||
|
||||
for (i = 0; i < dict->n_items; i++)
|
||||
changed += pw_properties_set(stream->properties, dict->items[i].key, dict->items[i].value);
|
||||
changed = pw_properties_update(stream->properties, dict);
|
||||
|
||||
if (!changed)
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue