4 * Babeltrace CTF IR - Field path
6 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
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:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
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
28 #define BT_LOG_TAG "FIELD-PATH"
29 #include <babeltrace/lib-logging-internal.h>
31 #include <babeltrace/ctf-ir/field-types.h>
32 #include <babeltrace/ctf-ir/field-types-internal.h>
33 #include <babeltrace/ctf-ir/field-path-internal.h>
34 #include <babeltrace/ctf-ir/field-path.h>
38 #include <babeltrace/assert-internal.h>
42 void field_path_destroy(struct bt_object
*obj
)
44 struct bt_field_path
*field_path
= (struct bt_field_path
*) obj
;
46 BT_LOGD("Destroying field path: addr=%p", obj
);
52 if (field_path
->indexes
) {
53 g_array_free(field_path
->indexes
, TRUE
);
59 struct bt_field_path
*bt_field_path_create(void)
61 struct bt_field_path
*field_path
= NULL
;
63 BT_LOGD_STR("Creating empty field path object.");
65 field_path
= g_new0(struct bt_field_path
, 1);
67 BT_LOGE_STR("Failed to allocate one field path.");
71 bt_object_init(field_path
, field_path_destroy
);
72 field_path
->root
= BT_SCOPE_UNKNOWN
;
73 field_path
->indexes
= g_array_new(TRUE
, FALSE
, sizeof(int));
74 if (!field_path
->indexes
) {
75 BT_LOGE_STR("Failed to allocate a GArray.");
79 BT_LOGD("Created empty field path object: addr=%p", field_path
);
88 void bt_field_path_clear(struct bt_field_path
*field_path
)
90 if (field_path
->indexes
->len
> 0) {
91 g_array_remove_range(field_path
->indexes
, 0,
92 field_path
->indexes
->len
);
97 struct bt_field_path
*bt_field_path_copy(
98 struct bt_field_path
*path
)
100 struct bt_field_path
*new_path
;
103 BT_LOGD("Copying field path: addr=%p, index-count=%u",
104 path
, path
->indexes
->len
);
105 new_path
= bt_field_path_create();
107 BT_LOGE_STR("Cannot create empty field path.");
111 new_path
->root
= path
->root
;
112 g_array_insert_vals(new_path
->indexes
, 0,
113 path
->indexes
->data
, path
->indexes
->len
);
114 BT_LOGD("Copied field path: original-addr=%p, copy-addr=%p",
120 enum bt_scope
bt_field_path_get_root_scope(
121 const struct bt_field_path
*field_path
)
123 enum bt_scope scope
= BT_SCOPE_UNKNOWN
;
126 BT_LOGW_STR("Invalid parameter: field path is NULL.");
130 scope
= field_path
->root
;
136 int64_t bt_field_path_get_index_count(
137 const struct bt_field_path
*field_path
)
139 int64_t count
= (int64_t) -1;
142 BT_LOGW_STR("Invalid parameter: field path is NULL.");
146 count
= (int64_t) field_path
->indexes
->len
;
152 int bt_field_path_get_index(const struct bt_field_path
*field_path
,
158 BT_LOGW_STR("Invalid parameter: field path is NULL.");
162 if (index
>= field_path
->indexes
->len
) {
163 BT_LOGW("Invalid parameter: index is out of bounds: "
164 "addr=%p, index=%" PRIu64
", count=%u",
165 field_path
, index
, field_path
->indexes
->len
);
169 ret
= g_array_index(field_path
->indexes
, int, index
);
This page took 0.035039 seconds and 4 git commands to generate.