ir: rename ctf_type_id -> bt_ctf_type_id
[babeltrace.git] / include / babeltrace / ctf / events-internal.h
CommitLineData
e4195791
MD
1#ifndef _BABELTRACE_CTF_EVENTS_INTERNAL_H
2#define _BABELTRACE_CTF_EVENTS_INTERNAL_H
3
4/*
5 * BabelTrace
6 *
7 * CTF events API (internal)
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.
e4195791
MD
32 */
33
34#include <babeltrace/iterator-internal.h>
634d474b
MD
35#include <babeltrace/ctf/callbacks.h>
36#include <babeltrace/ctf/callbacks-internal.h>
8a4722b0 37#include <babeltrace/ctf-ir/metadata.h>
9a19a512 38#include <babeltrace/ctf-ir/event-types.h>
634d474b 39#include <glib.h>
e4195791 40
9e88d150 41struct ctf_stream_definition;
04ae3991 42
c50d2a7a
JD
43/*
44 * These structures are public mappings to internal ctf_event structures.
45 */
46struct bt_ctf_event {
47 struct ctf_event_definition *parent;
48};
49
50struct bt_ctf_event_decl {
e003ab50 51 struct ctf_event_declaration parent;
64c2c249
JD
52 GPtrArray *context_decl;
53 GPtrArray *fields_decl;
54 GPtrArray *packet_header_decl;
55 GPtrArray *event_context_decl;
56 GPtrArray *event_header_decl;
57 GPtrArray *packet_context_decl;
c50d2a7a
JD
58};
59
e4195791
MD
60struct bt_ctf_iter {
61 struct bt_iter parent;
c50d2a7a 62 struct bt_ctf_event current_ctf_event; /* last read event */
634d474b
MD
63 GArray *callbacks; /* Array of struct bt_stream_callbacks */
64 struct bt_callback_chain main_callbacks; /* For all events */
65 /*
66 * Flag indicating if dependency graph needs to be recalculated.
67 * Set by bt_iter_add_callback(), and checked (and
68 * cleared) by upon entry into bt_iter_read_event().
69 * bt_iter_read_event() is responsible for calling dep
70 * graph calculation if it sees this flag set.
71 */
72 int recalculate_dep_graph;
73 /*
74 * Array of pointers to struct bt_dependencies, for garbage
75 * collection. We're not using a linked list here because each
76 * struct bt_dependencies can belong to more than one
77 * bt_iter.
78 */
79 GPtrArray *dep_gc;
f60efc0e 80 uint64_t events_lost;
e4195791
MD
81};
82
f1f52630
MD
83void ctf_update_current_packet_index(struct ctf_stream_definition *stream,
84 struct packet_index *prev_index,
85 struct packet_index *cur_index);
87148dc7 86
9a19a512
PP
87struct bt_definition;
88struct bt_declaration;
89struct bt_ctf_event;
90struct bt_ctf_event_decl;
91struct bt_ctf_field_decl;
92
93/*
94 * the top-level scopes in CTF
95 */
96enum ctf_scope {
97 BT_TRACE_PACKET_HEADER = 0,
98 BT_STREAM_PACKET_CONTEXT = 1,
99 BT_STREAM_EVENT_HEADER = 2,
100 BT_STREAM_EVENT_CONTEXT = 3,
101 BT_EVENT_CONTEXT = 4,
102 BT_EVENT_FIELDS = 5,
103};
104
105/*
106 * bt_ctf_get_top_level_scope: return a definition of the top-level scope
107 *
108 * Top-level scopes are defined in the ctf_scope enum.
109 * In order to get a field or a field list, the user needs to pass a
110 * scope as argument, this scope can be a top-level scope or a scope
111 * relative to an arbitrary field. This function provides the mapping
112 * between the enum and the actual definition of top-level scopes.
113 * On error return NULL.
114 */
115const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event,
116 enum ctf_scope scope);
117
118/*
119 * bt_ctf_event_get_name: returns the name of the event or NULL on error
120 */
121const char *bt_ctf_event_name(const struct bt_ctf_event *event);
122
123/*
124 * bt_ctf_get_cycles: returns the timestamp of the event as written
125 * in the packet (in cycles) or -1ULL on error.
126 */
127uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *event);
128
129/*
130 * bt_ctf_get_timestamp: get the timestamp of the event offsetted
131 * with the system clock source (in ns) in *timestamp.
132 *
133 * Return 0 on success, or -1ULL on error.
134 */
135int bt_ctf_get_timestamp(const struct bt_ctf_event *event, int64_t *timestamp);
136
137/*
138 * bt_ctf_get_field_list: obtain the list of fields for compound type
139 *
140 * This function can be used to obtain the list of fields contained
141 * within a top-level scope of an event or a compound type: array,
142 * sequence, structure, or variant.
143
144 * This function sets the "list" pointer to an array of definition
145 * pointers and set count to the number of elements in the array.
146 * Return 0 on success and a negative value on error.
147 *
148 * The content pointed to by "list" should *not* be freed. It stays
149 * valid as long as the event is unchanged (as long as the iterator
150 * from which the event is extracted is unchanged).
151 */
152int bt_ctf_get_field_list(const struct bt_ctf_event *event,
153 const struct bt_definition *scope,
154 struct bt_definition const * const **list,
155 unsigned int *count);
156
157/*
158 * bt_ctf_get_field: returns the definition of a specific field
159 */
160const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *event,
161 const struct bt_definition *scope,
162 const char *field);
163
164/*
165 * bt_ctf_get_index: if the field is an array or a sequence, return the element
166 * at position index, otherwise return NULL;
167 */
168const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *event,
169 const struct bt_definition *field,
170 unsigned int index);
171
172/*
173 * bt_ctf_field_name: returns the name of a field or NULL on error
174 */
175const char *bt_ctf_field_name(const struct bt_definition *def);
176
177/*
178 * bt_ctf_get_decl_from_def: return the declaration of a field from
179 * its definition or NULL on error
180 */
181const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *def);
182
183/*
184 * bt_ctf_get_decl_from_field_decl: return the declaration of a field from
185 * a field_decl or NULL on error
186 */
187const struct bt_declaration *bt_ctf_get_decl_from_field_decl(
188 const struct bt_ctf_field_decl *field);
189
190/*
191 * bt_ctf_field_type: returns the type of a field or -1 if unknown
192 */
193enum ctf_type_id bt_ctf_field_type(const struct bt_declaration *decl);
194
195/*
196 * bt_ctf_get_int_signedness: return the signedness of an integer
197 *
198 * return 0 if unsigned
199 * return 1 if signed
200 * return -1 on error
201 */
202int bt_ctf_get_int_signedness(const struct bt_declaration *decl);
203
204/*
205 * bt_ctf_get_int_base: return the base of an int or a negative value on error
206 */
207int bt_ctf_get_int_base(const struct bt_declaration *decl);
208
209/*
210 * bt_ctf_get_int_byte_order: return the byte order of an int or a negative
211 * value on error
212 */
213int bt_ctf_get_int_byte_order(const struct bt_declaration *decl);
214
215/*
216 * bt_ctf_get_int_len: return the size, in bits, of an int or a negative
217 * value on error
218 */
219ssize_t bt_ctf_get_int_len(const struct bt_declaration *decl);
220
221/*
222 * bt_ctf_get_encoding: return the encoding of an int, a string, or of
223 * the integer contained in a char array or a sequence.
224 * return a negative value on error
225 */
226enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *decl);
227
228/*
229 * bt_ctf_get_array_len: return the len of an array or a negative
230 * value on error
231 */
232int bt_ctf_get_array_len(const struct bt_declaration *decl);
233
234/*
235 * bt_ctf_get_struct_field_count: return the number of fields in a structure.
236 * Returns a negative value on error.
237 */
238uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *field);
239
240/*
241 * Field access functions
242 *
243 * These functions return the value associated with the field passed in
244 * parameter.
245 *
246 * If the field does not exist or is not of the type requested, the value
247 * returned is undefined. To check if an error occured, use the
248 * bt_ctf_field_get_error() function after accessing a field.
249 *
250 * bt_ctf_get_enum_int gets the integer field of an enumeration.
251 * bt_ctf_get_enum_str gets the string matching the current enumeration
252 * value, or NULL if the current value does not match any string.
253 */
254uint64_t bt_ctf_get_uint64(const struct bt_definition *field);
255int64_t bt_ctf_get_int64(const struct bt_definition *field);
256const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field);
257const char *bt_ctf_get_enum_str(const struct bt_definition *field);
258char *bt_ctf_get_char_array(const struct bt_definition *field);
259char *bt_ctf_get_string(const struct bt_definition *field);
260double bt_ctf_get_float(const struct bt_definition *field);
261const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field);
262const struct bt_definition *bt_ctf_get_struct_field_index(
263 const struct bt_definition *field, uint64_t i);
264
265/*
266 * bt_ctf_field_get_error: returns the last error code encountered while
267 * accessing a field and reset the error flag.
268 * Return 0 if no error, a negative value otherwise.
269 */
270int bt_ctf_field_get_error(void);
271
272/*
273 * bt_ctf_get_event_decl_list: get a list of all the event declarations in
274 * a trace.
275 *
276 * The list array is pointed to the array of event declarations.
277 * The number of events in the array is written in count.
278 *
279 * Return 0 on success and a negative value on error.
280 *
281 * The content pointed to by "list" should *not* be freed. It stays
282 * valid as long as the trace is opened.
283 */
284int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
285 struct bt_ctf_event_decl * const **list,
286 unsigned int *count);
287
288/*
289 * bt_ctf_get_decl_event_name: return the name of the event or NULL on error
290 */
291const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event);
292
293/*
294 * bt_ctf_get_decl_event_id: return the event-ID of the event or -1ULL on error
295 */
296uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event);
297
298/*
299 * bt_ctf_get_decl_fields: get all field declarations in a scope of an event
300 *
301 * The list array is pointed to the array of field declaration.
302 * The number of field declaration in the array is written in count.
303 *
304 * Returns 0 on success and a negative value on error
305 *
306 * The content pointed to by "list" should *not* be freed. It stays
307 * valid as long as the trace is opened.
308 */
309int bt_ctf_get_decl_fields(struct bt_ctf_event_decl *event_decl,
310 enum ctf_scope scope,
311 struct bt_ctf_field_decl const * const **list,
312 unsigned int *count);
313
314/*
315 * bt_ctf_get_decl_field_name: return the name of a field decl or NULL on error
316 */
317const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field);
318
e4195791 319#endif /*_BABELTRACE_CTF_EVENTS_INTERNAL_H */
This page took 0.041951 seconds and 4 git commands to generate.