Visibility hidden by default
[babeltrace.git] / src / lib / trace-ir / field-path.c
CommitLineData
b011f6b0 1/*
0235b0db
MJ
2 * SPDX-License-Identifier: MIT
3 *
e2f7325d 4 * Copyright 2016-2018 Philippe Proulx <pproulx@efficios.com>
b011f6b0 5 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
b011f6b0
PP
6 */
7
350ad6c1 8#define BT_LOG_TAG "LIB/FIELD-PATH"
c2d9d9cf 9#include "lib/logging.h"
1e6cfa95 10
d98421f2 11#include "lib/assert-cond.h"
3fadfbc0 12#include <babeltrace2/trace-ir/field-class.h>
43c59509 13#include <babeltrace2/trace-ir/field-path.h>
b011f6b0 14#include <limits.h>
544d0515 15#include <stdint.h>
1e6cfa95 16#include <inttypes.h>
578e048b 17#include "common/assert.h"
b011f6b0
PP
18#include <glib.h>
19
578e048b
MJ
20#include "field-class.h"
21#include "field-path.h"
22
b011f6b0 23static
44c440bc 24void destroy_field_path(struct bt_object *obj)
b011f6b0 25{
50842bdc 26 struct bt_field_path *field_path = (struct bt_field_path *) obj;
b011f6b0 27
44c440bc
PP
28 BT_ASSERT(field_path);
29 BT_LIB_LOGD("Destroying field path: %!+P", field_path);
66ddcddf
PP
30 g_array_free(field_path->items, TRUE);
31 field_path->items = NULL;
b011f6b0
PP
32 g_free(field_path);
33}
34
50842bdc 35struct bt_field_path *bt_field_path_create(void)
b011f6b0 36{
50842bdc 37 struct bt_field_path *field_path = NULL;
b011f6b0 38
1e6cfa95
PP
39 BT_LOGD_STR("Creating empty field path object.");
40
50842bdc 41 field_path = g_new0(struct bt_field_path, 1);
b011f6b0 42 if (!field_path) {
870631a2 43 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one field path.");
b011f6b0
PP
44 goto error;
45 }
46
44c440bc 47 bt_object_init_shared(&field_path->base, destroy_field_path);
66ddcddf
PP
48 field_path->items = g_array_new(FALSE, FALSE,
49 sizeof(struct bt_field_path_item));
50 if (!field_path->items) {
870631a2 51 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
b011f6b0
PP
52 goto error;
53 }
54
44c440bc
PP
55 BT_LIB_LOGD("Created empty field path object: %!+P", field_path);
56 goto end;
b011f6b0
PP
57
58error:
65300d60 59 BT_OBJECT_PUT_REF_AND_RESET(field_path);
b011f6b0 60
b011f6b0 61end:
44c440bc 62 return field_path;
b011f6b0
PP
63}
64
1353b066 65BT_EXPORT
e7ceb9df 66enum bt_field_path_scope bt_field_path_get_root_scope(
40f4ba76 67 const struct bt_field_path *field_path)
b011f6b0 68{
d5b13b9b 69 BT_ASSERT_PRE_DEV_FP_NON_NULL(field_path);
44c440bc 70 return field_path->root;
b011f6b0
PP
71}
72
1353b066 73BT_EXPORT
66ddcddf 74uint64_t bt_field_path_get_item_count(const struct bt_field_path *field_path)
b011f6b0 75{
d5b13b9b 76 BT_ASSERT_PRE_DEV_FP_NON_NULL(field_path);
66ddcddf 77 return (uint64_t) field_path->items->len;
b011f6b0
PP
78}
79
1353b066 80BT_EXPORT
66ddcddf 81const struct bt_field_path_item *bt_field_path_borrow_item_by_index_const(
40f4ba76 82 const struct bt_field_path *field_path, uint64_t index)
b011f6b0 83{
d5b13b9b 84 BT_ASSERT_PRE_DEV_FP_NON_NULL(field_path);
bdb288b3 85 BT_ASSERT_PRE_DEV_VALID_INDEX(index, field_path->items->len);
66ddcddf
PP
86 return bt_field_path_borrow_item_by_index_inline(field_path, index);
87}
88
1353b066 89BT_EXPORT
66ddcddf
PP
90enum bt_field_path_item_type bt_field_path_item_get_type(
91 const struct bt_field_path_item *field_path_item)
92{
1778c2a4
PP
93 BT_ASSERT_PRE_DEV_NON_NULL("field-path-item", field_path_item,
94 "Field path item");
66ddcddf
PP
95 return field_path_item->type;
96}
97
1353b066 98BT_EXPORT
66ddcddf
PP
99uint64_t bt_field_path_item_index_get_index(
100 const struct bt_field_path_item *field_path_item)
101{
1778c2a4
PP
102 BT_ASSERT_PRE_DEV_NON_NULL("field-path-item", field_path_item,
103 "Field path item");
104 BT_ASSERT_PRE_DEV("is-index-field-path-item",
105 field_path_item->type == BT_FIELD_PATH_ITEM_TYPE_INDEX,
66ddcddf
PP
106 "Field path item is not an index field path item: "
107 "addr=%p, type=%s", field_path_item,
108 bt_field_path_item_type_string(field_path_item->type));
109 return field_path_item->index;
b011f6b0 110}
c5b9b441 111
1353b066 112BT_EXPORT
c5b9b441
PP
113void bt_field_path_get_ref(const struct bt_field_path *field_path)
114{
115 bt_object_get_ref(field_path);
116}
117
1353b066 118BT_EXPORT
c5b9b441
PP
119void bt_field_path_put_ref(const struct bt_field_path *field_path)
120{
121 bt_object_put_ref(field_path);
122}
This page took 0.111143 seconds and 4 git commands to generate.