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