mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2026-01-07 01:30:13 +01:00
properties: add json to properties converters
This commit is contained in:
parent
add310d9eb
commit
f878e2f62d
2 changed files with 49 additions and 0 deletions
|
|
@ -146,6 +146,26 @@ wp_properties_new_string (const gchar * str)
|
|||
return self;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new properties set that contains the properties that can
|
||||
* be parsed from the given JSON object
|
||||
*
|
||||
* \ingroup wpproperties
|
||||
* \param json a JSON object
|
||||
* \returns (transfer full): the newly constructed properties set
|
||||
*/
|
||||
WpProperties *
|
||||
wp_properties_new_json (const WpSpaJson * json)
|
||||
{
|
||||
WpProperties * self;
|
||||
|
||||
g_return_val_if_fail (json != NULL, NULL);
|
||||
|
||||
self = wp_properties_new_empty ();
|
||||
wp_properties_update_from_json (self, json);
|
||||
return self;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Constructs a new WpProperties that wraps the given \a props structure,
|
||||
* allowing reading properties on that \a props structure through
|
||||
|
|
@ -398,6 +418,28 @@ wp_properties_update_from_dict (WpProperties * self,
|
|||
return pw_properties_update (self->props, dict);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Updates (adds new or modifies existing) properties in \a self,
|
||||
* using the given \a json as a source.
|
||||
*
|
||||
* Any properties that are not contained in \a json are left untouched.
|
||||
*
|
||||
* \ingroup wpproperties
|
||||
* \param self a properties object
|
||||
* \param json a JSON object that contains properties to update
|
||||
* \returns the number of properties that were changed
|
||||
*/
|
||||
gint
|
||||
wp_properties_update_from_json (WpProperties * self, const WpSpaJson * json)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, -EINVAL);
|
||||
g_return_val_if_fail (!(self->flags & FLAG_IS_DICT), -EINVAL);
|
||||
g_return_val_if_fail (!(self->flags & FLAG_NO_OWNERSHIP), -EINVAL);
|
||||
|
||||
return pw_properties_update_string (self->props, wp_spa_json_get_data (json),
|
||||
wp_spa_json_get_size (json));
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Adds new properties in \a self, using the given \a props as a source.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <glib-object.h>
|
||||
#include "defs.h"
|
||||
#include "iterator.h"
|
||||
#include "spa-json.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
|
@ -40,6 +41,9 @@ WpProperties * wp_properties_new_valist (const gchar * key, va_list args);
|
|||
WP_API
|
||||
WpProperties * wp_properties_new_string (const gchar * str);
|
||||
|
||||
WP_API
|
||||
WpProperties * wp_properties_new_json (const WpSpaJson * json);
|
||||
|
||||
WP_API
|
||||
WpProperties * wp_properties_new_wrap (const struct pw_properties * props);
|
||||
|
||||
|
|
@ -78,6 +82,9 @@ WP_API
|
|||
gint wp_properties_update_from_dict (WpProperties * self,
|
||||
const struct spa_dict * dict);
|
||||
|
||||
WP_API
|
||||
gint wp_properties_update_from_json (WpProperties * self, const WpSpaJson * json);
|
||||
|
||||
/* add */
|
||||
|
||||
WP_API
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue