-- v2: use enum for input bus type use g_return_if_fail to test function args for sanity v3: rename to GVirConfigDomainInput --- libvirt-gconfig/Makefile.am | 2 + libvirt-gconfig/libvirt-gconfig-domain-input.c | 113 ++++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-input.h | 82 +++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 7 ++ libvirt-gconfig/tests/test-domain-create.c | 14 +++- 6 files changed, 217 insertions(+), 2 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-input.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-input.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index bd7f41b..52721ad 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -15,6 +15,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain-clock.h \ libvirt-gconfig-domain-device.h \ libvirt-gconfig-domain-disk.h \ + libvirt-gconfig-domain-input.h \ libvirt-gconfig-domain-interface.h \ libvirt-gconfig-domain-interface-network.h \ libvirt-gconfig-domain-os.h \ @@ -38,6 +39,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain-clock.c \ libvirt-gconfig-domain-device.c \ libvirt-gconfig-domain-disk.c \ + libvirt-gconfig-domain-input.c \ libvirt-gconfig-domain-interface.c \ libvirt-gconfig-domain-interface-network.c \ libvirt-gconfig-domain-os.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-input.c b/libvirt-gconfig/libvirt-gconfig-domain-input.c new file mode 100644 index 0000000..8d4a09f --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-input.c @@ -0,0 +1,113 @@ +/* + * libvirt-gobject-config-device_input.c: libvirt glib integration + * + * Copyright (C) 2011 Red Hat + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@xxxxxxxxx> + */ + +#include <config.h> + +#include <string.h> + +#include <libxml/tree.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-helpers-private.h" +#include "libvirt-gconfig/libvirt-gconfig-object-private.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_CONFIG_DOMAIN_INPUT_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_INPUT, GVirConfigDomainInputPrivate)) + +struct _GVirConfigDomainInputPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainInput, gvir_config_domain_input, GVIR_TYPE_CONFIG_DOMAIN_DEVICE); + + +static void gvir_config_domain_input_class_init(GVirConfigDomainInputClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainInputPrivate)); +} + + +static void gvir_config_domain_input_init(GVirConfigDomainInput *device_input) +{ + GVirConfigDomainInputPrivate *priv; + + DEBUG("Init GVirConfigDomainInput=%p", device_input); + + priv = device_input->priv = GVIR_CONFIG_DOMAIN_INPUT_GET_PRIVATE(device_input); + + memset(priv, 0, sizeof(*priv)); +} + + +GVirConfigDomainInput *gvir_config_domain_input_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_DOMAIN_INPUT, + "input", NULL); + return GVIR_CONFIG_DOMAIN_INPUT(object); +} + +GVirConfigDomainInput *gvir_config_domain_input_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DOMAIN_INPUT, + "input", NULL, xml, error); + return GVIR_CONFIG_DOMAIN_INPUT(object); +} + +void gvir_config_domain_input_set_device_type(GVirConfigDomainInput *input, + GVirConfigDomainInputDeviceType type) +{ + xmlNodePtr node; + const char *type_str; + + g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_INPUT(input)); + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(input)); + g_return_if_fail(node != NULL); + type_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_INPUT_DEVICE_TYPE, + type); + g_return_if_fail(type_str != NULL); + xmlNewProp(node, (xmlChar*)"type", (xmlChar*)type_str); +} + +void gvir_config_domain_input_set_bus(GVirConfigDomainInput *input, + GVirConfigDomainInputBus bus) +{ + xmlNodePtr node; + const char *bus_str; + + g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_INPUT(input)); + node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(input)); + g_return_if_fail(node != NULL); + bus_str = gvir_config_genum_get_nick(GVIR_TYPE_CONFIG_DOMAIN_INPUT_BUS, + bus); + g_return_if_fail(bus_str != NULL); + xmlNewProp(node, (xmlChar*)"bus", (xmlChar*)bus_str); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-input.h b/libvirt-gconfig/libvirt-gconfig-domain-input.h new file mode 100644 index 0000000..e3f22b1 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-input.h @@ -0,0 +1,82 @@ +/* + * libvirt-gobject-domain-input.c: libvirt gobject integration + * + * Copyright (C) 2011 Red Hat + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Author: Christophe Fergeau <cfergeau@xxxxxxxxx> + */ + +#if !defined(__LIBVIRT_GCONFIG_H__) && !defined(LIBVIRT_GCONFIG_BUILD) +#error "Only <libvirt-gconfig/libvirt-gconfig.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GCONFIG_DOMAIN_INPUT_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_INPUT_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DOMAIN_INPUT (gvir_config_domain_input_get_type ()) +#define GVIR_CONFIG_DOMAIN_INPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DOMAIN_INPUT, GVirConfigDomainInput)) +#define GVIR_CONFIG_DOMAIN_INPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DOMAIN_INPUT, GVirConfigDomainInputClass)) +#define GVIR_IS_CONFIG_DOMAIN_INPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DOMAIN_INPUT)) +#define GVIR_IS_CONFIG_DOMAIN_INPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DOMAIN_INPUT)) +#define GVIR_CONFIG_DOMAIN_INPUT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DOMAIN_INPUT, GVirConfigDomainInputClass)) + +typedef struct _GVirConfigDomainInput GVirConfigDomainInput; +typedef struct _GVirConfigDomainInputPrivate GVirConfigDomainInputPrivate; +typedef struct _GVirConfigDomainInputClass GVirConfigDomainInputClass; + +struct _GVirConfigDomainInput +{ + GVirConfigDomainDevice parent; + + GVirConfigDomainInputPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainInputClass +{ + GVirConfigDomainDeviceClass parent_class; + + gpointer padding[20]; +}; + +typedef enum { + GVIR_CONFIG_DOMAIN_INPUT_DEVICE_MOUSE, + GVIR_CONFIG_DOMAIN_INPUT_DEVICE_TABLET +} GVirConfigDomainInputDeviceType; + +typedef enum { + GVIR_CONFIG_DOMAIN_INPUT_BUS_PS2, + GVIR_CONFIG_DOMAIN_INPUT_BUS_USB, + GVIR_CONFIG_DOMAIN_INPUT_BUS_XEN +} GVirConfigDomainInputBus; + +GType gvir_config_domain_input_get_type(void); + +GVirConfigDomainInput *gvir_config_domain_input_new(void); +GVirConfigDomainInput *gvir_config_domain_input_new_from_xml(const gchar *xml, + GError **error); +void gvir_config_domain_input_set_device_type(GVirConfigDomainInput *input, + GVirConfigDomainInputDeviceType type); +void gvir_config_domain_input_set_bus(GVirConfigDomainInput *input, + GVirConfigDomainInputBus bus); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_INPUT_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 9940c4e..f6bd45d 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -32,6 +32,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain-clock.h> #include <libvirt-gconfig/libvirt-gconfig-domain-device.h> #include <libvirt-gconfig/libvirt-gconfig-domain-disk.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-input.h> #include <libvirt-gconfig/libvirt-gconfig-domain-interface.h> #include <libvirt-gconfig/libvirt-gconfig-domain-interface-network.h> #include <libvirt-gconfig/libvirt-gconfig-domain-os.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 38a82a3..b0a5ae1 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -44,6 +44,13 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_config_domain_disk_set_target_dev; gvir_config_domain_disk_set_type; + gvir_config_domain_input_get_type; + gvir_config_domain_input_device_type_get_type; + gvir_config_domain_input_new; + gvir_config_domain_input_new_from_xml; + gvir_config_domain_input_set_device_type; + gvir_config_domain_input_set_bus; + gvir_config_domain_interface_get_type; gvir_config_domain_interface_network_get_type; diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index 8484b78..b0ed210 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -94,15 +94,25 @@ int main(void) gvir_config_domain_disk_set_driver_type(disk, "qcow2"); gvir_config_domain_disk_set_target_bus(disk, "ide"); gvir_config_domain_disk_set_target_dev(disk, "hda"); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(disk)); - devices = g_list_append(devices, disk); /* network interface node */ GVirConfigDomainInterfaceNetwork *interface; interface = gvir_config_domain_interface_network_new(); gvir_config_domain_interface_network_set_source(interface, "default"); - devices = g_list_append(devices, interface); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(interface)); + + /* input node */ + GVirConfigDomainInput *input; + + input = gvir_config_domain_input_new(); + gvir_config_domain_input_set_device_type(input, + GVIR_CONFIG_DOMAIN_INPUT_DEVICE_TABLET); + gvir_config_domain_input_set_bus(input, GVIR_CONFIG_DOMAIN_INPUT_BUS_USB); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(input)); + gvir_config_domain_set_devices(domain, devices); g_list_free(devices); -- 1.7.7.3 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list