From: Bartosz Golaszewski Date: Thu, 4 Dec 2014 16:27:07 +0000 (+0100) Subject: opt_to_gvar: support SR_T_KEYVALUE X-Git-Tag: sigrok-cli-0.6.0~47 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=e45889373bd907f0b760aab531787d87bf2bf691;p=sigrok-cli.git opt_to_gvar: support SR_T_KEYVALUE The key-value data type is not supported as a configuration option. Implement its support as a GLib dictionary. Signed-off-by: Bartosz Golaszewski --- diff --git a/session.c b/session.c index 7bae91a..b024196 100644 --- a/session.c +++ b/session.c @@ -326,7 +326,9 @@ int opt_to_gvar(char *key, char *value, struct sr_config *src) double tmp_double, dlow, dhigh; uint64_t tmp_u64, p, q, low, high; GVariant *rational[2], *range[2]; + GVariantBuilder *vbl; gboolean tmp_bool; + gchar **keyval; int ret; if (!(srci = sr_config_info_name_get(key))) { @@ -403,6 +405,21 @@ int opt_to_gvar(char *key, char *value, struct sr_config *src) src->data = g_variant_new_tuple(range, 2); } break; + case SR_T_KEYVALUE: + /* Expects the argument to be in the form of key=value. */ + keyval = g_strsplit(value, "=", 2); + if (!keyval[0] || !keyval[1]) { + g_strfreev(keyval); + ret = -1; + break; + } else { + vbl = g_variant_builder_new(G_VARIANT_TYPE_DICTIONARY); + g_variant_builder_add(vbl, "{ss}", + keyval[0], keyval[1]); + src->data = g_variant_builder_end(vbl); + g_strfreev(keyval); + } + break; default: g_critical("Unknown data type specified for option '%s' " "(driver implementation bug?).", key);