Fix: check return value of get_char_array
[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.
24 */
25
26#include <stdint.h>
e003ab50 27#include <babeltrace/context.h>
03798a93 28#include <babeltrace/clock-types.h>
9843982d 29
6946751f
JD
30#ifdef __cplusplus
31extern "C" {
32#endif
33
9843982d 34struct definition;
c50d2a7a 35struct bt_ctf_event;
e003ab50 36struct bt_ctf_event_decl;
64c2c249 37struct bt_ctf_field_decl;
9843982d
JD
38
39/*
40 * the top-level scopes in CTF
41 */
42enum bt_ctf_scope {
43 BT_TRACE_PACKET_HEADER = 0,
44 BT_STREAM_PACKET_CONTEXT = 1,
45 BT_STREAM_EVENT_HEADER = 2,
46 BT_STREAM_EVENT_CONTEXT = 3,
47 BT_EVENT_CONTEXT = 4,
48 BT_EVENT_FIELDS = 5,
49};
50
51/*
52 * the supported CTF types
53 */
54enum ctf_type_id {
55 CTF_TYPE_UNKNOWN = 0,
56 CTF_TYPE_INTEGER,
57 CTF_TYPE_FLOAT,
58 CTF_TYPE_ENUM,
59 CTF_TYPE_STRING,
60 CTF_TYPE_STRUCT,
61 CTF_TYPE_UNTAGGED_VARIANT,
62 CTF_TYPE_VARIANT,
63 CTF_TYPE_ARRAY,
64 CTF_TYPE_SEQUENCE,
65 NR_CTF_TYPES,
66};
67
8673030f
JD
68/*
69 * the supported CTF string encodings
70 */
71enum ctf_string_encoding {
72 CTF_STRING_NONE = 0,
73 CTF_STRING_UTF8,
74 CTF_STRING_ASCII,
75 CTF_STRING_UNKNOWN,
76};
77
9843982d
JD
78/*
79 * bt_ctf_get_top_level_scope: return a definition of the top-level scope
80 *
81 * Top-level scopes are defined in the bt_ctf_scope enum.
82 * In order to get a field or a field list, the user needs to pass a
83 * scope as argument, this scope can be a top-level scope or a scope
84 * relative to an arbitrary field. This function provides the mapping
85 * between the enum and the actual definition of top-level scopes.
86 * On error return NULL.
87 */
c50d2a7a 88const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event,
9843982d
JD
89 enum bt_ctf_scope scope);
90
91/*
92 * bt_ctf_event_get_name: returns the name of the event or NULL on error
93 */
c50d2a7a 94const char *bt_ctf_event_name(const struct bt_ctf_event *event);
9843982d
JD
95
96/*
d40ee8ec 97 * bt_ctf_get_cycles: returns the timestamp of the event as written
03798a93 98 * in the packet (in cycles) or -1ULL on error.
57f3005e 99 */
d40ee8ec 100uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *event);
57f3005e
SJD
101
102/*
d40ee8ec 103 * bt_ctf_get_timestamp: returns the timestamp of the event offsetted
03798a93 104 * with the system clock source (in ns) or -1ULL on error
9843982d 105 */
d40ee8ec 106uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *event);
9843982d
JD
107
108/*
bb337d59
MD
109 * bt_ctf_get_field_list: obtain the list of fields for compound type
110 *
111 * This function can be used to obtain the list of fields
112 * contained within a compound type: array, sequence,
113 * structure, or variant.
114
115 * This function sets the "list" pointer to an array of definition
aacd0c69
JD
116 * pointers and set count to the number of elements in the array.
117 * Return 0 on success and a negative value on error.
bb337d59
MD
118 *
119 * The content pointed to by "list" should *not* be freed. It stays
120 * valid as long as the event is unchanged (as long as the iterator
121 * from which the event is extracted is unchanged).
9843982d 122 */
c50d2a7a 123int bt_ctf_get_field_list(const struct bt_ctf_event *event,
04ae3991 124 const struct definition *scope,
9843982d
JD
125 struct definition const * const **list,
126 unsigned int *count);
127
128/*
129 * bt_ctf_get_field: returns the definition of a specific field
130 */
c50d2a7a 131const struct definition *bt_ctf_get_field(const struct bt_ctf_event *event,
04ae3991 132 const struct definition *scope,
9843982d
JD
133 const char *field);
134
135/*
136 * bt_ctf_get_index: if the field is an array or a sequence, return the element
137 * at position index, otherwise return NULL;
138 */
c50d2a7a 139const struct definition *bt_ctf_get_index(const struct bt_ctf_event *event,
04ae3991 140 const struct definition *field,
9843982d
JD
141 unsigned int index);
142
143/*
144 * bt_ctf_field_name: returns the name of a field or NULL on error
145 */
146const char *bt_ctf_field_name(const struct definition *def);
147
148/*
149 * bt_ctf_field_type: returns the type of a field or -1 if unknown
150 */
da320b83 151enum ctf_type_id bt_ctf_field_type(const struct definition *def);
9843982d 152
8673030f
JD
153/*
154 * bt_ctf_get_int_signedness: return the signedness of an integer
155 *
156 * return 0 if unsigned
157 * return 1 if signed
158 * return -1 on error
159 */
160int bt_ctf_get_int_signedness(const struct definition *field);
161
162/*
163 * bt_ctf_get_int_base: return the base of an int or a negative value on error
164 */
165int bt_ctf_get_int_base(const struct definition *field);
166
167/*
168 * bt_ctf_get_int_byte_order: return the byte order of an int or a negative
169 * value on error
170 */
171int bt_ctf_get_int_byte_order(const struct definition *field);
172
fef0e521
MD
173/*
174 * bt_ctf_get_int_len: return the size, in bits, of an int or a negative
175 * value on error
176 */
177ssize_t bt_ctf_get_int_len(const struct definition *field);
178
8673030f
JD
179/*
180 * bt_ctf_get_encoding: return the encoding of an int or a string.
181 * return a negative value on error
182 */
183enum ctf_string_encoding bt_ctf_get_encoding(const struct definition *field);
184
185/*
186 * bt_ctf_get_array_len: return the len of an array or a negative
187 * value on error
188 */
189int bt_ctf_get_array_len(const struct definition *field);
190
9843982d
JD
191/*
192 * Field access functions
193 *
194 * These functions return the value associated with the field passed in
195 * parameter.
196 *
197 * If the field does not exist or is not of the type requested, the value
198 * returned is undefined. To check if an error occured, use the
b330165c 199 * bt_ctf_field_get_error() function after accessing a field.
4d25c350
MD
200 *
201 * bt_ctf_get_enum_int gets the integer field of an enumeration.
202 * bt_ctf_get_enum_str gets the string matching the current enumeration
203 * value, or NULL if the current value does not match any string.
9843982d 204 */
da320b83
JD
205uint64_t bt_ctf_get_uint64(const struct definition *field);
206int64_t bt_ctf_get_int64(const struct definition *field);
4d25c350
MD
207const struct definition *bt_ctf_get_enum_int(const struct definition *field);
208const char *bt_ctf_get_enum_str(const struct definition *field);
da320b83
JD
209char *bt_ctf_get_char_array(const struct definition *field);
210char *bt_ctf_get_string(const struct definition *field);
9843982d
JD
211
212/*
b330165c 213 * bt_ctf_field_get_error: returns the last error code encountered while
9843982d
JD
214 * accessing a field and reset the error flag.
215 * Return 0 if no error, a negative value otherwise.
216 */
217int bt_ctf_field_get_error(void);
218
e003ab50
JD
219/*
220 * bt_ctf_get_event_decl_list: set list pointer to an array of bt_ctf_event_decl
221 * pointers and set count to the number of elements in the array.
222 *
223 * Return 0 on success and a negative value on error.
224 */
225int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
64c2c249 226 struct bt_ctf_event_decl * const **list,
e003ab50
JD
227 unsigned int *count);
228
229/*
230 * bt_ctf_get_decl_event_name: return the name of the event or NULL on error
231 */
232const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
233
64c2c249
JD
234/*
235 * bt_ctf_get_decl_fields: set list pointer to an array of bt_ctf_field_decl
236 * pointers and set count to the number of elements in the array.
237 *
238 * Returns 0 on success and a negative value on error
239 */
240int bt_ctf_get_decl_fields(struct bt_ctf_event_decl *event_decl,
241 enum bt_ctf_scope scope,
242 struct bt_ctf_field_decl const * const **list,
243 unsigned int *count);
244
245/*
246 * bt_ctf_get_decl_field_name: return the name of a field decl or NULL on error
247 */
248const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
249
6946751f
JD
250#ifdef __cplusplus
251}
252#endif
253
9843982d 254#endif /* _BABELTRACE_CTF_EVENTS_H */
This page took 0.050763 seconds and 4 git commands to generate.