lib: remove "accept port" concept
[babeltrace.git] / src / bindings / python / bt2 / bt2 / native_bt_graph.i
CommitLineData
6945df9a
SM
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/* Output argument typemap for connection output (always appends) */
26%typemap(in, numinputs=0)
27 (const bt_connection **BTOUTCONN)
28 (bt_connection *temp_conn = NULL) {
29 $1 = &temp_conn;
30}
31
32%typemap(argout)
33 (const bt_connection **BTOUTCONN) {
34 if (*$1) {
35 /* SWIG_Python_AppendOutput() steals the created object */
36 $result = SWIG_Python_AppendOutput($result,
37 SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
38 SWIGTYPE_p_bt_connection, 0));
39 } else {
40 /* SWIG_Python_AppendOutput() steals Py_None */
41 Py_INCREF(Py_None);
42 $result = SWIG_Python_AppendOutput($result, Py_None);
43 }
44}
45
46/* Output argument typemap for component output (always appends) */
47%typemap(in, numinputs=0)
48 (const bt_component_source **OUT)
49 (bt_component_source *temp_comp = NULL) {
50 $1 = &temp_comp;
51}
52
53%typemap(in, numinputs=0)
54 (const bt_component_filter **OUT)
55 (bt_component_filter *temp_comp = NULL) {
56 $1 = &temp_comp;
57}
58
59%typemap(in, numinputs=0)
60 (const bt_component_sink **OUT)
61 (bt_component_sink *temp_comp = NULL) {
62 $1 = &temp_comp;
63}
64
65%typemap(argout) (const bt_component_source **OUT) {
66 if (*$1) {
67 /* SWIG_Python_AppendOutput() steals the created object */
68 $result = SWIG_Python_AppendOutput($result,
69 SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
70 SWIGTYPE_p_bt_component_source, 0));
71 } else {
72 /* SWIG_Python_AppendOutput() steals Py_None */
73 Py_INCREF(Py_None);
74 $result = SWIG_Python_AppendOutput($result, Py_None);
75 }
76}
77
78%typemap(argout) (const bt_component_filter **OUT) {
79 if (*$1) {
80 /* SWIG_Python_AppendOutput() steals the created object */
81 $result = SWIG_Python_AppendOutput($result,
82 SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
83 SWIGTYPE_p_bt_component_filter, 0));
84 } else {
85 /* SWIG_Python_AppendOutput() steals Py_None */
86 Py_INCREF(Py_None);
87 $result = SWIG_Python_AppendOutput($result, Py_None);
88 }
89}
90
91%typemap(argout) (const bt_component_sink **OUT) {
92 if (*$1) {
93 /* SWIG_Python_AppendOutput() steals the created object */
94 $result = SWIG_Python_AppendOutput($result,
95 SWIG_NewPointerObj(SWIG_as_voidptr(*$1),
96 SWIGTYPE_p_bt_component_sink, 0));
97 } else {
98 /* SWIG_Python_AppendOutput() steals Py_None */
99 Py_INCREF(Py_None);
100 $result = SWIG_Python_AppendOutput($result, Py_None);
101 }
102}
103
104/* From graph-const.h */
105
106typedef enum bt_graph_status {
107 BT_GRAPH_STATUS_OK = 0,
108 BT_GRAPH_STATUS_END = 1,
109 BT_GRAPH_STATUS_AGAIN = 11,
6945df9a
SM
110 BT_GRAPH_STATUS_CANCELED = 125,
111 BT_GRAPH_STATUS_ERROR = -1,
112 BT_GRAPH_STATUS_NOMEM = -12,
113} bt_graph_status;
114
115extern bt_bool bt_graph_is_canceled(const bt_graph *graph);
116
117extern void bt_graph_get_ref(const bt_graph *graph);
118
119extern void bt_graph_put_ref(const bt_graph *graph);
120
121/* From graph.h */
122
8cc56726
SM
123typedef enum bt_graph_listener_status {
124 BT_GRAPH_LISTENER_STATUS_OK = 0,
125 BT_GRAPH_LISTENER_STATUS_ERROR = -1,
126 BT_GRAPH_LISTENER_STATUS_NOMEM = -12,
127} bt_graph_listener_status;
128
129
130typedef bt_graph_listener_status
131(*bt_graph_filter_component_input_port_added_listener_func)(
6945df9a
SM
132 const bt_component_filter *component,
133 const bt_port_input *port, void *data);
134
8cc56726
SM
135typedef bt_graph_listener_status
136(*bt_graph_sink_component_input_port_added_listener_func)(
6945df9a
SM
137 const bt_component_sink *component,
138 const bt_port_input *port, void *data);
139
8cc56726
SM
140typedef bt_graph_listener_status
141(*bt_graph_source_component_output_port_added_listener_func)(
6945df9a
SM
142 const bt_component_source *component,
143 const bt_port_output *port, void *data);
144
8cc56726
SM
145typedef bt_graph_listener_status
146(*bt_graph_filter_component_output_port_added_listener_func)(
6945df9a
SM
147 const bt_component_filter *component,
148 const bt_port_output *port, void *data);
149
8cc56726
SM
150typedef bt_graph_listener_status
151(*bt_graph_source_filter_component_ports_connected_listener_func)(
6945df9a
SM
152 const bt_component_source *source_component,
153 const bt_component_filter *filter_component,
154 const bt_port_output *upstream_port,
155 const bt_port_input *downstream_port, void *data);
156
8cc56726
SM
157typedef bt_graph_listener_status
158(*bt_graph_source_sink_component_ports_connected_listener_func)(
6945df9a
SM
159 const bt_component_source *source_component,
160 const bt_component_sink *sink_component,
161 const bt_port_output *upstream_port,
162 const bt_port_input *downstream_port, void *data);
163
8cc56726
SM
164typedef bt_graph_listener_status
165(*bt_graph_filter_filter_component_ports_connected_listener_func)(
6945df9a
SM
166 const bt_component_filter *filter_component_upstream,
167 const bt_component_filter *filter_component_downstream,
168 const bt_port_output *upstream_port,
169 const bt_port_input *downstream_port,
170 void *data);
171
8cc56726
SM
172typedef bt_graph_listener_status
173(*bt_graph_filter_sink_component_ports_connected_listener_func)(
6945df9a
SM
174 const bt_component_filter *filter_component,
175 const bt_component_sink *sink_component,
176 const bt_port_output *upstream_port,
177 const bt_port_input *downstream_port, void *data);
178
179typedef void (* bt_graph_listener_removed_func)(void *data);
180
181extern bt_graph *bt_graph_create(void);
182
183extern bt_graph_status bt_graph_add_source_component(bt_graph *graph,
184 const bt_component_class_source *component_class,
185 const char *name, const bt_value *params,
e874da19 186 bt_logging_level log_level, const bt_component_source **OUT);
6945df9a
SM
187
188extern bt_graph_status bt_graph_add_source_component_with_init_method_data(
189 bt_graph *graph,
190 const bt_component_class_source *component_class,
191 const char *name, const bt_value *params,
e874da19 192 void *init_method_data, bt_logging_level log_level,
6945df9a
SM
193 const bt_component_source **OUT);
194
195extern bt_graph_status bt_graph_add_filter_component(bt_graph *graph,
196 const bt_component_class_filter *component_class,
197 const char *name, const bt_value *params,
e874da19 198 bt_logging_level log_level,
6945df9a
SM
199 const bt_component_filter **OUT);
200
201extern bt_graph_status bt_graph_add_filter_component_with_init_method_data(
202 bt_graph *graph,
203 const bt_component_class_filter *component_class,
204 const char *name, const bt_value *params,
e874da19 205 void *init_method_data, bt_logging_level log_level,
6945df9a
SM
206 const bt_component_filter **OUT);
207
208extern bt_graph_status bt_graph_add_sink_component(
209 bt_graph *graph, const bt_component_class_sink *component_class,
210 const char *name, const bt_value *params,
e874da19 211 bt_logging_level log_level,
6945df9a
SM
212 const bt_component_sink **OUT);
213
214extern bt_graph_status bt_graph_add_sink_component_with_init_method_data(
215 bt_graph *graph, const bt_component_class_sink *component_class,
216 const char *name, const bt_value *params,
e874da19 217 void *init_method_data, bt_logging_level log_level,
6945df9a
SM
218 const bt_component_sink **OUT);
219
220extern bt_graph_status bt_graph_connect_ports(bt_graph *graph,
221 const bt_port_output *upstream,
222 const bt_port_input *downstream,
223 const bt_connection **BTOUTCONN);
224
225extern bt_graph_status bt_graph_run(bt_graph *graph);
226
227extern bt_graph_status bt_graph_consume(bt_graph *graph);
228
229extern bt_graph_status bt_graph_add_filter_component_input_port_added_listener(
230 bt_graph *graph,
231 bt_graph_filter_component_input_port_added_listener_func listener,
232 bt_graph_listener_removed_func listener_removed, void *data,
233 int *listener_id);
234
235extern bt_graph_status bt_graph_add_sink_component_input_port_added_listener(
236 bt_graph *graph,
237 bt_graph_sink_component_input_port_added_listener_func listener,
238 bt_graph_listener_removed_func listener_removed, void *data,
239 int *listener_id);
240
241extern bt_graph_status bt_graph_add_source_component_output_port_added_listener(
242 bt_graph *graph,
243 bt_graph_source_component_output_port_added_listener_func listener,
244 bt_graph_listener_removed_func listener_removed, void *data,
245 int *listener_id);
246
247extern bt_graph_status bt_graph_add_filter_component_output_port_added_listener(
248 bt_graph *graph,
249 bt_graph_filter_component_output_port_added_listener_func listener,
250 bt_graph_listener_removed_func listener_removed, void *data,
251 int *listener_id);
252
253extern bt_graph_status
254bt_graph_add_source_filter_component_ports_connected_listener(
255 bt_graph *graph,
256 bt_graph_source_filter_component_ports_connected_listener_func listener,
257 bt_graph_listener_removed_func listener_removed, void *data,
258 int *listener_id);
259
260extern bt_graph_status
261bt_graph_add_filter_filter_component_ports_connected_listener(
262 bt_graph *graph,
263 bt_graph_filter_filter_component_ports_connected_listener_func listener,
264 bt_graph_listener_removed_func listener_removed, void *data,
265 int *listener_id);
266
267extern bt_graph_status
268bt_graph_add_source_sink_component_ports_connected_listener(
269 bt_graph *graph,
270 bt_graph_source_sink_component_ports_connected_listener_func listener,
271 bt_graph_listener_removed_func listener_removed, void *data,
272 int *listener_id);
273
274extern bt_graph_status
275bt_graph_add_filter_sink_component_ports_connected_listener(
276 bt_graph *graph,
277 bt_graph_filter_sink_component_ports_connected_listener_func listener,
278 bt_graph_listener_removed_func listener_removed, void *data,
279 int *listener_id);
280
281extern bt_graph_status bt_graph_cancel(bt_graph *graph);
282
283/* Helper functions for Python */
284
285%{
286
287static void graph_listener_removed(void *py_callable)
288{
289 BT_ASSERT(py_callable);
290 Py_DECREF(py_callable);
291}
292
8cc56726 293static bt_graph_listener_status
6945df9a
SM
294port_added_listener(
295 const void *component,
296 swig_type_info *component_swig_type,
8cc56726 297 bt_component_class_type component_class_type,
6945df9a
SM
298 const void *port,
299 swig_type_info *port_swig_type,
300 bt_port_type port_type,
301 void *py_callable)
302{
303 PyObject *py_component_ptr = NULL;
304 PyObject *py_port_ptr = NULL;
305 PyObject *py_res = NULL;
5f25509b 306 bt_graph_listener_status status;
6945df9a
SM
307
308 py_component_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(component), component_swig_type, 0);
309 if (!py_component_ptr) {
310 BT_LOGF_STR("Failed to create component SWIG pointer object.");
5f25509b 311 status = BT_GRAPH_LISTENER_STATUS_NOMEM;
6945df9a
SM
312 goto end;
313 }
314
315 py_port_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(port), port_swig_type, 0);
316 if (!py_port_ptr) {
317 BT_LOGF_STR("Failed to create port SWIG pointer object.");
5f25509b 318 status = BT_GRAPH_LISTENER_STATUS_NOMEM;
6945df9a
SM
319 goto end;
320 }
321
322 py_res = PyObject_CallFunction(py_callable, "(OiOi)",
323 py_component_ptr, component_class_type, py_port_ptr, port_type);
324 if (!py_res) {
325 bt2_py_loge_exception();
326 PyErr_Clear();
5f25509b
SM
327 status = BT_GRAPH_LISTENER_STATUS_ERROR;
328 goto end;
6945df9a 329 }
e874da19 330
5f25509b
SM
331 BT_ASSERT(py_res == Py_None);
332 status = BT_GRAPH_LISTENER_STATUS_OK;
6945df9a
SM
333
334end:
335 Py_XDECREF(py_res);
336 Py_XDECREF(py_port_ptr);
337 Py_XDECREF(py_component_ptr);
8cc56726
SM
338
339 return status;
6945df9a
SM
340}
341
8cc56726 342static bt_graph_listener_status
6945df9a
SM
343source_component_output_port_added_listener(const bt_component_source *component_source,
344 const bt_port_output *port_output, void *py_callable)
345{
8cc56726 346 return port_added_listener(
6945df9a
SM
347 component_source, SWIGTYPE_p_bt_component_source, BT_COMPONENT_CLASS_TYPE_SOURCE,
348 port_output, SWIGTYPE_p_bt_port_output, BT_PORT_TYPE_OUTPUT, py_callable);
349}
350
8cc56726 351static bt_graph_listener_status
6945df9a
SM
352filter_component_input_port_added_listener(const bt_component_filter *component_filter,
353 const bt_port_input *port_input, void *py_callable)
354{
8cc56726 355 return port_added_listener(
6945df9a
SM
356 component_filter, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
357 port_input, SWIGTYPE_p_bt_port_input, BT_PORT_TYPE_INPUT, py_callable);
358}
359
8cc56726 360static bt_graph_listener_status
6945df9a
SM
361filter_component_output_port_added_listener(const bt_component_filter *component_filter,
362 const bt_port_output *port_output, void *py_callable)
363{
8cc56726 364 return port_added_listener(
6945df9a
SM
365 component_filter, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
366 port_output, SWIGTYPE_p_bt_port_output, BT_PORT_TYPE_OUTPUT, py_callable);
367}
368
8cc56726 369static bt_graph_listener_status
6945df9a
SM
370sink_component_input_port_added_listener(const bt_component_sink *component_sink,
371 const bt_port_input *port_input, void *py_callable)
372{
8cc56726 373 return port_added_listener(
6945df9a
SM
374 component_sink, SWIGTYPE_p_bt_component_sink, BT_COMPONENT_CLASS_TYPE_SINK,
375 port_input, SWIGTYPE_p_bt_port_input, BT_PORT_TYPE_INPUT, py_callable);
376}
377
378static PyObject *
379bt_py3_graph_add_port_added_listener(struct bt_graph *graph,
380 PyObject *py_callable)
381{
382 PyObject *py_listener_ids = NULL;
383 PyObject *py_listener_id = NULL;
384 int listener_id;
385 bt_graph_status status;
386
387 BT_ASSERT(graph);
388 BT_ASSERT(py_callable);
389
390 /*
391 * Behind the scene, we will be registering 4 different listeners and
392 * return all of their ids.
393 */
394 py_listener_ids = PyTuple_New(4);
395 if (!py_listener_ids) {
396 goto error;
397 }
398
399 /* source output port */
400 status = bt_graph_add_source_component_output_port_added_listener(
401 graph, source_component_output_port_added_listener,
402 graph_listener_removed, py_callable, &listener_id);
403 if (status != BT_GRAPH_STATUS_OK) {
404 goto error;
405 }
406
407 py_listener_id = PyLong_FromLong(listener_id);
408 if (!py_listener_id) {
409 goto error;
410 }
411
412 PyTuple_SET_ITEM(py_listener_ids, 0, py_listener_id);
413 py_listener_id = NULL;
414
415 /* filter input port */
416 status = bt_graph_add_filter_component_input_port_added_listener(
417 graph, filter_component_input_port_added_listener,
418 graph_listener_removed, py_callable, &listener_id);
419 if (status != BT_GRAPH_STATUS_OK) {
420 goto error;
421 }
422
423 py_listener_id = PyLong_FromLong(listener_id);
424 if (!py_listener_id) {
425 goto error;
426 }
427
428 PyTuple_SET_ITEM(py_listener_ids, 1, py_listener_id);
429 py_listener_id = NULL;
430
431 /* filter output port */
432 status = bt_graph_add_filter_component_output_port_added_listener(
433 graph, filter_component_output_port_added_listener,
434 graph_listener_removed, py_callable, &listener_id);
435 if (status != BT_GRAPH_STATUS_OK) {
436 goto error;
437 }
438
439 py_listener_id = PyLong_FromLong(listener_id);
440 if (!py_listener_id) {
441 goto error;
442 }
443
444 PyTuple_SET_ITEM(py_listener_ids, 2, py_listener_id);
445 py_listener_id = NULL;
446
447 /* sink input port */
448 status = bt_graph_add_sink_component_input_port_added_listener(
449 graph, sink_component_input_port_added_listener,
450 graph_listener_removed, py_callable, &listener_id);
451 if (status != BT_GRAPH_STATUS_OK) {
452 goto error;
453 }
454
455 py_listener_id = PyLong_FromLong(listener_id);
456 if (!py_listener_id) {
457 goto error;
458 }
459
460
461 PyTuple_SET_ITEM(py_listener_ids, 3, py_listener_id);
462 py_listener_id = NULL;
463
464 Py_INCREF(py_callable);
465 Py_INCREF(py_callable);
466 Py_INCREF(py_callable);
467 Py_INCREF(py_callable);
468
469 goto end;
470
471error:
472 Py_XDECREF(py_listener_ids);
473 py_listener_ids = Py_None;
474 Py_INCREF(py_listener_ids);
475
476end:
477
478 Py_XDECREF(py_listener_id);
479 return py_listener_ids;
480}
481
8cc56726 482static bt_graph_listener_status
5f25509b
SM
483ports_connected_listener(
484 const void *upstream_component,
485 swig_type_info *upstream_component_swig_type,
486 bt_component_class_type upstream_component_class_type,
487 const bt_port_output *upstream_port,
488 const void *downstream_component,
489 swig_type_info *downstream_component_swig_type,
490 bt_component_class_type downstream_component_class_type,
491 const bt_port_input *downstream_port,
492 void *py_callable)
6945df9a 493{
5f25509b 494 PyObject *py_upstream_component_ptr = NULL;
6945df9a 495 PyObject *py_upstream_port_ptr = NULL;
5f25509b 496 PyObject *py_downstream_component_ptr = NULL;
6945df9a
SM
497 PyObject *py_downstream_port_ptr = NULL;
498 PyObject *py_res = NULL;
5f25509b
SM
499 bt_graph_listener_status status;
500
501 py_upstream_component_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(upstream_component),
502 upstream_component_swig_type, 0);
503 if (!py_upstream_component_ptr) {
504 BT_LOGF_STR("Failed to create upstream component SWIG pointer object.");
505 status = BT_GRAPH_LISTENER_STATUS_NOMEM;
506 goto end;
507 }
6945df9a
SM
508
509 py_upstream_port_ptr = SWIG_NewPointerObj(
510 SWIG_as_voidptr(upstream_port), SWIGTYPE_p_bt_port_output, 0);
511 if (!py_upstream_port_ptr) {
5f25509b
SM
512 BT_LOGF_STR("Failed to create upstream port SWIG pointer object.");
513 status = BT_GRAPH_LISTENER_STATUS_NOMEM;
514 goto end;
515 }
e874da19 516
5f25509b
SM
517 py_downstream_component_ptr = SWIG_NewPointerObj(SWIG_as_voidptr(downstream_component),
518 downstream_component_swig_type, 0);
519 if (!py_downstream_component_ptr) {
520 BT_LOGF_STR("Failed to create downstream component SWIG pointer object.");
521 status = BT_GRAPH_LISTENER_STATUS_NOMEM;
522 goto end;
6945df9a
SM
523 }
524
525 py_downstream_port_ptr = SWIG_NewPointerObj(
526 SWIG_as_voidptr(downstream_port), SWIGTYPE_p_bt_port_input, 0);
527 if (!py_downstream_port_ptr) {
5f25509b
SM
528 BT_LOGF_STR("Failed to create downstream port SWIG pointer object.");
529 status = BT_GRAPH_LISTENER_STATUS_NOMEM;
530 goto end;
6945df9a
SM
531 }
532
5f25509b
SM
533 py_res = PyObject_CallFunction(py_callable, "(OiOOiO)",
534 py_upstream_component_ptr, upstream_component_class_type,
535 py_upstream_port_ptr,
536 py_downstream_component_ptr, downstream_component_class_type,
537 py_downstream_port_ptr);
6945df9a
SM
538 if (!py_res) {
539 bt2_py_loge_exception();
540 PyErr_Clear();
5f25509b
SM
541 status = BT_GRAPH_LISTENER_STATUS_ERROR;
542 goto end;
6945df9a 543 }
e874da19 544
5f25509b
SM
545 BT_ASSERT(py_res == Py_None);
546 status = BT_GRAPH_LISTENER_STATUS_OK;
6945df9a 547
5f25509b
SM
548end:
549 Py_XDECREF(py_upstream_component_ptr);
550 Py_XDECREF(py_upstream_port_ptr);
551 Py_XDECREF(py_downstream_component_ptr);
552 Py_XDECREF(py_downstream_port_ptr);
6945df9a 553 Py_XDECREF(py_res);
8cc56726
SM
554
555 return status;
6945df9a
SM
556}
557
8cc56726 558static bt_graph_listener_status
6945df9a
SM
559source_filter_component_ports_connected_listener(
560 const bt_component_source *source_component,
561 const bt_component_filter *filter_component,
562 const bt_port_output *upstream_port,
563 const bt_port_input *downstream_port, void *py_callable)
564{
5f25509b
SM
565 return ports_connected_listener(
566 source_component, SWIGTYPE_p_bt_component_source, BT_COMPONENT_CLASS_TYPE_SOURCE,
567 upstream_port,
568 filter_component, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
569 downstream_port,
570 py_callable);
6945df9a
SM
571}
572
8cc56726 573static bt_graph_listener_status
6945df9a
SM
574source_sink_component_ports_connected_listener(
575 const bt_component_source *source_component,
576 const bt_component_sink *sink_component,
577 const bt_port_output *upstream_port,
578 const bt_port_input *downstream_port, void *py_callable)
579{
5f25509b
SM
580 return ports_connected_listener(
581 source_component, SWIGTYPE_p_bt_component_source, BT_COMPONENT_CLASS_TYPE_SOURCE,
582 upstream_port,
583 sink_component, SWIGTYPE_p_bt_component_sink, BT_COMPONENT_CLASS_TYPE_SINK,
584 downstream_port,
585 py_callable);
6945df9a
SM
586}
587
8cc56726 588static bt_graph_listener_status
6945df9a
SM
589filter_filter_component_ports_connected_listener(
590 const bt_component_filter *filter_component_left,
591 const bt_component_filter *filter_component_right,
592 const bt_port_output *upstream_port,
593 const bt_port_input *downstream_port, void *py_callable)
594{
5f25509b
SM
595 return ports_connected_listener(
596 filter_component_left, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
597 upstream_port,
598 filter_component_right, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
599 downstream_port,
600 py_callable);
6945df9a
SM
601}
602
8cc56726 603static bt_graph_listener_status
6945df9a
SM
604filter_sink_component_ports_connected_listener(
605 const bt_component_filter *filter_component,
606 const bt_component_sink *sink_component,
607 const bt_port_output *upstream_port,
608 const bt_port_input *downstream_port, void *py_callable)
609{
5f25509b
SM
610 return ports_connected_listener(
611 filter_component, SWIGTYPE_p_bt_component_filter, BT_COMPONENT_CLASS_TYPE_FILTER,
612 upstream_port,
613 sink_component, SWIGTYPE_p_bt_component_sink, BT_COMPONENT_CLASS_TYPE_SINK,
614 downstream_port,
615 py_callable);
6945df9a
SM
616}
617
6945df9a
SM
618static PyObject*
619bt_py3_graph_add_ports_connected_listener(struct bt_graph *graph,
620 PyObject *py_callable)
621{
622 PyObject *py_listener_ids = NULL;
623 PyObject *py_listener_id = NULL;
624 int listener_id;
625 bt_graph_status status;
626
627 BT_ASSERT(graph);
628 BT_ASSERT(py_callable);
629
630 /* Behind the scene, we will be registering 4 different listeners and
631 * return all of their ids. */
632 py_listener_ids = PyTuple_New(4);
633 if (!py_listener_ids) {
634 goto error;
635 }
636
637 /* source -> filter connection */
638 status = bt_graph_add_source_filter_component_ports_connected_listener(
639 graph, source_filter_component_ports_connected_listener,
640 graph_listener_removed, py_callable, &listener_id);
641 if (status != BT_GRAPH_STATUS_OK) {
642 goto error;
643 }
644
645 py_listener_id = PyLong_FromLong(listener_id);
646 if (!py_listener_id) {
647 goto error;
648 }
649
650 PyTuple_SET_ITEM(py_listener_ids, 0, py_listener_id);
651 py_listener_id = NULL;
652
653 /* source -> sink connection */
654 status = bt_graph_add_source_sink_component_ports_connected_listener(
655 graph, source_sink_component_ports_connected_listener,
656 graph_listener_removed, py_callable, &listener_id);
657 if (status != BT_GRAPH_STATUS_OK) {
658 goto error;
659 }
660
661 py_listener_id = PyLong_FromLong(listener_id);
662 if (!py_listener_id) {
663 goto error;
664 }
665
666 PyTuple_SET_ITEM(py_listener_ids, 1, py_listener_id);
667 py_listener_id = NULL;
668
669 /* filter -> filter connection */
670 status = bt_graph_add_filter_filter_component_ports_connected_listener(
671 graph, filter_filter_component_ports_connected_listener,
672 graph_listener_removed, py_callable, &listener_id);
673 if (status != BT_GRAPH_STATUS_OK) {
674 goto error;
675 }
676
677 py_listener_id = PyLong_FromLong(listener_id);
678 if (!py_listener_id) {
679 goto error;
680 }
681
682 PyTuple_SET_ITEM(py_listener_ids, 2, py_listener_id);
683 py_listener_id = NULL;
684
685 /* filter -> sink connection */
686 status = bt_graph_add_filter_sink_component_ports_connected_listener(
687 graph, filter_sink_component_ports_connected_listener,
688 graph_listener_removed, py_callable, &listener_id);
689 if (status != BT_GRAPH_STATUS_OK) {
690 goto error;
691 }
692
693 py_listener_id = PyLong_FromLong(listener_id);
694 if (!py_listener_id) {
695 goto error;
696 }
697
698 PyTuple_SET_ITEM(py_listener_ids, 3, py_listener_id);
699 py_listener_id = NULL;
700
701 Py_INCREF(py_callable);
702 Py_INCREF(py_callable);
703 Py_INCREF(py_callable);
704 Py_INCREF(py_callable);
705
706 goto end;
707
708error:
709 Py_XDECREF(py_listener_ids);
710 py_listener_ids = Py_None;
711 Py_INCREF(py_listener_ids);
712
713end:
714
715 Py_XDECREF(py_listener_id);
716 return py_listener_ids;
717}
718
719%}
720
721PyObject *bt_py3_graph_add_port_added_listener(struct bt_graph *graph,
722 PyObject *py_callable);
723PyObject *bt_py3_graph_add_ports_connected_listener(struct bt_graph *graph,
724 PyObject *py_callable);
This page took 0.056395 seconds and 4 git commands to generate.