3303134b08ba3e248024642ac18ff90dd12877eb
[babeltrace.git] / lib / trace-ir / field-path.c
1 /*
2 * Copyright 2016-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
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
24 #define BT_LOG_TAG "FIELD-PATH"
25 #include <babeltrace/lib-logging-internal.h>
26
27 #include <babeltrace/assert-pre-internal.h>
28 #include <babeltrace/trace-ir/field-class.h>
29 #include <babeltrace/trace-ir/field-class-internal.h>
30 #include <babeltrace/trace-ir/field-path-internal.h>
31 #include <babeltrace/trace-ir/field-path-const.h>
32 #include <limits.h>
33 #include <stdint.h>
34 #include <inttypes.h>
35 #include <babeltrace/assert-internal.h>
36 #include <glib.h>
37
38 static
39 void destroy_field_path(struct bt_object *obj)
40 {
41 struct bt_field_path *field_path = (struct bt_field_path *) obj;
42
43 BT_ASSERT(field_path);
44 BT_LIB_LOGD("Destroying field path: %!+P", field_path);
45 g_array_free(field_path->indexes, TRUE);
46 field_path->indexes = NULL;
47 g_free(field_path);
48 }
49
50 BT_HIDDEN
51 struct bt_field_path *bt_field_path_create(void)
52 {
53 struct bt_field_path *field_path = NULL;
54
55 BT_LOGD_STR("Creating empty field path object.");
56
57 field_path = g_new0(struct bt_field_path, 1);
58 if (!field_path) {
59 BT_LOGE_STR("Failed to allocate one field path.");
60 goto error;
61 }
62
63 bt_object_init_shared(&field_path->base, destroy_field_path);
64 field_path->indexes = g_array_new(FALSE, FALSE, sizeof(uint64_t));
65 if (!field_path->indexes) {
66 BT_LOGE_STR("Failed to allocate a GArray.");
67 goto error;
68 }
69
70 BT_LIB_LOGD("Created empty field path object: %!+P", field_path);
71 goto end;
72
73 error:
74 BT_OBJECT_PUT_REF_AND_RESET(field_path);
75
76 end:
77 return field_path;
78 }
79
80 enum bt_scope bt_field_path_get_root_scope(
81 const struct bt_field_path *field_path)
82 {
83 BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
84 return field_path->root;
85 }
86
87 uint64_t bt_field_path_get_index_count(const struct bt_field_path *field_path)
88 {
89 BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
90 return (uint64_t) field_path->indexes->len;
91 }
92
93 uint64_t bt_field_path_get_index_by_index(
94 const struct bt_field_path *field_path, uint64_t index)
95 {
96 BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
97 BT_ASSERT_PRE_VALID_INDEX(index, field_path->indexes->len);
98 return bt_field_path_get_index_by_index_inline(field_path, index);
99 }
100
101 void bt_field_path_get_ref(const struct bt_field_path *field_path)
102 {
103 bt_object_get_ref(field_path);
104 }
105
106 void bt_field_path_put_ref(const struct bt_field_path *field_path)
107 {
108 bt_object_put_ref(field_path);
109 }
This page took 0.031013 seconds and 3 git commands to generate.