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