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 "LIB/PLUGIN-SO"
27 #include "lib/logging.h"
29 #include "common/assert.h"
30 #include "lib/assert-pre.h"
31 #include "compat/compiler.h"
32 #include <babeltrace2/plugin/plugin-dev.h>
33 #include "lib/graph/component-class.h"
34 #include <babeltrace2/graph/component-class.h>
35 #include <babeltrace2/graph/component-class-source.h>
36 #include <babeltrace2/graph/component-class-filter.h>
37 #include <babeltrace2/graph/component-class-sink.h>
38 #include <babeltrace2/types.h>
39 #include "common/list.h"
46 #include "plugin-so.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 bt_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 const char *bt_self_plugin_status_string(enum bt_self_plugin_status status
)
109 case BT_SELF_PLUGIN_STATUS_OK
:
110 return "BT_SELF_PLUGIN_STATUS_OK";
111 case BT_SELF_PLUGIN_STATUS_ERROR
:
112 return "BT_SELF_PLUGIN_STATUS_ERROR";
113 case BT_SELF_PLUGIN_STATUS_NOMEM
:
114 return "BT_SELF_PLUGIN_STATUS_NOMEM";
121 void bt_plugin_so_shared_lib_handle_destroy(struct bt_object
*obj
)
123 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
;
126 shared_lib_handle
= container_of(obj
,
127 struct bt_plugin_so_shared_lib_handle
, base
);
128 const char *path
= shared_lib_handle
->path
?
129 shared_lib_handle
->path
->str
: NULL
;
131 BT_LOGI("Destroying shared library handle: addr=%p, path=\"%s\"",
132 shared_lib_handle
, path
);
134 if (shared_lib_handle
->init_called
&& shared_lib_handle
->exit
) {
135 BT_LOGD_STR("Calling user's plugin exit function.");
136 shared_lib_handle
->exit();
137 BT_LOGD_STR("User function returned.");
140 if (shared_lib_handle
->module
) {
141 #ifndef BT_DEBUG_MODE
143 * Valgrind shows incomplete stack traces when
144 * dynamically loaded libraries are closed before it
145 * finishes. Use the BABELTRACE_NO_DLCLOSE in a debug
146 * build to avoid this.
148 const char *var
= getenv("BABELTRACE_NO_DLCLOSE");
150 if (!var
|| strcmp(var
, "1") != 0) {
152 BT_LOGI("Closing GModule: path=\"%s\"", path
);
154 if (!g_module_close(shared_lib_handle
->module
)) {
155 BT_LOGE("Cannot close GModule: %s: path=\"%s\"",
156 g_module_error(), path
);
159 shared_lib_handle
->module
= NULL
;
160 #ifndef BT_DEBUG_MODE
162 BT_LOGI("Not closing GModule because `BABELTRACE_NO_DLCLOSE=1`: "
163 "path=\"%s\"", path
);
168 if (shared_lib_handle
->path
) {
169 g_string_free(shared_lib_handle
->path
, TRUE
);
170 shared_lib_handle
->path
= NULL
;
173 g_free(shared_lib_handle
);
177 struct bt_plugin_so_shared_lib_handle
*bt_plugin_so_shared_lib_handle_create(
180 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
= NULL
;
182 BT_LOGI("Creating shared library handle: path=\"%s\"", path
);
183 shared_lib_handle
= g_new0(struct bt_plugin_so_shared_lib_handle
, 1);
184 if (!shared_lib_handle
) {
185 BT_LOGE_STR("Failed to allocate one shared library handle.");
189 bt_object_init_shared(&shared_lib_handle
->base
,
190 bt_plugin_so_shared_lib_handle_destroy
);
196 shared_lib_handle
->path
= g_string_new(path
);
197 if (!shared_lib_handle
->path
) {
198 BT_LOGE_STR("Failed to allocate a GString.");
202 shared_lib_handle
->module
= g_module_open(path
, G_MODULE_BIND_LOCAL
);
203 if (!shared_lib_handle
->module
) {
205 * INFO-level logging because we're only _trying_ to
206 * open this file as a Babeltrace plugin: if it's not,
207 * it's not an error. And because this can be tried
208 * during bt_plugin_find_all_from_dir(), it's not even a
211 BT_LOGI("Cannot open GModule: %s: path=\"%s\"",
212 g_module_error(), path
);
219 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle
);
222 if (shared_lib_handle
) {
223 BT_LOGI("Created shared library handle: path=\"%s\", addr=%p",
224 path
, shared_lib_handle
);
227 return shared_lib_handle
;
231 void bt_plugin_so_destroy_spec_data(struct bt_plugin
*plugin
)
233 struct bt_plugin_so_spec_data
*spec
= plugin
->spec_data
;
235 if (!plugin
->spec_data
) {
239 BT_ASSERT(plugin
->type
== BT_PLUGIN_TYPE_SO
);
241 BT_OBJECT_PUT_REF_AND_RESET(spec
->shared_lib_handle
);
242 g_free(plugin
->spec_data
);
243 plugin
->spec_data
= NULL
;
247 * This function does the following:
249 * 1. Iterate on the plugin descriptor attributes section and set the
250 * plugin's attributes depending on the attribute types. This
251 * includes the name of the plugin, its description, and its
252 * initialization function, for example.
254 * 2. Iterate on the component class descriptors section and create one
255 * "full descriptor" (temporary structure) for each one that is found
256 * and attached to our plugin descriptor.
258 * 3. Iterate on the component class descriptor attributes section and
259 * set the corresponding full descriptor's attributes depending on
260 * the attribute types. This includes the description of the
261 * component class, as well as its initialization and destroy
264 * 4. Call the user's plugin initialization function, if any is
267 * 5. For each full component class descriptor, create a component class
268 * object, set its optional attributes, and add it to the plugin
271 * 6. Freeze the plugin object.
274 enum bt_plugin_status
bt_plugin_so_init(
275 struct bt_plugin
*plugin
,
276 const struct __bt_plugin_descriptor
*descriptor
,
277 struct __bt_plugin_descriptor_attribute
const * const *attrs_begin
,
278 struct __bt_plugin_descriptor_attribute
const * const *attrs_end
,
279 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_begin
,
280 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_end
,
281 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_begin
,
282 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_end
)
285 * This structure's members point to the plugin's memory
288 struct comp_class_full_descriptor
{
289 const struct __bt_plugin_component_class_descriptor
*descriptor
;
290 const char *description
;
295 bt_component_class_source_init_method init
;
296 bt_component_class_source_finalize_method finalize
;
297 bt_component_class_source_query_method query
;
298 bt_component_class_source_output_port_connected_method output_port_connected
;
299 bt_component_class_source_message_iterator_init_method msg_iter_init
;
300 bt_component_class_source_message_iterator_finalize_method msg_iter_finalize
;
301 bt_component_class_source_message_iterator_seek_ns_from_origin_method msg_iter_seek_ns_from_origin
;
302 bt_component_class_source_message_iterator_seek_beginning_method msg_iter_seek_beginning
;
303 bt_component_class_source_message_iterator_can_seek_ns_from_origin_method msg_iter_can_seek_ns_from_origin
;
304 bt_component_class_source_message_iterator_can_seek_beginning_method msg_iter_can_seek_beginning
;
308 bt_component_class_filter_init_method init
;
309 bt_component_class_filter_finalize_method finalize
;
310 bt_component_class_filter_query_method query
;
311 bt_component_class_filter_input_port_connected_method input_port_connected
;
312 bt_component_class_filter_output_port_connected_method output_port_connected
;
313 bt_component_class_filter_message_iterator_init_method msg_iter_init
;
314 bt_component_class_filter_message_iterator_finalize_method msg_iter_finalize
;
315 bt_component_class_filter_message_iterator_seek_ns_from_origin_method msg_iter_seek_ns_from_origin
;
316 bt_component_class_filter_message_iterator_seek_beginning_method msg_iter_seek_beginning
;
317 bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method msg_iter_can_seek_ns_from_origin
;
318 bt_component_class_filter_message_iterator_can_seek_beginning_method msg_iter_can_seek_beginning
;
322 bt_component_class_sink_init_method init
;
323 bt_component_class_sink_finalize_method finalize
;
324 bt_component_class_sink_query_method query
;
325 bt_component_class_sink_input_port_connected_method input_port_connected
;
326 bt_component_class_sink_graph_is_configured_method graph_is_configured
;
331 enum bt_plugin_status status
= BT_PLUGIN_STATUS_OK
;
332 struct __bt_plugin_descriptor_attribute
const * const *cur_attr_ptr
;
333 struct __bt_plugin_component_class_descriptor
const * const *cur_cc_descr_ptr
;
334 struct __bt_plugin_component_class_descriptor_attribute
const * const *cur_cc_descr_attr_ptr
;
335 struct bt_plugin_so_spec_data
*spec
= plugin
->spec_data
;
336 GArray
*comp_class_full_descriptors
;
340 BT_LOGI("Initializing plugin object from descriptors found in sections: "
341 "plugin-addr=%p, plugin-path=\"%s\", "
342 "attrs-begin-addr=%p, attrs-end-addr=%p, "
343 "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, "
344 "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p",
346 spec
->shared_lib_handle
->path
?
347 spec
->shared_lib_handle
->path
->str
: NULL
,
348 attrs_begin
, attrs_end
,
349 cc_descriptors_begin
, cc_descriptors_end
,
350 cc_descr_attrs_begin
, cc_descr_attrs_end
);
351 comp_class_full_descriptors
= g_array_new(FALSE
, TRUE
,
352 sizeof(struct comp_class_full_descriptor
));
353 if (!comp_class_full_descriptors
) {
354 BT_LOGE_STR("Failed to allocate a GArray.");
355 status
= BT_PLUGIN_STATUS_ERROR
;
359 /* Set mandatory attributes */
360 spec
->descriptor
= descriptor
;
361 bt_plugin_set_name(plugin
, descriptor
->name
);
364 * Find and set optional attributes attached to this plugin
367 for (cur_attr_ptr
= attrs_begin
; cur_attr_ptr
!= attrs_end
; cur_attr_ptr
++) {
368 const struct __bt_plugin_descriptor_attribute
*cur_attr
=
371 if (cur_attr
== NULL
) {
375 if (cur_attr
->plugin_descriptor
!= descriptor
) {
379 switch (cur_attr
->type
) {
380 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_INIT
:
381 spec
->init
= cur_attr
->value
.init
;
383 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_EXIT
:
384 spec
->shared_lib_handle
->exit
= cur_attr
->value
.exit
;
386 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_AUTHOR
:
387 bt_plugin_set_author(plugin
, cur_attr
->value
.author
);
389 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_LICENSE
:
390 bt_plugin_set_license(plugin
, cur_attr
->value
.license
);
392 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION
:
393 bt_plugin_set_description(plugin
, cur_attr
->value
.description
);
395 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_VERSION
:
396 bt_plugin_set_version(plugin
,
397 (unsigned int) cur_attr
->value
.version
.major
,
398 (unsigned int) cur_attr
->value
.version
.minor
,
399 (unsigned int) cur_attr
->value
.version
.patch
,
400 cur_attr
->value
.version
.extra
);
404 * WARN-level logging because this should not
405 * happen with the appropriate ABI version. If
406 * we're here, we know that for the reported
407 * version of the ABI, this attribute is
410 BT_LOGW("Ignoring unknown plugin descriptor attribute: "
411 "plugin-path=\"%s\", plugin-name=\"%s\", "
412 "attr-type-name=\"%s\", attr-type-id=%d",
413 spec
->shared_lib_handle
->path
?
414 spec
->shared_lib_handle
->path
->str
:
416 descriptor
->name
, cur_attr
->type_name
,
423 * Find component class descriptors attached to this plugin
424 * descriptor and initialize corresponding full component class
425 * descriptors in the array.
427 for (cur_cc_descr_ptr
= cc_descriptors_begin
; cur_cc_descr_ptr
!= cc_descriptors_end
; cur_cc_descr_ptr
++) {
428 const struct __bt_plugin_component_class_descriptor
*cur_cc_descr
=
430 struct comp_class_full_descriptor full_descriptor
= {0};
432 if (cur_cc_descr
== NULL
) {
436 if (cur_cc_descr
->plugin_descriptor
!= descriptor
) {
440 full_descriptor
.descriptor
= cur_cc_descr
;
441 g_array_append_val(comp_class_full_descriptors
,
446 * Find component class descriptor attributes attached to this
447 * plugin descriptor and update corresponding full component
448 * class descriptors in the array.
450 for (cur_cc_descr_attr_ptr
= cc_descr_attrs_begin
; cur_cc_descr_attr_ptr
!= cc_descr_attrs_end
; cur_cc_descr_attr_ptr
++) {
451 const struct __bt_plugin_component_class_descriptor_attribute
*cur_cc_descr_attr
=
452 *cur_cc_descr_attr_ptr
;
453 enum bt_component_class_type cc_type
;
455 if (cur_cc_descr_attr
== NULL
) {
459 if (cur_cc_descr_attr
->comp_class_descriptor
->plugin_descriptor
!=
464 cc_type
= cur_cc_descr_attr
->comp_class_descriptor
->type
;
466 /* Find the corresponding component class descriptor entry */
467 for (i
= 0; i
< comp_class_full_descriptors
->len
; i
++) {
468 struct comp_class_full_descriptor
*cc_full_descr
=
469 &g_array_index(comp_class_full_descriptors
,
470 struct comp_class_full_descriptor
, i
);
472 if (cur_cc_descr_attr
->comp_class_descriptor
!=
473 cc_full_descr
->descriptor
) {
477 switch (cur_cc_descr_attr
->type
) {
478 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION
:
479 cc_full_descr
->description
=
480 cur_cc_descr_attr
->value
.description
;
482 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP
:
483 cc_full_descr
->help
=
484 cur_cc_descr_attr
->value
.help
;
486 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD
:
488 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
489 cc_full_descr
->methods
.source
.init
=
490 cur_cc_descr_attr
->value
.source_init_method
;
492 case BT_COMPONENT_CLASS_TYPE_FILTER
:
493 cc_full_descr
->methods
.filter
.init
=
494 cur_cc_descr_attr
->value
.filter_init_method
;
496 case BT_COMPONENT_CLASS_TYPE_SINK
:
497 cc_full_descr
->methods
.sink
.init
=
498 cur_cc_descr_attr
->value
.sink_init_method
;
504 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD
:
506 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
507 cc_full_descr
->methods
.source
.finalize
=
508 cur_cc_descr_attr
->value
.source_finalize_method
;
510 case BT_COMPONENT_CLASS_TYPE_FILTER
:
511 cc_full_descr
->methods
.filter
.finalize
=
512 cur_cc_descr_attr
->value
.filter_finalize_method
;
514 case BT_COMPONENT_CLASS_TYPE_SINK
:
515 cc_full_descr
->methods
.sink
.finalize
=
516 cur_cc_descr_attr
->value
.sink_finalize_method
;
522 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD
:
524 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
525 cc_full_descr
->methods
.source
.query
=
526 cur_cc_descr_attr
->value
.source_query_method
;
528 case BT_COMPONENT_CLASS_TYPE_FILTER
:
529 cc_full_descr
->methods
.filter
.query
=
530 cur_cc_descr_attr
->value
.filter_query_method
;
532 case BT_COMPONENT_CLASS_TYPE_SINK
:
533 cc_full_descr
->methods
.sink
.query
=
534 cur_cc_descr_attr
->value
.sink_query_method
;
540 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD
:
542 case BT_COMPONENT_CLASS_TYPE_FILTER
:
543 cc_full_descr
->methods
.filter
.input_port_connected
=
544 cur_cc_descr_attr
->value
.filter_input_port_connected_method
;
546 case BT_COMPONENT_CLASS_TYPE_SINK
:
547 cc_full_descr
->methods
.sink
.input_port_connected
=
548 cur_cc_descr_attr
->value
.sink_input_port_connected_method
;
554 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD
:
556 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
557 cc_full_descr
->methods
.source
.output_port_connected
=
558 cur_cc_descr_attr
->value
.source_output_port_connected_method
;
560 case BT_COMPONENT_CLASS_TYPE_FILTER
:
561 cc_full_descr
->methods
.filter
.output_port_connected
=
562 cur_cc_descr_attr
->value
.filter_output_port_connected_method
;
568 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_GRAPH_IS_CONFIGURED_METHOD
:
570 case BT_COMPONENT_CLASS_TYPE_SINK
:
571 cc_full_descr
->methods
.sink
.graph_is_configured
=
572 cur_cc_descr_attr
->value
.sink_graph_is_configured_method
;
578 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INIT_METHOD
:
580 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
581 cc_full_descr
->methods
.source
.msg_iter_init
=
582 cur_cc_descr_attr
->value
.source_msg_iter_init_method
;
584 case BT_COMPONENT_CLASS_TYPE_FILTER
:
585 cc_full_descr
->methods
.filter
.msg_iter_init
=
586 cur_cc_descr_attr
->value
.filter_msg_iter_init_method
;
592 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_FINALIZE_METHOD
:
594 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
595 cc_full_descr
->methods
.source
.msg_iter_finalize
=
596 cur_cc_descr_attr
->value
.source_msg_iter_finalize_method
;
598 case BT_COMPONENT_CLASS_TYPE_FILTER
:
599 cc_full_descr
->methods
.filter
.msg_iter_finalize
=
600 cur_cc_descr_attr
->value
.filter_msg_iter_finalize_method
;
606 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_NS_FROM_ORIGIN_METHOD
:
608 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
609 cc_full_descr
->methods
.source
.msg_iter_seek_ns_from_origin
=
610 cur_cc_descr_attr
->value
.source_msg_iter_seek_ns_from_origin_method
;
612 case BT_COMPONENT_CLASS_TYPE_FILTER
:
613 cc_full_descr
->methods
.filter
.msg_iter_seek_ns_from_origin
=
614 cur_cc_descr_attr
->value
.filter_msg_iter_seek_ns_from_origin_method
;
620 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_BEGINNING_METHOD
:
622 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
623 cc_full_descr
->methods
.source
.msg_iter_seek_beginning
=
624 cur_cc_descr_attr
->value
.source_msg_iter_seek_beginning_method
;
626 case BT_COMPONENT_CLASS_TYPE_FILTER
:
627 cc_full_descr
->methods
.filter
.msg_iter_seek_beginning
=
628 cur_cc_descr_attr
->value
.filter_msg_iter_seek_beginning_method
;
634 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_NS_FROM_ORIGIN_METHOD
:
636 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
637 cc_full_descr
->methods
.source
.msg_iter_can_seek_ns_from_origin
=
638 cur_cc_descr_attr
->value
.source_msg_iter_can_seek_ns_from_origin_method
;
640 case BT_COMPONENT_CLASS_TYPE_FILTER
:
641 cc_full_descr
->methods
.filter
.msg_iter_can_seek_ns_from_origin
=
642 cur_cc_descr_attr
->value
.filter_msg_iter_can_seek_ns_from_origin_method
;
648 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_BEGINNING_METHOD
:
650 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
651 cc_full_descr
->methods
.source
.msg_iter_can_seek_beginning
=
652 cur_cc_descr_attr
->value
.source_msg_iter_can_seek_beginning_method
;
654 case BT_COMPONENT_CLASS_TYPE_FILTER
:
655 cc_full_descr
->methods
.filter
.msg_iter_can_seek_beginning
=
656 cur_cc_descr_attr
->value
.filter_msg_iter_can_seek_beginning_method
;
664 * WARN-level logging because this
665 * should not happen with the
666 * appropriate ABI version. If we're
667 * here, we know that for the reported
668 * version of the ABI, this attribute is
671 BT_LOGW("Ignoring unknown component class descriptor attribute: "
672 "plugin-path=\"%s\", "
673 "plugin-name=\"%s\", "
674 "comp-class-name=\"%s\", "
675 "comp-class-type=%s, "
676 "attr-type-name=\"%s\", "
678 spec
->shared_lib_handle
->path
?
679 spec
->shared_lib_handle
->path
->str
:
682 cur_cc_descr_attr
->comp_class_descriptor
->name
,
683 bt_component_class_type_string(
684 cur_cc_descr_attr
->comp_class_descriptor
->type
),
685 cur_cc_descr_attr
->type_name
,
686 cur_cc_descr_attr
->type
);
692 /* Initialize plugin */
694 enum bt_self_plugin_status init_status
;
696 BT_LOGD_STR("Calling user's plugin initialization function.");
697 init_status
= spec
->init((void *) plugin
);
698 BT_LOGD("User function returned: %s",
699 bt_self_plugin_status_string(init_status
));
701 if (init_status
< 0) {
702 BT_LOGW_STR("User's plugin initialization function failed.");
703 status
= BT_PLUGIN_STATUS_ERROR
;
708 spec
->shared_lib_handle
->init_called
= BT_TRUE
;
710 /* Add described component classes to plugin */
711 for (i
= 0; i
< comp_class_full_descriptors
->len
; i
++) {
712 struct comp_class_full_descriptor
*cc_full_descr
=
713 &g_array_index(comp_class_full_descriptors
,
714 struct comp_class_full_descriptor
, i
);
715 struct bt_component_class
*comp_class
= NULL
;
716 struct bt_component_class_source
*src_comp_class
= NULL
;
717 struct bt_component_class_filter
*flt_comp_class
= NULL
;
718 struct bt_component_class_sink
*sink_comp_class
= NULL
;
720 BT_LOGI("Creating and setting properties of plugin's component class: "
721 "plugin-path=\"%s\", plugin-name=\"%s\", "
722 "comp-class-name=\"%s\", comp-class-type=%s",
723 spec
->shared_lib_handle
->path
?
724 spec
->shared_lib_handle
->path
->str
:
727 cc_full_descr
->descriptor
->name
,
728 bt_component_class_type_string(
729 cc_full_descr
->descriptor
->type
));
731 switch (cc_full_descr
->descriptor
->type
) {
732 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
733 src_comp_class
= bt_component_class_source_create(
734 cc_full_descr
->descriptor
->name
,
735 cc_full_descr
->descriptor
->methods
.source
.msg_iter_next
);
736 comp_class
= bt_component_class_source_as_component_class(
739 case BT_COMPONENT_CLASS_TYPE_FILTER
:
740 flt_comp_class
= bt_component_class_filter_create(
741 cc_full_descr
->descriptor
->name
,
742 cc_full_descr
->descriptor
->methods
.source
.msg_iter_next
);
743 comp_class
= bt_component_class_filter_as_component_class(
746 case BT_COMPONENT_CLASS_TYPE_SINK
:
747 sink_comp_class
= bt_component_class_sink_create(
748 cc_full_descr
->descriptor
->name
,
749 cc_full_descr
->descriptor
->methods
.sink
.consume
);
750 comp_class
= bt_component_class_sink_as_component_class(
755 * WARN-level logging because this should not
756 * happen with the appropriate ABI version. If
757 * we're here, we know that for the reported
758 * version of the ABI, this component class type
761 BT_LOGW("Ignoring unknown component class type: "
762 "plugin-path=\"%s\", plugin-name=\"%s\", "
763 "comp-class-name=\"%s\", comp-class-type=%d",
764 spec
->shared_lib_handle
->path
->str
?
765 spec
->shared_lib_handle
->path
->str
:
768 cc_full_descr
->descriptor
->name
,
769 cc_full_descr
->descriptor
->type
);
774 BT_LOGE_STR("Cannot create component class.");
775 status
= BT_PLUGIN_STATUS_ERROR
;
779 if (cc_full_descr
->description
) {
780 ret
= bt_component_class_set_description(
781 comp_class
, cc_full_descr
->description
);
783 BT_LOGE_STR("Cannot set component class's description.");
784 status
= BT_PLUGIN_STATUS_ERROR
;
785 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
790 if (cc_full_descr
->help
) {
791 ret
= bt_component_class_set_help(comp_class
,
792 cc_full_descr
->help
);
794 BT_LOGE_STR("Cannot set component class's help string.");
795 status
= BT_PLUGIN_STATUS_ERROR
;
796 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
801 switch (cc_full_descr
->descriptor
->type
) {
802 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
803 if (cc_full_descr
->methods
.source
.init
) {
804 ret
= bt_component_class_source_set_init_method(
806 cc_full_descr
->methods
.source
.init
);
808 BT_LOGE_STR("Cannot set source component class's initialization method.");
809 status
= BT_PLUGIN_STATUS_ERROR
;
810 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
815 if (cc_full_descr
->methods
.source
.finalize
) {
816 ret
= bt_component_class_source_set_finalize_method(
818 cc_full_descr
->methods
.source
.finalize
);
820 BT_LOGE_STR("Cannot set source component class's finalization method.");
821 status
= BT_PLUGIN_STATUS_ERROR
;
822 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
827 if (cc_full_descr
->methods
.source
.query
) {
828 ret
= bt_component_class_source_set_query_method(
830 cc_full_descr
->methods
.source
.query
);
832 BT_LOGE_STR("Cannot set source component class's query 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_connected
) {
840 ret
= bt_component_class_source_set_output_port_connected_method(
842 cc_full_descr
->methods
.source
.output_port_connected
);
844 BT_LOGE_STR("Cannot set source component class's \"output port connected\" method.");
845 status
= BT_PLUGIN_STATUS_ERROR
;
846 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
851 if (cc_full_descr
->methods
.source
.msg_iter_init
) {
852 ret
= bt_component_class_source_set_message_iterator_init_method(
854 cc_full_descr
->methods
.source
.msg_iter_init
);
856 BT_LOGE_STR("Cannot set source component class's message 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
.msg_iter_finalize
) {
864 ret
= bt_component_class_source_set_message_iterator_finalize_method(
866 cc_full_descr
->methods
.source
.msg_iter_finalize
);
868 BT_LOGE_STR("Cannot set source component class's message iterator finalization method.");
869 status
= BT_PLUGIN_STATUS_ERROR
;
870 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
875 if (cc_full_descr
->methods
.source
.msg_iter_seek_ns_from_origin
) {
876 ret
= bt_component_class_source_set_message_iterator_seek_ns_from_origin_method(
878 cc_full_descr
->methods
.source
.msg_iter_seek_ns_from_origin
);
880 BT_LOGE_STR("Cannot set source component class's message iterator \"seek nanoseconds from origin\" method.");
881 status
= BT_PLUGIN_STATUS_ERROR
;
882 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
887 if (cc_full_descr
->methods
.source
.msg_iter_seek_beginning
) {
888 ret
= bt_component_class_source_set_message_iterator_seek_beginning_method(
890 cc_full_descr
->methods
.source
.msg_iter_seek_beginning
);
892 BT_LOGE_STR("Cannot set source component class's message iterator \"seek beginning\" method.");
893 status
= BT_PLUGIN_STATUS_ERROR
;
894 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
899 if (cc_full_descr
->methods
.source
.msg_iter_can_seek_ns_from_origin
) {
900 ret
= bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method(
902 cc_full_descr
->methods
.source
.msg_iter_can_seek_ns_from_origin
);
904 BT_LOGE_STR("Cannot set source component class's message iterator \"can seek nanoseconds from origin\" method.");
905 status
= BT_PLUGIN_STATUS_ERROR
;
906 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
911 if (cc_full_descr
->methods
.source
.msg_iter_can_seek_beginning
) {
912 ret
= bt_component_class_source_set_message_iterator_can_seek_beginning_method(
914 cc_full_descr
->methods
.source
.msg_iter_can_seek_beginning
);
916 BT_LOGE_STR("Cannot set source component class's message iterator \"can seek beginning\" method.");
917 status
= BT_PLUGIN_STATUS_ERROR
;
918 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
924 case BT_COMPONENT_CLASS_TYPE_FILTER
:
925 if (cc_full_descr
->methods
.filter
.init
) {
926 ret
= bt_component_class_filter_set_init_method(
928 cc_full_descr
->methods
.filter
.init
);
930 BT_LOGE_STR("Cannot set filter component class's initialization method.");
931 status
= BT_PLUGIN_STATUS_ERROR
;
932 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
937 if (cc_full_descr
->methods
.filter
.finalize
) {
938 ret
= bt_component_class_filter_set_finalize_method(
940 cc_full_descr
->methods
.filter
.finalize
);
942 BT_LOGE_STR("Cannot set filter component class's finalization method.");
943 status
= BT_PLUGIN_STATUS_ERROR
;
944 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
949 if (cc_full_descr
->methods
.filter
.query
) {
950 ret
= bt_component_class_filter_set_query_method(
952 cc_full_descr
->methods
.filter
.query
);
954 BT_LOGE_STR("Cannot set filter component class's query 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_connected
) {
962 ret
= bt_component_class_filter_set_input_port_connected_method(
964 cc_full_descr
->methods
.filter
.input_port_connected
);
966 BT_LOGE_STR("Cannot set filter component class's \"input port connected\" 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_connected
) {
974 ret
= bt_component_class_filter_set_output_port_connected_method(
976 cc_full_descr
->methods
.filter
.output_port_connected
);
978 BT_LOGE_STR("Cannot set filter component class's \"output port connected\" method.");
979 status
= BT_PLUGIN_STATUS_ERROR
;
980 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
985 if (cc_full_descr
->methods
.filter
.msg_iter_init
) {
986 ret
= bt_component_class_filter_set_message_iterator_init_method(
988 cc_full_descr
->methods
.filter
.msg_iter_init
);
990 BT_LOGE_STR("Cannot set filter component class's message 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
.msg_iter_finalize
) {
998 ret
= bt_component_class_filter_set_message_iterator_finalize_method(
1000 cc_full_descr
->methods
.filter
.msg_iter_finalize
);
1002 BT_LOGE_STR("Cannot set filter component class's message iterator finalization method.");
1003 status
= BT_PLUGIN_STATUS_ERROR
;
1004 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1009 if (cc_full_descr
->methods
.filter
.msg_iter_seek_ns_from_origin
) {
1010 ret
= bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method(
1012 cc_full_descr
->methods
.filter
.msg_iter_seek_ns_from_origin
);
1014 BT_LOGE_STR("Cannot set filter component class's message iterator \"seek nanoseconds from origin\" method.");
1015 status
= BT_PLUGIN_STATUS_ERROR
;
1016 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1021 if (cc_full_descr
->methods
.filter
.msg_iter_seek_beginning
) {
1022 ret
= bt_component_class_filter_set_message_iterator_seek_beginning_method(
1024 cc_full_descr
->methods
.filter
.msg_iter_seek_beginning
);
1026 BT_LOGE_STR("Cannot set filter component class's message iterator \"seek beginning\" method.");
1027 status
= BT_PLUGIN_STATUS_ERROR
;
1028 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1033 if (cc_full_descr
->methods
.filter
.msg_iter_can_seek_ns_from_origin
) {
1034 ret
= bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method(
1036 cc_full_descr
->methods
.filter
.msg_iter_can_seek_ns_from_origin
);
1038 BT_LOGE_STR("Cannot set filter component class's message iterator \"can seek nanoseconds from origin\" method.");
1039 status
= BT_PLUGIN_STATUS_ERROR
;
1040 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1045 if (cc_full_descr
->methods
.filter
.msg_iter_can_seek_beginning
) {
1046 ret
= bt_component_class_filter_set_message_iterator_can_seek_beginning_method(
1048 cc_full_descr
->methods
.filter
.msg_iter_can_seek_beginning
);
1050 BT_LOGE_STR("Cannot set filter component class's message iterator \"can seek beginning\" method.");
1051 status
= BT_PLUGIN_STATUS_ERROR
;
1052 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1058 case BT_COMPONENT_CLASS_TYPE_SINK
:
1059 if (cc_full_descr
->methods
.sink
.init
) {
1060 ret
= bt_component_class_sink_set_init_method(
1062 cc_full_descr
->methods
.sink
.init
);
1064 BT_LOGE_STR("Cannot set sink component class's initialization method.");
1065 status
= BT_PLUGIN_STATUS_ERROR
;
1066 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1071 if (cc_full_descr
->methods
.sink
.finalize
) {
1072 ret
= bt_component_class_sink_set_finalize_method(
1074 cc_full_descr
->methods
.sink
.finalize
);
1076 BT_LOGE_STR("Cannot set sink component class's finalization method.");
1077 status
= BT_PLUGIN_STATUS_ERROR
;
1078 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1083 if (cc_full_descr
->methods
.sink
.query
) {
1084 ret
= bt_component_class_sink_set_query_method(
1086 cc_full_descr
->methods
.sink
.query
);
1088 BT_LOGE_STR("Cannot set sink component class's query method.");
1089 status
= BT_PLUGIN_STATUS_ERROR
;
1090 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1095 if (cc_full_descr
->methods
.sink
.input_port_connected
) {
1096 ret
= bt_component_class_sink_set_input_port_connected_method(
1098 cc_full_descr
->methods
.sink
.input_port_connected
);
1100 BT_LOGE_STR("Cannot set sink component class's \"input port connected\" method.");
1101 status
= BT_PLUGIN_STATUS_ERROR
;
1102 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1107 if (cc_full_descr
->methods
.sink
.graph_is_configured
) {
1108 ret
= bt_component_class_sink_set_graph_is_configured_method(
1110 cc_full_descr
->methods
.sink
.graph_is_configured
);
1112 BT_LOGE_STR("Cannot set sink component class's \"graph is configured\" method.");
1113 status
= BT_PLUGIN_STATUS_ERROR
;
1114 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1125 * Add component class to the plugin object.
1127 * This will call back
1128 * bt_plugin_so_on_add_component_class() so that we can
1129 * add a mapping in the component class list when we
1130 * know the component class is successfully added.
1132 status
= bt_plugin_add_component_class(plugin
,
1133 (void *) comp_class
);
1134 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
1136 BT_LOGE("Cannot add component class to plugin.");
1142 g_array_free(comp_class_full_descriptors
, TRUE
);
1147 struct bt_plugin
*bt_plugin_so_create_empty(
1148 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
)
1150 struct bt_plugin
*plugin
;
1151 struct bt_plugin_so_spec_data
*spec
;
1153 plugin
= bt_plugin_create_empty(BT_PLUGIN_TYPE_SO
);
1158 plugin
->destroy_spec_data
= bt_plugin_so_destroy_spec_data
;
1159 plugin
->spec_data
= g_new0(struct bt_plugin_so_spec_data
, 1);
1160 if (!plugin
->spec_data
) {
1161 BT_LOGE_STR("Failed to allocate one SO plugin specific data structure.");
1165 spec
= plugin
->spec_data
;
1166 spec
->shared_lib_handle
= shared_lib_handle
;
1167 bt_object_get_no_null_check(spec
->shared_lib_handle
);
1171 BT_OBJECT_PUT_REF_AND_RESET(plugin
);
1178 size_t count_non_null_items_in_section(const void *begin
, const void *end
)
1181 const int * const *begin_int
= (const int * const *) begin
;
1182 const int * const *end_int
= (const int * const *) end
;
1183 const int * const *iter
;
1185 for (iter
= begin_int
; iter
!= end_int
; iter
++) {
1195 struct bt_plugin_set
*bt_plugin_so_create_all_from_sections(
1196 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
,
1197 struct __bt_plugin_descriptor
const * const *descriptors_begin
,
1198 struct __bt_plugin_descriptor
const * const *descriptors_end
,
1199 struct __bt_plugin_descriptor_attribute
const * const *attrs_begin
,
1200 struct __bt_plugin_descriptor_attribute
const * const *attrs_end
,
1201 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_begin
,
1202 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_end
,
1203 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_begin
,
1204 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_end
)
1206 size_t descriptor_count
;
1208 size_t cc_descriptors_count
;
1209 size_t cc_descr_attrs_count
;
1211 struct bt_plugin_set
*plugin_set
= NULL
;
1213 descriptor_count
= count_non_null_items_in_section(descriptors_begin
, descriptors_end
);
1214 attrs_count
= count_non_null_items_in_section(attrs_begin
, attrs_end
);
1215 cc_descriptors_count
= count_non_null_items_in_section(cc_descriptors_begin
, cc_descriptors_end
);
1216 cc_descr_attrs_count
= count_non_null_items_in_section(cc_descr_attrs_begin
, cc_descr_attrs_end
);
1218 BT_LOGI("Creating all SO plugins from sections: "
1219 "plugin-path=\"%s\", "
1220 "descr-begin-addr=%p, descr-end-addr=%p, "
1221 "attrs-begin-addr=%p, attrs-end-addr=%p, "
1222 "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, "
1223 "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p, "
1224 "descr-count=%zu, attrs-count=%zu, "
1225 "cc-descr-count=%zu, cc-descr-attrs-count=%zu",
1226 shared_lib_handle
->path
? shared_lib_handle
->path
->str
: NULL
,
1227 descriptors_begin
, descriptors_end
,
1228 attrs_begin
, attrs_end
,
1229 cc_descriptors_begin
, cc_descriptors_end
,
1230 cc_descr_attrs_begin
, cc_descr_attrs_end
,
1231 descriptor_count
, attrs_count
,
1232 cc_descriptors_count
, cc_descr_attrs_count
);
1233 plugin_set
= bt_plugin_set_create();
1235 BT_LOGE_STR("Cannot create empty plugin set.");
1239 for (i
= 0; i
< descriptors_end
- descriptors_begin
; i
++) {
1240 enum bt_plugin_status status
;
1241 const struct __bt_plugin_descriptor
*descriptor
=
1242 descriptors_begin
[i
];
1243 struct bt_plugin
*plugin
;
1245 if (descriptor
== NULL
) {
1249 BT_LOGI("Creating plugin object for plugin: "
1250 "name=\"%s\", abi-major=%d, abi-minor=%d",
1251 descriptor
->name
, descriptor
->major
, descriptor
->minor
);
1253 if (descriptor
->major
> __BT_PLUGIN_VERSION_MAJOR
) {
1255 * INFO-level logging because we're only
1256 * _trying_ to open this file as a compatible
1257 * Babeltrace plugin: if it's not, it's not an
1258 * error. And because this can be tried during
1259 * bt_plugin_find_all_from_dir(), it's not even
1262 BT_LOGI("Unknown ABI major version: abi-major=%d",
1267 plugin
= bt_plugin_so_create_empty(shared_lib_handle
);
1269 BT_LOGE_STR("Cannot create empty shared library handle.");
1273 if (shared_lib_handle
&& shared_lib_handle
->path
) {
1274 bt_plugin_set_path(plugin
, shared_lib_handle
->path
->str
);
1277 status
= bt_plugin_so_init(plugin
, descriptor
, attrs_begin
,
1278 attrs_end
, cc_descriptors_begin
, cc_descriptors_end
,
1279 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1282 * DEBUG-level logging because we're only
1283 * _trying_ to open this file as a compatible
1284 * Babeltrace plugin: if it's not, it's not an
1285 * error. And because this can be tried during
1286 * bt_plugin_find_all_from_dir(), it's not
1289 BT_LOGD_STR("Cannot initialize SO plugin object from sections.");
1290 BT_OBJECT_PUT_REF_AND_RESET(plugin
);
1294 /* Add to plugin set */
1295 bt_plugin_set_add_plugin(plugin_set
, plugin
);
1296 bt_object_put_ref(plugin
);
1302 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
1309 struct bt_plugin_set
*bt_plugin_so_create_all_from_static(void)
1311 struct bt_plugin_set
*plugin_set
= NULL
;
1312 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
=
1313 bt_plugin_so_shared_lib_handle_create(NULL
);
1315 if (!shared_lib_handle
) {
1319 BT_LOGD_STR("Creating all SO plugins from built-in plugins.");
1320 plugin_set
= bt_plugin_so_create_all_from_sections(shared_lib_handle
,
1321 __bt_get_begin_section_plugin_descriptors(),
1322 __bt_get_end_section_plugin_descriptors(),
1323 __bt_get_begin_section_plugin_descriptor_attributes(),
1324 __bt_get_end_section_plugin_descriptor_attributes(),
1325 __bt_get_begin_section_component_class_descriptors(),
1326 __bt_get_end_section_component_class_descriptors(),
1327 __bt_get_begin_section_component_class_descriptor_attributes(),
1328 __bt_get_end_section_component_class_descriptor_attributes());
1331 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle
);
1337 struct bt_plugin_set
*bt_plugin_so_create_all_from_file(const char *path
)
1340 struct bt_plugin_set
*plugin_set
= NULL
;
1341 struct __bt_plugin_descriptor
const * const *descriptors_begin
= NULL
;
1342 struct __bt_plugin_descriptor
const * const *descriptors_end
= NULL
;
1343 struct __bt_plugin_descriptor_attribute
const * const *attrs_begin
= NULL
;
1344 struct __bt_plugin_descriptor_attribute
const * const *attrs_end
= NULL
;
1345 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_begin
= NULL
;
1346 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_end
= NULL
;
1347 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_begin
= NULL
;
1348 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_end
= NULL
;
1349 struct __bt_plugin_descriptor
const * const *(*get_begin_section_plugin_descriptors
)(void);
1350 struct __bt_plugin_descriptor
const * const *(*get_end_section_plugin_descriptors
)(void);
1351 struct __bt_plugin_descriptor_attribute
const * const *(*get_begin_section_plugin_descriptor_attributes
)(void);
1352 struct __bt_plugin_descriptor_attribute
const * const *(*get_end_section_plugin_descriptor_attributes
)(void);
1353 struct __bt_plugin_component_class_descriptor
const * const *(*get_begin_section_component_class_descriptors
)(void);
1354 struct __bt_plugin_component_class_descriptor
const * const *(*get_end_section_component_class_descriptors
)(void);
1355 struct __bt_plugin_component_class_descriptor_attribute
const * const *(*get_begin_section_component_class_descriptor_attributes
)(void);
1356 struct __bt_plugin_component_class_descriptor_attribute
const * const *(*get_end_section_component_class_descriptor_attributes
)(void);
1357 bt_bool is_libtool_wrapper
= BT_FALSE
, is_shared_object
= BT_FALSE
;
1358 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
= NULL
;
1361 path_len
= strlen(path
);
1362 BT_ASSERT_PRE(path_len
> PLUGIN_SUFFIX_LEN
,
1363 "Path length is too short: path-length=%zu, min-length=%zu",
1364 path_len
, PLUGIN_SUFFIX_LEN
);
1365 BT_LOGI("Trying to create all SO plugins from file: path=\"%s\"", path
);
1369 * Check if the file ends with a known plugin file type suffix
1370 * (i.e. .so or .la on Linux).
1372 is_libtool_wrapper
= !strncmp(LIBTOOL_PLUGIN_SUFFIX
,
1373 path
+ path_len
- LIBTOOL_PLUGIN_SUFFIX_LEN
,
1374 LIBTOOL_PLUGIN_SUFFIX_LEN
);
1375 is_shared_object
= !strncmp(NATIVE_PLUGIN_SUFFIX
,
1376 path
+ path_len
- NATIVE_PLUGIN_SUFFIX_LEN
,
1377 NATIVE_PLUGIN_SUFFIX_LEN
);
1378 if (!is_shared_object
&& !is_libtool_wrapper
) {
1379 /* Name indicates this is not a plugin file; not an error */
1380 BT_LOGI("File is not a SO plugin file: path=\"%s\"", path
);
1384 shared_lib_handle
= bt_plugin_so_shared_lib_handle_create(path
);
1385 if (!shared_lib_handle
) {
1386 /* bt_plugin_so_shared_lib_handle_create() logs more details */
1387 BT_LOGD_STR("Cannot create shared library handle.");
1391 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_plugin_descriptors",
1392 (gpointer
*) &get_begin_section_plugin_descriptors
)) {
1393 descriptors_begin
= get_begin_section_plugin_descriptors();
1395 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1396 "symbol=\"%s\"", path
,
1397 "__bt_get_begin_section_plugin_descriptors");
1401 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_plugin_descriptors",
1402 (gpointer
*) &get_end_section_plugin_descriptors
)) {
1403 descriptors_end
= get_end_section_plugin_descriptors();
1405 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1406 "symbol=\"%s\"", path
,
1407 "__bt_get_end_section_plugin_descriptors");
1411 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_plugin_descriptor_attributes",
1412 (gpointer
*) &get_begin_section_plugin_descriptor_attributes
)) {
1413 attrs_begin
= get_begin_section_plugin_descriptor_attributes();
1415 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1416 "symbol=\"%s\"", path
,
1417 "__bt_get_begin_section_plugin_descriptor_attributes");
1420 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_plugin_descriptor_attributes",
1421 (gpointer
*) &get_end_section_plugin_descriptor_attributes
)) {
1422 attrs_end
= get_end_section_plugin_descriptor_attributes();
1424 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1425 "symbol=\"%s\"", path
,
1426 "__bt_get_end_section_plugin_descriptor_attributes");
1429 if ((!!attrs_begin
- !!attrs_end
) != 0) {
1430 BT_LOGI("Found section start or end symbol, but not both: "
1431 "path=\"%s\", symbol-start=\"%s\", "
1432 "symbol-end=\"%s\", symbol-start-addr=%p, "
1433 "symbol-end-addr=%p",
1434 path
, "__bt_get_begin_section_plugin_descriptor_attributes",
1435 "__bt_get_end_section_plugin_descriptor_attributes",
1436 attrs_begin
, attrs_end
);
1440 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_component_class_descriptors",
1441 (gpointer
*) &get_begin_section_component_class_descriptors
)) {
1442 cc_descriptors_begin
= get_begin_section_component_class_descriptors();
1444 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1445 "symbol=\"%s\"", path
,
1446 "__bt_get_begin_section_component_class_descriptors");
1449 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_component_class_descriptors",
1450 (gpointer
*) &get_end_section_component_class_descriptors
)) {
1451 cc_descriptors_end
= get_end_section_component_class_descriptors();
1453 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1454 "symbol=\"%s\"", path
,
1455 "__bt_get_end_section_component_class_descriptors");
1458 if ((!!cc_descriptors_begin
- !!cc_descriptors_end
) != 0) {
1459 BT_LOGI("Found section start or end symbol, but not both: "
1460 "path=\"%s\", symbol-start=\"%s\", "
1461 "symbol-end=\"%s\", symbol-start-addr=%p, "
1462 "symbol-end-addr=%p",
1463 path
, "__bt_get_begin_section_component_class_descriptors",
1464 "__bt_get_end_section_component_class_descriptors",
1465 cc_descriptors_begin
, cc_descriptors_end
);
1469 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_component_class_descriptor_attributes",
1470 (gpointer
*) &get_begin_section_component_class_descriptor_attributes
)) {
1471 cc_descr_attrs_begin
= get_begin_section_component_class_descriptor_attributes();
1473 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1474 "symbol=\"%s\"", path
,
1475 "__bt_get_begin_section_component_class_descriptor_attributes");
1478 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_component_class_descriptor_attributes",
1479 (gpointer
*) &get_end_section_component_class_descriptor_attributes
)) {
1480 cc_descr_attrs_end
= get_end_section_component_class_descriptor_attributes();
1482 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1483 "symbol=\"%s\"", path
,
1484 "__bt_get_end_section_component_class_descriptor_attributes");
1487 if ((!!cc_descr_attrs_begin
- !!cc_descr_attrs_end
) != 0) {
1488 BT_LOGI("Found section start or end symbol, but not both: "
1489 "path=\"%s\", symbol-start=\"%s\", "
1490 "symbol-end=\"%s\", symbol-start-addr=%p, "
1491 "symbol-end-addr=%p",
1492 path
, "__bt_get_begin_section_component_class_descriptor_attributes",
1493 "__bt_get_end_section_component_class_descriptor_attributes",
1494 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1498 /* Initialize plugin */
1499 BT_LOGD_STR("Initializing plugin object.");
1500 plugin_set
= bt_plugin_so_create_all_from_sections(shared_lib_handle
,
1501 descriptors_begin
, descriptors_end
, attrs_begin
, attrs_end
,
1502 cc_descriptors_begin
, cc_descriptors_end
,
1503 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1506 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle
);
1511 void plugin_comp_class_destroy_listener(struct bt_component_class
*comp_class
,
1514 bt_list_del(&comp_class
->node
);
1515 BT_OBJECT_PUT_REF_AND_RESET(comp_class
->so_handle
);
1516 BT_LOGD("Component class destroyed: removed entry from list: "
1517 "comp-cls-addr=%p", comp_class
);
1520 void bt_plugin_so_on_add_component_class(struct bt_plugin
*plugin
,
1521 struct bt_component_class
*comp_class
)
1523 struct bt_plugin_so_spec_data
*spec
= plugin
->spec_data
;
1525 BT_ASSERT(plugin
->spec_data
);
1526 BT_ASSERT(plugin
->type
== BT_PLUGIN_TYPE_SO
);
1528 bt_list_add(&comp_class
->node
, &component_class_list
);
1529 comp_class
->so_handle
= spec
->shared_lib_handle
;
1530 bt_object_get_no_null_check(comp_class
->so_handle
);
1532 /* Add our custom destroy listener */
1533 bt_component_class_add_destroy_listener(comp_class
,
1534 plugin_comp_class_destroy_listener
, NULL
);