[libvirt-glib 1/4] API to get capabilities from connection

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

 



From: "Zeeshan Ali (Khattak)" <zeeshanak@xxxxxxxxx>

---
 libvirt-gconfig/libvirt-gconfig-capabilities.c |    4 -
 libvirt-gobject/libvirt-gobject-connection.c   |  104 ++++++++++++++++++++++++
 libvirt-gobject/libvirt-gobject-connection.h   |   11 +++
 libvirt-gobject/libvirt-gobject.sym            |    7 ++
 4 files changed, 122 insertions(+), 4 deletions(-)

diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c
index 4c4df68..3d9d036 100644
--- a/libvirt-gconfig/libvirt-gconfig-capabilities.c
+++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c
@@ -54,8 +54,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new(void)
 {
     GVirConfigObject *object;
 
-    /* FIXME: what is the XML root of the capability node? I suspect it is
-     * either 'guest' or 'host' */
     object = gvir_config_object_new(GVIR_CONFIG_TYPE_CAPABILITIES,
                                     "capabilities",
                                     DATADIR "/libvirt/schemas/capability.rng");
@@ -67,8 +65,6 @@ GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml,
 {
     GVirConfigObject *object;
 
-    /* FIXME: what is the XML root of the capability node? I suspect it is
-     * either 'guest' or 'host' */
     object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_CAPABILITIES,
                                              "capabilities",
                                              DATADIR "/libvirt/schemas/capability.rng",
diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c
index 186ad9d..9426510 100644
--- a/libvirt-gobject/libvirt-gobject-connection.c
+++ b/libvirt-gobject/libvirt-gobject-connection.c
@@ -1383,3 +1383,107 @@ GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn,
 
     return ret;
 }
+
+/**
+ * gvir_connection_get_capabilities:
+ * @conn: the connection
+ * @err: return location for any #GError
+ *
+ * Return value: (transfer full): a #GVirConfigCapabilities or NULL
+ */
+GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn,
+                                                         GError **err)
+{
+    GVirConfigCapabilities *caps;
+    char *caps_xml;
+
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+    g_return_val_if_fail(err == NULL || *err == NULL, NULL);
+    g_return_val_if_fail(conn->priv->conn, NULL);
+
+    caps_xml = virConnectGetCapabilities(conn->priv->conn);
+    if (caps_xml == NULL) {
+        gvir_set_error_literal(err, GVIR_CONNECTION_ERROR,
+                               0,
+                               "Unable to get capabilities");
+        return NULL;
+    }
+
+    caps = gvir_config_capabilities_new_from_xml(caps_xml, err);
+    free(caps_xml);
+
+    return caps;
+}
+
+static void
+gvir_connection_get_capabilities_helper(GSimpleAsyncResult *res,
+                                        GObject *object,
+                                        GCancellable *cancellable)
+{
+    GVirConnection *conn = GVIR_CONNECTION(object);
+    GError *err = NULL;
+    GVirConfigCapabilities *caps;
+
+    caps = gvir_connection_get_capabilities(conn, &err);
+    if (caps == NULL) {
+        g_simple_async_result_set_from_error(res, err);
+        g_error_free(err);
+
+        return;
+    }
+
+    g_simple_async_result_set_op_res_gpointer(res, caps, g_object_unref);
+}
+
+/**
+ * gvir_connection_get_capabilities_async:
+ * @conn: the connection
+ * @cancellable: (allow-none)(transfer none): cancellation object
+ * @callback: (scope async): completion callback
+ * @user_data: (closure): opaque data for callback
+ */
+void gvir_connection_get_capabilities_async(GVirConnection *conn,
+                                            GCancellable *cancellable,
+                                            GAsyncReadyCallback callback,
+                                            gpointer user_data)
+{
+    GSimpleAsyncResult *res;
+
+    res = g_simple_async_result_new(G_OBJECT(conn),
+                                    callback,
+                                    user_data,
+                                    gvir_connection_get_capabilities_async);
+    g_simple_async_result_run_in_thread(res,
+                                        gvir_connection_get_capabilities_helper,
+                                        G_PRIORITY_DEFAULT,
+                                        cancellable);
+    g_object_unref(res);
+}
+
+/**
+ * gvir_connection_get_capabilities_finish:
+ * @conn: the connection
+ * @result: (transfer none): async method result
+ *
+ * Return value: (transfer full): a #GVirConfigCapabilities or NULL.
+ */
+GVirConfigCapabilities *
+gvir_connection_get_capabilities_finish(GVirConnection *conn,
+                                        GAsyncResult *result,
+                                        GError **err)
+{
+    GVirConfigCapabilities *caps;
+
+    g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL);
+    g_return_val_if_fail(g_simple_async_result_is_valid(result, G_OBJECT(conn),
+                                                        gvir_connection_get_capabilities_async),
+                         NULL);
+
+    if (g_simple_async_result_propagate_error(G_SIMPLE_ASYNC_RESULT(result), err))
+        return NULL;
+
+    caps = g_simple_async_result_get_op_res_gpointer(G_SIMPLE_ASYNC_RESULT(result));
+    g_object_ref(caps);
+
+    return caps;
+}
diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h
index 3cc60a2..c80eecf 100644
--- a/libvirt-gobject/libvirt-gobject-connection.h
+++ b/libvirt-gobject/libvirt-gobject-connection.h
@@ -191,6 +191,17 @@ GVirStream *gvir_connection_get_stream(GVirConnection *conn,
 GVirNodeInfo *gvir_connection_get_node_info(GVirConnection *conn,
                                             GError **err);
 
+GVirConfigCapabilities *gvir_connection_get_capabilities(GVirConnection *conn,
+                                                         GError **err);
+void gvir_connection_get_capabilities_async(GVirConnection *conn,
+                                            GCancellable *cancellable,
+                                            GAsyncReadyCallback callback,
+                                            gpointer user_data);
+GVirConfigCapabilities *
+gvir_connection_get_capabilities_finish(GVirConnection *conn,
+                                        GAsyncResult *result,
+                                        GError **err);
+
 G_END_DECLS
 
 #endif /* __LIBVIRT_GOBJECT_CONNECTION_H__ */
diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym
index f43836f..7121794 100644
--- a/libvirt-gobject/libvirt-gobject.sym
+++ b/libvirt-gobject/libvirt-gobject.sym
@@ -160,4 +160,11 @@ LIBVIRT_GOBJECT_0.0.8 {
         *;
 };
 
+LIBVIRT_GOBJECT_0.0.9 {
+  global:
+	gvir_connection_get_capabilities;
+	gvir_connection_get_capabilities_async;
+	gvir_connection_get_capabilities_finish;
+} LIBVIRT_GOBJECT_0.0.8;
+
 # .... define new API here using predicted next version number ....
-- 
1.7.7.6

--
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]