mirror of
				https://gitlab.freedesktop.org/pipewire/pipewire.git
				synced 2025-11-03 09:01:54 -05:00 
			
		
		
		
	properties: add pw_properties_add(_keys)
Add method to only add properties when they don't already exist.
This commit is contained in:
		
							parent
							
								
									3e1eeb1c03
								
							
						
					
					
						commit
						7a69c07afc
					
				
					 2 changed files with 58 additions and 0 deletions
				
			
		| 
						 | 
					@ -267,6 +267,59 @@ int pw_properties_update(struct pw_properties *props,
 | 
				
			||||||
	return changed;
 | 
						return changed;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Add properties
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * \param props properties to add
 | 
				
			||||||
 | 
					 * \param dict new properties
 | 
				
			||||||
 | 
					 * \return the number of added properties
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * The properties from \a dict that are not yet in \a props are added.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * \memberof pw_properties
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					SPA_EXPORT
 | 
				
			||||||
 | 
					int pw_properties_add(struct pw_properties *props,
 | 
				
			||||||
 | 
							         const struct spa_dict *dict)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						uint32_t i;
 | 
				
			||||||
 | 
						int added = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; i < dict->n_items; i++) {
 | 
				
			||||||
 | 
							if (pw_properties_get(props, dict->items[i].key) == NULL)
 | 
				
			||||||
 | 
								added += pw_properties_set(props, dict->items[i].key, dict->items[i].value);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return added;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/** Add keys
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * \param props properties to add
 | 
				
			||||||
 | 
					 * \param dict new properties
 | 
				
			||||||
 | 
					 * \param keys a NULL terminated list of keys to add
 | 
				
			||||||
 | 
					 * \return the number of added properties
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * The properties with \a keys from \a dict that are not yet
 | 
				
			||||||
 | 
					 * in \a props are added.
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * \memberof pw_properties
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					SPA_EXPORT
 | 
				
			||||||
 | 
					int pw_properties_add_keys(struct pw_properties *props,
 | 
				
			||||||
 | 
							const struct spa_dict *dict, const char *keys[])
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						uint32_t i;
 | 
				
			||||||
 | 
						int added = 0;
 | 
				
			||||||
 | 
						const char *str;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for (i = 0; keys[i]; i++) {
 | 
				
			||||||
 | 
							if ((str = spa_dict_lookup(dict, keys[i])) == NULL)
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if (pw_properties_get(props, keys[i]) == NULL)
 | 
				
			||||||
 | 
								added += pw_properties_set(props, keys[i], str);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return added;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Free a properties object
 | 
					/** Free a properties object
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * \param properties the properties to free
 | 
					 * \param properties the properties to free
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -63,6 +63,11 @@ int pw_properties_update_keys(struct pw_properties *props,
 | 
				
			||||||
int pw_properties_update(struct pw_properties *oldprops,
 | 
					int pw_properties_update(struct pw_properties *oldprops,
 | 
				
			||||||
		     const struct spa_dict *dict);
 | 
							     const struct spa_dict *dict);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					int pw_properties_add(struct pw_properties *oldprops,
 | 
				
			||||||
 | 
							     const struct spa_dict *dict);
 | 
				
			||||||
 | 
					int pw_properties_add_keys(struct pw_properties *oldprops,
 | 
				
			||||||
 | 
							     const struct spa_dict *dict, const char *keys[]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void pw_properties_clear(struct pw_properties *properties);
 | 
					void pw_properties_clear(struct pw_properties *properties);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue