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