lib: remove unused includes
[babeltrace.git] / src / lib / plugin / plugin-so.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 */
7
8 #define BT_LOG_TAG "LIB/PLUGIN-SO"
9 #include "lib/logging.h"
10
11 #include "common/assert.h"
12 #include "compat/compiler.h"
13 #include <babeltrace2/plugin/plugin-dev.h>
14 #include "lib/graph/component-class.h"
15 #include <babeltrace2/graph/component-class.h>
16 #include <babeltrace2/types.h>
17 #include "common/list.h"
18 #include <string.h>
19 #include <stdbool.h>
20 #include <stdlib.h>
21 #include <glib.h>
22 #include <gmodule.h>
23
24 #include "plugin.h"
25 #include "plugin-so.h"
26 #include "lib/func-status.h"
27 #include "common/common.h"
28
29 #define NATIVE_PLUGIN_SUFFIX "." G_MODULE_SUFFIX
30 #define NATIVE_PLUGIN_SUFFIX_LEN sizeof(NATIVE_PLUGIN_SUFFIX)
31 #define LIBTOOL_PLUGIN_SUFFIX ".la"
32 #define LIBTOOL_PLUGIN_SUFFIX_LEN sizeof(LIBTOOL_PLUGIN_SUFFIX)
33
34 #define PLUGIN_SUFFIX_LEN bt_max_t(size_t, sizeof(NATIVE_PLUGIN_SUFFIX), \
35 sizeof(LIBTOOL_PLUGIN_SUFFIX))
36
37 BT_PLUGIN_MODULE();
38
39 /*
40 * This list, global to the library, keeps all component classes that
41 * have a reference to their shared library handles. It allows iteration
42 * on all component classes still present when the destructor executes
43 * to release the shared library handle references they might still have.
44 *
45 * The list items are the component classes created with
46 * bt_plugin_add_component_class(). They keep the shared library handle
47 * object created by their plugin alive so that the plugin's code is
48 * not discarded when it could still be in use by living components
49 * created from those component classes:
50 *
51 * [component] --ref-> [component class]-> [shlib handle]
52 *
53 * It allows this use-case:
54 *
55 * my_plugins = bt_plugin_find_all_from_file("/path/to/my-plugin.so");
56 * // instantiate components from a plugin's component classes
57 * // put plugins and free my_plugins here
58 * // user code of instantiated components still exists
59 *
60 * An entry is removed from this list when a component class is
61 * destroyed thanks to a custom destroy listener. When the entry is
62 * removed, the entry is removed from the list, and we release the
63 * reference on the shlib handle. Assuming the original plugin object
64 * which contained some component classes is put first, when the last
65 * component class is removed from this list, the shared library handle
66 * object's reference count falls to zero and the shared library is
67 * finally closed.
68 *
69 * We're not using a GLib linked list here because this destructor is
70 * called after GLib's thread-specific data is destroyed, which contains
71 * the allocated memory for GLib data structures (what's used by
72 * g_slice_alloc()).
73 */
74
75 static
76 BT_LIST_HEAD(component_class_list);
77
78 __attribute__((destructor)) static
79 void fini_comp_class_list(void)
80 {
81 struct bt_component_class *comp_class, *tmp;
82
83 bt_list_for_each_entry_safe(comp_class, tmp, &component_class_list, node) {
84 bt_list_del(&comp_class->node);
85 BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle);
86 }
87
88 BT_LOGD_STR("Released references from all component classes to shared library handles.");
89 }
90
91 static
92 void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj)
93 {
94 struct bt_plugin_so_shared_lib_handle *shared_lib_handle;
95
96 BT_ASSERT(obj);
97 shared_lib_handle = container_of(obj,
98 struct bt_plugin_so_shared_lib_handle, base);
99 const char *path = shared_lib_handle->path ?
100 shared_lib_handle->path->str : NULL;
101
102 BT_LOGI("Destroying shared library handle: addr=%p, path=\"%s\"",
103 shared_lib_handle, path);
104
105 if (shared_lib_handle->init_called && shared_lib_handle->exit) {
106 BT_LOGD_STR("Calling user's plugin exit function.");
107 shared_lib_handle->exit();
108 BT_LOGD_STR("User function returned.");
109 }
110
111 if (shared_lib_handle->module) {
112 #ifdef BT_DEBUG_MODE
113 /*
114 * Valgrind shows incomplete stack traces when
115 * dynamically loaded libraries are closed before it
116 * finishes. Use the LIBBABELTRACE2_NO_DLCLOSE in a debug
117 * build to avoid this.
118 */
119 const char *var = getenv("LIBBABELTRACE2_NO_DLCLOSE");
120
121 if (!var || strcmp(var, "1") != 0) {
122 #endif
123 BT_LOGI("Closing GModule: path=\"%s\"", path);
124
125 if (!g_module_close(shared_lib_handle->module)) {
126 /*
127 * Just log here: we're in a destructor,
128 * so we cannot append an error cause
129 * (there's no returned status).
130 */
131 BT_LOGE("Cannot close GModule: %s: path=\"%s\"",
132 g_module_error(), path);
133 }
134
135 shared_lib_handle->module = NULL;
136 #ifdef BT_DEBUG_MODE
137 } else {
138 BT_LOGI("Not closing GModule because `LIBBABELTRACE2_NO_DLCLOSE=1`: "
139 "path=\"%s\"", path);
140 }
141 #endif
142 }
143
144 if (shared_lib_handle->path) {
145 g_string_free(shared_lib_handle->path, TRUE);
146 shared_lib_handle->path = NULL;
147 }
148
149 g_free(shared_lib_handle);
150 }
151
152 static
153 int bt_plugin_so_shared_lib_handle_create(
154 const char *path,
155 struct bt_plugin_so_shared_lib_handle **shared_lib_handle)
156 {
157 int status = BT_FUNC_STATUS_OK;
158
159 BT_ASSERT(shared_lib_handle);
160 BT_LOGI("Creating shared library handle: path=\"%s\"", path ? path : "(null)");
161 *shared_lib_handle = g_new0(struct bt_plugin_so_shared_lib_handle, 1);
162 if (!*shared_lib_handle) {
163 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one shared library handle.");
164 status = BT_FUNC_STATUS_MEMORY_ERROR;
165 goto end;
166 }
167
168 bt_object_init_shared(&(*shared_lib_handle)->base,
169 bt_plugin_so_shared_lib_handle_destroy);
170
171 if (!path) {
172 goto end;
173 }
174
175 (*shared_lib_handle)->path = g_string_new(path);
176 if (!(*shared_lib_handle)->path) {
177 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
178 status = BT_FUNC_STATUS_MEMORY_ERROR;
179 goto end;
180 }
181
182 (*shared_lib_handle)->module = g_module_open(path, G_MODULE_BIND_LOCAL);
183 if (!(*shared_lib_handle)->module) {
184 /*
185 * INFO-level logging because we're only _trying_ to
186 * open this file as a Babeltrace plugin: if it's not,
187 * it's not an error. And because this can be tried
188 * during bt_plugin_find_all_from_dir(), it's not even a
189 * warning.
190 */
191 BT_LOGI("Cannot open GModule: %s: path=\"%s\"",
192 g_module_error(), path);
193 BT_OBJECT_PUT_REF_AND_RESET(*shared_lib_handle);
194 status = BT_FUNC_STATUS_NOT_FOUND;
195 goto end;
196 }
197
198 goto end;
199
200 end:
201 BT_ASSERT(*shared_lib_handle || status != BT_FUNC_STATUS_OK);
202 if (*shared_lib_handle) {
203 BT_LOGI("Created shared library handle: path=\"%s\", addr=%p",
204 path ? path : "(null)", *shared_lib_handle);
205 }
206
207 return status;
208 }
209
210 static
211 void bt_plugin_so_destroy_spec_data(struct bt_plugin *plugin)
212 {
213 struct bt_plugin_so_spec_data *spec = plugin->spec_data;
214
215 if (!plugin->spec_data) {
216 return;
217 }
218
219 BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO);
220 BT_ASSERT(spec);
221 BT_OBJECT_PUT_REF_AND_RESET(spec->shared_lib_handle);
222 g_free(plugin->spec_data);
223 plugin->spec_data = NULL;
224 }
225
226 /*
227 * This function does the following:
228 *
229 * 1. Iterate on the plugin descriptor attributes section and set the
230 * plugin's attributes depending on the attribute types. This
231 * includes the name of the plugin, its description, and its
232 * initialization function, for example.
233 *
234 * 2. Iterate on the component class descriptors section and create one
235 * "full descriptor" (temporary structure) for each one that is found
236 * and attached to our plugin descriptor.
237 *
238 * 3. Iterate on the component class descriptor attributes section and
239 * set the corresponding full descriptor's attributes depending on
240 * the attribute types. This includes the description of the
241 * component class, as well as its initialization and destroy
242 * methods.
243 *
244 * 4. Call the user's plugin initialization function, if any is
245 * defined.
246 *
247 * 5. For each full component class descriptor, create a component class
248 * object, set its optional attributes, and add it to the plugin
249 * object.
250 *
251 * 6. Freeze the plugin object.
252 */
253 static
254 int bt_plugin_so_init(struct bt_plugin *plugin,
255 bool fail_on_load_error,
256 const struct __bt_plugin_descriptor *descriptor,
257 struct __bt_plugin_descriptor_attribute const * const *attrs_begin,
258 struct __bt_plugin_descriptor_attribute const * const *attrs_end,
259 struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_begin,
260 struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_end,
261 struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_begin,
262 struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_end)
263 {
264 /*
265 * This structure's members point to the plugin's memory
266 * (do NOT free).
267 */
268 struct comp_class_full_descriptor {
269 const struct __bt_plugin_component_class_descriptor *descriptor;
270 const char *description;
271 const char *help;
272
273 union {
274 struct {
275 bt_component_class_source_get_supported_mip_versions_method get_supported_mip_versions;
276 bt_component_class_source_initialize_method init;
277 bt_component_class_source_finalize_method finalize;
278 bt_component_class_source_query_method query;
279 bt_component_class_source_output_port_connected_method output_port_connected;
280 bt_message_iterator_class_initialize_method msg_iter_initialize;
281 bt_message_iterator_class_finalize_method msg_iter_finalize;
282 bt_message_iterator_class_seek_ns_from_origin_method msg_iter_seek_ns_from_origin;
283 bt_message_iterator_class_seek_beginning_method msg_iter_seek_beginning;
284 bt_message_iterator_class_can_seek_ns_from_origin_method msg_iter_can_seek_ns_from_origin;
285 bt_message_iterator_class_can_seek_beginning_method msg_iter_can_seek_beginning;
286 } source;
287
288 struct {
289 bt_component_class_filter_get_supported_mip_versions_method get_supported_mip_versions;
290 bt_component_class_filter_initialize_method init;
291 bt_component_class_filter_finalize_method finalize;
292 bt_component_class_filter_query_method query;
293 bt_component_class_filter_input_port_connected_method input_port_connected;
294 bt_component_class_filter_output_port_connected_method output_port_connected;
295 bt_message_iterator_class_initialize_method msg_iter_initialize;
296 bt_message_iterator_class_finalize_method msg_iter_finalize;
297 bt_message_iterator_class_seek_ns_from_origin_method msg_iter_seek_ns_from_origin;
298 bt_message_iterator_class_seek_beginning_method msg_iter_seek_beginning;
299 bt_message_iterator_class_can_seek_ns_from_origin_method msg_iter_can_seek_ns_from_origin;
300 bt_message_iterator_class_can_seek_beginning_method msg_iter_can_seek_beginning;
301 } filter;
302
303 struct {
304 bt_component_class_sink_get_supported_mip_versions_method get_supported_mip_versions;
305 bt_component_class_sink_initialize_method init;
306 bt_component_class_sink_finalize_method finalize;
307 bt_component_class_sink_query_method query;
308 bt_component_class_sink_input_port_connected_method input_port_connected;
309 bt_component_class_sink_graph_is_configured_method graph_is_configured;
310 } sink;
311 } methods;
312 };
313
314 int status = BT_FUNC_STATUS_OK;
315 struct __bt_plugin_descriptor_attribute const * const *cur_attr_ptr;
316 struct __bt_plugin_component_class_descriptor const * const *cur_cc_descr_ptr;
317 struct __bt_plugin_component_class_descriptor_attribute const * const *cur_cc_descr_attr_ptr;
318 struct bt_plugin_so_spec_data *spec = plugin->spec_data;
319 GArray *comp_class_full_descriptors;
320 size_t i;
321 int ret;
322 struct bt_message_iterator_class *msg_iter_class = NULL;
323
324 BT_LOGI("Initializing plugin object from descriptors found in sections: "
325 "plugin-addr=%p, plugin-path=\"%s\", "
326 "attrs-begin-addr=%p, attrs-end-addr=%p, "
327 "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, "
328 "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p",
329 plugin,
330 spec->shared_lib_handle->path ?
331 spec->shared_lib_handle->path->str : NULL,
332 attrs_begin, attrs_end,
333 cc_descriptors_begin, cc_descriptors_end,
334 cc_descr_attrs_begin, cc_descr_attrs_end);
335 comp_class_full_descriptors = g_array_new(FALSE, TRUE,
336 sizeof(struct comp_class_full_descriptor));
337 if (!comp_class_full_descriptors) {
338 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
339 status = BT_FUNC_STATUS_MEMORY_ERROR;
340 goto end;
341 }
342
343 /* Set mandatory attributes */
344 spec->descriptor = descriptor;
345 bt_plugin_set_name(plugin, descriptor->name);
346
347 /*
348 * Find and set optional attributes attached to this plugin
349 * descriptor.
350 */
351 for (cur_attr_ptr = attrs_begin; cur_attr_ptr != attrs_end; cur_attr_ptr++) {
352 const struct __bt_plugin_descriptor_attribute *cur_attr =
353 *cur_attr_ptr;
354
355 if (!cur_attr) {
356 continue;
357 }
358
359 if (cur_attr->plugin_descriptor != descriptor) {
360 continue;
361 }
362
363 switch (cur_attr->type) {
364 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_INIT:
365 spec->init = cur_attr->value.init;
366 break;
367 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_EXIT:
368 spec->shared_lib_handle->exit = cur_attr->value.exit;
369 break;
370 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_AUTHOR:
371 bt_plugin_set_author(plugin, cur_attr->value.author);
372 break;
373 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_LICENSE:
374 bt_plugin_set_license(plugin, cur_attr->value.license);
375 break;
376 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION:
377 bt_plugin_set_description(plugin, cur_attr->value.description);
378 break;
379 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_VERSION:
380 bt_plugin_set_version(plugin,
381 (unsigned int) cur_attr->value.version.major,
382 (unsigned int) cur_attr->value.version.minor,
383 (unsigned int) cur_attr->value.version.patch,
384 cur_attr->value.version.extra);
385 break;
386 default:
387 if (fail_on_load_error) {
388 BT_LIB_LOGW_APPEND_CAUSE(
389 "Unknown plugin descriptor attribute: "
390 "plugin-path=\"%s\", plugin-name=\"%s\", "
391 "attr-type-name=\"%s\", attr-type-id=%d",
392 spec->shared_lib_handle->path ?
393 spec->shared_lib_handle->path->str :
394 NULL,
395 descriptor->name, cur_attr->type_name,
396 cur_attr->type);
397 status = BT_FUNC_STATUS_ERROR;
398 goto end;
399 } else {
400 BT_LIB_LOGW(
401 "Ignoring unknown plugin descriptor attribute: "
402 "plugin-path=\"%s\", plugin-name=\"%s\", "
403 "attr-type-name=\"%s\", attr-type-id=%d",
404 spec->shared_lib_handle->path ?
405 spec->shared_lib_handle->path->str :
406 NULL,
407 descriptor->name, cur_attr->type_name,
408 cur_attr->type);
409 }
410
411 break;
412 }
413 }
414
415 /*
416 * Find component class descriptors attached to this plugin
417 * descriptor and initialize corresponding full component class
418 * descriptors in the array.
419 */
420 for (cur_cc_descr_ptr = cc_descriptors_begin; cur_cc_descr_ptr != cc_descriptors_end; cur_cc_descr_ptr++) {
421 const struct __bt_plugin_component_class_descriptor *cur_cc_descr =
422 *cur_cc_descr_ptr;
423 struct comp_class_full_descriptor full_descriptor = {0};
424
425 if (!cur_cc_descr) {
426 continue;
427 }
428
429 if (cur_cc_descr->plugin_descriptor != descriptor) {
430 continue;
431 }
432
433 full_descriptor.descriptor = cur_cc_descr;
434 g_array_append_val(comp_class_full_descriptors,
435 full_descriptor);
436 }
437
438 /*
439 * Find component class descriptor attributes attached to this
440 * plugin descriptor and update corresponding full component
441 * class descriptors in the array.
442 */
443 for (cur_cc_descr_attr_ptr = cc_descr_attrs_begin; cur_cc_descr_attr_ptr != cc_descr_attrs_end; cur_cc_descr_attr_ptr++) {
444 const struct __bt_plugin_component_class_descriptor_attribute *cur_cc_descr_attr =
445 *cur_cc_descr_attr_ptr;
446 enum bt_component_class_type cc_type;
447
448 if (!cur_cc_descr_attr) {
449 continue;
450 }
451
452 if (cur_cc_descr_attr->comp_class_descriptor->plugin_descriptor !=
453 descriptor) {
454 continue;
455 }
456
457 cc_type = cur_cc_descr_attr->comp_class_descriptor->type;
458
459 /* Find the corresponding component class descriptor entry */
460 for (i = 0; i < comp_class_full_descriptors->len; i++) {
461 struct comp_class_full_descriptor *cc_full_descr =
462 &bt_g_array_index(comp_class_full_descriptors,
463 struct comp_class_full_descriptor, i);
464
465 if (cur_cc_descr_attr->comp_class_descriptor !=
466 cc_full_descr->descriptor) {
467 continue;
468 }
469
470 switch (cur_cc_descr_attr->type) {
471 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION:
472 cc_full_descr->description =
473 cur_cc_descr_attr->value.description;
474 break;
475 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP:
476 cc_full_descr->help =
477 cur_cc_descr_attr->value.help;
478 break;
479 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_GET_SUPPORTED_MIP_VERSIONS_METHOD:
480 switch (cc_type) {
481 case BT_COMPONENT_CLASS_TYPE_SOURCE:
482 cc_full_descr->methods.source.get_supported_mip_versions =
483 cur_cc_descr_attr->value.source_get_supported_mip_versions_method;
484 break;
485 case BT_COMPONENT_CLASS_TYPE_FILTER:
486 cc_full_descr->methods.filter.get_supported_mip_versions =
487 cur_cc_descr_attr->value.filter_get_supported_mip_versions_method;
488 break;
489 case BT_COMPONENT_CLASS_TYPE_SINK:
490 cc_full_descr->methods.sink.get_supported_mip_versions =
491 cur_cc_descr_attr->value.sink_get_supported_mip_versions_method;
492 break;
493 default:
494 bt_common_abort();
495 }
496 break;
497 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INITIALIZE_METHOD:
498 switch (cc_type) {
499 case BT_COMPONENT_CLASS_TYPE_SOURCE:
500 cc_full_descr->methods.source.init =
501 cur_cc_descr_attr->value.source_initialize_method;
502 break;
503 case BT_COMPONENT_CLASS_TYPE_FILTER:
504 cc_full_descr->methods.filter.init =
505 cur_cc_descr_attr->value.filter_initialize_method;
506 break;
507 case BT_COMPONENT_CLASS_TYPE_SINK:
508 cc_full_descr->methods.sink.init =
509 cur_cc_descr_attr->value.sink_initialize_method;
510 break;
511 default:
512 bt_common_abort();
513 }
514 break;
515 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD:
516 switch (cc_type) {
517 case BT_COMPONENT_CLASS_TYPE_SOURCE:
518 cc_full_descr->methods.source.finalize =
519 cur_cc_descr_attr->value.source_finalize_method;
520 break;
521 case BT_COMPONENT_CLASS_TYPE_FILTER:
522 cc_full_descr->methods.filter.finalize =
523 cur_cc_descr_attr->value.filter_finalize_method;
524 break;
525 case BT_COMPONENT_CLASS_TYPE_SINK:
526 cc_full_descr->methods.sink.finalize =
527 cur_cc_descr_attr->value.sink_finalize_method;
528 break;
529 default:
530 bt_common_abort();
531 }
532 break;
533 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD:
534 switch (cc_type) {
535 case BT_COMPONENT_CLASS_TYPE_SOURCE:
536 cc_full_descr->methods.source.query =
537 cur_cc_descr_attr->value.source_query_method;
538 break;
539 case BT_COMPONENT_CLASS_TYPE_FILTER:
540 cc_full_descr->methods.filter.query =
541 cur_cc_descr_attr->value.filter_query_method;
542 break;
543 case BT_COMPONENT_CLASS_TYPE_SINK:
544 cc_full_descr->methods.sink.query =
545 cur_cc_descr_attr->value.sink_query_method;
546 break;
547 default:
548 bt_common_abort();
549 }
550 break;
551 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD:
552 switch (cc_type) {
553 case BT_COMPONENT_CLASS_TYPE_FILTER:
554 cc_full_descr->methods.filter.input_port_connected =
555 cur_cc_descr_attr->value.filter_input_port_connected_method;
556 break;
557 case BT_COMPONENT_CLASS_TYPE_SINK:
558 cc_full_descr->methods.sink.input_port_connected =
559 cur_cc_descr_attr->value.sink_input_port_connected_method;
560 break;
561 default:
562 bt_common_abort();
563 }
564 break;
565 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD:
566 switch (cc_type) {
567 case BT_COMPONENT_CLASS_TYPE_SOURCE:
568 cc_full_descr->methods.source.output_port_connected =
569 cur_cc_descr_attr->value.source_output_port_connected_method;
570 break;
571 case BT_COMPONENT_CLASS_TYPE_FILTER:
572 cc_full_descr->methods.filter.output_port_connected =
573 cur_cc_descr_attr->value.filter_output_port_connected_method;
574 break;
575 default:
576 bt_common_abort();
577 }
578 break;
579 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_GRAPH_IS_CONFIGURED_METHOD:
580 switch (cc_type) {
581 case BT_COMPONENT_CLASS_TYPE_SINK:
582 cc_full_descr->methods.sink.graph_is_configured =
583 cur_cc_descr_attr->value.sink_graph_is_configured_method;
584 break;
585 default:
586 bt_common_abort();
587 }
588 break;
589 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INITIALIZE_METHOD:
590 switch (cc_type) {
591 case BT_COMPONENT_CLASS_TYPE_SOURCE:
592 cc_full_descr->methods.source.msg_iter_initialize =
593 cur_cc_descr_attr->value.msg_iter_initialize_method;
594 break;
595 case BT_COMPONENT_CLASS_TYPE_FILTER:
596 cc_full_descr->methods.filter.msg_iter_initialize =
597 cur_cc_descr_attr->value.msg_iter_initialize_method;
598 break;
599 default:
600 bt_common_abort();
601 }
602 break;
603 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_FINALIZE_METHOD:
604 switch (cc_type) {
605 case BT_COMPONENT_CLASS_TYPE_SOURCE:
606 cc_full_descr->methods.source.msg_iter_finalize =
607 cur_cc_descr_attr->value.msg_iter_finalize_method;
608 break;
609 case BT_COMPONENT_CLASS_TYPE_FILTER:
610 cc_full_descr->methods.filter.msg_iter_finalize =
611 cur_cc_descr_attr->value.msg_iter_finalize_method;
612 break;
613 default:
614 bt_common_abort();
615 }
616 break;
617 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_NS_FROM_ORIGIN_METHOD:
618 switch (cc_type) {
619 case BT_COMPONENT_CLASS_TYPE_SOURCE:
620 cc_full_descr->methods.source.msg_iter_seek_ns_from_origin =
621 cur_cc_descr_attr->value.msg_iter_seek_ns_from_origin_method;
622 break;
623 case BT_COMPONENT_CLASS_TYPE_FILTER:
624 cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin =
625 cur_cc_descr_attr->value.msg_iter_seek_ns_from_origin_method;
626 break;
627 default:
628 bt_common_abort();
629 }
630 break;
631 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_BEGINNING_METHOD:
632 switch (cc_type) {
633 case BT_COMPONENT_CLASS_TYPE_SOURCE:
634 cc_full_descr->methods.source.msg_iter_seek_beginning =
635 cur_cc_descr_attr->value.msg_iter_seek_beginning_method;
636 break;
637 case BT_COMPONENT_CLASS_TYPE_FILTER:
638 cc_full_descr->methods.filter.msg_iter_seek_beginning =
639 cur_cc_descr_attr->value.msg_iter_seek_beginning_method;
640 break;
641 default:
642 bt_common_abort();
643 }
644 break;
645 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_NS_FROM_ORIGIN_METHOD:
646 switch (cc_type) {
647 case BT_COMPONENT_CLASS_TYPE_SOURCE:
648 cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin =
649 cur_cc_descr_attr->value.msg_iter_can_seek_ns_from_origin_method;
650 break;
651 case BT_COMPONENT_CLASS_TYPE_FILTER:
652 cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin =
653 cur_cc_descr_attr->value.msg_iter_can_seek_ns_from_origin_method;
654 break;
655 default:
656 bt_common_abort();
657 }
658 break;
659 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_BEGINNING_METHOD:
660 switch (cc_type) {
661 case BT_COMPONENT_CLASS_TYPE_SOURCE:
662 cc_full_descr->methods.source.msg_iter_can_seek_beginning =
663 cur_cc_descr_attr->value.msg_iter_can_seek_beginning_method;
664 break;
665 case BT_COMPONENT_CLASS_TYPE_FILTER:
666 cc_full_descr->methods.filter.msg_iter_can_seek_beginning =
667 cur_cc_descr_attr->value.msg_iter_can_seek_beginning_method;
668 break;
669 default:
670 bt_common_abort();
671 }
672 break;
673 default:
674 if (fail_on_load_error) {
675 BT_LIB_LOGW_APPEND_CAUSE(
676 "Unknown component class descriptor attribute: "
677 "plugin-path=\"%s\", "
678 "plugin-name=\"%s\", "
679 "comp-class-name=\"%s\", "
680 "comp-class-type=%s, "
681 "attr-type-name=\"%s\", "
682 "attr-type-id=%d",
683 spec->shared_lib_handle->path ?
684 spec->shared_lib_handle->path->str :
685 NULL,
686 descriptor->name,
687 cur_cc_descr_attr->comp_class_descriptor->name,
688 bt_common_component_class_type_string(
689 cur_cc_descr_attr->comp_class_descriptor->type),
690 cur_cc_descr_attr->type_name,
691 cur_cc_descr_attr->type);
692 status = BT_FUNC_STATUS_ERROR;
693 goto end;
694 } else {
695 BT_LIB_LOGW(
696 "Ignoring unknown component class descriptor attribute: "
697 "plugin-path=\"%s\", "
698 "plugin-name=\"%s\", "
699 "comp-class-name=\"%s\", "
700 "comp-class-type=%s, "
701 "attr-type-name=\"%s\", "
702 "attr-type-id=%d",
703 spec->shared_lib_handle->path ?
704 spec->shared_lib_handle->path->str :
705 NULL,
706 descriptor->name,
707 cur_cc_descr_attr->comp_class_descriptor->name,
708 bt_common_component_class_type_string(
709 cur_cc_descr_attr->comp_class_descriptor->type),
710 cur_cc_descr_attr->type_name,
711 cur_cc_descr_attr->type);
712 }
713
714 break;
715 }
716 }
717 }
718
719 /* Initialize plugin */
720 if (spec->init) {
721 enum bt_plugin_initialize_func_status init_status;
722
723 BT_LOGD_STR("Calling user's plugin initialization function.");
724 init_status = spec->init((void *) plugin);
725 BT_LOGD("User function returned: status=%s",
726 bt_common_func_status_string(init_status));
727
728 if (init_status < 0) {
729 if (fail_on_load_error) {
730 BT_LIB_LOGW_APPEND_CAUSE(
731 "User's plugin initialization function failed: "
732 "status=%s",
733 bt_common_func_status_string(init_status));
734 status = init_status;
735 goto end;
736 } else {
737 BT_LIB_LOGW(
738 "User's plugin initialization function failed: "
739 "status=%s",
740 bt_common_func_status_string(init_status));
741 status = BT_FUNC_STATUS_NOT_FOUND;
742 }
743
744 goto end;
745 }
746 }
747
748 spec->shared_lib_handle->init_called = BT_TRUE;
749
750 /* Add described component classes to plugin */
751 for (i = 0; i < comp_class_full_descriptors->len; i++) {
752 struct comp_class_full_descriptor *cc_full_descr =
753 &bt_g_array_index(comp_class_full_descriptors,
754 struct comp_class_full_descriptor, i);
755 struct bt_component_class *comp_class = NULL;
756 struct bt_component_class_source *src_comp_class = NULL;
757 struct bt_component_class_filter *flt_comp_class = NULL;
758 struct bt_component_class_sink *sink_comp_class = NULL;
759
760 BT_LOGI("Creating and setting properties of plugin's component class: "
761 "plugin-path=\"%s\", plugin-name=\"%s\", "
762 "comp-class-name=\"%s\", comp-class-type=%s",
763 spec->shared_lib_handle->path ?
764 spec->shared_lib_handle->path->str :
765 NULL,
766 descriptor->name,
767 cc_full_descr->descriptor->name,
768 bt_common_component_class_type_string(
769 cc_full_descr->descriptor->type));
770
771 if (cc_full_descr->descriptor->type == BT_COMPONENT_CLASS_TYPE_SOURCE ||
772 cc_full_descr->descriptor->type == BT_COMPONENT_CLASS_TYPE_FILTER) {
773 bt_message_iterator_class_next_method next_method;
774 bt_message_iterator_class_initialize_method init_method;
775 bt_message_iterator_class_finalize_method fini_method;
776 bt_message_iterator_class_seek_ns_from_origin_method seek_ns_from_origin_method;
777 bt_message_iterator_class_seek_beginning_method seek_beginning_method;
778 bt_message_iterator_class_can_seek_ns_from_origin_method can_seek_ns_from_origin_method;
779 bt_message_iterator_class_can_seek_beginning_method can_seek_beginning_method;
780
781 if (cc_full_descr->descriptor->type == BT_COMPONENT_CLASS_TYPE_SOURCE) {
782 next_method = cc_full_descr->descriptor->methods.source.msg_iter_next;
783 init_method = cc_full_descr->methods.source.msg_iter_initialize;
784 fini_method = cc_full_descr->methods.source.msg_iter_finalize;
785 seek_ns_from_origin_method = cc_full_descr->methods.source.msg_iter_seek_ns_from_origin;
786 can_seek_ns_from_origin_method = cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin;
787 seek_beginning_method = cc_full_descr->methods.source.msg_iter_seek_beginning;
788 can_seek_beginning_method = cc_full_descr->methods.source.msg_iter_can_seek_beginning;
789 } else {
790 next_method = cc_full_descr->descriptor->methods.filter.msg_iter_next;
791 init_method = cc_full_descr->methods.filter.msg_iter_initialize;
792 fini_method = cc_full_descr->methods.filter.msg_iter_finalize;
793 seek_ns_from_origin_method = cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin;
794 can_seek_ns_from_origin_method = cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin;
795 seek_beginning_method = cc_full_descr->methods.filter.msg_iter_seek_beginning;
796 can_seek_beginning_method = cc_full_descr->methods.filter.msg_iter_can_seek_beginning;
797 }
798
799 msg_iter_class = bt_message_iterator_class_create(next_method);
800 if (!msg_iter_class) {
801 BT_LIB_LOGE_APPEND_CAUSE(
802 "Cannot create message iterator class.");
803 status = BT_FUNC_STATUS_MEMORY_ERROR;
804 goto end;
805 }
806
807 if (init_method) {
808 ret = bt_message_iterator_class_set_initialize_method(
809 msg_iter_class, init_method);
810 if (ret) {
811 BT_LIB_LOGE_APPEND_CAUSE(
812 "Cannot set message iterator initialization method.");
813 status = BT_FUNC_STATUS_MEMORY_ERROR;
814 goto end;
815 }
816 }
817
818 if (fini_method) {
819 ret = bt_message_iterator_class_set_finalize_method(
820 msg_iter_class, fini_method);
821 if (ret) {
822 BT_LIB_LOGE_APPEND_CAUSE(
823 "Cannot set message iterator finalization method.");
824 status = BT_FUNC_STATUS_MEMORY_ERROR;
825 goto end;
826 }
827 }
828
829 if (seek_ns_from_origin_method) {
830 ret = bt_message_iterator_class_set_seek_ns_from_origin_methods(
831 msg_iter_class,
832 seek_ns_from_origin_method,
833 can_seek_ns_from_origin_method);
834 if (ret) {
835 BT_LIB_LOGE_APPEND_CAUSE(
836 "Cannot set message iterator \"seek nanoseconds from origin\" methods.");
837 status = BT_FUNC_STATUS_MEMORY_ERROR;
838 goto end;
839 }
840 }
841
842 if (seek_beginning_method) {
843 ret = bt_message_iterator_class_set_seek_beginning_methods(
844 msg_iter_class,
845 seek_beginning_method,
846 can_seek_beginning_method);
847 if (ret) {
848 BT_LIB_LOGE_APPEND_CAUSE(
849 "Cannot set message iterator \"seek beginning\" methods.");
850 status = BT_FUNC_STATUS_MEMORY_ERROR;
851 goto end;
852 }
853 }
854 }
855
856 switch (cc_full_descr->descriptor->type) {
857 case BT_COMPONENT_CLASS_TYPE_SOURCE:
858 BT_ASSERT(msg_iter_class);
859
860 src_comp_class = bt_component_class_source_create(
861 cc_full_descr->descriptor->name, msg_iter_class);
862 comp_class = bt_component_class_source_as_component_class(
863 src_comp_class);
864 break;
865 case BT_COMPONENT_CLASS_TYPE_FILTER:
866 BT_ASSERT(msg_iter_class);
867
868 flt_comp_class = bt_component_class_filter_create(
869 cc_full_descr->descriptor->name, msg_iter_class);
870 comp_class = bt_component_class_filter_as_component_class(
871 flt_comp_class);
872 break;
873 case BT_COMPONENT_CLASS_TYPE_SINK:
874 BT_ASSERT(!msg_iter_class);
875
876 sink_comp_class = bt_component_class_sink_create(
877 cc_full_descr->descriptor->name,
878 cc_full_descr->descriptor->methods.sink.consume);
879 comp_class = bt_component_class_sink_as_component_class(
880 sink_comp_class);
881 break;
882 default:
883 if (fail_on_load_error) {
884 BT_LIB_LOGW_APPEND_CAUSE(
885 "Unknown component class type: "
886 "plugin-path=\"%s\", plugin-name=\"%s\", "
887 "comp-class-name=\"%s\", comp-class-type=%d",
888 spec->shared_lib_handle->path->str ?
889 spec->shared_lib_handle->path->str :
890 NULL,
891 descriptor->name,
892 cc_full_descr->descriptor->name,
893 cc_full_descr->descriptor->type);
894 status = BT_FUNC_STATUS_ERROR;
895 goto end;
896 } else {
897 BT_LIB_LOGW(
898 "Ignoring unknown component class type: "
899 "plugin-path=\"%s\", plugin-name=\"%s\", "
900 "comp-class-name=\"%s\", comp-class-type=%d",
901 spec->shared_lib_handle->path->str ?
902 spec->shared_lib_handle->path->str :
903 NULL,
904 descriptor->name,
905 cc_full_descr->descriptor->name,
906 cc_full_descr->descriptor->type);
907 continue;
908 }
909 }
910
911 if (!comp_class) {
912 BT_LIB_LOGE_APPEND_CAUSE(
913 "Cannot create component class.");
914 status = BT_FUNC_STATUS_MEMORY_ERROR;
915 goto end;
916 }
917
918 /*
919 * The component class has taken a reference on the message
920 * iterator class, so we can drop ours. The message iterator
921 * class will get destroyed at the same time as the component
922 * class.
923 */
924 bt_message_iterator_class_put_ref(msg_iter_class);
925 msg_iter_class = NULL;
926
927 if (cc_full_descr->description) {
928 ret = bt_component_class_set_description(
929 comp_class, cc_full_descr->description);
930 if (ret) {
931 BT_LIB_LOGE_APPEND_CAUSE(
932 "Cannot set component class's description.");
933 status = BT_FUNC_STATUS_MEMORY_ERROR;
934 BT_OBJECT_PUT_REF_AND_RESET(comp_class);
935 goto end;
936 }
937 }
938
939 if (cc_full_descr->help) {
940 ret = bt_component_class_set_help(comp_class,
941 cc_full_descr->help);
942 if (ret) {
943 BT_LIB_LOGE_APPEND_CAUSE(
944 "Cannot set component class's help string.");
945 status = BT_FUNC_STATUS_MEMORY_ERROR;
946 BT_OBJECT_PUT_REF_AND_RESET(comp_class);
947 goto end;
948 }
949 }
950
951 switch (cc_full_descr->descriptor->type) {
952 case BT_COMPONENT_CLASS_TYPE_SOURCE:
953 if (cc_full_descr->methods.source.get_supported_mip_versions) {
954 ret = bt_component_class_source_set_get_supported_mip_versions_method(
955 src_comp_class,
956 cc_full_descr->methods.source.get_supported_mip_versions);
957 if (ret) {
958 BT_LIB_LOGE_APPEND_CAUSE(
959 "Cannot set source component class's \"get supported MIP versions\" method.");
960 status = BT_FUNC_STATUS_MEMORY_ERROR;
961 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
962 goto end;
963 }
964 }
965
966 if (cc_full_descr->methods.source.init) {
967 ret = bt_component_class_source_set_initialize_method(
968 src_comp_class,
969 cc_full_descr->methods.source.init);
970 if (ret) {
971 BT_LIB_LOGE_APPEND_CAUSE(
972 "Cannot set source component class's initialization method.");
973 status = BT_FUNC_STATUS_MEMORY_ERROR;
974 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
975 goto end;
976 }
977 }
978
979 if (cc_full_descr->methods.source.finalize) {
980 ret = bt_component_class_source_set_finalize_method(
981 src_comp_class,
982 cc_full_descr->methods.source.finalize);
983 if (ret) {
984 BT_LIB_LOGE_APPEND_CAUSE(
985 "Cannot set source component class's finalization method.");
986 status = BT_FUNC_STATUS_MEMORY_ERROR;
987 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
988 goto end;
989 }
990 }
991
992 if (cc_full_descr->methods.source.query) {
993 ret = bt_component_class_source_set_query_method(
994 src_comp_class,
995 cc_full_descr->methods.source.query);
996 if (ret) {
997 BT_LIB_LOGE_APPEND_CAUSE(
998 "Cannot set source component class's query method.");
999 status = BT_FUNC_STATUS_MEMORY_ERROR;
1000 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
1001 goto end;
1002 }
1003 }
1004
1005 if (cc_full_descr->methods.source.output_port_connected) {
1006 ret = bt_component_class_source_set_output_port_connected_method(
1007 src_comp_class,
1008 cc_full_descr->methods.source.output_port_connected);
1009 if (ret) {
1010 BT_LIB_LOGE_APPEND_CAUSE(
1011 "Cannot set source component class's \"output port connected\" method.");
1012 status = BT_FUNC_STATUS_MEMORY_ERROR;
1013 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
1014 goto end;
1015 }
1016 }
1017
1018 break;
1019 case BT_COMPONENT_CLASS_TYPE_FILTER:
1020 if (cc_full_descr->methods.filter.get_supported_mip_versions) {
1021 ret = bt_component_class_filter_set_get_supported_mip_versions_method(
1022 flt_comp_class,
1023 cc_full_descr->methods.filter.get_supported_mip_versions);
1024 if (ret) {
1025 BT_LIB_LOGE_APPEND_CAUSE(
1026 "Cannot set filter component class's \"get supported MIP versions\" method.");
1027 status = BT_FUNC_STATUS_MEMORY_ERROR;
1028 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
1029 goto end;
1030 }
1031 }
1032
1033 if (cc_full_descr->methods.filter.init) {
1034 ret = bt_component_class_filter_set_initialize_method(
1035 flt_comp_class,
1036 cc_full_descr->methods.filter.init);
1037 if (ret) {
1038 BT_LIB_LOGE_APPEND_CAUSE(
1039 "Cannot set filter component class's initialization method.");
1040 status = BT_FUNC_STATUS_MEMORY_ERROR;
1041 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
1042 goto end;
1043 }
1044 }
1045
1046 if (cc_full_descr->methods.filter.finalize) {
1047 ret = bt_component_class_filter_set_finalize_method(
1048 flt_comp_class,
1049 cc_full_descr->methods.filter.finalize);
1050 if (ret) {
1051 BT_LIB_LOGE_APPEND_CAUSE(
1052 "Cannot set filter component class's finalization method.");
1053 status = BT_FUNC_STATUS_MEMORY_ERROR;
1054 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
1055 goto end;
1056 }
1057 }
1058
1059 if (cc_full_descr->methods.filter.query) {
1060 ret = bt_component_class_filter_set_query_method(
1061 flt_comp_class,
1062 cc_full_descr->methods.filter.query);
1063 if (ret) {
1064 BT_LIB_LOGE_APPEND_CAUSE(
1065 "Cannot set filter component class's query method.");
1066 status = BT_FUNC_STATUS_MEMORY_ERROR;
1067 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
1068 goto end;
1069 }
1070 }
1071
1072 if (cc_full_descr->methods.filter.input_port_connected) {
1073 ret = bt_component_class_filter_set_input_port_connected_method(
1074 flt_comp_class,
1075 cc_full_descr->methods.filter.input_port_connected);
1076 if (ret) {
1077 BT_LIB_LOGE_APPEND_CAUSE(
1078 "Cannot set filter component class's \"input port connected\" method.");
1079 status = BT_FUNC_STATUS_MEMORY_ERROR;
1080 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
1081 goto end;
1082 }
1083 }
1084
1085 if (cc_full_descr->methods.filter.output_port_connected) {
1086 ret = bt_component_class_filter_set_output_port_connected_method(
1087 flt_comp_class,
1088 cc_full_descr->methods.filter.output_port_connected);
1089 if (ret) {
1090 BT_LIB_LOGE_APPEND_CAUSE(
1091 "Cannot set filter component class's \"output port connected\" method.");
1092 status = BT_FUNC_STATUS_MEMORY_ERROR;
1093 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
1094 goto end;
1095 }
1096 }
1097
1098 break;
1099 case BT_COMPONENT_CLASS_TYPE_SINK:
1100 if (cc_full_descr->methods.sink.get_supported_mip_versions) {
1101 ret = bt_component_class_sink_set_get_supported_mip_versions_method(
1102 sink_comp_class,
1103 cc_full_descr->methods.sink.get_supported_mip_versions);
1104 if (ret) {
1105 BT_LIB_LOGE_APPEND_CAUSE(
1106 "Cannot set sink component class's \"get supported MIP versions\" method.");
1107 status = BT_FUNC_STATUS_MEMORY_ERROR;
1108 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
1109 goto end;
1110 }
1111 }
1112
1113 if (cc_full_descr->methods.sink.init) {
1114 ret = bt_component_class_sink_set_initialize_method(
1115 sink_comp_class,
1116 cc_full_descr->methods.sink.init);
1117 if (ret) {
1118 BT_LIB_LOGE_APPEND_CAUSE(
1119 "Cannot set sink component class's initialization method.");
1120 status = BT_FUNC_STATUS_MEMORY_ERROR;
1121 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
1122 goto end;
1123 }
1124 }
1125
1126 if (cc_full_descr->methods.sink.finalize) {
1127 ret = bt_component_class_sink_set_finalize_method(
1128 sink_comp_class,
1129 cc_full_descr->methods.sink.finalize);
1130 if (ret) {
1131 BT_LIB_LOGE_APPEND_CAUSE(
1132 "Cannot set sink component class's finalization method.");
1133 status = BT_FUNC_STATUS_MEMORY_ERROR;
1134 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
1135 goto end;
1136 }
1137 }
1138
1139 if (cc_full_descr->methods.sink.query) {
1140 ret = bt_component_class_sink_set_query_method(
1141 sink_comp_class,
1142 cc_full_descr->methods.sink.query);
1143 if (ret) {
1144 BT_LIB_LOGE_APPEND_CAUSE(
1145 "Cannot set sink component class's query method.");
1146 status = BT_FUNC_STATUS_MEMORY_ERROR;
1147 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
1148 goto end;
1149 }
1150 }
1151
1152 if (cc_full_descr->methods.sink.input_port_connected) {
1153 ret = bt_component_class_sink_set_input_port_connected_method(
1154 sink_comp_class,
1155 cc_full_descr->methods.sink.input_port_connected);
1156 if (ret) {
1157 BT_LIB_LOGE_APPEND_CAUSE(
1158 "Cannot set sink component class's \"input port connected\" method.");
1159 status = BT_FUNC_STATUS_MEMORY_ERROR;
1160 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
1161 goto end;
1162 }
1163 }
1164
1165 if (cc_full_descr->methods.sink.graph_is_configured) {
1166 ret = bt_component_class_sink_set_graph_is_configured_method(
1167 sink_comp_class,
1168 cc_full_descr->methods.sink.graph_is_configured);
1169 if (ret) {
1170 BT_LIB_LOGE_APPEND_CAUSE(
1171 "Cannot set sink component class's \"graph is configured\" method.");
1172 status = BT_FUNC_STATUS_MEMORY_ERROR;
1173 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
1174 goto end;
1175 }
1176 }
1177
1178 break;
1179 default:
1180 bt_common_abort();
1181 }
1182
1183 /*
1184 * Add component class to the plugin object.
1185 *
1186 * This will call back
1187 * bt_plugin_so_on_add_component_class() so that we can
1188 * add a mapping in the component class list when we
1189 * know the component class is successfully added.
1190 */
1191 status = bt_plugin_add_component_class(plugin,
1192 (void *) comp_class);
1193 BT_OBJECT_PUT_REF_AND_RESET(comp_class);
1194 if (status < 0) {
1195 BT_LIB_LOGE_APPEND_CAUSE(
1196 "Cannot add component class to plugin.");
1197 goto end;
1198 }
1199 }
1200
1201 end:
1202 bt_message_iterator_class_put_ref(msg_iter_class);
1203 g_array_free(comp_class_full_descriptors, TRUE);
1204 return status;
1205 }
1206
1207 static
1208 struct bt_plugin *bt_plugin_so_create_empty(
1209 struct bt_plugin_so_shared_lib_handle *shared_lib_handle)
1210 {
1211 struct bt_plugin *plugin;
1212 struct bt_plugin_so_spec_data *spec;
1213
1214 plugin = bt_plugin_create_empty(BT_PLUGIN_TYPE_SO);
1215 if (!plugin) {
1216 goto error;
1217 }
1218
1219 plugin->destroy_spec_data = bt_plugin_so_destroy_spec_data;
1220 plugin->spec_data = g_new0(struct bt_plugin_so_spec_data, 1);
1221 if (!plugin->spec_data) {
1222 BT_LIB_LOGE_APPEND_CAUSE(
1223 "Failed to allocate one SO plugin specific data structure.");
1224 goto error;
1225 }
1226
1227 spec = plugin->spec_data;
1228 spec->shared_lib_handle = shared_lib_handle;
1229 bt_object_get_ref_no_null_check(spec->shared_lib_handle);
1230 goto end;
1231
1232 error:
1233 BT_OBJECT_PUT_REF_AND_RESET(plugin);
1234
1235 end:
1236 return plugin;
1237 }
1238
1239 static
1240 size_t count_non_null_items_in_section(const void *begin, const void *end)
1241 {
1242 size_t count = 0;
1243 const int * const *begin_int = (const int * const *) begin;
1244 const int * const *end_int = (const int * const *) end;
1245 const int * const *iter;
1246
1247 for (iter = begin_int; iter != end_int; iter++) {
1248 if (*iter) {
1249 count++;
1250 }
1251 }
1252
1253 return count;
1254 }
1255
1256 static
1257 int bt_plugin_so_create_all_from_sections(
1258 struct bt_plugin_so_shared_lib_handle *shared_lib_handle,
1259 bool fail_on_load_error,
1260 struct __bt_plugin_descriptor const * const *descriptors_begin,
1261 struct __bt_plugin_descriptor const * const *descriptors_end,
1262 struct __bt_plugin_descriptor_attribute const * const *attrs_begin,
1263 struct __bt_plugin_descriptor_attribute const * const *attrs_end,
1264 struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_begin,
1265 struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_end,
1266 struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_begin,
1267 struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_end,
1268 struct bt_plugin_set **plugin_set_out)
1269 {
1270 int status = BT_FUNC_STATUS_OK;
1271 size_t descriptor_count;
1272 size_t attrs_count;
1273 size_t cc_descriptors_count;
1274 size_t cc_descr_attrs_count;
1275 size_t i;
1276
1277 BT_ASSERT(shared_lib_handle);
1278 BT_ASSERT(plugin_set_out);
1279 *plugin_set_out = NULL;
1280 descriptor_count = count_non_null_items_in_section(descriptors_begin, descriptors_end);
1281 attrs_count = count_non_null_items_in_section(attrs_begin, attrs_end);
1282 cc_descriptors_count = count_non_null_items_in_section(cc_descriptors_begin, cc_descriptors_end);
1283 cc_descr_attrs_count = count_non_null_items_in_section(cc_descr_attrs_begin, cc_descr_attrs_end);
1284 BT_LOGI("Creating all SO plugins from sections: "
1285 "plugin-path=\"%s\", "
1286 "descr-begin-addr=%p, descr-end-addr=%p, "
1287 "attrs-begin-addr=%p, attrs-end-addr=%p, "
1288 "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, "
1289 "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p, "
1290 "descr-count=%zu, attrs-count=%zu, "
1291 "cc-descr-count=%zu, cc-descr-attrs-count=%zu",
1292 shared_lib_handle->path ? shared_lib_handle->path->str : NULL,
1293 descriptors_begin, descriptors_end,
1294 attrs_begin, attrs_end,
1295 cc_descriptors_begin, cc_descriptors_end,
1296 cc_descr_attrs_begin, cc_descr_attrs_end,
1297 descriptor_count, attrs_count,
1298 cc_descriptors_count, cc_descr_attrs_count);
1299 *plugin_set_out = bt_plugin_set_create();
1300 if (!*plugin_set_out) {
1301 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
1302 status = BT_FUNC_STATUS_MEMORY_ERROR;
1303 goto error;
1304 }
1305
1306 for (i = 0; i < descriptors_end - descriptors_begin; i++) {
1307 const struct __bt_plugin_descriptor *descriptor =
1308 descriptors_begin[i];
1309 struct bt_plugin *plugin;
1310
1311 if (!descriptor) {
1312 continue;
1313 }
1314
1315 BT_LOGI("Creating plugin object for plugin: name=\"%s\"",
1316 descriptor->name);
1317 plugin = bt_plugin_so_create_empty(shared_lib_handle);
1318 if (!plugin) {
1319 BT_LIB_LOGE_APPEND_CAUSE(
1320 "Cannot create empty shared library handle.");
1321 status = BT_FUNC_STATUS_MEMORY_ERROR;
1322 goto error;
1323 }
1324
1325 if (shared_lib_handle->path) {
1326 bt_plugin_set_path(plugin,
1327 shared_lib_handle->path->str);
1328 }
1329
1330 status = bt_plugin_so_init(plugin, fail_on_load_error,
1331 descriptor, attrs_begin, attrs_end,
1332 cc_descriptors_begin, cc_descriptors_end,
1333 cc_descr_attrs_begin, cc_descr_attrs_end);
1334 if (status == BT_FUNC_STATUS_OK) {
1335 /* Add to plugin set */
1336 bt_plugin_set_add_plugin(*plugin_set_out, plugin);
1337 BT_OBJECT_PUT_REF_AND_RESET(plugin);
1338 } else if (status < 0) {
1339 /*
1340 * bt_plugin_so_init() handles
1341 * `fail_on_load_error`, so this is a "real"
1342 * error.
1343 */
1344 BT_LIB_LOGW_APPEND_CAUSE(
1345 "Cannot initialize SO plugin object from sections.");
1346 BT_OBJECT_PUT_REF_AND_RESET(plugin);
1347 goto error;
1348 }
1349
1350 BT_ASSERT(!plugin);
1351 }
1352
1353 BT_ASSERT(*plugin_set_out);
1354
1355 if ((*plugin_set_out)->plugins->len == 0) {
1356 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out);
1357 status = BT_FUNC_STATUS_NOT_FOUND;
1358 }
1359
1360 goto end;
1361
1362 error:
1363 BT_ASSERT(status < 0);
1364 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out);
1365
1366 end:
1367 return status;
1368 }
1369
1370 int bt_plugin_so_create_all_from_static(bool fail_on_load_error,
1371 struct bt_plugin_set **plugin_set_out)
1372 {
1373 int status;
1374 struct bt_plugin_so_shared_lib_handle *shared_lib_handle = NULL;
1375
1376 BT_ASSERT(plugin_set_out);
1377 *plugin_set_out = NULL;
1378 status = bt_plugin_so_shared_lib_handle_create(NULL,
1379 &shared_lib_handle);
1380 if (status != BT_FUNC_STATUS_OK) {
1381 BT_ASSERT(!shared_lib_handle);
1382 goto end;
1383 }
1384
1385 BT_ASSERT(shared_lib_handle);
1386 BT_LOGD_STR("Creating all SO plugins from built-in plugins.");
1387 status = bt_plugin_so_create_all_from_sections(shared_lib_handle,
1388 fail_on_load_error,
1389 __bt_get_begin_section_plugin_descriptors(),
1390 __bt_get_end_section_plugin_descriptors(),
1391 __bt_get_begin_section_plugin_descriptor_attributes(),
1392 __bt_get_end_section_plugin_descriptor_attributes(),
1393 __bt_get_begin_section_component_class_descriptors(),
1394 __bt_get_end_section_component_class_descriptors(),
1395 __bt_get_begin_section_component_class_descriptor_attributes(),
1396 __bt_get_end_section_component_class_descriptor_attributes(),
1397 plugin_set_out);
1398 BT_ASSERT((status == BT_FUNC_STATUS_OK && *plugin_set_out &&
1399 (*plugin_set_out)->plugins->len > 0) || !*plugin_set_out);
1400
1401 end:
1402 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle);
1403 return status;
1404 }
1405
1406 int bt_plugin_so_create_all_from_file(const char *path,
1407 bool fail_on_load_error, struct bt_plugin_set **plugin_set_out)
1408 {
1409 size_t path_len;
1410 int status;
1411 struct __bt_plugin_descriptor const * const *descriptors_begin = NULL;
1412 struct __bt_plugin_descriptor const * const *descriptors_end = NULL;
1413 struct __bt_plugin_descriptor_attribute const * const *attrs_begin = NULL;
1414 struct __bt_plugin_descriptor_attribute const * const *attrs_end = NULL;
1415 struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_begin = NULL;
1416 struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_end = NULL;
1417 struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_begin = NULL;
1418 struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_end = NULL;
1419 struct __bt_plugin_descriptor const * const *(*get_begin_section_plugin_descriptors)(void);
1420 struct __bt_plugin_descriptor const * const *(*get_end_section_plugin_descriptors)(void);
1421 struct __bt_plugin_descriptor_attribute const * const *(*get_begin_section_plugin_descriptor_attributes)(void);
1422 struct __bt_plugin_descriptor_attribute const * const *(*get_end_section_plugin_descriptor_attributes)(void);
1423 struct __bt_plugin_component_class_descriptor const * const *(*get_begin_section_component_class_descriptors)(void);
1424 struct __bt_plugin_component_class_descriptor const * const *(*get_end_section_component_class_descriptors)(void);
1425 struct __bt_plugin_component_class_descriptor_attribute const * const *(*get_begin_section_component_class_descriptor_attributes)(void);
1426 struct __bt_plugin_component_class_descriptor_attribute const * const *(*get_end_section_component_class_descriptor_attributes)(void);
1427 bt_bool is_libtool_wrapper = BT_FALSE, is_shared_object = BT_FALSE;
1428 struct bt_plugin_so_shared_lib_handle *shared_lib_handle = NULL;
1429
1430 BT_ASSERT(path);
1431 BT_ASSERT(plugin_set_out);
1432 *plugin_set_out = NULL;
1433 path_len = strlen(path);
1434
1435 /*
1436 * An SO plugin file must have a known plugin file suffix. So the file
1437 * path must be longer than the suffix length.
1438 */
1439 if (path_len <= PLUGIN_SUFFIX_LEN) {
1440 BT_LOGI("Path is too short to be an `.so` or `.la` plugin file:"
1441 "path=%s, path-length=%zu, min-length=%zu",
1442 path, path_len, PLUGIN_SUFFIX_LEN);
1443 status = BT_FUNC_STATUS_NOT_FOUND;
1444 goto end;
1445 }
1446
1447 BT_LOGI("Trying to create all SO plugins from file: path=\"%s\"", path);
1448 path_len++;
1449
1450 /*
1451 * Check if the file ends with a known plugin file type suffix
1452 * (i.e. .so or .la on Linux).
1453 */
1454 is_libtool_wrapper = !strncmp(LIBTOOL_PLUGIN_SUFFIX,
1455 path + path_len - LIBTOOL_PLUGIN_SUFFIX_LEN,
1456 LIBTOOL_PLUGIN_SUFFIX_LEN);
1457 is_shared_object = !strncmp(NATIVE_PLUGIN_SUFFIX,
1458 path + path_len - NATIVE_PLUGIN_SUFFIX_LEN,
1459 NATIVE_PLUGIN_SUFFIX_LEN);
1460 if (!is_shared_object && !is_libtool_wrapper) {
1461 /* Name indicates this is not a plugin file; not an error */
1462 BT_LOGI("File is not an SO plugin file: path=\"%s\"", path);
1463 status = BT_FUNC_STATUS_NOT_FOUND;
1464 goto end;
1465 }
1466
1467 status = bt_plugin_so_shared_lib_handle_create(path,
1468 &shared_lib_handle);
1469 if (status != BT_FUNC_STATUS_OK) {
1470 /* bt_plugin_so_shared_lib_handle_create() logs more details */
1471 BT_ASSERT(!shared_lib_handle);
1472 goto end;
1473 }
1474
1475 if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_plugin_descriptors",
1476 (gpointer *) &get_begin_section_plugin_descriptors)) {
1477 descriptors_begin = get_begin_section_plugin_descriptors();
1478 } else {
1479 /*
1480 * Use this first symbol to know whether or not this
1481 * shared object _looks like_ a Babeltrace plugin. Since
1482 * g_module_symbol() failed, assume that this is not a
1483 * Babeltrace plugin, so it's not an error.
1484 */
1485 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1486 "symbol=\"%s\"", path,
1487 "__bt_get_begin_section_plugin_descriptors");
1488 status = BT_FUNC_STATUS_NOT_FOUND;
1489 goto end;
1490 }
1491
1492 /*
1493 * If g_module_symbol() fails for any of the other symbols, fail
1494 * if `fail_on_load_error` is true.
1495 */
1496 if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_plugin_descriptors",
1497 (gpointer *) &get_end_section_plugin_descriptors)) {
1498 descriptors_end = get_end_section_plugin_descriptors();
1499 } else {
1500 if (fail_on_load_error) {
1501 BT_LIB_LOGW_APPEND_CAUSE(
1502 "Cannot resolve plugin symbol: path=\"%s\", "
1503 "symbol=\"%s\"", path,
1504 "__bt_get_end_section_plugin_descriptors");
1505 status = BT_FUNC_STATUS_ERROR;
1506 } else {
1507 BT_LIB_LOGW(
1508 "Cannot resolve plugin symbol: path=\"%s\", "
1509 "symbol=\"%s\"", path,
1510 "__bt_get_end_section_plugin_descriptors");
1511 status = BT_FUNC_STATUS_NOT_FOUND;
1512 }
1513
1514 goto end;
1515 }
1516
1517 if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_plugin_descriptor_attributes",
1518 (gpointer *) &get_begin_section_plugin_descriptor_attributes)) {
1519 attrs_begin = get_begin_section_plugin_descriptor_attributes();
1520 } else {
1521 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1522 "symbol=\"%s\"", path,
1523 "__bt_get_begin_section_plugin_descriptor_attributes");
1524 }
1525
1526 if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_plugin_descriptor_attributes",
1527 (gpointer *) &get_end_section_plugin_descriptor_attributes)) {
1528 attrs_end = get_end_section_plugin_descriptor_attributes();
1529 } else {
1530 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1531 "symbol=\"%s\"", path,
1532 "__bt_get_end_section_plugin_descriptor_attributes");
1533 }
1534
1535 if ((!!attrs_begin - !!attrs_end) != 0) {
1536 if (fail_on_load_error) {
1537 BT_LIB_LOGW_APPEND_CAUSE(
1538 "Found section start or end symbol, but not both: "
1539 "path=\"%s\", symbol-start=\"%s\", "
1540 "symbol-end=\"%s\", symbol-start-addr=%p, "
1541 "symbol-end-addr=%p",
1542 path, "__bt_get_begin_section_plugin_descriptor_attributes",
1543 "__bt_get_end_section_plugin_descriptor_attributes",
1544 attrs_begin, attrs_end);
1545 status = BT_FUNC_STATUS_ERROR;
1546 } else {
1547 BT_LIB_LOGW(
1548 "Found section start or end symbol, but not both: "
1549 "path=\"%s\", symbol-start=\"%s\", "
1550 "symbol-end=\"%s\", symbol-start-addr=%p, "
1551 "symbol-end-addr=%p",
1552 path, "__bt_get_begin_section_plugin_descriptor_attributes",
1553 "__bt_get_end_section_plugin_descriptor_attributes",
1554 attrs_begin, attrs_end);
1555 status = BT_FUNC_STATUS_NOT_FOUND;
1556 }
1557
1558 goto end;
1559 }
1560
1561 if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_component_class_descriptors",
1562 (gpointer *) &get_begin_section_component_class_descriptors)) {
1563 cc_descriptors_begin = get_begin_section_component_class_descriptors();
1564 } else {
1565 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1566 "symbol=\"%s\"", path,
1567 "__bt_get_begin_section_component_class_descriptors");
1568 }
1569
1570 if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_component_class_descriptors",
1571 (gpointer *) &get_end_section_component_class_descriptors)) {
1572 cc_descriptors_end = get_end_section_component_class_descriptors();
1573 } else {
1574 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1575 "symbol=\"%s\"", path,
1576 "__bt_get_end_section_component_class_descriptors");
1577 }
1578
1579 if ((!!cc_descriptors_begin - !!cc_descriptors_end) != 0) {
1580 if (fail_on_load_error) {
1581 BT_LIB_LOGW_APPEND_CAUSE(
1582 "Found section start or end symbol, but not both: "
1583 "path=\"%s\", symbol-start=\"%s\", "
1584 "symbol-end=\"%s\", symbol-start-addr=%p, "
1585 "symbol-end-addr=%p",
1586 path, "__bt_get_begin_section_component_class_descriptors",
1587 "__bt_get_end_section_component_class_descriptors",
1588 cc_descriptors_begin, cc_descriptors_end);
1589 status = BT_FUNC_STATUS_ERROR;
1590 } else {
1591 BT_LIB_LOGW(
1592 "Found section start or end symbol, but not both: "
1593 "path=\"%s\", symbol-start=\"%s\", "
1594 "symbol-end=\"%s\", symbol-start-addr=%p, "
1595 "symbol-end-addr=%p",
1596 path, "__bt_get_begin_section_component_class_descriptors",
1597 "__bt_get_end_section_component_class_descriptors",
1598 cc_descriptors_begin, cc_descriptors_end);
1599 status = BT_FUNC_STATUS_NOT_FOUND;
1600 }
1601
1602 goto end;
1603 }
1604
1605 if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_component_class_descriptor_attributes",
1606 (gpointer *) &get_begin_section_component_class_descriptor_attributes)) {
1607 cc_descr_attrs_begin = get_begin_section_component_class_descriptor_attributes();
1608 } else {
1609 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1610 "symbol=\"%s\"", path,
1611 "__bt_get_begin_section_component_class_descriptor_attributes");
1612 }
1613
1614 if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_component_class_descriptor_attributes",
1615 (gpointer *) &get_end_section_component_class_descriptor_attributes)) {
1616 cc_descr_attrs_end = get_end_section_component_class_descriptor_attributes();
1617 } else {
1618 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1619 "symbol=\"%s\"", path,
1620 "__bt_get_end_section_component_class_descriptor_attributes");
1621 }
1622
1623 if ((!!cc_descr_attrs_begin - !!cc_descr_attrs_end) != 0) {
1624 if (fail_on_load_error) {
1625 BT_LIB_LOGW_APPEND_CAUSE(
1626 "Found section start or end symbol, but not both: "
1627 "path=\"%s\", symbol-start=\"%s\", "
1628 "symbol-end=\"%s\", symbol-start-addr=%p, "
1629 "symbol-end-addr=%p",
1630 path, "__bt_get_begin_section_component_class_descriptor_attributes",
1631 "__bt_get_end_section_component_class_descriptor_attributes",
1632 cc_descr_attrs_begin, cc_descr_attrs_end);
1633 status = BT_FUNC_STATUS_ERROR;
1634 } else {
1635 BT_LIB_LOGW(
1636 "Found section start or end symbol, but not both: "
1637 "path=\"%s\", symbol-start=\"%s\", "
1638 "symbol-end=\"%s\", symbol-start-addr=%p, "
1639 "symbol-end-addr=%p",
1640 path, "__bt_get_begin_section_component_class_descriptor_attributes",
1641 "__bt_get_end_section_component_class_descriptor_attributes",
1642 cc_descr_attrs_begin, cc_descr_attrs_end);
1643 status = BT_FUNC_STATUS_NOT_FOUND;
1644 }
1645
1646 goto end;
1647 }
1648
1649 /* Initialize plugin */
1650 BT_LOGD_STR("Initializing plugin object.");
1651 status = bt_plugin_so_create_all_from_sections(shared_lib_handle,
1652 fail_on_load_error,
1653 descriptors_begin, descriptors_end, attrs_begin, attrs_end,
1654 cc_descriptors_begin, cc_descriptors_end,
1655 cc_descr_attrs_begin, cc_descr_attrs_end, plugin_set_out);
1656
1657 end:
1658 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle);
1659 return status;
1660 }
1661
1662 static
1663 void plugin_comp_class_destroy_listener(struct bt_component_class *comp_class,
1664 void *data __attribute__((unused)))
1665 {
1666 bt_list_del(&comp_class->node);
1667 BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle);
1668 BT_LOGD("Component class destroyed: removed entry from list: "
1669 "comp-cls-addr=%p", comp_class);
1670 }
1671
1672 /*
1673 * This function would normally not be BT_EXPORTed, but it is used by the
1674 * Python plugin provider, which is conceptually part of libbabeltrace2, but
1675 * implemented as a separate shared object, for modularity. It is therefore
1676 * exposed, but not part of the public ABI.
1677 */
1678 BT_EXPORT
1679 void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin,
1680 struct bt_component_class *comp_class)
1681 {
1682 struct bt_plugin_so_spec_data *spec = plugin->spec_data;
1683
1684 BT_ASSERT(plugin->spec_data);
1685 BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO);
1686
1687 bt_list_add(&comp_class->node, &component_class_list);
1688 comp_class->so_handle = spec->shared_lib_handle;
1689 bt_object_get_ref_no_null_check(comp_class->so_handle);
1690
1691 /* Add our custom destroy listener */
1692 bt_component_class_add_destroy_listener(comp_class,
1693 plugin_comp_class_destroy_listener, NULL);
1694 }
This page took 0.098475 seconds and 4 git commands to generate.