Document libbabeltrace2's C API
[babeltrace.git] / src / lib / trace-ir / field-path.c
CommitLineData
b011f6b0 1/*
f2b0325d 2 * Copyright 2016-2018 Philippe Proulx <pproulx@efficios.com>
b011f6b0 3 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
b011f6b0
PP
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
b03487ab 24#define BT_LOG_TAG "LIB/FIELD-PATH"
1633ef46 25#include "lib/logging.h"
1e6cfa95 26
57952005 27#include "lib/assert-pre.h"
71c5da58 28#include <babeltrace2/trace-ir/field-class.h>
7704a0af 29#include <babeltrace2/trace-ir/field-path.h>
b011f6b0 30#include <limits.h>
544d0515 31#include <stdint.h>
1e6cfa95 32#include <inttypes.h>
57952005 33#include "common/assert.h"
b011f6b0
PP
34#include <glib.h>
35
57952005
MJ
36#include "field-class.h"
37#include "field-path.h"
38
b011f6b0 39static
7b33a0e0 40void destroy_field_path(struct bt_object *obj)
b011f6b0 41{
839d52a5 42 struct bt_field_path *field_path = (struct bt_field_path *) obj;
b011f6b0 43
7b33a0e0
PP
44 BT_ASSERT(field_path);
45 BT_LIB_LOGD("Destroying field path: %!+P", field_path);
1d4afa5f
PP
46 g_array_free(field_path->items, TRUE);
47 field_path->items = NULL;
b011f6b0
PP
48 g_free(field_path);
49}
50
51BT_HIDDEN
839d52a5 52struct bt_field_path *bt_field_path_create(void)
b011f6b0 53{
839d52a5 54 struct bt_field_path *field_path = NULL;
b011f6b0 55
1e6cfa95
PP
56 BT_LOGD_STR("Creating empty field path object.");
57
839d52a5 58 field_path = g_new0(struct bt_field_path, 1);
b011f6b0 59 if (!field_path) {
a8f90e5d 60 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one field path.");
b011f6b0
PP
61 goto error;
62 }
63
7b33a0e0 64 bt_object_init_shared(&field_path->base, destroy_field_path);
1d4afa5f
PP
65 field_path->items = g_array_new(FALSE, FALSE,
66 sizeof(struct bt_field_path_item));
67 if (!field_path->items) {
a8f90e5d 68 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
b011f6b0
PP
69 goto error;
70 }
71
7b33a0e0
PP
72 BT_LIB_LOGD("Created empty field path object: %!+P", field_path);
73 goto end;
b011f6b0
PP
74
75error:
8138bfe1 76 BT_OBJECT_PUT_REF_AND_RESET(field_path);
b011f6b0 77
b011f6b0 78end:
7b33a0e0 79 return field_path;
b011f6b0
PP
80}
81
056995e5 82enum bt_field_path_scope bt_field_path_get_root_scope(
78cf9df6 83 const struct bt_field_path *field_path)
b011f6b0 84{
fa6cfec3 85 BT_ASSERT_PRE_DEV_NON_NULL(field_path, "Field path");
7b33a0e0 86 return field_path->root;
b011f6b0
PP
87}
88
1d4afa5f 89uint64_t bt_field_path_get_item_count(const struct bt_field_path *field_path)
b011f6b0 90{
fa6cfec3 91 BT_ASSERT_PRE_DEV_NON_NULL(field_path, "Field path");
1d4afa5f 92 return (uint64_t) field_path->items->len;
b011f6b0
PP
93}
94
1d4afa5f 95const struct bt_field_path_item *bt_field_path_borrow_item_by_index_const(
78cf9df6 96 const struct bt_field_path *field_path, uint64_t index)
b011f6b0 97{
fa6cfec3
PP
98 BT_ASSERT_PRE_DEV_NON_NULL(field_path, "Field path");
99 BT_ASSERT_PRE_DEV_VALID_INDEX(index, field_path->items->len);
1d4afa5f
PP
100 return bt_field_path_borrow_item_by_index_inline(field_path, index);
101}
102
103enum bt_field_path_item_type bt_field_path_item_get_type(
104 const struct bt_field_path_item *field_path_item)
105{
fa6cfec3 106 BT_ASSERT_PRE_DEV_NON_NULL(field_path_item, "Field path item");
1d4afa5f
PP
107 return field_path_item->type;
108}
109
110uint64_t bt_field_path_item_index_get_index(
111 const struct bt_field_path_item *field_path_item)
112{
fa6cfec3
PP
113 BT_ASSERT_PRE_DEV_NON_NULL(field_path_item, "Field path item");
114 BT_ASSERT_PRE_DEV(field_path_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX,
1d4afa5f
PP
115 "Field path item is not an index field path item: "
116 "addr=%p, type=%s", field_path_item,
117 bt_field_path_item_type_string(field_path_item->type));
118 return field_path_item->index;
b011f6b0 119}
8c6884d9
PP
120
121void bt_field_path_get_ref(const struct bt_field_path *field_path)
122{
123 bt_object_get_ref(field_path);
124}
125
126void bt_field_path_put_ref(const struct bt_field_path *field_path)
127{
128 bt_object_put_ref(field_path);
129}
This page took 0.077462 seconds and 4 git commands to generate.