diff options
author | Christophe Fergeau <cfergeau@redhat.com> | 2014-01-27 13:43:17 +0100 |
---|---|---|
committer | Christophe Fergeau <cfergeau@redhat.com> | 2014-01-27 13:56:56 +0100 |
commit | 30801d973bb30ea03e71ba9a2d8ba4cc695a4eb8 (patch) | |
tree | ab461d8ed513173291b8680530cfd9691a747007 | |
parent | d7730acae904b75c11664b4cf90a7653f94d9636 (diff) |
add GVirBuilderDomain boiler plate
Not even sure this will be needed nor what the final API will look like,
but having the boilerplate there will make experimentations more pleasont
:)
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | libvirt-builder/Makefile.am | 6 | ||||
-rw-r--r-- | libvirt-builder/libvirt-builder-domain.c | 260 | ||||
-rw-r--r-- | libvirt-builder/libvirt-builder-domain.h | 72 | ||||
-rw-r--r-- | libvirt-builder/libvirt-builder.h | 3 | ||||
-rw-r--r-- | libvirt-builder/libvirt-builder.sym | 3 |
6 files changed, 346 insertions, 2 deletions
diff --git a/configure.ac b/configure.ac index 1affa61..4b317be 100644 --- a/configure.ac +++ b/configure.ac @@ -75,7 +75,9 @@ AC_CONFIG_LIBOBJ_DIR([libvirt-builder]) LIBVIRT_BUILDER_COMPILE_WARNINGS -PKG_CHECK_MODULES(GLIB2, glib-2.0) +PKG_CHECK_MODULES(GLIB2, [glib-2.0]) +PKG_CHECK_MODULES(OSINFO, [libosinfo-1.0]) +PKG_CHECK_MODULES(LIBVIRT_GCONFIG, [libvirt-gconfig-1.0]) LIBVIRT_BUILDER_GETTEXT LIBVIRT_BUILDER_GTK_MISC diff --git a/libvirt-builder/Makefile.am b/libvirt-builder/Makefile.am index 91b502e..a1ea535 100644 --- a/libvirt-builder/Makefile.am +++ b/libvirt-builder/Makefile.am @@ -21,9 +21,11 @@ BUILDER_GENERATED_FILES = \ BUILDER_HEADER_FILES = \ libvirt-builder.h \ libvirt-builder-internal.h \ + libvirt-builder-domain.h \ libvirt-builder-main.h \ $(NULL) BUILDER_SOURCE_FILES = \ + libvirt-builder-domain.c \ libvirt-builder-main.c \ $(NULL) @@ -47,10 +49,14 @@ libvirt_builder_1_0_la_CFLAGS = \ $(COVERAGE_CFLAGS) \ -I$(top_srcdir) \ $(GLIB2_CFLAGS) \ + $(LIBVIRT_GCONFIG_CFLAGS) \ + $(OSINFO_CFLAGS) \ $(WARN_CFLAGS) \ $(NULL) libvirt_builder_1_0_la_LIBADD = \ $(GLIB2_LIBS) \ + $(LIBVIRT_GCONFIG_LIBS) \ + $(OSINFO_LIBS) \ $(CYGWIN_EXTRA_LIBADD) \ $(NULL) libvirt_builder_1_0_la_DEPENDENCIES = \ diff --git a/libvirt-builder/libvirt-builder-domain.c b/libvirt-builder/libvirt-builder-domain.c new file mode 100644 index 0000000..3a34691 --- /dev/null +++ b/libvirt-builder/libvirt-builder-domain.c @@ -0,0 +1,260 @@ +/* + * libvirt-builder-domain.c: libvirt domain configuration + * + * Copyright (C) 2012-2014 Red Hat, Inc. + * + * 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, see + * <http://www.gnu.org/licenses/>. + * + * Authors: + * Daniel P. Berrange <berrange@redhat.com> + * Christophe Fergeau <cfergeau@redhat.com> + */ + +#include <config.h> +#include <string.h> +#include <sys/utsname.h> + +#include "libvirt-builder/libvirt-builder.h" +#include "libvirt-builder/libvirt-builder-internal.h" + +#define GVIR_BUILDER_DOMAIN_GET_PRIVATE(obj) \ + (G_TYPE_INSTANCE_GET_PRIVATE((obj), GVIR_BUILDER_TYPE_DOMAIN, GVirBuilderDomainPrivate)) + +struct _GVirBuilderDomainPrivate +{ + GVirConfigDomain *config; + GVirConfigCapabilities *caps; + OsinfoDb *osinfo_db; + OsinfoOs *os; + OsinfoPlatform *platform; + + OsinfoDeployment *deployment; + OsinfoDeviceDriverList *drivers; + + /* next disk targets */ + unsigned int ide; + unsigned int virtio; + unsigned int sata; +}; + +G_DEFINE_TYPE(GVirBuilderDomain, gvir_builder_domain, G_TYPE_OBJECT); + +#if 0 +#define GVIR_BUILDER_DOMAIN_ERROR gvir_builder_domain_error_quark() + +static GQuark +gvir_builder_domain_error_quark(void) +{ + return g_quark_from_static_string("gvir-builder-domain"); +} + +static gboolean error_is_set(GError **error) +{ + return ((error != NULL) && (*error != NULL)); +} +#endif + +enum { + PROP_0, + PROP_CONFIG, + PROP_OS, + PROP_PLATFORM, + PROP_CAPS, + PROP_OSINFO_DB, +}; + +static void gvir_builder_domain_get_property(GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + g_return_if_fail(GVIR_BUILDER_IS_DOMAIN(object)); + + GVirBuilderDomain *design = GVIR_BUILDER_DOMAIN(object); + GVirBuilderDomainPrivate *priv = design->priv; + + switch (prop_id) { + case PROP_CONFIG: + g_value_set_object(value, priv->config); + break; + + case PROP_OSINFO_DB: + g_value_set_object(value, priv->osinfo_db); + break; + + case PROP_OS: + g_value_set_object(value, priv->os); + break; + + case PROP_PLATFORM: + g_value_set_object(value, priv->platform); + break; + + case PROP_CAPS: + g_value_set_object(value, priv->caps); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + + +static void gvir_builder_domain_set_property(GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + g_return_if_fail(GVIR_BUILDER_IS_DOMAIN(object)); + + GVirBuilderDomain *design = GVIR_BUILDER_DOMAIN(object); + GVirBuilderDomainPrivate *priv = design->priv; + + switch (prop_id) { + case PROP_OSINFO_DB: + if (priv->osinfo_db) + g_object_unref(priv->osinfo_db); + priv->osinfo_db = g_value_dup_object(value); + break; + case PROP_OS: + if (priv->os) + g_object_unref(priv->os); + priv->os = g_value_dup_object(value); + break; + + case PROP_PLATFORM: + if (priv->platform) + g_object_unref(priv->platform); + priv->platform = g_value_dup_object(value); + break; + + case PROP_CAPS: + if (priv->caps) + g_object_unref(priv->caps); + priv->caps = g_value_dup_object(value); + break; + + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); + } +} + + +static void gvir_builder_domain_finalize(GObject *object) +{ + GVirBuilderDomain *conn = GVIR_BUILDER_DOMAIN(object); + GVirBuilderDomainPrivate *priv = conn->priv; + + g_object_unref(priv->config); + g_object_unref(priv->os); + g_object_unref(priv->platform); + g_object_unref(priv->caps); + if (priv->deployment) + g_object_unref(priv->deployment); + if (priv->osinfo_db) + g_object_unref(priv->osinfo_db); + if (priv->drivers) + g_object_unref(priv->drivers); + + G_OBJECT_CLASS(gvir_builder_domain_parent_class)->finalize(object); +} + + +static void gvir_builder_domain_class_init(GVirBuilderDomainClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS(klass); + + object_class->finalize = gvir_builder_domain_finalize; + + object_class->get_property = gvir_builder_domain_get_property; + object_class->set_property = gvir_builder_domain_set_property; + + g_object_class_install_property(object_class, + PROP_CONFIG, + g_param_spec_object("config", + "Config", + "Domain config", + GVIR_CONFIG_TYPE_DOMAIN, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property(object_class, + PROP_OSINFO_DB, + g_param_spec_object("osinfo-db", + "Osinfo Database", + "libosinfo database", + OSINFO_TYPE_DB, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + g_object_class_install_property(object_class, + PROP_OS, + g_param_spec_object("os", + "Os", + "Operating system", + OSINFO_TYPE_OS, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + g_object_class_install_property(object_class, + PROP_PLATFORM, + g_param_spec_object("platform", + "Platform", + "Platform", + OSINFO_TYPE_PLATFORM, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + g_object_class_install_property(object_class, + PROP_CAPS, + g_param_spec_object("capabilities", + "Capabilities", + "Capabilities", + GVIR_CONFIG_TYPE_CAPABILITIES, + G_PARAM_READABLE | + G_PARAM_WRITABLE | + G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + g_type_class_add_private(klass, sizeof(GVirBuilderDomainPrivate)); +} + +static void gvir_builder_domain_init(GVirBuilderDomain *design) +{ + GVirBuilderDomainPrivate *priv; + g_debug("Init GVirBuilderDomain=%p", design); + + priv = design->priv = GVIR_BUILDER_DOMAIN_GET_PRIVATE(design); + priv->config = gvir_config_domain_new(); + priv->drivers = osinfo_device_driverlist_new(); +} + + +GVirBuilderDomain *gvir_builder_domain_new(OsinfoDb *db, + OsinfoOs *os, + OsinfoPlatform *platform, + GVirConfigCapabilities *caps) +{ + return GVIR_BUILDER_DOMAIN(g_object_new(GVIR_BUILDER_TYPE_DOMAIN, + "osinfo-db", db, + "os", os, + "platform", platform, + "capabilities", caps, + NULL)); +} + diff --git a/libvirt-builder/libvirt-builder-domain.h b/libvirt-builder/libvirt-builder-domain.h new file mode 100644 index 0000000..9120aa3 --- /dev/null +++ b/libvirt-builder/libvirt-builder-domain.h @@ -0,0 +1,72 @@ +/* + * libvirt-builder-domain.h: libvirt domain configuration + * + * Copyright (C) 2012, 2014 Red Hat, Inc. + * + * 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, see + * <http://www.gnu.org/licenses/>. + * + * Author: Daniel P. Berrange <berrange@redhat.com> + * Christophe Fergeau <cfergeau@redhat.com> + */ + +#if !defined(__LIBVIRT_BUILDER_H__) && !defined(LIBVIRT_BUILDER_BUILD) +#error "Only <libvirt-builder/libvirt-builder.h> can be included directly." +#endif + +#ifndef __LIBVIRT_BUILDER_DOMAIN_H__ +#define __LIBVIRT_BUILDER_DOMAIN_H__ + +#include <osinfo/osinfo.h> +#include <libvirt-gconfig/libvirt-gconfig.h> + +G_BEGIN_DECLS + +#define GVIR_BUILDER_TYPE_DOMAIN (gvir_builder_domain_get_type ()) +#define GVIR_BUILDER_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GVIR_BUILDER_TYPE_DOMAIN, GVirBuilderDomain)) +#define GVIR_BUILDER_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GVIR_BUILDER_TYPE_DOMAIN, GVirBuilderDomainClass)) +#define GVIR_BUILDER_IS_DOMAIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GVIR_BUILDER_TYPE_DOMAIN)) +#define GVIR_BUILDER_IS_DOMAIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GVIR_BUILDER_TYPE_DOMAIN)) +#define GVIR_BUILDER_DOMAIN_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GVIR_BUILDER_TYPE_DOMAIN, GVirBuilderDomainClass)) + +typedef struct _GVirBuilderDomain GVirBuilderDomain; +typedef struct _GVirBuilderDomainPrivate GVirBuilderDomainPrivate; +typedef struct _GVirBuilderDomainClass GVirBuilderDomainClass; + +struct _GVirBuilderDomain +{ + GObject parent; + + GVirBuilderDomainPrivate *priv; + + /* Do not add fields to this struct */ +}; + +struct _GVirBuilderDomainClass +{ + GObjectClass parent_class; + + gpointer padding[20]; +}; + +GType gvir_builder_domain_get_type(void); + +GVirBuilderDomain *gvir_builder_domain_new(OsinfoDb *osinfo_db, + OsinfoOs *os, + OsinfoPlatform *platform, + GVirConfigCapabilities *caps); + +G_END_DECLS + +#endif /* __LIBVIRT_BUILDER_DOMAIN_H__ */ diff --git a/libvirt-builder/libvirt-builder.h b/libvirt-builder/libvirt-builder.h index 69300e9..d8e2b12 100644 --- a/libvirt-builder/libvirt-builder.h +++ b/libvirt-builder/libvirt-builder.h @@ -1,7 +1,7 @@ /* * libvirt-builder.h: libvirt builder integration * - * Copyright (C) 2012, 2013 Red Hat, Inc. + * Copyright (C) 2012-2014 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -28,6 +28,7 @@ #include <glib.h> /* Local includes */ +#include <libvirt-builder/libvirt-builder-domain.h> #include <libvirt-builder/libvirt-builder-main.h> #include <libvirt-builder/libvirt-builder-enum-types.h> diff --git a/libvirt-builder/libvirt-builder.sym b/libvirt-builder/libvirt-builder.sym index 4d24aa5..2ac4aec 100644 --- a/libvirt-builder/libvirt-builder.sym +++ b/libvirt-builder/libvirt-builder.sym @@ -3,6 +3,9 @@ LIBVIRT_BUILDER_0.0.1 { gvir_builder_init; gvir_builder_init_check; + gvir_builder_domain_get_type; + gvir_builder_domain_new; + local: *; }; |