1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
|
/*
* 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, see
* <http://www.gnu.org/licenses/>.
*
* Authors:
* Daniel P. Berrange <berrange@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)
{
list->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:
*/
|