[dbus PATCH 2/3] util: Introduce virtDBusUtilGVariantToTypedParams

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This converts D-Bus dictionary into virTypedParameters.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/util.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/util.h |  6 +++++
 2 files changed, 89 insertions(+)

diff --git a/src/util.c b/src/util.c
index ac965c4..5a69c89 100644
--- a/src/util.c
+++ b/src/util.c
@@ -69,6 +69,89 @@ virtDBusUtilTypedParamsToGVariant(virTypedParameterPtr params,
     return g_variant_builder_end(&builder);
 }
 
+gboolean
+virtDBusUtilGVariantToTypedParams(GVariantIter *iter,
+                                  virTypedParameterPtr *params,
+                                  gint *nparams,
+                                  GError **error)
+{
+    g_autofree gchar *name = NULL;
+    g_autoptr(GVariant) value = NULL;
+    gint maxParams = 0;
+
+    while (g_variant_iter_loop(iter, "{sv}", &name, &value)) {
+        const gchar *type = g_variant_get_type_string(value);
+
+        switch (type[0]) {
+        case 'i':
+            if (virTypedParamsAddInt(params, nparams, &maxParams, name,
+                                     g_variant_get_int32(value)) < 0) {
+                virtDBusUtilSetLastVirtError(error);
+                return FALSE;
+            }
+            break;
+
+        case 'u':
+            if (virTypedParamsAddUInt(params, nparams, &maxParams, name,
+                                      g_variant_get_uint32(value)) < 0) {
+                virtDBusUtilSetLastVirtError(error);
+                return FALSE;
+            }
+            break;
+
+        case 'x':
+            if (virTypedParamsAddLLong(params, nparams, &maxParams, name,
+                                       g_variant_get_int64(value)) < 0) {
+                virtDBusUtilSetLastVirtError(error);
+                return FALSE;
+            }
+            break;
+
+        case 't':
+            if (virTypedParamsAddULLong(params, nparams, &maxParams, name,
+                                        g_variant_get_uint64(value)) < 0) {
+                virtDBusUtilSetLastVirtError(error);
+                return FALSE;
+            }
+            break;
+
+        case 'd':
+            if (virTypedParamsAddDouble(params, nparams, &maxParams, name,
+                                        g_variant_get_double(value)) < 0) {
+                virtDBusUtilSetLastVirtError(error);
+                return FALSE;
+            }
+            break;
+
+        case 'b':
+            if (virTypedParamsAddBoolean(params, nparams, &maxParams, name,
+                                         g_variant_get_boolean(value)) < 0) {
+                virtDBusUtilSetLastVirtError(error);
+                return FALSE;
+            }
+            break;
+
+        case 's':
+            if (virTypedParamsAddString(params, nparams, &maxParams, name,
+                                        g_variant_get_string(value, NULL)) < 0) {
+                virtDBusUtilSetLastVirtError(error);
+                return FALSE;
+            }
+            break;
+
+        default:
+            g_set_error(error, VIRT_DBUS_ERROR, VIRT_DBUS_ERROR_LIBVIRT,
+                        "Invalid typed parameter '%s'.", type);
+            return FALSE;
+        }
+    }
+
+    name = NULL;
+    value = NULL;
+
+    return TRUE;
+}
+
 void
 virtDBusUtilSetLastVirtError(GError **error)
 {
diff --git a/src/util.h b/src/util.h
index 4ffc15c..86d2edc 100644
--- a/src/util.h
+++ b/src/util.h
@@ -31,6 +31,12 @@ GVariant *
 virtDBusUtilTypedParamsToGVariant(virTypedParameterPtr params,
                                   gint nparams);
 
+gboolean
+virtDBusUtilGVariantToTypedParams(GVariantIter *iter,
+                                  virTypedParameterPtr *params,
+                                  gint *nparams,
+                                  GError **error);
+
 void
 virtDBusUtilSetLastVirtError(GError **error);
 
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux