Move to kernel style SPDX license identifiers
[babeltrace.git] / include / babeltrace2-ctf-writer / writer.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (C) 2010-2019 EfficiOS Inc. and Linux Foundation
5 */
6
7 #ifndef BABELTRACE2_CTF_WRITER_WRITER_H
8 #define BABELTRACE2_CTF_WRITER_WRITER_H
9
10 #include <babeltrace2-ctf-writer/field-types.h>
11 #include <babeltrace2-ctf-writer/stream-class.h>
12 #include <babeltrace2-ctf-writer/stream.h>
13 #include <babeltrace2-ctf-writer/trace.h>
14
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18
19 struct bt_ctf_writer;
20 struct bt_ctf_stream;
21 struct bt_ctf_stream_class;
22 struct bt_ctf_clock;
23
24 /*
25 * bt_ctf_writer_create: create a writer instance.
26 *
27 * Allocate a new writer that will produce a trace in the given path.
28 * The creation of a writer sets its reference count to 1.
29 *
30 * @param path Path to the trace's containing folder (string is copied).
31 *
32 * Returns an allocated writer on success, NULL on error.
33 */
34 extern struct bt_ctf_writer *bt_ctf_writer_create(const char *path);
35
36 /*
37 * bt_ctf_writer_get_trace: Get a writer's associated trace.
38 *
39 * @param writer Writer instance.
40 *
41 * Return the writer's associated instance, NULL on error.
42 */
43 extern struct bt_ctf_trace *bt_ctf_writer_get_trace(
44 struct bt_ctf_writer *writer);
45
46 /*
47 * bt_ctf_writer_create_stream: create a stream instance.
48 *
49 * Allocate a new stream instance and register it to the writer. The creation of
50 * a stream sets its reference count to 1.
51 *
52 * @param writer Writer instance.
53 * @param stream_class Stream class to instantiate.
54 *
55 * Returns an allocated stream on success, NULL on error.
56 */
57 extern struct bt_ctf_stream *bt_ctf_writer_create_stream(
58 struct bt_ctf_writer *writer,
59 struct bt_ctf_stream_class *stream_class);
60
61 /*
62 * bt_ctf_writer_add_environment_field: add an environment field to the trace.
63 *
64 * Add an environment field to the trace. The name and value parameters are
65 * copied.
66 *
67 * @param writer Writer instance.
68 * @param name Name of the environment field (will be copied).
69 * @param value Value of the environment field (will be copied).
70 *
71 * Returns 0 on success, a negative value on error.
72 */
73 extern int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer,
74 const char *name,
75 const char *value);
76
77 /*
78 * bt_ctf_writer_add_environment_field_int64: add an environment field to the trace.
79 *
80 * Add an environment field to the trace. The name and value parameters are
81 * copied.
82 *
83 * @param writer Writer instance.
84 * @param name Name of the environment field (will be copied).
85 * @param value Value of the environment field.
86 *
87 * Returns 0 on success, a negative value on error.
88 */
89 extern int bt_ctf_writer_add_environment_field_int64(
90 struct bt_ctf_writer *writer,
91 const char *name,
92 int64_t value);
93
94 /*
95 * bt_ctf_writer_add_clock: add a clock to the trace.
96 *
97 * Add a clock to the trace. Clocks assigned to stream classes must be
98 * registered to the writer.
99 *
100 * @param writer Writer instance.
101 * @param clock Clock to add to the trace.
102 *
103 * Returns 0 on success, a negative value on error.
104 */
105 extern int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer,
106 struct bt_ctf_clock *clock);
107
108 /*
109 * bt_ctf_writer_get_metadata_string: get meta-data string.
110 *
111 * Get the trace's TSDL meta-data. The caller assumes the ownership of the
112 * returned string.
113 *
114 * @param writer Writer instance.
115 *
116 * Returns the metadata string on success, NULL on error.
117 */
118 extern char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer);
119
120 /*
121 * bt_ctf_writer_flush_metadata: flush the trace's metadata to disk.
122 *
123 * Flush the trace's metadata to the metadata file. Note that the metadata will
124 * be flushed automatically when the Writer instance is released (last call to
125 * bt_ctf_writer_put).
126 *
127 * @param writer Writer instance.
128 */
129 extern void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer);
130
131 /*
132 * bt_ctf_writer_set_byte_order: set a field type's byte order.
133 *
134 * Set the trace's byte order. Defaults to the host machine's endianness.
135 *
136 * @param writer Writer instance.
137 * @param byte_order Trace's byte order.
138 *
139 * Returns 0 on success, a negative value on error.
140 *
141 * Note: byte_order must not be BT_CTF_BYTE_ORDER_NATIVE since, according
142 * to the CTF specification, is defined as "the byte order described in the
143 * trace description".
144 */
145 extern int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer,
146 enum bt_ctf_byte_order byte_order);
147
148 /*
149 * bt_ctf_writer_get and bt_ctf_writer_put: increment and decrement the
150 * writer's reference count.
151 *
152 * You may also use bt_ctf_get() and bt_ctf_put() with writer objects.
153 *
154 * These functions ensure that the writer won't be destroyed while it
155 * is in use. The same number of get and put (plus one extra put to
156 * release the initial reference done at creation) have to be done to
157 * destroy a writer.
158 *
159 * When the writer's reference count is decremented to 0 by a
160 * bt_ctf_writer_put, the writer is freed.
161 *
162 * @param writer Writer instance.
163 */
164
165 /* Pre-2.0 CTF writer compatibility */
166 static inline
167 void bt_ctf_writer_get(struct bt_ctf_writer *writer)
168 {
169 bt_ctf_object_get_ref(writer);
170 }
171
172 /* Pre-2.0 CTF writer compatibility */
173 static inline
174 void bt_ctf_writer_put(struct bt_ctf_writer *writer)
175 {
176 bt_ctf_object_put_ref(writer);
177 }
178
179 #ifdef __cplusplus
180 }
181 #endif
182
183 #endif /* BABELTRACE2_CTF_WRITER_WRITER_H */
This page took 0.032989 seconds and 4 git commands to generate.