Remove dead code, enable optimized integer read/write
[babeltrace.git] / formats / ctf-text / ctf-text.c
1 /*
2 * BabelTrace - Common Trace Format (CTF)
3 *
4 * CTF Text Format registration.
5 *
6 * Copyright 2010, 2011 - 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 <babeltrace/format.h>
20 #include <babeltrace/ctf-text/types.h>
21 #include <babeltrace/babeltrace.h>
22 #include <inttypes.h>
23 #include <uuid/uuid.h>
24 #include <sys/mman.h>
25 #include <errno.h>
26 #include <sys/types.h>
27 #include <sys/stat.h>
28 #include <fcntl.h>
29 #include <dirent.h>
30 #include <glib.h>
31 #include <unistd.h>
32 #include <stdlib.h>
33
34 struct trace_descriptor *ctf_text_open_trace(const char *path, int flags);
35 void ctf_text_close_trace(struct trace_descriptor *descriptor);
36
37 static
38 rw_dispatch write_dispatch_table[] = {
39 [ CTF_TYPE_INTEGER ] = ctf_text_integer_write,
40 [ CTF_TYPE_FLOAT ] = ctf_text_float_write,
41 [ CTF_TYPE_ENUM ] = ctf_text_enum_write,
42 [ CTF_TYPE_STRING ] = ctf_text_string_write,
43 [ CTF_TYPE_STRUCT ] = ctf_text_struct_write,
44 [ CTF_TYPE_VARIANT ] = ctf_text_variant_write,
45 [ CTF_TYPE_ARRAY ] = ctf_text_array_write,
46 [ CTF_TYPE_SEQUENCE ] = ctf_text_sequence_write,
47 };
48
49 static
50 struct format ctf_text_format = {
51 .open_trace = ctf_text_open_trace,
52 .close_trace = ctf_text_close_trace,
53 };
54
55 struct trace_descriptor *ctf_text_open_trace(const char *path, int flags)
56 {
57 struct ctf_text_stream_pos *pos;
58 FILE *fp;
59
60 pos = g_new0(struct ctf_text_stream_pos, 1);
61
62 switch (flags & O_ACCMODE) {
63 case O_WRONLY:
64 if (!path)
65 path = "/dev/stdout";
66 fp = fopen(path, "w");
67 if (!fp)
68 goto error;
69 pos->fp = fp;
70 pos->parent.rw_table = write_dispatch_table;
71 break;
72 case O_RDONLY:
73 default:
74 fprintf(stdout, "[error] Incorrect open flags.\n");
75 goto error;
76 }
77
78 return &pos->trace_descriptor;
79 error:
80 g_free(pos);
81 return NULL;
82 }
83
84 void ctf_text_close_trace(struct trace_descriptor *td)
85 {
86 struct ctf_text_stream_pos *pos =
87 container_of(td, struct ctf_text_stream_pos, trace_descriptor);
88 fclose(pos->fp);
89 g_free(pos);
90 }
91
92 void __attribute__((constructor)) ctf_text_init(void)
93 {
94 int ret;
95
96 ctf_text_format.name = g_quark_from_static_string("text");
97 ret = bt_register_format(&ctf_text_format);
98 assert(!ret);
99 }
100
101 /* TODO: finalize */
This page took 0.035384 seconds and 5 git commands to generate.