2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@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/assert-internal.h>
30 #include <babeltrace/assert-pre-internal.h>
31 #include <babeltrace/compiler-internal.h>
32 #include <babeltrace/plugin/plugin-internal.h>
33 #include <babeltrace/plugin/plugin-so-internal.h>
34 #include <babeltrace/plugin/plugin-dev.h>
35 #include <babeltrace/plugin/plugin-internal.h>
36 #include <babeltrace/graph/component-class-internal.h>
37 #include <babeltrace/graph/component-class.h>
38 #include <babeltrace/graph/component-class-source.h>
39 #include <babeltrace/graph/component-class-filter.h>
40 #include <babeltrace/graph/component-class-sink.h>
41 #include <babeltrace/types.h>
42 #include <babeltrace/list-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_find_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
);
152 shared_lib_handle
->module
= NULL
;
155 BT_LOGD("Not closing GModule because `BABELTRACE_NO_DLCLOSE=1`: "
156 "path=\"%s\"", path
);
161 if (shared_lib_handle
->path
) {
162 g_string_free(shared_lib_handle
->path
, TRUE
);
163 shared_lib_handle
->path
= NULL
;
166 g_free(shared_lib_handle
);
170 struct bt_plugin_so_shared_lib_handle
*bt_plugin_so_shared_lib_handle_create(
173 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
= NULL
;
175 BT_LOGD("Creating shared library handle: path=\"%s\"", path
);
176 shared_lib_handle
= g_new0(struct bt_plugin_so_shared_lib_handle
, 1);
177 if (!shared_lib_handle
) {
178 BT_LOGE_STR("Failed to allocate one shared library handle.");
182 bt_object_init_shared(&shared_lib_handle
->base
,
183 bt_plugin_so_shared_lib_handle_destroy
);
189 shared_lib_handle
->path
= g_string_new(path
);
190 if (!shared_lib_handle
->path
) {
191 BT_LOGE_STR("Failed to allocate a GString.");
195 shared_lib_handle
->module
= g_module_open(path
, G_MODULE_BIND_LOCAL
);
196 if (!shared_lib_handle
->module
) {
198 * DEBUG-level logging because we're only _trying_ to
199 * open this file as a Babeltrace plugin: if it's not,
200 * it's not an error. And because this can be tried
201 * during bt_plugin_find_all_from_dir(), it's not even
204 BT_LOGD("Cannot open GModule: %s: path=\"%s\"",
205 g_module_error(), path
);
212 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle
);
215 if (shared_lib_handle
) {
216 BT_LOGD("Created shared library handle: path=\"%s\", addr=%p",
217 path
, shared_lib_handle
);
220 return shared_lib_handle
;
224 void bt_plugin_so_destroy_spec_data(struct bt_plugin
*plugin
)
226 struct bt_plugin_so_spec_data
*spec
= plugin
->spec_data
;
228 if (!plugin
->spec_data
) {
232 BT_ASSERT(plugin
->type
== BT_PLUGIN_TYPE_SO
);
234 BT_OBJECT_PUT_REF_AND_RESET(spec
->shared_lib_handle
);
235 g_free(plugin
->spec_data
);
236 plugin
->spec_data
= NULL
;
240 * This function does the following:
242 * 1. Iterate on the plugin descriptor attributes section and set the
243 * plugin's attributes depending on the attribute types. This
244 * includes the name of the plugin, its description, and its
245 * initialization function, for example.
247 * 2. Iterate on the component class descriptors section and create one
248 * "full descriptor" (temporary structure) for each one that is found
249 * and attached to our plugin descriptor.
251 * 3. Iterate on the component class descriptor attributes section and
252 * set the corresponding full descriptor's attributes depending on
253 * the attribute types. This includes the description of the
254 * component class, as well as its initialization and destroy
257 * 4. Call the user's plugin initialization function, if any is
260 * 5. For each full component class descriptor, create a component class
261 * object, set its optional attributes, and add it to the plugin
264 * 6. Freeze the plugin object.
267 enum bt_plugin_status
bt_plugin_so_init(
268 struct bt_plugin
*plugin
,
269 const struct __bt_plugin_descriptor
*descriptor
,
270 struct __bt_plugin_descriptor_attribute
const * const *attrs_begin
,
271 struct __bt_plugin_descriptor_attribute
const * const *attrs_end
,
272 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_begin
,
273 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_end
,
274 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_begin
,
275 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_end
)
278 * This structure's members point to the plugin's memory
281 struct comp_class_full_descriptor
{
282 const struct __bt_plugin_component_class_descriptor
*descriptor
;
283 const char *description
;
288 bt_component_class_source_init_method init
;
289 bt_component_class_source_finalize_method finalize
;
290 bt_component_class_source_query_method query
;
291 bt_component_class_source_accept_output_port_connection_method accept_output_port_connection
;
292 bt_component_class_source_output_port_connected_method output_port_connected
;
293 bt_component_class_source_output_port_disconnected_method output_port_disconnected
;
294 bt_component_class_source_message_iterator_init_method msg_iter_init
;
295 bt_component_class_source_message_iterator_finalize_method msg_iter_finalize
;
299 bt_component_class_filter_init_method init
;
300 bt_component_class_filter_finalize_method finalize
;
301 bt_component_class_filter_query_method query
;
302 bt_component_class_filter_accept_input_port_connection_method accept_input_port_connection
;
303 bt_component_class_filter_accept_output_port_connection_method accept_output_port_connection
;
304 bt_component_class_filter_input_port_connected_method input_port_connected
;
305 bt_component_class_filter_output_port_connected_method output_port_connected
;
306 bt_component_class_filter_input_port_disconnected_method input_port_disconnected
;
307 bt_component_class_filter_output_port_disconnected_method output_port_disconnected
;
308 bt_component_class_filter_message_iterator_init_method msg_iter_init
;
309 bt_component_class_filter_message_iterator_finalize_method msg_iter_finalize
;
313 bt_component_class_sink_init_method init
;
314 bt_component_class_sink_finalize_method finalize
;
315 bt_component_class_sink_query_method query
;
316 bt_component_class_sink_accept_input_port_connection_method accept_input_port_connection
;
317 bt_component_class_sink_input_port_connected_method input_port_connected
;
318 bt_component_class_sink_input_port_disconnected_method input_port_disconnected
;
323 enum bt_plugin_status status
= BT_PLUGIN_STATUS_OK
;
324 struct __bt_plugin_descriptor_attribute
const * const *cur_attr_ptr
;
325 struct __bt_plugin_component_class_descriptor
const * const *cur_cc_descr_ptr
;
326 struct __bt_plugin_component_class_descriptor_attribute
const * const *cur_cc_descr_attr_ptr
;
327 struct bt_plugin_so_spec_data
*spec
= plugin
->spec_data
;
328 GArray
*comp_class_full_descriptors
;
332 BT_LOGD("Initializing plugin object from descriptors found in sections: "
333 "plugin-addr=%p, plugin-path=\"%s\", "
334 "attrs-begin-addr=%p, attrs-end-addr=%p, "
335 "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, "
336 "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p",
338 spec
->shared_lib_handle
->path
?
339 spec
->shared_lib_handle
->path
->str
: NULL
,
340 attrs_begin
, attrs_end
,
341 cc_descriptors_begin
, cc_descriptors_end
,
342 cc_descr_attrs_begin
, cc_descr_attrs_end
);
343 comp_class_full_descriptors
= g_array_new(FALSE
, TRUE
,
344 sizeof(struct comp_class_full_descriptor
));
345 if (!comp_class_full_descriptors
) {
346 BT_LOGE_STR("Failed to allocate a GArray.");
347 status
= BT_PLUGIN_STATUS_ERROR
;
351 /* Set mandatory attributes */
352 spec
->descriptor
= descriptor
;
353 bt_plugin_set_name(plugin
, descriptor
->name
);
356 * Find and set optional attributes attached to this plugin
359 for (cur_attr_ptr
= attrs_begin
; cur_attr_ptr
!= attrs_end
; cur_attr_ptr
++) {
360 const struct __bt_plugin_descriptor_attribute
*cur_attr
=
363 if (cur_attr
== NULL
) {
367 if (cur_attr
->plugin_descriptor
!= descriptor
) {
371 switch (cur_attr
->type
) {
372 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_INIT
:
373 spec
->init
= cur_attr
->value
.init
;
375 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_EXIT
:
376 spec
->shared_lib_handle
->exit
= cur_attr
->value
.exit
;
378 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_AUTHOR
:
379 bt_plugin_set_author(plugin
, cur_attr
->value
.author
);
381 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_LICENSE
:
382 bt_plugin_set_license(plugin
, cur_attr
->value
.license
);
384 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION
:
385 bt_plugin_set_description(plugin
, cur_attr
->value
.description
);
387 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_VERSION
:
388 bt_plugin_set_version(plugin
,
389 (unsigned int) cur_attr
->value
.version
.major
,
390 (unsigned int) cur_attr
->value
.version
.minor
,
391 (unsigned int) cur_attr
->value
.version
.patch
,
392 cur_attr
->value
.version
.extra
);
396 * WARN-level logging because this should not
397 * happen with the appropriate ABI version. If
398 * we're here, we know that for the reported
399 * version of the ABI, this attribute is
402 BT_LOGW("Ignoring unknown plugin descriptor attribute: "
403 "plugin-path=\"%s\", plugin-name=\"%s\", "
404 "attr-type-name=\"%s\", attr-type-id=%d",
405 spec
->shared_lib_handle
->path
?
406 spec
->shared_lib_handle
->path
->str
:
408 descriptor
->name
, cur_attr
->type_name
,
415 * Find component class descriptors attached to this plugin
416 * descriptor and initialize corresponding full component class
417 * descriptors in the array.
419 for (cur_cc_descr_ptr
= cc_descriptors_begin
; cur_cc_descr_ptr
!= cc_descriptors_end
; cur_cc_descr_ptr
++) {
420 const struct __bt_plugin_component_class_descriptor
*cur_cc_descr
=
422 struct comp_class_full_descriptor full_descriptor
= {0};
424 if (cur_cc_descr
== NULL
) {
428 if (cur_cc_descr
->plugin_descriptor
!= descriptor
) {
432 full_descriptor
.descriptor
= cur_cc_descr
;
433 g_array_append_val(comp_class_full_descriptors
,
438 * Find component class descriptor attributes attached to this
439 * plugin descriptor and update corresponding full component
440 * class descriptors in the array.
442 for (cur_cc_descr_attr_ptr
= cc_descr_attrs_begin
; cur_cc_descr_attr_ptr
!= cc_descr_attrs_end
; cur_cc_descr_attr_ptr
++) {
443 const struct __bt_plugin_component_class_descriptor_attribute
*cur_cc_descr_attr
=
444 *cur_cc_descr_attr_ptr
;
445 enum bt_component_class_type cc_type
;
447 if (cur_cc_descr_attr
== NULL
) {
451 if (cur_cc_descr_attr
->comp_class_descriptor
->plugin_descriptor
!=
456 cc_type
= cur_cc_descr_attr
->comp_class_descriptor
->type
;
458 /* Find the corresponding component class descriptor entry */
459 for (i
= 0; i
< comp_class_full_descriptors
->len
; i
++) {
460 struct comp_class_full_descriptor
*cc_full_descr
=
461 &g_array_index(comp_class_full_descriptors
,
462 struct comp_class_full_descriptor
, i
);
464 if (cur_cc_descr_attr
->comp_class_descriptor
!=
465 cc_full_descr
->descriptor
) {
469 switch (cur_cc_descr_attr
->type
) {
470 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION
:
471 cc_full_descr
->description
=
472 cur_cc_descr_attr
->value
.description
;
474 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP
:
475 cc_full_descr
->help
=
476 cur_cc_descr_attr
->value
.help
;
478 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD
:
480 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
481 cc_full_descr
->methods
.source
.init
=
482 cur_cc_descr_attr
->value
.source_init_method
;
484 case BT_COMPONENT_CLASS_TYPE_FILTER
:
485 cc_full_descr
->methods
.filter
.init
=
486 cur_cc_descr_attr
->value
.filter_init_method
;
488 case BT_COMPONENT_CLASS_TYPE_SINK
:
489 cc_full_descr
->methods
.sink
.init
=
490 cur_cc_descr_attr
->value
.sink_init_method
;
496 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD
:
498 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
499 cc_full_descr
->methods
.source
.finalize
=
500 cur_cc_descr_attr
->value
.source_finalize_method
;
502 case BT_COMPONENT_CLASS_TYPE_FILTER
:
503 cc_full_descr
->methods
.filter
.finalize
=
504 cur_cc_descr_attr
->value
.filter_finalize_method
;
506 case BT_COMPONENT_CLASS_TYPE_SINK
:
507 cc_full_descr
->methods
.sink
.finalize
=
508 cur_cc_descr_attr
->value
.sink_finalize_method
;
514 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD
:
516 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
517 cc_full_descr
->methods
.source
.query
=
518 cur_cc_descr_attr
->value
.source_query_method
;
520 case BT_COMPONENT_CLASS_TYPE_FILTER
:
521 cc_full_descr
->methods
.filter
.query
=
522 cur_cc_descr_attr
->value
.filter_query_method
;
524 case BT_COMPONENT_CLASS_TYPE_SINK
:
525 cc_full_descr
->methods
.sink
.query
=
526 cur_cc_descr_attr
->value
.sink_query_method
;
532 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_INPUT_PORT_CONNECTION_METHOD
:
534 case BT_COMPONENT_CLASS_TYPE_FILTER
:
535 cc_full_descr
->methods
.filter
.accept_input_port_connection
=
536 cur_cc_descr_attr
->value
.filter_accept_input_port_connection_method
;
538 case BT_COMPONENT_CLASS_TYPE_SINK
:
539 cc_full_descr
->methods
.sink
.accept_input_port_connection
=
540 cur_cc_descr_attr
->value
.sink_accept_input_port_connection_method
;
546 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD
:
548 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
549 cc_full_descr
->methods
.source
.accept_output_port_connection
=
550 cur_cc_descr_attr
->value
.source_accept_output_port_connection_method
;
552 case BT_COMPONENT_CLASS_TYPE_FILTER
:
553 cc_full_descr
->methods
.filter
.accept_output_port_connection
=
554 cur_cc_descr_attr
->value
.filter_accept_output_port_connection_method
;
560 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD
:
562 case BT_COMPONENT_CLASS_TYPE_FILTER
:
563 cc_full_descr
->methods
.filter
.input_port_connected
=
564 cur_cc_descr_attr
->value
.filter_input_port_connected_method
;
566 case BT_COMPONENT_CLASS_TYPE_SINK
:
567 cc_full_descr
->methods
.sink
.input_port_connected
=
568 cur_cc_descr_attr
->value
.sink_input_port_connected_method
;
574 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD
:
576 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
577 cc_full_descr
->methods
.source
.output_port_connected
=
578 cur_cc_descr_attr
->value
.source_output_port_connected_method
;
580 case BT_COMPONENT_CLASS_TYPE_FILTER
:
581 cc_full_descr
->methods
.filter
.output_port_connected
=
582 cur_cc_descr_attr
->value
.filter_output_port_connected_method
;
588 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD
:
590 case BT_COMPONENT_CLASS_TYPE_FILTER
:
591 cc_full_descr
->methods
.filter
.input_port_disconnected
=
592 cur_cc_descr_attr
->value
.filter_input_port_disconnected_method
;
594 case BT_COMPONENT_CLASS_TYPE_SINK
:
595 cc_full_descr
->methods
.sink
.input_port_disconnected
=
596 cur_cc_descr_attr
->value
.sink_input_port_disconnected_method
;
602 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD
:
604 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
605 cc_full_descr
->methods
.source
.output_port_disconnected
=
606 cur_cc_descr_attr
->value
.source_output_port_disconnected_method
;
608 case BT_COMPONENT_CLASS_TYPE_FILTER
:
609 cc_full_descr
->methods
.filter
.output_port_disconnected
=
610 cur_cc_descr_attr
->value
.filter_output_port_disconnected_method
;
616 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INIT_METHOD
:
618 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
619 cc_full_descr
->methods
.source
.msg_iter_init
=
620 cur_cc_descr_attr
->value
.source_msg_iter_init_method
;
622 case BT_COMPONENT_CLASS_TYPE_FILTER
:
623 cc_full_descr
->methods
.filter
.msg_iter_init
=
624 cur_cc_descr_attr
->value
.filter_msg_iter_init_method
;
630 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_FINALIZE_METHOD
:
632 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
633 cc_full_descr
->methods
.source
.msg_iter_finalize
=
634 cur_cc_descr_attr
->value
.source_msg_iter_finalize_method
;
636 case BT_COMPONENT_CLASS_TYPE_FILTER
:
637 cc_full_descr
->methods
.filter
.msg_iter_finalize
=
638 cur_cc_descr_attr
->value
.filter_msg_iter_finalize_method
;
646 * WARN-level logging because this
647 * should not happen with the
648 * appropriate ABI version. If we're
649 * here, we know that for the reported
650 * version of the ABI, this attribute is
653 BT_LOGW("Ignoring unknown component class descriptor attribute: "
654 "plugin-path=\"%s\", "
655 "plugin-name=\"%s\", "
656 "comp-class-name=\"%s\", "
657 "comp-class-type=%s, "
658 "attr-type-name=\"%s\", "
660 spec
->shared_lib_handle
->path
?
661 spec
->shared_lib_handle
->path
->str
:
664 cur_cc_descr_attr
->comp_class_descriptor
->name
,
665 bt_component_class_type_string(
666 cur_cc_descr_attr
->comp_class_descriptor
->type
),
667 cur_cc_descr_attr
->type_name
,
668 cur_cc_descr_attr
->type
);
674 /* Initialize plugin */
676 BT_LOGD_STR("Calling user's plugin initialization function.");
677 status
= spec
->init(plugin
);
678 BT_LOGD("User function returned: %s",
679 bt_plugin_status_string(status
));
682 BT_LOGW_STR("User's plugin initialization function failed.");
687 spec
->shared_lib_handle
->init_called
= BT_TRUE
;
689 /* Add described component classes to plugin */
690 for (i
= 0; i
< comp_class_full_descriptors
->len
; i
++) {
691 struct comp_class_full_descriptor
*cc_full_descr
=
692 &g_array_index(comp_class_full_descriptors
,
693 struct comp_class_full_descriptor
, i
);
694 struct bt_component_class
*comp_class
= NULL
;
695 struct bt_component_class_source
*src_comp_class
= NULL
;
696 struct bt_component_class_filter
*flt_comp_class
= NULL
;
697 struct bt_component_class_sink
*sink_comp_class
= NULL
;
699 BT_LOGD("Creating and setting properties of plugin's component class: "
700 "plugin-path=\"%s\", plugin-name=\"%s\", "
701 "comp-class-name=\"%s\", comp-class-type=%s",
702 spec
->shared_lib_handle
->path
?
703 spec
->shared_lib_handle
->path
->str
:
706 cc_full_descr
->descriptor
->name
,
707 bt_component_class_type_string(
708 cc_full_descr
->descriptor
->type
));
710 switch (cc_full_descr
->descriptor
->type
) {
711 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
712 src_comp_class
= bt_component_class_source_create(
713 cc_full_descr
->descriptor
->name
,
714 cc_full_descr
->descriptor
->methods
.source
.msg_iter_next
);
715 comp_class
= bt_component_class_source_as_component_class(
718 case BT_COMPONENT_CLASS_TYPE_FILTER
:
719 flt_comp_class
= bt_component_class_filter_create(
720 cc_full_descr
->descriptor
->name
,
721 cc_full_descr
->descriptor
->methods
.source
.msg_iter_next
);
722 comp_class
= bt_component_class_filter_as_component_class(
725 case BT_COMPONENT_CLASS_TYPE_SINK
:
726 sink_comp_class
= bt_component_class_sink_create(
727 cc_full_descr
->descriptor
->name
,
728 cc_full_descr
->descriptor
->methods
.sink
.consume
);
729 comp_class
= bt_component_class_sink_as_component_class(
734 * WARN-level logging because this should not
735 * happen with the appropriate ABI version. If
736 * we're here, we know that for the reported
737 * version of the ABI, this component class type
740 BT_LOGW("Ignoring unknown component class type: "
741 "plugin-path=\"%s\", plugin-name=\"%s\", "
742 "comp-class-name=\"%s\", comp-class-type=%d",
743 spec
->shared_lib_handle
->path
->str
?
744 spec
->shared_lib_handle
->path
->str
:
747 cc_full_descr
->descriptor
->name
,
748 cc_full_descr
->descriptor
->type
);
753 BT_LOGE_STR("Cannot create component class.");
754 status
= BT_PLUGIN_STATUS_ERROR
;
758 if (cc_full_descr
->description
) {
759 ret
= bt_component_class_set_description(
760 comp_class
, cc_full_descr
->description
);
762 BT_LOGE_STR("Cannot set component class's description.");
763 status
= BT_PLUGIN_STATUS_ERROR
;
764 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
769 if (cc_full_descr
->help
) {
770 ret
= bt_component_class_set_help(comp_class
,
771 cc_full_descr
->help
);
773 BT_LOGE_STR("Cannot set component class's help string.");
774 status
= BT_PLUGIN_STATUS_ERROR
;
775 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
780 switch (cc_full_descr
->descriptor
->type
) {
781 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
782 if (cc_full_descr
->methods
.source
.init
) {
783 ret
= bt_component_class_source_set_init_method(
785 cc_full_descr
->methods
.source
.init
);
787 BT_LOGE_STR("Cannot set source component class's initialization method.");
788 status
= BT_PLUGIN_STATUS_ERROR
;
789 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
794 if (cc_full_descr
->methods
.source
.finalize
) {
795 ret
= bt_component_class_source_set_finalize_method(
797 cc_full_descr
->methods
.source
.finalize
);
799 BT_LOGE_STR("Cannot set source component class's finalization method.");
800 status
= BT_PLUGIN_STATUS_ERROR
;
801 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
806 if (cc_full_descr
->methods
.source
.query
) {
807 ret
= bt_component_class_source_set_query_method(
809 cc_full_descr
->methods
.source
.query
);
811 BT_LOGE_STR("Cannot set source component class's query method.");
812 status
= BT_PLUGIN_STATUS_ERROR
;
813 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
818 if (cc_full_descr
->methods
.source
.accept_output_port_connection
) {
819 ret
= bt_component_class_source_set_accept_output_port_connection_method(
821 cc_full_descr
->methods
.source
.accept_output_port_connection
);
823 BT_LOGE_STR("Cannot set source component class's \"accept input output connection\" method.");
824 status
= BT_PLUGIN_STATUS_ERROR
;
825 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
830 if (cc_full_descr
->methods
.source
.output_port_connected
) {
831 ret
= bt_component_class_source_set_output_port_connected_method(
833 cc_full_descr
->methods
.source
.output_port_connected
);
835 BT_LOGE_STR("Cannot set source component class's \"output port connected\" method.");
836 status
= BT_PLUGIN_STATUS_ERROR
;
837 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
842 if (cc_full_descr
->methods
.source
.output_port_disconnected
) {
843 ret
= bt_component_class_source_set_output_port_disconnected_method(
845 cc_full_descr
->methods
.source
.output_port_disconnected
);
847 BT_LOGE_STR("Cannot set source component class's \"output port disconnected\" method.");
848 status
= BT_PLUGIN_STATUS_ERROR
;
849 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
854 if (cc_full_descr
->methods
.source
.msg_iter_init
) {
855 ret
= bt_component_class_source_set_message_iterator_init_method(
857 cc_full_descr
->methods
.source
.msg_iter_init
);
859 BT_LOGE_STR("Cannot set source component class's message iterator initialization method.");
860 status
= BT_PLUGIN_STATUS_ERROR
;
861 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
866 if (cc_full_descr
->methods
.source
.msg_iter_finalize
) {
867 ret
= bt_component_class_source_set_message_iterator_finalize_method(
869 cc_full_descr
->methods
.source
.msg_iter_finalize
);
871 BT_LOGE_STR("Cannot set source component class's message iterator finalization method.");
872 status
= BT_PLUGIN_STATUS_ERROR
;
873 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
879 case BT_COMPONENT_CLASS_TYPE_FILTER
:
880 if (cc_full_descr
->methods
.filter
.init
) {
881 ret
= bt_component_class_filter_set_init_method(
883 cc_full_descr
->methods
.filter
.init
);
885 BT_LOGE_STR("Cannot set filter component class's initialization method.");
886 status
= BT_PLUGIN_STATUS_ERROR
;
887 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
892 if (cc_full_descr
->methods
.filter
.finalize
) {
893 ret
= bt_component_class_filter_set_finalize_method(
895 cc_full_descr
->methods
.filter
.finalize
);
897 BT_LOGE_STR("Cannot set filter component class's finalization method.");
898 status
= BT_PLUGIN_STATUS_ERROR
;
899 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
904 if (cc_full_descr
->methods
.filter
.query
) {
905 ret
= bt_component_class_filter_set_query_method(
907 cc_full_descr
->methods
.filter
.query
);
909 BT_LOGE_STR("Cannot set filter component class's query method.");
910 status
= BT_PLUGIN_STATUS_ERROR
;
911 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
916 if (cc_full_descr
->methods
.filter
.accept_input_port_connection
) {
917 ret
= bt_component_class_filter_set_accept_input_port_connection_method(
919 cc_full_descr
->methods
.filter
.accept_input_port_connection
);
921 BT_LOGE_STR("Cannot set filter component class's \"accept input port connection\" method.");
922 status
= BT_PLUGIN_STATUS_ERROR
;
923 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
928 if (cc_full_descr
->methods
.filter
.accept_output_port_connection
) {
929 ret
= bt_component_class_filter_set_accept_output_port_connection_method(
931 cc_full_descr
->methods
.filter
.accept_output_port_connection
);
933 BT_LOGE_STR("Cannot set filter component class's \"accept input output connection\" method.");
934 status
= BT_PLUGIN_STATUS_ERROR
;
935 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
940 if (cc_full_descr
->methods
.filter
.input_port_connected
) {
941 ret
= bt_component_class_filter_set_input_port_connected_method(
943 cc_full_descr
->methods
.filter
.input_port_connected
);
945 BT_LOGE_STR("Cannot set filter component class's \"input port connected\" method.");
946 status
= BT_PLUGIN_STATUS_ERROR
;
947 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
952 if (cc_full_descr
->methods
.filter
.output_port_connected
) {
953 ret
= bt_component_class_filter_set_output_port_connected_method(
955 cc_full_descr
->methods
.filter
.output_port_connected
);
957 BT_LOGE_STR("Cannot set filter component class's \"output port connected\" method.");
958 status
= BT_PLUGIN_STATUS_ERROR
;
959 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
964 if (cc_full_descr
->methods
.filter
.input_port_disconnected
) {
965 ret
= bt_component_class_filter_set_input_port_disconnected_method(
967 cc_full_descr
->methods
.filter
.input_port_disconnected
);
969 BT_LOGE_STR("Cannot set filter component class's \"input port disconnected\" method.");
970 status
= BT_PLUGIN_STATUS_ERROR
;
971 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
976 if (cc_full_descr
->methods
.filter
.output_port_disconnected
) {
977 ret
= bt_component_class_filter_set_output_port_disconnected_method(
979 cc_full_descr
->methods
.filter
.output_port_disconnected
);
981 BT_LOGE_STR("Cannot set filter component class's \"output port disconnected\" method.");
982 status
= BT_PLUGIN_STATUS_ERROR
;
983 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
988 if (cc_full_descr
->methods
.filter
.msg_iter_init
) {
989 ret
= bt_component_class_filter_set_message_iterator_init_method(
991 cc_full_descr
->methods
.filter
.msg_iter_init
);
993 BT_LOGE_STR("Cannot set filter component class's message iterator initialization method.");
994 status
= BT_PLUGIN_STATUS_ERROR
;
995 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1000 if (cc_full_descr
->methods
.filter
.msg_iter_finalize
) {
1001 ret
= bt_component_class_filter_set_message_iterator_finalize_method(
1003 cc_full_descr
->methods
.filter
.msg_iter_finalize
);
1005 BT_LOGE_STR("Cannot set filter component class's message iterator finalization method.");
1006 status
= BT_PLUGIN_STATUS_ERROR
;
1007 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1013 case BT_COMPONENT_CLASS_TYPE_SINK
:
1014 if (cc_full_descr
->methods
.sink
.init
) {
1015 ret
= bt_component_class_sink_set_init_method(
1017 cc_full_descr
->methods
.sink
.init
);
1019 BT_LOGE_STR("Cannot set sink component class's initialization method.");
1020 status
= BT_PLUGIN_STATUS_ERROR
;
1021 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1026 if (cc_full_descr
->methods
.sink
.finalize
) {
1027 ret
= bt_component_class_sink_set_finalize_method(
1029 cc_full_descr
->methods
.sink
.finalize
);
1031 BT_LOGE_STR("Cannot set sink component class's finalization method.");
1032 status
= BT_PLUGIN_STATUS_ERROR
;
1033 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1038 if (cc_full_descr
->methods
.sink
.query
) {
1039 ret
= bt_component_class_sink_set_query_method(
1041 cc_full_descr
->methods
.sink
.query
);
1043 BT_LOGE_STR("Cannot set sink component class's query method.");
1044 status
= BT_PLUGIN_STATUS_ERROR
;
1045 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1050 if (cc_full_descr
->methods
.sink
.accept_input_port_connection
) {
1051 ret
= bt_component_class_sink_set_accept_input_port_connection_method(
1053 cc_full_descr
->methods
.sink
.accept_input_port_connection
);
1055 BT_LOGE_STR("Cannot set sink component class's \"accept input port connection\" method.");
1056 status
= BT_PLUGIN_STATUS_ERROR
;
1057 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1062 if (cc_full_descr
->methods
.sink
.input_port_connected
) {
1063 ret
= bt_component_class_sink_set_input_port_connected_method(
1065 cc_full_descr
->methods
.sink
.input_port_connected
);
1067 BT_LOGE_STR("Cannot set sink component class's \"input port connected\" method.");
1068 status
= BT_PLUGIN_STATUS_ERROR
;
1069 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1074 if (cc_full_descr
->methods
.sink
.input_port_disconnected
) {
1075 ret
= bt_component_class_sink_set_input_port_disconnected_method(
1077 cc_full_descr
->methods
.sink
.input_port_disconnected
);
1079 BT_LOGE_STR("Cannot set sink component class's \"input port disconnected\" method.");
1080 status
= BT_PLUGIN_STATUS_ERROR
;
1081 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1092 * Add component class to the plugin object.
1094 * This will call back
1095 * bt_plugin_so_on_add_component_class() so that we can
1096 * add a mapping in the component class list when we
1097 * know the component class is successfully added.
1099 status
= bt_plugin_add_component_class(plugin
,
1100 (void *) comp_class
);
1101 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
1103 BT_LOGE("Cannot add component class to plugin.");
1109 g_array_free(comp_class_full_descriptors
, TRUE
);
1114 struct bt_plugin
*bt_plugin_so_create_empty(
1115 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
)
1117 struct bt_plugin
*plugin
;
1118 struct bt_plugin_so_spec_data
*spec
;
1120 plugin
= bt_plugin_create_empty(BT_PLUGIN_TYPE_SO
);
1125 plugin
->destroy_spec_data
= bt_plugin_so_destroy_spec_data
;
1126 plugin
->spec_data
= g_new0(struct bt_plugin_so_spec_data
, 1);
1127 if (!plugin
->spec_data
) {
1128 BT_LOGE_STR("Failed to allocate one SO plugin specific data structure.");
1132 spec
= plugin
->spec_data
;
1133 spec
->shared_lib_handle
= shared_lib_handle
;
1134 bt_object_get_no_null_check(spec
->shared_lib_handle
);
1138 BT_OBJECT_PUT_REF_AND_RESET(plugin
);
1145 size_t count_non_null_items_in_section(const void *begin
, const void *end
)
1148 const int * const *begin_int
= (const int * const *) begin
;
1149 const int * const *end_int
= (const int * const *) end
;
1150 const int * const *iter
;
1152 for (iter
= begin_int
; iter
!= end_int
; iter
++) {
1162 struct bt_plugin_set
*bt_plugin_so_create_all_from_sections(
1163 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
,
1164 struct __bt_plugin_descriptor
const * const *descriptors_begin
,
1165 struct __bt_plugin_descriptor
const * const *descriptors_end
,
1166 struct __bt_plugin_descriptor_attribute
const * const *attrs_begin
,
1167 struct __bt_plugin_descriptor_attribute
const * const *attrs_end
,
1168 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_begin
,
1169 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_end
,
1170 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_begin
,
1171 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_end
)
1173 size_t descriptor_count
;
1175 size_t cc_descriptors_count
;
1176 size_t cc_descr_attrs_count
;
1178 struct bt_plugin_set
*plugin_set
= NULL
;
1180 descriptor_count
= count_non_null_items_in_section(descriptors_begin
, descriptors_end
);
1181 attrs_count
= count_non_null_items_in_section(attrs_begin
, attrs_end
);
1182 cc_descriptors_count
= count_non_null_items_in_section(cc_descriptors_begin
, cc_descriptors_end
);
1183 cc_descr_attrs_count
= count_non_null_items_in_section(cc_descr_attrs_begin
, cc_descr_attrs_end
);
1185 BT_LOGD("Creating all SO plugins from sections: "
1186 "plugin-path=\"%s\", "
1187 "descr-begin-addr=%p, descr-end-addr=%p, "
1188 "attrs-begin-addr=%p, attrs-end-addr=%p, "
1189 "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, "
1190 "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p, "
1191 "descr-count=%zu, attrs-count=%zu, "
1192 "cc-descr-count=%zu, cc-descr-attrs-count=%zu",
1193 shared_lib_handle
->path
? shared_lib_handle
->path
->str
: NULL
,
1194 descriptors_begin
, descriptors_end
,
1195 attrs_begin
, attrs_end
,
1196 cc_descriptors_begin
, cc_descriptors_end
,
1197 cc_descr_attrs_begin
, cc_descr_attrs_end
,
1198 descriptor_count
, attrs_count
,
1199 cc_descriptors_count
, cc_descr_attrs_count
);
1200 plugin_set
= bt_plugin_set_create();
1202 BT_LOGE_STR("Cannot create empty plugin set.");
1206 for (i
= 0; i
< descriptors_end
- descriptors_begin
; i
++) {
1207 enum bt_plugin_status status
;
1208 const struct __bt_plugin_descriptor
*descriptor
=
1209 descriptors_begin
[i
];
1210 struct bt_plugin
*plugin
;
1212 if (descriptor
== NULL
) {
1216 BT_LOGD("Creating plugin object for plugin: "
1217 "name=\"%s\", abi-major=%d, abi-minor=%d",
1218 descriptor
->name
, descriptor
->major
, descriptor
->minor
);
1220 if (descriptor
->major
> __BT_PLUGIN_VERSION_MAJOR
) {
1222 * DEBUG-level logging because we're only
1223 * _trying_ to open this file as a compatible
1224 * Babeltrace plugin: if it's not, it's not an
1225 * error. And because this can be tried during
1226 * bt_plugin_find_all_from_dir(), it's not
1229 BT_LOGD("Unknown ABI major version: abi-major=%d",
1234 plugin
= bt_plugin_so_create_empty(shared_lib_handle
);
1236 BT_LOGE_STR("Cannot create empty shared library handle.");
1240 if (shared_lib_handle
&& shared_lib_handle
->path
) {
1241 bt_plugin_set_path(plugin
, shared_lib_handle
->path
->str
);
1244 status
= bt_plugin_so_init(plugin
, descriptor
, attrs_begin
,
1245 attrs_end
, cc_descriptors_begin
, cc_descriptors_end
,
1246 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1249 * DEBUG-level logging because we're only
1250 * _trying_ to open this file as a compatible
1251 * Babeltrace plugin: if it's not, it's not an
1252 * error. And because this can be tried during
1253 * bt_plugin_find_all_from_dir(), it's not
1256 BT_LOGD_STR("Cannot initialize SO plugin object from sections.");
1257 BT_OBJECT_PUT_REF_AND_RESET(plugin
);
1261 /* Add to plugin set */
1262 bt_plugin_set_add_plugin(plugin_set
, plugin
);
1263 bt_object_put_ref(plugin
);
1269 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
1276 struct bt_plugin_set
*bt_plugin_so_create_all_from_static(void)
1278 struct bt_plugin_set
*plugin_set
= NULL
;
1279 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
=
1280 bt_plugin_so_shared_lib_handle_create(NULL
);
1282 if (!shared_lib_handle
) {
1286 BT_LOGD_STR("Creating all SO plugins from built-in plugins.");
1287 plugin_set
= bt_plugin_so_create_all_from_sections(shared_lib_handle
,
1288 __bt_get_begin_section_plugin_descriptors(),
1289 __bt_get_end_section_plugin_descriptors(),
1290 __bt_get_begin_section_plugin_descriptor_attributes(),
1291 __bt_get_end_section_plugin_descriptor_attributes(),
1292 __bt_get_begin_section_component_class_descriptors(),
1293 __bt_get_end_section_component_class_descriptors(),
1294 __bt_get_begin_section_component_class_descriptor_attributes(),
1295 __bt_get_end_section_component_class_descriptor_attributes());
1298 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle
);
1304 struct bt_plugin_set
*bt_plugin_so_create_all_from_file(const char *path
)
1307 struct bt_plugin_set
*plugin_set
= NULL
;
1308 struct __bt_plugin_descriptor
const * const *descriptors_begin
= NULL
;
1309 struct __bt_plugin_descriptor
const * const *descriptors_end
= NULL
;
1310 struct __bt_plugin_descriptor_attribute
const * const *attrs_begin
= NULL
;
1311 struct __bt_plugin_descriptor_attribute
const * const *attrs_end
= NULL
;
1312 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_begin
= NULL
;
1313 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_end
= NULL
;
1314 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_begin
= NULL
;
1315 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_end
= NULL
;
1316 struct __bt_plugin_descriptor
const * const *(*get_begin_section_plugin_descriptors
)(void);
1317 struct __bt_plugin_descriptor
const * const *(*get_end_section_plugin_descriptors
)(void);
1318 struct __bt_plugin_descriptor_attribute
const * const *(*get_begin_section_plugin_descriptor_attributes
)(void);
1319 struct __bt_plugin_descriptor_attribute
const * const *(*get_end_section_plugin_descriptor_attributes
)(void);
1320 struct __bt_plugin_component_class_descriptor
const * const *(*get_begin_section_component_class_descriptors
)(void);
1321 struct __bt_plugin_component_class_descriptor
const * const *(*get_end_section_component_class_descriptors
)(void);
1322 struct __bt_plugin_component_class_descriptor_attribute
const * const *(*get_begin_section_component_class_descriptor_attributes
)(void);
1323 struct __bt_plugin_component_class_descriptor_attribute
const * const *(*get_end_section_component_class_descriptor_attributes
)(void);
1324 bt_bool is_libtool_wrapper
= BT_FALSE
, is_shared_object
= BT_FALSE
;
1325 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
= NULL
;
1328 BT_LOGW_STR("Invalid parameter: path is NULL.");
1332 BT_LOGD("Creating all SO plugins from file: path=\"%s\"", path
);
1333 path_len
= strlen(path
);
1334 if (path_len
<= PLUGIN_SUFFIX_LEN
) {
1335 BT_LOGW("Invalid parameter: path length is too short: "
1336 "path-length=%zu", path_len
);
1342 * Check if the file ends with a known plugin file type suffix (i.e. .so
1345 is_libtool_wrapper
= !strncmp(LIBTOOL_PLUGIN_SUFFIX
,
1346 path
+ path_len
- LIBTOOL_PLUGIN_SUFFIX_LEN
,
1347 LIBTOOL_PLUGIN_SUFFIX_LEN
);
1348 is_shared_object
= !strncmp(NATIVE_PLUGIN_SUFFIX
,
1349 path
+ path_len
- NATIVE_PLUGIN_SUFFIX_LEN
,
1350 NATIVE_PLUGIN_SUFFIX_LEN
);
1351 if (!is_shared_object
&& !is_libtool_wrapper
) {
1352 /* Name indicates this is not a plugin file; not an error */
1353 BT_LOGV("File is not a SO plugin file: path=\"%s\"", path
);
1357 shared_lib_handle
= bt_plugin_so_shared_lib_handle_create(path
);
1358 if (!shared_lib_handle
) {
1359 BT_LOGD_STR("Cannot create shared library handle.");
1363 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_plugin_descriptors",
1364 (gpointer
*) &get_begin_section_plugin_descriptors
)) {
1365 descriptors_begin
= get_begin_section_plugin_descriptors();
1367 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1368 "symbol=\"%s\"", path
,
1369 "__bt_get_begin_section_plugin_descriptors");
1373 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_plugin_descriptors",
1374 (gpointer
*) &get_end_section_plugin_descriptors
)) {
1375 descriptors_end
= get_end_section_plugin_descriptors();
1377 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1378 "symbol=\"%s\"", path
,
1379 "__bt_get_end_section_plugin_descriptors");
1383 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_plugin_descriptor_attributes",
1384 (gpointer
*) &get_begin_section_plugin_descriptor_attributes
)) {
1385 attrs_begin
= get_begin_section_plugin_descriptor_attributes();
1387 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1388 "symbol=\"%s\"", path
,
1389 "__bt_get_begin_section_plugin_descriptor_attributes");
1392 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_plugin_descriptor_attributes",
1393 (gpointer
*) &get_end_section_plugin_descriptor_attributes
)) {
1394 attrs_end
= get_end_section_plugin_descriptor_attributes();
1396 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1397 "symbol=\"%s\"", path
,
1398 "__bt_get_end_section_plugin_descriptor_attributes");
1401 if ((!!attrs_begin
- !!attrs_end
) != 0) {
1402 BT_LOGD("Found section start or end symbol, but not both: "
1403 "path=\"%s\", symbol-start=\"%s\", "
1404 "symbol-end=\"%s\", symbol-start-addr=%p, "
1405 "symbol-end-addr=%p",
1406 path
, "__bt_get_begin_section_plugin_descriptor_attributes",
1407 "__bt_get_end_section_plugin_descriptor_attributes",
1408 attrs_begin
, attrs_end
);
1412 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_component_class_descriptors",
1413 (gpointer
*) &get_begin_section_component_class_descriptors
)) {
1414 cc_descriptors_begin
= get_begin_section_component_class_descriptors();
1416 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1417 "symbol=\"%s\"", path
,
1418 "__bt_get_begin_section_component_class_descriptors");
1421 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_component_class_descriptors",
1422 (gpointer
*) &get_end_section_component_class_descriptors
)) {
1423 cc_descriptors_end
= get_end_section_component_class_descriptors();
1425 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1426 "symbol=\"%s\"", path
,
1427 "__bt_get_end_section_component_class_descriptors");
1430 if ((!!cc_descriptors_begin
- !!cc_descriptors_end
) != 0) {
1431 BT_LOGD("Found section start or end symbol, but not both: "
1432 "path=\"%s\", symbol-start=\"%s\", "
1433 "symbol-end=\"%s\", symbol-start-addr=%p, "
1434 "symbol-end-addr=%p",
1435 path
, "__bt_get_begin_section_component_class_descriptors",
1436 "__bt_get_end_section_component_class_descriptors",
1437 cc_descriptors_begin
, cc_descriptors_end
);
1441 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_component_class_descriptor_attributes",
1442 (gpointer
*) &get_begin_section_component_class_descriptor_attributes
)) {
1443 cc_descr_attrs_begin
= get_begin_section_component_class_descriptor_attributes();
1445 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1446 "symbol=\"%s\"", path
,
1447 "__bt_get_begin_section_component_class_descriptor_attributes");
1450 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_component_class_descriptor_attributes",
1451 (gpointer
*) &get_end_section_component_class_descriptor_attributes
)) {
1452 cc_descr_attrs_end
= get_end_section_component_class_descriptor_attributes();
1454 BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
1455 "symbol=\"%s\"", path
,
1456 "__bt_get_end_section_component_class_descriptor_attributes");
1459 if ((!!cc_descr_attrs_begin
- !!cc_descr_attrs_end
) != 0) {
1460 BT_LOGD("Found section start or end symbol, but not both: "
1461 "path=\"%s\", symbol-start=\"%s\", "
1462 "symbol-end=\"%s\", symbol-start-addr=%p, "
1463 "symbol-end-addr=%p",
1464 path
, "__bt_get_begin_section_component_class_descriptor_attributes",
1465 "__bt_get_end_section_component_class_descriptor_attributes",
1466 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1470 /* Initialize plugin */
1471 BT_LOGD_STR("Initializing plugin object.");
1472 plugin_set
= bt_plugin_so_create_all_from_sections(shared_lib_handle
,
1473 descriptors_begin
, descriptors_end
, attrs_begin
, attrs_end
,
1474 cc_descriptors_begin
, cc_descriptors_end
,
1475 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1478 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle
);
1483 void plugin_comp_class_destroy_listener(struct bt_component_class
*comp_class
,
1486 bt_list_del(&comp_class
->node
);
1487 BT_OBJECT_PUT_REF_AND_RESET(comp_class
->so_handle
);
1488 BT_LOGV("Component class destroyed: removed entry from list: "
1489 "comp-cls-addr=%p", comp_class
);
1493 void bt_plugin_so_on_add_component_class(struct bt_plugin
*plugin
,
1494 struct bt_component_class
*comp_class
)
1496 struct bt_plugin_so_spec_data
*spec
= plugin
->spec_data
;
1498 BT_ASSERT(plugin
->spec_data
);
1499 BT_ASSERT(plugin
->type
== BT_PLUGIN_TYPE_SO
);
1501 bt_list_add(&comp_class
->node
, &component_class_list
);
1502 comp_class
->so_handle
= spec
->shared_lib_handle
;
1503 bt_object_get_no_null_check(comp_class
->so_handle
);
1505 /* Add our custom destroy listener */
1506 bt_component_class_add_destroy_listener(comp_class
,
1507 plugin_comp_class_destroy_listener
, NULL
);