2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2019 EfficiOS Inc. and Linux Foundation
7 #ifndef BABELTRACE2_CTF_WRITER_WRITER_H
8 #define BABELTRACE2_CTF_WRITER_WRITER_H
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>
21 struct bt_ctf_stream_class
;
25 * bt_ctf_writer_create: create a writer instance.
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.
30 * @param path Path to the trace's containing folder (string is copied).
32 * Returns an allocated writer on success, NULL on error.
34 extern struct bt_ctf_writer
*bt_ctf_writer_create(const char *path
);
37 * bt_ctf_writer_get_trace: Get a writer's associated trace.
39 * @param writer Writer instance.
41 * Return the writer's associated instance, NULL on error.
43 extern struct bt_ctf_trace
*bt_ctf_writer_get_trace(
44 struct bt_ctf_writer
*writer
);
47 * bt_ctf_writer_create_stream: create a stream instance.
49 * Allocate a new stream instance and register it to the writer. The creation of
50 * a stream sets its reference count to 1.
52 * @param writer Writer instance.
53 * @param stream_class Stream class to instantiate.
55 * Returns an allocated stream on success, NULL on error.
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
);
62 * bt_ctf_writer_add_environment_field: add an environment field to the trace.
64 * Add an environment field to the trace. The name and value parameters are
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).
71 * Returns 0 on success, a negative value on error.
73 extern int bt_ctf_writer_add_environment_field(struct bt_ctf_writer
*writer
,
78 * bt_ctf_writer_add_environment_field_int64: add an environment field to the trace.
80 * Add an environment field to the trace. The name and value parameters are
83 * @param writer Writer instance.
84 * @param name Name of the environment field (will be copied).
85 * @param value Value of the environment field.
87 * Returns 0 on success, a negative value on error.
89 extern int bt_ctf_writer_add_environment_field_int64(
90 struct bt_ctf_writer
*writer
,
95 * bt_ctf_writer_add_clock: add a clock to the trace.
97 * Add a clock to the trace. Clocks assigned to stream classes must be
98 * registered to the writer.
100 * @param writer Writer instance.
101 * @param clock Clock to add to the trace.
103 * Returns 0 on success, a negative value on error.
105 extern int bt_ctf_writer_add_clock(struct bt_ctf_writer
*writer
,
106 struct bt_ctf_clock
*clock
);
109 * bt_ctf_writer_get_metadata_string: get meta-data string.
111 * Get the trace's TSDL meta-data. The caller assumes the ownership of the
114 * @param writer Writer instance.
116 * Returns the metadata string on success, NULL on error.
118 extern char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer
*writer
);
121 * bt_ctf_writer_flush_metadata: flush the trace's metadata to disk.
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).
127 * @param writer Writer instance.
129 extern void bt_ctf_writer_flush_metadata(struct bt_ctf_writer
*writer
);
132 * bt_ctf_writer_set_byte_order: set a field type's byte order.
134 * Set the trace's byte order. Defaults to the host machine's endianness.
136 * @param writer Writer instance.
137 * @param byte_order Trace's byte order.
139 * Returns 0 on success, a negative value on error.
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".
145 extern int bt_ctf_writer_set_byte_order(struct bt_ctf_writer
*writer
,
146 enum bt_ctf_byte_order byte_order
);
149 * bt_ctf_writer_get and bt_ctf_writer_put: increment and decrement the
150 * writer's reference count.
152 * You may also use bt_ctf_get() and bt_ctf_put() with writer objects.
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
159 * When the writer's reference count is decremented to 0 by a
160 * bt_ctf_writer_put, the writer is freed.
162 * @param writer Writer instance.
165 /* Pre-2.0 CTF writer compatibility */
167 void bt_ctf_writer_get(struct bt_ctf_writer
*writer
)
169 bt_ctf_object_get_ref(writer
);
172 /* Pre-2.0 CTF writer compatibility */
174 void bt_ctf_writer_put(struct bt_ctf_writer
*writer
)
176 bt_ctf_object_put_ref(writer
);
183 #endif /* BABELTRACE2_CTF_WRITER_WRITER_H */