On Mon, Dec 10, 2012 at 6:45 PM, Christophe Fergeau <cfergeau@xxxxxxxxxx> wrote: > From: "Daniel P. Berrange" <berrange@xxxxxxxxxx> > > 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 | 11 ++++ > 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, 403 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..c644adc 100644 > --- a/osinfo/libosinfo.syms > +++ b/osinfo/libosinfo.syms > @@ -337,6 +337,17 @@ LIBOSINFO_0.2.2 { > osinfo_product_relationship_get_type; > osinfo_path_format_get_type; > > + osinfo_datamap_get_type; > + osinfo_datamap_new; > + osinfo_datamap_insert; > + osinfo_datamap_lookup; > + osinfo_datamap_reverse_lookup; > + > + osinfo_datamaplist_get_type; > + osinfo_datamaplist_new; > + > + osinfo_db_get_datamap; > + > osinfo_entity_get_param_value_enum; > osinfo_entity_set_param_enum; > > 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@xxxxxxxxxx> > + */ > + > +#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@xxxxxxxxxx> > + */ > + > +#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); The parent Entity class already provides API that does the same thing as the two methods above + some utility API on top. > +const gchar *osinfo_datamap_reverse_lookup(OsinfoDatamap *map, > + const gchar *outval); This one is not provided by parent Entity class but perhaps it should be added there instead as it *might* be useful for the some other entity class? -- Regards, Zeeshan Ali (Khattak) FSF member#5124 _______________________________________________ virt-tools-list mailing list virt-tools-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/virt-tools-list