lib: add pre condition asserts to check current thread has no error
[babeltrace.git] / src / lib / graph / graph.c
CommitLineData
c0418dd9 1/*
f2b0325d 2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
f60c8b34 3 * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
c0418dd9
JG
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
b03487ab 24#define BT_LOG_TAG "LIB/GRAPH"
1633ef46 25#include "lib/logging.h"
262e5473 26
57952005
MJ
27#include "common/assert.h"
28#include "lib/assert-pre.h"
3b7d3ccc 29#include "lib/assert-post.h"
71c5da58
MJ
30#include <babeltrace2/graph/graph.h>
31#include <babeltrace2/graph/graph-const.h>
71c5da58
MJ
32#include <babeltrace2/graph/component-source-const.h>
33#include <babeltrace2/graph/component-filter-const.h>
34#include <babeltrace2/graph/port-const.h>
57952005
MJ
35#include "lib/graph/message/message.h"
36#include "compat/compiler.h"
37#include "common/common.h"
71c5da58
MJ
38#include <babeltrace2/types.h>
39#include <babeltrace2/value.h>
40#include <babeltrace2/value-const.h>
57952005 41#include "lib/value.h"
f60c8b34 42#include <unistd.h>
969c1d8a 43#include <stdbool.h>
1bf957a0
PP
44#include <glib.h>
45
5efafa1a 46#include "component-class-sink-simple.h"
57952005
MJ
47#include "component.h"
48#include "component-sink.h"
49#include "connection.h"
50#include "graph.h"
d73bb381 51#include "interrupter.h"
57952005
MJ
52#include "message/event.h"
53#include "message/packet.h"
54
fb25b9e3
PP
55typedef enum bt_graph_listener_func_status
56(*port_added_func_t)(const void *, const void *, void *);
7b53201c 57
fb25b9e3
PP
58typedef enum bt_graph_listener_func_status
59(*ports_connected_func_t)(const void *, const void *, const void *,
7b53201c 60 const void *, void *);
834e9996 61
4175c1d5 62typedef enum bt_component_class_initialize_method_status
e3250e61 63(*comp_init_method_t)(const void *, void *, const void *, void *);
fb25b9e3 64
1bf957a0 65struct bt_graph_listener {
7b53201c 66 bt_graph_listener_removed_func removed;
1bf957a0
PP
67 void *data;
68};
c0418dd9 69
834e9996
PP
70struct bt_graph_listener_port_added {
71 struct bt_graph_listener base;
72 port_added_func_t func;
73};
eb87cce7 74
834e9996
PP
75struct bt_graph_listener_ports_connected {
76 struct bt_graph_listener base;
77 ports_connected_func_t func;
78};
eb87cce7 79
834e9996
PP
80#define INIT_LISTENERS_ARRAY(_type, _listeners) \
81 do { \
82 _listeners = g_array_new(FALSE, TRUE, sizeof(_type)); \
83 if (!(_listeners)) { \
a8f90e5d
PP
84 BT_LIB_LOGE_APPEND_CAUSE( \
85 "Failed to allocate one GArray."); \
834e9996
PP
86 } \
87 } while (0)
88
89#define CALL_REMOVE_LISTENERS(_type, _listeners) \
90 do { \
91 size_t i; \
92 \
8a62a380
FD
93 if (!_listeners) { \
94 break; \
95 } \
834e9996
PP
96 for (i = 0; i < (_listeners)->len; i++) { \
97 _type *listener = \
98 &g_array_index((_listeners), _type, i); \
99 \
100 if (listener->base.removed) { \
101 listener->base.removed(listener->base.data); \
102 } \
103 } \
104 } while (0)
eb87cce7 105
f60c8b34 106static
834e9996 107void destroy_graph(struct bt_object *obj)
c0418dd9 108{
7b53201c 109 struct bt_graph *graph = container_of(obj, struct bt_graph, base);
c0418dd9 110
bd14d768
PP
111 /*
112 * The graph's reference count is 0 if we're here. Increment
113 * it to avoid a double-destroy (possibly infinitely recursive)
114 * in this situation:
115 *
116 * 1. We put and destroy a connection.
904860cb
PP
117 * 2. This connection's destructor finalizes its active message
118 * iterators.
119 * 3. A message iterator's finalization function gets a new
120 * reference on its component (reference count goes from 0 to
121 * 1).
bd14d768
PP
122 * 4. Since this component's reference count goes to 1, it takes
123 * a reference on its parent (this graph). This graph's
124 * reference count goes from 0 to 1.
b09a5592 125 * 5. The message iterator's finalization function puts its
bd14d768
PP
126 * component reference (reference count goes from 1 to 0).
127 * 6. Since this component's reference count goes from 1 to 0,
128 * it puts its parent (this graph). This graph's reference
129 * count goes from 1 to 0.
904860cb
PP
130 * 7. Since this graph's reference count goes from 1 to 0, its
131 * destructor is called (this function).
bd14d768
PP
132 *
133 * With the incrementation below, the graph's reference count at
134 * step 4 goes from 1 to 2, and from 2 to 1 at step 6. This
135 * ensures that this function is not called two times.
136 */
a684a357 137 BT_LIB_LOGI("Destroying graph: %!+g", graph);
1d7bf349 138 obj->ref_count++;
d73bb381 139 graph->config_state = BT_GRAPH_CONFIGURATION_STATE_DESTROYING;
49682acd 140
eb87cce7 141 /* Call all remove listeners */
834e9996
PP
142 CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_added,
143 graph->listeners.source_output_port_added);
144 CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_added,
145 graph->listeners.filter_output_port_added);
146 CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_added,
147 graph->listeners.filter_input_port_added);
148 CALL_REMOVE_LISTENERS(struct bt_graph_listener_port_added,
149 graph->listeners.sink_input_port_added);
834e9996
PP
150 CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_connected,
151 graph->listeners.source_filter_ports_connected);
ee976410
PP
152 CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_connected,
153 graph->listeners.filter_filter_ports_connected);
834e9996
PP
154 CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_connected,
155 graph->listeners.source_sink_ports_connected);
156 CALL_REMOVE_LISTENERS(struct bt_graph_listener_ports_connected,
157 graph->listeners.filter_sink_ports_connected);
eb87cce7 158
b09a5592
PP
159 if (graph->messages) {
160 g_ptr_array_free(graph->messages, TRUE);
161 graph->messages = NULL;
f7c3ac09
PP
162 }
163
c0418dd9 164 if (graph->connections) {
262e5473 165 BT_LOGD_STR("Destroying connections.");
c0418dd9 166 g_ptr_array_free(graph->connections, TRUE);
834e9996 167 graph->connections = NULL;
c0418dd9 168 }
f7c3ac09 169
bd14d768 170 if (graph->components) {
262e5473 171 BT_LOGD_STR("Destroying components.");
bd14d768 172 g_ptr_array_free(graph->components, TRUE);
834e9996 173 graph->components = NULL;
bd14d768 174 }
f7c3ac09 175
d73bb381
PP
176 if (graph->interrupters) {
177 BT_LOGD_STR("Putting interrupters.");
178 g_ptr_array_free(graph->interrupters, TRUE);
179 graph->interrupters = NULL;
180 }
181
182 BT_OBJECT_PUT_REF_AND_RESET(graph->default_interrupter);
183
f60c8b34
JG
184 if (graph->sinks_to_consume) {
185 g_queue_free(graph->sinks_to_consume);
834e9996
PP
186 graph->sinks_to_consume = NULL;
187 }
188
189 if (graph->listeners.source_output_port_added) {
190 g_array_free(graph->listeners.source_output_port_added, TRUE);
191 graph->listeners.source_output_port_added = NULL;
192 }
193
194 if (graph->listeners.filter_output_port_added) {
195 g_array_free(graph->listeners.filter_output_port_added, TRUE);
196 graph->listeners.filter_output_port_added = NULL;
197 }
198
199 if (graph->listeners.filter_input_port_added) {
200 g_array_free(graph->listeners.filter_input_port_added, TRUE);
201 graph->listeners.filter_input_port_added = NULL;
c0418dd9 202 }
1bf957a0 203
834e9996
PP
204 if (graph->listeners.sink_input_port_added) {
205 g_array_free(graph->listeners.sink_input_port_added, TRUE);
206 graph->listeners.sink_input_port_added = NULL;
1bf957a0
PP
207 }
208
834e9996
PP
209 if (graph->listeners.source_filter_ports_connected) {
210 g_array_free(graph->listeners.source_filter_ports_connected,
211 TRUE);
212 graph->listeners.source_filter_ports_connected = NULL;
213 }
214
ee976410
PP
215 if (graph->listeners.filter_filter_ports_connected) {
216 g_array_free(graph->listeners.filter_filter_ports_connected,
217 TRUE);
218 graph->listeners.filter_filter_ports_connected = NULL;
219 }
220
834e9996
PP
221 if (graph->listeners.source_sink_ports_connected) {
222 g_array_free(graph->listeners.source_sink_ports_connected,
223 TRUE);
224 graph->listeners.source_sink_ports_connected = NULL;
225 }
226
227 if (graph->listeners.filter_sink_ports_connected) {
228 g_array_free(graph->listeners.filter_sink_ports_connected,
229 TRUE);
230 graph->listeners.filter_sink_ports_connected = NULL;
231 }
232
b09a5592
PP
233 bt_object_pool_finalize(&graph->event_msg_pool);
234 bt_object_pool_finalize(&graph->packet_begin_msg_pool);
235 bt_object_pool_finalize(&graph->packet_end_msg_pool);
c0418dd9
JG
236 g_free(graph);
237}
238
f7c3ac09 239static
b09a5592 240void destroy_message_event(struct bt_message *msg,
f7c3ac09
PP
241 struct bt_graph *graph)
242{
b09a5592 243 bt_message_event_destroy(msg);
f7c3ac09
PP
244}
245
246static
b09a5592 247void destroy_message_packet_begin(struct bt_message *msg,
f7c3ac09
PP
248 struct bt_graph *graph)
249{
a1f053a9 250 bt_message_packet_destroy(msg);
f7c3ac09
PP
251}
252
253static
b09a5592 254void destroy_message_packet_end(struct bt_message *msg,
f7c3ac09
PP
255 struct bt_graph *graph)
256{
a1f053a9 257 bt_message_packet_destroy(msg);
f7c3ac09
PP
258}
259
260static
b09a5592 261void notify_message_graph_is_destroyed(struct bt_message *msg)
f7c3ac09 262{
b09a5592 263 bt_message_unlink_graph(msg);
f7c3ac09
PP
264}
265
253a9ecc 266struct bt_graph *bt_graph_create(uint64_t mip_version)
c0418dd9 267{
f60c8b34 268 struct bt_graph *graph;
1bf957a0 269 int ret;
c0418dd9 270
7c7324d3 271 BT_ASSERT_PRE_NO_ERROR();
253a9ecc
PP
272 BT_ASSERT_PRE(mip_version <= bt_get_maximal_mip_version(),
273 "Unknown MIP version: mip-version=%" PRIu64 ", "
274 "max-mip-version=%" PRIu64,
275 mip_version, bt_get_maximal_mip_version());
a684a357 276 BT_LOGI_STR("Creating graph object.");
f60c8b34 277 graph = g_new0(struct bt_graph, 1);
c0418dd9 278 if (!graph) {
a8f90e5d 279 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one graph.");
c0418dd9
JG
280 goto end;
281 }
282
834e9996 283 bt_object_init_shared(&graph->base, destroy_graph);
253a9ecc 284 graph->mip_version = mip_version;
1d7bf349
PP
285 graph->connections = g_ptr_array_new_with_free_func(
286 (GDestroyNotify) bt_object_try_spec_release);
c0418dd9 287 if (!graph->connections) {
a8f90e5d 288 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
c0418dd9
JG
289 goto error;
290 }
1d7bf349
PP
291 graph->components = g_ptr_array_new_with_free_func(
292 (GDestroyNotify) bt_object_try_spec_release);
f60c8b34 293 if (!graph->components) {
a8f90e5d 294 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
f60c8b34
JG
295 goto error;
296 }
297 graph->sinks_to_consume = g_queue_new();
298 if (!graph->sinks_to_consume) {
a8f90e5d 299 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GQueue.");
c0418dd9
JG
300 goto error;
301 }
1bf957a0 302
834e9996
PP
303 bt_graph_set_can_consume(graph, true);
304 INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_added,
305 graph->listeners.source_output_port_added);
306
307 if (!graph->listeners.source_output_port_added) {
1bf957a0
PP
308 goto error;
309 }
310
834e9996
PP
311 INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_added,
312 graph->listeners.filter_output_port_added);
313
314 if (!graph->listeners.filter_output_port_added) {
1bf957a0
PP
315 goto error;
316 }
317
834e9996
PP
318 INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_added,
319 graph->listeners.filter_input_port_added);
320
321 if (!graph->listeners.filter_input_port_added) {
1bf957a0
PP
322 goto error;
323 }
324
834e9996
PP
325 INIT_LISTENERS_ARRAY(struct bt_graph_listener_port_added,
326 graph->listeners.sink_input_port_added);
327
328 if (!graph->listeners.sink_input_port_added) {
834e9996
PP
329 goto error;
330 }
331
834e9996
PP
332 INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_connected,
333 graph->listeners.source_filter_ports_connected);
334
335 if (!graph->listeners.source_filter_ports_connected) {
834e9996
PP
336 goto error;
337 }
338
339 INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_connected,
340 graph->listeners.source_sink_ports_connected);
341
342 if (!graph->listeners.source_sink_ports_connected) {
834e9996
PP
343 goto error;
344 }
345
ee976410
PP
346 INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_connected,
347 graph->listeners.filter_filter_ports_connected);
348
349 if (!graph->listeners.filter_filter_ports_connected) {
ee976410
PP
350 goto error;
351 }
352
834e9996
PP
353 INIT_LISTENERS_ARRAY(struct bt_graph_listener_ports_connected,
354 graph->listeners.filter_sink_ports_connected);
355
356 if (!graph->listeners.filter_sink_ports_connected) {
834e9996
PP
357 goto error;
358 }
359
d73bb381 360 graph->interrupters = g_ptr_array_new_with_free_func(
864aa43f 361 (GDestroyNotify) bt_object_put_ref_no_null_check);
d73bb381
PP
362 if (!graph->interrupters) {
363 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
364 goto error;
365 }
366
367 graph->default_interrupter = bt_interrupter_create();
368 if (!graph->default_interrupter) {
369 BT_LIB_LOGE_APPEND_CAUSE(
370 "Failed to create one interrupter object.");
371 goto error;
372 }
373
374 bt_graph_add_interrupter(graph, graph->default_interrupter);
b09a5592
PP
375 ret = bt_object_pool_initialize(&graph->event_msg_pool,
376 (bt_object_pool_new_object_func) bt_message_event_new,
377 (bt_object_pool_destroy_object_func) destroy_message_event,
f7c3ac09
PP
378 graph);
379 if (ret) {
a8f90e5d
PP
380 BT_LIB_LOGE_APPEND_CAUSE(
381 "Failed to initialize event message pool: ret=%d",
f7c3ac09
PP
382 ret);
383 goto error;
384 }
385
b09a5592
PP
386 ret = bt_object_pool_initialize(&graph->packet_begin_msg_pool,
387 (bt_object_pool_new_object_func) bt_message_packet_beginning_new,
388 (bt_object_pool_destroy_object_func) destroy_message_packet_begin,
f7c3ac09
PP
389 graph);
390 if (ret) {
a8f90e5d
PP
391 BT_LIB_LOGE_APPEND_CAUSE(
392 "Failed to initialize packet beginning message pool: ret=%d",
f7c3ac09
PP
393 ret);
394 goto error;
395 }
396
b09a5592
PP
397 ret = bt_object_pool_initialize(&graph->packet_end_msg_pool,
398 (bt_object_pool_new_object_func) bt_message_packet_end_new,
399 (bt_object_pool_destroy_object_func) destroy_message_packet_end,
f7c3ac09
PP
400 graph);
401 if (ret) {
a8f90e5d
PP
402 BT_LIB_LOGE_APPEND_CAUSE(
403 "Failed to initialize packet end message pool: ret=%d",
f7c3ac09
PP
404 ret);
405 goto error;
406 }
407
b09a5592
PP
408 graph->messages = g_ptr_array_new_with_free_func(
409 (GDestroyNotify) notify_message_graph_is_destroyed);
a684a357 410 BT_LIB_LOGI("Created graph object: %!+g", graph);
262e5473 411
c0418dd9 412end:
8d750b42 413 return (void *) graph;
834e9996 414
c0418dd9 415error:
8138bfe1 416 BT_OBJECT_PUT_REF_AND_RESET(graph);
c0418dd9
JG
417 goto end;
418}
419
fb25b9e3 420enum bt_graph_connect_ports_status bt_graph_connect_ports(
7b53201c
PP
421 struct bt_graph *graph,
422 const struct bt_port_output *upstream_port_out,
423 const struct bt_port_input *downstream_port_in,
424 const struct bt_connection **user_connection)
f60c8b34 425{
fb25b9e3
PP
426 enum bt_graph_connect_ports_status status = BT_FUNC_STATUS_OK;
427 enum bt_graph_listener_func_status listener_status;
f60c8b34 428 struct bt_connection *connection = NULL;
834e9996
PP
429 struct bt_port *upstream_port = (void *) upstream_port_out;
430 struct bt_port *downstream_port = (void *) downstream_port_in;
f60c8b34
JG
431 struct bt_component *upstream_component = NULL;
432 struct bt_component *downstream_component = NULL;
fb25b9e3 433 enum bt_component_class_port_connected_method_status port_connected_status;
834e9996 434 bool init_can_consume;
f60c8b34 435
7c7324d3 436 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
437 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
438 BT_ASSERT_PRE_NON_NULL(upstream_port, "Upstream port");
439 BT_ASSERT_PRE_NON_NULL(downstream_port, "Downstream port port");
1043fdea
PP
440 BT_ASSERT_PRE(
441 graph->config_state == BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
9a84962b 442 "Graph is not in the \"configuring\" state: %!+g", graph);
834e9996
PP
443 BT_ASSERT_PRE(!bt_port_is_connected(upstream_port),
444 "Upstream port is already connected: %!+p", upstream_port);
445 BT_ASSERT_PRE(!bt_port_is_connected(downstream_port),
446 "Downstream port is already connected: %!+p", downstream_port);
7b53201c 447 BT_ASSERT_PRE(bt_port_borrow_component_inline((void *) upstream_port),
834e9996
PP
448 "Upstream port does not belong to a component: %!+p",
449 upstream_port);
7b53201c 450 BT_ASSERT_PRE(bt_port_borrow_component_inline((void *) downstream_port),
834e9996
PP
451 "Downstream port does not belong to a component: %!+p",
452 downstream_port);
3afb93ee 453 init_can_consume = graph->can_consume;
a684a357 454 BT_LIB_LOGI("Connecting component ports within graph: "
834e9996
PP
455 "%![graph-]+g, %![up-port-]+p, %![down-port-]+p",
456 graph, upstream_port, downstream_port);
457 bt_graph_set_can_consume(graph, false);
7b53201c 458 upstream_component = bt_port_borrow_component_inline(
834e9996 459 (void *) upstream_port);
7b53201c 460 downstream_component = bt_port_borrow_component_inline(
834e9996 461 (void *) downstream_port);
262e5473 462
262e5473 463 BT_LOGD_STR("Creating connection.");
834e9996
PP
464 connection = bt_connection_create(graph, (void *) upstream_port,
465 (void *) downstream_port);
f60c8b34 466 if (!connection) {
a8f90e5d 467 BT_LIB_LOGE_APPEND_CAUSE("Cannot create connection object.");
fb25b9e3 468 status = BT_FUNC_STATUS_MEMORY_ERROR;
a256a42d 469 goto end;
f60c8b34
JG
470 }
471
834e9996 472 BT_LIB_LOGD("Connection object created: %!+x", connection);
262e5473 473
f60c8b34 474 /*
72b913fb
PP
475 * Ownership of upstream_component/downstream_component and of
476 * the connection object is transferred to the graph.
f60c8b34
JG
477 */
478 g_ptr_array_add(graph->connections, connection);
ffeb0eed 479
f60c8b34 480 /*
0d8b4d8e 481 * Notify both components that their port is connected.
f60c8b34 482 */
834e9996
PP
483 BT_LIB_LOGD("Notifying upstream component that its port is connected: "
484 "%![comp-]+c, %![port-]+p", upstream_component, upstream_port);
fb25b9e3 485 port_connected_status = bt_component_port_connected(upstream_component,
834e9996 486 (void *) upstream_port, (void *) downstream_port);
fb25b9e3 487 if (port_connected_status != BT_FUNC_STATUS_OK) {
a8f90e5d
PP
488 if (port_connected_status < 0) {
489 BT_LIB_LOGW_APPEND_CAUSE(
490 "Upstream component's \"port connected\" method failed: "
491 "status=%s, %![graph-]+g, %![up-comp-]+c, "
492 "%![down-comp-]+c, %![up-port-]+p, %![down-port-]+p",
493 bt_common_func_status_string(
494 port_connected_status),
495 graph, upstream_component, downstream_component,
496 upstream_port, downstream_port);
497 }
498
634f394c 499 bt_connection_end(connection, true);
fb25b9e3 500 status = (int) port_connected_status;
634f394c
PP
501 goto end;
502 }
503
0f15970b 504 connection->notified_upstream_port_connected = true;
834e9996
PP
505 BT_LIB_LOGD("Notifying downstream component that its port is connected: "
506 "%![comp-]+c, %![port-]+p", downstream_component,
507 downstream_port);
fb25b9e3 508 port_connected_status = bt_component_port_connected(downstream_component,
834e9996 509 (void *) downstream_port, (void *) upstream_port);
fb25b9e3 510 if (port_connected_status != BT_FUNC_STATUS_OK) {
a8f90e5d
PP
511 if (port_connected_status < 0) {
512 BT_LIB_LOGW_APPEND_CAUSE(
513 "Downstream component's \"port connected\" method failed: "
514 "status=%s, %![graph-]+g, %![up-comp-]+c, "
515 "%![down-comp-]+c, %![up-port-]+p, %![down-port-]+p",
516 bt_common_func_status_string(
517 port_connected_status),
518 graph, upstream_component, downstream_component,
519 upstream_port, downstream_port);
520 }
521
634f394c 522 bt_connection_end(connection, true);
fb25b9e3 523 status = (int) port_connected_status;
634f394c
PP
524 goto end;
525 }
526
0f15970b 527 connection->notified_downstream_port_connected = true;
1bf957a0
PP
528
529 /*
0d8b4d8e 530 * Notify the graph's creator that both ports are connected.
1bf957a0 531 */
262e5473 532 BT_LOGD_STR("Notifying graph's user that new component ports are connected.");
e18f3e2b 533 listener_status = bt_graph_notify_ports_connected(graph, upstream_port, downstream_port);
fb25b9e3 534 if (listener_status != BT_FUNC_STATUS_OK) {
a8f90e5d
PP
535 if (listener_status < 0) {
536 BT_LIB_LOGW_APPEND_CAUSE(
537 "Graph \"ports connected\" listener failed: "
538 "status=%d, %![graph-]+g, %![up-comp-]+c, "
539 "%![down-comp-]+c, %![up-port-]+p, %![down-port-]+p",
540 listener_status, graph,
541 upstream_component, downstream_component,
542 upstream_port, downstream_port);
543 }
544
e18f3e2b
SM
545 status = (int) listener_status;
546 goto end;
547 }
548
0f15970b 549 connection->notified_graph_ports_connected = true;
a684a357 550 BT_LIB_LOGI("Connected component ports within graph: "
834e9996
PP
551 "%![graph-]+g, %![up-comp-]+c, %![down-comp-]+c, "
552 "%![up-port-]+p, %![down-port-]+p",
553 graph, upstream_component, downstream_component,
554 upstream_port, downstream_port);
1bf957a0 555
a256a42d 556 if (user_connection) {
1a6a376a
PP
557 /* Move reference to user */
558 *user_connection = connection;
559 connection = NULL;
a256a42d
PP
560 }
561
f60c8b34 562end:
fb25b9e3 563 if (status != BT_FUNC_STATUS_OK) {
e18f3e2b 564 bt_graph_make_faulty(graph);
9a84962b
PP
565 }
566
8138bfe1 567 bt_object_put_ref(connection);
834e9996
PP
568 (void) init_can_consume;
569 bt_graph_set_can_consume(graph, init_can_consume);
a256a42d 570 return status;
f60c8b34
JG
571}
572
371361a1 573static inline
fb25b9e3 574int consume_graph_sink(struct bt_component_sink *comp)
c0418dd9 575{
fb25b9e3 576 enum bt_component_class_sink_consume_method_status consume_status;
834e9996
PP
577 struct bt_component_class_sink *sink_class = NULL;
578
ec4a3354 579 BT_ASSERT_DBG(comp);
834e9996 580 sink_class = (void *) comp->parent.class;
ec4a3354 581 BT_ASSERT_DBG(sink_class->methods.consume);
834e9996 582 BT_LIB_LOGD("Calling user's consume method: %!+c", comp);
fb25b9e3 583 consume_status = sink_class->methods.consume((void *) comp);
834e9996 584 BT_LOGD("User method returned: status=%s",
fb25b9e3 585 bt_common_func_status_string(consume_status));
fa6cfec3 586 BT_ASSERT_POST_DEV(consume_status == BT_FUNC_STATUS_OK ||
fb25b9e3
PP
587 consume_status == BT_FUNC_STATUS_END ||
588 consume_status == BT_FUNC_STATUS_AGAIN ||
589 consume_status == BT_FUNC_STATUS_ERROR ||
590 consume_status == BT_FUNC_STATUS_MEMORY_ERROR,
834e9996 591 "Invalid component status returned by consuming method: "
fb25b9e3 592 "status=%s", bt_common_func_status_string(consume_status));
d6f6a5aa 593 BT_ASSERT_POST_DEV_NO_ERROR_IF_NO_ERROR_STATUS(consume_status);
a8f90e5d
PP
594 if (consume_status) {
595 if (consume_status < 0) {
596 BT_LIB_LOGW_APPEND_CAUSE(
597 "Component's \"consume\" method failed: "
598 "status=%s, %![comp-]+c",
599 bt_common_func_status_string(consume_status),
600 comp);
601 }
602
834e9996
PP
603 goto end;
604 }
605
a684a357 606 BT_LIB_LOGD("Consumed from sink: %![comp-]+c, status=%s",
fb25b9e3 607 comp, bt_common_func_status_string(consume_status));
834e9996
PP
608
609end:
fb25b9e3 610 return consume_status;
c3ac0193
PP
611}
612
613/*
614 * `node` is removed from the queue of sinks to consume when passed to
615 * this function. This function adds it back to the queue if there's
616 * still something to consume afterwards.
617 */
371361a1 618static inline
fb25b9e3 619int consume_sink_node(struct bt_graph *graph, GList *node)
c3ac0193 620{
fb25b9e3 621 int status;
834e9996 622 struct bt_component_sink *sink;
c3ac0193
PP
623
624 sink = node->data;
625 status = consume_graph_sink(sink);
fb25b9e3 626 if (G_UNLIKELY(status != BT_FUNC_STATUS_END)) {
c3ac0193 627 g_queue_push_tail_link(graph->sinks_to_consume, node);
f60c8b34
JG
628 goto end;
629 }
630
631 /* End reached, the node is not added back to the queue and free'd. */
c3ac0193 632 g_queue_delete_link(graph->sinks_to_consume, node);
f60c8b34
JG
633
634 /* Don't forward an END status if there are sinks left to consume. */
635 if (!g_queue_is_empty(graph->sinks_to_consume)) {
fb25b9e3 636 status = BT_FUNC_STATUS_OK;
f60c8b34
JG
637 goto end;
638 }
c3ac0193
PP
639
640end:
a684a357 641 BT_LIB_LOGD("Consumed sink node: %![comp-]+c, status=%s",
fb25b9e3 642 sink, bt_common_func_status_string(status));
c3ac0193
PP
643 return status;
644}
645
646BT_HIDDEN
fb25b9e3 647int bt_graph_consume_sink_no_check(struct bt_graph *graph,
834e9996 648 struct bt_component_sink *sink)
c3ac0193 649{
fb25b9e3 650 int status;
c3ac0193
PP
651 GList *sink_node;
652 int index;
653
a684a357 654 BT_LIB_LOGD("Making specific sink consume: %![comp-]+c", sink);
ec4a3354 655 BT_ASSERT_DBG(bt_component_borrow_graph((void *) sink) == graph);
c3ac0193
PP
656
657 if (g_queue_is_empty(graph->sinks_to_consume)) {
a684a357 658 BT_LOGD_STR("Graph's sink queue is empty: end of graph.");
fb25b9e3 659 status = BT_FUNC_STATUS_END;
c3ac0193
PP
660 goto end;
661 }
662
663 index = g_queue_index(graph->sinks_to_consume, sink);
664 if (index < 0) {
a684a357
PP
665 BT_LIB_LOGD("Sink component is not marked as consumable: "
666 "component sink is ended: %![comp-]+c", sink);
fb25b9e3 667 status = BT_FUNC_STATUS_END;
c3ac0193
PP
668 goto end;
669 }
670
671 sink_node = g_queue_pop_nth_link(graph->sinks_to_consume, index);
ec4a3354 672 BT_ASSERT_DBG(sink_node);
c3ac0193
PP
673 status = consume_sink_node(graph, sink_node);
674
675end:
676 return status;
677}
678
371361a1 679static inline
fb25b9e3 680int consume_no_check(struct bt_graph *graph)
c3ac0193 681{
fb25b9e3 682 int status = BT_FUNC_STATUS_OK;
c3ac0193
PP
683 struct bt_component *sink;
684 GList *current_node;
685
fa6cfec3 686 BT_ASSERT_PRE_DEV(graph->has_sink,
8b45963b 687 "Graph has no sink component: %!+g", graph);
a684a357 688 BT_LIB_LOGD("Making next sink component consume: %![graph-]+g", graph);
c3ac0193 689
85e7137b 690 if (G_UNLIKELY(g_queue_is_empty(graph->sinks_to_consume))) {
a684a357 691 BT_LOGD_STR("Graph's sink queue is empty: end of graph.");
fb25b9e3 692 status = BT_FUNC_STATUS_END;
c3ac0193
PP
693 goto end;
694 }
695
696 current_node = g_queue_pop_head_link(graph->sinks_to_consume);
697 sink = current_node->data;
a684a357 698 BT_LIB_LOGD("Chose next sink to consume: %!+c", sink);
c3ac0193
PP
699 status = consume_sink_node(graph, current_node);
700
f60c8b34
JG
701end:
702 return status;
c0418dd9
JG
703}
704
e023d253 705enum bt_graph_run_once_status bt_graph_run_once(struct bt_graph *graph)
851b70bd 706{
e023d253 707 enum bt_graph_run_once_status status;
9ef22b36 708
7c7324d3 709 BT_ASSERT_PRE_NO_ERROR();
fa6cfec3 710 BT_ASSERT_PRE_DEV_NON_NULL(graph, "Graph");
fa6cfec3 711 BT_ASSERT_PRE_DEV(graph->can_consume,
8b45963b 712 "Cannot consume graph in its current state: %!+g", graph);
fa6cfec3
PP
713 BT_ASSERT_PRE_DEV(graph->config_state !=
714 BT_GRAPH_CONFIGURATION_STATE_FAULTY,
9a84962b 715 "Graph is in a faulty state: %!+g", graph);
9cce94e4 716 bt_graph_set_can_consume(graph, false);
1043fdea 717 status = bt_graph_configure(graph);
85e7137b 718 if (G_UNLIKELY(status)) {
1043fdea
PP
719 /* bt_graph_configure() logs errors */
720 goto end;
721 }
722
834e9996 723 status = consume_no_check(graph);
9cce94e4 724 bt_graph_set_can_consume(graph, true);
1043fdea
PP
725
726end:
f8cd6131 727 return status;
851b70bd
PP
728}
729
fb25b9e3 730enum bt_graph_run_status bt_graph_run(struct bt_graph *graph)
f60c8b34 731{
fb25b9e3 732 enum bt_graph_run_status status;
f60c8b34 733
7c7324d3 734 BT_ASSERT_PRE_NO_ERROR();
834e9996 735 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
371361a1
PP
736 BT_ASSERT_PRE(graph->can_consume,
737 "Cannot consume graph in its current state: %!+g", graph);
9a84962b
PP
738 BT_ASSERT_PRE(graph->config_state != BT_GRAPH_CONFIGURATION_STATE_FAULTY,
739 "Graph is in a faulty state: %!+g", graph);
9cce94e4 740 bt_graph_set_can_consume(graph, false);
1043fdea 741 status = bt_graph_configure(graph);
85e7137b 742 if (G_UNLIKELY(status)) {
1043fdea
PP
743 /* bt_graph_configure() logs errors */
744 goto end;
745 }
746
a684a357 747 BT_LIB_LOGI("Running graph: %!+g", graph);
262e5473 748
f60c8b34 749 do {
851b70bd 750 /*
d73bb381
PP
751 * Check if the graph is interrupted at each iteration.
752 * If the graph was interrupted by another thread or by
753 * a signal handler, this is NOT a warning nor an error;
754 * it was intentional: log with an INFO level only.
851b70bd 755 */
d73bb381
PP
756 if (G_UNLIKELY(bt_graph_is_interrupted(graph))) {
757 BT_LIB_LOGI("Stopping the graph: "
758 "graph was interrupted: %!+g", graph);
759 status = BT_FUNC_STATUS_AGAIN;
851b70bd
PP
760 goto end;
761 }
762
834e9996 763 status = consume_no_check(graph);
fb25b9e3 764 if (G_UNLIKELY(status == BT_FUNC_STATUS_AGAIN)) {
f60c8b34 765 /*
202a3a13
PP
766 * If AGAIN is received and there are multiple
767 * sinks, go ahead and consume from the next
768 * sink.
f60c8b34 769 *
202a3a13
PP
770 * However, in the case where a single sink is
771 * left, the caller can decide to busy-wait and
7b53201c 772 * call bt_graph_run() continuously
834e9996
PP
773 * until the source is ready or it can decide to
774 * sleep for an arbitrary amount of time.
f60c8b34
JG
775 */
776 if (graph->sinks_to_consume->length > 1) {
fb25b9e3 777 status = BT_FUNC_STATUS_OK;
f60c8b34
JG
778 }
779 }
fb25b9e3 780 } while (status == BT_FUNC_STATUS_OK);
f60c8b34 781
0e312dbd
PP
782 if (status == BT_FUNC_STATUS_END) {
783 /*
784 * The last call to consume_no_check() returned
785 * `BT_FUNC_STATUS_END`, but bt_graph_run() has no
786 * `BT_GRAPH_RUN_STATUS_END` status: replace with
787 * `BT_GRAPH_RUN_STATUS_OK` (success: graph ran
788 * completely).
789 */
790 status = BT_FUNC_STATUS_OK;
f60c8b34 791 }
262e5473 792
202a3a13 793end:
a684a357 794 BT_LIB_LOGI("Graph ran: %![graph-]+g, status=%s", graph,
fb25b9e3 795 bt_common_func_status_string(status));
9cce94e4 796 bt_graph_set_can_consume(graph, true);
72b913fb 797 return status;
f60c8b34 798}
1bf957a0 799
fb25b9e3 800enum bt_graph_add_listener_status
7b53201c
PP
801bt_graph_add_source_component_output_port_added_listener(
802 struct bt_graph *graph,
803 bt_graph_source_component_output_port_added_listener_func func,
804 bt_graph_listener_removed_func listener_removed, void *data,
eba7ea21 805 bt_listener_id *out_listener_id)
1bf957a0 806{
834e9996
PP
807 struct bt_graph_listener_port_added listener = {
808 .base = {
809 .removed = listener_removed,
810 .data = data,
811 },
812 .func = (port_added_func_t) func,
1bf957a0 813 };
eba7ea21 814 bt_listener_id listener_id;
1bf957a0 815
7c7324d3 816 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
817 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
818 BT_ASSERT_PRE_NON_NULL(func, "Listener");
819 BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener");
820 BT_ASSERT_PRE(!graph->in_remove_listener,
821 "Graph currently executing a \"listener removed\" listener: "
822 "%!+g", graph);
823 g_array_append_val(graph->listeners.source_output_port_added, listener);
824 listener_id = graph->listeners.source_output_port_added->len - 1;
a684a357 825 BT_LIB_LOGD("Added \"source component output port added\" listener to graph: "
834e9996
PP
826 "%![graph-]+g, listener-addr=%p, id=%d", graph, listener,
827 listener_id);
828
829 if (listener_id) {
830 *out_listener_id = listener_id;
831 }
832
fb25b9e3 833 return BT_FUNC_STATUS_OK;
1bf957a0
PP
834}
835
fb25b9e3 836enum bt_graph_add_listener_status
7b53201c
PP
837bt_graph_add_filter_component_output_port_added_listener(
838 struct bt_graph *graph,
839 bt_graph_filter_component_output_port_added_listener_func func,
840 bt_graph_listener_removed_func listener_removed, void *data,
eba7ea21 841 bt_listener_id *out_listener_id)
1bf957a0 842{
834e9996
PP
843 struct bt_graph_listener_port_added listener = {
844 .base = {
845 .removed = listener_removed,
846 .data = data,
847 },
848 .func = (port_added_func_t) func,
849 };
eba7ea21 850 bt_listener_id listener_id;
1bf957a0 851
7c7324d3 852 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
853 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
854 BT_ASSERT_PRE_NON_NULL(func, "Listener");
855 BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener");
856 BT_ASSERT_PRE(!graph->in_remove_listener,
857 "Graph currently executing a \"listener removed\" listener: "
858 "%!+g", graph);
859 g_array_append_val(graph->listeners.filter_output_port_added, listener);
860 listener_id = graph->listeners.filter_output_port_added->len - 1;
a684a357 861 BT_LIB_LOGD("Added \"filter component output port added\" listener to graph: "
834e9996
PP
862 "%![graph-]+g, listener-addr=%p, id=%d", graph, listener,
863 listener_id);
864
865 if (listener_id) {
866 *out_listener_id = listener_id;
867 }
868
fb25b9e3 869 return BT_FUNC_STATUS_OK;
834e9996 870}
262e5473 871
fb25b9e3 872enum bt_graph_add_listener_status
7b53201c
PP
873bt_graph_add_filter_component_input_port_added_listener(
874 struct bt_graph *graph,
875 bt_graph_filter_component_input_port_added_listener_func func,
876 bt_graph_listener_removed_func listener_removed, void *data,
eba7ea21 877 bt_listener_id *out_listener_id)
834e9996 878{
834e9996
PP
879 struct bt_graph_listener_port_added listener = {
880 .base = {
881 .removed = listener_removed,
882 .data = data,
883 },
884 .func = (port_added_func_t) func,
885 };
eba7ea21 886 bt_listener_id listener_id;
eb87cce7 887
7c7324d3 888 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
889 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
890 BT_ASSERT_PRE_NON_NULL(func, "Listener");
891 BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener");
892 BT_ASSERT_PRE(!graph->in_remove_listener,
893 "Graph currently executing a \"listener removed\" listener: "
894 "%!+g", graph);
895 g_array_append_val(graph->listeners.filter_input_port_added, listener);
896 listener_id = graph->listeners.filter_input_port_added->len - 1;
a684a357 897 BT_LIB_LOGD("Added \"filter component input port added\" listener to graph: "
834e9996
PP
898 "%![graph-]+g, listener-addr=%p, id=%d", graph, listener,
899 listener_id);
900
901 if (listener_id) {
902 *out_listener_id = listener_id;
903 }
904
fb25b9e3 905 return BT_FUNC_STATUS_OK;
834e9996 906}
1bf957a0 907
fb25b9e3 908enum bt_graph_add_listener_status
7b53201c
PP
909bt_graph_add_sink_component_input_port_added_listener(
910 struct bt_graph *graph,
911 bt_graph_sink_component_input_port_added_listener_func func,
912 bt_graph_listener_removed_func listener_removed, void *data,
eba7ea21 913 bt_listener_id *out_listener_id)
834e9996 914{
834e9996
PP
915 struct bt_graph_listener_port_added listener = {
916 .base = {
917 .removed = listener_removed,
918 .data = data,
919 },
920 .func = (port_added_func_t) func,
921 };
eba7ea21 922 bt_listener_id listener_id;
1bf957a0 923
7c7324d3 924 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
925 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
926 BT_ASSERT_PRE_NON_NULL(func, "Listener");
927 BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener");
928 BT_ASSERT_PRE(!graph->in_remove_listener,
929 "Graph currently executing a \"listener removed\" listener: "
930 "%!+g", graph);
931 g_array_append_val(graph->listeners.sink_input_port_added, listener);
932 listener_id = graph->listeners.sink_input_port_added->len - 1;
a684a357 933 BT_LIB_LOGD("Added \"sink component input port added\" listener to graph: "
834e9996
PP
934 "%![graph-]+g, listener-addr=%p, id=%d", graph, listener,
935 listener_id);
936
937 if (listener_id) {
938 *out_listener_id = listener_id;
939 }
940
fb25b9e3 941 return BT_FUNC_STATUS_OK;
1bf957a0
PP
942}
943
fb25b9e3 944enum bt_graph_add_listener_status
7b53201c
PP
945bt_graph_add_source_filter_component_ports_connected_listener(
946 struct bt_graph *graph,
947 bt_graph_source_filter_component_ports_connected_listener_func func,
948 bt_graph_listener_removed_func listener_removed, void *data,
eba7ea21 949 bt_listener_id *out_listener_id)
834e9996 950{
834e9996
PP
951 struct bt_graph_listener_ports_connected listener = {
952 .base = {
953 .removed = listener_removed,
954 .data = data,
955 },
956 .func = (ports_connected_func_t) func,
957 };
eba7ea21 958 bt_listener_id listener_id;
eb87cce7 959
7c7324d3 960 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
961 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
962 BT_ASSERT_PRE_NON_NULL(func, "Listener");
963 BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener");
964 BT_ASSERT_PRE(!graph->in_remove_listener,
965 "Graph currently executing a \"listener removed\" listener: "
966 "%!+g", graph);
967 g_array_append_val(graph->listeners.source_filter_ports_connected,
968 listener);
969 listener_id = graph->listeners.source_filter_ports_connected->len - 1;
a684a357 970 BT_LIB_LOGD("Added \"source to filter component ports connected\" listener to graph: "
834e9996
PP
971 "%![graph-]+g, listener-addr=%p, id=%d", graph, listener,
972 listener_id);
973
974 if (listener_id) {
975 *out_listener_id = listener_id;
976 }
977
fb25b9e3 978 return BT_FUNC_STATUS_OK;
834e9996 979}
1bf957a0 980
fb25b9e3 981enum bt_graph_add_listener_status
7b53201c
PP
982bt_graph_add_source_sink_component_ports_connected_listener(
983 struct bt_graph *graph,
984 bt_graph_source_sink_component_ports_connected_listener_func func,
985 bt_graph_listener_removed_func listener_removed, void *data,
eba7ea21 986 bt_listener_id *out_listener_id)
834e9996 987{
834e9996
PP
988 struct bt_graph_listener_ports_connected listener = {
989 .base = {
990 .removed = listener_removed,
991 .data = data,
992 },
993 .func = (ports_connected_func_t) func,
994 };
eba7ea21 995 bt_listener_id listener_id;
1bf957a0 996
7c7324d3 997 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
998 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
999 BT_ASSERT_PRE_NON_NULL(func, "Listener");
1000 BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener");
1001 BT_ASSERT_PRE(!graph->in_remove_listener,
1002 "Graph currently executing a \"listener removed\" listener: "
1003 "%!+g", graph);
1004 g_array_append_val(graph->listeners.source_sink_ports_connected,
1005 listener);
1006 listener_id = graph->listeners.source_sink_ports_connected->len - 1;
a684a357 1007 BT_LIB_LOGD("Added \"source to sink component ports connected\" listener to graph: "
834e9996
PP
1008 "%![graph-]+g, listener-addr=%p, id=%d", graph, listener,
1009 listener_id);
1010
1011 if (listener_id) {
1012 *out_listener_id = listener_id;
1013 }
1014
fb25b9e3 1015 return BT_FUNC_STATUS_OK;
1bf957a0
PP
1016}
1017
fb25b9e3 1018enum bt_graph_add_listener_status
ee976410
PP
1019bt_graph_add_filter_filter_component_ports_connected_listener(
1020 struct bt_graph *graph,
1021 bt_graph_filter_filter_component_ports_connected_listener_func func,
1022 bt_graph_listener_removed_func listener_removed, void *data,
eba7ea21 1023 bt_listener_id *out_listener_id)
ee976410
PP
1024{
1025 struct bt_graph_listener_ports_connected listener = {
1026 .base = {
1027 .removed = listener_removed,
1028 .data = data,
1029 },
1030 .func = (ports_connected_func_t) func,
1031 };
eba7ea21 1032 bt_listener_id listener_id;
ee976410 1033
7c7324d3 1034 BT_ASSERT_PRE_NO_ERROR();
ee976410
PP
1035 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
1036 BT_ASSERT_PRE_NON_NULL(func, "Listener");
1037 BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener");
1038 BT_ASSERT_PRE(!graph->in_remove_listener,
1039 "Graph currently executing a \"listener removed\" listener: "
1040 "%!+g", graph);
1041 g_array_append_val(graph->listeners.filter_filter_ports_connected,
1042 listener);
1043 listener_id = graph->listeners.filter_filter_ports_connected->len - 1;
a684a357 1044 BT_LIB_LOGD("Added \"filter to filter component ports connected\" listener to graph: "
ee976410
PP
1045 "%![graph-]+g, listener-addr=%p, id=%d", graph, listener,
1046 listener_id);
1047
1048 if (listener_id) {
1049 *out_listener_id = listener_id;
1050 }
1051
fb25b9e3 1052 return BT_FUNC_STATUS_OK;
ee976410
PP
1053}
1054
fb25b9e3 1055enum bt_graph_add_listener_status
7b53201c
PP
1056bt_graph_add_filter_sink_component_ports_connected_listener(
1057 struct bt_graph *graph,
1058 bt_graph_filter_sink_component_ports_connected_listener_func func,
1059 bt_graph_listener_removed_func listener_removed, void *data,
eba7ea21 1060 bt_listener_id *out_listener_id)
1bf957a0 1061{
834e9996
PP
1062 struct bt_graph_listener_ports_connected listener = {
1063 .base = {
1064 .removed = listener_removed,
1065 .data = data,
1066 },
1067 .func = (ports_connected_func_t) func,
1068 };
eba7ea21 1069 bt_listener_id listener_id;
1bf957a0 1070
7c7324d3 1071 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
1072 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
1073 BT_ASSERT_PRE_NON_NULL(func, "Listener");
1074 BT_ASSERT_PRE_NON_NULL(func, "\"Listener removed\" listener");
1075 BT_ASSERT_PRE(!graph->in_remove_listener,
1076 "Graph currently executing a \"listener removed\" listener: "
1077 "%!+g", graph);
1078 g_array_append_val(graph->listeners.filter_sink_ports_connected,
1079 listener);
1080 listener_id = graph->listeners.filter_sink_ports_connected->len - 1;
a684a357 1081 BT_LIB_LOGD("Added \"filter to sink component ports connected\" listener to graph: "
834e9996
PP
1082 "%![graph-]+g, listener-addr=%p, id=%d", graph, listener,
1083 listener_id);
1084
1085 if (listener_id) {
1086 *out_listener_id = listener_id;
1087 }
1088
fb25b9e3 1089 return BT_FUNC_STATUS_OK;
834e9996 1090}
262e5473 1091
1bf957a0 1092BT_HIDDEN
fb25b9e3 1093enum bt_graph_listener_func_status bt_graph_notify_port_added(
e18f3e2b 1094 struct bt_graph *graph, struct bt_port *port)
1bf957a0 1095{
834e9996
PP
1096 uint64_t i;
1097 GArray *listeners;
1098 struct bt_component *comp;
fb25b9e3 1099 enum bt_graph_listener_func_status status = BT_FUNC_STATUS_OK;
1bf957a0 1100
834e9996
PP
1101 BT_ASSERT(graph);
1102 BT_ASSERT(port);
a684a357 1103 BT_LIB_LOGD("Notifying graph listeners that a port was added: "
834e9996 1104 "%![graph-]+g, %![port-]+p", graph, port);
7b53201c 1105 comp = bt_port_borrow_component_inline(port);
834e9996
PP
1106 BT_ASSERT(comp);
1107
1108 switch (comp->class->type) {
1109 case BT_COMPONENT_CLASS_TYPE_SOURCE:
1110 {
1111 switch (port->type) {
1112 case BT_PORT_TYPE_OUTPUT:
1113 listeners = graph->listeners.source_output_port_added;
1114 break;
1115 default:
24847fc7 1116 bt_common_abort();
834e9996
PP
1117 }
1118
1119 break;
1120 }
1121 case BT_COMPONENT_CLASS_TYPE_FILTER:
1122 {
1123 switch (port->type) {
1124 case BT_PORT_TYPE_INPUT:
1125 listeners = graph->listeners.filter_input_port_added;
1126 break;
1127 case BT_PORT_TYPE_OUTPUT:
1128 listeners = graph->listeners.filter_output_port_added;
1129 break;
1130 default:
24847fc7 1131 bt_common_abort();
834e9996 1132 }
262e5473 1133
834e9996
PP
1134 break;
1135 }
1136 case BT_COMPONENT_CLASS_TYPE_SINK:
1137 {
1138 switch (port->type) {
1139 case BT_PORT_TYPE_INPUT:
1140 listeners = graph->listeners.sink_input_port_added;
1141 break;
1142 default:
24847fc7 1143 bt_common_abort();
834e9996 1144 }
1bf957a0 1145
834e9996
PP
1146 break;
1147 }
1148 default:
24847fc7 1149 bt_common_abort();
834e9996
PP
1150 }
1151
1152 for (i = 0; i < listeners->len; i++) {
1153 struct bt_graph_listener_port_added *listener =
1154 &g_array_index(listeners,
1155 struct bt_graph_listener_port_added, i);
1156
e18f3e2b 1157
834e9996 1158 BT_ASSERT(listener->func);
e18f3e2b 1159 status = listener->func(comp, port, listener->base.data);
d6f6a5aa 1160 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(status);
fb25b9e3 1161 if (status != BT_FUNC_STATUS_OK) {
e18f3e2b
SM
1162 goto end;
1163 }
1bf957a0 1164 }
e18f3e2b
SM
1165
1166end:
1167 return status;
1bf957a0
PP
1168}
1169
1bf957a0 1170BT_HIDDEN
fb25b9e3 1171enum bt_graph_listener_func_status bt_graph_notify_ports_connected(
e18f3e2b
SM
1172 struct bt_graph *graph, struct bt_port *upstream_port,
1173 struct bt_port *downstream_port)
1bf957a0 1174{
834e9996
PP
1175 uint64_t i;
1176 GArray *listeners;
1177 struct bt_component *upstream_comp;
1178 struct bt_component *downstream_comp;
fb25b9e3 1179 enum bt_graph_listener_func_status status = BT_FUNC_STATUS_OK;
1bf957a0 1180
834e9996
PP
1181 BT_ASSERT(graph);
1182 BT_ASSERT(upstream_port);
1183 BT_ASSERT(downstream_port);
a684a357 1184 BT_LIB_LOGD("Notifying graph listeners that ports were connected: "
834e9996
PP
1185 "%![graph-]+g, %![up-port-]+p, %![down-port-]+p",
1186 graph, upstream_port, downstream_port);
7b53201c 1187 upstream_comp = bt_port_borrow_component_inline(upstream_port);
834e9996 1188 BT_ASSERT(upstream_comp);
7b53201c 1189 downstream_comp = bt_port_borrow_component_inline(downstream_port);
834e9996
PP
1190 BT_ASSERT(downstream_comp);
1191
1192 switch (upstream_comp->class->type) {
1193 case BT_COMPONENT_CLASS_TYPE_SOURCE:
1194 {
1195 switch (downstream_comp->class->type) {
1196 case BT_COMPONENT_CLASS_TYPE_FILTER:
1197 listeners =
1198 graph->listeners.source_filter_ports_connected;
1199 break;
1200 case BT_COMPONENT_CLASS_TYPE_SINK:
1201 listeners =
1202 graph->listeners.source_sink_ports_connected;
1203 break;
1204 default:
24847fc7 1205 bt_common_abort();
834e9996 1206 }
262e5473 1207
834e9996
PP
1208 break;
1209 }
1210 case BT_COMPONENT_CLASS_TYPE_FILTER:
1211 {
1212 switch (downstream_comp->class->type) {
ee976410
PP
1213 case BT_COMPONENT_CLASS_TYPE_FILTER:
1214 listeners =
1215 graph->listeners.filter_filter_ports_connected;
1216 break;
834e9996
PP
1217 case BT_COMPONENT_CLASS_TYPE_SINK:
1218 listeners =
1219 graph->listeners.filter_sink_ports_connected;
1220 break;
1221 default:
24847fc7 1222 bt_common_abort();
834e9996 1223 }
1bf957a0 1224
834e9996
PP
1225 break;
1226 }
1227 default:
24847fc7 1228 bt_common_abort();
834e9996
PP
1229 }
1230
1231 for (i = 0; i < listeners->len; i++) {
1232 struct bt_graph_listener_ports_connected *listener =
1233 &g_array_index(listeners,
1234 struct bt_graph_listener_ports_connected, i);
1235
1236 BT_ASSERT(listener->func);
e18f3e2b 1237 status = listener->func(upstream_comp, downstream_comp,
834e9996 1238 upstream_port, downstream_port, listener->base.data);
d6f6a5aa 1239 BT_ASSERT_POST_DEV_NO_ERROR_IF_NO_ERROR_STATUS(status);
fb25b9e3 1240 if (status != BT_FUNC_STATUS_OK) {
e18f3e2b
SM
1241 goto end;
1242 }
1bf957a0 1243 }
e18f3e2b
SM
1244
1245end:
1246 return status;
1bf957a0
PP
1247}
1248
f167d3c0
PP
1249BT_HIDDEN
1250void bt_graph_remove_connection(struct bt_graph *graph,
1251 struct bt_connection *connection)
1252{
8b45963b
PP
1253 BT_ASSERT(graph);
1254 BT_ASSERT(connection);
a684a357 1255 BT_LIB_LOGD("Removing graph's connection: %![graph-]+g, %![conn-]+x",
262e5473 1256 graph, connection);
f167d3c0
PP
1257 g_ptr_array_remove(graph->connections, connection);
1258}
36712f1d 1259
834e9996
PP
1260static inline
1261bool component_name_exists(struct bt_graph *graph, const char *name)
1262{
1263 bool exists = false;
1264 uint64_t i;
1265
1266 for (i = 0; i < graph->components->len; i++) {
1267 struct bt_component *other_comp = graph->components->pdata[i];
1268
1269 if (strcmp(name, bt_component_get_name(other_comp)) == 0) {
1270 BT_ASSERT_PRE_MSG("Another component with the same name already exists in the graph: "
1271 "%![other-comp-]+c, name=\"%s\"",
1272 other_comp, name);
1273 exists = true;
1274 goto end;
1275 }
1276 }
1277
1278end:
1279 return exists;
1280}
1281
1282static
fb25b9e3 1283int add_component_with_init_method_data(
7b53201c 1284 struct bt_graph *graph,
834e9996
PP
1285 struct bt_component_class *comp_cls,
1286 comp_init_method_t init_method,
ce141536 1287 const char *name, const struct bt_value *params,
cc81b5ab 1288 void *init_method_data, bt_logging_level log_level,
8345fc26 1289 const struct bt_component **user_component)
36712f1d 1290{
fb25b9e3 1291 int status = BT_FUNC_STATUS_OK;
4175c1d5 1292 enum bt_component_class_initialize_method_status init_status;
36712f1d 1293 struct bt_component *component = NULL;
834e9996
PP
1294 int ret;
1295 bool init_can_consume;
ce141536 1296 struct bt_value *new_params = NULL;
36712f1d 1297
834e9996
PP
1298 BT_ASSERT(comp_cls);
1299 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
1300 BT_ASSERT_PRE_NON_NULL(name, "Name");
1043fdea
PP
1301 BT_ASSERT_PRE(
1302 graph->config_state == BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
9a84962b 1303 "Graph is not in the \"configuring\" state: %!+g", graph);
834e9996
PP
1304 BT_ASSERT_PRE(!component_name_exists(graph, name),
1305 "Duplicate component name: %!+g, name=\"%s\"", graph, name);
1306 BT_ASSERT_PRE(!params || bt_value_is_map(params),
1307 "Parameter value is not a map value: %!+v", params);
3afb93ee 1308 init_can_consume = graph->can_consume;
834e9996 1309 bt_graph_set_can_consume(graph, false);
a684a357 1310 BT_LIB_LOGI("Adding component to graph: "
cc81b5ab
PP
1311 "%![graph-]+g, %![cc-]+C, name=\"%s\", log-level=%s, "
1312 "%![params-]+v, init-method-data-addr=%p",
1313 graph, comp_cls, name,
1314 bt_common_logging_level_string(log_level), params,
1315 init_method_data);
36712f1d 1316
834e9996 1317 if (!params) {
ce141536
PP
1318 new_params = bt_value_map_create();
1319 if (!new_params) {
a8f90e5d
PP
1320 BT_LIB_LOGE_APPEND_CAUSE(
1321 "Cannot create empty map value object.");
fb25b9e3 1322 status = BT_FUNC_STATUS_MEMORY_ERROR;
36712f1d
PP
1323 goto end;
1324 }
ce141536
PP
1325
1326 params = new_params;
36712f1d
PP
1327 }
1328
cc81b5ab 1329 ret = bt_component_create(comp_cls, name, log_level, &component);
834e9996 1330 if (ret) {
a8f90e5d
PP
1331 BT_LIB_LOGE_APPEND_CAUSE(
1332 "Cannot create empty component object: ret=%d",
834e9996 1333 ret);
fb25b9e3 1334 status = BT_FUNC_STATUS_MEMORY_ERROR;
36712f1d
PP
1335 goto end;
1336 }
1337
1338 /*
1339 * The user's initialization method needs to see that this
1340 * component is part of the graph. If the user method fails, we
1341 * immediately remove the component from the graph's components.
1342 */
1343 g_ptr_array_add(graph->components, component);
1344 bt_component_set_graph(component, graph);
f433d1bf 1345 bt_value_freeze(params);
36712f1d 1346
834e9996 1347 if (init_method) {
e3250e61
SM
1348 /*
1349 * There is no use for config objects right now, so just pass
1350 * NULL.
1351 */
36712f1d 1352 BT_LOGD_STR("Calling user's initialization method.");
e3250e61 1353 init_status = init_method(component, NULL, params, init_method_data);
36712f1d 1354 BT_LOGD("User method returned: status=%s",
fb25b9e3 1355 bt_common_func_status_string(init_status));
d6f6a5aa 1356 BT_ASSERT_POST_DEV_NO_ERROR_IF_NO_ERROR_STATUS(init_status);
fb25b9e3 1357 if (init_status != BT_FUNC_STATUS_OK) {
a8f90e5d
PP
1358 if (init_status < 0) {
1359 BT_LIB_LOGW_APPEND_CAUSE(
1360 "Component initialization method failed: "
1361 "status=%s, %![comp-]+c",
1362 bt_common_func_status_string(init_status),
1363 component);
1364 }
1365
fb25b9e3 1366 status = init_status;
36712f1d
PP
1367 bt_component_set_graph(component, NULL);
1368 g_ptr_array_remove_fast(graph->components, component);
1369 goto end;
1370 }
1371 }
1372
1373 /*
1374 * Mark the component as initialized so that its finalization
1375 * method is called when it is destroyed.
1376 */
1377 component->initialized = true;
1378
1379 /*
1380 * If it's a sink component, it needs to be part of the graph's
e023d253
PP
1381 * sink queue to be consumed by bt_graph_run() or
1382 * bt_graph_run_once().
36712f1d
PP
1383 */
1384 if (bt_component_is_sink(component)) {
834e9996 1385 graph->has_sink = true;
36712f1d
PP
1386 g_queue_push_tail(graph->sinks_to_consume, component);
1387 }
1388
1389 /*
1390 * Freeze the component class now that it's instantiated at
1391 * least once.
1392 */
1393 BT_LOGD_STR("Freezing component class.");
834e9996 1394 bt_component_class_freeze(comp_cls);
a684a357 1395 BT_LIB_LOGI("Added component to graph: "
cc81b5ab
PP
1396 "%![graph-]+g, %![cc-]+C, name=\"%s\", log-level=%s, "
1397 "%![params-]+v, init-method-data-addr=%p, %![comp-]+c",
1398 graph, comp_cls, name,
1399 bt_common_logging_level_string(log_level), params,
1400 init_method_data, component);
36712f1d
PP
1401
1402 if (user_component) {
1403 /* Move reference to user */
1404 *user_component = component;
1405 component = NULL;
1406 }
1407
1408end:
fb25b9e3 1409 if (status != BT_FUNC_STATUS_OK) {
e18f3e2b 1410 bt_graph_make_faulty(graph);
9a84962b
PP
1411 }
1412
8138bfe1 1413 bt_object_put_ref(component);
ce141536 1414 bt_object_put_ref(new_params);
834e9996
PP
1415 (void) init_can_consume;
1416 bt_graph_set_can_consume(graph, init_can_consume);
fb25b9e3 1417 return status;
36712f1d
PP
1418}
1419
fb25b9e3 1420enum bt_graph_add_component_status
4175c1d5 1421bt_graph_add_source_component_with_initialize_method_data(
7b53201c
PP
1422 struct bt_graph *graph,
1423 const struct bt_component_class_source *comp_cls,
ce141536 1424 const char *name, const struct bt_value *params,
cc81b5ab 1425 void *init_method_data, bt_logging_level log_level,
7b53201c 1426 const struct bt_component_source **component)
834e9996 1427{
7c7324d3 1428 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
1429 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
1430 return add_component_with_init_method_data(graph,
1431 (void *) comp_cls, (comp_init_method_t) comp_cls->methods.init,
cc81b5ab 1432 name, params, init_method_data, log_level, (void *) component);
834e9996
PP
1433}
1434
fb25b9e3 1435enum bt_graph_add_component_status bt_graph_add_source_component(
7b53201c
PP
1436 struct bt_graph *graph,
1437 const struct bt_component_class_source *comp_cls,
ce141536 1438 const char *name, const struct bt_value *params,
8345fc26 1439 enum bt_logging_level log_level,
7b53201c 1440 const struct bt_component_source **component)
834e9996 1441{
7c7324d3 1442 BT_ASSERT_PRE_NO_ERROR();
4175c1d5 1443 return bt_graph_add_source_component_with_initialize_method_data(
cc81b5ab 1444 graph, comp_cls, name, params, NULL, log_level, component);
834e9996
PP
1445}
1446
fb25b9e3 1447enum bt_graph_add_component_status
4175c1d5 1448bt_graph_add_filter_component_with_initialize_method_data(
7b53201c
PP
1449 struct bt_graph *graph,
1450 const struct bt_component_class_filter *comp_cls,
ce141536 1451 const char *name, const struct bt_value *params,
8345fc26 1452 void *init_method_data, enum bt_logging_level log_level,
7b53201c 1453 const struct bt_component_filter **component)
834e9996 1454{
7c7324d3 1455 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
1456 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
1457 return add_component_with_init_method_data(graph,
1458 (void *) comp_cls, (comp_init_method_t) comp_cls->methods.init,
cc81b5ab 1459 name, params, init_method_data, log_level, (void *) component);
834e9996
PP
1460}
1461
fb25b9e3 1462enum bt_graph_add_component_status bt_graph_add_filter_component(
7b53201c
PP
1463 struct bt_graph *graph,
1464 const struct bt_component_class_filter *comp_cls,
ce141536 1465 const char *name, const struct bt_value *params,
8345fc26 1466 enum bt_logging_level log_level,
7b53201c 1467 const struct bt_component_filter **component)
834e9996 1468{
7c7324d3 1469 BT_ASSERT_PRE_NO_ERROR();
4175c1d5 1470 return bt_graph_add_filter_component_with_initialize_method_data(
cc81b5ab 1471 graph, comp_cls, name, params, NULL, log_level, component);
834e9996
PP
1472}
1473
fb25b9e3 1474enum bt_graph_add_component_status
4175c1d5 1475bt_graph_add_sink_component_with_initialize_method_data(
7b53201c
PP
1476 struct bt_graph *graph,
1477 const struct bt_component_class_sink *comp_cls,
ce141536 1478 const char *name, const struct bt_value *params,
8345fc26 1479 void *init_method_data, enum bt_logging_level log_level,
7b53201c 1480 const struct bt_component_sink **component)
36712f1d 1481{
7c7324d3 1482 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
1483 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
1484 return add_component_with_init_method_data(graph,
1485 (void *) comp_cls, (comp_init_method_t) comp_cls->methods.init,
cc81b5ab 1486 name, params, init_method_data, log_level, (void *) component);
834e9996
PP
1487}
1488
fb25b9e3 1489enum bt_graph_add_component_status bt_graph_add_sink_component(
7b53201c
PP
1490 struct bt_graph *graph,
1491 const struct bt_component_class_sink *comp_cls,
ce141536 1492 const char *name, const struct bt_value *params,
8345fc26 1493 enum bt_logging_level log_level,
7b53201c 1494 const struct bt_component_sink **component)
834e9996 1495{
7c7324d3 1496 BT_ASSERT_PRE_NO_ERROR();
4175c1d5 1497 return bt_graph_add_sink_component_with_initialize_method_data(
cc81b5ab 1498 graph, comp_cls, name, params, NULL, log_level, component);
36712f1d 1499}
c3ac0193 1500
5efafa1a
PP
1501enum bt_graph_add_component_status
1502bt_graph_add_simple_sink_component(struct bt_graph *graph, const char *name,
4175c1d5 1503 bt_graph_simple_sink_component_initialize_func init_func,
5efafa1a
PP
1504 bt_graph_simple_sink_component_consume_func consume_func,
1505 bt_graph_simple_sink_component_finalize_func finalize_func,
1506 void *user_data, const bt_component_sink **component)
1507{
1508 enum bt_graph_add_component_status status;
1509 struct bt_component_class_sink *comp_cls;
1510 struct simple_sink_init_method_data init_method_data = {
1511 .init_func = init_func,
1512 .consume_func = consume_func,
1513 .finalize_func = finalize_func,
1514 .user_data = user_data,
1515 };
1516
7c7324d3
SM
1517 BT_ASSERT_PRE_NO_ERROR();
1518
5efafa1a
PP
1519 /*
1520 * Other preconditions are checked by
1521 * bt_graph_add_sink_component_with_init_method_data().
1522 */
1523 BT_ASSERT_PRE_NON_NULL(consume_func, "Consume function");
1524
1525 comp_cls = bt_component_class_sink_simple_borrow();
1526 if (!comp_cls) {
1527 BT_LIB_LOGE_APPEND_CAUSE(
1528 "Cannot borrow simple sink component class.");
1529 status = BT_FUNC_STATUS_MEMORY_ERROR;
1530 goto end;
1531 }
1532
4175c1d5 1533 status = bt_graph_add_sink_component_with_initialize_method_data(graph,
5efafa1a
PP
1534 comp_cls, name, NULL, &init_method_data,
1535 BT_LOGGING_LEVEL_NONE, component);
1536
1537end:
1538 return status;
1539}
1540
f7c3ac09 1541BT_HIDDEN
b09a5592
PP
1542void bt_graph_add_message(struct bt_graph *graph,
1543 struct bt_message *msg)
f7c3ac09
PP
1544{
1545 BT_ASSERT(graph);
b09a5592 1546 BT_ASSERT(msg);
f7c3ac09
PP
1547
1548 /*
1549 * It's okay not to take a reference because, when a
b09a5592 1550 * message's reference count drops to 0, either:
f7c3ac09
PP
1551 *
1552 * * It is recycled back to one of this graph's pool.
1553 * * It is destroyed because it doesn't have any link to any
1554 * graph, which means the original graph is already destroyed.
1555 */
b09a5592 1556 g_ptr_array_add(graph->messages, msg);
f7c3ac09 1557}
8c6884d9 1558
d73bb381
PP
1559BT_HIDDEN
1560bool bt_graph_is_interrupted(const struct bt_graph *graph)
1561{
ec4a3354 1562 BT_ASSERT_DBG(graph);
d73bb381
PP
1563 return bt_interrupter_array_any_is_set(graph->interrupters);
1564}
1565
1566enum bt_graph_add_interrupter_status bt_graph_add_interrupter(
1567 struct bt_graph *graph, const struct bt_interrupter *intr)
1568{
7c7324d3 1569 BT_ASSERT_PRE_NO_ERROR();
d73bb381
PP
1570 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
1571 BT_ASSERT_PRE_NON_NULL(intr, "Interrupter");
1572 g_ptr_array_add(graph->interrupters, (void *) intr);
864aa43f 1573 bt_object_get_ref_no_null_check(intr);
d73bb381
PP
1574 BT_LIB_LOGD("Added interrupter to graph: %![graph-]+g, %![intr-]+z",
1575 graph, intr);
1576 return BT_FUNC_STATUS_OK;
1577}
1578
1579void bt_graph_interrupt(struct bt_graph *graph)
1580{
1581 BT_ASSERT_PRE_NON_NULL(graph, "Graph");
1582 bt_interrupter_set(graph->default_interrupter);
1583 BT_LIB_LOGI("Interrupted graph: %!+g", graph);
1584}
1585
8c6884d9
PP
1586void bt_graph_get_ref(const struct bt_graph *graph)
1587{
1588 bt_object_get_ref(graph);
1589}
1590
1591void bt_graph_put_ref(const struct bt_graph *graph)
1592{
1593 bt_object_put_ref(graph);
1594}
This page took 0.149097 seconds and 4 git commands to generate.