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