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