Move to kernel style SPDX license identifiers
[babeltrace.git] / src / bindings / python / bt2 / bt2 / native_bt_value.i.h
CommitLineData
4212232c 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
4212232c
PP
3 *
4 * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
4212232c
PP
5 */
6
7struct bt_value_map_get_keys_data {
8 struct bt_value *keys;
9};
10
27c61ce8
PP
11static bt_value_map_foreach_entry_const_func_status bt_value_map_get_keys_cb(
12 const char *key, const struct bt_value *object, void *data)
4212232c 13{
27c61ce8 14 int status;
4212232c
PP
15 struct bt_value_map_get_keys_data *priv_data = data;
16
17 status = bt_value_array_append_string_element(priv_data->keys, key);
27c61ce8
PP
18 BT_ASSERT(status == __BT_FUNC_STATUS_OK ||
19 status == __BT_FUNC_STATUS_MEMORY_ERROR);
20 return status;
4212232c
PP
21}
22
23static struct bt_value *bt_value_map_get_keys(const struct bt_value *map_obj)
24{
25 bt_value_map_foreach_entry_const_status status;
26 struct bt_value_map_get_keys_data data;
27
28 data.keys = bt_value_array_create();
29 if (!data.keys) {
30 return NULL;
31 }
32
33 status = bt_value_map_foreach_entry_const(map_obj, bt_value_map_get_keys_cb,
34 &data);
35 if (status != __BT_FUNC_STATUS_OK) {
36 goto error;
37 }
38
39 goto end;
40
41error:
42 if (data.keys) {
43 BT_VALUE_PUT_REF_AND_RESET(data.keys);
44 }
45
46end:
47 return data.keys;
48}
This page took 0.0417 seconds and 4 git commands to generate.