Use the new gvir_config_object_new{_from_xml} in all classes inheriting from GVirConfigObject. This simplifies the code in the _new methods creating empty objects. This commit also adds _new_from_xml methods to all these objects. --- libvirt-gconfig/libvirt-gconfig-capabilities.c | 26 +++++++++++++++----- libvirt-gconfig/libvirt-gconfig-capabilities.h | 2 + libvirt-gconfig/libvirt-gconfig-domain-snapshot.c | 23 +++++++++++++----- libvirt-gconfig/libvirt-gconfig-domain-snapshot.h | 2 + libvirt-gconfig/libvirt-gconfig-interface.c | 25 ++++++++++++++----- libvirt-gconfig/libvirt-gconfig-interface.h | 2 + libvirt-gconfig/libvirt-gconfig-network-filter.c | 24 +++++++++++++----- libvirt-gconfig/libvirt-gconfig-network-filter.h | 2 + libvirt-gconfig/libvirt-gconfig-network.c | 24 +++++++++++++----- libvirt-gconfig/libvirt-gconfig-network.h | 2 + libvirt-gconfig/libvirt-gconfig-node-device.c | 25 +++++++++++++------ libvirt-gconfig/libvirt-gconfig-node-device.h | 2 + libvirt-gconfig/libvirt-gconfig-secret.c | 24 +++++++++++++----- libvirt-gconfig/libvirt-gconfig-secret.h | 2 + libvirt-gconfig/libvirt-gconfig-storage-pool.c | 24 +++++++++++++----- libvirt-gconfig/libvirt-gconfig-storage-pool.h | 2 + libvirt-gconfig/libvirt-gconfig-storage-vol.c | 24 +++++++++++++----- libvirt-gconfig/libvirt-gconfig-storage-vol.h | 2 + libvirt-gconfig/libvirt-gconfig.sym | 9 +++++++ 19 files changed, 182 insertions(+), 64 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.c b/libvirt-gconfig/libvirt-gconfig-capabilities.c index 8ed0e2e..2f79073 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.c +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.c @@ -63,14 +63,26 @@ static void gvir_config_capabilities_init(GVirConfigCapabilities *conn) GVirConfigCapabilities *gvir_config_capabilities_new(void) { - xmlDocPtr doc; + GVirConfigObject *object; - doc = xmlNewDoc((xmlChar *)"1.0"); /* FIXME: what is the XML root of the capability node? I suspect it is * either 'guest' or 'host' */ - doc->children = xmlNewDocNode(doc, NULL, (xmlChar *)"capabilities", NULL); - return GVIR_CONFIG_CAPABILITIES(g_object_new(GVIR_TYPE_CONFIG_CAPABILITIES, - "node", doc->children, - "schema", DATADIR "/libvirt/schemas/capability.rng", - NULL)); + object = gvir_config_object_new(GVIR_TYPE_CONFIG_CAPABILITIES, + "capabilities", + DATADIR "/libvirt/schemas/capability.rng"); + return GVIR_CONFIG_CAPABILITIES(object); +} + +GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, + GError **error) +{ + 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_TYPE_CONFIG_CAPABILITIES, + "capabilities", + DATADIR "/libvirt/schemas/capability.rng", + xml, error); + return GVIR_CONFIG_CAPABILITIES(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-capabilities.h b/libvirt-gconfig/libvirt-gconfig-capabilities.h index b5660df..7170683 100644 --- a/libvirt-gconfig/libvirt-gconfig-capabilities.h +++ b/libvirt-gconfig/libvirt-gconfig-capabilities.h @@ -60,6 +60,8 @@ struct _GVirConfigCapabilitiesClass GType gvir_config_capabilities_get_type(void); GVirConfigCapabilities *gvir_config_capabilities_new(void); +GVirConfigCapabilities *gvir_config_capabilities_new_from_xml(const gchar *xml, + GError **error); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c index 35f63ec..e7dc36e 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.c @@ -63,13 +63,22 @@ static void gvir_config_domain_snapshot_init(GVirConfigDomainSnapshot *conn) GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new(void) { - xmlDocPtr doc; + GVirConfigObject *object; - doc = xmlNewDoc((xmlChar *)"1.0"); - doc->children = xmlNewDocNode(doc, NULL, (xmlChar *)"domainsnapshot", NULL); + object = gvir_config_object_new(GVIR_TYPE_CONFIG_DOMAIN_SNAPSHOT, + "domainsnapshot", + DATADIR "/libvirt/schemas/domainsnapshot.rng"); + return GVIR_CONFIG_DOMAIN_SNAPSHOT(object); +} + +GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; - return GVIR_CONFIG_DOMAIN_SNAPSHOT(g_object_new(GVIR_TYPE_CONFIG_DOMAIN_SNAPSHOT, - "node", doc->children, - "schema", DATADIR "/libvirt/schemas/domainsnapshot.rng", - NULL)); + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DOMAIN_SNAPSHOT, + "domainsnapshot", + DATADIR "/libvirt/schemas/domainsnapshot.rng", + xml, error); + return GVIR_CONFIG_DOMAIN_SNAPSHOT(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h index 1924903..d086c1e 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-snapshot.h @@ -60,6 +60,8 @@ struct _GVirConfigDomainSnapshotClass GType gvir_config_domain_snapshot_get_type(void); GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new(void); +GVirConfigDomainSnapshot *gvir_config_domain_snapshot_new_from_xml(const gchar *xml, + GError **error); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-interface.c b/libvirt-gconfig/libvirt-gconfig-interface.c index 48cbcfb..5e934f6 100644 --- a/libvirt-gconfig/libvirt-gconfig-interface.c +++ b/libvirt-gconfig/libvirt-gconfig-interface.c @@ -63,12 +63,23 @@ static void gvir_config_interface_init(GVirConfigInterface *conn) GVirConfigInterface *gvir_config_interface_new(void) { - xmlDocPtr doc; + GVirConfigObject *object; - doc = xmlNewDoc((xmlChar *)"1.0"); - doc->children = xmlNewDocNode(doc, NULL, (xmlChar *)"interface", NULL); - return GVIR_CONFIG_INTERFACE(g_object_new(GVIR_TYPE_CONFIG_INTERFACE, - "node", doc->children, - "schema", DATADIR "/libvirt/schemas/interface.rng", - NULL)); + object = gvir_config_object_new(GVIR_TYPE_CONFIG_INTERFACE, + "interface", + DATADIR "/libvirt/schemas/interface.rng"); + return GVIR_CONFIG_INTERFACE(object); } + +GVirConfigInterface *gvir_config_interface_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_INTERFACE, + "interface", + DATADIR "/libvirt/schemas/interface.rng", + xml, error); + return GVIR_CONFIG_INTERFACE(object); +} + diff --git a/libvirt-gconfig/libvirt-gconfig-interface.h b/libvirt-gconfig/libvirt-gconfig-interface.h index abfcc4e..0728c29 100644 --- a/libvirt-gconfig/libvirt-gconfig-interface.h +++ b/libvirt-gconfig/libvirt-gconfig-interface.h @@ -60,6 +60,8 @@ struct _GVirConfigInterfaceClass GType gvir_config_interface_get_type(void); GVirConfigInterface *gvir_config_interface_new(void); +GVirConfigInterface *gvir_config_interface_new_from_xml(const gchar *xml, + GError **error); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-network-filter.c b/libvirt-gconfig/libvirt-gconfig-network-filter.c index 1b4c22d..8b615bf 100644 --- a/libvirt-gconfig/libvirt-gconfig-network-filter.c +++ b/libvirt-gconfig/libvirt-gconfig-network-filter.c @@ -63,12 +63,22 @@ static void gvir_config_network_filter_init(GVirConfigNetworkFilter *conn) GVirConfigNetworkFilter *gvir_config_network_filter_new(void) { - xmlDocPtr doc; + GVirConfigObject *object; - doc = xmlNewDoc((xmlChar *)"1.0"); - doc->children = xmlNewDocNode(doc, NULL, (xmlChar *)"filter", NULL); - return GVIR_CONFIG_NETWORK_FILTER(g_object_new(GVIR_TYPE_CONFIG_NETWORK_FILTER, - "node", doc->children, - "schema", DATADIR "/libvirt/schemas/nwfilter.rng", - NULL)); + object = gvir_config_object_new(GVIR_TYPE_CONFIG_NETWORK_FILTER, + "filter", + DATADIR "/libvirt/schemas/nwfilter.rng"); + return GVIR_CONFIG_NETWORK_FILTER(object); +} + +GVirConfigNetworkFilter *gvir_config_network_filter_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_NETWORK_FILTER, + "filter", + DATADIR "/libvirt/schemas/nwfilter.rng", + xml, error); + return GVIR_CONFIG_NETWORK_FILTER(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-network-filter.h b/libvirt-gconfig/libvirt-gconfig-network-filter.h index c3f87b7..3032608 100644 --- a/libvirt-gconfig/libvirt-gconfig-network-filter.h +++ b/libvirt-gconfig/libvirt-gconfig-network-filter.h @@ -60,6 +60,8 @@ struct _GVirConfigNetworkFilterClass GType gvir_config_network_filter_get_type(void); GVirConfigNetworkFilter *gvir_config_network_filter_new(void); +GVirConfigNetworkFilter *gvir_config_network_filter_new_from_xml(const gchar *xml, + GError **error); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-network.c b/libvirt-gconfig/libvirt-gconfig-network.c index f2d19f7..2bd2512 100644 --- a/libvirt-gconfig/libvirt-gconfig-network.c +++ b/libvirt-gconfig/libvirt-gconfig-network.c @@ -63,12 +63,22 @@ static void gvir_config_network_init(GVirConfigNetwork *conn) GVirConfigNetwork *gvir_config_network_new(void) { - xmlDocPtr doc; + GVirConfigObject *object; - doc = xmlNewDoc((xmlChar *)"1.0"); - doc->children = xmlNewDocNode(doc, NULL, (xmlChar *)"network", NULL); - return GVIR_CONFIG_NETWORK(g_object_new(GVIR_TYPE_CONFIG_NETWORK, - "node", doc->children, - "schema", DATADIR "/libvirt/schemas/network.rng", - NULL)); + object = gvir_config_object_new(GVIR_TYPE_CONFIG_NETWORK, + "network", + DATADIR "/libvirt/schemas/network.rng"); + return GVIR_CONFIG_NETWORK(object); +} + +GVirConfigNetwork *gvir_config_network_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_NETWORK, + "network", + DATADIR "/libvirt/schemas/network.rng", + xml, error); + return GVIR_CONFIG_NETWORK(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-network.h b/libvirt-gconfig/libvirt-gconfig-network.h index f156971..3810589 100644 --- a/libvirt-gconfig/libvirt-gconfig-network.h +++ b/libvirt-gconfig/libvirt-gconfig-network.h @@ -60,6 +60,8 @@ struct _GVirConfigNetworkClass GType gvir_config_network_get_type(void); GVirConfigNetwork *gvir_config_network_new(void); +GVirConfigNetwork *gvir_config_network_new_from_xml(const gchar *xml, + GError **error); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-node-device.c b/libvirt-gconfig/libvirt-gconfig-node-device.c index a6e6d9e..3be973f 100644 --- a/libvirt-gconfig/libvirt-gconfig-node-device.c +++ b/libvirt-gconfig/libvirt-gconfig-node-device.c @@ -63,13 +63,22 @@ static void gvir_config_node_device_init(GVirConfigNodeDevice *conn) GVirConfigNodeDevice *gvir_config_node_device_new(void) { - xmlDocPtr doc; + GVirConfigObject *object; - doc = xmlNewDoc((xmlChar *)"1.0"); - /* FIXME: correct node name ? */ - doc->children = xmlNewDocNode(doc, NULL, (xmlChar *)"device", NULL); - return GVIR_CONFIG_NODE_DEVICE(g_object_new(GVIR_TYPE_CONFIG_NODE_DEVICE, - "node", doc->children, - "schema", DATADIR "/libvirt/schemas/nodedev.rng", - NULL)); + object = gvir_config_object_new(GVIR_TYPE_CONFIG_NODE_DEVICE, + "device", + DATADIR "/libvirt/schemas/nodedev.rng"); + return GVIR_CONFIG_NODE_DEVICE(object); +} + +GVirConfigNodeDevice *gvir_config_node_device_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_NODE_DEVICE, + "device", + DATADIR "/libvirt/schemas/nodedev.rng", + xml, error); + return GVIR_CONFIG_NODE_DEVICE(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-node-device.h b/libvirt-gconfig/libvirt-gconfig-node-device.h index 720b580..293820d 100644 --- a/libvirt-gconfig/libvirt-gconfig-node-device.h +++ b/libvirt-gconfig/libvirt-gconfig-node-device.h @@ -60,6 +60,8 @@ struct _GVirConfigNodeDeviceClass GType gvir_config_node_device_get_type(void); GVirConfigNodeDevice *gvir_config_node_device_new(void); +GVirConfigNodeDevice *gvir_config_node_device_new_from_xml(const gchar *xml, + GError **error); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-secret.c b/libvirt-gconfig/libvirt-gconfig-secret.c index 505de4c..bb55c44 100644 --- a/libvirt-gconfig/libvirt-gconfig-secret.c +++ b/libvirt-gconfig/libvirt-gconfig-secret.c @@ -63,12 +63,22 @@ static void gvir_config_secret_init(GVirConfigSecret *conn) GVirConfigSecret *gvir_config_secret_new(void) { - xmlDocPtr doc; + GVirConfigObject *object; - doc = xmlNewDoc((xmlChar *)"1.0"); - doc->children = xmlNewDocNode(doc, NULL, (xmlChar *)"secret", NULL); - return GVIR_CONFIG_SECRET(g_object_new(GVIR_TYPE_CONFIG_SECRET, - "node", doc->children, - "schema", DATADIR "/libvirt/schemas/secret.rng", - NULL)); + object = gvir_config_object_new(GVIR_TYPE_CONFIG_SECRET, + "secret", + DATADIR "/libvirt/schemas/secret.rng"); + return GVIR_CONFIG_SECRET(object); +} + +GVirConfigSecret *gvir_config_secret_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_SECRET, + "secret", + DATADIR "/libvirt/schemas/secret.rng", + xml, error); + return GVIR_CONFIG_SECRET(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-secret.h b/libvirt-gconfig/libvirt-gconfig-secret.h index fbd4564..72d67af 100644 --- a/libvirt-gconfig/libvirt-gconfig-secret.h +++ b/libvirt-gconfig/libvirt-gconfig-secret.h @@ -60,6 +60,8 @@ struct _GVirConfigSecretClass GType gvir_config_secret_get_type(void); GVirConfigSecret *gvir_config_secret_new(void); +GVirConfigSecret *gvir_config_secret_new_from_xml(const gchar *xml, + GError **error); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-storage-pool.c b/libvirt-gconfig/libvirt-gconfig-storage-pool.c index ef32aeb..4cbda27 100644 --- a/libvirt-gconfig/libvirt-gconfig-storage-pool.c +++ b/libvirt-gconfig/libvirt-gconfig-storage-pool.c @@ -63,12 +63,22 @@ static void gvir_config_storage_pool_init(GVirConfigStoragePool *conn) GVirConfigStoragePool *gvir_config_storage_pool_new(void) { - xmlDocPtr doc; + GVirConfigObject *object; - doc = xmlNewDoc((xmlChar *)"1.0"); - doc->children = xmlNewDocNode(doc, NULL, (xmlChar *)"pool", NULL); - return GVIR_CONFIG_STORAGE_POOL(g_object_new(GVIR_TYPE_CONFIG_STORAGE_POOL, - "node", doc->children, - "schema", DATADIR "/libvirt/schemas/storagepool.rng", - NULL)); + object = gvir_config_object_new(GVIR_TYPE_CONFIG_STORAGE_POOL, + "pool", + DATADIR "/libvirt/schemas/storagepool.rng"); + return GVIR_CONFIG_STORAGE_POOL(object); +} + +GVirConfigStoragePool *gvir_config_storage_pool_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_STORAGE_POOL, + "pool", + DATADIR "/libvirt/schemas/storagepool.rng", + xml, error); + return GVIR_CONFIG_STORAGE_POOL(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-storage-pool.h b/libvirt-gconfig/libvirt-gconfig-storage-pool.h index e5912f9..ab7aa4d 100644 --- a/libvirt-gconfig/libvirt-gconfig-storage-pool.h +++ b/libvirt-gconfig/libvirt-gconfig-storage-pool.h @@ -60,6 +60,8 @@ struct _GVirConfigStoragePoolClass GType gvir_config_storage_pool_get_type(void); GVirConfigStoragePool *gvir_config_storage_pool_new(void); +GVirConfigStoragePool *gvir_config_storage_pool_new_from_xml(const gchar *xml, + GError **error); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig-storage-vol.c b/libvirt-gconfig/libvirt-gconfig-storage-vol.c index 886b1e0..e9e90be 100644 --- a/libvirt-gconfig/libvirt-gconfig-storage-vol.c +++ b/libvirt-gconfig/libvirt-gconfig-storage-vol.c @@ -63,12 +63,22 @@ static void gvir_config_storage_vol_init(GVirConfigStorageVol *conn) GVirConfigStorageVol *gvir_config_storage_vol_new(void) { - xmlDocPtr doc; + GVirConfigObject *object; - doc = xmlNewDoc((xmlChar *)"1.0"); - doc->children = xmlNewDocNode(doc, NULL, (xmlChar *)"volume", NULL); - return GVIR_CONFIG_STORAGE_VOL(g_object_new(GVIR_TYPE_CONFIG_STORAGE_VOL, - "node", doc->children, - "schema", DATADIR "/libvirt/schemas/storage_vol.rng", - NULL)); + object = gvir_config_object_new(GVIR_TYPE_CONFIG_STORAGE_VOL, + "volume", + DATADIR "/libvirt/schemas/storage_vol.rng"); + return GVIR_CONFIG_STORAGE_VOL(object); +} + +GVirConfigStorageVol *gvir_config_storage_vol_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_STORAGE_VOL, + "volume", + DATADIR "/libvirt/schemas/storage_vol.rng", + xml, error); + return GVIR_CONFIG_STORAGE_VOL(object); } diff --git a/libvirt-gconfig/libvirt-gconfig-storage-vol.h b/libvirt-gconfig/libvirt-gconfig-storage-vol.h index 08a2180..8728a22 100644 --- a/libvirt-gconfig/libvirt-gconfig-storage-vol.h +++ b/libvirt-gconfig/libvirt-gconfig-storage-vol.h @@ -60,6 +60,8 @@ struct _GVirConfigStorageVolClass GType gvir_config_storage_vol_get_type(void); GVirConfigStorageVol *gvir_config_storage_vol_new(void); +GVirConfigStorageVol *gvir_config_storage_vol_new_from_xml(const gchar *xml, + GError **error); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 31a89d2..a386ff1 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -2,6 +2,7 @@ LIBVIRT_GOBJECT_0.0.1 { global: gvir_config_capabilities_get_type; gvir_config_capabilities_new; + gvir_config_capabilities_new_from_xml; gvir_config_domain_get_type; gvir_config_domain_new; @@ -15,18 +16,23 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_snapshot_get_type; gvir_config_domain_snapshot_new; + gvir_config_domain_snapshot_new_from_xml; gvir_config_interface_get_type; gvir_config_interface_new; + gvir_config_interface_new_from_xml; gvir_config_network_get_type; gvir_config_network_new; + gvir_config_network_new_from_xml; gvir_config_network_filter_get_type; gvir_config_network_filter_new; + gvir_config_network_filter_new_from_xml; gvir_config_node_device_get_type; gvir_config_node_device_new; + gvir_config_node_device_new_from_xml; gvir_config_object_get_type; gvir_config_object_error_quark; @@ -39,12 +45,15 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_secret_get_type; gvir_config_secret_new; + gvir_config_secret_new_from_xml; gvir_config_storage_pool_get_type; gvir_config_storage_pool_new; + gvir_config_storage_pool_new_from_xml; gvir_config_storage_vol_get_type; gvir_config_storage_vol_new; + gvir_config_storage_vol_new_from_xml; local: *; -- 1.7.7 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list