wireplumber/lib/wp/settings.h
Julian Bouzas 2223cd47d4 settings: use WpSpaJson to parse the settings
We need to use WpSpaJson to parse the values in WpSettings. This is because the
wireplumber configuration is written in JSON, so WpSettings should only hold
JSON values. To fix this, 2 API changes have been done:

- wp_settings_get_int() only accepts gint values, instead of gint64 values. This
is because the WpSpaJson API only parses int values, like spa_json_parse_int().

- wp_settings_get_string() now returns a newly allocated string, this is because
the string needs to be decoded in case it has quotes.
2023-04-17 07:47:09 -04:00

88 lines
2.1 KiB
C

/* WirePlumber
*
* Copyright © 2022 Collabora Ltd.
* @author Ashok Sidipotu <ashok.sidipotu@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#ifndef __WIREPLUMBER_SETTINGS_H__
#define __WIREPLUMBER_SETTINGS_H__
#include "object.h"
#include "spa-json.h"
G_BEGIN_DECLS
/*!
* \brief Flags to be used as WpObjectFeatures on WpSettings subclasses.
* \ingroup wpsettings
*/
typedef enum { /*< flags >*/
/*! Loads the settings */
WP_SETTINGS_LOADED = (1 << 0),
} WpSettingsFeatures;
/*!
* \brief The WpSettings GType
* \ingroup wpsettings
*/
#define WP_TYPE_SETTINGS (wp_settings_get_type ())
WP_API
G_DECLARE_FINAL_TYPE (WpSettings, wp_settings, WP, SETTINGS, WpObject)
WP_API
WpSettings * wp_settings_get_instance (WpCore * core,
const gchar *metadata_name);
/*!
* \brief callback conveying the changed setting and its string(raw) value
*
* \ingroup wpsettings
* \param obj the wpsettings object
* \param setting the changed setting
* \param raw_value string value of the the changed setting
* \param user_data data passed in the \a wp_settings_subscribe
*/
typedef void (*WpSettingsChangedCallback) (WpSettings *obj,
const gchar *setting, const gchar *raw_value, gpointer user_data);
WP_API
guintptr wp_settings_subscribe (WpSettings *self,
const gchar *pattern, WpSettingsChangedCallback callback,
gpointer user_data);
WP_API
guintptr wp_settings_subscribe_closure (WpSettings *self,
const gchar *pattern, GClosure * closure);
WP_API
gboolean wp_settings_unsubscribe (WpSettings *self,
guintptr subscription_id);
WP_API
gboolean wp_settings_get_boolean (WpSettings *self, const gchar *setting,
gboolean *value);
WP_API
gchar * wp_settings_get_string (WpSettings *self, const gchar *setting);
WP_API
gboolean wp_settings_get_int (WpSettings *self, const gchar *setting,
gint *value);
WP_API
gboolean wp_settings_get_float (WpSettings *self, const gchar *setting,
gfloat *value);
WP_API
WpSpaJson * wp_settings_get (WpSettings *self, const gchar *setting);
WP_API
gboolean wp_settings_apply_rule (WpSettings *self, const gchar *rule,
WpProperties *client_props, WpProperties *applied_props);
G_END_DECLS
#endif