Relicense BabelTrace library to MIT (BSD-style)
[babeltrace.git] / types / types.c
1 /*
2 * types.c
3 *
4 * BabelTrace - Converter
5 *
6 * Types registry.
7 *
8 * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 */
20
21 #include <ctf/ctf-types.h>
22 #include <glib.h>
23 #include <errno.h>
24
25 /*
26 * Type hash table contains the registered types. Type registration is typically
27 * performed by a type plugin.
28 * TODO: support plugin unload (unregistration of types).
29 */
30 GHashTable *types;
31
32 struct type_class *ctf_lookup_type(GQuark qname)
33 {
34 return g_hash_table_lookup(type_classes,
35 (gconstpointer) (unsigned long) qname)
36 }
37
38 static void free_type(struct type_class *type_class)
39 {
40 type_class->free(type_class);
41 }
42
43 int ctf_register_type(struct type_class *type_class)
44 {
45 if (ctf_lookup_type_class(type_class->name))
46 return -EEXIST;
47
48 g_hash_table_insert(type_classes,
49 (gconstpointer) (unsigned long) type_class->name,
50 type_class);
51 return 0;
52 }
53
54 int ctf_init_types(void)
55 {
56 type_classes = g_hash_table_new_full(g_direct_hash, g_direct_equal,
57 NULL, free_type);
58 if (!type_classes)
59 return -ENOMEM;
60 return 0;
61 }
62
63 int ctf_finalize_types(void)
64 {
65 g_hash_table_destroy(type_classes);
66 }
This page took 0.031335 seconds and 5 git commands to generate.