[libvirt] [libvirt-glib 1/4] API to get capabilities from connection
Christophe Fergeau
cfergeau at redhat.com
Wed May 9 13:44:04 UTC 2012
On Wed, May 09, 2012 at 04:16:13AM +0300, Zeeshan Ali (Khattak) wrote:
> From: "Zeeshan Ali (Khattak)" <zeeshanak at gnome.org>
>
> ---
> 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);
These 2 lines can be replaced with g_simple_async_result_take_error(res,
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;
This could be return g_object_ref(caps);
ACK with or without these 2 changes merged in
Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120509/292ed525/attachment-0001.sig>
More information about the libvir-list
mailing list