Use default if there is no clock declaration
[babeltrace.git] / formats / registry.c
index 4f9dc244a3618451c54e0f4265563d0a7a0bc739..a08b59364548104a93ad1503aac1543fd06b4394 100644 (file)
@@ -3,7 +3,9 @@
  *
  * Format Registry
  *
- * Copyright 2010 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright 2010-2011 EfficiOS Inc. and Linux Foundation
+ *
+ * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
 #include <babeltrace/format.h>
 #include <glib.h>
 #include <errno.h>
+#include <stdio.h>
+
+struct walk_data {
+       FILE *fp;
+       int iter;
+};
 
 static int init_done;
 void __attribute__((constructor)) format_init(void);
@@ -39,6 +47,31 @@ struct format *bt_lookup_format(GQuark 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, "<none>");
+       fprintf(fp, ".\n");
+}
+
 int bt_register_format(struct format *format)
 {
        if (!init_done)
@@ -55,6 +88,8 @@ int bt_register_format(struct format *format)
 
 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;
This page took 0.023673 seconds and 4 git commands to generate.