lib: Make bt_value_null a const pointer
[babeltrace.git] / bindings / python / bt2 / bt2 / native_btgraph.i
CommitLineData
f6a5e476
PP
1/*
2 * The MIT License (MIT)
3 *
4 * Copyright (c) 2017 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/* Types */
26struct bt_graph;
27
28/* Status */
29enum bt_graph_status {
30 BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION = 111,
31 BT_GRAPH_STATUS_CANCELED = 125,
32 BT_GRAPH_STATUS_AGAIN = 11,
33 BT_GRAPH_STATUS_END = 1,
34 BT_GRAPH_STATUS_OK = 0,
35 BT_GRAPH_STATUS_INVALID = -22,
36 BT_GRAPH_STATUS_NO_SINK = -6,
9ef22b36 37 BT_GRAPH_STATUS_CANNOT_CONSUME = -2,
f6a5e476
PP
38 BT_GRAPH_STATUS_ERROR = -1,
39 BT_GRAPH_STATUS_NOMEM = -12,
40};
41
42/* Functions */
43struct bt_graph *bt_graph_create(void);
44enum bt_graph_status bt_graph_add_component(
45 struct bt_graph *graph,
46 struct bt_component_class *component_class,
47 const char *name, struct bt_value *params,
48 struct bt_component **BTOUTCOMP);
49enum bt_graph_status bt_graph_add_component_with_init_method_data(
50 struct bt_graph *graph,
51 struct bt_component_class *component_class,
52 const char *name, struct bt_value *params,
53 void *init_method_data,
54 struct bt_component **BTOUTCOMP);
55enum bt_graph_status bt_graph_connect_ports(struct bt_graph *graph,
56 struct bt_port *upstream, struct bt_port *downstream,
57 struct bt_connection **BTOUTCONN);
58enum bt_graph_status bt_graph_run(struct bt_graph *graph);
59enum bt_graph_status bt_graph_consume(struct bt_graph *graph);
60enum bt_graph_status bt_graph_cancel(struct bt_graph *graph);
61int bt_graph_is_canceled(struct bt_graph *graph);
62
63/* Helper functions for Python */
64%{
65static void port_added_listener(struct bt_port *port, void *py_callable)
66{
67 PyObject *py_port_ptr = NULL;
68 PyObject *py_res = NULL;
69
70 py_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(port),
71 SWIGTYPE_p_bt_port, 0);
72 if (!py_port_ptr) {
73 BT_LOGF_STR("Failed to create a SWIG pointer object.");
74 abort();
75 }
76
77 py_res = PyObject_CallFunction(py_callable, "(O)", py_port_ptr);
8b45963b 78 BT_ASSERT(py_res == Py_None);
f6a5e476
PP
79 Py_DECREF(py_port_ptr);
80 Py_DECREF(py_res);
81}
82
83static void port_removed_listener(struct bt_component *component,
84 struct bt_port *port, void *py_callable)
85{
86 PyObject *py_port_ptr = NULL;
87 PyObject *py_res = NULL;
88
89 py_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(port),
90 SWIGTYPE_p_bt_port, 0);
91 if (!py_port_ptr) {
92 BT_LOGF_STR("Failed to create a SWIG pointer object.");
93 abort();
94 }
95
96 py_res = PyObject_CallFunction(py_callable, "(O)", py_port_ptr);
8b45963b 97 BT_ASSERT(py_res == Py_None);
f6a5e476
PP
98 Py_DECREF(py_port_ptr);
99 Py_DECREF(py_res);
100}
101
102static void ports_connected_listener(struct bt_port *upstream_port,
103 struct bt_port *downstream_port, void *py_callable)
104{
105 PyObject *py_upstream_port_ptr = NULL;
106 PyObject *py_downstream_port_ptr = NULL;
107 PyObject *py_res = NULL;
108
109 py_upstream_port_ptr = SWIG_NewPointerObj(
110 SWIG_as_voidptr(upstream_port), SWIGTYPE_p_bt_port, 0);
111 if (!py_upstream_port_ptr) {
112 BT_LOGF_STR("Failed to create a SWIG pointer object.");
113 abort();
114 }
115
116 py_downstream_port_ptr = SWIG_NewPointerObj(
117 SWIG_as_voidptr(downstream_port), SWIGTYPE_p_bt_port, 0);
118 if (!py_downstream_port_ptr) {
119 BT_LOGF_STR("Failed to create a SWIG pointer object.");
120 abort();
121 }
122
123 py_res = PyObject_CallFunction(py_callable, "(OO)",
124 py_upstream_port_ptr, py_downstream_port_ptr);
8b45963b 125 BT_ASSERT(py_res == Py_None);
f6a5e476
PP
126 Py_DECREF(py_upstream_port_ptr);
127 Py_DECREF(py_downstream_port_ptr);
128 Py_DECREF(py_res);
129}
130
131static void ports_disconnected_listener(
132 struct bt_component *upstream_component,
133 struct bt_component *downstream_component,
134 struct bt_port *upstream_port, struct bt_port *downstream_port,
135 void *py_callable)
136{
137 PyObject *py_upstream_comp_ptr = NULL;
138 PyObject *py_downstream_comp_ptr = NULL;
139 PyObject *py_upstream_port_ptr = NULL;
140 PyObject *py_downstream_port_ptr = NULL;
141 PyObject *py_res = NULL;
142
143 py_upstream_comp_ptr = SWIG_NewPointerObj(
144 SWIG_as_voidptr(upstream_component),
145 SWIGTYPE_p_bt_component, 0);
146 if (!py_upstream_comp_ptr) {
147 BT_LOGF_STR("Failed to create a SWIG pointer object.");
148 abort();
149 }
150
151 py_downstream_comp_ptr = SWIG_NewPointerObj(
152 SWIG_as_voidptr(downstream_component),
153 SWIGTYPE_p_bt_component, 0);
154 if (!py_downstream_comp_ptr) {
155 BT_LOGF_STR("Failed to create a SWIG pointer object.");
156 abort();
157 }
158
159 py_upstream_port_ptr = SWIG_NewPointerObj(
160 SWIG_as_voidptr(upstream_port), SWIGTYPE_p_bt_port, 0);
161 if (!py_upstream_port_ptr) {
162 BT_LOGF_STR("Failed to create a SWIG pointer object.");
163 abort();
164 }
165
166 py_downstream_port_ptr = SWIG_NewPointerObj(
167 SWIG_as_voidptr(downstream_port), SWIGTYPE_p_bt_port, 0);
168 if (!py_downstream_port_ptr) {
169 BT_LOGF_STR("Failed to create a SWIG pointer object.");
170 abort();
171 }
172
173 py_res = PyObject_CallFunction(py_callable, "(OOOO)",
174 py_upstream_comp_ptr, py_downstream_comp_ptr,
175 py_upstream_port_ptr, py_downstream_port_ptr);
8b45963b 176 BT_ASSERT(py_res == Py_None);
f6a5e476
PP
177 Py_DECREF(py_upstream_comp_ptr);
178 Py_DECREF(py_downstream_comp_ptr);
179 Py_DECREF(py_upstream_port_ptr);
180 Py_DECREF(py_downstream_port_ptr);
181 Py_DECREF(py_res);
182}
183
184static void graph_listener_removed(void *py_callable)
185{
8b45963b 186 BT_ASSERT(py_callable);
f6a5e476
PP
187 Py_DECREF(py_callable);
188}
189
190static int bt_py3_graph_add_port_added_listener(struct bt_graph *graph,
191 PyObject *py_callable)
192{
193 int ret = 0;
194
8b45963b
PP
195 BT_ASSERT(graph);
196 BT_ASSERT(py_callable);
f6a5e476
PP
197 ret = bt_graph_add_port_added_listener(graph, port_added_listener,
198 graph_listener_removed, py_callable);
199 if (ret >= 0) {
200 Py_INCREF(py_callable);
201 }
202
203 return ret;
204}
205
206static int bt_py3_graph_add_port_removed_listener(struct bt_graph *graph,
207 PyObject *py_callable)
208{
209 int ret = 0;
210
8b45963b
PP
211 BT_ASSERT(graph);
212 BT_ASSERT(py_callable);
f6a5e476
PP
213 ret = bt_graph_add_port_removed_listener(graph, port_removed_listener,
214 graph_listener_removed, py_callable);
215 if (ret >= 0) {
216 Py_INCREF(py_callable);
217 }
218
219 return ret;
220}
221
222static int bt_py3_graph_add_ports_connected_listener(struct bt_graph *graph,
223 PyObject *py_callable)
224{
225 int ret = 0;
226
8b45963b
PP
227 BT_ASSERT(graph);
228 BT_ASSERT(py_callable);
f6a5e476
PP
229 ret = bt_graph_add_ports_connected_listener(graph,
230 ports_connected_listener, graph_listener_removed, py_callable);
231 if (ret >= 0) {
232 Py_INCREF(py_callable);
233 }
234
235 return ret;
236}
237
238static int bt_py3_graph_add_ports_disconnected_listener(struct bt_graph *graph,
239 PyObject *py_callable)
240{
241 int ret = 0;
242
8b45963b
PP
243 BT_ASSERT(graph);
244 BT_ASSERT(py_callable);
f6a5e476
PP
245 ret = bt_graph_add_ports_disconnected_listener(graph,
246 ports_disconnected_listener, graph_listener_removed,
247 py_callable);
248 if (ret >= 0) {
249 Py_INCREF(py_callable);
250 }
251
252 return ret;
253}
254%}
255
256int bt_py3_graph_add_port_added_listener(struct bt_graph *graph,
257 PyObject *py_callable);
258int bt_py3_graph_add_port_removed_listener(struct bt_graph *graph,
259 PyObject *py_callable);
260int bt_py3_graph_add_ports_connected_listener(struct bt_graph *graph,
261 PyObject *py_callable);
262int bt_py3_graph_add_ports_disconnected_listener(struct bt_graph *graph,
263 PyObject *py_callable);
This page took 0.037037 seconds and 4 git commands to generate.