Add missing ctf-text.c to repo
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 7 May 2011 00:24:40 +0000 (20:24 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 7 May 2011 00:24:40 +0000 (20:24 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf-text/ctf-text.c [new file with mode: 0644]

diff --git a/formats/ctf-text/ctf-text.c b/formats/ctf-text/ctf-text.c
new file mode 100644 (file)
index 0000000..2e9509e
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * BabelTrace - Common Trace Format (CTF)
+ *
+ * CTF Text Format registration.
+ *
+ * Copyright 2010, 2011 - 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
+ * 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:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ */
+
+#include <babeltrace/format.h>
+#include <babeltrace/ctf-text/types.h>
+#include <babeltrace/babeltrace.h>
+#include <inttypes.h>
+#include <uuid/uuid.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <glib.h>
+#include <unistd.h>
+#include <stdlib.h>
+
+struct trace_descriptor *ctf_text_open_trace(const char *path, int flags);
+void ctf_text_close_trace(struct trace_descriptor *descriptor);
+
+static
+rw_dispatch read_dispatch_table[] = {
+       /* All unimplemented */
+};
+
+static
+rw_dispatch write_dispatch_table[] = {
+       [ CTF_TYPE_INTEGER ] = ctf_text_integer_write,
+       [ CTF_TYPE_FLOAT ] = ctf_text_float_write,
+       [ CTF_TYPE_ENUM ] = ctf_text_enum_write,
+       [ CTF_TYPE_STRING ] = ctf_text_string_write,
+       [ CTF_TYPE_STRUCT ] = ctf_text_struct_write,
+       [ CTF_TYPE_VARIANT ] = ctf_text_variant_write,
+       [ CTF_TYPE_ARRAY ] = ctf_text_array_write,
+       [ CTF_TYPE_SEQUENCE ] = ctf_text_sequence_write,
+};
+
+static
+struct format ctf_text_format = {
+       .open_trace = ctf_text_open_trace,
+       .close_trace = ctf_text_close_trace,
+};
+
+struct trace_descriptor *ctf_text_open_trace(const char *path, int flags)
+{
+       struct ctf_text_stream_pos *pos;
+       FILE *fp;
+
+       pos = g_new0(struct ctf_text_stream_pos, 1);
+
+       switch (flags & O_ACCMODE) {
+       case O_WRONLY:
+               fp = fopen(path, "w");
+               if (!fp)
+                       goto error;
+               pos->fp = fp;
+               pos->parent.rw_table = write_dispatch_table;
+               break;
+       case O_RDONLY:
+       default:
+               fprintf(stdout, "[error] Incorrect open flags.\n");
+               goto error;
+       }
+
+       return &pos->trace_descriptor;
+error:
+       g_free(pos);
+       return NULL;
+}
+
+void ctf_text_close_trace(struct trace_descriptor *td)
+{
+       struct ctf_text_stream_pos *pos =
+               container_of(td, struct ctf_text_stream_pos, trace_descriptor);
+       fclose(pos->fp);
+       g_free(pos);
+}
+
+void __attribute__((constructor)) ctf_text_init(void)
+{
+       int ret;
+
+       ctf_text_format.name = g_quark_from_static_string("text");
+       ret = bt_register_format(&ctf_text_format);
+       assert(!ret);
+}
+
+/* TODO: finalize */
This page took 0.025054 seconds and 4 git commands to generate.