opt_to_gvar: support SR_T_KEYVALUE
authorBartosz Golaszewski <bgolaszewski@baylibre.com>
Thu, 4 Dec 2014 16:27:07 +0000 (17:27 +0100)
committerUwe Hermann <uwe@hermann-uwe.de>
Sat, 3 Jan 2015 18:15:59 +0000 (19:15 +0100)
The key-value data type is not supported as a configuration option. Implement
its support as a GLib dictionary.

Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
session.c

index 7bae91ac5c920235b71ed680cc517c4c1c80ba3d..b0241969b7481a8ff4f2c765d68e2ca44c34f718 100644 (file)
--- 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);