lib/plugin/plugin.c: do not use G_MODULE_BIND_LOCAL for Python plugin provider
[babeltrace.git] / bindings / python / bt2 / native_btvalues.i
CommitLineData
81447b5b
PP
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2016 Philippe Proulx <pproulx@efficios.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25%{
26#include <babeltrace/values.h>
27%}
28
29/* For uint*_t/int*_t */
30%include "stdint.i"
31
32/* Remove prefix from `bt_value_null` */
33%rename(value_null) bt_value_null;
34
35/* Type and status */
36struct bt_value;
37
38enum bt_value_type {
39 BT_VALUE_TYPE_UNKNOWN = -1,
40 BT_VALUE_TYPE_NULL = 0,
41 BT_VALUE_TYPE_BOOL = 1,
42 BT_VALUE_TYPE_INTEGER = 2,
43 BT_VALUE_TYPE_FLOAT = 3,
44 BT_VALUE_TYPE_STRING = 4,
45 BT_VALUE_TYPE_ARRAY = 5,
46 BT_VALUE_TYPE_MAP = 6,
47};
48
49enum bt_value_type bt_value_get_type(const struct bt_value *object);
50
51enum bt_value_status {
52 BT_VALUE_STATUS_FROZEN = -4,
53 BT_VALUE_STATUS_CANCELLED = -3,
54 BT_VALUE_STATUS_INVAL = -22,
55 BT_VALUE_STATUS_ERROR = -1,
56 BT_VALUE_STATUS_OK = 0,
57};
58
59/* Null value object singleton */
60struct bt_value * const bt_value_null;
61
62/* Common functions */
63enum bt_value_status bt_value_freeze(struct bt_value *object);
64bool bt_value_is_frozen(const struct bt_value *object);
65struct bt_value *bt_value_copy(const struct bt_value *object);
66bool bt_value_compare(const struct bt_value *object_a,
67 const struct bt_value *object_b);
68
69/* Boolean value object functions */
70struct bt_value *bt_value_bool_create(void);
71struct bt_value *bt_value_bool_create_init(bool val);
72enum bt_value_status bt_value_bool_get(
73 const struct bt_value *bool_obj, bool *OUTPUT);
74enum bt_value_status bt_value_bool_set(struct bt_value *bool_obj,
75 bool val);
76
77/* Integer value object functions */
78struct bt_value *bt_value_integer_create(void);
79struct bt_value *bt_value_integer_create_init(int64_t val);
80enum bt_value_status bt_value_integer_get(
81 const struct bt_value *integer_obj, int64_t *OUTPUT);
82enum bt_value_status bt_value_integer_set(
83 struct bt_value *integer_obj, int64_t val);
84
85/* Floating point number value object functions */
86struct bt_value *bt_value_float_create(void);
87struct bt_value *bt_value_float_create_init(double val);
88enum bt_value_status bt_value_float_get(
89 const struct bt_value *float_obj, double *OUTPUT);
90enum bt_value_status bt_value_float_set(
91 struct bt_value *float_obj, double val);
92
93/* String value object functions */
94struct bt_value *bt_value_string_create(void);
95struct bt_value *bt_value_string_create_init(const char *val);
96enum bt_value_status bt_value_string_set(struct bt_value *string_obj,
97 const char *val);
98enum bt_value_status bt_value_string_get(
99 const struct bt_value *string_obj, const char **BTOUTSTR);
100
101/* Array value object functions */
102struct bt_value *bt_value_array_create(void);
103int bt_value_array_size(const struct bt_value *array_obj);
104struct bt_value *bt_value_array_get(const struct bt_value *array_obj,
105 size_t index);
106enum bt_value_status bt_value_array_append(struct bt_value *array_obj,
107 struct bt_value *element_obj);
108enum bt_value_status bt_value_array_set(struct bt_value *array_obj,
109 size_t index, struct bt_value *element_obj);
110
111/* Map value object functions */
112struct bt_value *bt_value_map_create(void);
113int bt_value_map_size(const struct bt_value *map_obj);
114struct bt_value *bt_value_map_get(const struct bt_value *map_obj,
115 const char *key);
116bool bt_value_map_has_key(const struct bt_value *map_obj,
117 const char *key);
118enum bt_value_status bt_value_map_insert(
119 struct bt_value *map_obj, const char *key,
120 struct bt_value *element_obj);
121
122%{
123struct bt_value_map_get_keys_private_data {
124 struct bt_value *keys;
125};
126
127static bool bt_value_map_get_keys_private_cb(const char *key,
128 struct bt_value *object, void *data)
129{
130 enum bt_value_status status;
131 struct bt_value_map_get_keys_private_data *priv_data = data;
132
133 status = bt_value_array_append_string(priv_data->keys, key);
134 if (status != BT_VALUE_STATUS_OK) {
135 return false;
136 }
137
138 return true;
139}
140
141static struct bt_value *bt_value_map_get_keys_private(
142 const struct bt_value *map_obj)
143{
144 enum bt_value_status status;
145 struct bt_value_map_get_keys_private_data data;
146
147 data.keys = bt_value_array_create();
148 if (!data.keys) {
149 return NULL;
150 }
151
152 status = bt_value_map_foreach(map_obj, bt_value_map_get_keys_private_cb,
153 &data);
154 if (status != BT_VALUE_STATUS_OK) {
155 goto error;
156 }
157
158 goto end;
159
160error:
161 if (data.keys) {
162 BT_PUT(data.keys);
163 }
164
165end:
166 return data.keys;
167}
168%}
169
170struct bt_value *bt_value_map_get_keys_private(const struct bt_value *map_obj);
This page took 0.034845 seconds and 4 git commands to generate.