Wp.Properties¶
Fields¶
None
Methods¶
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- class Wp.Properties¶
Wp.Properties
is a data structure that contains string key-value pairs, which are used to send/receive/attach arbitrary properties to PipeWire objects. This could be thought of as a hash table with strings as both keys and values. However, the reason that this class exists instead of usingGLib.HashTable
directly is that in reality it wraps the PipeWire native struct spa_dict and struct pw_properties and therefore it can be easily passed to PipeWire function calls that require a struct spa_dict * or a struct pw_properties * as arguments. Or alternatively, it can easily wrap a struct spa_dict * or a struct pw_properties * that was given from the PipeWire API without necessarily doing an expensive copy operation.Wp.Properties
normally wraps a struct pw_properties, unless it was created withWp.Properties.new_wrap_dict
(), in which case it wraps a struct spa_dict and it is immutable (you cannot add/remove/modify any key-value pair). In most cases, it actually owns the struct pw_properties internally and manages its lifetime. The exception to that rule is whenWp.Properties
is constructed withWp.Properties.new_wrap
(), in which case the ownership of the struct pw_properties remains outside. This must be used with care, as the struct pw_properties may be free’ed externally.Wp.Properties
is reference-counted withWp.Properties.ref
() andWp.Properties.unref
().- classmethod new_copy(props)¶
- Parameters:
props (
object
orNone
) – a native pw_properties structure to copy- Returns:
the newly constructed properties set
- Return type:
Constructs a new
Wp.Properties
that contains a copy of all the properties contained in the given props structure.
- classmethod new_copy_dict(dict)¶
- Parameters:
- Returns:
the newly constructed properties set
- Return type:
Constructs a new
Wp.Properties
that contains a copy of all the properties contained in the given dict structure.
- classmethod new_empty()¶
- Returns:
the newly constructed properties set
- Return type:
Creates a new empty properties set.
- classmethod new_json(json)¶
- Parameters:
json (
Wp.SpaJson
) – a JSON object- Returns:
the newly constructed properties set
- Return type:
Constructs a new properties set that contains the properties that can be parsed from the given JSON object.
- classmethod new_string(str)¶
- Parameters:
str (
str
) – a string containing either a whitespace separated list of key=value pairs (ex. “key1=value1 key2=value2”) or a JSON object (ex. ‘{“key1”:”value1”}’)- Returns:
the newly constructed properties set
- Return type:
Constructs a new properties set that contains the properties that can be parsed from the given string.
- classmethod new_take(props)¶
- Parameters:
props (
object
orNone
) – a native pw_properties structure to wrap- Returns:
the newly constructed properties set
- Return type:
Constructs a new
Wp.Properties
that wraps the given props structure, allowing reading & writing properties on that props structure through theWp.Properties
API.In constrast with
Wp.Properties.new_wrap
(), this function assumes ownership of the props structure, so it will try to free props when it is destroyed.
- classmethod new_wrap(props)¶
- Parameters:
props (
object
orNone
) – a native pw_properties structure to wrap- Returns:
the newly constructed properties set
- Return type:
Constructs a new
Wp.Properties
that wraps the given props structure, allowing reading properties on that props structure through theWp.Properties
API.Care must be taken when using this function, since the returned
Wp.Properties
object does not own the props structure. Therefore, if the owner decides to free props, the returnedWp.Properties
will crash when used. In addition, the returnedWp.Properties
object will not try to free props when destroyed. Furthermore, note that the returnedWp.Properties
object is immutable. That means that you cannot add or modify any properties on it, unless you make a copy first.
- classmethod new_wrap_dict(dict)¶
- Parameters:
- Returns:
the newly constructed properties set
- Return type:
Constructs a new
Wp.Properties
that wraps the given dict structure, allowing reading properties from that dict through theWp.Properties
API.Note that the returned object does not own the dict, so care must be taken not to free it externally while this
Wp.Properties
object is alive. In addition, note that the returnedWp.Properties
object is immutable. That means that you cannot add or modify any properties on it, since there is no defined method for modifying a struct spa_dict. If you need to change this properties set later, you should make a copy withWp.Properties.copy
().
- add(props)¶
- Parameters:
props (
Wp.Properties
) – a properties set that contains properties to add- Returns:
the number of properties that were changed
- Return type:
Adds new properties in self, using the given props as a source.
Properties (keys) from props that are already contained in self are not modified, unlike what happens with
Wp.Properties.update
(). Properties in self that are not contained in props are left untouched.
- add_from_dict(dict)¶
- Parameters:
dict (
object
orNone
) – a spa_dict that contains properties to add- Returns:
the number of properties that were changed
- Return type:
Adds new properties in self, using the given dict as a source.
Properties (keys) from dict that are already contained in self are not modified, unlike what happens with
Wp.Properties.update_from_dict
(). Properties in self that are not contained in dict are left untouched.
- add_keys_array(props, keys)¶
- Parameters:
props (
Wp.Properties
) – a properties set that contains properties to addkeys ([
str
]) – the properties to add
- Returns:
the number of properties that were changed
- Return type:
The same as wp_properties_add_keys(), using a
None
-terminated array for specifying the keys to add.
- copy()¶
- Returns:
the newly constructed properties set
- Return type:
Constructs and returns a new
Wp.Properties
object that contains a copy of all the properties contained in self.
- ensure_unique_owner()¶
- Returns:
the uniquely owned properties object
- Return type:
Ensures that the given properties set is uniquely owned.
“Uniquely owned” means that:
its reference count is 1
it is not wrapping a native spa_dict or pw_properties object
If self is not uniquely owned already, then it is unrefed and a copy of it is returned instead. You should always consider self as unsafe to use after this call and you should use the returned object instead.
- get(key)¶
- Parameters:
key (
str
) – a property key- Returns:
the value of the property identified with key, or
None
if this property is not contained in self- Return type:
Looks up a given property value from a key.
- get_count()¶
- Returns:
the number of properties contained in this object
- Return type:
Gets the number of properties contained in this object.
New in version 0.4.10.
- matches(other)¶
- Parameters:
other (
Wp.Properties
) – a set of properties to match- Returns:
True
if all matches were successfull,False
if at least one property value did not match- Return type:
Checks if all property values contained in other are matching with the values in self.
If a property is contained in other and not in self, the result is not matched. If a property is contained in both sets, then the value of the property in other is interpreted as a glob-style pattern (using
GLib.pattern_match_simple
()) and the value in self is checked to see if it matches with this pattern.
- new_iterator()¶
- Returns:
an iterator that iterates over the properties. The items in the iterator are of type
Wp.PropertiesItem
. UseWp.PropertiesItem.get_key
() andWp.PropertiesItem.get_value
() to retrieve their contents.- Return type:
Iterates through all the properties in the properties object.
- peek_dict()¶
-
Gets the dictionary wrapped by a properties object.
- ref()¶
- Return type:
- set(key, value)¶
- Parameters:
- Returns:
1 if the property was changed. 0 if nothing was changed because the property already existed with the same value or because the key to remove did not exist.
- Return type:
Sets the given property key - value pair on self.
If the property already existed, the value is overwritten with the new one. If the value is
None
, then the specified property is removed from self
- sort()¶
Sorts the keys in alphabetical order.
- to_pw_properties()¶
-
Gets a copy of the properties object as a struct pw_properties
- unref()¶
Decreases the reference count on self and frees it when the ref count reaches zero.
- unref_and_take_pw_properties()¶
-
Similar to
Wp.Properties.to_pw_properties
(), but this method avoids making a copy of the properties by returning the struct pw_properties that is stored internally and then freeing theWp.Properties
wrapper.If self is not uniquely owned (see
Wp.Properties.ensure_unique_owner
()), then this method does make a copy and is the same asWp.Properties.to_pw_properties
(), performance-wise.
- update(props)¶
- Parameters:
props (
Wp.Properties
) – a properties set that contains properties to update- Returns:
the number of properties that were changed
- Return type:
Updates (adds new or modifies existing) properties in self, using the given props as a source.
Any properties that are not contained in props are left untouched.
- update_from_dict(dict)¶
- Parameters:
dict (
object
orNone
) – a spa_dict that contains properties to update- Returns:
the number of properties that were changed
- Return type:
Updates (adds new or modifies existing) properties in self, using the given dict as a source.
Any properties that are not contained in dict are left untouched.
- update_from_json(json)¶
- Parameters:
json (
Wp.SpaJson
) – a JSON object that contains properties to update- Returns:
the number of properties that were changed
- Return type:
Updates (adds new or modifies existing) properties in self, using the given json as a source.
Any properties that are not contained in json are left untouched.
- update_keys_array(props, keys)¶
- Parameters:
props (
Wp.Properties
) – a properties set that contains properties to updatekeys ([
str
]) – the properties to update
- Returns:
the number of properties that were changed
- Return type:
The same as wp_properties_update_keys(), using a
None
-terminated array for specifying the keys to update.