--- libvirt-gobject/Makefile.am | 3 + .../libvirt-gobject-domain-device-private.h | 31 +++++ libvirt-gobject/libvirt-gobject-domain-device.c | 139 ++++++++++++++++++++ libvirt-gobject/libvirt-gobject-domain-device.h | 64 +++++++++ libvirt-gobject/libvirt-gobject.h | 1 + libvirt-gobject/libvirt-gobject.sym | 2 + 6 files changed, 240 insertions(+), 0 deletions(-) create mode 100644 libvirt-gobject/libvirt-gobject-domain-device-private.h create mode 100644 libvirt-gobject/libvirt-gobject-domain-device.c create mode 100644 libvirt-gobject/libvirt-gobject-domain-device.h diff --git a/libvirt-gobject/Makefile.am b/libvirt-gobject/Makefile.am index 4f84b8b..56a047e 100644 --- a/libvirt-gobject/Makefile.am +++ b/libvirt-gobject/Makefile.am @@ -7,6 +7,7 @@ GOBJECT_HEADER_FILES = \ libvirt-gobject.h \ libvirt-gobject-main.h \ libvirt-gobject-domain-snapshot.h \ + libvirt-gobject-domain-device.h \ libvirt-gobject-domain.h \ libvirt-gobject-interface.h \ libvirt-gobject-network.h \ @@ -21,6 +22,7 @@ GOBJECT_HEADER_FILES = \ GOBJECT_SOURCE_FILES = \ libvirt-gobject-main.c \ libvirt-gobject-domain-snapshot.c \ + libvirt-gobject-domain-device.c \ libvirt-gobject-domain.c \ libvirt-gobject-interface.c \ libvirt-gobject-network.c \ @@ -42,6 +44,7 @@ libvirt_gobject_1_0_la_HEADERS = \ $(GOBJECT_HEADER_FILES) \ libvirt-gobject-input-stream.h nodist_libvirt_gobject_1_0_la_HEADERS = \ + libvirt-gobject-domain-device-private.h \ libvirt-gobject-enums.h libvirt_gobject_1_0_la_SOURCES = \ $(libvirt_gobject_1_0_la_HEADERS) \ diff --git a/libvirt-gobject/libvirt-gobject-domain-device-private.h b/libvirt-gobject/libvirt-gobject-domain-device-private.h new file mode 100644 index 0000000..2a34309 --- /dev/null +++ b/libvirt-gobject/libvirt-gobject-domain-device-private.h @@ -0,0 +1,31 @@ +/* + * libvirt-gobject-domain-device-private.h: 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: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx> + */ +#ifndef __LIBVIRT_GOBJECT_DOMAIN_DEVICE_PRIVATE_H__ +#define __LIBVIRT_GOBJECT_DOMAIN_DEVICE_PRIVATEH__ + +G_BEGIN_DECLS + +virDomainPtr gvir_domain_device_get_domain_handle(GVirDomainDevice *self); + +G_END_DECLS + +#endif /* __LIBVIRT_GOBJECT_DOMAIN_DEVICE_PRIVATEH__ */ diff --git a/libvirt-gobject/libvirt-gobject-domain-device.c b/libvirt-gobject/libvirt-gobject-domain-device.c new file mode 100644 index 0000000..ae03489 --- /dev/null +++ b/libvirt-gobject/libvirt-gobject-domain-device.c @@ -0,0 +1,139 @@ +/* + * libvirt-gobject-domain-device.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: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx> + */ + +#include <config.h> + +#include <libvirt/virterror.h> +#include <string.h> + +#include "libvirt-glib/libvirt-glib.h" +#include "libvirt-gobject/libvirt-gobject.h" + +#include "libvirt-gobject/libvirt-gobject-domain-device-private.h" + +extern gboolean debugFlag; + +#define DEBUG(fmt, ...) do { if (G_UNLIKELY(debugFlag)) g_debug(fmt, ## __VA_ARGS__); } while (0) + +#define GVIR_DOMAIN_DEVICE_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_TYPE_DOMAIN_DEVICE, GVirDomainDevicePrivate)) + +struct _GVirDomainDevicePrivate +{ + GVirDomain *domain; +}; + +G_DEFINE_ABSTRACT_TYPE(GVirDomainDevice, gvir_domain_device, G_TYPE_OBJECT); + +enum { + PROP_0, + PROP_DOMAIN, +}; + +static void gvir_domain_device_get_property(GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + GVirDomainDevice *self = GVIR_DOMAIN_DEVICE(object); + GVirDomainDevicePrivate *priv = self->priv; + + switch (prop_id) { + case PROP_DOMAIN: + g_value_set_object(value, priv->domain); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + + +static void gvir_domain_device_set_property(GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + GVirDomainDevice *self = GVIR_DOMAIN_DEVICE(object); + GVirDomainDevicePrivate *priv = self->priv; + + switch (prop_id) { + case PROP_DOMAIN: + g_clear_object(&priv->domain); + priv->domain = g_value_dup_object(value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + + +static void gvir_domain_device_finalize(GObject *object) +{ + GVirDomainDevice *self = GVIR_DOMAIN_DEVICE(object); + GVirDomainDevicePrivate *priv = self->priv; + + DEBUG("Finalize GVirDomainDevice=%p", self); + + g_clear_object(&priv->domain); + + G_OBJECT_CLASS(gvir_domain_device_parent_class)->finalize(object); +} + +static void gvir_domain_device_class_init(GVirDomainDeviceClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = gvir_domain_device_finalize; + object_class->get_property = gvir_domain_device_get_property; + object_class->set_property = gvir_domain_device_set_property; + + g_object_class_install_property(object_class, + PROP_DOMAIN, + g_param_spec_object("domain", + "domain", + "The associated domain", + GVIR_TYPE_DOMAIN, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_type_class_add_private(klass, sizeof(GVirDomainDevicePrivate)); +} + +static void gvir_domain_device_init(GVirDomainDevice *self) +{ + DEBUG("Init GVirDomainDevice=%p", self); + + self->priv = GVIR_DOMAIN_DEVICE_GET_PRIVATE(self); +} + +G_GNUC_INTERNAL +virDomainPtr gvir_domain_device_get_domain_handle(GVirDomainDevice *self) +{ + virDomainPtr handle; + + g_object_get(self->priv->domain, "handle", &handle, NULL); + + return handle; +} diff --git a/libvirt-gobject/libvirt-gobject-domain-device.h b/libvirt-gobject/libvirt-gobject-domain-device.h new file mode 100644 index 0000000..35d70f5 --- /dev/null +++ b/libvirt-gobject/libvirt-gobject-domain-device.h @@ -0,0 +1,64 @@ +/* + * libvirt-gobject-domain-device.h: 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: Marc-André Lureau <marcandre.lureau@xxxxxxxxxx> + */ + +#if !defined(__LIBVIRT_GOBJECT_H__) && !defined(LIBVIRT_GOBJECT_BUILD) +#error "Only <libvirt-gobject/libvirt-gobject.h> can be included directly." +#endif + +#ifndef __LIBVIRT_GOBJECT_DOMAIN_DEVICE_H__ +#define __LIBVIRT_GOBJECT_DOMAIN_DEVICE_H__ + +G_BEGIN_DECLS + +#define GVIR_TYPE_DOMAIN_DEVICE (gvir_domain_device_get_type ()) +#define GVIR_DOMAIN_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_TYPE_DOMAIN_DEVICE, GVirDomainDevice)) +#define GVIR_DOMAIN_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_TYPE_DOMAIN_DEVICE, GVirDomainDeviceClass)) +#define GVIR_IS_DOMAIN_DEVICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_TYPE_DOMAIN_DEVICE)) +#define GVIR_IS_DOMAIN_DEVICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_TYPE_DOMAIN_DEVICE)) +#define GVIR_DOMAIN_DEVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_TYPE_DOMAIN_DEVICE, GVirDomainDeviceClass)) + +typedef struct _GVirDomainDevice GVirDomainDevice; +typedef struct _GVirDomainDevicePrivate GVirDomainDevicePrivate; +typedef struct _GVirDomainDeviceClass GVirDomainDeviceClass; + +struct _GVirDomainDevice +{ + GObject parent; + + GVirDomainDevicePrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirDomainDeviceClass +{ + GObjectClass parent_class; + + gpointer padding[20]; +}; + + +GType gvir_domain_device_get_type(void); + +G_END_DECLS + +#endif /* __LIBVIRT_GOBJECT_DOMAIN_DEVICE_H__ */ diff --git a/libvirt-gobject/libvirt-gobject.h b/libvirt-gobject/libvirt-gobject.h index 12124e9..3bec2c9 100644 --- a/libvirt-gobject/libvirt-gobject.h +++ b/libvirt-gobject/libvirt-gobject.h @@ -30,6 +30,7 @@ #include <libvirt-gobject/libvirt-gobject-main.h> #include <libvirt-gobject/libvirt-gobject-enums.h> #include <libvirt-gobject/libvirt-gobject-stream.h> +#include <libvirt-gobject/libvirt-gobject-domain-device.h> #include <libvirt-gobject/libvirt-gobject-domain-snapshot.h> #include <libvirt-gobject/libvirt-gobject-domain.h> #include <libvirt-gobject/libvirt-gobject-interface.h> diff --git a/libvirt-gobject/libvirt-gobject.sym b/libvirt-gobject/libvirt-gobject.sym index f0e8402..da03001 100644 --- a/libvirt-gobject/libvirt-gobject.sym +++ b/libvirt-gobject/libvirt-gobject.sym @@ -29,6 +29,8 @@ LIBVIRT_GOBJECT_0.0.1 { gvir_connection_create_domain; gvir_connection_create_storage_pool; + gvir_domain_device_get_type; + gvir_domain_get_type; gvir_domain_handle_get_type; gvir_domain_info_get_type; -- 1.7.7 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list