which is basically a wrapper for virConnectGetType(). --- examples/conn-test.c | 9 ++++++ libvirt-gobject/libvirt-gobject-connection.c | 41 ++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 2 + libvirt-gobject/libvirt-gobject.sym | 5 +++ 4 files changed, 57 insertions(+), 0 deletions(-) diff --git a/examples/conn-test.c b/examples/conn-test.c index 8c70997..b9cb417 100644 --- a/examples/conn-test.c +++ b/examples/conn-test.c @@ -31,11 +31,20 @@ do_connection_open(GObject *source, { GVirConnection *conn = GVIR_CONNECTION(source); GError *err = NULL; + gchar *hv_name = NULL; if (!gvir_connection_open_finish(conn, res, &err)) { g_error("%s", err->message); } g_print("Connected to libvirt\n"); + + if (!(hv_name = gvir_connection_get_hypervisor_name(conn, &err))) { + g_error("%s", err->message); + } + + g_print("Hypervisor name: %s\n", hv_name); + + g_free(hv_name); g_object_unref(conn); } diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index d826905..3dff564 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -1025,6 +1025,47 @@ const gchar *gvir_connection_get_uri(GVirConnection *conn) return conn->priv->uri; } +/** + * gvir_connection_get_hypervisor_name: + * @conn: a #GVirConnection + * @err: return location for any #GError + * + * Get name of current hypervisor used. + * + * Return value: new string that should be freed when no longer needed, + * or NULL upon error. + */ +gchar * +gvir_connection_get_hypervisor_name(GVirConnection *conn, + GError **err) +{ + GVirConnectionPrivate *priv; + gchar *ret = NULL; + const char *type; + + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), NULL); + g_return_val_if_fail(err == NULL || *err == NULL, NULL); + + priv = conn->priv; + if (!priv->conn) { + g_set_error_literal(err, GVIR_CONNECTION_ERROR, 0, + "Connection is not opened"); + goto cleanup; + } + + type = virConnectGetType(priv->conn); + if (!type) { + gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, 0, + "Unable to get hypervisor name"); + goto cleanup; + } + + ret = g_strdup(type); + +cleanup: + return ret; +} + static void gvir_domain_ref(gpointer obj, gpointer ignore G_GNUC_UNUSED) { g_object_ref(obj); diff --git a/libvirt-gobject/libvirt-gobject-connection.h b/libvirt-gobject/libvirt-gobject-connection.h index d658b01..1bdac54 100644 --- a/libvirt-gobject/libvirt-gobject-connection.h +++ b/libvirt-gobject/libvirt-gobject-connection.h @@ -112,6 +112,8 @@ gboolean gvir_connection_fetch_domains_finish(GVirConnection *conn, const gchar *gvir_connection_get_uri(GVirConnection *conn); +gchar *gvir_connection_get_hypervisor_name(GVirConnection *conn, + GError **err); GList *gvir_connection_get_domains(GVirConnection *conn); GVirDomain *gvir_connection_get_domain(GVirConnection *conn, diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index 67e5a4f..2c2f1f4 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -194,4 +194,9 @@ LIBVIRT_GOBJECT_0.1.2 { gvir_domain_resume_finish; } LIBVIRT_GOBJECT_0.1.1; +LIBVIRT_GOBJECT_0.1.3 { + global: + gvir_connection_get_hypervisor_name; +} LIBVIRT_GOBJECT_0.1.2; + # .... define new API here using predicted next version number .... -- 1.7.8.6 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list