Trace IR and notification APIs: split into private and public APIs
[babeltrace.git] / lib / trace-ir / field-path.c
1 /*
2 * field-path.c
3 *
4 * Babeltrace trace IR - Field path
5 *
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28 #define BT_LOG_TAG "FIELD-PATH"
29 #include <babeltrace/lib-logging-internal.h>
30
31 #include <babeltrace/assert-pre-internal.h>
32 #include <babeltrace/trace-ir/field-classes.h>
33 #include <babeltrace/trace-ir/field-classes-internal.h>
34 #include <babeltrace/trace-ir/field-path-internal.h>
35 #include <babeltrace/trace-ir/field-path.h>
36 #include <babeltrace/object.h>
37 #include <limits.h>
38 #include <stdint.h>
39 #include <inttypes.h>
40 #include <babeltrace/assert-internal.h>
41 #include <glib.h>
42
43 static
44 void destroy_field_path(struct bt_object *obj)
45 {
46 struct bt_field_path *field_path = (struct bt_field_path *) obj;
47
48 BT_ASSERT(field_path);
49 BT_LIB_LOGD("Destroying field path: %!+P", field_path);
50 g_array_free(field_path->indexes, TRUE);
51 g_free(field_path);
52 }
53
54 BT_HIDDEN
55 struct bt_field_path *bt_field_path_create(void)
56 {
57 struct bt_field_path *field_path = NULL;
58
59 BT_LOGD_STR("Creating empty field path object.");
60
61 field_path = g_new0(struct bt_field_path, 1);
62 if (!field_path) {
63 BT_LOGE_STR("Failed to allocate one field path.");
64 goto error;
65 }
66
67 bt_object_init_shared(&field_path->base, destroy_field_path);
68 field_path->indexes = g_array_new(FALSE, FALSE, sizeof(uint64_t));
69 if (!field_path->indexes) {
70 BT_LOGE_STR("Failed to allocate a GArray.");
71 goto error;
72 }
73
74 BT_LIB_LOGD("Created empty field path object: %!+P", field_path);
75 goto end;
76
77 error:
78 BT_OBJECT_PUT_REF_AND_RESET(field_path);
79
80 end:
81 return field_path;
82 }
83
84 enum bt_scope bt_field_path_get_root_scope(struct bt_field_path *field_path)
85 {
86 BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
87 return field_path->root;
88 }
89
90 uint64_t bt_field_path_get_index_count(struct bt_field_path *field_path)
91 {
92 BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
93 return (uint64_t) field_path->indexes->len;
94 }
95
96 uint64_t bt_field_path_get_index_by_index(struct bt_field_path *field_path,
97 uint64_t index)
98 {
99 BT_ASSERT_PRE_NON_NULL(field_path, "Field path");
100 BT_ASSERT_PRE_VALID_INDEX(index, field_path->indexes->len);
101 return bt_field_path_get_index_by_index_inline(field_path, index);
102 }
This page took 0.030559 seconds and 4 git commands to generate.