X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fregistry.c;h=a08b59364548104a93ad1503aac1543fd06b4394;hp=83e0aa0e30d5b04c4157abb370edd56c1ed7afc6;hb=1842a4c801d0878adf40862fda0c310a52a6fdd2;hpb=fc93b2bdc2ced1d46fefb91fe79391afded8e504 diff --git a/formats/registry.c b/formats/registry.c index 83e0aa0e..a08b5936 100644 --- a/formats/registry.c +++ b/formats/registry.c @@ -3,25 +3,30 @@ * * Format Registry * - * Copyright (c) 2010 Mathieu Desnoyers + * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation * - * 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. + * Author: Mathieu Desnoyers * - * 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. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: * - * 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 + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. */ +#include #include #include +#include + +struct walk_data { + FILE *fp; + int iter; +}; static int init_done; void __attribute__((constructor)) format_init(void); @@ -39,31 +44,58 @@ struct format *bt_lookup_format(GQuark qname) if (!init_done) return NULL; return g_hash_table_lookup(format_registry, - (gconstpointer) (unsigned long) qname) + (gconstpointer) (unsigned long) qname); +} + +static void show_format(gpointer key, gpointer value, gpointer user_data) +{ + struct walk_data *data = user_data; + + fprintf(data->fp, "%s%s", data->iter ? ", " : "", + g_quark_to_string((GQuark) (unsigned long) key)); + data->iter++; +} + +void bt_fprintf_format_list(FILE *fp) +{ + struct walk_data data; + + data.fp = fp; + data.iter = 0; + + fprintf(fp, "Formats available: "); + if (!init_done) + return; + g_hash_table_foreach(format_registry, show_format, &data); + if (data.iter == 0) + fprintf(fp, ""); + fprintf(fp, ".\n"); } -int bt_register_format(const struct format *format) +int bt_register_format(struct format *format) { if (!init_done) format_init(); - if (bt_lookup_format(qname)) + if (bt_lookup_format(format->name)) return -EEXIST; g_hash_table_insert(format_registry, - (gconstpointer) (unsigned long) format->name, + (gpointer) (unsigned long) format->name, format); return 0; } void format_init(void) { + if (init_done) + return; format_registry = g_hash_table_new(g_direct_hash, g_direct_equal); assert(format_registry); init_done = 1; } -int format_finalize(void) +void format_finalize(void) { g_hash_table_destroy(format_registry); }