[virt-tools-list] [libosinfo PATCHv2 01/11] Add datamap classes

Christophe Fergeau cfergeau at redhat.com
Tue Dec 11 18:20:05 UTC 2012


These will be used to remap generic values set by libosinfo users
to OS-specific values used by OS solution files for automatic
installation.
Based on a patch from Daniel P. Berrange.
---
 osinfo/Makefile.am          |   6 +-
 osinfo/libosinfo.syms       |  12 ++++
 osinfo/osinfo.h             |   2 +
 osinfo/osinfo_datamap.c     | 131 ++++++++++++++++++++++++++++++++++++++++++++
 osinfo/osinfo_datamap.h     |  84 ++++++++++++++++++++++++++++
 osinfo/osinfo_datamaplist.c |  92 +++++++++++++++++++++++++++++++
 osinfo/osinfo_datamaplist.h |  78 ++++++++++++++++++++++++++
 7 files changed, 404 insertions(+), 1 deletion(-)
 create mode 100644 osinfo/osinfo_datamap.c
 create mode 100644 osinfo/osinfo_datamap.h
 create mode 100644 osinfo/osinfo_datamaplist.c
 create mode 100644 osinfo/osinfo_datamaplist.h

diff --git a/osinfo/Makefile.am b/osinfo/Makefile.am
index fa563f4..c365e5f 100644
--- a/osinfo/Makefile.am
+++ b/osinfo/Makefile.am
@@ -58,6 +58,8 @@ OSINFO_HEADER_FILES =		\
   osinfo_avatar_format.h 	\
   osinfo_db.h			\
   osinfo_loader.h		\
+  osinfo_datamap.h		\
+  osinfo_datamaplist.h		\
   osinfo_device.h		\
   osinfo_device_driver.h	\
   osinfo_device_driverlist.h	\
@@ -94,7 +96,9 @@ libosinfo_1_0_include_HEADERS = \
   osinfo_enum_types.h
 
 libosinfo_1_0_la_SOURCES =	  \
-  osinfo_avatar_format.c 	  \
+  osinfo_avatar_format.c	  \
+  osinfo_datamap.c		  \
+  osinfo_datamaplist.c		  \
   osinfo_entity.c		  \
   osinfo_enum_types.c		  \
   osinfo_filter.c		  \
diff --git a/osinfo/libosinfo.syms b/osinfo/libosinfo.syms
index 82f6f95..35525a0 100644
--- a/osinfo/libosinfo.syms
+++ b/osinfo/libosinfo.syms
@@ -372,6 +372,18 @@ LIBOSINFO_0.2.2 {
 	osinfo_os_add_device_driver;
 } LIBOSINFO_0.2.1;
 
+LIBOSINFO_0.2.3 {
+    global:
+	osinfo_datamap_get_type;
+	osinfo_datamap_new;
+	osinfo_datamap_insert;
+	osinfo_datamap_lookup;
+	osinfo_datamap_reverse_lookup;
+
+	osinfo_datamaplist_get_type;
+	osinfo_datamaplist_new;
+} LIBOSINFO_0.2.2;
+
 /* Symbols in next release...
 
   LIBOSINFO_0.0.2 {
diff --git a/osinfo/osinfo.h b/osinfo/osinfo.h
index 836baf1..13b5a0b 100644
--- a/osinfo/osinfo.h
+++ b/osinfo/osinfo.h
@@ -27,6 +27,8 @@
 
 #include <glib-object.h>
 
+#include <osinfo/osinfo_datamap.h>
+#include <osinfo/osinfo_datamaplist.h>
 #include <osinfo/osinfo_enum_types.h>
 #include <osinfo/osinfo_entity.h>
 #include <osinfo/osinfo_filter.h>
diff --git a/osinfo/osinfo_datamap.c b/osinfo/osinfo_datamap.c
new file mode 100644
index 0000000..50c9c7c
--- /dev/null
+++ b/osinfo/osinfo_datamap.c
@@ -0,0 +1,131 @@
+/*
+ * libosinfo:
+ *
+ * Copyright (C) 2009-2012 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors:
+ *   Daniel P. Berrange <berrange at redhat.com>
+ */
+
+#include <config.h>
+
+#include <osinfo/osinfo.h>
+#include <string.h>
+#include <libxml/tree.h>
+#include <libxslt/transform.h>
+#include <libxslt/xsltutils.h>
+#include <libxslt/xsltInternals.h>
+
+G_DEFINE_TYPE (OsinfoDatamap, osinfo_datamap, OSINFO_TYPE_ENTITY);
+
+#define OSINFO_DATAMAP_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_DATAMAP, OsinfoDatamapPrivate))
+
+/**
+ * SECTION:osinfo_datamap
+ * @short_descripion: OS  datamap
+ * @see_also: #OsinfoDatamap
+ *
+ * #OsinfoDatamap is an object for representing OS
+ * datamaps. It is to translate generic osinfo values to OS
+ * specific data.
+ */
+
+struct _OsinfoDatamapPrivate
+{
+    GHashTable *map;
+    GHashTable *reverse_map;
+};
+
+static void
+osinfo_datamap_finalize (GObject *object)
+{
+    OsinfoDatamap *map = OSINFO_DATAMAP(object);
+
+    g_hash_table_unref(map->priv->map);
+    g_hash_table_unref(map->priv->reverse_map);
+
+    /* Chain up to the parent class */
+    G_OBJECT_CLASS (osinfo_datamap_parent_class)->finalize (object);
+}
+
+/* Init functions */
+static void
+osinfo_datamap_class_init (OsinfoDatamapClass *klass)
+{
+    GObjectClass *g_klass = G_OBJECT_CLASS (klass);
+
+    g_klass->finalize = osinfo_datamap_finalize;
+
+    g_type_class_add_private (klass, sizeof (OsinfoDatamapPrivate));
+}
+
+static void
+osinfo_datamap_init (OsinfoDatamap *list)
+{
+    OsinfoDatamapPrivate *priv;
+    list->priv = priv = OSINFO_DATAMAP_GET_PRIVATE(list);
+
+    list->priv->map = g_hash_table_new_full(g_str_hash,
+                                            g_str_equal,
+                                            g_free,
+                                            g_free);
+    list->priv->reverse_map = g_hash_table_new(g_str_hash, g_str_equal);
+}
+
+
+OsinfoDatamap *osinfo_datamap_new(const gchar *id)
+{
+    return g_object_new(OSINFO_TYPE_DATAMAP,
+                        "id", id,
+                        NULL);
+}
+
+
+void osinfo_datamap_insert(OsinfoDatamap *map,
+                           const gchar *inval,
+                           const gchar *outval)
+{
+    gchar *dup_inval;
+    gchar *dup_outval;
+    g_return_if_fail(OSINFO_IS_DATAMAP(map));
+    g_return_if_fail(inval != NULL);
+
+    dup_inval = g_strdup(inval);
+    dup_outval = g_strdup(outval);
+    g_hash_table_insert(map->priv->map, dup_inval, dup_outval);
+    g_hash_table_insert(map->priv->reverse_map, dup_outval, dup_inval);
+}
+
+const gchar *osinfo_datamap_lookup(OsinfoDatamap *map,
+                                   const gchar *inval)
+{
+    return g_hash_table_lookup(map->priv->map, inval);
+}
+
+const gchar *osinfo_datamap_reverse_lookup(OsinfoDatamap *map,
+                                           const gchar *outval)
+{
+    return g_hash_table_lookup(map->priv->reverse_map, outval);
+}
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_datamap.h b/osinfo/osinfo_datamap.h
new file mode 100644
index 0000000..238157c
--- /dev/null
+++ b/osinfo/osinfo_datamap.h
@@ -0,0 +1,84 @@
+/*
+ * libosinfo: OS data map
+ *
+ * Copyright (C) 2009-2012 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors:
+ *   Daniel P. Berrange <berrange at redhat.com>
+ */
+
+#include <glib-object.h>
+
+#ifndef __OSINFO_DATAMAP_H__
+#define __OSINFO_DATAMAP_H__
+
+#include <osinfo/osinfo_entity.h>
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_DATAMAP                  (osinfo_datamap_get_type ())
+#define OSINFO_DATAMAP(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_DATAMAP, OsinfoDatamap))
+#define OSINFO_IS_DATAMAP(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_DATAMAP))
+#define OSINFO_DATAMAP_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_DATAMAP, OsinfoDatamapClass))
+#define OSINFO_IS_DATAMAP_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_DATAMAP))
+#define OSINFO_DATAMAP_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_DATAMAP, OsinfoDatamapClass))
+
+typedef struct _OsinfoDatamap        OsinfoDatamap;
+typedef struct _OsinfoDatamapClass   OsinfoDatamapClass;
+typedef struct _OsinfoDatamapPrivate OsinfoDatamapPrivate;
+
+/* object */
+struct _OsinfoDatamap
+{
+    OsinfoEntity parent_instance;
+
+    /* public */
+
+    /* private */
+    OsinfoDatamapPrivate *priv;
+};
+
+/* class */
+struct _OsinfoDatamapClass
+{
+    OsinfoEntityClass parent_class;
+
+    /* class members */
+};
+
+GType osinfo_datamap_get_type(void);
+
+OsinfoDatamap *osinfo_datamap_new(const gchar *id);
+
+void osinfo_datamap_insert(OsinfoDatamap *map,
+                           const gchar *inval,
+                           const gchar *outval);
+
+const gchar *osinfo_datamap_lookup(OsinfoDatamap *map,
+                                   const gchar *inval);
+const gchar *osinfo_datamap_reverse_lookup(OsinfoDatamap *map,
+                                           const gchar *outval);
+
+#endif /* __OSINFO_DATAMAP_H__ */
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_datamaplist.c b/osinfo/osinfo_datamaplist.c
new file mode 100644
index 0000000..db25bbe
--- /dev/null
+++ b/osinfo/osinfo_datamaplist.c
@@ -0,0 +1,92 @@
+/*
+ * libosinfo:
+ *
+ * Copyright (C) 2009-2012 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors:
+ *   Arjun Roy <arroy at redhat.com>
+ *   Daniel P. Berrange <berrange at redhat.com>
+ */
+
+#include <config.h>
+
+#include <osinfo/osinfo.h>
+
+G_DEFINE_TYPE (OsinfoDatamapList, osinfo_datamaplist, OSINFO_TYPE_LIST);
+
+#define OSINFO_DATAMAPLIST_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), OSINFO_TYPE_DATAMAPLIST, OsinfoDatamapListPrivate))
+
+/**
+ * SECTION:osinfo_datamaplist
+ * @short_description: A list of datamaps
+ * @see_also: #OsinfoList, #OsinfoDatamap
+ *
+ * #OsinfoDatamapList is a list specialization that stores
+ * only #OsinfoDatamap objects.
+ */
+
+struct _OsinfoDatamapListPrivate
+{
+    gboolean unused;
+};
+
+static void
+osinfo_datamaplist_finalize (GObject *object)
+{
+    /* Chain up to the parent class */
+    G_OBJECT_CLASS (osinfo_datamaplist_parent_class)->finalize (object);
+}
+
+/* Init functions */
+static void
+osinfo_datamaplist_class_init (OsinfoDatamapListClass *klass)
+{
+    GObjectClass *g_klass = G_OBJECT_CLASS (klass);
+
+    g_klass->finalize = osinfo_datamaplist_finalize;
+    g_type_class_add_private (klass, sizeof (OsinfoDatamapListPrivate));
+}
+
+static void
+osinfo_datamaplist_init (OsinfoDatamapList *list)
+{
+    OsinfoDatamapListPrivate *priv;
+    list->priv = priv = OSINFO_DATAMAPLIST_GET_PRIVATE(list);
+
+}
+
+/**
+ * osinfo_datamaplist_new:
+ *
+ * Construct a new install_datamap list that is initially empty.
+ *
+ * Returns: (transfer full): an empty install_datamap list
+ */
+OsinfoDatamapList *osinfo_datamaplist_new(void)
+{
+    return g_object_new(OSINFO_TYPE_DATAMAPLIST,
+                        "element-type", OSINFO_TYPE_DATAMAP,
+                        NULL);
+}
+
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
diff --git a/osinfo/osinfo_datamaplist.h b/osinfo/osinfo_datamaplist.h
new file mode 100644
index 0000000..9b7fd1c
--- /dev/null
+++ b/osinfo/osinfo_datamaplist.h
@@ -0,0 +1,78 @@
+/*
+ * libosinfo: a list of installation install_datamap
+ *
+ * Copyright (C) 2009-2012 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Authors:
+ *   Zeeshan Ali <zeenix at redhat.com>
+ *   Arjun Roy <arroy at redhat.com>
+ *   Daniel P. Berrange <berrange at redhat.com>
+ */
+
+#include <glib-object.h>
+#include <osinfo/osinfo_list.h>
+
+#ifndef __OSINFO_DATAMAPLIST_H__
+#define __OSINFO_DATAMAPLIST_H__
+
+/*
+ * Type macros.
+ */
+#define OSINFO_TYPE_DATAMAPLIST                  (osinfo_datamaplist_get_type ())
+#define OSINFO_DATAMAPLIST(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), OSINFO_TYPE_DATAMAPLIST, OsinfoDatamapList))
+#define OSINFO_IS_DATAMAPLIST(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), OSINFO_TYPE_DATAMAPLIST))
+#define OSINFO_DATAMAPLIST_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), OSINFO_TYPE_DATAMAPLIST, OsinfoDatamapListClass))
+#define OSINFO_IS_DATAMAPLIST_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), OSINFO_TYPE_DATAMAPLIST))
+#define OSINFO_DATAMAPLIST_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), OSINFO_TYPE_DATAMAPLIST, OsinfoDatamapListClass))
+
+typedef struct _OsinfoDatamapList        OsinfoDatamapList;
+
+typedef struct _OsinfoDatamapListClass   OsinfoDatamapListClass;
+
+typedef struct _OsinfoDatamapListPrivate OsinfoDatamapListPrivate;
+
+/* object */
+struct _OsinfoDatamapList
+{
+    OsinfoList parent_instance;
+
+    /* public */
+
+    /* private */
+    OsinfoDatamapListPrivate *priv;
+};
+
+/* class */
+struct _OsinfoDatamapListClass
+{
+    OsinfoListClass parent_class;
+
+    /* class members */
+};
+
+GType osinfo_datamaplist_get_type(void);
+
+OsinfoDatamapList *osinfo_datamaplist_new(void);
+
+#endif /* __OSINFO_DATAMAPLIST_H__ */
+/*
+ * Local variables:
+ *  indent-tabs-mode: nil
+ *  c-indent-level: 4
+ *  c-basic-offset: 4
+ * End:
+ */
-- 
1.8.0.1




More information about the virt-tools-list mailing list