Skip to content
Snippets Groups Projects
Commit f9f7f6e2 authored by George Kiagiadakis's avatar George Kiagiadakis
Browse files

config: implement reading properties for modules from the config file

Properties are expected to be a GVariant a{sv} dictionary,
specified in the GVariant text format:
https://developer.gnome.org/glib/stable/gvariant-text.html
parent d02bfcd2
No related branches found
No related tags found
No related merge requests found
......@@ -99,9 +99,10 @@ parse_commands_file (struct WpDaemonData *d, GInputStream * stream,
gchar buffer[4096];
gssize bytes_read;
gchar *cur, *linestart, *saveptr;
gchar *cmd, *abi, *module;
gchar *cmd, *abi, *module, *props;
gint lineno = 1;
gboolean eof = FALSE;
GVariant *properties;
linestart = cur = buffer;
......@@ -142,7 +143,26 @@ parse_commands_file (struct WpDaemonData *d, GInputStream * stream,
return FALSE;
}
if (!wp_module_load (d->core, abi, module, NULL, error)) {
/* if there are remaining characters after the module name,
treat it as a serialized GVariant for the properties */
props = module + strlen(module) + 1;
if (cur - props > 0) {
g_autoptr (GError) tmperr = NULL;
g_autofree gchar *context = NULL;
properties = g_variant_parse (G_VARIANT_TYPE_VARDICT, props, cur,
NULL, &tmperr);
if (!properties) {
context = g_variant_parse_error_print_context (tmperr, props);
g_set_error (error, WP_DOMAIN_DAEMON, WP_CODE_INVALID_ARGUMENT,
"GVariant parse error:\n%s", context);
return FALSE;
}
} else {
properties = g_variant_new_parsed ("@a{sv} {}");
}
if (!wp_module_load (d->core, abi, module, properties, error)) {
return FALSE;
}
} else {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment