2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
5 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #define BT_LOG_TAG "PLUGIN-SO"
27 #include <babeltrace/lib-logging-internal.h>
29 #include <babeltrace/compiler-internal.h>
30 #include <babeltrace/object.h>
31 #include <babeltrace/plugin/plugin-internal.h>
32 #include <babeltrace/plugin/plugin-so-internal.h>
33 #include <babeltrace/plugin/plugin-dev.h>
34 #include <babeltrace/plugin/plugin-internal.h>
35 #include <babeltrace/graph/component-class-internal.h>
36 #include <babeltrace/graph/private-component-class.h>
37 #include <babeltrace/graph/private-component-class-source.h>
38 #include <babeltrace/graph/private-component-class-filter.h>
39 #include <babeltrace/graph/private-component-class-sink.h>
40 #include <babeltrace/types.h>
41 #include <babeltrace/list-internal.h>
42 #include <babeltrace/assert-internal.h>
48 #define NATIVE_PLUGIN_SUFFIX "." G_MODULE_SUFFIX
49 #define NATIVE_PLUGIN_SUFFIX_LEN sizeof(NATIVE_PLUGIN_SUFFIX)
50 #define LIBTOOL_PLUGIN_SUFFIX ".la"
51 #define LIBTOOL_PLUGIN_SUFFIX_LEN sizeof(LIBTOOL_PLUGIN_SUFFIX)
53 #define PLUGIN_SUFFIX_LEN max_t(size_t, sizeof(NATIVE_PLUGIN_SUFFIX), \
54 sizeof(LIBTOOL_PLUGIN_SUFFIX))
59 * This list, global to the library, keeps all component classes that
60 * have a reference to their shared library handles. It allows iteration
61 * on all component classes still present when the destructor executes
62 * to release the shared library handle references they might still have.
64 * The list items are the component classes created with
65 * bt_plugin_add_component_class(). They keep the shared library handle
66 * object created by their plugin alive so that the plugin's code is
67 * not discarded when it could still be in use by living components
68 * created from those component classes:
70 * [component] --ref-> [component class]-> [shlib handle]
72 * It allows this use-case:
74 * my_plugins = bt_plugin_create_all_from_file("/path/to/my-plugin.so");
75 * // instantiate components from a plugin's component classes
76 * // put plugins and free my_plugins here
77 * // user code of instantiated components still exists
79 * An entry is removed from this list when a component class is
80 * destroyed thanks to a custom destroy listener. When the entry is
81 * removed, the entry is removed from the list, and we release the
82 * reference on the shlib handle. Assuming the original plugin object
83 * which contained some component classes is put first, when the last
84 * component class is removed from this list, the shared library handle
85 * object's reference count falls to zero and the shared library is
90 BT_LIST_HEAD(component_class_list
);
92 __attribute__((destructor
)) static
93 void fini_comp_class_list(void)
95 struct bt_component_class
*comp_class
, *tmp
;
97 bt_list_for_each_entry_safe(comp_class
, tmp
, &component_class_list
, node
) {
98 bt_list_del(&comp_class
->node
);
99 BT_OBJECT_PUT_REF_AND_RESET(comp_class
->so_handle
);
102 BT_LOGD_STR("Released references from all component classes to shared library handles.");
106 void bt_plugin_so_shared_lib_handle_destroy(struct bt_object
*obj
)
108 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
;
111 shared_lib_handle
= container_of(obj
,
112 struct bt_plugin_so_shared_lib_handle
, base
);
113 const char *path
= shared_lib_handle
->path
?
114 shared_lib_handle
->path
->str
: NULL
;
116 BT_LOGD("Destroying shared library handle: addr=%p, path=\"%s\"",
117 shared_lib_handle
, path
);
119 if (shared_lib_handle
->init_called
&& shared_lib_handle
->exit
) {
120 enum bt_plugin_status status
;
122 BT_LOGD_STR("Calling user's plugin exit function.");
123 status
= shared_lib_handle
->exit();
124 BT_LOGD("User function returned: %s",
125 bt_plugin_status_string(status
));
128 BT_LOGW("User's plugin exit function failed: "
129 "path=\"%s\"", path
);
133 if (shared_lib_handle
->module
) {
136 * Valgrind shows incomplete stack traces when
137 * dynamically loaded libraries are closed before it
138 * finishes. Use the BABELTRACE_NO_DLCLOSE in a debug
139 * build to avoid this.
141 const char *var
= getenv("BABELTRACE_NO_DLCLOSE");
143 if (!var
|| strcmp(var
, "1") != 0) {
145 BT_LOGD("Closing GModule: path=\"%s\"", path
);
147 if (!g_module_close(shared_lib_handle
->module
)) {
148 BT_LOGE("Cannot close GModule: %s: path=\"%s\"",
149 g_module_error(), path
);
153 BT_LOGD("Not closing GModule because `BABELTRACE_NO_DLCLOSE=1`: "
154 "path=\"%s\"", path
);
159 if (shared_lib_handle
->path
) {
160 g_string_free(shared_lib_handle
->path
, TRUE
);
163 g_free(shared_lib_handle
);
167 struct bt_plugin_so_shared_lib_handle
*bt_plugin_so_shared_lib_handle_create(
170 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
= NULL
;
172 BT_LOGD("Creating shared library handle: path=\"%s\"", path
);
173 shared_lib_handle
= g_new0(struct bt_plugin_so_shared_lib_handle
, 1);
174 if (!shared_lib_handle
) {
175 BT_LOGE_STR("Failed to allocate one shared library handle.");
179 bt_object_init_shared(&shared_lib_handle
->base
,
180 bt_plugin_so_shared_lib_handle_destroy
);
186 shared_lib_handle
->path
= g_string_new(path
);
187 if (!shared_lib_handle
->path
) {
188 BT_LOGE_STR("Failed to allocate a GString.");
192 shared_lib_handle
->module
= g_module_open(path
, G_MODULE_BIND_LOCAL
);
193 if (!shared_lib_handle
->module
) {
195 * DEBUG-level logging because we're only _trying_ to
196 * open this file as a Babeltrace plugin: if it's not,
197 * it's not an error. And because this can be tried
198 * during bt_plugin_create_all_from_dir(), it's not even
201 BT_LOGD("Cannot open GModule: %s: path=\"%s\"",
202 g_module_error(), path
);
209 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle
);
212 if (shared_lib_handle
) {
213 BT_LOGD("Created shared library handle: path=\"%s\", addr=%p",
214 path
, shared_lib_handle
);
217 return shared_lib_handle
;
221 void bt_plugin_so_destroy_spec_data(struct bt_plugin
*plugin
)
223 struct bt_plugin_so_spec_data
*spec
= plugin
->spec_data
;
225 if (!plugin
->spec_data
) {
229 BT_ASSERT(plugin
->type
== BT_PLUGIN_TYPE_SO
);
231 BT_OBJECT_PUT_REF_AND_RESET(spec
->shared_lib_handle
);
232 g_free(plugin
->spec_data
);
233 plugin
->spec_data
= NULL
;
237 * This function does the following:
239 * 1. Iterate on the plugin descriptor attributes section and set the
240 * plugin's attributes depending on the attribute types. This
241 * includes the name of the plugin, its description, and its
242 * initialization function, for example.
244 * 2. Iterate on the component class descriptors section and create one
245 * "full descriptor" (temporary structure) for each one that is found
246 * and attached to our plugin descriptor.
248 * 3. Iterate on the component class descriptor attributes section and
249 * set the corresponding full descriptor's attributes depending on
250 * the attribute types. This includes the description of the
251 * component class, as well as its initialization and destroy
254 * 4. Call the user's plugin initialization function, if any is
257 * 5. For each full component class descriptor, create a component class
258 * object, set its optional attributes, and add it to the plugin
261 * 6. Freeze the plugin object.
264 enum bt_plugin_status
bt_plugin_so_init(
265 struct bt_plugin
*plugin
,
266 const struct __bt_plugin_descriptor
*descriptor
,
267 struct __bt_plugin_descriptor_attribute
const * const *attrs_begin
,
268 struct __bt_plugin_descriptor_attribute
const * const *attrs_end
,
269 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_begin
,
270 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_end
,
271 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_begin
,
272 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_end
)
275 * This structure's members point to the plugin's memory
278 struct comp_class_full_descriptor
{
279 const struct __bt_plugin_component_class_descriptor
*descriptor
;
280 const char *description
;
285 bt_private_component_class_source_init_method init
;
286 bt_private_component_class_source_finalize_method finalize
;
287 bt_private_component_class_source_query_method query
;
288 bt_private_component_class_source_accept_output_port_connection_method accept_output_port_connection
;
289 bt_private_component_class_source_output_port_connected_method output_port_connected
;
290 bt_private_component_class_source_output_port_disconnected_method output_port_disconnected
;
291 bt_private_component_class_source_notification_iterator_init_method notif_iter_init
;
292 bt_private_component_class_source_notification_iterator_finalize_method notif_iter_finalize
;
296 bt_private_component_class_filter_init_method init
;
297 bt_private_component_class_filter_finalize_method finalize
;
298 bt_private_component_class_filter_query_method query
;
299 bt_private_component_class_filter_accept_input_port_connection_method accept_input_port_connection
;
300 bt_private_component_class_filter_accept_output_port_connection_method accept_output_port_connection
;
301 bt_private_component_class_filter_input_port_connected_method input_port_connected
;
302 bt_private_component_class_filter_output_port_connected_method output_port_connected
;
303 bt_private_component_class_filter_input_port_disconnected_method input_port_disconnected
;
304 bt_private_component_class_filter_output_port_disconnected_method output_port_disconnected
;
305 bt_private_component_class_filter_notification_iterator_init_method notif_iter_init
;
306 bt_private_component_class_filter_notification_iterator_finalize_method notif_iter_finalize
;
310 bt_private_component_class_sink_init_method init
;
311 bt_private_component_class_sink_finalize_method finalize
;
312 bt_private_component_class_sink_query_method query
;
313 bt_private_component_class_sink_accept_input_port_connection_method accept_input_port_connection
;
314 bt_private_component_class_sink_input_port_connected_method input_port_connected
;
315 bt_private_component_class_sink_input_port_disconnected_method input_port_disconnected
;
320 enum bt_plugin_status status
= BT_PLUGIN_STATUS_OK
;
321 struct __bt_plugin_descriptor_attribute
const * const *cur_attr_ptr
;
322 struct __bt_plugin_component_class_descriptor
const * const *cur_cc_descr_ptr
;
323 struct __bt_plugin_component_class_descriptor_attribute
const * const *cur_cc_descr_attr_ptr
;
324 struct bt_plugin_so_spec_data
*spec
= plugin
->spec_data
;
325 GArray
*comp_class_full_descriptors
;
329 BT_LOGD("Initializing plugin object from descriptors found in sections: "
330 "plugin-addr=%p, plugin-path=\"%s\", "
331 "attrs-begin-addr=%p, attrs-end-addr=%p, "
332 "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, "
333 "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p",
335 spec
->shared_lib_handle
->path
?
336 spec
->shared_lib_handle
->path
->str
: NULL
,
337 attrs_begin
, attrs_end
,
338 cc_descriptors_begin
, cc_descriptors_end
,
339 cc_descr_attrs_begin
, cc_descr_attrs_end
);
340 comp_class_full_descriptors
= g_array_new(FALSE
, TRUE
,
341 sizeof(struct comp_class_full_descriptor
));
342 if (!comp_class_full_descriptors
) {
343 BT_LOGE_STR("Failed to allocate a GArray.");
344 status
= BT_PLUGIN_STATUS_ERROR
;
348 /* Set mandatory attributes */
349 spec
->descriptor
= descriptor
;
350 bt_plugin_set_name(plugin
, descriptor
->name
);
353 * Find and set optional attributes attached to this plugin
356 for (cur_attr_ptr
= attrs_begin
; cur_attr_ptr
!= attrs_end
; cur_attr_ptr
++) {
357 const struct __bt_plugin_descriptor_attribute
*cur_attr
=
360 if (cur_attr
== NULL
) {
364 if (cur_attr
->plugin_descriptor
!= descriptor
) {
368 switch (cur_attr
->type
) {
369 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_INIT
:
370 spec
->init
= cur_attr
->value
.init
;
372 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_EXIT
:
373 spec
->shared_lib_handle
->exit
= cur_attr
->value
.exit
;
375 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_AUTHOR
:
376 bt_plugin_set_author(plugin
, cur_attr
->value
.author
);
378 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_LICENSE
:
379 bt_plugin_set_license(plugin
, cur_attr
->value
.license
);
381 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION
:
382 bt_plugin_set_description(plugin
, cur_attr
->value
.description
);
384 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_VERSION
:
385 bt_plugin_set_version(plugin
,
386 (unsigned int) cur_attr
->value
.version
.major
,
387 (unsigned int) cur_attr
->value
.version
.minor
,
388 (unsigned int) cur_attr
->value
.version
.patch
,
389 cur_attr
->value
.version
.extra
);
393 * WARN-level logging because this should not
394 * happen with the appropriate ABI version. If
395 * we're here, we know that for the reported
396 * version of the ABI, this attribute is
399 BT_LOGW("Ignoring unknown plugin descriptor attribute: "
400 "plugin-path=\"%s\", plugin-name=\"%s\", "
401 "attr-type-name=\"%s\", attr-type-id=%d",
402 spec
->shared_lib_handle
->path
?
403 spec
->shared_lib_handle
->path
->str
:
405 descriptor
->name
, cur_attr
->type_name
,
412 * Find component class descriptors attached to this plugin
413 * descriptor and initialize corresponding full component class
414 * descriptors in the array.
416 for (cur_cc_descr_ptr
= cc_descriptors_begin
; cur_cc_descr_ptr
!= cc_descriptors_end
; cur_cc_descr_ptr
++) {
417 const struct __bt_plugin_component_class_descriptor
*cur_cc_descr
=
419 struct comp_class_full_descriptor full_descriptor
= {0};
421 if (cur_cc_descr
== NULL
) {
425 if (cur_cc_descr
->plugin_descriptor
!= descriptor
) {
429 full_descriptor
.descriptor
= cur_cc_descr
;
430 g_array_append_val(comp_class_full_descriptors
,
435 * Find component class descriptor attributes attached to this
436 * plugin descriptor and update corresponding full component
437 * class descriptors in the array.
439 for (cur_cc_descr_attr_ptr
= cc_descr_attrs_begin
; cur_cc_descr_attr_ptr
!= cc_descr_attrs_end
; cur_cc_descr_attr_ptr
++) {
440 const struct __bt_plugin_component_class_descriptor_attribute
*cur_cc_descr_attr
=
441 *cur_cc_descr_attr_ptr
;
442 enum bt_component_class_type cc_type
;
444 if (cur_cc_descr_attr
== NULL
) {
448 if (cur_cc_descr_attr
->comp_class_descriptor
->plugin_descriptor
!=
453 cc_type
= cur_cc_descr_attr
->comp_class_descriptor
->type
;
455 /* Find the corresponding component class descriptor entry */
456 for (i
= 0; i
< comp_class_full_descriptors
->len
; i
++) {
457 struct comp_class_full_descriptor
*cc_full_descr
=
458 &g_array_index(comp_class_full_descriptors
,
459 struct comp_class_full_descriptor
, i
);
461 if (cur_cc_descr_attr
->comp_class_descriptor
!=
462 cc_full_descr
->descriptor
) {
466 switch (cur_cc_descr_attr
->type
) {
467 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION
:
468 cc_full_descr
->description
=
469 cur_cc_descr_attr
->value
.description
;
471 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP
:
472 cc_full_descr
->help
=
473 cur_cc_descr_attr
->value
.help
;
475 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD
:
477 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
478 cc_full_descr
->methods
.source
.init
=
479 cur_cc_descr_attr
->value
.source_init_method
;
481 case BT_COMPONENT_CLASS_TYPE_FILTER
:
482 cc_full_descr
->methods
.filter
.init
=
483 cur_cc_descr_attr
->value
.filter_init_method
;
485 case BT_COMPONENT_CLASS_TYPE_SINK
:
486 cc_full_descr
->methods
.sink
.init
=
487 cur_cc_descr_attr
->value
.sink_init_method
;
493 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD
:
495 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
496 cc_full_descr
->methods
.source
.finalize
=
497 cur_cc_descr_attr
->value
.source_finalize_method
;
499 case BT_COMPONENT_CLASS_TYPE_FILTER
:
500 cc_full_descr
->methods
.filter
.finalize
=
501 cur_cc_descr_attr
->value
.filter_finalize_method
;
503 case BT_COMPONENT_CLASS_TYPE_SINK
:
504 cc_full_descr
->methods
.sink
.finalize
=
505 cur_cc_descr_attr
->value
.sink_finalize_method
;
511 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD
:
513 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
514 cc_full_descr
->methods
.source
.query
=
515 cur_cc_descr_attr
->value
.source_query_method
;
517 case BT_COMPONENT_CLASS_TYPE_FILTER
:
518 cc_full_descr
->methods
.filter
.query
=
519 cur_cc_descr_attr
->value
.filter_query_method
;
521 case BT_COMPONENT_CLASS_TYPE_SINK
:
522 cc_full_descr
->methods
.sink
.query
=
523 cur_cc_descr_attr
->value
.sink_query_method
;
529 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_INPUT_PORT_CONNECTION_METHOD
:
531 case BT_COMPONENT_CLASS_TYPE_FILTER
:
532 cc_full_descr
->methods
.filter
.accept_input_port_connection
=
533 cur_cc_descr_attr
->value
.filter_accept_input_port_connection_method
;
535 case BT_COMPONENT_CLASS_TYPE_SINK
:
536 cc_full_descr
->methods
.sink
.accept_input_port_connection
=
537 cur_cc_descr_attr
->value
.sink_accept_input_port_connection_method
;
543 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD
:
545 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
546 cc_full_descr
->methods
.source
.accept_output_port_connection
=
547 cur_cc_descr_attr
->value
.source_accept_output_port_connection_method
;
549 case BT_COMPONENT_CLASS_TYPE_FILTER
:
550 cc_full_descr
->methods
.filter
.accept_output_port_connection
=
551 cur_cc_descr_attr
->value
.filter_accept_output_port_connection_method
;
557 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD
:
559 case BT_COMPONENT_CLASS_TYPE_FILTER
:
560 cc_full_descr
->methods
.filter
.input_port_connected
=
561 cur_cc_descr_attr
->value
.filter_input_port_connected_method
;
563 case BT_COMPONENT_CLASS_TYPE_SINK
:
564 cc_full_descr
->methods
.sink
.input_port_connected
=
565 cur_cc_descr_attr
->value
.sink_input_port_connected_method
;
571 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD
:
573 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
574 cc_full_descr
->methods
.source
.output_port_connected
=
575 cur_cc_descr_attr
->value
.source_output_port_connected_method
;
577 case BT_COMPONENT_CLASS_TYPE_FILTER
:
578 cc_full_descr
->methods
.filter
.output_port_connected
=
579 cur_cc_descr_attr
->value
.filter_output_port_connected_method
;
585 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD
:
587 case BT_COMPONENT_CLASS_TYPE_FILTER
:
588 cc_full_descr
->methods
.filter
.input_port_disconnected
=
589 cur_cc_descr_attr
->value
.filter_input_port_disconnected_method
;
591 case BT_COMPONENT_CLASS_TYPE_SINK
:
592 cc_full_descr
->methods
.sink
.input_port_disconnected
=
593 cur_cc_descr_attr
->value
.sink_input_port_disconnected_method
;
599 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD
:
601 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
602 cc_full_descr
->methods
.source
.output_port_disconnected
=
603 cur_cc_descr_attr
->value
.source_output_port_disconnected_method
;
605 case BT_COMPONENT_CLASS_TYPE_FILTER
:
606 cc_full_descr
->methods
.filter
.output_port_disconnected
=
607 cur_cc_descr_attr
->value
.filter_output_port_disconnected_method
;
613 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD
:
615 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
616 cc_full_descr
->methods
.source
.notif_iter_init
=
617 cur_cc_descr_attr
->value
.source_notif_iter_init_method
;
619 case BT_COMPONENT_CLASS_TYPE_FILTER
:
620 cc_full_descr
->methods
.filter
.notif_iter_init
=
621 cur_cc_descr_attr
->value
.filter_notif_iter_init_method
;
627 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD
:
629 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
630 cc_full_descr
->methods
.source
.notif_iter_finalize
=
631 cur_cc_descr_attr
->value
.source_notif_iter_finalize_method
;
633 case BT_COMPONENT_CLASS_TYPE_FILTER
:
634 cc_full_descr
->methods
.filter
.notif_iter_finalize
=
635 cur_cc_descr_attr
->value
.filter_notif_iter_finalize_method
;
643 * WARN-level logging because this
644 * should not happen with the
645 * appropriate ABI version. If we're
646 * here, we know that for the reported
647 * version of the ABI, this attribute is
650 BT_LOGW("Ignoring unknown component class descriptor attribute: "
651 "plugin-path=\"%s\", "
652 "plugin-name=\"%s\", "
653 "comp-class-name=\"%s\", "
654 "comp-class-type=%s, "
655 "attr-type-name=\"%s\", "
657 spec
->shared_lib_handle
->path
?
658 spec
->shared_lib_handle
->path
->str
:
661 cur_cc_descr_attr
->comp_class_descriptor
->name
,
662 bt_component_class_type_string(
663 cur_cc_descr_attr
->comp_class_descriptor
->type
),
664 cur_cc_descr_attr
->type_name
,
665 cur_cc_descr_attr
->type
);
671 /* Initialize plugin */
673 BT_LOGD_STR("Calling user's plugin initialization function.");
674 status
= spec
->init(plugin
);
675 BT_LOGD("User function returned: %s",
676 bt_plugin_status_string(status
));
679 BT_LOGW_STR("User's plugin initialization function failed.");
684 spec
->shared_lib_handle
->init_called
= BT_TRUE
;
686 /* Add described component classes to plugin */
687 for (i
= 0; i
< comp_class_full_descriptors
->len
; i
++) {
688 struct comp_class_full_descriptor
*cc_full_descr
=
689 &g_array_index(comp_class_full_descriptors
,
690 struct comp_class_full_descriptor
, i
);
691 struct bt_private_component_class
*comp_class
= NULL
;
692 struct bt_private_component_class_source
*src_comp_class
= NULL
;
693 struct bt_private_component_class_filter
*flt_comp_class
= NULL
;
694 struct bt_private_component_class_sink
*sink_comp_class
= NULL
;
696 BT_LOGD("Creating and setting properties of plugin's component class: "
697 "plugin-path=\"%s\", plugin-name=\"%s\", "
698 "comp-class-name=\"%s\", comp-class-type=%s",
699 spec
->shared_lib_handle
->path
?
700 spec
->shared_lib_handle
->path
->str
:
703 cc_full_descr
->descriptor
->name
,
704 bt_component_class_type_string(
705 cc_full_descr
->descriptor
->type
));
707 switch (cc_full_descr
->descriptor
->type
) {
708 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
709 src_comp_class
= bt_private_component_class_source_create(
710 cc_full_descr
->descriptor
->name
,
711 cc_full_descr
->descriptor
->methods
.source
.notif_iter_next
);
712 comp_class
= bt_private_component_class_source_borrow_private_component_class(
715 case BT_COMPONENT_CLASS_TYPE_FILTER
:
716 flt_comp_class
= bt_private_component_class_filter_create(
717 cc_full_descr
->descriptor
->name
,
718 cc_full_descr
->descriptor
->methods
.source
.notif_iter_next
);
719 comp_class
= bt_private_component_class_filter_borrow_private_component_class(
722 case BT_COMPONENT_CLASS_TYPE_SINK
:
723 sink_comp_class
= bt_private_component_class_sink_create(
724 cc_full_descr
->descriptor
->name
,
725 cc_full_descr
->descriptor
->methods
.sink
.consume
);
726 comp_class
= bt_private_component_class_sink_borrow_private_component_class(
731 * WARN-level logging because this should not
732 * happen with the appropriate ABI version. If
733 * we're here, we know that for the reported
734 * version of the ABI, this component class type
737 BT_LOGW("Ignoring unknown component class type: "
738 "plugin-path=\"%s\", plugin-name=\"%s\", "
739 "comp-class-name=\"%s\", comp-class-type=%d",
740 spec
->shared_lib_handle
->path
->str
?
741 spec
->shared_lib_handle
->path
->str
:
744 cc_full_descr
->descriptor
->name
,
745 cc_full_descr
->descriptor
->type
);
750 BT_LOGE_STR("Cannot create component class.");
751 status
= BT_PLUGIN_STATUS_ERROR
;
755 if (cc_full_descr
->description
) {
756 ret
= bt_private_component_class_set_description(
757 comp_class
, cc_full_descr
->description
);
759 BT_LOGE_STR("Cannot set component class's description.");
760 status
= BT_PLUGIN_STATUS_ERROR
;
761 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
766 if (cc_full_descr
->help
) {
767 ret
= bt_private_component_class_set_help(comp_class
,
768 cc_full_descr
->help
);
770 BT_LOGE_STR("Cannot set component class's help string.");
771 status
= BT_PLUGIN_STATUS_ERROR
;
772 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
777 switch (cc_full_descr
->descriptor
->type
) {
778 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
779 if (cc_full_descr
->methods
.source
.init
) {
780 ret
= bt_private_component_class_source_set_init_method(
782 cc_full_descr
->methods
.source
.init
);
784 BT_LOGE_STR("Cannot set source component class's initialization method.");
785 status
= BT_PLUGIN_STATUS_ERROR
;
786 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
791 if (cc_full_descr
->methods
.source
.finalize
) {
792 ret
= bt_private_component_class_source_set_finalize_method(
794 cc_full_descr
->methods
.source
.finalize
);
796 BT_LOGE_STR("Cannot set source component class's finalization method.");
797 status
= BT_PLUGIN_STATUS_ERROR
;
798 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
803 if (cc_full_descr
->methods
.source
.query
) {
804 ret
= bt_private_component_class_source_set_query_method(
806 cc_full_descr
->methods
.source
.query
);
808 BT_LOGE_STR("Cannot set source component class's query method.");
809 status
= BT_PLUGIN_STATUS_ERROR
;
810 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
815 if (cc_full_descr
->methods
.source
.accept_output_port_connection
) {
816 ret
= bt_private_component_class_source_set_accept_output_port_connection_method(
818 cc_full_descr
->methods
.source
.accept_output_port_connection
);
820 BT_LOGE_STR("Cannot set source component class's \"accept input output connection\" method.");
821 status
= BT_PLUGIN_STATUS_ERROR
;
822 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
827 if (cc_full_descr
->methods
.source
.output_port_connected
) {
828 ret
= bt_private_component_class_source_set_output_port_connected_method(
830 cc_full_descr
->methods
.source
.output_port_connected
);
832 BT_LOGE_STR("Cannot set source component class's \"output port connected\" method.");
833 status
= BT_PLUGIN_STATUS_ERROR
;
834 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
839 if (cc_full_descr
->methods
.source
.output_port_disconnected
) {
840 ret
= bt_private_component_class_source_set_output_port_disconnected_method(
842 cc_full_descr
->methods
.source
.output_port_disconnected
);
844 BT_LOGE_STR("Cannot set source component class's \"output port disconnected\" method.");
845 status
= BT_PLUGIN_STATUS_ERROR
;
846 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
851 if (cc_full_descr
->methods
.source
.notif_iter_init
) {
852 ret
= bt_private_component_class_source_set_notification_iterator_init_method(
854 cc_full_descr
->methods
.source
.notif_iter_init
);
856 BT_LOGE_STR("Cannot set source component class's notification iterator initialization method.");
857 status
= BT_PLUGIN_STATUS_ERROR
;
858 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
863 if (cc_full_descr
->methods
.source
.notif_iter_finalize
) {
864 ret
= bt_private_component_class_source_set_notification_iterator_finalize_method(
866 cc_full_descr
->methods
.source
.notif_iter_finalize
);
868 BT_LOGE_STR("Cannot set source component class's notification iterator finalization method.");
869 status
= BT_PLUGIN_STATUS_ERROR
;
870 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
876 case BT_COMPONENT_CLASS_TYPE_FILTER
:
877 if (cc_full_descr
->methods
.filter
.init
) {
878 ret
= bt_private_component_class_filter_set_init_method(
880 cc_full_descr
->methods
.filter
.init
);
882 BT_LOGE_STR("Cannot set filter component class's initialization method.");
883 status
= BT_PLUGIN_STATUS_ERROR
;
884 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
889 if (cc_full_descr
->methods
.filter
.finalize
) {
890 ret
= bt_private_component_class_filter_set_finalize_method(
892 cc_full_descr
->methods
.filter
.finalize
);
894 BT_LOGE_STR("Cannot set filter component class's finalization method.");
895 status
= BT_PLUGIN_STATUS_ERROR
;
896 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
901 if (cc_full_descr
->methods
.filter
.query
) {
902 ret
= bt_private_component_class_filter_set_query_method(
904 cc_full_descr
->methods
.filter
.query
);
906 BT_LOGE_STR("Cannot set filter component class's query method.");
907 status
= BT_PLUGIN_STATUS_ERROR
;
908 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
913 if (cc_full_descr
->methods
.filter
.accept_input_port_connection
) {
914 ret
= bt_private_component_class_filter_set_accept_input_port_connection_method(
916 cc_full_descr
->methods
.filter
.accept_input_port_connection
);
918 BT_LOGE_STR("Cannot set filter component class's \"accept input port connection\" method.");
919 status
= BT_PLUGIN_STATUS_ERROR
;
920 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
925 if (cc_full_descr
->methods
.filter
.accept_output_port_connection
) {
926 ret
= bt_private_component_class_filter_set_accept_output_port_connection_method(
928 cc_full_descr
->methods
.filter
.accept_output_port_connection
);
930 BT_LOGE_STR("Cannot set filter component class's \"accept input output connection\" method.");
931 status
= BT_PLUGIN_STATUS_ERROR
;
932 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
937 if (cc_full_descr
->methods
.filter
.input_port_connected
) {
938 ret
= bt_private_component_class_filter_set_input_port_connected_method(
940 cc_full_descr
->methods
.filter
.input_port_connected
);
942 BT_LOGE_STR("Cannot set filter component class's \"input port connected\" method.");
943 status
= BT_PLUGIN_STATUS_ERROR
;
944 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
949 if (cc_full_descr
->methods
.filter
.output_port_connected
) {
950 ret
= bt_private_component_class_filter_set_output_port_connected_method(
952 cc_full_descr
->methods
.filter
.output_port_connected
);
954 BT_LOGE_STR("Cannot set filter component class's \"output port connected\" method.");
955 status
= BT_PLUGIN_STATUS_ERROR
;
956 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
961 if (cc_full_descr
->methods
.filter
.input_port_disconnected
) {
962 ret
= bt_private_component_class_filter_set_input_port_disconnected_method(
964 cc_full_descr
->methods
.filter
.input_port_disconnected
);
966 BT_LOGE_STR("Cannot set filter component class's \"input port disconnected\" method.");
967 status
= BT_PLUGIN_STATUS_ERROR
;
968 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
973 if (cc_full_descr
->methods
.filter
.output_port_disconnected
) {
974 ret
= bt_private_component_class_filter_set_output_port_disconnected_method(
976 cc_full_descr
->methods
.filter
.output_port_disconnected
);
978 BT_LOGE_STR("Cannot set filter component class's \"output port disconnected\" method.");
979 status
= BT_PLUGIN_STATUS_ERROR
;
980 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
985 if (cc_full_descr
->methods
.filter
.notif_iter_init
) {
986 ret
= bt_private_component_class_filter_set_notification_iterator_init_method(
988 cc_full_descr
->methods
.filter
.notif_iter_init
);
990 BT_LOGE_STR("Cannot set filter component class's notification iterator initialization method.");
991 status
= BT_PLUGIN_STATUS_ERROR
;
992 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
997 if (cc_full_descr
->methods
.filter
.notif_iter_finalize
) {
998 ret
= bt_private_component_class_filter_set_notification_iterator_finalize_method(
1000 cc_full_descr
->methods
.filter
.notif_iter_finalize
);
1002 BT_LOGE_STR("Cannot set filter component class's notification iterator finalization method.");
1003 status
= BT_PLUGIN_STATUS_ERROR
;
1004 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1010 case BT_COMPONENT_CLASS_TYPE_SINK
:
1011 if (cc_full_descr
->methods
.sink
.init
) {
1012 ret
= bt_private_component_class_sink_set_init_method(
1014 cc_full_descr
->methods
.sink
.init
);
1016 BT_LOGE_STR("Cannot set sink component class's initialization method.");
1017 status
= BT_PLUGIN_STATUS_ERROR
;
1018 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1023 if (cc_full_descr
->methods
.sink
.finalize
) {
1024 ret
= bt_private_component_class_sink_set_finalize_method(
1026 cc_full_descr
->methods
.sink
.finalize
);
1028 BT_LOGE_STR("Cannot set sink component class's finalization method.");
1029 status
= BT_PLUGIN_STATUS_ERROR
;
1030 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1035 if (cc_full_descr
->methods
.sink
.query
) {
1036 ret
= bt_private_component_class_sink_set_query_method(
1038 cc_full_descr
->methods
.sink
.query
);
1040 BT_LOGE_STR("Cannot set sink component class's query method.");
1041 status
= BT_PLUGIN_STATUS_ERROR
;
1042 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1047 if (cc_full_descr
->methods
.sink
.accept_input_port_connection
) {
1048 ret
= bt_private_component_class_sink_set_accept_input_port_connection_method(
1050 cc_full_descr
->methods
.sink
.accept_input_port_connection
);
1052 BT_LOGE_STR("Cannot set sink component class's \"accept input port connection\" method.");
1053 status
= BT_PLUGIN_STATUS_ERROR
;
1054 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1059 if (cc_full_descr
->methods
.sink
.input_port_connected
) {
1060 ret
= bt_private_component_class_sink_set_input_port_connected_method(
1062 cc_full_descr
->methods
.sink
.input_port_connected
);
1064 BT_LOGE_STR("Cannot set sink component class's \"input port connected\" method.");
1065 status
= BT_PLUGIN_STATUS_ERROR
;
1066 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1071 if (cc_full_descr
->methods
.sink
.input_port_disconnected
) {
1072 ret
= bt_private_component_class_sink_set_input_port_disconnected_method(
1074 cc_full_descr
->methods
.sink
.input_port_disconnected
);
1076 BT_LOGE_STR("Cannot set sink component class's \"input port disconnected\" method.");
1077 status
= BT_PLUGIN_STATUS_ERROR
;
1078 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1089 * Add component class to the plugin object.
1091 * This will call back
1092 * bt_plugin_so_on_add_component_class() so that we can
1093 * add a mapping in the component class list when we
1094 * know the component class is successfully added.
1096 status
= bt_plugin_add_component_class(plugin
,
1097 (void *) comp_class
);
1098 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
1100 BT_LOGE("Cannot add component class to plugin.");
1106 g_array_free(comp_class_full_descriptors
, TRUE
);
1111 struct bt_plugin
*bt_plugin_so_create_empty(
1112 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
)
1114 struct bt_plugin
*plugin
;
1115 struct bt_plugin_so_spec_data
*spec
;
1117 plugin
= bt_plugin_create_empty(BT_PLUGIN_TYPE_SO
);
1122 plugin
->destroy_spec_data
= bt_plugin_so_destroy_spec_data
;
1123 plugin
->spec_data
= g_new0(struct bt_plugin_so_spec_data
, 1);
1124 if (!plugin
->spec_data
) {
1125 BT_LOGE_STR("Failed to allocate one SO plugin specific data structure.");
1129 spec
= plugin
->spec_data
;
1130 spec
->shared_lib_handle
= bt_object_get_ref(shared_lib_handle
);
1134 BT_OBJECT_PUT_REF_AND_RESET(plugin
);
1141 size_t count_non_null_items_in_section(const void *begin
, const void *end
)
1144 const int * const *begin_int
= (const int * const *) begin
;
1145 const int * const *end_int
= (const int * const *) end
;
1146 const int * const *iter
;
1148 for (iter
= begin_int
; iter
!= end_int
; iter
++) {
1158 struct bt_plugin_set
*bt_plugin_so_create_all_from_sections(
1159 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
,
1160 struct __bt_plugin_descriptor
const * const *descriptors_begin
,
1161 struct __bt_plugin_descriptor
const * const *descriptors_end
,
1162 struct __bt_plugin_descriptor_attribute
const * const *attrs_begin
,
1163 struct __bt_plugin_descriptor_attribute
const * const *attrs_end
,
1164 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_begin
,
1165 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_end
,
1166 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_begin
,
1167 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_end
)
1169 size_t descriptor_count
;
1171 size_t cc_descriptors_count
;
1172 size_t cc_descr_attrs_count
;
1174 struct bt_plugin_set
*plugin_set
= NULL
;
1176 descriptor_count
= count_non_null_items_in_section(descriptors_begin
, descriptors_end
);
1177 attrs_count
= count_non_null_items_in_section(attrs_begin
, attrs_end
);
1178 cc_descriptors_count
= count_non_null_items_in_section(cc_descriptors_begin
, cc_descriptors_end
);
1179 cc_descr_attrs_count
= count_non_null_items_in_section(cc_descr_attrs_begin
, cc_descr_attrs_end
);
1181 BT_LOGD("Creating all SO plugins from sections: "
1182 "plugin-path=\"%s\", "
1183 "descr-begin-addr=%p, descr-end-addr=%p, "
1184 "attrs-begin-addr=%p, attrs-end-addr=%p, "
1185 "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, "
1186 "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p, "
1187 "descr-count=%zu, attrs-count=%zu, "
1188 "cc-descr-count=%zu, cc-descr-attrs-count=%zu",
1189 shared_lib_handle
->path
? shared_lib_handle
->path
->str
: NULL
,
1190 descriptors_begin
, descriptors_end
,
1191 attrs_begin
, attrs_end
,
1192 cc_descriptors_begin
, cc_descriptors_end
,
1193 cc_descr_attrs_begin
, cc_descr_attrs_end
,
1194 descriptor_count
, attrs_count
,
1195 cc_descriptors_count
, cc_descr_attrs_count
);
1196 plugin_set
= bt_plugin_set_create();
1198 BT_LOGE_STR("Cannot create empty plugin set.");
1202 for (i
= 0; i
< descriptors_end
- descriptors_begin
; i
++) {
1203 enum bt_plugin_status status
;
1204 const struct __bt_plugin_descriptor
*descriptor
=
1205 descriptors_begin
[i
];
1206 struct bt_plugin
*plugin
;
1208 if (descriptor
== NULL
) {
1212 BT_LOGD("Creating plugin object for plugin: "
1213 "name=\"%s\", abi-major=%d, abi-minor=%d",
1214 descriptor
->name
, descriptor
->major
, descriptor
->minor
);
1216 if (descriptor
->major
> __BT_PLUGIN_VERSION_MAJOR
) {
1218 * DEBUG-level logging because we're only
1219 * _trying_ to open this file as a compatible
1220 * Babeltrace plugin: if it's not, it's not an
1221 * error. And because this can be tried during
1222 * bt_plugin_create_all_from_dir(), it's not
1225 BT_LOGD("Unknown ABI major version: abi-major=%d",
1230 plugin
= bt_plugin_so_create_empty(shared_lib_handle
);
1232 BT_LOGE_STR("Cannot create empty shared library handle.");
1236 if (shared_lib_handle
&& shared_lib_handle
->path
) {
1237 bt_plugin_set_path(plugin
, shared_lib_handle
->path
->str
);
1240 status
= bt_plugin_so_init(plugin
, descriptor
, attrs_begin
,
1241 attrs_end
, cc_descriptors_begin
, cc_descriptors_end
,
1242 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1245 * DEBUG-level logging because we're only
1246 * _trying_ to open this file as a compatible
1247 * Babeltrace plugin: if it's not, it's not an
1248 * error. And because this can be tried during
1249 * bt_plugin_create_all_from_dir(), it's not
1252 BT_LOGD_STR("Cannot initialize SO plugin object from sections.");
1253 BT_OBJECT_PUT_REF_AND_RESET(plugin
);
1257 /* Add to plugin set */
1258 bt_plugin_set_add_plugin(plugin_set
, plugin
);
1259 bt_object_put_ref(plugin
);
1265 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
1272 struct bt_plugin_set
*bt_plugin_so_create_all_from_static(void)
1274 struct bt_plugin_set
*plugin_set
= NULL
;
1275 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
=
1276 bt_plugin_so_shared_lib_handle_create(NULL
);
1278 if (!shared_lib_handle
) {
1282 BT_LOGD_STR("Creating all SO plugins from built-in plugins.");
1283 plugin_set
= bt_plugin_so_create_all_from_sections(shared_lib_handle
,
1284 __bt_get_begin_section_plugin_descriptors(),
1285 __bt_get_end_section_plugin_descriptors(),
1286 __bt_get_begin_section_plugin_descriptor_attributes(),
1287 __bt_get_end_section_plugin_descriptor_attributes(),
1288 __bt_get_begin_section_component_class_descriptors(),
1289 __bt_get_end_section_component_class_descriptors(),
1290 __bt_get_begin_section_component_class_descriptor_attributes(),
1291 __bt_get_end_section_component_class_descriptor_attributes());
1294 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle
);
1300 struct bt_plugin_set
*bt_plugin_so_create_all_from_file(const char *path
)
1303 struct bt_plugin_set
*plugin_set
= NULL
;
1304 struct __bt_plugin_descriptor
const * const *descriptors_begin
= NULL
;
1305 struct __bt_plugin_descriptor
const * const *descriptors_end
= NULL
;
1306 struct __bt_plugin_descriptor_attribute
const * const *attrs_begin
= NULL
;
1307 struct __bt_plugin_descriptor_attribute
const * const *attrs_end
= NULL
;
1308 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_begin
= NULL
;
1309 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_end
= NULL
;
1310 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_begin
= NULL
;
1311 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_end
= NULL
;
1312 struct __bt_plugin_descriptor
const * const *(*get_begin_section_plugin_descriptors
)(void);
1313 struct __bt_plugin_descriptor
const * const *(*get_end_section_plugin_descriptors
)(void);
1314 struct __bt_plugin_descriptor_attribute
const * const *(*get_begin_section_plugin_descriptor_attributes
)(void);
1315 struct __bt_plugin_descriptor_attribute
const * const *(*get_end_section_plugin_descriptor_attributes
)(void);
1316 struct __bt_plugin_component_class_descriptor
const * const *(*get_begin_section_component_class_descriptors
)(void);
1317 struct __bt_plugin_component_class_descriptor
const * const *(*get_end_section_component_class_descriptors
)(void);
1318 struct __bt_plugin_component_class_descriptor_attribute
const * const *(*get_begin_section_component_class_descriptor_attributes
)(void);
1319 struct __bt_plugin_component_class_descriptor_attribute
const * const *(*get_end_section_component_class_descriptor_attributes
)(void);
1320 bt_bool is_libtool_wrapper
= BT_FALSE
, is_shared_object
= BT_FALSE
;
1321 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
= NULL
;
1324 BT_LOGW_STR("Invalid parameter: path is NULL.");
1328 BT_LOGD("Creating all SO plugins from file: path=\"%s\"", path
);
1329 path_len
= strlen(path
);
1330 if (path_len
<= PLUGIN_SUFFIX_LEN
) {
1331 BT_LOGW("Invalid parameter: path length is too short: "
1332 "path-length=%zu", path_len
);
1338 * Check if the file ends with a known plugin file type suffix (i.e. .so
1341 is_libtool_wrapper
= !strncmp(LIBTOOL_PLUGIN_SUFFIX
,
1342 path
+ path_len
- LIBTOOL_PLUGIN_SUFFIX_LEN
,
1343 LIBTOOL_PLUGIN_SUFFIX_LEN
);
1344 is_shared_object
= !strncmp(NATIVE_PLUGIN_SUFFIX
,
1345 path
+ path_len
- NATIVE_PLUGIN_SUFFIX_LEN
,
1346 NATIVE_PLUGIN_SUFFIX_LEN
);
1347 if (!is_shared_object
&& !is_libtool_wrapper
) {
1348 /* Name indicates this is not a plugin file; not an error */
1349 BT_LOGV("File is not a SO plugin file: path=\"%s\"", path
);
1353 shared_lib_handle
= bt_plugin_so_shared_lib_handle_create(path
);
1354 if (!shared_lib_handle
) {
1355 BT_LOGD_STR("Cannot create shared library handle.");
1359 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_plugin_descriptors",
1360 (gpointer
*) &get_begin_section_plugin_descriptors
)) {
1361 descriptors_begin
= get_begin_section_plugin_descriptors();
1363 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1364 "symbol=\"%s\"", path
,
1365 "__bt_get_begin_section_plugin_descriptors");
1369 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_plugin_descriptors",
1370 (gpointer
*) &get_end_section_plugin_descriptors
)) {
1371 descriptors_end
= get_end_section_plugin_descriptors();
1373 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1374 "symbol=\"%s\"", path
,
1375 "__bt_get_end_section_plugin_descriptors");
1379 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_plugin_descriptor_attributes",
1380 (gpointer
*) &get_begin_section_plugin_descriptor_attributes
)) {
1381 attrs_begin
= get_begin_section_plugin_descriptor_attributes();
1383 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1384 "symbol=\"%s\"", path
,
1385 "__bt_get_begin_section_plugin_descriptor_attributes");
1388 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_plugin_descriptor_attributes",
1389 (gpointer
*) &get_end_section_plugin_descriptor_attributes
)) {
1390 attrs_end
= get_end_section_plugin_descriptor_attributes();
1392 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1393 "symbol=\"%s\"", path
,
1394 "__bt_get_end_section_plugin_descriptor_attributes");
1397 if ((!!attrs_begin
- !!attrs_end
) != 0) {
1398 BT_LOGD("Found section start or end symbol, but not both: "
1399 "path=\"%s\", symbol-start=\"%s\", "
1400 "symbol-end=\"%s\", symbol-start-addr=%p, "
1401 "symbol-end-addr=%p",
1402 path
, "__bt_get_begin_section_plugin_descriptor_attributes",
1403 "__bt_get_end_section_plugin_descriptor_attributes",
1404 attrs_begin
, attrs_end
);
1408 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_component_class_descriptors",
1409 (gpointer
*) &get_begin_section_component_class_descriptors
)) {
1410 cc_descriptors_begin
= get_begin_section_component_class_descriptors();
1412 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1413 "symbol=\"%s\"", path
,
1414 "__bt_get_begin_section_component_class_descriptors");
1417 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_component_class_descriptors",
1418 (gpointer
*) &get_end_section_component_class_descriptors
)) {
1419 cc_descriptors_end
= get_end_section_component_class_descriptors();
1421 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1422 "symbol=\"%s\"", path
,
1423 "__bt_get_end_section_component_class_descriptors");
1426 if ((!!cc_descriptors_begin
- !!cc_descriptors_end
) != 0) {
1427 BT_LOGD("Found section start or end symbol, but not both: "
1428 "path=\"%s\", symbol-start=\"%s\", "
1429 "symbol-end=\"%s\", symbol-start-addr=%p, "
1430 "symbol-end-addr=%p",
1431 path
, "__bt_get_begin_section_component_class_descriptors",
1432 "__bt_get_end_section_component_class_descriptors",
1433 cc_descriptors_begin
, cc_descriptors_end
);
1437 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_component_class_descriptor_attributes",
1438 (gpointer
*) &get_begin_section_component_class_descriptor_attributes
)) {
1439 cc_descr_attrs_begin
= get_begin_section_component_class_descriptor_attributes();
1441 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1442 "symbol=\"%s\"", path
,
1443 "__bt_get_begin_section_component_class_descriptor_attributes");
1446 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_component_class_descriptor_attributes",
1447 (gpointer
*) &get_end_section_component_class_descriptor_attributes
)) {
1448 cc_descr_attrs_end
= get_end_section_component_class_descriptor_attributes();
1450 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1451 "symbol=\"%s\"", path
,
1452 "__bt_get_end_section_component_class_descriptor_attributes");
1455 if ((!!cc_descr_attrs_begin
- !!cc_descr_attrs_end
) != 0) {
1456 BT_LOGD("Found section start or end symbol, but not both: "
1457 "path=\"%s\", symbol-start=\"%s\", "
1458 "symbol-end=\"%s\", symbol-start-addr=%p, "
1459 "symbol-end-addr=%p",
1460 path
, "__bt_get_begin_section_component_class_descriptor_attributes",
1461 "__bt_get_end_section_component_class_descriptor_attributes",
1462 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1466 /* Initialize plugin */
1467 BT_LOGD_STR("Initializing plugin object.");
1468 plugin_set
= bt_plugin_so_create_all_from_sections(shared_lib_handle
,
1469 descriptors_begin
, descriptors_end
, attrs_begin
, attrs_end
,
1470 cc_descriptors_begin
, cc_descriptors_end
,
1471 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1474 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle
);
1479 void plugin_comp_class_destroy_listener(struct bt_component_class
*comp_class
,
1482 bt_list_del(&comp_class
->node
);
1483 BT_OBJECT_PUT_REF_AND_RESET(comp_class
->so_handle
);
1484 BT_LOGV("Component class destroyed: removed entry from list: "
1485 "comp-cls-addr=%p", comp_class
);
1489 void bt_plugin_so_on_add_component_class(struct bt_plugin
*plugin
,
1490 struct bt_component_class
*comp_class
)
1492 struct bt_plugin_so_spec_data
*spec
= plugin
->spec_data
;
1494 BT_ASSERT(plugin
->spec_data
);
1495 BT_ASSERT(plugin
->type
== BT_PLUGIN_TYPE_SO
);
1497 bt_list_add(&comp_class
->node
, &component_class_list
);
1498 comp_class
->so_handle
= bt_object_get_ref(spec
->shared_lib_handle
);
1500 /* Add our custom destroy listener */
1501 bt_component_class_add_destroy_listener(comp_class
,
1502 plugin_comp_class_destroy_listener
, NULL
);