Commit | Line | Data |
---|---|---|
46bd0f2b JG |
1 | #ifndef BABELTRACE_CTF_WRITER_WRITER_H |
2 | #define BABELTRACE_CTF_WRITER_WRITER_H | |
3 | ||
4 | /* | |
5 | * BabelTrace - CTF Writer: Writer | |
6 | * | |
de9dd397 | 7 | * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
46bd0f2b JG |
8 | * |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
28 | * | |
29 | * The Common Trace Format (CTF) Specification is available at | |
30 | * http://www.efficios.com/ctf | |
31 | */ | |
32 | ||
8deee039 PP |
33 | #include <babeltrace/ctf-writer/field-types.h> |
34 | #include <babeltrace/ctf-writer/stream-class.h> | |
35 | #include <babeltrace/ctf-writer/stream.h> | |
36 | #include <babeltrace/ctf-writer/trace.h> | |
adc315b8 | 37 | |
46bd0f2b JG |
38 | #ifdef __cplusplus |
39 | extern "C" { | |
40 | #endif | |
41 | ||
42 | struct bt_ctf_writer; | |
43 | struct bt_ctf_stream; | |
44 | struct bt_ctf_stream_class; | |
45 | struct bt_ctf_clock; | |
46 | ||
46bd0f2b JG |
47 | /* |
48 | * bt_ctf_writer_create: create a writer instance. | |
49 | * | |
50 | * Allocate a new writer that will produce a trace in the given path. | |
51 | * The creation of a writer sets its reference count to 1. | |
52 | * | |
53 | * @param path Path to the trace's containing folder (string is copied). | |
54 | * | |
55 | * Returns an allocated writer on success, NULL on error. | |
56 | */ | |
57 | extern struct bt_ctf_writer *bt_ctf_writer_create(const char *path); | |
58 | ||
a2540e85 JG |
59 | /* |
60 | * bt_ctf_writer_get_trace: Get a writer's associated trace. | |
61 | * | |
62 | * @param writer Writer instance. | |
63 | * | |
64 | * Return the writer's associated instance, NULL on error. | |
65 | */ | |
66 | extern struct bt_ctf_trace *bt_ctf_writer_get_trace( | |
67 | struct bt_ctf_writer *writer); | |
68 | ||
46bd0f2b JG |
69 | /* |
70 | * bt_ctf_writer_create_stream: create a stream instance. | |
71 | * | |
72 | * Allocate a new stream instance and register it to the writer. The creation of | |
73 | * a stream sets its reference count to 1. | |
74 | * | |
75 | * @param writer Writer instance. | |
76 | * @param stream_class Stream class to instantiate. | |
77 | * | |
cbd6a071 | 78 | * Returns an allocated stream on success, NULL on error. |
46bd0f2b JG |
79 | */ |
80 | extern struct bt_ctf_stream *bt_ctf_writer_create_stream( | |
81 | struct bt_ctf_writer *writer, | |
82 | struct bt_ctf_stream_class *stream_class); | |
83 | ||
84 | /* | |
85 | * bt_ctf_writer_add_environment_field: add an environment field to the trace. | |
86 | * | |
87 | * Add an environment field to the trace. The name and value parameters are | |
88 | * copied. | |
89 | * | |
90 | * @param writer Writer instance. | |
91 | * @param name Name of the environment field (will be copied). | |
92 | * @param value Value of the environment field (will be copied). | |
93 | * | |
94 | * Returns 0 on success, a negative value on error. | |
95 | */ | |
96 | extern int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, | |
97 | const char *name, | |
98 | const char *value); | |
99 | ||
d7503815 SM |
100 | /* |
101 | * bt_ctf_writer_add_environment_field_int64: add an environment field to the trace. | |
102 | * | |
103 | * Add an environment field to the trace. The name and value parameters are | |
104 | * copied. | |
105 | * | |
106 | * @param writer Writer instance. | |
107 | * @param name Name of the environment field (will be copied). | |
108 | * @param value Value of the environment field. | |
109 | * | |
110 | * Returns 0 on success, a negative value on error. | |
111 | */ | |
112 | extern int bt_ctf_writer_add_environment_field_int64( | |
113 | struct bt_ctf_writer *writer, | |
114 | const char *name, | |
115 | int64_t value); | |
116 | ||
46bd0f2b JG |
117 | /* |
118 | * bt_ctf_writer_add_clock: add a clock to the trace. | |
119 | * | |
120 | * Add a clock to the trace. Clocks assigned to stream classes must be | |
121 | * registered to the writer. | |
122 | * | |
123 | * @param writer Writer instance. | |
124 | * @param clock Clock to add to the trace. | |
125 | * | |
126 | * Returns 0 on success, a negative value on error. | |
127 | */ | |
128 | extern int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, | |
129 | struct bt_ctf_clock *clock); | |
130 | ||
131 | /* | |
132 | * bt_ctf_writer_get_metadata_string: get meta-data string. | |
133 | * | |
134 | * Get the trace's TSDL meta-data. The caller assumes the ownership of the | |
135 | * returned string. | |
136 | * | |
137 | * @param writer Writer instance. | |
138 | * | |
139 | * Returns the metadata string on success, NULL on error. | |
140 | */ | |
141 | extern char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer); | |
142 | ||
143 | /* | |
144 | * bt_ctf_writer_flush_metadata: flush the trace's metadata to disk. | |
145 | * | |
146 | * Flush the trace's metadata to the metadata file. Note that the metadata will | |
147 | * be flushed automatically when the Writer instance is released (last call to | |
148 | * bt_ctf_writer_put). | |
149 | * | |
150 | * @param writer Writer instance. | |
151 | */ | |
152 | extern void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer); | |
153 | ||
154 | /* | |
155 | * bt_ctf_writer_set_byte_order: set a field type's byte order. | |
156 | * | |
c35a1669 | 157 | * Set the trace's byte order. Defaults to the host machine's endianness. |
46bd0f2b JG |
158 | * |
159 | * @param writer Writer instance. | |
160 | * @param byte_order Trace's byte order. | |
161 | * | |
162 | * Returns 0 on success, a negative value on error. | |
c35a1669 JG |
163 | * |
164 | * Note: byte_order must not be BT_CTF_BYTE_ORDER_NATIVE since, according | |
165 | * to the CTF specification, is defined as "the byte order described in the | |
166 | * trace description". | |
46bd0f2b JG |
167 | */ |
168 | extern int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, | |
169 | enum bt_ctf_byte_order byte_order); | |
170 | ||
171 | /* | |
172 | * bt_ctf_writer_get and bt_ctf_writer_put: increment and decrement the | |
173 | * writer's reference count. | |
174 | * | |
de3dd40e PP |
175 | * You may also use bt_ctf_get() and bt_ctf_put() with writer objects. |
176 | * | |
46bd0f2b JG |
177 | * These functions ensure that the writer won't be destroyed while it |
178 | * is in use. The same number of get and put (plus one extra put to | |
179 | * release the initial reference done at creation) have to be done to | |
180 | * destroy a writer. | |
181 | * | |
182 | * When the writer's reference count is decremented to 0 by a | |
183 | * bt_ctf_writer_put, the writer is freed. | |
184 | * | |
185 | * @param writer Writer instance. | |
186 | */ | |
8deee039 PP |
187 | |
188 | /* Pre-2.0 CTF writer compatibility */ | |
189 | static inline | |
190 | void bt_ctf_writer_get(struct bt_ctf_writer *writer) | |
191 | { | |
8138bfe1 | 192 | bt_object_get_ref(writer); |
8deee039 PP |
193 | } |
194 | ||
195 | /* Pre-2.0 CTF writer compatibility */ | |
196 | static inline | |
197 | void bt_ctf_writer_put(struct bt_ctf_writer *writer) | |
198 | { | |
8138bfe1 | 199 | bt_object_put_ref(writer); |
8deee039 | 200 | } |
46bd0f2b JG |
201 | |
202 | #ifdef __cplusplus | |
203 | } | |
204 | #endif | |
205 | ||
206 | #endif /* BABELTRACE_CTF_WRITER_WRITER_H */ |