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