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/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_accept_output_port_connection_method accept_output_port_connection
;
299 bt_component_class_source_output_port_connected_method output_port_connected
;
300 bt_component_class_source_message_iterator_init_method msg_iter_init
;
301 bt_component_class_source_message_iterator_finalize_method msg_iter_finalize
;
302 bt_component_class_source_message_iterator_seek_ns_from_origin_method msg_iter_seek_ns_from_origin
;
303 bt_component_class_source_message_iterator_seek_beginning_method msg_iter_seek_beginning
;
304 bt_component_class_source_message_iterator_can_seek_ns_from_origin_method msg_iter_can_seek_ns_from_origin
;
305 bt_component_class_source_message_iterator_can_seek_beginning_method msg_iter_can_seek_beginning
;
309 bt_component_class_filter_init_method init
;
310 bt_component_class_filter_finalize_method finalize
;
311 bt_component_class_filter_query_method query
;
312 bt_component_class_filter_accept_input_port_connection_method accept_input_port_connection
;
313 bt_component_class_filter_accept_output_port_connection_method accept_output_port_connection
;
314 bt_component_class_filter_input_port_connected_method input_port_connected
;
315 bt_component_class_filter_output_port_connected_method output_port_connected
;
316 bt_component_class_filter_message_iterator_init_method msg_iter_init
;
317 bt_component_class_filter_message_iterator_finalize_method msg_iter_finalize
;
318 bt_component_class_filter_message_iterator_seek_ns_from_origin_method msg_iter_seek_ns_from_origin
;
319 bt_component_class_filter_message_iterator_seek_beginning_method msg_iter_seek_beginning
;
320 bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method msg_iter_can_seek_ns_from_origin
;
321 bt_component_class_filter_message_iterator_can_seek_beginning_method msg_iter_can_seek_beginning
;
325 bt_component_class_sink_init_method init
;
326 bt_component_class_sink_finalize_method finalize
;
327 bt_component_class_sink_query_method query
;
328 bt_component_class_sink_accept_input_port_connection_method accept_input_port_connection
;
329 bt_component_class_sink_input_port_connected_method input_port_connected
;
330 bt_component_class_sink_graph_is_configured_method graph_is_configured
;
335 enum bt_plugin_status status
= BT_PLUGIN_STATUS_OK
;
336 struct __bt_plugin_descriptor_attribute
const * const *cur_attr_ptr
;
337 struct __bt_plugin_component_class_descriptor
const * const *cur_cc_descr_ptr
;
338 struct __bt_plugin_component_class_descriptor_attribute
const * const *cur_cc_descr_attr_ptr
;
339 struct bt_plugin_so_spec_data
*spec
= plugin
->spec_data
;
340 GArray
*comp_class_full_descriptors
;
344 BT_LOGI("Initializing plugin object from descriptors found in sections: "
345 "plugin-addr=%p, plugin-path=\"%s\", "
346 "attrs-begin-addr=%p, attrs-end-addr=%p, "
347 "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, "
348 "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p",
350 spec
->shared_lib_handle
->path
?
351 spec
->shared_lib_handle
->path
->str
: NULL
,
352 attrs_begin
, attrs_end
,
353 cc_descriptors_begin
, cc_descriptors_end
,
354 cc_descr_attrs_begin
, cc_descr_attrs_end
);
355 comp_class_full_descriptors
= g_array_new(FALSE
, TRUE
,
356 sizeof(struct comp_class_full_descriptor
));
357 if (!comp_class_full_descriptors
) {
358 BT_LOGE_STR("Failed to allocate a GArray.");
359 status
= BT_PLUGIN_STATUS_ERROR
;
363 /* Set mandatory attributes */
364 spec
->descriptor
= descriptor
;
365 bt_plugin_set_name(plugin
, descriptor
->name
);
368 * Find and set optional attributes attached to this plugin
371 for (cur_attr_ptr
= attrs_begin
; cur_attr_ptr
!= attrs_end
; cur_attr_ptr
++) {
372 const struct __bt_plugin_descriptor_attribute
*cur_attr
=
375 if (cur_attr
== NULL
) {
379 if (cur_attr
->plugin_descriptor
!= descriptor
) {
383 switch (cur_attr
->type
) {
384 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_INIT
:
385 spec
->init
= cur_attr
->value
.init
;
387 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_EXIT
:
388 spec
->shared_lib_handle
->exit
= cur_attr
->value
.exit
;
390 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_AUTHOR
:
391 bt_plugin_set_author(plugin
, cur_attr
->value
.author
);
393 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_LICENSE
:
394 bt_plugin_set_license(plugin
, cur_attr
->value
.license
);
396 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION
:
397 bt_plugin_set_description(plugin
, cur_attr
->value
.description
);
399 case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_VERSION
:
400 bt_plugin_set_version(plugin
,
401 (unsigned int) cur_attr
->value
.version
.major
,
402 (unsigned int) cur_attr
->value
.version
.minor
,
403 (unsigned int) cur_attr
->value
.version
.patch
,
404 cur_attr
->value
.version
.extra
);
408 * WARN-level logging because this should not
409 * happen with the appropriate ABI version. If
410 * we're here, we know that for the reported
411 * version of the ABI, this attribute is
414 BT_LOGW("Ignoring unknown plugin descriptor attribute: "
415 "plugin-path=\"%s\", plugin-name=\"%s\", "
416 "attr-type-name=\"%s\", attr-type-id=%d",
417 spec
->shared_lib_handle
->path
?
418 spec
->shared_lib_handle
->path
->str
:
420 descriptor
->name
, cur_attr
->type_name
,
427 * Find component class descriptors attached to this plugin
428 * descriptor and initialize corresponding full component class
429 * descriptors in the array.
431 for (cur_cc_descr_ptr
= cc_descriptors_begin
; cur_cc_descr_ptr
!= cc_descriptors_end
; cur_cc_descr_ptr
++) {
432 const struct __bt_plugin_component_class_descriptor
*cur_cc_descr
=
434 struct comp_class_full_descriptor full_descriptor
= {0};
436 if (cur_cc_descr
== NULL
) {
440 if (cur_cc_descr
->plugin_descriptor
!= descriptor
) {
444 full_descriptor
.descriptor
= cur_cc_descr
;
445 g_array_append_val(comp_class_full_descriptors
,
450 * Find component class descriptor attributes attached to this
451 * plugin descriptor and update corresponding full component
452 * class descriptors in the array.
454 for (cur_cc_descr_attr_ptr
= cc_descr_attrs_begin
; cur_cc_descr_attr_ptr
!= cc_descr_attrs_end
; cur_cc_descr_attr_ptr
++) {
455 const struct __bt_plugin_component_class_descriptor_attribute
*cur_cc_descr_attr
=
456 *cur_cc_descr_attr_ptr
;
457 enum bt_component_class_type cc_type
;
459 if (cur_cc_descr_attr
== NULL
) {
463 if (cur_cc_descr_attr
->comp_class_descriptor
->plugin_descriptor
!=
468 cc_type
= cur_cc_descr_attr
->comp_class_descriptor
->type
;
470 /* Find the corresponding component class descriptor entry */
471 for (i
= 0; i
< comp_class_full_descriptors
->len
; i
++) {
472 struct comp_class_full_descriptor
*cc_full_descr
=
473 &g_array_index(comp_class_full_descriptors
,
474 struct comp_class_full_descriptor
, i
);
476 if (cur_cc_descr_attr
->comp_class_descriptor
!=
477 cc_full_descr
->descriptor
) {
481 switch (cur_cc_descr_attr
->type
) {
482 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION
:
483 cc_full_descr
->description
=
484 cur_cc_descr_attr
->value
.description
;
486 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP
:
487 cc_full_descr
->help
=
488 cur_cc_descr_attr
->value
.help
;
490 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD
:
492 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
493 cc_full_descr
->methods
.source
.init
=
494 cur_cc_descr_attr
->value
.source_init_method
;
496 case BT_COMPONENT_CLASS_TYPE_FILTER
:
497 cc_full_descr
->methods
.filter
.init
=
498 cur_cc_descr_attr
->value
.filter_init_method
;
500 case BT_COMPONENT_CLASS_TYPE_SINK
:
501 cc_full_descr
->methods
.sink
.init
=
502 cur_cc_descr_attr
->value
.sink_init_method
;
508 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD
:
510 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
511 cc_full_descr
->methods
.source
.finalize
=
512 cur_cc_descr_attr
->value
.source_finalize_method
;
514 case BT_COMPONENT_CLASS_TYPE_FILTER
:
515 cc_full_descr
->methods
.filter
.finalize
=
516 cur_cc_descr_attr
->value
.filter_finalize_method
;
518 case BT_COMPONENT_CLASS_TYPE_SINK
:
519 cc_full_descr
->methods
.sink
.finalize
=
520 cur_cc_descr_attr
->value
.sink_finalize_method
;
526 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD
:
528 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
529 cc_full_descr
->methods
.source
.query
=
530 cur_cc_descr_attr
->value
.source_query_method
;
532 case BT_COMPONENT_CLASS_TYPE_FILTER
:
533 cc_full_descr
->methods
.filter
.query
=
534 cur_cc_descr_attr
->value
.filter_query_method
;
536 case BT_COMPONENT_CLASS_TYPE_SINK
:
537 cc_full_descr
->methods
.sink
.query
=
538 cur_cc_descr_attr
->value
.sink_query_method
;
544 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_INPUT_PORT_CONNECTION_METHOD
:
546 case BT_COMPONENT_CLASS_TYPE_FILTER
:
547 cc_full_descr
->methods
.filter
.accept_input_port_connection
=
548 cur_cc_descr_attr
->value
.filter_accept_input_port_connection_method
;
550 case BT_COMPONENT_CLASS_TYPE_SINK
:
551 cc_full_descr
->methods
.sink
.accept_input_port_connection
=
552 cur_cc_descr_attr
->value
.sink_accept_input_port_connection_method
;
558 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD
:
560 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
561 cc_full_descr
->methods
.source
.accept_output_port_connection
=
562 cur_cc_descr_attr
->value
.source_accept_output_port_connection_method
;
564 case BT_COMPONENT_CLASS_TYPE_FILTER
:
565 cc_full_descr
->methods
.filter
.accept_output_port_connection
=
566 cur_cc_descr_attr
->value
.filter_accept_output_port_connection_method
;
572 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD
:
574 case BT_COMPONENT_CLASS_TYPE_FILTER
:
575 cc_full_descr
->methods
.filter
.input_port_connected
=
576 cur_cc_descr_attr
->value
.filter_input_port_connected_method
;
578 case BT_COMPONENT_CLASS_TYPE_SINK
:
579 cc_full_descr
->methods
.sink
.input_port_connected
=
580 cur_cc_descr_attr
->value
.sink_input_port_connected_method
;
586 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD
:
588 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
589 cc_full_descr
->methods
.source
.output_port_connected
=
590 cur_cc_descr_attr
->value
.source_output_port_connected_method
;
592 case BT_COMPONENT_CLASS_TYPE_FILTER
:
593 cc_full_descr
->methods
.filter
.output_port_connected
=
594 cur_cc_descr_attr
->value
.filter_output_port_connected_method
;
600 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_GRAPH_IS_CONFIGURED_METHOD
:
602 case BT_COMPONENT_CLASS_TYPE_SINK
:
603 cc_full_descr
->methods
.sink
.graph_is_configured
=
604 cur_cc_descr_attr
->value
.sink_graph_is_configured_method
;
610 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INIT_METHOD
:
612 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
613 cc_full_descr
->methods
.source
.msg_iter_init
=
614 cur_cc_descr_attr
->value
.source_msg_iter_init_method
;
616 case BT_COMPONENT_CLASS_TYPE_FILTER
:
617 cc_full_descr
->methods
.filter
.msg_iter_init
=
618 cur_cc_descr_attr
->value
.filter_msg_iter_init_method
;
624 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_FINALIZE_METHOD
:
626 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
627 cc_full_descr
->methods
.source
.msg_iter_finalize
=
628 cur_cc_descr_attr
->value
.source_msg_iter_finalize_method
;
630 case BT_COMPONENT_CLASS_TYPE_FILTER
:
631 cc_full_descr
->methods
.filter
.msg_iter_finalize
=
632 cur_cc_descr_attr
->value
.filter_msg_iter_finalize_method
;
638 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_NS_FROM_ORIGIN_METHOD
:
640 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
641 cc_full_descr
->methods
.source
.msg_iter_seek_ns_from_origin
=
642 cur_cc_descr_attr
->value
.source_msg_iter_seek_ns_from_origin_method
;
644 case BT_COMPONENT_CLASS_TYPE_FILTER
:
645 cc_full_descr
->methods
.filter
.msg_iter_seek_ns_from_origin
=
646 cur_cc_descr_attr
->value
.filter_msg_iter_seek_ns_from_origin_method
;
652 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_BEGINNING_METHOD
:
654 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
655 cc_full_descr
->methods
.source
.msg_iter_seek_beginning
=
656 cur_cc_descr_attr
->value
.source_msg_iter_seek_beginning_method
;
658 case BT_COMPONENT_CLASS_TYPE_FILTER
:
659 cc_full_descr
->methods
.filter
.msg_iter_seek_beginning
=
660 cur_cc_descr_attr
->value
.filter_msg_iter_seek_beginning_method
;
666 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_NS_FROM_ORIGIN_METHOD
:
668 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
669 cc_full_descr
->methods
.source
.msg_iter_can_seek_ns_from_origin
=
670 cur_cc_descr_attr
->value
.source_msg_iter_can_seek_ns_from_origin_method
;
672 case BT_COMPONENT_CLASS_TYPE_FILTER
:
673 cc_full_descr
->methods
.filter
.msg_iter_can_seek_ns_from_origin
=
674 cur_cc_descr_attr
->value
.filter_msg_iter_can_seek_ns_from_origin_method
;
680 case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_BEGINNING_METHOD
:
682 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
683 cc_full_descr
->methods
.source
.msg_iter_can_seek_beginning
=
684 cur_cc_descr_attr
->value
.source_msg_iter_can_seek_beginning_method
;
686 case BT_COMPONENT_CLASS_TYPE_FILTER
:
687 cc_full_descr
->methods
.filter
.msg_iter_can_seek_beginning
=
688 cur_cc_descr_attr
->value
.filter_msg_iter_can_seek_beginning_method
;
696 * WARN-level logging because this
697 * should not happen with the
698 * appropriate ABI version. If we're
699 * here, we know that for the reported
700 * version of the ABI, this attribute is
703 BT_LOGW("Ignoring unknown component class descriptor attribute: "
704 "plugin-path=\"%s\", "
705 "plugin-name=\"%s\", "
706 "comp-class-name=\"%s\", "
707 "comp-class-type=%s, "
708 "attr-type-name=\"%s\", "
710 spec
->shared_lib_handle
->path
?
711 spec
->shared_lib_handle
->path
->str
:
714 cur_cc_descr_attr
->comp_class_descriptor
->name
,
715 bt_component_class_type_string(
716 cur_cc_descr_attr
->comp_class_descriptor
->type
),
717 cur_cc_descr_attr
->type_name
,
718 cur_cc_descr_attr
->type
);
724 /* Initialize plugin */
726 enum bt_self_plugin_status init_status
;
728 BT_LOGD_STR("Calling user's plugin initialization function.");
729 init_status
= spec
->init((void *) plugin
);
730 BT_LOGD("User function returned: %s",
731 bt_self_plugin_status_string(init_status
));
733 if (init_status
< 0) {
734 BT_LOGW_STR("User's plugin initialization function failed.");
735 status
= BT_PLUGIN_STATUS_ERROR
;
740 spec
->shared_lib_handle
->init_called
= BT_TRUE
;
742 /* Add described component classes to plugin */
743 for (i
= 0; i
< comp_class_full_descriptors
->len
; i
++) {
744 struct comp_class_full_descriptor
*cc_full_descr
=
745 &g_array_index(comp_class_full_descriptors
,
746 struct comp_class_full_descriptor
, i
);
747 struct bt_component_class
*comp_class
= NULL
;
748 struct bt_component_class_source
*src_comp_class
= NULL
;
749 struct bt_component_class_filter
*flt_comp_class
= NULL
;
750 struct bt_component_class_sink
*sink_comp_class
= NULL
;
752 BT_LOGI("Creating and setting properties of plugin's component class: "
753 "plugin-path=\"%s\", plugin-name=\"%s\", "
754 "comp-class-name=\"%s\", comp-class-type=%s",
755 spec
->shared_lib_handle
->path
?
756 spec
->shared_lib_handle
->path
->str
:
759 cc_full_descr
->descriptor
->name
,
760 bt_component_class_type_string(
761 cc_full_descr
->descriptor
->type
));
763 switch (cc_full_descr
->descriptor
->type
) {
764 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
765 src_comp_class
= bt_component_class_source_create(
766 cc_full_descr
->descriptor
->name
,
767 cc_full_descr
->descriptor
->methods
.source
.msg_iter_next
);
768 comp_class
= bt_component_class_source_as_component_class(
771 case BT_COMPONENT_CLASS_TYPE_FILTER
:
772 flt_comp_class
= bt_component_class_filter_create(
773 cc_full_descr
->descriptor
->name
,
774 cc_full_descr
->descriptor
->methods
.source
.msg_iter_next
);
775 comp_class
= bt_component_class_filter_as_component_class(
778 case BT_COMPONENT_CLASS_TYPE_SINK
:
779 sink_comp_class
= bt_component_class_sink_create(
780 cc_full_descr
->descriptor
->name
,
781 cc_full_descr
->descriptor
->methods
.sink
.consume
);
782 comp_class
= bt_component_class_sink_as_component_class(
787 * WARN-level logging because this should not
788 * happen with the appropriate ABI version. If
789 * we're here, we know that for the reported
790 * version of the ABI, this component class type
793 BT_LOGW("Ignoring unknown component class type: "
794 "plugin-path=\"%s\", plugin-name=\"%s\", "
795 "comp-class-name=\"%s\", comp-class-type=%d",
796 spec
->shared_lib_handle
->path
->str
?
797 spec
->shared_lib_handle
->path
->str
:
800 cc_full_descr
->descriptor
->name
,
801 cc_full_descr
->descriptor
->type
);
806 BT_LOGE_STR("Cannot create component class.");
807 status
= BT_PLUGIN_STATUS_ERROR
;
811 if (cc_full_descr
->description
) {
812 ret
= bt_component_class_set_description(
813 comp_class
, cc_full_descr
->description
);
815 BT_LOGE_STR("Cannot set component class's description.");
816 status
= BT_PLUGIN_STATUS_ERROR
;
817 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
822 if (cc_full_descr
->help
) {
823 ret
= bt_component_class_set_help(comp_class
,
824 cc_full_descr
->help
);
826 BT_LOGE_STR("Cannot set component class's help string.");
827 status
= BT_PLUGIN_STATUS_ERROR
;
828 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
833 switch (cc_full_descr
->descriptor
->type
) {
834 case BT_COMPONENT_CLASS_TYPE_SOURCE
:
835 if (cc_full_descr
->methods
.source
.init
) {
836 ret
= bt_component_class_source_set_init_method(
838 cc_full_descr
->methods
.source
.init
);
840 BT_LOGE_STR("Cannot set source component class's initialization method.");
841 status
= BT_PLUGIN_STATUS_ERROR
;
842 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
847 if (cc_full_descr
->methods
.source
.finalize
) {
848 ret
= bt_component_class_source_set_finalize_method(
850 cc_full_descr
->methods
.source
.finalize
);
852 BT_LOGE_STR("Cannot set source component class's finalization method.");
853 status
= BT_PLUGIN_STATUS_ERROR
;
854 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
859 if (cc_full_descr
->methods
.source
.query
) {
860 ret
= bt_component_class_source_set_query_method(
862 cc_full_descr
->methods
.source
.query
);
864 BT_LOGE_STR("Cannot set source component class's query method.");
865 status
= BT_PLUGIN_STATUS_ERROR
;
866 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
871 if (cc_full_descr
->methods
.source
.accept_output_port_connection
) {
872 ret
= bt_component_class_source_set_accept_output_port_connection_method(
874 cc_full_descr
->methods
.source
.accept_output_port_connection
);
876 BT_LOGE_STR("Cannot set source component class's \"accept input output connection\" method.");
877 status
= BT_PLUGIN_STATUS_ERROR
;
878 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
883 if (cc_full_descr
->methods
.source
.output_port_connected
) {
884 ret
= bt_component_class_source_set_output_port_connected_method(
886 cc_full_descr
->methods
.source
.output_port_connected
);
888 BT_LOGE_STR("Cannot set source component class's \"output port connected\" method.");
889 status
= BT_PLUGIN_STATUS_ERROR
;
890 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
895 if (cc_full_descr
->methods
.source
.msg_iter_init
) {
896 ret
= bt_component_class_source_set_message_iterator_init_method(
898 cc_full_descr
->methods
.source
.msg_iter_init
);
900 BT_LOGE_STR("Cannot set source component class's message iterator initialization method.");
901 status
= BT_PLUGIN_STATUS_ERROR
;
902 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
907 if (cc_full_descr
->methods
.source
.msg_iter_finalize
) {
908 ret
= bt_component_class_source_set_message_iterator_finalize_method(
910 cc_full_descr
->methods
.source
.msg_iter_finalize
);
912 BT_LOGE_STR("Cannot set source component class's message iterator finalization method.");
913 status
= BT_PLUGIN_STATUS_ERROR
;
914 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
919 if (cc_full_descr
->methods
.source
.msg_iter_seek_ns_from_origin
) {
920 ret
= bt_component_class_source_set_message_iterator_seek_ns_from_origin_method(
922 cc_full_descr
->methods
.source
.msg_iter_seek_ns_from_origin
);
924 BT_LOGE_STR("Cannot set source component class's message iterator \"seek nanoseconds from origin\" method.");
925 status
= BT_PLUGIN_STATUS_ERROR
;
926 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
931 if (cc_full_descr
->methods
.source
.msg_iter_seek_beginning
) {
932 ret
= bt_component_class_source_set_message_iterator_seek_beginning_method(
934 cc_full_descr
->methods
.source
.msg_iter_seek_beginning
);
936 BT_LOGE_STR("Cannot set source component class's message iterator \"seek beginning\" method.");
937 status
= BT_PLUGIN_STATUS_ERROR
;
938 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
943 if (cc_full_descr
->methods
.source
.msg_iter_can_seek_ns_from_origin
) {
944 ret
= bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method(
946 cc_full_descr
->methods
.source
.msg_iter_can_seek_ns_from_origin
);
948 BT_LOGE_STR("Cannot set source component class's message iterator \"can seek nanoseconds from origin\" method.");
949 status
= BT_PLUGIN_STATUS_ERROR
;
950 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
955 if (cc_full_descr
->methods
.source
.msg_iter_can_seek_beginning
) {
956 ret
= bt_component_class_source_set_message_iterator_can_seek_beginning_method(
958 cc_full_descr
->methods
.source
.msg_iter_can_seek_beginning
);
960 BT_LOGE_STR("Cannot set source component class's message iterator \"can seek beginning\" method.");
961 status
= BT_PLUGIN_STATUS_ERROR
;
962 BT_OBJECT_PUT_REF_AND_RESET(src_comp_class
);
968 case BT_COMPONENT_CLASS_TYPE_FILTER
:
969 if (cc_full_descr
->methods
.filter
.init
) {
970 ret
= bt_component_class_filter_set_init_method(
972 cc_full_descr
->methods
.filter
.init
);
974 BT_LOGE_STR("Cannot set filter component class's initialization method.");
975 status
= BT_PLUGIN_STATUS_ERROR
;
976 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
981 if (cc_full_descr
->methods
.filter
.finalize
) {
982 ret
= bt_component_class_filter_set_finalize_method(
984 cc_full_descr
->methods
.filter
.finalize
);
986 BT_LOGE_STR("Cannot set filter component class's finalization method.");
987 status
= BT_PLUGIN_STATUS_ERROR
;
988 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
993 if (cc_full_descr
->methods
.filter
.query
) {
994 ret
= bt_component_class_filter_set_query_method(
996 cc_full_descr
->methods
.filter
.query
);
998 BT_LOGE_STR("Cannot set filter component class's query method.");
999 status
= BT_PLUGIN_STATUS_ERROR
;
1000 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1005 if (cc_full_descr
->methods
.filter
.accept_input_port_connection
) {
1006 ret
= bt_component_class_filter_set_accept_input_port_connection_method(
1008 cc_full_descr
->methods
.filter
.accept_input_port_connection
);
1010 BT_LOGE_STR("Cannot set filter component class's \"accept input port connection\" method.");
1011 status
= BT_PLUGIN_STATUS_ERROR
;
1012 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1017 if (cc_full_descr
->methods
.filter
.accept_output_port_connection
) {
1018 ret
= bt_component_class_filter_set_accept_output_port_connection_method(
1020 cc_full_descr
->methods
.filter
.accept_output_port_connection
);
1022 BT_LOGE_STR("Cannot set filter component class's \"accept input output connection\" method.");
1023 status
= BT_PLUGIN_STATUS_ERROR
;
1024 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1029 if (cc_full_descr
->methods
.filter
.input_port_connected
) {
1030 ret
= bt_component_class_filter_set_input_port_connected_method(
1032 cc_full_descr
->methods
.filter
.input_port_connected
);
1034 BT_LOGE_STR("Cannot set filter component class's \"input port connected\" method.");
1035 status
= BT_PLUGIN_STATUS_ERROR
;
1036 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1041 if (cc_full_descr
->methods
.filter
.output_port_connected
) {
1042 ret
= bt_component_class_filter_set_output_port_connected_method(
1044 cc_full_descr
->methods
.filter
.output_port_connected
);
1046 BT_LOGE_STR("Cannot set filter component class's \"output port connected\" method.");
1047 status
= BT_PLUGIN_STATUS_ERROR
;
1048 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1053 if (cc_full_descr
->methods
.filter
.msg_iter_init
) {
1054 ret
= bt_component_class_filter_set_message_iterator_init_method(
1056 cc_full_descr
->methods
.filter
.msg_iter_init
);
1058 BT_LOGE_STR("Cannot set filter component class's message iterator initialization method.");
1059 status
= BT_PLUGIN_STATUS_ERROR
;
1060 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1065 if (cc_full_descr
->methods
.filter
.msg_iter_finalize
) {
1066 ret
= bt_component_class_filter_set_message_iterator_finalize_method(
1068 cc_full_descr
->methods
.filter
.msg_iter_finalize
);
1070 BT_LOGE_STR("Cannot set filter component class's message iterator finalization method.");
1071 status
= BT_PLUGIN_STATUS_ERROR
;
1072 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1077 if (cc_full_descr
->methods
.filter
.msg_iter_seek_ns_from_origin
) {
1078 ret
= bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method(
1080 cc_full_descr
->methods
.filter
.msg_iter_seek_ns_from_origin
);
1082 BT_LOGE_STR("Cannot set filter component class's message iterator \"seek nanoseconds from origin\" method.");
1083 status
= BT_PLUGIN_STATUS_ERROR
;
1084 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1089 if (cc_full_descr
->methods
.filter
.msg_iter_seek_beginning
) {
1090 ret
= bt_component_class_filter_set_message_iterator_seek_beginning_method(
1092 cc_full_descr
->methods
.filter
.msg_iter_seek_beginning
);
1094 BT_LOGE_STR("Cannot set filter component class's message iterator \"seek beginning\" method.");
1095 status
= BT_PLUGIN_STATUS_ERROR
;
1096 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1101 if (cc_full_descr
->methods
.filter
.msg_iter_can_seek_ns_from_origin
) {
1102 ret
= bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method(
1104 cc_full_descr
->methods
.filter
.msg_iter_can_seek_ns_from_origin
);
1106 BT_LOGE_STR("Cannot set filter component class's message iterator \"can seek nanoseconds from origin\" method.");
1107 status
= BT_PLUGIN_STATUS_ERROR
;
1108 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1113 if (cc_full_descr
->methods
.filter
.msg_iter_can_seek_beginning
) {
1114 ret
= bt_component_class_filter_set_message_iterator_can_seek_beginning_method(
1116 cc_full_descr
->methods
.filter
.msg_iter_can_seek_beginning
);
1118 BT_LOGE_STR("Cannot set filter component class's message iterator \"can seek beginning\" method.");
1119 status
= BT_PLUGIN_STATUS_ERROR
;
1120 BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class
);
1126 case BT_COMPONENT_CLASS_TYPE_SINK
:
1127 if (cc_full_descr
->methods
.sink
.init
) {
1128 ret
= bt_component_class_sink_set_init_method(
1130 cc_full_descr
->methods
.sink
.init
);
1132 BT_LOGE_STR("Cannot set sink component class's initialization method.");
1133 status
= BT_PLUGIN_STATUS_ERROR
;
1134 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1139 if (cc_full_descr
->methods
.sink
.finalize
) {
1140 ret
= bt_component_class_sink_set_finalize_method(
1142 cc_full_descr
->methods
.sink
.finalize
);
1144 BT_LOGE_STR("Cannot set sink component class's finalization method.");
1145 status
= BT_PLUGIN_STATUS_ERROR
;
1146 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1151 if (cc_full_descr
->methods
.sink
.query
) {
1152 ret
= bt_component_class_sink_set_query_method(
1154 cc_full_descr
->methods
.sink
.query
);
1156 BT_LOGE_STR("Cannot set sink component class's query method.");
1157 status
= BT_PLUGIN_STATUS_ERROR
;
1158 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1163 if (cc_full_descr
->methods
.sink
.accept_input_port_connection
) {
1164 ret
= bt_component_class_sink_set_accept_input_port_connection_method(
1166 cc_full_descr
->methods
.sink
.accept_input_port_connection
);
1168 BT_LOGE_STR("Cannot set sink component class's \"accept input port connection\" method.");
1169 status
= BT_PLUGIN_STATUS_ERROR
;
1170 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1175 if (cc_full_descr
->methods
.sink
.input_port_connected
) {
1176 ret
= bt_component_class_sink_set_input_port_connected_method(
1178 cc_full_descr
->methods
.sink
.input_port_connected
);
1180 BT_LOGE_STR("Cannot set sink component class's \"input port connected\" method.");
1181 status
= BT_PLUGIN_STATUS_ERROR
;
1182 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1187 if (cc_full_descr
->methods
.sink
.graph_is_configured
) {
1188 ret
= bt_component_class_sink_set_graph_is_configured_method(
1190 cc_full_descr
->methods
.sink
.graph_is_configured
);
1192 BT_LOGE_STR("Cannot set sink component class's \"graph is configured\" method.");
1193 status
= BT_PLUGIN_STATUS_ERROR
;
1194 BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class
);
1205 * Add component class to the plugin object.
1207 * This will call back
1208 * bt_plugin_so_on_add_component_class() so that we can
1209 * add a mapping in the component class list when we
1210 * know the component class is successfully added.
1212 status
= bt_plugin_add_component_class(plugin
,
1213 (void *) comp_class
);
1214 BT_OBJECT_PUT_REF_AND_RESET(comp_class
);
1216 BT_LOGE("Cannot add component class to plugin.");
1222 g_array_free(comp_class_full_descriptors
, TRUE
);
1227 struct bt_plugin
*bt_plugin_so_create_empty(
1228 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
)
1230 struct bt_plugin
*plugin
;
1231 struct bt_plugin_so_spec_data
*spec
;
1233 plugin
= bt_plugin_create_empty(BT_PLUGIN_TYPE_SO
);
1238 plugin
->destroy_spec_data
= bt_plugin_so_destroy_spec_data
;
1239 plugin
->spec_data
= g_new0(struct bt_plugin_so_spec_data
, 1);
1240 if (!plugin
->spec_data
) {
1241 BT_LOGE_STR("Failed to allocate one SO plugin specific data structure.");
1245 spec
= plugin
->spec_data
;
1246 spec
->shared_lib_handle
= shared_lib_handle
;
1247 bt_object_get_no_null_check(spec
->shared_lib_handle
);
1251 BT_OBJECT_PUT_REF_AND_RESET(plugin
);
1258 size_t count_non_null_items_in_section(const void *begin
, const void *end
)
1261 const int * const *begin_int
= (const int * const *) begin
;
1262 const int * const *end_int
= (const int * const *) end
;
1263 const int * const *iter
;
1265 for (iter
= begin_int
; iter
!= end_int
; iter
++) {
1275 struct bt_plugin_set
*bt_plugin_so_create_all_from_sections(
1276 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
,
1277 struct __bt_plugin_descriptor
const * const *descriptors_begin
,
1278 struct __bt_plugin_descriptor
const * const *descriptors_end
,
1279 struct __bt_plugin_descriptor_attribute
const * const *attrs_begin
,
1280 struct __bt_plugin_descriptor_attribute
const * const *attrs_end
,
1281 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_begin
,
1282 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_end
,
1283 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_begin
,
1284 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_end
)
1286 size_t descriptor_count
;
1288 size_t cc_descriptors_count
;
1289 size_t cc_descr_attrs_count
;
1291 struct bt_plugin_set
*plugin_set
= NULL
;
1293 descriptor_count
= count_non_null_items_in_section(descriptors_begin
, descriptors_end
);
1294 attrs_count
= count_non_null_items_in_section(attrs_begin
, attrs_end
);
1295 cc_descriptors_count
= count_non_null_items_in_section(cc_descriptors_begin
, cc_descriptors_end
);
1296 cc_descr_attrs_count
= count_non_null_items_in_section(cc_descr_attrs_begin
, cc_descr_attrs_end
);
1298 BT_LOGI("Creating all SO plugins from sections: "
1299 "plugin-path=\"%s\", "
1300 "descr-begin-addr=%p, descr-end-addr=%p, "
1301 "attrs-begin-addr=%p, attrs-end-addr=%p, "
1302 "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, "
1303 "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p, "
1304 "descr-count=%zu, attrs-count=%zu, "
1305 "cc-descr-count=%zu, cc-descr-attrs-count=%zu",
1306 shared_lib_handle
->path
? shared_lib_handle
->path
->str
: NULL
,
1307 descriptors_begin
, descriptors_end
,
1308 attrs_begin
, attrs_end
,
1309 cc_descriptors_begin
, cc_descriptors_end
,
1310 cc_descr_attrs_begin
, cc_descr_attrs_end
,
1311 descriptor_count
, attrs_count
,
1312 cc_descriptors_count
, cc_descr_attrs_count
);
1313 plugin_set
= bt_plugin_set_create();
1315 BT_LOGE_STR("Cannot create empty plugin set.");
1319 for (i
= 0; i
< descriptors_end
- descriptors_begin
; i
++) {
1320 enum bt_plugin_status status
;
1321 const struct __bt_plugin_descriptor
*descriptor
=
1322 descriptors_begin
[i
];
1323 struct bt_plugin
*plugin
;
1325 if (descriptor
== NULL
) {
1329 BT_LOGI("Creating plugin object for plugin: "
1330 "name=\"%s\", abi-major=%d, abi-minor=%d",
1331 descriptor
->name
, descriptor
->major
, descriptor
->minor
);
1333 if (descriptor
->major
> __BT_PLUGIN_VERSION_MAJOR
) {
1335 * INFO-level logging because we're only
1336 * _trying_ to open this file as a compatible
1337 * Babeltrace plugin: if it's not, it's not an
1338 * error. And because this can be tried during
1339 * bt_plugin_find_all_from_dir(), it's not even
1342 BT_LOGI("Unknown ABI major version: abi-major=%d",
1347 plugin
= bt_plugin_so_create_empty(shared_lib_handle
);
1349 BT_LOGE_STR("Cannot create empty shared library handle.");
1353 if (shared_lib_handle
&& shared_lib_handle
->path
) {
1354 bt_plugin_set_path(plugin
, shared_lib_handle
->path
->str
);
1357 status
= bt_plugin_so_init(plugin
, descriptor
, attrs_begin
,
1358 attrs_end
, cc_descriptors_begin
, cc_descriptors_end
,
1359 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1362 * DEBUG-level logging because we're only
1363 * _trying_ to open this file as a compatible
1364 * Babeltrace plugin: if it's not, it's not an
1365 * error. And because this can be tried during
1366 * bt_plugin_find_all_from_dir(), it's not
1369 BT_LOGD_STR("Cannot initialize SO plugin object from sections.");
1370 BT_OBJECT_PUT_REF_AND_RESET(plugin
);
1374 /* Add to plugin set */
1375 bt_plugin_set_add_plugin(plugin_set
, plugin
);
1376 bt_object_put_ref(plugin
);
1382 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
1389 struct bt_plugin_set
*bt_plugin_so_create_all_from_static(void)
1391 struct bt_plugin_set
*plugin_set
= NULL
;
1392 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
=
1393 bt_plugin_so_shared_lib_handle_create(NULL
);
1395 if (!shared_lib_handle
) {
1399 BT_LOGD_STR("Creating all SO plugins from built-in plugins.");
1400 plugin_set
= bt_plugin_so_create_all_from_sections(shared_lib_handle
,
1401 __bt_get_begin_section_plugin_descriptors(),
1402 __bt_get_end_section_plugin_descriptors(),
1403 __bt_get_begin_section_plugin_descriptor_attributes(),
1404 __bt_get_end_section_plugin_descriptor_attributes(),
1405 __bt_get_begin_section_component_class_descriptors(),
1406 __bt_get_end_section_component_class_descriptors(),
1407 __bt_get_begin_section_component_class_descriptor_attributes(),
1408 __bt_get_end_section_component_class_descriptor_attributes());
1411 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle
);
1417 struct bt_plugin_set
*bt_plugin_so_create_all_from_file(const char *path
)
1420 struct bt_plugin_set
*plugin_set
= NULL
;
1421 struct __bt_plugin_descriptor
const * const *descriptors_begin
= NULL
;
1422 struct __bt_plugin_descriptor
const * const *descriptors_end
= NULL
;
1423 struct __bt_plugin_descriptor_attribute
const * const *attrs_begin
= NULL
;
1424 struct __bt_plugin_descriptor_attribute
const * const *attrs_end
= NULL
;
1425 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_begin
= NULL
;
1426 struct __bt_plugin_component_class_descriptor
const * const *cc_descriptors_end
= NULL
;
1427 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_begin
= NULL
;
1428 struct __bt_plugin_component_class_descriptor_attribute
const * const *cc_descr_attrs_end
= NULL
;
1429 struct __bt_plugin_descriptor
const * const *(*get_begin_section_plugin_descriptors
)(void);
1430 struct __bt_plugin_descriptor
const * const *(*get_end_section_plugin_descriptors
)(void);
1431 struct __bt_plugin_descriptor_attribute
const * const *(*get_begin_section_plugin_descriptor_attributes
)(void);
1432 struct __bt_plugin_descriptor_attribute
const * const *(*get_end_section_plugin_descriptor_attributes
)(void);
1433 struct __bt_plugin_component_class_descriptor
const * const *(*get_begin_section_component_class_descriptors
)(void);
1434 struct __bt_plugin_component_class_descriptor
const * const *(*get_end_section_component_class_descriptors
)(void);
1435 struct __bt_plugin_component_class_descriptor_attribute
const * const *(*get_begin_section_component_class_descriptor_attributes
)(void);
1436 struct __bt_plugin_component_class_descriptor_attribute
const * const *(*get_end_section_component_class_descriptor_attributes
)(void);
1437 bt_bool is_libtool_wrapper
= BT_FALSE
, is_shared_object
= BT_FALSE
;
1438 struct bt_plugin_so_shared_lib_handle
*shared_lib_handle
= NULL
;
1441 path_len
= strlen(path
);
1442 BT_ASSERT_PRE(path_len
> PLUGIN_SUFFIX_LEN
,
1443 "Path length is too short: path-length=%zu, min-length=%zu",
1444 path_len
, PLUGIN_SUFFIX_LEN
);
1445 BT_LOGI("Trying to create all SO plugins from file: path=\"%s\"", path
);
1449 * Check if the file ends with a known plugin file type suffix
1450 * (i.e. .so or .la on Linux).
1452 is_libtool_wrapper
= !strncmp(LIBTOOL_PLUGIN_SUFFIX
,
1453 path
+ path_len
- LIBTOOL_PLUGIN_SUFFIX_LEN
,
1454 LIBTOOL_PLUGIN_SUFFIX_LEN
);
1455 is_shared_object
= !strncmp(NATIVE_PLUGIN_SUFFIX
,
1456 path
+ path_len
- NATIVE_PLUGIN_SUFFIX_LEN
,
1457 NATIVE_PLUGIN_SUFFIX_LEN
);
1458 if (!is_shared_object
&& !is_libtool_wrapper
) {
1459 /* Name indicates this is not a plugin file; not an error */
1460 BT_LOGI("File is not a SO plugin file: path=\"%s\"", path
);
1464 shared_lib_handle
= bt_plugin_so_shared_lib_handle_create(path
);
1465 if (!shared_lib_handle
) {
1466 /* bt_plugin_so_shared_lib_handle_create() logs more details */
1467 BT_LOGD_STR("Cannot create shared library handle.");
1471 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_plugin_descriptors",
1472 (gpointer
*) &get_begin_section_plugin_descriptors
)) {
1473 descriptors_begin
= get_begin_section_plugin_descriptors();
1475 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1476 "symbol=\"%s\"", path
,
1477 "__bt_get_begin_section_plugin_descriptors");
1481 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_plugin_descriptors",
1482 (gpointer
*) &get_end_section_plugin_descriptors
)) {
1483 descriptors_end
= get_end_section_plugin_descriptors();
1485 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1486 "symbol=\"%s\"", path
,
1487 "__bt_get_end_section_plugin_descriptors");
1491 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_plugin_descriptor_attributes",
1492 (gpointer
*) &get_begin_section_plugin_descriptor_attributes
)) {
1493 attrs_begin
= get_begin_section_plugin_descriptor_attributes();
1495 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1496 "symbol=\"%s\"", path
,
1497 "__bt_get_begin_section_plugin_descriptor_attributes");
1500 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_plugin_descriptor_attributes",
1501 (gpointer
*) &get_end_section_plugin_descriptor_attributes
)) {
1502 attrs_end
= get_end_section_plugin_descriptor_attributes();
1504 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1505 "symbol=\"%s\"", path
,
1506 "__bt_get_end_section_plugin_descriptor_attributes");
1509 if ((!!attrs_begin
- !!attrs_end
) != 0) {
1510 BT_LOGI("Found section start or end symbol, but not both: "
1511 "path=\"%s\", symbol-start=\"%s\", "
1512 "symbol-end=\"%s\", symbol-start-addr=%p, "
1513 "symbol-end-addr=%p",
1514 path
, "__bt_get_begin_section_plugin_descriptor_attributes",
1515 "__bt_get_end_section_plugin_descriptor_attributes",
1516 attrs_begin
, attrs_end
);
1520 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_component_class_descriptors",
1521 (gpointer
*) &get_begin_section_component_class_descriptors
)) {
1522 cc_descriptors_begin
= get_begin_section_component_class_descriptors();
1524 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1525 "symbol=\"%s\"", path
,
1526 "__bt_get_begin_section_component_class_descriptors");
1529 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_component_class_descriptors",
1530 (gpointer
*) &get_end_section_component_class_descriptors
)) {
1531 cc_descriptors_end
= get_end_section_component_class_descriptors();
1533 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1534 "symbol=\"%s\"", path
,
1535 "__bt_get_end_section_component_class_descriptors");
1538 if ((!!cc_descriptors_begin
- !!cc_descriptors_end
) != 0) {
1539 BT_LOGI("Found section start or end symbol, but not both: "
1540 "path=\"%s\", symbol-start=\"%s\", "
1541 "symbol-end=\"%s\", symbol-start-addr=%p, "
1542 "symbol-end-addr=%p",
1543 path
, "__bt_get_begin_section_component_class_descriptors",
1544 "__bt_get_end_section_component_class_descriptors",
1545 cc_descriptors_begin
, cc_descriptors_end
);
1549 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_begin_section_component_class_descriptor_attributes",
1550 (gpointer
*) &get_begin_section_component_class_descriptor_attributes
)) {
1551 cc_descr_attrs_begin
= get_begin_section_component_class_descriptor_attributes();
1553 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1554 "symbol=\"%s\"", path
,
1555 "__bt_get_begin_section_component_class_descriptor_attributes");
1558 if (g_module_symbol(shared_lib_handle
->module
, "__bt_get_end_section_component_class_descriptor_attributes",
1559 (gpointer
*) &get_end_section_component_class_descriptor_attributes
)) {
1560 cc_descr_attrs_end
= get_end_section_component_class_descriptor_attributes();
1562 BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", "
1563 "symbol=\"%s\"", path
,
1564 "__bt_get_end_section_component_class_descriptor_attributes");
1567 if ((!!cc_descr_attrs_begin
- !!cc_descr_attrs_end
) != 0) {
1568 BT_LOGI("Found section start or end symbol, but not both: "
1569 "path=\"%s\", symbol-start=\"%s\", "
1570 "symbol-end=\"%s\", symbol-start-addr=%p, "
1571 "symbol-end-addr=%p",
1572 path
, "__bt_get_begin_section_component_class_descriptor_attributes",
1573 "__bt_get_end_section_component_class_descriptor_attributes",
1574 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1578 /* Initialize plugin */
1579 BT_LOGD_STR("Initializing plugin object.");
1580 plugin_set
= bt_plugin_so_create_all_from_sections(shared_lib_handle
,
1581 descriptors_begin
, descriptors_end
, attrs_begin
, attrs_end
,
1582 cc_descriptors_begin
, cc_descriptors_end
,
1583 cc_descr_attrs_begin
, cc_descr_attrs_end
);
1586 BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle
);
1591 void plugin_comp_class_destroy_listener(struct bt_component_class
*comp_class
,
1594 bt_list_del(&comp_class
->node
);
1595 BT_OBJECT_PUT_REF_AND_RESET(comp_class
->so_handle
);
1596 BT_LOGD("Component class destroyed: removed entry from list: "
1597 "comp-cls-addr=%p", comp_class
);
1600 void bt_plugin_so_on_add_component_class(struct bt_plugin
*plugin
,
1601 struct bt_component_class
*comp_class
)
1603 struct bt_plugin_so_spec_data
*spec
= plugin
->spec_data
;
1605 BT_ASSERT(plugin
->spec_data
);
1606 BT_ASSERT(plugin
->type
== BT_PLUGIN_TYPE_SO
);
1608 bt_list_add(&comp_class
->node
, &component_class_list
);
1609 comp_class
->so_handle
= spec
->shared_lib_handle
;
1610 bt_object_get_no_null_check(comp_class
->so_handle
);
1612 /* Add our custom destroy listener */
1613 bt_component_class_add_destroy_listener(comp_class
,
1614 plugin_comp_class_destroy_listener
, NULL
);