mirror of
https://gitlab.freedesktop.org/pipewire/wireplumber.git
synced 2025-12-20 15:50:03 +01:00
main: use WpSpaJson when loading components
This commit is contained in:
parent
a68a7cec0e
commit
2f186c10e7
1 changed files with 17 additions and 22 deletions
39
src/main.c
39
src/main.c
|
|
@ -130,38 +130,33 @@ do_load_components(void *data, const char *location, const char *section,
|
||||||
struct data *d = data;
|
struct data *d = data;
|
||||||
WpTransition *transition = d->transition;
|
WpTransition *transition = d->transition;
|
||||||
WpCore *core = wp_transition_get_source_object (transition);
|
WpCore *core = wp_transition_get_source_object (transition);
|
||||||
struct spa_json it[3];
|
struct spa_json spa_json;
|
||||||
char key[512];
|
g_autoptr (WpSpaJson) json = NULL;
|
||||||
|
g_autoptr (WpIterator) it = NULL;
|
||||||
|
g_auto (GValue) item = G_VALUE_INIT;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
spa_json_init(&it[0], str, len);
|
spa_json_init(&spa_json, str, len);
|
||||||
|
json = wp_spa_json_new_wrap (&spa_json);
|
||||||
|
|
||||||
if (spa_json_enter_array(&it[0], &it[1]) < 0) {
|
if (!wp_spa_json_is_array (json)) {
|
||||||
wp_transition_return_error (transition, g_error_new (
|
wp_transition_return_error (transition, g_error_new (
|
||||||
WP_DOMAIN_DAEMON, WP_EXIT_CONFIG,
|
WP_DOMAIN_DAEMON, WP_EXIT_CONFIG,
|
||||||
"wireplumber.components is not a JSON array"));
|
"wireplumber.components is not a JSON array"));
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (spa_json_enter_object(&it[1], &it[2]) > 0) {
|
it = wp_spa_json_new_iterator (json);
|
||||||
char *name = NULL, *type = NULL;
|
for (; wp_iterator_next (it, &item); g_value_unset (&item)) {
|
||||||
|
WpSpaJson *o = g_value_get_boxed (&item);
|
||||||
|
g_autofree gchar *name = NULL;
|
||||||
|
g_autofree gchar *type = NULL;
|
||||||
|
|
||||||
while (spa_json_get_string(&it[2], key, sizeof(key)) > 0) {
|
if (!wp_spa_json_is_object (o) ||
|
||||||
const char *val;
|
!wp_spa_json_object_get (o,
|
||||||
int len;
|
"name", "s", &name,
|
||||||
|
"type", "s", &type,
|
||||||
if ((len = spa_json_next(&it[2], &val)) <= 0)
|
NULL)) {
|
||||||
break;
|
|
||||||
|
|
||||||
if (strcmp(key, "name") == 0) {
|
|
||||||
name = (char*)val;
|
|
||||||
spa_json_parse_stringn(val, len, name, len+1);
|
|
||||||
} else if (strcmp(key, "type") == 0) {
|
|
||||||
type = (char*)val;
|
|
||||||
spa_json_parse_stringn(val, len, type, len+1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (name == NULL || type == NULL) {
|
|
||||||
wp_transition_return_error (transition, g_error_new (
|
wp_transition_return_error (transition, g_error_new (
|
||||||
WP_DOMAIN_DAEMON, WP_EXIT_CONFIG,
|
WP_DOMAIN_DAEMON, WP_EXIT_CONFIG,
|
||||||
"component must have both a 'name' and a 'type'"));
|
"component must have both a 'name' and a 'type'"));
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue