2 * SPDX-License-Identifier: MIT
4 * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Copyright 2016 Philippe Proulx <pproulx@efficios.com>
7 * Babeltrace CTF writer - Field path
10 #define BT_LOG_TAG "CTF-WRITER/FIELD-PATH"
18 #include <babeltrace2-ctf-writer/field-types.h>
20 #include "common/assert.h"
22 #include "field-path.h"
23 #include "field-types.h"
26 void field_path_destroy(struct bt_ctf_object
*obj
)
28 struct bt_ctf_field_path
*field_path
= (struct bt_ctf_field_path
*) obj
;
30 BT_LOGD("Destroying field path: addr=%p", obj
);
36 if (field_path
->indexes
) {
37 g_array_free(field_path
->indexes
, TRUE
);
42 struct bt_ctf_field_path
*bt_ctf_field_path_create(void)
44 struct bt_ctf_field_path
*field_path
= NULL
;
46 BT_LOGD_STR("Creating empty field path object.");
48 field_path
= g_new0(struct bt_ctf_field_path
, 1);
50 BT_LOGE_STR("Failed to allocate one field path.");
54 bt_ctf_object_init_shared(&field_path
->base
, field_path_destroy
);
55 field_path
->root
= BT_CTF_SCOPE_UNKNOWN
;
56 field_path
->indexes
= g_array_new(TRUE
, FALSE
, sizeof(int));
57 if (!field_path
->indexes
) {
58 BT_LOGE_STR("Failed to allocate a GArray.");
62 BT_LOGD("Created empty field path object: addr=%p", field_path
);
66 BT_CTF_OBJECT_PUT_REF_AND_RESET(field_path
);
70 void bt_ctf_field_path_clear(struct bt_ctf_field_path
*field_path
)
72 if (field_path
->indexes
->len
> 0) {
73 g_array_remove_range(field_path
->indexes
, 0,
74 field_path
->indexes
->len
);
78 struct bt_ctf_field_path
*bt_ctf_field_path_copy(
79 struct bt_ctf_field_path
*path
)
81 struct bt_ctf_field_path
*new_path
;
84 BT_LOGD("Copying field path: addr=%p, index-count=%u",
85 path
, path
->indexes
->len
);
86 new_path
= bt_ctf_field_path_create();
88 BT_LOGE_STR("Cannot create empty field path.");
92 new_path
->root
= path
->root
;
93 g_array_insert_vals(new_path
->indexes
, 0,
94 path
->indexes
->data
, path
->indexes
->len
);
95 BT_LOGD("Copied field path: original-addr=%p, copy-addr=%p",
101 enum bt_ctf_scope
bt_ctf_field_path_get_root_scope(
102 const struct bt_ctf_field_path
*field_path
)
104 enum bt_ctf_scope scope
= BT_CTF_SCOPE_UNKNOWN
;
107 BT_LOGW_STR("Invalid parameter: field path is NULL.");
111 scope
= field_path
->root
;
117 int64_t bt_ctf_field_path_get_index_count(
118 const struct bt_ctf_field_path
*field_path
)
120 int64_t count
= (int64_t) -1;
123 BT_LOGW_STR("Invalid parameter: field path is NULL.");
127 count
= (int64_t) field_path
->indexes
->len
;
133 int bt_ctf_field_path_get_index(const struct bt_ctf_field_path
*field_path
,
139 BT_LOGW_STR("Invalid parameter: field path is NULL.");
143 if (index
>= field_path
->indexes
->len
) {
144 BT_LOGW("Invalid parameter: index is out of bounds: "
145 "addr=%p, index=%" PRIu64
", count=%u",
146 field_path
, index
, field_path
->indexes
->len
);
150 ret
= bt_g_array_index(field_path
->indexes
, int, index
);
This page took 0.034712 seconds and 4 git commands to generate.