| 1 |
/* WirePlumber |
| 2 |
* |
| 3 |
* Copyright © 2022 Collabora Ltd. |
| 4 |
* @author Ashok Sidipotu <[email protected]> |
| 5 |
* |
| 6 |
* SPDX-License-Identifier: MIT |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef __WIREPLUMBER_SETTINGS_H__ |
| 10 |
#define __WIREPLUMBER_SETTINGS_H__ |
| 11 |
|
| 12 |
#include "object.h" |
| 13 |
#include "spa-json.h" |
| 14 |
|
| 15 |
#define WP_SETTINGS_SCHEMA_METADATA_NAME_PREFIX "schema-" |
| 16 |
#define WP_SETTINGS_PERSISTENT_METADATA_NAME_PREFIX "persistent-" |
| 17 |
|
| 18 |
G_BEGIN_DECLS |
| 19 |
|
| 20 |
/*! |
| 21 |
* \brief The different spec types of a setting |
| 22 |
* \ingroup wpsettings |
| 23 |
*/ |
| 24 |
typedef enum { |
| 25 |
WP_SETTINGS_SPEC_TYPE_UNKNOWN, |
| 26 |
WP_SETTINGS_SPEC_TYPE_BOOL, |
| 27 |
WP_SETTINGS_SPEC_TYPE_INT, |
| 28 |
WP_SETTINGS_SPEC_TYPE_FLOAT, |
| 29 |
WP_SETTINGS_SPEC_TYPE_STRING, |
| 30 |
WP_SETTINGS_SPEC_TYPE_ARRAY, |
| 31 |
WP_SETTINGS_SPEC_TYPE_OBJECT, |
| 32 |
} WpSettingsSpecType; |
| 33 |
|
| 34 |
typedef struct _WpSettingsSpec WpSettingsSpec; |
| 35 |
|
| 36 |
/*! |
| 37 |
* \brief The WpSettingsSpec GType |
| 38 |
* \ingroup wpsettings |
| 39 |
*/ |
| 40 |
#define WP_TYPE_SETTINGS_SPEC (wp_settings_spec_get_type ()) |
| 41 |
WP_API |
| 42 |
GType wp_settings_spec_get_type (void); |
| 43 |
|
| 44 |
WP_API |
| 45 |
WpSettingsSpec *wp_settings_spec_ref (WpSettingsSpec * self); |
| 46 |
|
| 47 |
WP_API |
| 48 |
void wp_settings_spec_unref (WpSettingsSpec * self); |
| 49 |
|
| 50 |
WP_API |
| 51 |
const gchar * wp_settings_spec_get_name (WpSettingsSpec * self); |
| 52 |
|
| 53 |
WP_API |
| 54 |
const gchar * wp_settings_spec_get_description (WpSettingsSpec * self); |
| 55 |
|
| 56 |
WP_API |
| 57 |
WpSettingsSpecType wp_settings_spec_get_value_type (WpSettingsSpec * self); |
| 58 |
|
| 59 |
WP_API |
| 60 |
WpSpaJson * wp_settings_spec_get_default_value (WpSettingsSpec * self); |
| 61 |
|
| 62 |
WP_API |
| 63 |
WpSpaJson * wp_settings_spec_get_min_value (WpSettingsSpec * self); |
| 64 |
|
| 65 |
WP_API |
| 66 |
WpSpaJson * wp_settings_spec_get_max_value (WpSettingsSpec * self); |
| 67 |
|
| 68 |
WP_API |
| 69 |
gboolean wp_settings_spec_check_value (WpSettingsSpec * self, WpSpaJson *value); |
| 70 |
|
| 71 |
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WpSettingsSpec, wp_settings_spec_unref) |
| 72 |
|
| 73 |
/*! |
| 74 |
* \brief The WpSettingsItem GType |
| 75 |
* \ingroup wpsettings |
| 76 |
*/ |
| 77 |
#define WP_TYPE_SETTINGS_ITEM (wp_settings_item_get_type ()) |
| 78 |
WP_API |
| 79 |
GType wp_settings_item_get_type (void); |
| 80 |
|
| 81 |
typedef struct _WpSettingsItem WpSettingsItem; |
| 82 |
|
| 83 |
WP_API |
| 84 |
WpSettingsItem *wp_settings_item_ref (WpSettingsItem *self); |
| 85 |
|
| 86 |
WP_API |
| 87 |
void wp_settings_item_unref (WpSettingsItem *self); |
| 88 |
|
| 89 |
WP_API |
| 90 |
const gchar * wp_settings_item_get_key (WpSettingsItem * self); |
| 91 |
|
| 92 |
WP_API |
| 93 |
WpSpaJson * wp_settings_item_get_value (WpSettingsItem * self); |
| 94 |
|
| 95 |
G_DEFINE_AUTOPTR_CLEANUP_FUNC (WpSettingsItem, wp_settings_item_unref) |
| 96 |
|
| 97 |
/*! |
| 98 |
* \brief Flags to be used as WpObjectFeatures on WpSettings subclasses. |
| 99 |
* \ingroup wpsettings |
| 100 |
*/ |
| 101 |
typedef enum { /*< flags >*/ |
| 102 |
/*! Loads the settings */ |
| 103 |
WP_SETTINGS_LOADED = (1 << 0), |
| 104 |
} WpSettingsFeatures; |
| 105 |
|
| 106 |
/*! |
| 107 |
* \brief The WpSettings GType |
| 108 |
* \ingroup wpsettings |
| 109 |
*/ |
| 110 |
#define WP_TYPE_SETTINGS (wp_settings_get_type ()) |
| 111 |
|
| 112 |
WP_API |
| 113 |
G_DECLARE_FINAL_TYPE (WpSettings, wp_settings, WP, SETTINGS, WpObject) |
| 114 |
|
| 115 |
WP_API |
| 116 |
WpSettings * wp_settings_new (WpCore * core, const gchar * metadata_name); |
| 117 |
|
| 118 |
WP_API |
| 119 |
WpSettings * wp_settings_find (WpCore * core, const gchar * metadata_name); |
| 120 |
|
| 121 |
/*! |
| 122 |
* \brief callback conveying the changed setting and its json value |
| 123 |
* |
| 124 |
* \ingroup wpsettings |
| 125 |
* \param obj the wpsettings object |
| 126 |
* \param setting the changed setting |
| 127 |
* \param value json value of the the changed setting |
| 128 |
* \param user_data data passed in the \a wp_settings_subscribe |
| 129 |
*/ |
| 130 |
typedef void (*WpSettingsChangedCallback) (WpSettings *obj, |
| 131 |
const gchar *setting, WpSpaJson *value, gpointer user_data); |
| 132 |
|
| 133 |
WP_API |
| 134 |
guintptr wp_settings_subscribe (WpSettings *self, |
| 135 |
const gchar *pattern, WpSettingsChangedCallback callback, |
| 136 |
gpointer user_data); |
| 137 |
|
| 138 |
WP_API |
| 139 |
guintptr wp_settings_subscribe_closure (WpSettings *self, |
| 140 |
const gchar *pattern, GClosure * closure); |
| 141 |
|
| 142 |
WP_API |
| 143 |
gboolean wp_settings_unsubscribe (WpSettings *self, |
| 144 |
guintptr subscription_id); |
| 145 |
|
| 146 |
WP_API |
| 147 |
WpSpaJson * wp_settings_get (WpSettings *self, const gchar *name); |
| 148 |
|
| 149 |
WP_API |
| 150 |
WpSpaJson * wp_settings_get_saved (WpSettings *self, const gchar *name); |
| 151 |
|
| 152 |
WP_API |
| 153 |
WpSettingsSpec * wp_settings_get_spec (WpSettings *self, const gchar *name); |
| 154 |
|
| 155 |
WP_API |
| 156 |
gboolean wp_settings_set (WpSettings *self, const gchar *name, |
| 157 |
WpSpaJson *value); |
| 158 |
|
| 159 |
WP_API |
| 160 |
gboolean wp_settings_reset (WpSettings *self, const char *name); |
| 161 |
|
| 162 |
WP_API |
| 163 |
gboolean wp_settings_save (WpSettings *self, const char *name); |
| 164 |
|
| 165 |
WP_API |
| 166 |
gboolean wp_settings_delete (WpSettings *self, const char *name); |
| 167 |
|
| 168 |
WP_API |
| 169 |
void wp_settings_reset_all (WpSettings *self); |
| 170 |
|
| 171 |
WP_API |
| 172 |
void wp_settings_save_all (WpSettings *self); |
| 173 |
|
| 174 |
WP_API |
| 175 |
void wp_settings_delete_all (WpSettings *self); |
| 176 |
|
| 177 |
WP_API |
| 178 |
WpIterator * wp_settings_new_iterator (WpSettings *self); |
| 179 |
|
| 180 |
G_END_DECLS |
| 181 |
|
| 182 |
#endif |