On Tue, Sep 11, 2012 at 07:42:42PM +0200, Michal Privoznik wrote: > which is basically a wrapper for virConnectGetVersion(). > --- > examples/conn-test.c | 13 ++++++ > libvirt-gobject/libvirt-gobject-connection.c | 52 ++++++++++++++++++++++++++ > libvirt-gobject/libvirt-gobject-connection.h | 4 +- > libvirt-gobject/libvirt-gobject.sym | 1 + > 4 files changed, 69 insertions(+), 1 deletions(-) > > diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c > index f0be875..bc11151 100644 > --- a/libvirt-gobject/libvirt-gobject-connection.c > +++ b/libvirt-gobject/libvirt-gobject-connection.c > @@ -1078,6 +1078,58 @@ cleanup: > return ret; > } > > +/** > + * gvir_connection_get_version: > + * @conn: a #GVirConnection > + * @version: return location for version > + * @err: return location for any #GError > + * > + * Get version of current hypervisor used. > + * > + * Return value: TRUE on success, FALSE otherwise. > + */ > +gboolean > +gvir_connection_get_version(GVirConnection *conn, > + gulong *version, > + GError **err) > +{ > + GVirConnectionPrivate *priv; > + virConnectPtr vconn = NULL; > + gboolean ret = FALSE; > + > + g_return_val_if_fail(GVIR_IS_CONNECTION(conn), FALSE); > + > + priv = conn->priv; > + g_mutex_lock(priv->lock); > + if (!priv->conn) { > + g_set_error_literal(err, GVIR_CONNECTION_ERROR, 0, > + "Connection is not open"); > + g_mutex_unlock(priv->lock); > + goto cleanup; > + } > + > + vconn = priv->conn; > + /* Stop another thread closing the connection just at the minute */ > + virConnectRef(vconn); > + g_mutex_unlock(priv->lock); > + > + if ( virConnectGetVersion(priv->conn, version) < 0) { Bogus extra space after the first '(' > + gvir_set_error_literal(err, GVIR_CONNECTION_ERROR, 0, > + "Unable to get hypervisor version"); > + goto cleanup; > + } > + > + ret = TRUE; > + > +cleanup: > + if (vconn) { > + g_mutex_lock(priv->lock); > + virConnectClose(vconn); > + g_mutex_unlock(priv->lock); No need for this extra locking here Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :| -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list