Commit | Line | Data |
---|---|---|
fc93b2bd MD |
1 | /* |
2 | * BabelTrace - Common Trace Format (CTF) | |
3 | * | |
4 | * Format registration. | |
5 | * | |
c054553d | 6 | * Copyright 2010, 2011 - Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
fc93b2bd | 7 | * |
ccd7e1c8 MD |
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: | |
fc93b2bd | 14 | * |
ccd7e1c8 MD |
15 | * The above copyright notice and this permission notice shall be included in |
16 | * all copies or substantial portions of the Software. | |
fc93b2bd MD |
17 | */ |
18 | ||
19 | #include <babeltrace/format.h> | |
20 | #include <babeltrace/ctf/types.h> | |
bbefb8dd MD |
21 | #include <babeltrace/ctf/metadata.h> |
22 | #include <errno.h> | |
23 | #include <sys/stat.h> | |
24 | #include <sys/types.h> | |
25 | #include <dirent.h> | |
26 | #include <fcntl.h> | |
27 | #include <glib.h> | |
28 | ||
29 | struct trace_descriptor { | |
30 | struct ctf_trace ctf_trace; | |
31 | }; | |
32 | ||
33 | struct trace_descriptor *ctf_open_trace(const char *path, int flags); | |
34 | void ctf_close_trace(struct trace_descriptor *descriptor); | |
fc93b2bd | 35 | |
4c8bfb7e | 36 | static struct format ctf_format = { |
fc93b2bd MD |
37 | .uint_read = ctf_uint_read, |
38 | .int_read = ctf_int_read, | |
39 | .uint_write = ctf_uint_write, | |
40 | .int_write = ctf_int_write, | |
0a46062b MD |
41 | .double_read = ctf_double_read, |
42 | .double_write = ctf_double_write, | |
fc93b2bd MD |
43 | .float_copy = ctf_float_copy, |
44 | .string_copy = ctf_string_copy, | |
a52d7f6a MD |
45 | .string_read = ctf_string_read, |
46 | .string_write = ctf_string_write, | |
47 | .string_free_temp = ctf_string_free_temp, | |
448d3cc7 MD |
48 | .enum_read = ctf_enum_read, |
49 | .enum_write = ctf_enum_write, | |
11796b96 MD |
50 | .struct_begin = ctf_struct_begin, |
51 | .struct_end = ctf_struct_end, | |
c054553d MD |
52 | .variant_begin = ctf_variant_begin, |
53 | .variant_end = ctf_variant_end, | |
d06d03db MD |
54 | .array_begin = ctf_array_begin, |
55 | .array_end = ctf_array_end, | |
56 | .sequence_begin = ctf_sequence_begin, | |
57 | .sequence_end = ctf_sequence_end, | |
bbefb8dd MD |
58 | .open_trace = ctf_open_trace, |
59 | .close_trace = ctf_close_trace, | |
fc93b2bd MD |
60 | }; |
61 | ||
bbefb8dd MD |
62 | static |
63 | int ctf_open_trace_read(struct trace_descriptor *td, const char *path, int flags) | |
64 | { | |
65 | int ret; | |
66 | ||
67 | td->ctf_trace.flags = flags; | |
68 | ||
69 | /* Open trace directory */ | |
70 | td->ctf_trace.dir = opendir(path); | |
71 | if (!td->ctf_trace.dir) { | |
72 | fprintf(stdout, "Unable to open trace directory.\n"); | |
73 | ret = -ENOENT; | |
74 | goto error; | |
75 | } | |
76 | ||
77 | ||
78 | ||
79 | /* | |
80 | * Open each stream: for each file, try to open, check magic | |
81 | * number, and get the stream ID to add to the right location in | |
82 | * the stream array. | |
83 | * | |
84 | * Keep the metadata file separate. | |
85 | */ | |
86 | ||
87 | ||
88 | ||
89 | /* | |
90 | * Use the metadata file to populate the trace metadata. | |
91 | */ | |
92 | ||
93 | ||
94 | return 0; | |
95 | error: | |
96 | return ret; | |
97 | } | |
98 | ||
99 | static | |
100 | int ctf_open_trace_write(struct trace_descriptor *td, const char *path, int flags) | |
101 | { | |
102 | int ret; | |
103 | ||
104 | ret = mkdir(path, S_IRWXU|S_IRWXG); | |
105 | if (ret) | |
106 | return ret; | |
107 | ||
108 | return 0; | |
109 | } | |
110 | ||
111 | struct trace_descriptor *ctf_open_trace(const char *path, int flags) | |
112 | { | |
113 | struct trace_descriptor *td; | |
114 | int ret; | |
115 | ||
116 | td = g_new(struct trace_descriptor, 1); | |
117 | ||
118 | switch (flags) { | |
119 | case O_RDONLY: | |
120 | ret = ctf_open_trace_read(td, path, flags); | |
121 | if (ret) | |
122 | goto error; | |
123 | break; | |
124 | case O_WRONLY: | |
125 | ret = ctf_open_trace_write(td, path, flags); | |
126 | if (ret) | |
127 | goto error; | |
128 | break; | |
129 | default: | |
130 | fprintf(stdout, "Incorrect open flags.\n"); | |
131 | goto error; | |
132 | } | |
133 | ||
134 | return td; | |
135 | error: | |
136 | g_free(td); | |
137 | return NULL; | |
138 | } | |
139 | ||
140 | void ctf_close_trace(struct trace_descriptor *td) | |
141 | { | |
142 | closedir(td->ctf_trace.dir); | |
143 | g_free(td); | |
144 | } | |
145 | ||
7fb21036 | 146 | void __attribute__((constructor)) ctf_init(void) |
fc93b2bd MD |
147 | { |
148 | int ret; | |
149 | ||
4c8bfb7e | 150 | ctf_format.name = g_quark_from_static_string("ctf"); |
fc93b2bd MD |
151 | ret = bt_register_format(&ctf_format); |
152 | assert(!ret); | |
153 | } | |
698f0fe4 MD |
154 | |
155 | /* TODO: finalize */ |