
On Mon, Sep 26, 2011 at 09:29:33PM +0300, Zeeshan Ali (Khattak) wrote:
From: "Zeeshan Ali (Khattak)" <zeeshanak@gnome.org>
--- libvirt-gobject/libvirt-gobject-connection.c | 38 ++++++++++++++++++++++++++ libvirt-gobject/libvirt-gobject-connection.h | 3 ++ libvirt-gobject/libvirt-gobject.sym | 1 + 3 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 32f749c..072484e 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -720,3 +720,41 @@ GVirStream *gvir_connection_get_stream(GVirConnection *self,
return klass->stream_new(self, st); } + +/** + * gvir_connection_create_domain: + * @conn: the connection on which to create the dmain + * @conf: the configuration for the new domain + * Returns: (transfer full): the newly created domain + */ +GVirDomain *gvir_connection_create_domain(GVirConnection *conn, + GVirConfigDomain *conf, + GError **err) +{ + const gchar *xml; + virDomainPtr handle; + GVirConnectionPrivate *priv = conn->priv; + + xml = gvir_config_object_get_doc(GVIR_CONFIG_OBJECT(conf)); + + g_return_val_if_fail(xml != NULL, NULL); + + if (!(handle = virDomainDefineXML(priv->conn, xml))) { + *err = gvir_error_new_literal(GVIR_CONNECTION_ERROR, + 0, + "Failed to create domain"); + return NULL; + } + + GVirDomain *domain; + + domain = GVIR_DOMAIN(g_object_new(GVIR_TYPE_DOMAIN, + "handle", handle, + NULL)); + + g_hash_table_insert(priv->domains, + g_strdup(gvir_domain_get_uuid(domain)), + domain);
Since the return value is annotated '(transfer full)' you need todo 'g_object_ref(domain)' before putting it into the hash table, since the hash needs to keep hold of a reference. Also you want to have a g_mutex_lock/unlock either side of use of the hash table. Regards, 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 :|