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