Add stddef.h include for offsetof
[babeltrace.git] / types / types.c
CommitLineData
6dc2ca62 1/*
d79865b9 2 * BabelTrace - Converter
6dc2ca62
MD
3 *
4 * Types registry.
5 *
de0ba614 6 * Copyright (c) 2010 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6dc2ca62 7 *
de0ba614
MD
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6dc2ca62
MD
21 */
22
23#include <ctf/ctf-types.h>
24#include <glib.h>
d1708134
MD
25#include <errno.h>
26
d1708134 27/*
698f0fe4
MD
28 * Type hash table contains the registered types. Type registration is typically
29 * performed by a type plugin.
30 * TODO: support plugin unload (unregistration of types).
d1708134 31 */
698f0fe4 32GHashTable *types;
d1708134 33
698f0fe4 34struct type_class *ctf_lookup_type(GQuark qname)
d1708134
MD
35{
36 return g_hash_table_lookup(type_classes,
37 (gconstpointer) (unsigned long) qname)
38}
39
90b676d7
MD
40static void free_type(struct type_class *type_class)
41{
42 type_class->free(type_class);
43}
44
698f0fe4 45int ctf_register_type(struct type_class *type_class)
d1708134 46{
698f0fe4 47 if (ctf_lookup_type_class(type_class->name))
d1708134
MD
48 return -EEXIST;
49
50 g_hash_table_insert(type_classes,
698f0fe4
MD
51 (gconstpointer) (unsigned long) type_class->name,
52 type_class);
d1708134
MD
53 return 0;
54}
55
56int ctf_init_types(void)
57{
58 type_classes = g_hash_table_new_full(g_direct_hash, g_direct_equal,
90b676d7 59 NULL, free_type);
d1708134
MD
60 if (!type_classes)
61 return -ENOMEM;
62 return 0;
63}
64
65int ctf_finalize_types(void)
66{
67 g_hash_table_destroy(type_classes);
68}
This page took 0.024984 seconds and 4 git commands to generate.