[libvirt] [libvirt-glib PATCHv2 1/5] Add objects for dealing with <console> devices

Add an abstract GVirConfigDomainChardev object for <console>, <serial>, ... devices and a GVirConfigDomainConsole implementation. This needs to be completed with a separate GVirConfigDomainChardevSource inheritance tree which will be specialized to GVirConfigDomainChardevSourcePty, ... and GVirConfigDomainChardev will offer a helper function to attach a GVirConfigDomainChardevSource to a GVirConfigDomainChardev --- libvirt-gconfig/Makefile.am | 4 + libvirt-gconfig/libvirt-gconfig-domain-chardev.c | 48 +++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-chardev.h | 64 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-console.c | 70 ++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-console.h | 67 +++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 2 + libvirt-gconfig/libvirt-gconfig.sym | 6 ++ 7 files changed, 261 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev.h create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-console.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-console.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 575715e..88fb556 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -13,7 +13,9 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-object.h \ libvirt-gconfig-capabilities.h \ libvirt-gconfig-domain.h \ + libvirt-gconfig-domain-chardev.h \ libvirt-gconfig-domain-clock.h \ + libvirt-gconfig-domain-console.h \ libvirt-gconfig-domain-device.h \ libvirt-gconfig-domain-disk.h \ libvirt-gconfig-domain-filesys.h \ @@ -47,7 +49,9 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-main.c \ libvirt-gconfig-capabilities.c \ libvirt-gconfig-domain.c \ + libvirt-gconfig-domain-chardev.c \ libvirt-gconfig-domain-clock.c \ + libvirt-gconfig-domain-console.c \ libvirt-gconfig-domain-device.c \ libvirt-gconfig-domain-disk.c \ libvirt-gconfig-domain-filesys.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev.c b/libvirt-gconfig/libvirt-gconfig-domain-chardev.c new file mode 100644 index 0000000..525fc2b --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev.c @@ -0,0 +1,48 @@ +/* + * libvirt-gconfig-domain-chardev.c: libvirt domain chardev configuration + * + * 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@redhat.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +#define GVIR_CONFIG_DOMAIN_CHARDEV_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV, GVirConfigDomainChardevPrivate)) + +struct _GVirConfigDomainChardevPrivate +{ + gboolean unused; +}; + +G_DEFINE_ABSTRACT_TYPE(GVirConfigDomainChardev, gvir_config_domain_chardev, GVIR_TYPE_CONFIG_DOMAIN_DEVICE) + +static void gvir_config_domain_chardev_class_init(GVirConfigDomainChardevClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainChardevPrivate)); +} + + +static void gvir_config_domain_chardev_init(GVirConfigDomainChardev *chardev) +{ + g_debug("Init GVirConfigDomainChardev=%p", chardev); + + chardev->priv = GVIR_CONFIG_DOMAIN_CHARDEV_GET_PRIVATE(chardev); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev.h b/libvirt-gconfig/libvirt-gconfig-domain-chardev.h new file mode 100644 index 0000000..91b7f4e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev.h @@ -0,0 +1,64 @@ +/* + * libvirt-gconfig-domain-chardev.h: libvirt domain chardev configuration + * + * 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: Daniel P. Berrange <berrange@redhat.com> + */ + +#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_CHARDEV_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DOMAIN_CHARDEV (gvir_config_domain_chardev_get_type ()) +#define GVIR_CONFIG_DOMAIN_CHARDEV(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV, GVirConfigDomainChardev)) +#define GVIR_CONFIG_DOMAIN_CHARDEV_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV, GVirConfigDomainChardevClass)) +#define GVIR_IS_CONFIG_DOMAIN_CHARDEV(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV)) +#define GVIR_IS_CONFIG_DOMAIN_CHARDEV_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV)) +#define GVIR_CONFIG_DOMAIN_CHARDEV_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV, GVirConfigDomainChardevClass)) + +typedef struct _GVirConfigDomainChardev GVirConfigDomainChardev; +typedef struct _GVirConfigDomainChardevPrivate GVirConfigDomainChardevPrivate; +typedef struct _GVirConfigDomainChardevClass GVirConfigDomainChardevClass; + +struct _GVirConfigDomainChardev +{ + GVirConfigDomainDevice parent; + + GVirConfigDomainChardevPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainChardevClass +{ + GVirConfigDomainDeviceClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_domain_chardev_get_type(void); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-console.c b/libvirt-gconfig/libvirt-gconfig-domain-console.c new file mode 100644 index 0000000..d85cc3e --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-console.c @@ -0,0 +1,70 @@ +/* + * libvirt-gconfig-domain-console.c: libvirt domain console configuration + * + * 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: Daniel P. Berrange <berrange@redhat.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +#define GVIR_CONFIG_DOMAIN_CONSOLE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_CONSOLE, GVirConfigDomainConsolePrivate)) + +struct _GVirConfigDomainConsolePrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainConsole, gvir_config_domain_console, GVIR_TYPE_CONFIG_DOMAIN_CHARDEV); + + +static void gvir_config_domain_console_class_init(GVirConfigDomainConsoleClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainConsolePrivate)); +} + + +static void gvir_config_domain_console_init(GVirConfigDomainConsole *console) +{ + g_debug("Init GVirConfigDomainConsole=%p", console); + + console->priv = GVIR_CONFIG_DOMAIN_CONSOLE_GET_PRIVATE(console); +} + +GVirConfigDomainConsole *gvir_config_domain_console_new(void) +{ + GVirConfigObject *object; + + object = gvir_config_object_new(GVIR_TYPE_CONFIG_DOMAIN_CONSOLE, + "console", NULL); + return GVIR_CONFIG_DOMAIN_CONSOLE(object); +} + +GVirConfigDomainConsole *gvir_config_domain_console_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DOMAIN_CONSOLE, + "console", NULL, xml, error); + if (object == NULL) + return NULL; + return GVIR_CONFIG_DOMAIN_CONSOLE(object); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-console.h b/libvirt-gconfig/libvirt-gconfig-domain-console.h new file mode 100644 index 0000000..6243ecf --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-console.h @@ -0,0 +1,67 @@ +/* + * libvirt-gconfig-domain-console.h: libvirt domain console configuration + * + * 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: Daniel P. Berrange <berrange@redhat.com> + */ + +#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_CONSOLE_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_CONSOLE_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DOMAIN_CONSOLE (gvir_config_domain_console_get_type ()) +#define GVIR_CONFIG_DOMAIN_CONSOLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DOMAIN_CONSOLE, GVirConfigDomainConsole)) +#define GVIR_CONFIG_DOMAIN_CONSOLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DOMAIN_CONSOLE, GVirConfigDomainConsoleClass)) +#define GVIR_IS_CONFIG_DOMAIN_CONSOLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DOMAIN_CONSOLE)) +#define GVIR_IS_CONFIG_DOMAIN_CONSOLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DOMAIN_CONSOLE)) +#define GVIR_CONFIG_DOMAIN_CONSOLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DOMAIN_CONSOLE, GVirConfigDomainConsoleClass)) + +typedef struct _GVirConfigDomainConsole GVirConfigDomainConsole; +typedef struct _GVirConfigDomainConsolePrivate GVirConfigDomainConsolePrivate; +typedef struct _GVirConfigDomainConsoleClass GVirConfigDomainConsoleClass; + +struct _GVirConfigDomainConsole +{ + GVirConfigDomainChardev parent; + + GVirConfigDomainConsolePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainConsoleClass +{ + GVirConfigDomainChardevClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_domain_console_get_type(void); +GVirConfigDomainConsole *gvir_config_domain_console_new(void); +GVirConfigDomainConsole *gvir_config_domain_console_new_from_xml(const gchar *xml, + GError **error); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_CONSOLE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index c8df278..ca7d2dc 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -30,7 +30,9 @@ #include <libvirt-gconfig/libvirt-gconfig-object.h> #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-chardev.h> #include <libvirt-gconfig/libvirt-gconfig-domain-clock.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-console.h> #include <libvirt-gconfig/libvirt-gconfig-domain-device.h> #include <libvirt-gconfig/libvirt-gconfig-domain-disk.h> #include <libvirt-gconfig/libvirt-gconfig-domain-filesys.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 9547db1..345dd42 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -29,6 +29,8 @@ LIBVIRT_GCONFIG_0.0.1 { gvir_config_domain_set_virt_type; gvir_config_domain_virt_type_get_type; + gvir_config_domain_chardev_get_type; + gvir_config_domain_clock_get_type; gvir_config_domain_clock_offset_get_type; gvir_config_domain_clock_new; @@ -37,6 +39,10 @@ LIBVIRT_GCONFIG_0.0.1 { gvir_config_domain_clock_set_timezone; gvir_config_domain_clock_set_variable_offset; + gvir_config_domain_console_get_type; + gvir_config_domain_console_new; + gvir_config_domain_console_new_from_xml; + gvir_config_domain_device_get_type; gvir_config_domain_disk_get_type; -- 1.7.7.3

--- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-chardev-source.c | 49 +++++++++++++++ .../libvirt-gconfig-domain-chardev-source.h | 64 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 2 + 5 files changed, 118 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev-source.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index 88fb556..f017848 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -14,6 +14,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-capabilities.h \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-chardev.h \ + libvirt-gconfig-domain-chardev-source.h \ libvirt-gconfig-domain-clock.h \ libvirt-gconfig-domain-console.h \ libvirt-gconfig-domain-device.h \ @@ -50,6 +51,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-capabilities.c \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-chardev.c \ + libvirt-gconfig-domain-chardev-source.c \ libvirt-gconfig-domain-clock.c \ libvirt-gconfig-domain-console.c \ libvirt-gconfig-domain-device.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source.c b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source.c new file mode 100644 index 0000000..0ec3d05 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source.c @@ -0,0 +1,49 @@ +/* + * libvirt-gconfig-domain-chardev-source.c: libvirt domain chardev source base class + * + * 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@redhat.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" + +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE, GVirConfigDomainChardevSourcePrivate)) + +struct _GVirConfigDomainChardevSourcePrivate +{ + gboolean unused; +}; + +G_DEFINE_ABSTRACT_TYPE(GVirConfigDomainChardevSource, gvir_config_domain_chardev_source, GVIR_TYPE_CONFIG_OBJECT); + + +static void gvir_config_domain_chardev_source_class_init(GVirConfigDomainChardevSourceClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainChardevSourcePrivate)); +} + + +static void gvir_config_domain_chardev_source_init(GVirConfigDomainChardevSource *source) +{ + g_debug("Init GVirConfigDomainChardevSource=%p", source); + + source->priv = GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_GET_PRIVATE(source); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h new file mode 100644 index 0000000..dcaa665 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h @@ -0,0 +1,64 @@ +/* + * libvirt-gconfig-domain-chardev-source.h: libvirt domain chardev source base class + * + * 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@redhat.com> + */ + +#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_CHARDEV_SOURCE_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE (gvir_config_domain_chardev_source_get_type ()) +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE, GVirConfigDomainChardevSource)) +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE, GVirConfigDomainChardevSourceClass)) +#define GVIR_IS_CONFIG_DOMAIN_CHARDEV_SOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE)) +#define GVIR_IS_CONFIG_DOMAIN_CHARDEV_SOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE)) +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE, GVirConfigDomainChardevSourceClass)) + +typedef struct _GVirConfigDomainChardevSource GVirConfigDomainChardevSource; +typedef struct _GVirConfigDomainChardevSourcePrivate GVirConfigDomainChardevSourcePrivate; +typedef struct _GVirConfigDomainChardevSourceClass GVirConfigDomainChardevSourceClass; + +struct _GVirConfigDomainChardevSource +{ + GVirConfigObject parent; + + GVirConfigDomainChardevSourcePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainChardevSourceClass +{ + GVirConfigObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_domain_chardev_source_get_type(void); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index ca7d2dc..549f00a 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -31,6 +31,7 @@ #include <libvirt-gconfig/libvirt-gconfig-capabilities.h> #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-chardev.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h> #include <libvirt-gconfig/libvirt-gconfig-domain-clock.h> #include <libvirt-gconfig/libvirt-gconfig-domain-console.h> #include <libvirt-gconfig/libvirt-gconfig-domain-device.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 345dd42..c337b58 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -31,6 +31,8 @@ LIBVIRT_GCONFIG_0.0.1 { gvir_config_domain_chardev_get_type; + gvir_config_domain_chardev_source_get_type; + gvir_config_domain_clock_get_type; gvir_config_domain_clock_offset_get_type; gvir_config_domain_clock_new; -- 1.7.7.3

This is used to associate a ChardevSource (pty, file, ...) with a Chardev (console, serial, ...). --- libvirt-gconfig/libvirt-gconfig-domain-chardev.c | 40 ++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-chardev.h | 4 ++ libvirt-gconfig/libvirt-gconfig.sym | 1 + 3 files changed, 45 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev.c b/libvirt-gconfig/libvirt-gconfig-domain-chardev.c index 525fc2b..ffa9964 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-chardev.c +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev.c @@ -23,6 +23,7 @@ #include <config.h> #include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-object-private.h" #define GVIR_CONFIG_DOMAIN_CHARDEV_GET_PRIVATE(obj) \ (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV, GVirConfigDomainChardevPrivate)) @@ -46,3 +47,42 @@ static void gvir_config_domain_chardev_init(GVirConfigDomainChardev *chardev) chardev->priv = GVIR_CONFIG_DOMAIN_CHARDEV_GET_PRIVATE(chardev); } + +static void prepend_prop(xmlNodePtr node, xmlAttrPtr prop) +{ + if (node->properties == NULL) { + node->properties = prop; + } else { + prop->next = node->properties; + node->properties->prev = prop; + node->properties = prop; + } +} + +void gvir_config_domain_chardev_set_source(GVirConfigDomainChardev *chardev, + GVirConfigDomainChardevSource *source) +{ + xmlNodePtr chardev_node; + xmlNodePtr source_node; + xmlNodePtr child; + xmlAttrPtr attr; + + g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_CHARDEV(chardev)); + g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_CHARDEV_SOURCE(source)); + + chardev_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(chardev)); + source_node = gvir_config_object_get_xml_node(GVIR_CONFIG_OBJECT(source)); + + g_return_if_fail((chardev_node != NULL) && (source_node != NULL)); + + for (child = source_node->children; child != NULL; child = child->next) { + xmlUnlinkNode(child); + xmlAddChild(chardev_node, child); + } + + for (attr = source_node->properties; attr != NULL; attr = attr->next) { + xmlAttrPtr new_attr; + new_attr = xmlCopyProp(chardev_node, attr); + prepend_prop(chardev_node, new_attr); + } +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev.h b/libvirt-gconfig/libvirt-gconfig-domain-chardev.h index 91b7f4e..456c97a 100644 --- a/libvirt-gconfig/libvirt-gconfig-domain-chardev.h +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev.h @@ -27,6 +27,8 @@ #ifndef __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_H__ #define __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_H__ +#include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h> + G_BEGIN_DECLS #define GVIR_TYPE_CONFIG_DOMAIN_CHARDEV (gvir_config_domain_chardev_get_type ()) @@ -58,6 +60,8 @@ struct _GVirConfigDomainChardevClass GType gvir_config_domain_chardev_get_type(void); +void gvir_config_domain_chardev_set_source(GVirConfigDomainChardev *chardev, + GVirConfigDomainChardevSource *source); G_END_DECLS diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index c337b58..6249730 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -30,6 +30,7 @@ LIBVIRT_GCONFIG_0.0.1 { gvir_config_domain_virt_type_get_type; gvir_config_domain_chardev_get_type; + gvir_config_domain_chardev_set_source; gvir_config_domain_chardev_source_get_type; -- 1.7.7.3

--- libvirt-gconfig/Makefile.am | 2 + .../libvirt-gconfig-domain-chardev-source-pty.c | 94 ++++++++++++++++++++ .../libvirt-gconfig-domain-chardev-source-pty.h | 70 +++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 1 + libvirt-gconfig/libvirt-gconfig.sym | 5 + 5 files changed, 172 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h diff --git a/libvirt-gconfig/Makefile.am b/libvirt-gconfig/Makefile.am index f017848..d9f3096 100644 --- a/libvirt-gconfig/Makefile.am +++ b/libvirt-gconfig/Makefile.am @@ -15,6 +15,7 @@ GCONFIG_HEADER_FILES = \ libvirt-gconfig-domain.h \ libvirt-gconfig-domain-chardev.h \ libvirt-gconfig-domain-chardev-source.h \ + libvirt-gconfig-domain-chardev-source-pty.h \ libvirt-gconfig-domain-clock.h \ libvirt-gconfig-domain-console.h \ libvirt-gconfig-domain-device.h \ @@ -52,6 +53,7 @@ GCONFIG_SOURCE_FILES = \ libvirt-gconfig-domain.c \ libvirt-gconfig-domain-chardev.c \ libvirt-gconfig-domain-chardev-source.c \ + libvirt-gconfig-domain-chardev-source-pty.c \ libvirt-gconfig-domain-clock.c \ libvirt-gconfig-domain-console.c \ libvirt-gconfig-domain-device.c \ diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c new file mode 100644 index 0000000..70e553f --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.c @@ -0,0 +1,94 @@ +/* + * libvirt-gconfig-domain-chardev-source-pty.c: libvirt domain chardev pty configuration + * + * 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@redhat.com> + */ + +#include <config.h> + +#include "libvirt-gconfig/libvirt-gconfig.h" +#include "libvirt-gconfig/libvirt-gconfig-object-private.h" + +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY, GVirConfigDomainChardevSourcePtyPrivate)) + +struct _GVirConfigDomainChardevSourcePtyPrivate +{ + gboolean unused; +}; + +G_DEFINE_TYPE(GVirConfigDomainChardevSourcePty, gvir_config_domain_chardev_source_pty, GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE); + + +static void gvir_config_domain_chardev_source_pty_class_init(GVirConfigDomainChardevSourcePtyClass *klass) +{ + g_type_class_add_private(klass, sizeof(GVirConfigDomainChardevSourcePtyPrivate)); +} + + +static void gvir_config_domain_chardev_source_pty_init(GVirConfigDomainChardevSourcePty *source) +{ + g_debug("Init GVirConfigDomainChardevSourcePty=%p", source); + + source->priv = GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY_GET_PRIVATE(source); +} + + +GVirConfigDomainChardevSourcePty *gvir_config_domain_chardev_source_pty_new(void) +{ + GVirConfigObject *object; + + /* the name of the root node is just a placeholder, it will be + * overwritten when the GVirConfigDomainChardevSourcePty is attached to a + * GVirConfigDomainChardevSourcePty + */ + object = gvir_config_object_new(GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY, "dummy", NULL); + gvir_config_object_set_attribute(object, "type", "pty", NULL); + return GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY(object); +} + + +GVirConfigDomainChardevSourcePty *gvir_config_domain_chardev_source_pty_new_from_xml(const gchar *xml, + GError **error) +{ + GVirConfigObject *object; + + /* the name of the root node is just a placeholder, it will be + * overwritten when the GVirConfigDomainChardevSourcePty is attached to a + * GVirConfigDomainChardevSourcePty + */ + object = gvir_config_object_new_from_xml(GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY, + "dummy", NULL, xml, error); + gvir_config_object_set_attribute(object, "type", "pty", NULL); + return GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY(object); +} + +void gvir_config_domain_source_pty_set_path(GVirConfigDomainChardevSourcePty *pty, + const char *path) +{ + GVirConfigObject *source; + g_return_if_fail(GVIR_IS_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY(pty)); + + source = gvir_config_object_replace_child(GVIR_CONFIG_OBJECT(pty), + "source"); + g_return_if_fail(GVIR_IS_CONFIG_OBJECT(source)); + gvir_config_object_set_node_content(GVIR_CONFIG_OBJECT(source), + "path", path); + g_object_unref(G_OBJECT(source)); +} diff --git a/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h new file mode 100644 index 0000000..1c77671 --- /dev/null +++ b/libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h @@ -0,0 +1,70 @@ +/* + * libvirt-gconfig-domain-chardev-source-pty.h: libvirt domain chardev pty configuration + * + * 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@redhat.com> + */ + +#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_CHARDEV_SOURCE_PTY_H__ +#define __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_PTY_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY (gvir_config_domain_chardev_source_pty_get_type ()) +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY, GVirConfigDomainChardevSourcePty)) +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY, GVirConfigDomainChardevSourcePtyClass)) +#define GVIR_IS_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY)) +#define GVIR_IS_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY)) +#define GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_CONFIG_DOMAIN_CHARDEV_SOURCE_PTY, GVirConfigDomainChardevSourcePtyClass)) + +typedef struct _GVirConfigDomainChardevSourcePty GVirConfigDomainChardevSourcePty; +typedef struct _GVirConfigDomainChardevSourcePtyPrivate GVirConfigDomainChardevSourcePtyPrivate; +typedef struct _GVirConfigDomainChardevSourcePtyClass GVirConfigDomainChardevSourcePtyClass; + +struct _GVirConfigDomainChardevSourcePty +{ + GVirConfigDomainChardevSource parent; + + GVirConfigDomainChardevSourcePtyPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirConfigDomainChardevSourcePtyClass +{ + GVirConfigDomainChardevSourceClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_config_domain_chardev_source_pty_get_type(void); + +GVirConfigDomainChardevSourcePty *gvir_config_domain_chardev_source_pty_new(void); +GVirConfigDomainChardevSourcePty *gvir_config_domain_chardev_source_pty_new_from_xml(const gchar *xml, + GError **error); +void gvir_config_domain_source_pty_set_path(GVirConfigDomainChardevSourcePty *pty, + const char *path); + +G_END_DECLS + +#endif /* __LIBVIRT_GCONFIG_DOMAIN_CHARDEV_SOURCE_PTY_H__ */ diff --git a/libvirt-gconfig/libvirt-gconfig.h b/libvirt-gconfig/libvirt-gconfig.h index 549f00a..c60e221 100644 --- a/libvirt-gconfig/libvirt-gconfig.h +++ b/libvirt-gconfig/libvirt-gconfig.h @@ -32,6 +32,7 @@ #include <libvirt-gconfig/libvirt-gconfig-domain.h> #include <libvirt-gconfig/libvirt-gconfig-domain-chardev.h> #include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source.h> +#include <libvirt-gconfig/libvirt-gconfig-domain-chardev-source-pty.h> #include <libvirt-gconfig/libvirt-gconfig-domain-clock.h> #include <libvirt-gconfig/libvirt-gconfig-domain-console.h> #include <libvirt-gconfig/libvirt-gconfig-domain-device.h> diff --git a/libvirt-gconfig/libvirt-gconfig.sym b/libvirt-gconfig/libvirt-gconfig.sym index 6249730..4ea2b1b 100644 --- a/libvirt-gconfig/libvirt-gconfig.sym +++ b/libvirt-gconfig/libvirt-gconfig.sym @@ -34,6 +34,11 @@ LIBVIRT_GCONFIG_0.0.1 { gvir_config_domain_chardev_source_get_type; + gvir_config_domain_chardev_source_pty_get_type; + gvir_config_domain_chardev_source_pty_new; + gvir_config_domain_chardev_source_pty_new_from_xml; + gvir_config_domain_source_pty_set_path; + gvir_config_domain_clock_get_type; gvir_config_domain_clock_offset_get_type; gvir_config_domain_clock_new; -- 1.7.7.3

--- libvirt-gconfig/tests/test-domain-create.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-) diff --git a/libvirt-gconfig/tests/test-domain-create.c b/libvirt-gconfig/tests/test-domain-create.c index cb9ffcb..006ebc6 100644 --- a/libvirt-gconfig/tests/test-domain-create.c +++ b/libvirt-gconfig/tests/test-domain-create.c @@ -136,6 +136,17 @@ int main(void) GVIR_CONFIG_DOMAIN_VIDEO_MODEL_QXL); devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(video)); + /* console node */ + GVirConfigDomainConsole *console; + GVirConfigDomainChardevSourcePty *pty; + + console = gvir_config_domain_console_new(); + pty = gvir_config_domain_chardev_source_pty_new(); + gvir_config_domain_chardev_set_source(GVIR_CONFIG_DOMAIN_CHARDEV(console), + GVIR_CONFIG_DOMAIN_CHARDEV_SOURCE(pty)); + g_object_unref(G_OBJECT(pty)); + devices = g_list_append(devices, GVIR_CONFIG_DOMAIN_DEVICE(console)); + gvir_config_domain_set_devices(domain, devices); g_list_foreach(devices, (GFunc)g_object_unref, NULL); -- 1.7.7.3

On Tue, Dec 06, 2011 at 11:18:03AM +0100, Christophe Fergeau wrote:
Add an abstract GVirConfigDomainChardev object for <console>, <serial>, ... devices and a GVirConfigDomainConsole implementation. This needs to be completed with a separate GVirConfigDomainChardevSource inheritance tree which will be specialized to GVirConfigDomainChardevSourcePty, ... and GVirConfigDomainChardev will offer a helper function to attach a GVirConfigDomainChardevSource to a GVirConfigDomainChardev --- libvirt-gconfig/Makefile.am | 4 + libvirt-gconfig/libvirt-gconfig-domain-chardev.c | 48 +++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-chardev.h | 64 ++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-console.c | 70 ++++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig-domain-console.h | 67 +++++++++++++++++++++ libvirt-gconfig/libvirt-gconfig.h | 2 + libvirt-gconfig/libvirt-gconfig.sym | 6 ++ 7 files changed, 261 insertions(+), 0 deletions(-) create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-chardev.h create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-console.c create mode 100644 libvirt-gconfig/libvirt-gconfig-domain-console.h
ACK to all 5 patches. 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 :|
participants (2)
-
Christophe Fergeau
-
Daniel P. Berrange