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