| 1 | /* |
| 2 | * component.c |
| 3 | * |
| 4 | * Babeltrace Plugin Component |
| 5 | * |
| 6 | * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 7 | * |
| 8 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 9 | * |
| 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 11 | * of this software and associated documentation files (the "Software"), to deal |
| 12 | * in the Software without restriction, including without limitation the rights |
| 13 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 14 | * copies of the Software, and to permit persons to whom the Software is |
| 15 | * furnished to do so, subject to the following conditions: |
| 16 | * |
| 17 | * The above copyright notice and this permission notice shall be included in |
| 18 | * all copies or substantial portions of the Software. |
| 19 | * |
| 20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 21 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 23 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 24 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 25 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 26 | * SOFTWARE. |
| 27 | */ |
| 28 | |
| 29 | #include <babeltrace/graph/private-component.h> |
| 30 | #include <babeltrace/graph/component.h> |
| 31 | #include <babeltrace/graph/component-internal.h> |
| 32 | #include <babeltrace/graph/component-class-internal.h> |
| 33 | #include <babeltrace/graph/component-source-internal.h> |
| 34 | #include <babeltrace/graph/component-filter-internal.h> |
| 35 | #include <babeltrace/graph/component-sink-internal.h> |
| 36 | #include <babeltrace/graph/private-connection.h> |
| 37 | #include <babeltrace/graph/connection-internal.h> |
| 38 | #include <babeltrace/graph/graph-internal.h> |
| 39 | #include <babeltrace/graph/notification-iterator-internal.h> |
| 40 | #include <babeltrace/graph/private-notification-iterator.h> |
| 41 | #include <babeltrace/babeltrace-internal.h> |
| 42 | #include <babeltrace/compiler-internal.h> |
| 43 | #include <babeltrace/ref.h> |
| 44 | #include <babeltrace/types.h> |
| 45 | #include <stdint.h> |
| 46 | |
| 47 | static |
| 48 | struct bt_component * (* const component_create_funcs[])( |
| 49 | struct bt_component_class *, struct bt_value *) = { |
| 50 | [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_create, |
| 51 | [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_create, |
| 52 | [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_create, |
| 53 | }; |
| 54 | |
| 55 | static |
| 56 | void (*component_destroy_funcs[])(struct bt_component *) = { |
| 57 | [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_destroy, |
| 58 | [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_destroy, |
| 59 | [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_destroy, |
| 60 | }; |
| 61 | |
| 62 | static |
| 63 | enum bt_component_status (* const component_validation_funcs[])( |
| 64 | struct bt_component *) = { |
| 65 | [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_validate, |
| 66 | [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_validate, |
| 67 | [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_validate, |
| 68 | }; |
| 69 | |
| 70 | static |
| 71 | void bt_component_destroy(struct bt_object *obj) |
| 72 | { |
| 73 | struct bt_component *component = NULL; |
| 74 | struct bt_component_class *component_class = NULL; |
| 75 | int i; |
| 76 | |
| 77 | if (!obj) { |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * The component's reference count is 0 if we're here. Increment |
| 83 | * it to avoid a double-destroy (possibly infinitely recursive). |
| 84 | * This could happen for example if the component's finalization |
| 85 | * function does bt_get() (or anything that causes bt_get() to |
| 86 | * be called) on itself (ref. count goes from 0 to 1), and then |
| 87 | * bt_put(): the reference count would go from 1 to 0 again and |
| 88 | * this function would be called again. |
| 89 | */ |
| 90 | obj->ref_count.count++; |
| 91 | component = container_of(obj, struct bt_component, base); |
| 92 | |
| 93 | /* Call destroy listeners in reverse registration order */ |
| 94 | for (i = component->destroy_listeners->len - 1; i >= 0; i--) { |
| 95 | struct bt_component_destroy_listener *listener = |
| 96 | &g_array_index(component->destroy_listeners, |
| 97 | struct bt_component_destroy_listener, i); |
| 98 | |
| 99 | listener->func(component, listener->data); |
| 100 | } |
| 101 | |
| 102 | component_class = component->class; |
| 103 | |
| 104 | /* |
| 105 | * User data is destroyed first, followed by the concrete component |
| 106 | * instance. |
| 107 | */ |
| 108 | if (component->class->methods.finalize) { |
| 109 | component->class->methods.finalize( |
| 110 | bt_private_component_from_component(component)); |
| 111 | } |
| 112 | |
| 113 | if (component->destroy) { |
| 114 | component->destroy(component); |
| 115 | } |
| 116 | |
| 117 | if (component->input_ports) { |
| 118 | g_ptr_array_free(component->input_ports, TRUE); |
| 119 | } |
| 120 | |
| 121 | if (component->output_ports) { |
| 122 | g_ptr_array_free(component->output_ports, TRUE); |
| 123 | } |
| 124 | |
| 125 | if (component->destroy_listeners) { |
| 126 | g_array_free(component->destroy_listeners, TRUE); |
| 127 | } |
| 128 | |
| 129 | g_string_free(component->name, TRUE); |
| 130 | bt_put(component_class); |
| 131 | g_free(component); |
| 132 | } |
| 133 | |
| 134 | struct bt_component *bt_component_from_private_component( |
| 135 | struct bt_private_component *private_component) |
| 136 | { |
| 137 | return bt_get(bt_component_from_private(private_component)); |
| 138 | } |
| 139 | |
| 140 | enum bt_component_class_type bt_component_get_class_type( |
| 141 | struct bt_component *component) |
| 142 | { |
| 143 | return component ? component->class->type : BT_COMPONENT_CLASS_TYPE_UNKNOWN; |
| 144 | } |
| 145 | |
| 146 | static |
| 147 | struct bt_port *bt_component_add_port( |
| 148 | struct bt_component *component, GPtrArray *ports, |
| 149 | enum bt_port_type port_type, const char *name, void *user_data) |
| 150 | { |
| 151 | size_t i; |
| 152 | struct bt_port *new_port = NULL; |
| 153 | struct bt_graph *graph = NULL; |
| 154 | |
| 155 | if (!name || strlen(name) == 0) { |
| 156 | goto end; |
| 157 | } |
| 158 | |
| 159 | /* Look for a port having the same name. */ |
| 160 | for (i = 0; i < ports->len; i++) { |
| 161 | const char *port_name; |
| 162 | struct bt_port *port = g_ptr_array_index( |
| 163 | ports, i); |
| 164 | |
| 165 | port_name = bt_port_get_name(port); |
| 166 | if (!port_name) { |
| 167 | continue; |
| 168 | } |
| 169 | |
| 170 | if (!strcmp(name, port_name)) { |
| 171 | /* Port name clash, abort. */ |
| 172 | goto end; |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | new_port = bt_port_create(component, port_type, name, user_data); |
| 177 | if (!new_port) { |
| 178 | goto end; |
| 179 | } |
| 180 | |
| 181 | /* |
| 182 | * No name clash, add the port. |
| 183 | * The component is now the port's parent; it should _not_ |
| 184 | * hold a reference to the port since the port's lifetime |
| 185 | * is now protected by the component's own lifetime. |
| 186 | */ |
| 187 | g_ptr_array_add(ports, new_port); |
| 188 | |
| 189 | /* |
| 190 | * Notify the graph's creator that a new port was added. |
| 191 | */ |
| 192 | graph = bt_component_get_graph(component); |
| 193 | if (graph) { |
| 194 | bt_graph_notify_port_added(graph, new_port); |
| 195 | BT_PUT(graph); |
| 196 | } |
| 197 | |
| 198 | end: |
| 199 | return new_port; |
| 200 | } |
| 201 | |
| 202 | BT_HIDDEN |
| 203 | int64_t bt_component_get_input_port_count(struct bt_component *comp) |
| 204 | { |
| 205 | assert(comp); |
| 206 | return (int64_t) comp->input_ports->len; |
| 207 | } |
| 208 | |
| 209 | BT_HIDDEN |
| 210 | int64_t bt_component_get_output_port_count(struct bt_component *comp) |
| 211 | { |
| 212 | assert(comp); |
| 213 | return (int64_t) comp->output_ports->len; |
| 214 | } |
| 215 | |
| 216 | struct bt_component *bt_component_create_with_init_method_data( |
| 217 | struct bt_component_class *component_class, const char *name, |
| 218 | struct bt_value *params, void *init_method_data) |
| 219 | { |
| 220 | int ret; |
| 221 | struct bt_component *component = NULL; |
| 222 | enum bt_component_class_type type; |
| 223 | |
| 224 | bt_get(params); |
| 225 | |
| 226 | if (!component_class) { |
| 227 | goto end; |
| 228 | } |
| 229 | |
| 230 | type = bt_component_class_get_type(component_class); |
| 231 | if (type <= BT_COMPONENT_CLASS_TYPE_UNKNOWN || |
| 232 | type > BT_COMPONENT_CLASS_TYPE_FILTER) { |
| 233 | goto end; |
| 234 | } |
| 235 | |
| 236 | /* |
| 237 | * Parameters must be a map value, but we create a convenient |
| 238 | * empty one if it's NULL. |
| 239 | */ |
| 240 | if (params) { |
| 241 | if (!bt_value_is_map(params)) { |
| 242 | goto end; |
| 243 | } |
| 244 | } else { |
| 245 | params = bt_value_map_create(); |
| 246 | if (!params) { |
| 247 | goto end; |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | component = component_create_funcs[type](component_class, params); |
| 252 | if (!component) { |
| 253 | goto end; |
| 254 | } |
| 255 | |
| 256 | bt_object_init(component, bt_component_destroy); |
| 257 | component->class = bt_get(component_class); |
| 258 | component->destroy = component_destroy_funcs[type]; |
| 259 | component->name = g_string_new(name); |
| 260 | if (!component->name) { |
| 261 | BT_PUT(component); |
| 262 | goto end; |
| 263 | } |
| 264 | |
| 265 | component->input_ports = g_ptr_array_new_with_free_func( |
| 266 | bt_object_release); |
| 267 | if (!component->input_ports) { |
| 268 | BT_PUT(component); |
| 269 | goto end; |
| 270 | } |
| 271 | |
| 272 | component->output_ports = g_ptr_array_new_with_free_func( |
| 273 | bt_object_release); |
| 274 | if (!component->output_ports) { |
| 275 | BT_PUT(component); |
| 276 | goto end; |
| 277 | } |
| 278 | |
| 279 | component->destroy_listeners = g_array_new(FALSE, TRUE, |
| 280 | sizeof(struct bt_component_destroy_listener)); |
| 281 | if (!component->destroy_listeners) { |
| 282 | BT_PUT(component); |
| 283 | goto end; |
| 284 | } |
| 285 | |
| 286 | component->initializing = BT_TRUE; |
| 287 | |
| 288 | if (component_class->methods.init) { |
| 289 | ret = component_class->methods.init( |
| 290 | bt_private_component_from_component(component), params, |
| 291 | init_method_data); |
| 292 | component->initializing = BT_FALSE; |
| 293 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 294 | BT_PUT(component); |
| 295 | goto end; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | component->initializing = BT_FALSE; |
| 300 | ret = component_validation_funcs[type](component); |
| 301 | if (ret != BT_COMPONENT_STATUS_OK) { |
| 302 | BT_PUT(component); |
| 303 | goto end; |
| 304 | } |
| 305 | |
| 306 | bt_component_class_freeze(component->class); |
| 307 | end: |
| 308 | bt_put(params); |
| 309 | return component; |
| 310 | } |
| 311 | |
| 312 | struct bt_component *bt_component_create( |
| 313 | struct bt_component_class *component_class, const char *name, |
| 314 | struct bt_value *params) |
| 315 | { |
| 316 | return bt_component_create_with_init_method_data(component_class, name, |
| 317 | params, NULL); |
| 318 | } |
| 319 | |
| 320 | const char *bt_component_get_name(struct bt_component *component) |
| 321 | { |
| 322 | const char *ret = NULL; |
| 323 | |
| 324 | if (!component) { |
| 325 | goto end; |
| 326 | } |
| 327 | |
| 328 | ret = component->name->len == 0 ? NULL : component->name->str; |
| 329 | end: |
| 330 | return ret; |
| 331 | } |
| 332 | |
| 333 | struct bt_component_class *bt_component_get_class( |
| 334 | struct bt_component *component) |
| 335 | { |
| 336 | return component ? bt_get(component->class) : NULL; |
| 337 | } |
| 338 | |
| 339 | void *bt_private_component_get_user_data( |
| 340 | struct bt_private_component *private_component) |
| 341 | { |
| 342 | struct bt_component *component = |
| 343 | bt_component_from_private(private_component); |
| 344 | |
| 345 | return component ? component->user_data : NULL; |
| 346 | } |
| 347 | |
| 348 | enum bt_component_status bt_private_component_set_user_data( |
| 349 | struct bt_private_component *private_component, |
| 350 | void *data) |
| 351 | { |
| 352 | struct bt_component *component = |
| 353 | bt_component_from_private(private_component); |
| 354 | enum bt_component_status ret = BT_COMPONENT_STATUS_OK; |
| 355 | |
| 356 | if (!component || !component->initializing) { |
| 357 | ret = BT_COMPONENT_STATUS_INVALID; |
| 358 | goto end; |
| 359 | } |
| 360 | |
| 361 | component->user_data = data; |
| 362 | end: |
| 363 | return ret; |
| 364 | } |
| 365 | |
| 366 | BT_HIDDEN |
| 367 | void bt_component_set_graph(struct bt_component *component, |
| 368 | struct bt_graph *graph) |
| 369 | { |
| 370 | struct bt_object *parent = bt_object_get_parent(&component->base); |
| 371 | |
| 372 | assert(!parent || parent == &graph->base); |
| 373 | if (!parent) { |
| 374 | bt_object_set_parent(component, &graph->base); |
| 375 | } |
| 376 | bt_put(parent); |
| 377 | } |
| 378 | |
| 379 | struct bt_graph *bt_component_get_graph( |
| 380 | struct bt_component *component) |
| 381 | { |
| 382 | return (struct bt_graph *) bt_object_get_parent(&component->base); |
| 383 | } |
| 384 | |
| 385 | static |
| 386 | struct bt_port *bt_component_get_port_by_name(GPtrArray *ports, |
| 387 | const char *name) |
| 388 | { |
| 389 | size_t i; |
| 390 | struct bt_port *ret_port = NULL; |
| 391 | |
| 392 | assert(name); |
| 393 | |
| 394 | for (i = 0; i < ports->len; i++) { |
| 395 | struct bt_port *port = g_ptr_array_index(ports, i); |
| 396 | const char *port_name = bt_port_get_name(port); |
| 397 | |
| 398 | if (!port_name) { |
| 399 | continue; |
| 400 | } |
| 401 | |
| 402 | if (!strcmp(name, port_name)) { |
| 403 | ret_port = bt_get(port); |
| 404 | break; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | return ret_port; |
| 409 | } |
| 410 | |
| 411 | BT_HIDDEN |
| 412 | struct bt_port *bt_component_get_input_port_by_name(struct bt_component *comp, |
| 413 | const char *name) |
| 414 | { |
| 415 | assert(comp); |
| 416 | |
| 417 | return bt_component_get_port_by_name(comp->input_ports, name); |
| 418 | } |
| 419 | |
| 420 | BT_HIDDEN |
| 421 | struct bt_port *bt_component_get_output_port_by_name(struct bt_component *comp, |
| 422 | const char *name) |
| 423 | { |
| 424 | assert(comp); |
| 425 | |
| 426 | return bt_component_get_port_by_name(comp->output_ports, name); |
| 427 | } |
| 428 | |
| 429 | static |
| 430 | struct bt_port *bt_component_get_port_by_index(GPtrArray *ports, uint64_t index) |
| 431 | { |
| 432 | struct bt_port *port = NULL; |
| 433 | |
| 434 | if (index >= ports->len) { |
| 435 | goto end; |
| 436 | } |
| 437 | |
| 438 | port = bt_get(g_ptr_array_index(ports, index)); |
| 439 | end: |
| 440 | return port; |
| 441 | } |
| 442 | |
| 443 | BT_HIDDEN |
| 444 | struct bt_port *bt_component_get_input_port_by_index(struct bt_component *comp, |
| 445 | uint64_t index) |
| 446 | { |
| 447 | assert(comp); |
| 448 | |
| 449 | return bt_component_get_port_by_index(comp->input_ports, index); |
| 450 | } |
| 451 | |
| 452 | BT_HIDDEN |
| 453 | struct bt_port *bt_component_get_output_port_by_index(struct bt_component *comp, |
| 454 | uint64_t index) |
| 455 | { |
| 456 | assert(comp); |
| 457 | |
| 458 | return bt_component_get_port_by_index(comp->output_ports, index); |
| 459 | } |
| 460 | |
| 461 | BT_HIDDEN |
| 462 | struct bt_port *bt_component_add_input_port( |
| 463 | struct bt_component *component, const char *name, |
| 464 | void *user_data) |
| 465 | { |
| 466 | return bt_component_add_port(component, component->input_ports, |
| 467 | BT_PORT_TYPE_INPUT, name, user_data); |
| 468 | } |
| 469 | |
| 470 | BT_HIDDEN |
| 471 | struct bt_port *bt_component_add_output_port( |
| 472 | struct bt_component *component, const char *name, |
| 473 | void *user_data) |
| 474 | { |
| 475 | return bt_component_add_port(component, component->output_ports, |
| 476 | BT_PORT_TYPE_OUTPUT, name, user_data); |
| 477 | } |
| 478 | |
| 479 | static |
| 480 | void bt_component_remove_port_by_index(struct bt_component *component, |
| 481 | GPtrArray *ports, size_t index) |
| 482 | { |
| 483 | struct bt_port *port; |
| 484 | struct bt_graph *graph; |
| 485 | |
| 486 | assert(ports); |
| 487 | assert(index < ports->len); |
| 488 | port = g_ptr_array_index(ports, index); |
| 489 | |
| 490 | /* Disconnect both ports of this port's connection, if any */ |
| 491 | if (port->connection) { |
| 492 | bt_connection_disconnect_ports(port->connection); |
| 493 | } |
| 494 | |
| 495 | /* Remove from parent's array of ports (weak refs) */ |
| 496 | g_ptr_array_remove_index(ports, index); |
| 497 | |
| 498 | /* Detach port from its component parent */ |
| 499 | BT_PUT(port->base.parent); |
| 500 | |
| 501 | /* |
| 502 | * Notify the graph's creator that a port is removed. |
| 503 | */ |
| 504 | graph = bt_component_get_graph(component); |
| 505 | if (graph) { |
| 506 | bt_graph_notify_port_removed(graph, component, port); |
| 507 | BT_PUT(graph); |
| 508 | } |
| 509 | } |
| 510 | |
| 511 | BT_HIDDEN |
| 512 | enum bt_component_status bt_component_remove_port( |
| 513 | struct bt_component *component, struct bt_port *port) |
| 514 | { |
| 515 | size_t i; |
| 516 | enum bt_component_status status = BT_COMPONENT_STATUS_OK; |
| 517 | GPtrArray *ports = NULL; |
| 518 | |
| 519 | if (!component || !port) { |
| 520 | status = BT_COMPONENT_STATUS_INVALID; |
| 521 | goto end; |
| 522 | } |
| 523 | |
| 524 | if (bt_port_get_type(port) == BT_PORT_TYPE_INPUT) { |
| 525 | ports = component->input_ports; |
| 526 | } else if (bt_port_get_type(port) == BT_PORT_TYPE_OUTPUT) { |
| 527 | ports = component->output_ports; |
| 528 | } |
| 529 | |
| 530 | assert(ports); |
| 531 | |
| 532 | for (i = 0; i < ports->len; i++) { |
| 533 | struct bt_port *cur_port = g_ptr_array_index(ports, i); |
| 534 | |
| 535 | if (cur_port == port) { |
| 536 | bt_component_remove_port_by_index(component, |
| 537 | ports, i); |
| 538 | goto end; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | status = BT_COMPONENT_STATUS_NOT_FOUND; |
| 543 | end: |
| 544 | return status; |
| 545 | } |
| 546 | |
| 547 | BT_HIDDEN |
| 548 | enum bt_component_status bt_component_accept_port_connection( |
| 549 | struct bt_component *comp, struct bt_port *self_port, |
| 550 | struct bt_port *other_port) |
| 551 | { |
| 552 | enum bt_component_status status = BT_COMPONENT_STATUS_OK; |
| 553 | |
| 554 | assert(comp); |
| 555 | assert(self_port); |
| 556 | assert(other_port); |
| 557 | |
| 558 | if (comp->class->methods.accept_port_connection) { |
| 559 | status = comp->class->methods.accept_port_connection( |
| 560 | bt_private_component_from_component(comp), |
| 561 | bt_private_port_from_port(self_port), |
| 562 | other_port); |
| 563 | } |
| 564 | |
| 565 | return status; |
| 566 | } |
| 567 | |
| 568 | BT_HIDDEN |
| 569 | void bt_component_port_connected(struct bt_component *comp, |
| 570 | struct bt_port *self_port, struct bt_port *other_port) |
| 571 | { |
| 572 | assert(comp); |
| 573 | assert(self_port); |
| 574 | assert(other_port); |
| 575 | |
| 576 | if (comp->class->methods.port_connected) { |
| 577 | comp->class->methods.port_connected( |
| 578 | bt_private_component_from_component(comp), |
| 579 | bt_private_port_from_port(self_port), other_port); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | BT_HIDDEN |
| 584 | void bt_component_port_disconnected(struct bt_component *comp, |
| 585 | struct bt_port *port) |
| 586 | { |
| 587 | assert(comp); |
| 588 | assert(port); |
| 589 | |
| 590 | if (comp->class->methods.port_disconnected) { |
| 591 | comp->class->methods.port_disconnected( |
| 592 | bt_private_component_from_component(comp), |
| 593 | bt_private_port_from_port(port)); |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | BT_HIDDEN |
| 598 | void bt_component_add_destroy_listener(struct bt_component *component, |
| 599 | bt_component_destroy_listener_func func, void *data) |
| 600 | { |
| 601 | struct bt_component_destroy_listener listener; |
| 602 | |
| 603 | assert(component); |
| 604 | assert(func); |
| 605 | listener.func = func; |
| 606 | listener.data = data; |
| 607 | g_array_append_val(component->destroy_listeners, listener); |
| 608 | } |
| 609 | |
| 610 | BT_HIDDEN |
| 611 | void bt_component_remove_destroy_listener(struct bt_component *component, |
| 612 | bt_component_destroy_listener_func func, void *data) |
| 613 | { |
| 614 | size_t i; |
| 615 | |
| 616 | assert(component); |
| 617 | assert(func); |
| 618 | |
| 619 | for (i = 0; i < component->destroy_listeners->len; i++) { |
| 620 | struct bt_component_destroy_listener *listener = |
| 621 | &g_array_index(component->destroy_listeners, |
| 622 | struct bt_component_destroy_listener, i); |
| 623 | |
| 624 | if (listener->func == func && listener->data == data) { |
| 625 | g_array_remove_index(component->destroy_listeners, i); |
| 626 | i--; |
| 627 | } |
| 628 | } |
| 629 | } |