Add missing permission notice in each source file
[babeltrace.git] / include / babeltrace / ctf / events.h
CommitLineData
9843982d
JD
1#ifndef _BABELTRACE_CTF_EVENTS_H
2#define _BABELTRACE_CTF_EVENTS_H
3
4/*
5 * BabelTrace
6 *
7 * CTF events API
8 *
9 * Copyright 2011-2012 EfficiOS Inc. and Linux Foundation
10 *
11 * Author: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
12 * Julien Desfossez <julien.desfossez@efficios.com>
13 *
14 * Permission is hereby granted, free of charge, to any person obtaining
15 * a copy of this software and associated documentation files (the
16 * "Software"), to deal in the Software without restriction, including
17 * without limitation the rights to use, copy, modify, merge, publish,
18 * distribute, sublicense, and/or sell copies of the Software, and to
19 * permit persons to whom the Software is furnished to do so, subject to
20 * the following conditions:
21 *
22 * The above copyright notice and this permission notice shall be
23 * included in all copies or substantial portions of the Software.
c462e188
MD
24 *
25 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 * SOFTWARE.
9843982d
JD
32 */
33
34#include <stdint.h>
e003ab50 35#include <babeltrace/context.h>
03798a93 36#include <babeltrace/clock-types.h>
9843982d 37
6946751f
JD
38#ifdef __cplusplus
39extern "C" {
40#endif
41
9843982d 42struct definition;
2bdfa4cf 43struct declaration;
c50d2a7a 44struct bt_ctf_event;
e003ab50 45struct bt_ctf_event_decl;
64c2c249 46struct bt_ctf_field_decl;
9843982d
JD
47
48/*
49 * the top-level scopes in CTF
50 */
51enum bt_ctf_scope {
52 BT_TRACE_PACKET_HEADER = 0,
53 BT_STREAM_PACKET_CONTEXT = 1,
54 BT_STREAM_EVENT_HEADER = 2,
55 BT_STREAM_EVENT_CONTEXT = 3,
56 BT_EVENT_CONTEXT = 4,
57 BT_EVENT_FIELDS = 5,
58};
59
60/*
61 * the supported CTF types
62 */
63enum ctf_type_id {
64 CTF_TYPE_UNKNOWN = 0,
65 CTF_TYPE_INTEGER,
66 CTF_TYPE_FLOAT,
67 CTF_TYPE_ENUM,
68 CTF_TYPE_STRING,
69 CTF_TYPE_STRUCT,
70 CTF_TYPE_UNTAGGED_VARIANT,
71 CTF_TYPE_VARIANT,
72 CTF_TYPE_ARRAY,
73 CTF_TYPE_SEQUENCE,
74 NR_CTF_TYPES,
75};
76
8673030f
JD
77/*
78 * the supported CTF string encodings
79 */
80enum ctf_string_encoding {
81 CTF_STRING_NONE = 0,
82 CTF_STRING_UTF8,
83 CTF_STRING_ASCII,
84 CTF_STRING_UNKNOWN,
85};
86
9843982d
JD
87/*
88 * bt_ctf_get_top_level_scope: return a definition of the top-level scope
89 *
90 * Top-level scopes are defined in the bt_ctf_scope enum.
91 * In order to get a field or a field list, the user needs to pass a
92 * scope as argument, this scope can be a top-level scope or a scope
93 * relative to an arbitrary field. This function provides the mapping
94 * between the enum and the actual definition of top-level scopes.
95 * On error return NULL.
96 */
c50d2a7a 97const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event,
9843982d
JD
98 enum bt_ctf_scope scope);
99
100/*
101 * bt_ctf_event_get_name: returns the name of the event or NULL on error
102 */
c50d2a7a 103const char *bt_ctf_event_name(const struct bt_ctf_event *event);
9843982d
JD
104
105/*
d40ee8ec 106 * bt_ctf_get_cycles: returns the timestamp of the event as written
03798a93 107 * in the packet (in cycles) or -1ULL on error.
57f3005e 108 */
d40ee8ec 109uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *event);
57f3005e
SJD
110
111/*
d40ee8ec 112 * bt_ctf_get_timestamp: returns the timestamp of the event offsetted
03798a93 113 * with the system clock source (in ns) or -1ULL on error
9843982d 114 */
d40ee8ec 115uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *event);
9843982d
JD
116
117/*
bb337d59
MD
118 * bt_ctf_get_field_list: obtain the list of fields for compound type
119 *
f5464725
JD
120 * This function can be used to obtain the list of fields contained
121 * within a top-level scope of an event or a compound type: array,
122 * sequence, structure, or variant.
bb337d59
MD
123
124 * This function sets the "list" pointer to an array of definition
aacd0c69
JD
125 * pointers and set count to the number of elements in the array.
126 * Return 0 on success and a negative value on error.
bb337d59
MD
127 *
128 * The content pointed to by "list" should *not* be freed. It stays
129 * valid as long as the event is unchanged (as long as the iterator
130 * from which the event is extracted is unchanged).
9843982d 131 */
c50d2a7a 132int bt_ctf_get_field_list(const struct bt_ctf_event *event,
04ae3991 133 const struct definition *scope,
9843982d
JD
134 struct definition const * const **list,
135 unsigned int *count);
136
137/*
138 * bt_ctf_get_field: returns the definition of a specific field
139 */
c50d2a7a 140const struct definition *bt_ctf_get_field(const struct bt_ctf_event *event,
04ae3991 141 const struct definition *scope,
9843982d
JD
142 const char *field);
143
144/*
145 * bt_ctf_get_index: if the field is an array or a sequence, return the element
146 * at position index, otherwise return NULL;
147 */
c50d2a7a 148const struct definition *bt_ctf_get_index(const struct bt_ctf_event *event,
04ae3991 149 const struct definition *field,
9843982d
JD
150 unsigned int index);
151
152/*
153 * bt_ctf_field_name: returns the name of a field or NULL on error
154 */
155const char *bt_ctf_field_name(const struct definition *def);
156
2bdfa4cf 157/*
b14d90be
JD
158 * bt_ctf_get_decl_from_def: return the declaration of a field from
159 * its definition or NULL on error
2bdfa4cf 160 */
b14d90be
JD
161const struct declaration *bt_ctf_get_decl_from_def(const struct definition *def);
162
163/*
164 * bt_ctf_get_decl_from_field_decl: return the declaration of a field from
165 * a field_decl or NULL on error
166 */
167const struct declaration *bt_ctf_get_decl_from_field_decl(
168 const struct bt_ctf_field_decl *field);
2bdfa4cf 169
9843982d
JD
170/*
171 * bt_ctf_field_type: returns the type of a field or -1 if unknown
172 */
2bdfa4cf 173enum ctf_type_id bt_ctf_field_type(const struct declaration *decl);
9843982d 174
8673030f
JD
175/*
176 * bt_ctf_get_int_signedness: return the signedness of an integer
177 *
178 * return 0 if unsigned
179 * return 1 if signed
180 * return -1 on error
181 */
2bdfa4cf 182int bt_ctf_get_int_signedness(const struct declaration *decl);
8673030f
JD
183
184/*
185 * bt_ctf_get_int_base: return the base of an int or a negative value on error
186 */
2bdfa4cf 187int bt_ctf_get_int_base(const struct declaration *decl);
8673030f
JD
188
189/*
190 * bt_ctf_get_int_byte_order: return the byte order of an int or a negative
191 * value on error
192 */
2bdfa4cf 193int bt_ctf_get_int_byte_order(const struct declaration *decl);
8673030f 194
fef0e521
MD
195/*
196 * bt_ctf_get_int_len: return the size, in bits, of an int or a negative
197 * value on error
198 */
2bdfa4cf 199ssize_t bt_ctf_get_int_len(const struct declaration *decl);
fef0e521 200
8673030f 201/*
c22b9327
JD
202 * bt_ctf_get_encoding: return the encoding of an int, a string, or of
203 * the integer contained in a char array or a sequence.
8673030f
JD
204 * return a negative value on error
205 */
2bdfa4cf 206enum ctf_string_encoding bt_ctf_get_encoding(const struct declaration *decl);
8673030f
JD
207
208/*
209 * bt_ctf_get_array_len: return the len of an array or a negative
210 * value on error
211 */
2bdfa4cf 212int bt_ctf_get_array_len(const struct declaration *decl);
8673030f 213
9843982d
JD
214/*
215 * Field access functions
216 *
217 * These functions return the value associated with the field passed in
218 * parameter.
219 *
220 * If the field does not exist or is not of the type requested, the value
221 * returned is undefined. To check if an error occured, use the
b330165c 222 * bt_ctf_field_get_error() function after accessing a field.
4d25c350
MD
223 *
224 * bt_ctf_get_enum_int gets the integer field of an enumeration.
225 * bt_ctf_get_enum_str gets the string matching the current enumeration
226 * value, or NULL if the current value does not match any string.
9843982d 227 */
da320b83
JD
228uint64_t bt_ctf_get_uint64(const struct definition *field);
229int64_t bt_ctf_get_int64(const struct definition *field);
4d25c350
MD
230const struct definition *bt_ctf_get_enum_int(const struct definition *field);
231const char *bt_ctf_get_enum_str(const struct definition *field);
da320b83
JD
232char *bt_ctf_get_char_array(const struct definition *field);
233char *bt_ctf_get_string(const struct definition *field);
9843982d
JD
234
235/*
b330165c 236 * bt_ctf_field_get_error: returns the last error code encountered while
9843982d
JD
237 * accessing a field and reset the error flag.
238 * Return 0 if no error, a negative value otherwise.
239 */
240int bt_ctf_field_get_error(void);
241
e003ab50 242/*
f5464725
JD
243 * bt_ctf_get_event_decl_list: get a list of all the event declarations in
244 * a trace.
245 *
246 * The list array is pointed to the array of event declarations.
247 * The number of events in the array is written in count.
e003ab50
JD
248 *
249 * Return 0 on success and a negative value on error.
f5464725
JD
250 *
251 * The content pointed to by "list" should *not* be freed. It stays
252 * valid as long as the trace is opened.
e003ab50
JD
253 */
254int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
64c2c249 255 struct bt_ctf_event_decl * const **list,
e003ab50
JD
256 unsigned int *count);
257
258/*
259 * bt_ctf_get_decl_event_name: return the name of the event or NULL on error
260 */
261const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
262
64c2c249 263/*
f5464725
JD
264 * bt_ctf_get_decl_fields: get all field declarations in a scope of an event
265 *
266 * The list array is pointed to the array of field declaration.
267 * The number of field declaration in the array is written in count.
64c2c249
JD
268 *
269 * Returns 0 on success and a negative value on error
f5464725
JD
270 *
271 * The content pointed to by "list" should *not* be freed. It stays
272 * valid as long as the trace is opened.
64c2c249
JD
273 */
274int bt_ctf_get_decl_fields(struct bt_ctf_event_decl *event_decl,
275 enum bt_ctf_scope scope,
276 struct bt_ctf_field_decl const * const **list,
277 unsigned int *count);
278
279/*
280 * bt_ctf_get_decl_field_name: return the name of a field decl or NULL on error
281 */
282const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
283
6946751f
JD
284#ifdef __cplusplus
285}
286#endif
287
9843982d 288#endif /* _BABELTRACE_CTF_EVENTS_H */
This page took 0.035775 seconds and 4 git commands to generate.