2 * SPDX-License-Identifier: MIT
4 * Copyright (C) 2010-2019 EfficiOS Inc. and Linux Foundation
7 #ifndef BABELTRACE2_TRACE_IR_FIELD_PATH_H
8 #define BABELTRACE2_TRACE_IR_FIELD_PATH_H
10 /* IWYU pragma: private, include <babeltrace2/babeltrace.h> */
12 #ifndef __BT_IN_BABELTRACE_H
13 # error "Please include <babeltrace2/babeltrace.h> instead."
18 #include <babeltrace2/types.h>
25 @defgroup api-tir-field-path Field path
31 A <strong><em>field path</em></strong> indicates how to reach a given
32 \bt_field from a given <em>root scope</em>.
34 More specifically, a field path indicates how to reach:
36 - The length field of a \bt_darray_field (with a length field).
37 - The selector field of a \bt_opt_field (with a selector field).
38 - The selector field of a \bt_var_field (with a selector field).
40 You can borrow the field path from the \ref api-tir-fc "classes" of such
42 bt_field_class_array_dynamic_with_length_field_borrow_length_field_path_const(),
43 bt_field_class_option_with_selector_field_borrow_selector_field_path_const(),
45 bt_field_class_variant_with_selector_field_borrow_selector_field_path_const().
46 Note that the field path properties of those field classes only becomes
47 available when the field class becomes part of an \bt_ev_cls or of a
49 \ref api-tir-fc-link "Field classes with links to other field classes".
51 A field path is a \ref api-tir "trace IR" metadata object.
53 A field path is a \ref api-fund-shared-object "shared object": get a
54 new reference with bt_field_path_get_ref() and put an existing
55 reference with bt_field_path_put_ref().
57 The type of a field path is #bt_field_path.
61 A field path has the following properties:
65 \anchor api-tir-field-path-prop-root
69 Indicates from which \bt_struct_field to start a lookup.
71 See \ref api-tir-field-path-lookup-algo "Lookup algorithm" to
74 Get a field path's root scope with bt_field_path_get_root_scope().
78 \anchor api-tir-field-path-prop-items
82 Each item in a field path's item list indicates which action to take
83 to follow the path to the linked \bt_field.
85 See \ref api-tir-field-path-lookup-algo "Lookup algorithm" to
88 Get the number of items in a field path with
89 bt_field_path_get_item_count().
91 Borrow an item from a field path with
92 bt_field_path_borrow_item_by_index_const(). This function
93 returns the #bt_field_path_item type.
95 A field path item is a \ref api-fund-unique-object "unique object":
96 it belongs to the field path which contains it.
100 <h1>\anchor api-tir-field-path-lookup-algo Lookup algorithm</h1>
102 The field resolution algorithm using a field path is:
104 -# Use the appropriate function to set a <em>current field</em> variable
105 from the root scope (as returned by bt_field_path_get_root_scope()):
108 <dt>#BT_FIELD_PATH_SCOPE_PACKET_CONTEXT</dt>
110 bt_packet_borrow_context_field_const().
112 <dt>#BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT</dt>
114 bt_event_borrow_common_context_field_const().
116 <dt>#BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT</dt>
118 bt_event_borrow_specific_context_field_const().
120 <dt>#BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD</dt>
122 bt_event_borrow_payload_field_const().
126 -# For each field path item (use bt_field_path_get_item_count()
127 and bt_field_path_borrow_item_by_index_const()), depending on
128 the item's type (as returned by bt_field_path_item_get_type()):
131 <dt>#BT_FIELD_PATH_ITEM_TYPE_INDEX</dt>
133 Call bt_field_path_item_index_get_index() to get the item's
136 Depending on the current field's class's type (as
137 returned by bt_field_get_class_type()):
140 <dt>\bt_c_struct_fc</dt>
142 Call bt_field_structure_borrow_member_field_by_index_const()
143 with the current field and with the item's index to set the
147 <dt>\bt_c_var_fc</dt>
149 Call bt_field_variant_borrow_selected_option_field_const()
150 with the current field to set the new current field.
155 <dt>#BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT</dt>
157 Call bt_field_array_borrow_element_field_by_index_const()
158 with the index of the field eventually containing the
159 field with a link (\bt_darray_field, \bt_opt_field, or
160 \bt_var_field) and the current field to set the new current
164 <dt>#BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT</dt>
166 Call bt_field_option_borrow_field_const() with the current
167 field to set the new current field.
171 After applying this procedure, the current field is the linked
181 @typedef struct bt_field_path bt_field_path;
192 typedef enum bt_field_path_scope
{
197 BT_FIELD_PATH_SCOPE_PACKET_CONTEXT
= 0,
201 Event common context.
203 BT_FIELD_PATH_SCOPE_EVENT_COMMON_CONTEXT
= 1,
207 Event specific context.
209 BT_FIELD_PATH_SCOPE_EVENT_SPECIFIC_CONTEXT
= 2,
215 BT_FIELD_PATH_SCOPE_EVENT_PAYLOAD
= 3,
216 } bt_field_path_scope
;
220 Returns the root scope of the field path \bt_p{field_path}.
222 See the \ref api-tir-field-path-prop-root "root scope" property.
224 @param[in] field_path
225 Field path of which to get the root scope.
228 Root scope of \bt_p{field_path}.
230 @bt_pre_not_null{field_path}
232 extern bt_field_path_scope
bt_field_path_get_root_scope(
233 const bt_field_path
*field_path
);
237 Returns the number of items contained in the field path
240 See the \ref api-tir-field-path-prop-items "items" property.
242 @param[in] field_path
243 Field path of which to get the number of contained items.
246 Number of contained items in \bt_p{field_path}.
248 @bt_pre_not_null{field_path}
250 extern uint64_t bt_field_path_get_item_count(
251 const bt_field_path
*field_path
);
255 Borrows the item at index \bt_p{index} from the
256 field path \bt_p{field_path}.
258 See the \ref api-tir-field-path-prop-items "items" property.
260 @param[in] field_path
261 Field path from which to borrow the item at index \bt_p{index}.
263 Index of the item to borrow from \bt_p{field_path}.
267 \em Borrowed reference of the item of
268 \bt_p{field_path} at index \bt_p{index}.
270 The returned pointer remains valid as long as \bt_p{field_path}
274 @bt_pre_not_null{field_path}
276 \bt_p{index} is less than the number of items in
277 \bt_p{field_path} (as returned by bt_field_path_get_item_count()).
279 @sa bt_field_path_get_item_count() —
280 Returns the number of items contained in a field path.
282 extern const bt_field_path_item
*bt_field_path_borrow_item_by_index_const(
283 const bt_field_path
*field_path
, uint64_t index
);
287 Increments the \ref api-fund-shared-object "reference count" of
288 the field path \bt_p{field_path}.
290 @param[in] field_path
292 Field path of which to increment the reference count.
297 @sa bt_field_path_put_ref() —
298 Decrements the reference count of a field path.
300 extern void bt_field_path_get_ref(const bt_field_path
*field_path
);
304 Decrements the \ref api-fund-shared-object "reference count" of
305 the field path \bt_p{field_path}.
307 @param[in] field_path
309 Field path of which to decrement the reference count.
314 @sa bt_field_path_get_ref() —
315 Increments the reference count of a field path.
317 extern void bt_field_path_put_ref(const bt_field_path
*field_path
);
321 Decrements the reference count of the field path
322 \bt_p{_field_path}, and then sets \bt_p{_field_path} to \c NULL.
326 Field path of which to decrement the reference count.
331 @bt_pre_assign_expr{_field_path}
333 #define BT_FIELD_PATH_PUT_REF_AND_RESET(_field_path) \
335 bt_field_path_put_ref(_field_path); \
336 (_field_path) = NULL; \
341 Decrements the reference count of the field path \bt_p{_dst}, sets
342 \bt_p{_dst} to \bt_p{_src}, and then sets \bt_p{_src} to \c NULL.
344 This macro effectively moves a field path reference from the expression
345 \bt_p{_src} to the expression \bt_p{_dst}, putting the existing
346 \bt_p{_dst} reference.
350 Destination expression.
361 @bt_pre_assign_expr{_dst}
362 @bt_pre_assign_expr{_src}
364 #define BT_FIELD_PATH_MOVE_REF(_dst, _src) \
366 bt_field_path_put_ref(_dst); \
374 @name Field path item
377 @typedef struct bt_field_path_item bt_field_path_item;
386 Field path item type enumerators.
388 typedef enum bt_field_path_item_type
{
391 Index of a \bt_struct_field member or selected \bt_var_field
394 BT_FIELD_PATH_ITEM_TYPE_INDEX
= 1 << 0,
398 Common field of an \bt_array_field.
400 BT_FIELD_PATH_ITEM_TYPE_CURRENT_ARRAY_ELEMENT
= 1 << 1,
404 Current field of an \bt_opt_field.
406 BT_FIELD_PATH_ITEM_TYPE_CURRENT_OPTION_CONTENT
= 1 << 2,
407 } bt_field_path_item_type
;
411 Returns the type enumerator of the field path item
414 See the \ref api-tir-field-path-prop-items "items" property.
417 Field path item of which to get the type enumerator
420 Type enumerator of \bt_p{item}.
422 @bt_pre_not_null{item}
424 extern bt_field_path_item_type
bt_field_path_item_get_type(
425 const bt_field_path_item
*item
);
429 Returns the index value of the index field path item
432 See the \ref api-tir-field-path-prop-items "items" property.
435 Index field path item of which to get the index value.
438 Index value of \bt_p{item}.
440 @bt_pre_not_null{item}
442 \bt_p{item} is an index field path item
443 (bt_field_path_item_get_type() returns
444 #BT_FIELD_PATH_ITEM_TYPE_INDEX).
446 extern uint64_t bt_field_path_item_index_get_index(
447 const bt_field_path_item
*item
);
457 #endif /* BABELTRACE2_TRACE_IR_FIELD_PATH_H */