void gvir_config_domain_address_pci_set_multifunction(GVirConfigDomainAddressPci *address,
                                                      gboolean multifunction)
{
    gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(address),
                                     "multifunction",
                                     multifunction?"on":"off", NULL);
}
GVirConfigDomainGraphicsSdl *gvir_config_domain_graphics_sdl_new(void)
{
    GVirConfigObject *object;

    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_SDL,
                                    "graphics", NULL);
    gvir_config_object_set_attribute(object, "type", "sdl", NULL);
    return GVIR_CONFIG_DOMAIN_GRAPHICS_SDL(object);
}
GVirConfigDomainInterfaceUser *gvir_config_domain_interface_user_new(void)
{
    GVirConfigObject *object;

    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_USER,
                                    "interface", NULL);
    gvir_config_object_set_attribute(object, "type", "user", NULL);
    return GVIR_CONFIG_DOMAIN_INTERFACE_USER(object);
}
/**
 * gvir_config_domain_controller_usb_new:
 *
 * Creates a new #GVirConfigDomainControllerUsb with a reference count of 1.
 * gvir_config_domain_controller_set_index() must be called before
 * this controller is usable.
 *
 * Returns: a new #GVirConfigDomainControllerUsb
 */
GVirConfigDomainControllerUsb *gvir_config_domain_controller_usb_new(void)
{
    GVirConfigObject *object;

    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_CONTROLLER_USB,
                                    "controller", NULL);
    gvir_config_object_set_attribute(object, "type", "usb", NULL);
    return GVIR_CONFIG_DOMAIN_CONTROLLER_USB(object);
}
GVirConfigDomainAddressPci *gvir_config_domain_address_pci_new(void)
{
    GVirConfigObject *object;

    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_ADDRESS_PCI,
                                    "address", NULL);
    gvir_config_object_set_attribute(object, "type", "pci", NULL);
    return GVIR_CONFIG_DOMAIN_ADDRESS_PCI(object);
}
GVirConfigDomainTimerHpet *gvir_config_domain_timer_hpet_new(void)
{
    GVirConfigObject *object;

    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_TIMER_HPET,
                                    "timer", NULL);
    gvir_config_object_set_attribute(object, "name", "hpet", NULL);
    return GVIR_CONFIG_DOMAIN_TIMER_HPET(object);
}
void gvir_config_domain_graphics_vnc_set_password(GVirConfigDomainGraphicsVnc *graphics,
                                                  const char *password)
{
    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_VNC(graphics));

    gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(graphics),
                                     "passwd", password,
                                     NULL);
}
GVirConfigDomainGraphicsVnc *gvir_config_domain_graphics_vnc_new(void)
{
    GVirConfigObject *object;

    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_VNC,
                                    "graphics", NULL);
    gvir_config_object_set_attribute(object, "type", "vnc", NULL);
    return GVIR_CONFIG_DOMAIN_GRAPHICS_VNC(object);
}
GVirConfigDomainTimerRtc *gvir_config_domain_timer_rtc_new(void)
{
    GVirConfigObject *object;

    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_TIMER_RTC,
                                    "timer", NULL);
    gvir_config_object_set_attribute(object, "name", "rtc", NULL);
    return GVIR_CONFIG_DOMAIN_TIMER_RTC(object);
}
GVirConfigDomainInterfaceBridge *gvir_config_domain_interface_bridge_new(void)
{
    GVirConfigObject *object;

    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_BRIDGE,
                                    "interface", NULL);
    gvir_config_object_set_attribute(object, "type", "bridge", NULL);
    return GVIR_CONFIG_DOMAIN_INTERFACE_BRIDGE(object);
}
void gvir_config_domain_graphics_sdl_set_display(GVirConfigDomainGraphicsSdl *graphics,
                                                 const gchar *disp)
{
    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_SDL(graphics));

    gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(graphics),
                                     "display", disp,
                                     NULL);
}
void gvir_config_domain_graphics_sdl_set_xauthority(GVirConfigDomainGraphicsSdl *graphics,
                                                    const gchar *path)
{
    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_GRAPHICS_SDL(graphics));

    gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(graphics),
                                     "xauth", path,
                                     NULL);
}
GVirConfigDomainTimerRtc *gvir_config_domain_timer_rtc_new_from_xml(const gchar *xml,
                                                                    GError **error)
{
    GVirConfigObject *object;

    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_TIMER_RTC,
                                             "timer", NULL, xml, error);
    gvir_config_object_set_attribute(object, "name", "rtc", NULL);
    return GVIR_CONFIG_DOMAIN_TIMER_RTC(object);
}
GVirConfigDomainInterfaceUser *gvir_config_domain_interface_user_new_from_xml(const gchar *xml,
                                                                              GError **error)
{
    GVirConfigObject *object;

    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_INTERFACE_USER,
                                             "interface", NULL, xml, error);
    if (object == NULL)
        return NULL;
    gvir_config_object_set_attribute(object, "type", "user", NULL);
    return GVIR_CONFIG_DOMAIN_INTERFACE_USER(object);
}
void gvir_config_storage_pool_source_set_directory(GVirConfigStoragePoolSource *source,
                                                   const char *directory)
{
    GVirConfigObject *node;

    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL_SOURCE(source));

    node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(source), "directory");
    g_return_if_fail(GVIR_CONFIG_IS_OBJECT(node));
    gvir_config_object_set_attribute(node, "path", directory, NULL);
    g_object_unref(G_OBJECT(node));
}
void gvir_config_storage_vol_backing_store_set_format(GVirConfigStorageVolBackingStore *backing_store,
                                                      const char *format)
{
    GVirConfigObject *node;

    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_VOL_BACKING_STORE(backing_store));

    node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(backing_store), "format");
    g_return_if_fail(GVIR_CONFIG_IS_OBJECT(node));
    gvir_config_object_set_attribute(node, "type", format, NULL);
    g_object_unref(G_OBJECT(node));
}
GVirConfigDomainChardevSourceSpiceVmc *gvir_config_domain_chardev_source_spicevmc_new(void)
{
    GVirConfigObject *object;

    /* the name of the root node is just a placeholder, it will be
     * overwritten when the GVirConfigDomainChardevSourceSpiceVmc is attached to a
     * GVirConfigDomainChardevSourceSpiceVmc
     */
    object = gvir_config_object_new(GVIR_CONFIG_TYPE_DOMAIN_CHARDEV_SOURCE_SPICE_VMC, "dummy", NULL);
    gvir_config_object_set_attribute(object, "type", "spicevmc", NULL);
    return GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_SPICE_VMC(object);
}
void gvir_config_storage_pool_source_set_adapter(GVirConfigStoragePoolSource *source,
                                                 const char *adapter)
{
    GVirConfigObject *node;

    g_return_if_fail(GVIR_CONFIG_IS_STORAGE_POOL_SOURCE(source));

    node = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(source), "adapter");
    g_return_if_fail(GVIR_CONFIG_IS_OBJECT(node));
    gvir_config_object_set_attribute(node, "name", adapter, NULL);
    g_object_unref(G_OBJECT(node));
}
GVirConfigDomainGraphicsSdl *
gvir_config_domain_graphics_sdl_new_from_xml(const gchar *xml,
                                             GError **error)
{
    GVirConfigObject *object;

    object = gvir_config_object_new_from_xml(GVIR_CONFIG_TYPE_DOMAIN_GRAPHICS_SDL,
                                             "graphics", NULL, xml, error);
    if (object == NULL)
        return NULL;
    gvir_config_object_set_attribute(object, "type", "sdl", NULL);
    return GVIR_CONFIG_DOMAIN_GRAPHICS_SDL(object);
}
static void set_attribute_hex(GVirConfigDomainAddressPci *address,
                              const char *attr_name,
                              guint attr_val,
                              guint min_val,
                              guint max_val,
                              guint size)
{
    char *hex_str;
    char *format;
    g_return_if_fail(GVIR_CONFIG_IS_DOMAIN_ADDRESS_PCI(address));
    g_return_if_fail((attr_val >= min_val) && (attr_val <= max_val));

    format = g_strdup_printf("0x%%0%dx", size);
    hex_str = g_strdup_printf(format, attr_val);
    gvir_config_object_set_attribute(GVIR_CONFIG_OBJECT(address),
                                     attr_name, hex_str, NULL);
    g_free(hex_str);
    g_free(format);
}