lib: add new json-utils set of functions

The purpose is to wrap some utilities that pipewire provides that use JSON.

Start by wrapping pw_conf_match_rules(), which despite its name, it has nothing
to do with the configuration object. It operates directly on JSON and can be
useful to work with match rules outside the context of configuration files.
This commit is contained in:
George Kiagiadakis
2023-11-06 12:05:08 +02:00
parent d45c5eb623
commit 89ac416e99
6 changed files with 537 additions and 0 deletions

38
lib/wp/json-utils.h Normal file
View File

@@ -0,0 +1,38 @@
/* WirePlumber
*
* Copyright © 2023 Collabora Ltd.
* @author George Kiagiadakis <george.kiagiadakis@collabora.com>
*
* SPDX-License-Identifier: MIT
*/
#ifndef __WIREPLUMBER_JSON_UTILS_H__
#define __WIREPLUMBER_JSON_UTILS_H__
#include "spa-json.h"
#include "properties.h"
G_BEGIN_DECLS
/*!
* \brief A function to be called by wp_json_utils_match_rules() when a match is found.
* \param data (closure): the user data passed to wp_json_utils_match_rules()
* \param action the rule's action string
* \param value the value associated with this action
* \param error (out): return location for a GError
* \returns FALSE if an error occurred and the match process should stop, TRUE otherwise
* \ingroup wpjsonutils
*/
typedef gboolean (*WpRuleMatchCallback) (gpointer data, const gchar * action,
WpSpaJson * value, GError ** error);
WP_API
gboolean wp_json_utils_match_rules (WpSpaJson * json, WpProperties * match_props,
WpRuleMatchCallback callback, gpointer data, GError ** error);
WP_API
gint wp_json_utils_match_rules_update_properties (WpSpaJson *json, WpProperties *props);
G_END_DECLS
#endif