lib: merge `assert-pre.h` and `assert-post.h` into `assert-cond.h`
[babeltrace.git] / src / lib / graph / component.c
CommitLineData
de713ce0 1/*
0235b0db
MJ
2 * SPDX-License-Identifier: MIT
3 *
e2f7325d 4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
de713ce0 5 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
de713ce0
JG
6 */
7
350ad6c1 8#define BT_LOG_TAG "LIB/COMPONENT"
c2d9d9cf 9#include "lib/logging.h"
ab0d387b 10
e874da19 11#include "common/common.h"
578e048b 12#include "common/assert.h"
d98421f2 13#include "lib/assert-cond.h"
3fadfbc0 14#include <babeltrace2/graph/self-component.h>
43c59509
PP
15#include <babeltrace2/graph/component.h>
16#include <babeltrace2/graph/graph.h>
91d81473 17#include "common/macros.h"
578e048b 18#include "compat/compiler.h"
3fadfbc0
MJ
19#include <babeltrace2/types.h>
20#include <babeltrace2/value.h>
578e048b 21#include "lib/value.h"
9ac68eb1 22#include <stdint.h>
ab0d387b 23#include <inttypes.h>
de713ce0 24
578e048b
MJ
25#include "component.h"
26#include "component-class.h"
27#include "component-source.h"
28#include "component-filter.h"
29#include "component-sink.h"
30#include "connection.h"
31#include "graph.h"
32#include "message/iterator.h"
33#include "port.h"
d24d5663 34#include "lib/func-status.h"
578e048b 35
7c7c0433
JG
36static
37struct bt_component * (* const component_create_funcs[])(
0d72b8c3 38 const struct bt_component_class *) = {
d3e4dcd8
PP
39 [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_create,
40 [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_create,
41 [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_create,
7c7c0433
JG
42};
43
72b913fb
PP
44static
45void (*component_destroy_funcs[])(struct bt_component *) = {
46 [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_destroy,
47 [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_destroy,
48 [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_destroy,
49};
50
b8a06801 51static
d94d92ac
PP
52void finalize_component(struct bt_component *comp)
53{
54 typedef void (*method_t)(void *);
55
56 method_t method = NULL;
57
58 BT_ASSERT(comp);
59
60 switch (comp->class->type) {
61 case BT_COMPONENT_CLASS_TYPE_SOURCE:
62 {
63 struct bt_component_class_source *src_cc = (void *) comp->class;
64
65 method = (method_t) src_cc->methods.finalize;
66 break;
67 }
68 case BT_COMPONENT_CLASS_TYPE_FILTER:
69 {
70 struct bt_component_class_filter *flt_cc = (void *) comp->class;
71
72 method = (method_t) flt_cc->methods.finalize;
73 break;
74 }
75 case BT_COMPONENT_CLASS_TYPE_SINK:
76 {
77 struct bt_component_class_sink *sink_cc = (void *) comp->class;
78
79 method = (method_t) sink_cc->methods.finalize;
80 break;
81 }
82 default:
498e7994 83 bt_common_abort();
d94d92ac
PP
84 }
85
86 if (method) {
42a63165
SM
87 const struct bt_error *saved_error;
88
89 saved_error = bt_current_thread_take_error();
90
3f7d4d90 91 BT_LIB_LOGI("Calling user's component finalization method: "
d94d92ac
PP
92 "%![comp-]+c", comp);
93 method(comp);
42a63165
SM
94 BT_ASSERT_POST_NO_ERROR();
95
96 if (saved_error) {
97 BT_CURRENT_THREAD_MOVE_ERROR_AND_RESET(saved_error);
98 }
d94d92ac
PP
99 }
100}
101
102static
103void destroy_component(struct bt_object *obj)
b8a06801
JG
104{
105 struct bt_component *component = NULL;
3230ee6b 106 int i;
b8a06801
JG
107
108 if (!obj) {
109 return;
110 }
111
bd14d768
PP
112 /*
113 * The component's reference count is 0 if we're here. Increment
114 * it to avoid a double-destroy (possibly infinitely recursive).
115 * This could happen for example if the component's finalization
d94d92ac
PP
116 * function does bt_object_get_ref() (or anything that causes
117 * bt_object_get_ref() to be called) on itself (ref. count goes
118 * from 0 to 1), and then bt_object_put_ref(): the reference
119 * count would go from 1 to 0 again and this function would be
120 * called again.
bd14d768 121 */
3fea54f6 122 obj->ref_count++;
b8a06801 123 component = container_of(obj, struct bt_component, base);
3f7d4d90 124 BT_LIB_LOGI("Destroying component: %![comp-]+c, %![graph-]+g",
d94d92ac 125 component, bt_component_borrow_graph(component));
3230ee6b
PP
126
127 /* Call destroy listeners in reverse registration order */
ab0d387b
PP
128 BT_LOGD_STR("Calling destroy listeners.");
129
3230ee6b
PP
130 for (i = component->destroy_listeners->len - 1; i >= 0; i--) {
131 struct bt_component_destroy_listener *listener =
132 &g_array_index(component->destroy_listeners,
133 struct bt_component_destroy_listener, i);
134
135 listener->func(component, listener->data);
136 }
137
7c7c0433 138 /*
36712f1d
PP
139 * User data is destroyed first, followed by the concrete
140 * component instance. Do not finalize if the component's user
141 * initialization method failed in the first place.
b8a06801 142 */
d94d92ac
PP
143 if (component->initialized) {
144 finalize_component(component);
7c7c0433 145 }
b8a06801 146
ab09f844 147 if (component->destroy) {
ab0d387b 148 BT_LOGD_STR("Destroying type-specific data.");
ab09f844
JG
149 component->destroy(component);
150 }
151
72b913fb 152 if (component->input_ports) {
ab0d387b 153 BT_LOGD_STR("Destroying input ports.");
72b913fb 154 g_ptr_array_free(component->input_ports, TRUE);
d94d92ac 155 component->input_ports = NULL;
72b913fb 156 }
b8a06801 157
72b913fb 158 if (component->output_ports) {
ab0d387b 159 BT_LOGD_STR("Destroying output ports.");
72b913fb 160 g_ptr_array_free(component->output_ports, TRUE);
d94d92ac 161 component->output_ports = NULL;
b8a06801
JG
162 }
163
3230ee6b
PP
164 if (component->destroy_listeners) {
165 g_array_free(component->destroy_listeners, TRUE);
d94d92ac 166 component->destroy_listeners = NULL;
3230ee6b
PP
167 }
168
ab0d387b
PP
169 if (component->name) {
170 g_string_free(component->name, TRUE);
d94d92ac 171 component->name = NULL;
ab0d387b
PP
172 }
173
d94d92ac
PP
174 BT_LOGD_STR("Putting component class.");
175 BT_OBJECT_PUT_REF_AND_RESET(component->class);
72b913fb 176 g_free(component);
b8a06801 177}
de713ce0 178
890882ef 179enum bt_component_class_type bt_component_get_class_type(
0d72b8c3 180 const struct bt_component *component)
5645cd95 181{
bdb288b3 182 BT_ASSERT_PRE_DEV_NON_NULL(component, "Component");
d94d92ac 183 return component->class->type;
5645cd95
JG
184}
185
72b913fb 186static
d24d5663 187enum bt_self_component_add_port_status add_port(
72b913fb 188 struct bt_component *component, GPtrArray *ports,
8cc56726
SM
189 enum bt_port_type port_type, const char *name, void *user_data,
190 struct bt_port **port)
72b913fb 191{
72b913fb 192 struct bt_port *new_port = NULL;
1bf957a0 193 struct bt_graph *graph = NULL;
d24d5663 194 enum bt_self_component_add_port_status status;
72b913fb 195
d94d92ac
PP
196 BT_ASSERT_PRE_NON_NULL(component, "Component");
197 BT_ASSERT_PRE_NON_NULL(name, "Name");
198 BT_ASSERT_PRE(strlen(name) > 0, "Name is empty");
199 graph = bt_component_borrow_graph(component);
5badd463
PP
200 BT_ASSERT_PRE(
201 graph->config_state == BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
4725a201
PP
202 "Component's graph is already configured: "
203 "%![comp-]+c, %![graph-]+g", component, graph);
72b913fb 204
d94d92ac 205 // TODO: Validate that the name is not already used.
ab0d387b 206
3f7d4d90 207 BT_LIB_LOGI("Adding port to component: %![comp-]+c, "
ab0d387b 208 "port-type=%s, port-name=\"%s\"", component,
ab0d387b
PP
209 bt_port_type_string(port_type), name);
210
3e9b0023 211 new_port = bt_port_create(component, port_type, name, user_data);
72b913fb 212 if (!new_port) {
870631a2 213 BT_LIB_LOGE_APPEND_CAUSE("Cannot create port object.");
d24d5663 214 status = BT_FUNC_STATUS_MEMORY_ERROR;
8cc56726 215 goto error;
72b913fb
PP
216 }
217
218 /*
219 * No name clash, add the port.
220 * The component is now the port's parent; it should _not_
221 * hold a reference to the port since the port's lifetime
222 * is now protected by the component's own lifetime.
223 */
224 g_ptr_array_add(ports, new_port);
1bf957a0
PP
225
226 /*
227 * Notify the graph's creator that a new port was added.
228 */
398454ed 229 graph = bt_component_borrow_graph(component);
1bf957a0 230 if (graph) {
d24d5663 231 enum bt_graph_listener_func_status listener_status;
8cc56726
SM
232
233 listener_status = bt_graph_notify_port_added(graph, new_port);
d24d5663 234 if (listener_status != BT_FUNC_STATUS_OK) {
8cc56726 235 bt_graph_make_faulty(graph);
d24d5663 236 status = (int) listener_status;
8cc56726
SM
237 goto error;
238 }
1bf957a0
PP
239 }
240
3f7d4d90 241 BT_LIB_LOGI("Created and added port to component: "
d94d92ac 242 "%![comp-]+c, %![port-]+p", component, new_port);
ab0d387b 243
8cc56726 244 *port = new_port;
d24d5663 245 status = BT_FUNC_STATUS_OK;
8cc56726
SM
246
247 goto end;
248error:
249 /*
250 * We need to release the reference that we would otherwise have
251 * returned to the caller.
252 */
253 BT_PORT_PUT_REF_AND_RESET(new_port);
254
72b913fb 255end:
8cc56726 256 return status;
72b913fb
PP
257}
258
259BT_HIDDEN
0d72b8c3 260uint64_t bt_component_get_input_port_count(const struct bt_component *comp)
72b913fb 261{
bdb288b3 262 BT_ASSERT_PRE_DEV_NON_NULL(comp, "Component");
d94d92ac 263 return (uint64_t) comp->input_ports->len;
72b913fb
PP
264}
265
266BT_HIDDEN
0d72b8c3 267uint64_t bt_component_get_output_port_count(const struct bt_component *comp)
72b913fb 268{
bdb288b3 269 BT_ASSERT_PRE_DEV_NON_NULL(comp, "Component");
d94d92ac 270 return (uint64_t) comp->output_ports->len;
72b913fb
PP
271}
272
dd8a4547 273BT_HIDDEN
d94d92ac 274int bt_component_create(struct bt_component_class *component_class,
e874da19
PP
275 const char *name, bt_logging_level log_level,
276 struct bt_component **user_component)
38b48196 277{
d94d92ac 278 int ret = 0;
38b48196 279 struct bt_component *component = NULL;
d3e4dcd8 280 enum bt_component_class_type type;
38b48196 281
f6ccaed9
PP
282 BT_ASSERT(user_component);
283 BT_ASSERT(component_class);
284 BT_ASSERT(name);
7c7c0433 285 type = bt_component_class_get_type(component_class);
3f7d4d90 286 BT_LIB_LOGI("Creating empty component from component class: %![cc-]+C, "
e874da19
PP
287 "comp-name=\"%s\", log-level=%s", component_class, name,
288 bt_common_logging_level_string(log_level));
36712f1d 289 component = component_create_funcs[type](component_class);
7c7c0433 290 if (!component) {
870631a2
PP
291 BT_LIB_LOGE_APPEND_CAUSE(
292 "Cannot create specific component object.");
d94d92ac 293 ret = -1;
7c7c0433
JG
294 goto end;
295 }
296
d0fea130 297 bt_object_init_shared_with_parent(&component->base, destroy_component);
398454ed 298 component->class = component_class;
6871026b 299 bt_object_get_ref_no_null_check(component->class);
72b913fb 300 component->destroy = component_destroy_funcs[type];
7c7c0433 301 component->name = g_string_new(name);
4b70dd83 302 if (!component->name) {
870631a2 303 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GString.");
d94d92ac 304 ret = -1;
7c7c0433
JG
305 goto end;
306 }
307
e874da19 308 component->log_level = log_level;
72b913fb 309 component->input_ports = g_ptr_array_new_with_free_func(
3fea54f6 310 (GDestroyNotify) bt_object_try_spec_release);
72b913fb 311 if (!component->input_ports) {
870631a2 312 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
d94d92ac 313 ret = -1;
72b913fb
PP
314 goto end;
315 }
316
317 component->output_ports = g_ptr_array_new_with_free_func(
3fea54f6 318 (GDestroyNotify) bt_object_try_spec_release);
72b913fb 319 if (!component->output_ports) {
870631a2 320 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GPtrArray.");
d94d92ac 321 ret = -1;
72b913fb
PP
322 goto end;
323 }
324
3230ee6b
PP
325 component->destroy_listeners = g_array_new(FALSE, TRUE,
326 sizeof(struct bt_component_destroy_listener));
327 if (!component->destroy_listeners) {
870631a2 328 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GArray.");
d94d92ac 329 ret = -1;
3230ee6b
PP
330 goto end;
331 }
332
3f7d4d90 333 BT_LIB_LOGI("Created empty component from component class: "
d94d92ac 334 "%![cc-]+C, %![comp-]+c", component_class, component);
65300d60 335 BT_OBJECT_MOVE_REF(*user_component, component);
ab0d387b 336
38b48196 337end:
65300d60 338 bt_object_put_ref(component);
d94d92ac 339 return ret;
6358c163
PP
340}
341
0d72b8c3 342const char *bt_component_get_name(const struct bt_component *component)
de713ce0 343{
bdb288b3 344 BT_ASSERT_PRE_DEV_NON_NULL(component, "Component");
d94d92ac 345 return component->name->str;
de713ce0
JG
346}
347
1de6a2b0 348const struct bt_component_class *bt_component_borrow_class_const(
0d72b8c3 349 const struct bt_component *component)
de713ce0 350{
bdb288b3 351 BT_ASSERT_PRE_DEV_NON_NULL(component, "Component");
d94d92ac 352 return component->class;
de713ce0
JG
353}
354
0d72b8c3 355void *bt_self_component_get_data(const struct bt_self_component *self_comp)
de713ce0 356{
d94d92ac 357 struct bt_component *component = (void *) self_comp;
890882ef 358
bdb288b3 359 BT_ASSERT_PRE_DEV_NON_NULL(component, "Component");
d94d92ac 360 return component->user_data;
de713ce0
JG
361}
362
d94d92ac 363void bt_self_component_set_data(struct bt_self_component *self_comp,
de713ce0
JG
364 void *data)
365{
d94d92ac 366 struct bt_component *component = (void *) self_comp;
ab0d387b 367
bdb288b3 368 BT_ASSERT_PRE_DEV_NON_NULL(component, "Component");
de713ce0 369 component->user_data = data;
3f7d4d90 370 BT_LIB_LOGD("Set component's user data: %!+c", component);
de713ce0 371}
366e034f
JG
372
373BT_HIDDEN
f60c8b34 374void bt_component_set_graph(struct bt_component *component,
366e034f
JG
375 struct bt_graph *graph)
376{
3fea54f6
PP
377 bt_object_set_parent(&component->base,
378 graph ? &graph->base : NULL);
366e034f
JG
379}
380
72b913fb 381static
d94d92ac 382struct bt_port *borrow_port_by_name(GPtrArray *ports,
9ac68eb1 383 const char *name)
366e034f 384{
d94d92ac 385 uint64_t i;
366e034f
JG
386 struct bt_port *ret_port = NULL;
387
f6ccaed9 388 BT_ASSERT(name);
72b913fb 389
366e034f
JG
390 for (i = 0; i < ports->len; i++) {
391 struct bt_port *port = g_ptr_array_index(ports, i);
366e034f 392
2242b43d 393 if (strcmp(name, port->name->str) == 0) {
d94d92ac 394 ret_port = port;
366e034f
JG
395 break;
396 }
397 }
398
399 return ret_port;
400}
401
402BT_HIDDEN
d94d92ac
PP
403struct bt_port_input *bt_component_borrow_input_port_by_name(
404 struct bt_component *comp, const char *name)
72b913fb 405{
f6ccaed9 406 BT_ASSERT(comp);
d94d92ac 407 return (void *) borrow_port_by_name(comp->input_ports, name);
72b913fb
PP
408}
409
410BT_HIDDEN
d94d92ac
PP
411struct bt_port_output *bt_component_borrow_output_port_by_name(
412 struct bt_component *comp, const char *name)
72b913fb 413{
bdb288b3 414 BT_ASSERT_PRE_DEV_NON_NULL(comp, "Component");
d94d92ac
PP
415 return (void *)
416 borrow_port_by_name(comp->output_ports, name);
72b913fb
PP
417}
418
419static
d94d92ac 420struct bt_port *borrow_port_by_index(GPtrArray *ports, uint64_t index)
366e034f 421{
d94d92ac
PP
422 BT_ASSERT(index < ports->len);
423 return g_ptr_array_index(ports, index);
366e034f
JG
424}
425
426BT_HIDDEN
d94d92ac
PP
427struct bt_port_input *bt_component_borrow_input_port_by_index(
428 struct bt_component *comp, uint64_t index)
366e034f 429{
bdb288b3
PP
430 BT_ASSERT_PRE_DEV_NON_NULL(comp, "Component");
431 BT_ASSERT_PRE_DEV_VALID_INDEX(index, comp->input_ports->len);
d94d92ac
PP
432 return (void *)
433 borrow_port_by_index(comp->input_ports, index);
72b913fb 434}
366e034f 435
72b913fb 436BT_HIDDEN
d94d92ac
PP
437struct bt_port_output *bt_component_borrow_output_port_by_index(
438 struct bt_component *comp, uint64_t index)
72b913fb 439{
bdb288b3
PP
440 BT_ASSERT_PRE_DEV_NON_NULL(comp, "Component");
441 BT_ASSERT_PRE_DEV_VALID_INDEX(index, comp->output_ports->len);
d94d92ac
PP
442 return (void *)
443 borrow_port_by_index(comp->output_ports, index);
72b913fb 444}
366e034f 445
72b913fb 446BT_HIDDEN
d24d5663 447enum bt_self_component_add_port_status bt_component_add_input_port(
3e9b0023 448 struct bt_component *component, const char *name,
8cc56726 449 void *user_data, struct bt_port **port)
72b913fb 450{
d94d92ac 451 /* add_port() logs details */
8cc56726
SM
452 return add_port(component, component->input_ports,
453 BT_PORT_TYPE_INPUT, name, user_data, port);
72b913fb 454}
366e034f 455
72b913fb 456BT_HIDDEN
d24d5663 457enum bt_self_component_add_port_status bt_component_add_output_port(
3e9b0023 458 struct bt_component *component, const char *name,
8cc56726 459 void *user_data, struct bt_port **port)
72b913fb 460{
d94d92ac 461 /* add_port() logs details */
8cc56726
SM
462 return add_port(component, component->output_ports,
463 BT_PORT_TYPE_OUTPUT, name, user_data, port);
72b913fb
PP
464}
465
157a98ed
SM
466BT_HIDDEN
467bool bt_component_port_name_is_unique(GPtrArray *ports, const char *name)
468{
469 guint i;
470 bool unique;
471
472 for (i = 0; i < ports->len; i++) {
473 struct bt_port *port = g_ptr_array_index(ports, i);
474
475 if (strcmp(port->name->str, name) == 0) {
476 unique = false;
477 goto end;
478 }
479 }
480
481 unique = true;
482
483end:
484 return unique;
485}
486
0d8b4d8e 487BT_HIDDEN
d24d5663
PP
488enum bt_component_class_port_connected_method_status
489bt_component_port_connected(
d94d92ac
PP
490 struct bt_component *comp, struct bt_port *self_port,
491 struct bt_port *other_port)
0d8b4d8e 492{
d24d5663 493 typedef enum bt_component_class_port_connected_method_status (*method_t)(
0d72b8c3 494 void *, void *, const void *);
d94d92ac 495
9275bef4 496 enum bt_component_class_port_connected_method_status status =
d24d5663 497 BT_FUNC_STATUS_OK;
d94d92ac 498 method_t method = NULL;
bf55043c 499
f6ccaed9
PP
500 BT_ASSERT(comp);
501 BT_ASSERT(self_port);
502 BT_ASSERT(other_port);
0d8b4d8e 503
d94d92ac
PP
504 switch (comp->class->type) {
505 case BT_COMPONENT_CLASS_TYPE_SOURCE:
506 {
507 struct bt_component_class_source *src_cc = (void *) comp->class;
508
509 switch (self_port->type) {
510 case BT_PORT_TYPE_OUTPUT:
511 method = (method_t) src_cc->methods.output_port_connected;
512 break;
513 default:
498e7994 514 bt_common_abort();
d94d92ac
PP
515 }
516
517 break;
518 }
519 case BT_COMPONENT_CLASS_TYPE_FILTER:
520 {
521 struct bt_component_class_filter *flt_cc = (void *) comp->class;
522
523 switch (self_port->type) {
524 case BT_PORT_TYPE_INPUT:
525 method = (method_t) flt_cc->methods.input_port_connected;
526 break;
527 case BT_PORT_TYPE_OUTPUT:
528 method = (method_t) flt_cc->methods.output_port_connected;
529 break;
530 default:
498e7994 531 bt_common_abort();
d94d92ac
PP
532 }
533
534 break;
535 }
536 case BT_COMPONENT_CLASS_TYPE_SINK:
537 {
538 struct bt_component_class_sink *sink_cc = (void *) comp->class;
539
540 switch (self_port->type) {
541 case BT_PORT_TYPE_INPUT:
542 method = (method_t) sink_cc->methods.input_port_connected;
543 break;
544 default:
498e7994 545 bt_common_abort();
d94d92ac
PP
546 }
547
548 break;
549 }
550 default:
498e7994 551 bt_common_abort();
d94d92ac
PP
552 }
553
554 if (method) {
555 BT_LIB_LOGD("Calling user's \"port connected\" method: "
556 "%![comp-]+c, %![self-port-]+p, %![other-port-]+p",
557 comp, self_port, other_port);
d24d5663 558 status = (int) method(comp, self_port, (void *) other_port);
d94d92ac 559 BT_LOGD("User method returned: status=%s",
d24d5663
PP
560 bt_common_func_status_string(status));
561 BT_ASSERT_POST(status == BT_FUNC_STATUS_OK ||
562 status == BT_FUNC_STATUS_ERROR ||
563 status == BT_FUNC_STATUS_MEMORY_ERROR,
4725a201 564 "Unexpected returned component status: status=%s",
d24d5663 565 bt_common_func_status_string(status));
6ecdcca3 566 BT_ASSERT_POST_NO_ERROR_IF_NO_ERROR_STATUS(status);
0d8b4d8e 567 }
bf55043c
PP
568
569 return status;
0d8b4d8e
PP
570}
571
3230ee6b
PP
572BT_HIDDEN
573void bt_component_add_destroy_listener(struct bt_component *component,
574 bt_component_destroy_listener_func func, void *data)
575{
576 struct bt_component_destroy_listener listener;
577
f6ccaed9
PP
578 BT_ASSERT(component);
579 BT_ASSERT(func);
3230ee6b
PP
580 listener.func = func;
581 listener.data = data;
582 g_array_append_val(component->destroy_listeners, listener);
3f7d4d90 583 BT_LIB_LOGD("Added destroy listener: %![comp-]+c, "
ab0d387b 584 "func-addr=%p, data-addr=%p",
d94d92ac 585 component, func, data);
3230ee6b
PP
586}
587
588BT_HIDDEN
589void bt_component_remove_destroy_listener(struct bt_component *component,
590 bt_component_destroy_listener_func func, void *data)
591{
d94d92ac 592 uint64_t i;
3230ee6b 593
f6ccaed9
PP
594 BT_ASSERT(component);
595 BT_ASSERT(func);
3230ee6b
PP
596
597 for (i = 0; i < component->destroy_listeners->len; i++) {
598 struct bt_component_destroy_listener *listener =
599 &g_array_index(component->destroy_listeners,
600 struct bt_component_destroy_listener, i);
601
602 if (listener->func == func && listener->data == data) {
603 g_array_remove_index(component->destroy_listeners, i);
604 i--;
3f7d4d90 605 BT_LIB_LOGD("Removed destroy listener: %![comp-]+c, "
ab0d387b 606 "func-addr=%p, data-addr=%p",
d94d92ac 607 component, func, data);
3230ee6b
PP
608 }
609 }
610}
c5b9b441 611
e874da19
PP
612bt_logging_level bt_component_get_logging_level(
613 const struct bt_component *component)
614{
bdb288b3 615 BT_ASSERT_PRE_DEV_NON_NULL(component, "Component");
e874da19
PP
616 return component->log_level;
617}
618
056deb59
PP
619uint64_t bt_self_component_get_graph_mip_version(
620 bt_self_component *self_component)
621{
622 struct bt_component *comp = (void *) self_component;
623
624 BT_ASSERT_PRE_NON_NULL(self_component, "Component");
625 return bt_component_borrow_graph(comp)->mip_version;
626}
627
c5b9b441
PP
628void bt_component_get_ref(const struct bt_component *component)
629{
630 bt_object_get_ref(component);
631}
632
633void bt_component_put_ref(const struct bt_component *component)
634{
635 bt_object_put_ref(component);
636}
This page took 0.107278 seconds and 4 git commands to generate.