Commit | Line | Data |
---|---|---|
55bb57e0 | 1 | /* |
f2b0325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
55bb57e0 | 3 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
55bb57e0 PP |
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 | ||
b03487ab | 26 | #define BT_LOG_TAG "LIB/PLUGIN-SO" |
1633ef46 | 27 | #include "lib/logging.h" |
3fe0bf43 | 28 | |
57952005 MJ |
29 | #include "common/assert.h" |
30 | #include "lib/assert-pre.h" | |
31 | #include "compat/compiler.h" | |
71c5da58 | 32 | #include <babeltrace2/plugin/plugin-dev.h> |
57952005 | 33 | #include "lib/graph/component-class.h" |
71c5da58 | 34 | #include <babeltrace2/graph/component-class.h> |
71c5da58 | 35 | #include <babeltrace2/types.h> |
57952005 | 36 | #include "common/list.h" |
55bb57e0 | 37 | #include <string.h> |
969c1d8a | 38 | #include <stdbool.h> |
0fbb9a9f | 39 | #include <stdlib.h> |
55bb57e0 PP |
40 | #include <glib.h> |
41 | #include <gmodule.h> | |
42 | ||
57952005 MJ |
43 | #include "plugin.h" |
44 | #include "plugin-so.h" | |
fb25b9e3 PP |
45 | #include "lib/func-status.h" |
46 | #include "common/common.h" | |
57952005 | 47 | |
44a3451a | 48 | #define NATIVE_PLUGIN_SUFFIX "." G_MODULE_SUFFIX |
55bb57e0 PP |
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 | ||
85e7137b | 53 | #define PLUGIN_SUFFIX_LEN bt_max_t(size_t, sizeof(NATIVE_PLUGIN_SUFFIX), \ |
55bb57e0 PP |
54 | sizeof(LIBTOOL_PLUGIN_SUFFIX)) |
55 | ||
be3c4e36 | 56 | BT_PLUGIN_MODULE(); |
55bb57e0 PP |
57 | |
58 | /* | |
bfa9a4be MD |
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. | |
55bb57e0 | 63 | * |
bfa9a4be | 64 | * The list items are the component classes created with |
55bb57e0 PP |
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 | * | |
bfa9a4be | 70 | * [component] --ref-> [component class]-> [shlib handle] |
55bb57e0 | 71 | * |
bfa9a4be | 72 | * It allows this use-case: |
55bb57e0 | 73 | * |
781ae911 | 74 | * my_plugins = bt_plugin_find_all_from_file("/path/to/my-plugin.so"); |
55bb57e0 PP |
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 | * | |
bfa9a4be MD |
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. | |
55bb57e0 | 87 | */ |
bfa9a4be | 88 | |
55bb57e0 | 89 | static |
bfa9a4be | 90 | BT_LIST_HEAD(component_class_list); |
55bb57e0 PP |
91 | |
92 | __attribute__((destructor)) static | |
bfa9a4be MD |
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); | |
8138bfe1 | 99 | BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle); |
55bb57e0 | 100 | } |
834e9996 | 101 | |
bfa9a4be | 102 | BT_LOGD_STR("Released references from all component classes to shared library handles."); |
55bb57e0 PP |
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 | ||
8b45963b | 110 | BT_ASSERT(obj); |
55bb57e0 PP |
111 | shared_lib_handle = container_of(obj, |
112 | struct bt_plugin_so_shared_lib_handle, base); | |
3fe0bf43 PP |
113 | const char *path = shared_lib_handle->path ? |
114 | shared_lib_handle->path->str : NULL; | |
115 | ||
a684a357 | 116 | BT_LOGI("Destroying shared library handle: addr=%p, path=\"%s\"", |
3fe0bf43 | 117 | shared_lib_handle, path); |
55bb57e0 PP |
118 | |
119 | if (shared_lib_handle->init_called && shared_lib_handle->exit) { | |
3fe0bf43 | 120 | BT_LOGD_STR("Calling user's plugin exit function."); |
0ae03127 PP |
121 | shared_lib_handle->exit(); |
122 | BT_LOGD_STR("User function returned."); | |
55bb57e0 PP |
123 | } |
124 | ||
125 | if (shared_lib_handle->module) { | |
d9501218 | 126 | #ifdef BT_DEBUG_MODE |
f1447220 PP |
127 | /* |
128 | * Valgrind shows incomplete stack traces when | |
129 | * dynamically loaded libraries are closed before it | |
e17763ec | 130 | * finishes. Use the LIBBABELTRACE2_NO_DLCLOSE in a debug |
f1447220 PP |
131 | * build to avoid this. |
132 | */ | |
e17763ec | 133 | const char *var = getenv("LIBBABELTRACE2_NO_DLCLOSE"); |
f1447220 PP |
134 | |
135 | if (!var || strcmp(var, "1") != 0) { | |
136 | #endif | |
a684a357 | 137 | BT_LOGI("Closing GModule: path=\"%s\"", path); |
3fe0bf43 | 138 | |
f1447220 | 139 | if (!g_module_close(shared_lib_handle->module)) { |
a8f90e5d PP |
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 | */ | |
3fe0bf43 PP |
145 | BT_LOGE("Cannot close GModule: %s: path=\"%s\"", |
146 | g_module_error(), path); | |
f1447220 | 147 | } |
c6578b03 PP |
148 | |
149 | shared_lib_handle->module = NULL; | |
d9501218 | 150 | #ifdef BT_DEBUG_MODE |
3fe0bf43 | 151 | } else { |
e17763ec | 152 | BT_LOGI("Not closing GModule because `LIBBABELTRACE2_NO_DLCLOSE=1`: " |
3fe0bf43 | 153 | "path=\"%s\"", path); |
55bb57e0 | 154 | } |
f1447220 | 155 | #endif |
55bb57e0 PP |
156 | } |
157 | ||
158 | if (shared_lib_handle->path) { | |
159 | g_string_free(shared_lib_handle->path, TRUE); | |
c6578b03 | 160 | shared_lib_handle->path = NULL; |
55bb57e0 PP |
161 | } |
162 | ||
163 | g_free(shared_lib_handle); | |
164 | } | |
165 | ||
166 | static | |
fb25b9e3 | 167 | int bt_plugin_so_shared_lib_handle_create( |
01f50d54 PP |
168 | const char *path, |
169 | struct bt_plugin_so_shared_lib_handle **shared_lib_handle) | |
55bb57e0 | 170 | { |
fb25b9e3 | 171 | int status = BT_FUNC_STATUS_OK; |
55bb57e0 | 172 | |
01f50d54 | 173 | BT_ASSERT(shared_lib_handle); |
a684a357 | 174 | BT_LOGI("Creating shared library handle: path=\"%s\"", path); |
01f50d54 PP |
175 | *shared_lib_handle = g_new0(struct bt_plugin_so_shared_lib_handle, 1); |
176 | if (!*shared_lib_handle) { | |
a8f90e5d | 177 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one shared library handle."); |
fb25b9e3 | 178 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
01f50d54 | 179 | goto end; |
55bb57e0 PP |
180 | } |
181 | ||
01f50d54 | 182 | bt_object_init_shared(&(*shared_lib_handle)->base, |
1d7bf349 | 183 | bt_plugin_so_shared_lib_handle_destroy); |
55bb57e0 PP |
184 | |
185 | if (!path) { | |
186 | goto end; | |
187 | } | |
188 | ||
01f50d54 PP |
189 | (*shared_lib_handle)->path = g_string_new(path); |
190 | if (!(*shared_lib_handle)->path) { | |
a8f90e5d | 191 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
fb25b9e3 | 192 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
01f50d54 | 193 | goto end; |
55bb57e0 PP |
194 | } |
195 | ||
01f50d54 PP |
196 | (*shared_lib_handle)->module = g_module_open(path, G_MODULE_BIND_LOCAL); |
197 | if (!(*shared_lib_handle)->module) { | |
50ad9320 | 198 | /* |
a684a357 | 199 | * INFO-level logging because we're only _trying_ to |
50ad9320 PP |
200 | * open this file as a Babeltrace plugin: if it's not, |
201 | * it's not an error. And because this can be tried | |
a684a357 PP |
202 | * during bt_plugin_find_all_from_dir(), it's not even a |
203 | * warning. | |
50ad9320 | 204 | */ |
a684a357 | 205 | BT_LOGI("Cannot open GModule: %s: path=\"%s\"", |
3fe0bf43 | 206 | g_module_error(), path); |
01f50d54 | 207 | BT_OBJECT_PUT_REF_AND_RESET(*shared_lib_handle); |
fb25b9e3 | 208 | status = BT_FUNC_STATUS_NOT_FOUND; |
01f50d54 | 209 | goto end; |
55bb57e0 PP |
210 | } |
211 | ||
212 | goto end; | |
213 | ||
55bb57e0 | 214 | end: |
fb25b9e3 | 215 | BT_ASSERT(*shared_lib_handle || status != BT_FUNC_STATUS_OK); |
01f50d54 | 216 | if (*shared_lib_handle) { |
a684a357 | 217 | BT_LOGI("Created shared library handle: path=\"%s\", addr=%p", |
01f50d54 | 218 | path, *shared_lib_handle); |
3fe0bf43 PP |
219 | } |
220 | ||
01f50d54 | 221 | return status; |
55bb57e0 PP |
222 | } |
223 | ||
6fbd4105 | 224 | static |
55bb57e0 PP |
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 | ||
8b45963b PP |
233 | BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO); |
234 | BT_ASSERT(spec); | |
8138bfe1 | 235 | BT_OBJECT_PUT_REF_AND_RESET(spec->shared_lib_handle); |
55bb57e0 PP |
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 | |
fb25b9e3 | 268 | int bt_plugin_so_init(struct bt_plugin *plugin, |
01f50d54 | 269 | bool fail_on_load_error, |
55bb57e0 PP |
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; | |
279b3f15 | 285 | const char *help; |
834e9996 PP |
286 | |
287 | union { | |
288 | struct { | |
be788861 | 289 | bt_component_class_source_get_supported_mip_versions_method get_supported_mip_versions; |
4175c1d5 | 290 | bt_component_class_source_initialize_method init; |
7b53201c PP |
291 | bt_component_class_source_finalize_method finalize; |
292 | bt_component_class_source_query_method query; | |
7b53201c | 293 | bt_component_class_source_output_port_connected_method output_port_connected; |
68e2deed SM |
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; | |
834e9996 PP |
300 | } source; |
301 | ||
302 | struct { | |
be788861 | 303 | bt_component_class_filter_get_supported_mip_versions_method get_supported_mip_versions; |
4175c1d5 | 304 | bt_component_class_filter_initialize_method init; |
7b53201c PP |
305 | bt_component_class_filter_finalize_method finalize; |
306 | bt_component_class_filter_query_method query; | |
7b53201c PP |
307 | bt_component_class_filter_input_port_connected_method input_port_connected; |
308 | bt_component_class_filter_output_port_connected_method output_port_connected; | |
68e2deed SM |
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; | |
834e9996 PP |
315 | } filter; |
316 | ||
317 | struct { | |
be788861 | 318 | bt_component_class_sink_get_supported_mip_versions_method get_supported_mip_versions; |
4175c1d5 | 319 | bt_component_class_sink_initialize_method init; |
7b53201c PP |
320 | bt_component_class_sink_finalize_method finalize; |
321 | bt_component_class_sink_query_method query; | |
7b53201c | 322 | bt_component_class_sink_input_port_connected_method input_port_connected; |
1043fdea | 323 | bt_component_class_sink_graph_is_configured_method graph_is_configured; |
834e9996 PP |
324 | } sink; |
325 | } methods; | |
55bb57e0 PP |
326 | }; |
327 | ||
fb25b9e3 | 328 | int status = BT_FUNC_STATUS_OK; |
55bb57e0 PP |
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; | |
68e2deed | 336 | struct bt_message_iterator_class *msg_iter_class = NULL; |
55bb57e0 | 337 | |
a684a357 | 338 | BT_LOGI("Initializing plugin object from descriptors found in sections: " |
3fe0bf43 PP |
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); | |
55bb57e0 PP |
349 | comp_class_full_descriptors = g_array_new(FALSE, TRUE, |
350 | sizeof(struct comp_class_full_descriptor)); | |
351 | if (!comp_class_full_descriptors) { | |
a8f90e5d | 352 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray."); |
fb25b9e3 | 353 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
55bb57e0 PP |
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 | ||
8e01f2d9 | 369 | if (!cur_attr) { |
be3c4e36 MJ |
370 | continue; |
371 | } | |
372 | ||
55bb57e0 PP |
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: | |
01f50d54 | 401 | if (fail_on_load_error) { |
a8f90e5d PP |
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); | |
c24a8f3c | 411 | status = BT_FUNC_STATUS_ERROR; |
01f50d54 | 412 | goto end; |
a8f90e5d | 413 | } else { |
6b076590 | 414 | BT_LIB_LOGW( |
a8f90e5d PP |
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); | |
01f50d54 PP |
423 | } |
424 | ||
55bb57e0 PP |
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 | ||
8e01f2d9 | 439 | if (!cur_cc_descr) { |
be3c4e36 MJ |
440 | continue; |
441 | } | |
442 | ||
55bb57e0 PP |
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; | |
834e9996 | 460 | enum bt_component_class_type cc_type; |
55bb57e0 | 461 | |
8e01f2d9 | 462 | if (!cur_cc_descr_attr) { |
be3c4e36 MJ |
463 | continue; |
464 | } | |
465 | ||
55bb57e0 PP |
466 | if (cur_cc_descr_attr->comp_class_descriptor->plugin_descriptor != |
467 | descriptor) { | |
468 | continue; | |
469 | } | |
470 | ||
834e9996 PP |
471 | cc_type = cur_cc_descr_attr->comp_class_descriptor->type; |
472 | ||
55bb57e0 PP |
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 | ||
834e9996 | 479 | if (cur_cc_descr_attr->comp_class_descriptor != |
55bb57e0 | 480 | cc_full_descr->descriptor) { |
834e9996 PP |
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; | |
be788861 PP |
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: | |
24847fc7 | 508 | bt_common_abort(); |
be788861 PP |
509 | } |
510 | break; | |
4175c1d5 | 511 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INITIALIZE_METHOD: |
834e9996 PP |
512 | switch (cc_type) { |
513 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
514 | cc_full_descr->methods.source.init = | |
4175c1d5 | 515 | cur_cc_descr_attr->value.source_initialize_method; |
55bb57e0 | 516 | break; |
834e9996 PP |
517 | case BT_COMPONENT_CLASS_TYPE_FILTER: |
518 | cc_full_descr->methods.filter.init = | |
4175c1d5 | 519 | cur_cc_descr_attr->value.filter_initialize_method; |
279b3f15 | 520 | break; |
834e9996 PP |
521 | case BT_COMPONENT_CLASS_TYPE_SINK: |
522 | cc_full_descr->methods.sink.init = | |
4175c1d5 | 523 | cur_cc_descr_attr->value.sink_initialize_method; |
55bb57e0 | 524 | break; |
834e9996 | 525 | default: |
24847fc7 | 526 | bt_common_abort(); |
834e9996 PP |
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; | |
55bb57e0 | 534 | break; |
834e9996 PP |
535 | case BT_COMPONENT_CLASS_TYPE_FILTER: |
536 | cc_full_descr->methods.filter.finalize = | |
537 | cur_cc_descr_attr->value.filter_finalize_method; | |
8463eac2 | 538 | break; |
834e9996 PP |
539 | case BT_COMPONENT_CLASS_TYPE_SINK: |
540 | cc_full_descr->methods.sink.finalize = | |
541 | cur_cc_descr_attr->value.sink_finalize_method; | |
72b913fb | 542 | break; |
834e9996 | 543 | default: |
24847fc7 | 544 | bt_common_abort(); |
834e9996 PP |
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; | |
0d8b4d8e | 552 | break; |
834e9996 PP |
553 | case BT_COMPONENT_CLASS_TYPE_FILTER: |
554 | cc_full_descr->methods.filter.query = | |
555 | cur_cc_descr_attr->value.filter_query_method; | |
55bb57e0 | 556 | break; |
834e9996 PP |
557 | case BT_COMPONENT_CLASS_TYPE_SINK: |
558 | cc_full_descr->methods.sink.query = | |
559 | cur_cc_descr_attr->value.sink_query_method; | |
55bb57e0 | 560 | break; |
834e9996 | 561 | default: |
24847fc7 | 562 | bt_common_abort(); |
834e9996 PP |
563 | } |
564 | break; | |
834e9996 PP |
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; | |
55bb57e0 | 574 | break; |
55bb57e0 | 575 | default: |
24847fc7 | 576 | bt_common_abort(); |
834e9996 PP |
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; | |
55bb57e0 | 588 | break; |
834e9996 | 589 | default: |
24847fc7 | 590 | bt_common_abort(); |
55bb57e0 | 591 | } |
834e9996 | 592 | break; |
1043fdea PP |
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: | |
24847fc7 | 600 | bt_common_abort(); |
1043fdea PP |
601 | } |
602 | break; | |
4175c1d5 | 603 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INITIALIZE_METHOD: |
834e9996 PP |
604 | switch (cc_type) { |
605 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
4175c1d5 | 606 | cc_full_descr->methods.source.msg_iter_initialize = |
68e2deed | 607 | cur_cc_descr_attr->value.msg_iter_initialize_method; |
834e9996 PP |
608 | break; |
609 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
4175c1d5 | 610 | cc_full_descr->methods.filter.msg_iter_initialize = |
68e2deed | 611 | cur_cc_descr_attr->value.msg_iter_initialize_method; |
834e9996 PP |
612 | break; |
613 | default: | |
24847fc7 | 614 | bt_common_abort(); |
834e9996 PP |
615 | } |
616 | break; | |
b09a5592 | 617 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_FINALIZE_METHOD: |
834e9996 PP |
618 | switch (cc_type) { |
619 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
b09a5592 | 620 | cc_full_descr->methods.source.msg_iter_finalize = |
68e2deed | 621 | cur_cc_descr_attr->value.msg_iter_finalize_method; |
834e9996 PP |
622 | break; |
623 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
b09a5592 | 624 | cc_full_descr->methods.filter.msg_iter_finalize = |
68e2deed | 625 | cur_cc_descr_attr->value.msg_iter_finalize_method; |
834e9996 PP |
626 | break; |
627 | default: | |
24847fc7 | 628 | bt_common_abort(); |
834e9996 PP |
629 | } |
630 | break; | |
15a52f66 PP |
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 = | |
68e2deed | 635 | cur_cc_descr_attr->value.msg_iter_seek_ns_from_origin_method; |
15a52f66 PP |
636 | break; |
637 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
638 | cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin = | |
68e2deed | 639 | cur_cc_descr_attr->value.msg_iter_seek_ns_from_origin_method; |
15a52f66 PP |
640 | break; |
641 | default: | |
24847fc7 | 642 | bt_common_abort(); |
15a52f66 PP |
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 = | |
68e2deed | 649 | cur_cc_descr_attr->value.msg_iter_seek_beginning_method; |
15a52f66 PP |
650 | break; |
651 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
652 | cc_full_descr->methods.filter.msg_iter_seek_beginning = | |
68e2deed | 653 | cur_cc_descr_attr->value.msg_iter_seek_beginning_method; |
15a52f66 PP |
654 | break; |
655 | default: | |
24847fc7 | 656 | bt_common_abort(); |
15a52f66 PP |
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 = | |
68e2deed | 663 | cur_cc_descr_attr->value.msg_iter_can_seek_ns_from_origin_method; |
15a52f66 PP |
664 | break; |
665 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
666 | cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin = | |
68e2deed | 667 | cur_cc_descr_attr->value.msg_iter_can_seek_ns_from_origin_method; |
15a52f66 PP |
668 | break; |
669 | default: | |
24847fc7 | 670 | bt_common_abort(); |
15a52f66 PP |
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 = | |
68e2deed | 677 | cur_cc_descr_attr->value.msg_iter_can_seek_beginning_method; |
15a52f66 PP |
678 | break; |
679 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
680 | cc_full_descr->methods.filter.msg_iter_can_seek_beginning = | |
68e2deed | 681 | cur_cc_descr_attr->value.msg_iter_can_seek_beginning_method; |
15a52f66 PP |
682 | break; |
683 | default: | |
24847fc7 | 684 | bt_common_abort(); |
15a52f66 PP |
685 | } |
686 | break; | |
834e9996 | 687 | default: |
01f50d54 | 688 | if (fail_on_load_error) { |
a8f90e5d PP |
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); | |
c24a8f3c | 706 | status = BT_FUNC_STATUS_ERROR; |
01f50d54 | 707 | goto end; |
a8f90e5d | 708 | } else { |
6b076590 | 709 | BT_LIB_LOGW( |
a8f90e5d PP |
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); | |
01f50d54 PP |
726 | } |
727 | ||
834e9996 | 728 | break; |
55bb57e0 PP |
729 | } |
730 | } | |
731 | } | |
732 | ||
733 | /* Initialize plugin */ | |
734 | if (spec->init) { | |
4175c1d5 | 735 | enum bt_plugin_initialize_func_status init_status; |
c8750769 | 736 | |
3fe0bf43 | 737 | BT_LOGD_STR("Calling user's plugin initialization function."); |
c8750769 | 738 | init_status = spec->init((void *) plugin); |
01f50d54 | 739 | BT_LOGD("User function returned: status=%s", |
fb25b9e3 | 740 | bt_common_func_status_string(init_status)); |
3fe0bf43 | 741 | |
0ae03127 | 742 | if (init_status < 0) { |
01f50d54 | 743 | if (fail_on_load_error) { |
a8f90e5d PP |
744 | BT_LIB_LOGW_APPEND_CAUSE( |
745 | "User's plugin initialization function failed: " | |
746 | "status=%s", | |
747 | bt_common_func_status_string(init_status)); | |
fb25b9e3 | 748 | status = init_status; |
01f50d54 | 749 | goto end; |
a8f90e5d | 750 | } else { |
6b076590 | 751 | BT_LIB_LOGW( |
a8f90e5d PP |
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; | |
01f50d54 | 756 | } |
a8f90e5d PP |
757 | |
758 | goto end; | |
55bb57e0 PP |
759 | } |
760 | } | |
761 | ||
c55a9f58 | 762 | spec->shared_lib_handle->init_called = BT_TRUE; |
55bb57e0 PP |
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); | |
7b53201c PP |
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; | |
55bb57e0 | 773 | |
a684a357 | 774 | BT_LOGI("Creating and setting properties of plugin's component class: " |
3fe0bf43 PP |
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 | ||
68e2deed SM |
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 | ||
55bb57e0 PP |
870 | switch (cc_full_descr->descriptor->type) { |
871 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
68e2deed SM |
872 | BT_ASSERT(msg_iter_class); |
873 | ||
7b53201c | 874 | src_comp_class = bt_component_class_source_create( |
68e2deed | 875 | cc_full_descr->descriptor->name, msg_iter_class); |
7b53201c | 876 | comp_class = bt_component_class_source_as_component_class( |
834e9996 | 877 | src_comp_class); |
55bb57e0 PP |
878 | break; |
879 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
68e2deed SM |
880 | BT_ASSERT(msg_iter_class); |
881 | ||
7b53201c | 882 | flt_comp_class = bt_component_class_filter_create( |
68e2deed | 883 | cc_full_descr->descriptor->name, msg_iter_class); |
7b53201c | 884 | comp_class = bt_component_class_filter_as_component_class( |
834e9996 | 885 | flt_comp_class); |
55bb57e0 PP |
886 | break; |
887 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
68e2deed SM |
888 | BT_ASSERT(!msg_iter_class); |
889 | ||
7b53201c | 890 | sink_comp_class = bt_component_class_sink_create( |
55bb57e0 PP |
891 | cc_full_descr->descriptor->name, |
892 | cc_full_descr->descriptor->methods.sink.consume); | |
7b53201c | 893 | comp_class = bt_component_class_sink_as_component_class( |
834e9996 | 894 | sink_comp_class); |
55bb57e0 PP |
895 | break; |
896 | default: | |
01f50d54 | 897 | if (fail_on_load_error) { |
a8f90e5d PP |
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); | |
c24a8f3c | 908 | status = BT_FUNC_STATUS_ERROR; |
01f50d54 | 909 | goto end; |
a8f90e5d | 910 | } else { |
6b076590 | 911 | BT_LIB_LOGW( |
a8f90e5d PP |
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; | |
01f50d54 | 922 | } |
55bb57e0 PP |
923 | } |
924 | ||
925 | if (!comp_class) { | |
a8f90e5d PP |
926 | BT_LIB_LOGE_APPEND_CAUSE( |
927 | "Cannot create component class."); | |
fb25b9e3 | 928 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
55bb57e0 PP |
929 | goto end; |
930 | } | |
931 | ||
68e2deed SM |
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 | ||
55bb57e0 | 941 | if (cc_full_descr->description) { |
7b53201c | 942 | ret = bt_component_class_set_description( |
834e9996 | 943 | comp_class, cc_full_descr->description); |
55bb57e0 | 944 | if (ret) { |
a8f90e5d PP |
945 | BT_LIB_LOGE_APPEND_CAUSE( |
946 | "Cannot set component class's description."); | |
fb25b9e3 | 947 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
8138bfe1 | 948 | BT_OBJECT_PUT_REF_AND_RESET(comp_class); |
55bb57e0 PP |
949 | goto end; |
950 | } | |
951 | } | |
952 | ||
279b3f15 | 953 | if (cc_full_descr->help) { |
7b53201c | 954 | ret = bt_component_class_set_help(comp_class, |
279b3f15 PP |
955 | cc_full_descr->help); |
956 | if (ret) { | |
a8f90e5d PP |
957 | BT_LIB_LOGE_APPEND_CAUSE( |
958 | "Cannot set component class's help string."); | |
fb25b9e3 | 959 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
8138bfe1 | 960 | BT_OBJECT_PUT_REF_AND_RESET(comp_class); |
279b3f15 PP |
961 | goto end; |
962 | } | |
963 | } | |
964 | ||
834e9996 PP |
965 | switch (cc_full_descr->descriptor->type) { |
966 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
be788861 PP |
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 | ||
834e9996 | 980 | if (cc_full_descr->methods.source.init) { |
4175c1d5 | 981 | ret = bt_component_class_source_set_initialize_method( |
834e9996 PP |
982 | src_comp_class, |
983 | cc_full_descr->methods.source.init); | |
984 | if (ret) { | |
a8f90e5d PP |
985 | BT_LIB_LOGE_APPEND_CAUSE( |
986 | "Cannot set source component class's initialization method."); | |
fb25b9e3 | 987 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
988 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
989 | goto end; | |
990 | } | |
55bb57e0 | 991 | } |
55bb57e0 | 992 | |
834e9996 | 993 | if (cc_full_descr->methods.source.finalize) { |
7b53201c | 994 | ret = bt_component_class_source_set_finalize_method( |
834e9996 PP |
995 | src_comp_class, |
996 | cc_full_descr->methods.source.finalize); | |
997 | if (ret) { | |
a8f90e5d PP |
998 | BT_LIB_LOGE_APPEND_CAUSE( |
999 | "Cannot set source component class's finalization method."); | |
fb25b9e3 | 1000 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1001 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
1002 | goto end; | |
1003 | } | |
55bb57e0 | 1004 | } |
55bb57e0 | 1005 | |
834e9996 | 1006 | if (cc_full_descr->methods.source.query) { |
7b53201c | 1007 | ret = bt_component_class_source_set_query_method( |
834e9996 PP |
1008 | src_comp_class, |
1009 | cc_full_descr->methods.source.query); | |
1010 | if (ret) { | |
a8f90e5d PP |
1011 | BT_LIB_LOGE_APPEND_CAUSE( |
1012 | "Cannot set source component class's query method."); | |
fb25b9e3 | 1013 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1014 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
1015 | goto end; | |
1016 | } | |
8463eac2 | 1017 | } |
8463eac2 | 1018 | |
834e9996 | 1019 | if (cc_full_descr->methods.source.output_port_connected) { |
7b53201c | 1020 | ret = bt_component_class_source_set_output_port_connected_method( |
834e9996 PP |
1021 | src_comp_class, |
1022 | cc_full_descr->methods.source.output_port_connected); | |
1023 | if (ret) { | |
a8f90e5d PP |
1024 | BT_LIB_LOGE_APPEND_CAUSE( |
1025 | "Cannot set source component class's \"output port connected\" method."); | |
fb25b9e3 | 1026 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1027 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
1028 | goto end; | |
1029 | } | |
0d8b4d8e | 1030 | } |
0d8b4d8e | 1031 | |
55bb57e0 PP |
1032 | break; |
1033 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
be788861 PP |
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 | ||
834e9996 | 1047 | if (cc_full_descr->methods.filter.init) { |
4175c1d5 | 1048 | ret = bt_component_class_filter_set_initialize_method( |
834e9996 PP |
1049 | flt_comp_class, |
1050 | cc_full_descr->methods.filter.init); | |
1051 | if (ret) { | |
a8f90e5d PP |
1052 | BT_LIB_LOGE_APPEND_CAUSE( |
1053 | "Cannot set filter component class's initialization method."); | |
fb25b9e3 | 1054 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1055 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1056 | goto end; | |
1057 | } | |
1058 | } | |
1059 | ||
1060 | if (cc_full_descr->methods.filter.finalize) { | |
7b53201c | 1061 | ret = bt_component_class_filter_set_finalize_method( |
834e9996 PP |
1062 | flt_comp_class, |
1063 | cc_full_descr->methods.filter.finalize); | |
1064 | if (ret) { | |
a8f90e5d PP |
1065 | BT_LIB_LOGE_APPEND_CAUSE( |
1066 | "Cannot set filter component class's finalization method."); | |
fb25b9e3 | 1067 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1068 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1069 | goto end; | |
1070 | } | |
1071 | } | |
1072 | ||
1073 | if (cc_full_descr->methods.filter.query) { | |
7b53201c | 1074 | ret = bt_component_class_filter_set_query_method( |
834e9996 PP |
1075 | flt_comp_class, |
1076 | cc_full_descr->methods.filter.query); | |
1077 | if (ret) { | |
a8f90e5d PP |
1078 | BT_LIB_LOGE_APPEND_CAUSE( |
1079 | "Cannot set filter component class's query method."); | |
fb25b9e3 | 1080 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1081 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1082 | goto end; | |
1083 | } | |
1084 | } | |
1085 | ||
834e9996 | 1086 | if (cc_full_descr->methods.filter.input_port_connected) { |
7b53201c | 1087 | ret = bt_component_class_filter_set_input_port_connected_method( |
834e9996 PP |
1088 | flt_comp_class, |
1089 | cc_full_descr->methods.filter.input_port_connected); | |
1090 | if (ret) { | |
a8f90e5d PP |
1091 | BT_LIB_LOGE_APPEND_CAUSE( |
1092 | "Cannot set filter component class's \"input port connected\" method."); | |
fb25b9e3 | 1093 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
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) { | |
7b53201c | 1100 | ret = bt_component_class_filter_set_output_port_connected_method( |
834e9996 PP |
1101 | flt_comp_class, |
1102 | cc_full_descr->methods.filter.output_port_connected); | |
1103 | if (ret) { | |
a8f90e5d PP |
1104 | BT_LIB_LOGE_APPEND_CAUSE( |
1105 | "Cannot set filter component class's \"output port connected\" method."); | |
fb25b9e3 | 1106 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1107 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1108 | goto end; | |
1109 | } | |
1110 | } | |
1111 | ||
55bb57e0 PP |
1112 | break; |
1113 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
be788861 PP |
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 | ||
834e9996 | 1127 | if (cc_full_descr->methods.sink.init) { |
4175c1d5 | 1128 | ret = bt_component_class_sink_set_initialize_method( |
834e9996 PP |
1129 | sink_comp_class, |
1130 | cc_full_descr->methods.sink.init); | |
1131 | if (ret) { | |
a8f90e5d PP |
1132 | BT_LIB_LOGE_APPEND_CAUSE( |
1133 | "Cannot set sink component class's initialization method."); | |
fb25b9e3 | 1134 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1135 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1136 | goto end; | |
1137 | } | |
1138 | } | |
1139 | ||
1140 | if (cc_full_descr->methods.sink.finalize) { | |
7b53201c | 1141 | ret = bt_component_class_sink_set_finalize_method( |
834e9996 PP |
1142 | sink_comp_class, |
1143 | cc_full_descr->methods.sink.finalize); | |
1144 | if (ret) { | |
a8f90e5d PP |
1145 | BT_LIB_LOGE_APPEND_CAUSE( |
1146 | "Cannot set sink component class's finalization method."); | |
fb25b9e3 | 1147 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1148 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1149 | goto end; | |
1150 | } | |
1151 | } | |
1152 | ||
1153 | if (cc_full_descr->methods.sink.query) { | |
7b53201c | 1154 | ret = bt_component_class_sink_set_query_method( |
834e9996 PP |
1155 | sink_comp_class, |
1156 | cc_full_descr->methods.sink.query); | |
1157 | if (ret) { | |
a8f90e5d PP |
1158 | BT_LIB_LOGE_APPEND_CAUSE( |
1159 | "Cannot set sink component class's query method."); | |
fb25b9e3 | 1160 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1161 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1162 | goto end; | |
1163 | } | |
1164 | } | |
1165 | ||
834e9996 | 1166 | if (cc_full_descr->methods.sink.input_port_connected) { |
7b53201c | 1167 | ret = bt_component_class_sink_set_input_port_connected_method( |
834e9996 PP |
1168 | sink_comp_class, |
1169 | cc_full_descr->methods.sink.input_port_connected); | |
1170 | if (ret) { | |
a8f90e5d PP |
1171 | BT_LIB_LOGE_APPEND_CAUSE( |
1172 | "Cannot set sink component class's \"input port connected\" method."); | |
fb25b9e3 | 1173 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1174 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1175 | goto end; | |
1176 | } | |
1177 | } | |
1178 | ||
1043fdea PP |
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) { | |
a8f90e5d PP |
1184 | BT_LIB_LOGE_APPEND_CAUSE( |
1185 | "Cannot set sink component class's \"graph is configured\" method."); | |
fb25b9e3 | 1186 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
1043fdea PP |
1187 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1188 | goto end; | |
1189 | } | |
1190 | } | |
1191 | ||
55bb57e0 PP |
1192 | break; |
1193 | default: | |
24847fc7 | 1194 | bt_common_abort(); |
55bb57e0 PP |
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 | |
834e9996 PP |
1202 | * add a mapping in the component class list when we |
1203 | * know the component class is successfully added. | |
55bb57e0 PP |
1204 | */ |
1205 | status = bt_plugin_add_component_class(plugin, | |
834e9996 | 1206 | (void *) comp_class); |
8138bfe1 | 1207 | BT_OBJECT_PUT_REF_AND_RESET(comp_class); |
55bb57e0 | 1208 | if (status < 0) { |
a8f90e5d PP |
1209 | BT_LIB_LOGE_APPEND_CAUSE( |
1210 | "Cannot add component class to plugin."); | |
55bb57e0 PP |
1211 | goto end; |
1212 | } | |
1213 | } | |
1214 | ||
55bb57e0 | 1215 | end: |
68e2deed | 1216 | bt_message_iterator_class_put_ref(msg_iter_class); |
55bb57e0 PP |
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 | ||
6fbd4105 | 1233 | plugin->destroy_spec_data = bt_plugin_so_destroy_spec_data; |
55bb57e0 PP |
1234 | plugin->spec_data = g_new0(struct bt_plugin_so_spec_data, 1); |
1235 | if (!plugin->spec_data) { | |
a8f90e5d PP |
1236 | BT_LIB_LOGE_APPEND_CAUSE( |
1237 | "Failed to allocate one SO plugin specific data structure."); | |
55bb57e0 PP |
1238 | goto error; |
1239 | } | |
1240 | ||
1241 | spec = plugin->spec_data; | |
4b70020d | 1242 | spec->shared_lib_handle = shared_lib_handle; |
864aa43f | 1243 | bt_object_get_ref_no_null_check(spec->shared_lib_handle); |
55bb57e0 PP |
1244 | goto end; |
1245 | ||
1246 | error: | |
8138bfe1 | 1247 | BT_OBJECT_PUT_REF_AND_RESET(plugin); |
55bb57e0 PP |
1248 | |
1249 | end: | |
1250 | return plugin; | |
1251 | } | |
1252 | ||
be3c4e36 MJ |
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 | ||
55bb57e0 | 1270 | static |
fb25b9e3 | 1271 | int bt_plugin_so_create_all_from_sections( |
55bb57e0 | 1272 | struct bt_plugin_so_shared_lib_handle *shared_lib_handle, |
01f50d54 | 1273 | bool fail_on_load_error, |
55bb57e0 PP |
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, | |
01f50d54 PP |
1281 | struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_end, |
1282 | struct bt_plugin_set **plugin_set_out) | |
55bb57e0 | 1283 | { |
fb25b9e3 | 1284 | int status = BT_FUNC_STATUS_OK; |
55bb57e0 PP |
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; | |
55bb57e0 | 1290 | |
dbf7ef57 | 1291 | BT_ASSERT(shared_lib_handle); |
01f50d54 PP |
1292 | BT_ASSERT(plugin_set_out); |
1293 | *plugin_set_out = NULL; | |
be3c4e36 MJ |
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); | |
a684a357 | 1298 | BT_LOGI("Creating all SO plugins from sections: " |
3fe0bf43 PP |
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); | |
01f50d54 PP |
1313 | *plugin_set_out = bt_plugin_set_create(); |
1314 | if (!*plugin_set_out) { | |
a8f90e5d | 1315 | BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set."); |
fb25b9e3 | 1316 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
55bb57e0 PP |
1317 | goto error; |
1318 | } | |
1319 | ||
be3c4e36 | 1320 | for (i = 0; i < descriptors_end - descriptors_begin; i++) { |
55bb57e0 PP |
1321 | const struct __bt_plugin_descriptor *descriptor = |
1322 | descriptors_begin[i]; | |
1323 | struct bt_plugin *plugin; | |
1324 | ||
8e01f2d9 | 1325 | if (!descriptor) { |
be3c4e36 MJ |
1326 | continue; |
1327 | } | |
1328 | ||
f488daa2 PP |
1329 | BT_LOGI("Creating plugin object for plugin: name=\"%s\"", |
1330 | descriptor->name); | |
55bb57e0 PP |
1331 | plugin = bt_plugin_so_create_empty(shared_lib_handle); |
1332 | if (!plugin) { | |
a8f90e5d PP |
1333 | BT_LIB_LOGE_APPEND_CAUSE( |
1334 | "Cannot create empty shared library handle."); | |
fb25b9e3 | 1335 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
55bb57e0 PP |
1336 | goto error; |
1337 | } | |
1338 | ||
474039c7 | 1339 | if (shared_lib_handle->path) { |
01f50d54 PP |
1340 | bt_plugin_set_path(plugin, |
1341 | shared_lib_handle->path->str); | |
55bb57e0 PP |
1342 | } |
1343 | ||
01f50d54 PP |
1344 | status = bt_plugin_so_init(plugin, fail_on_load_error, |
1345 | descriptor, attrs_begin, attrs_end, | |
1346 | cc_descriptors_begin, cc_descriptors_end, | |
55bb57e0 | 1347 | cc_descr_attrs_begin, cc_descr_attrs_end); |
fb25b9e3 | 1348 | if (status == BT_FUNC_STATUS_OK) { |
01f50d54 PP |
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) { | |
50ad9320 | 1353 | /* |
01f50d54 PP |
1354 | * bt_plugin_so_init() handles |
1355 | * `fail_on_load_error`, so this is a "real" | |
1356 | * error. | |
50ad9320 | 1357 | */ |
a8f90e5d PP |
1358 | BT_LIB_LOGW_APPEND_CAUSE( |
1359 | "Cannot initialize SO plugin object from sections."); | |
8138bfe1 | 1360 | BT_OBJECT_PUT_REF_AND_RESET(plugin); |
55bb57e0 PP |
1361 | goto error; |
1362 | } | |
1363 | ||
01f50d54 PP |
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); | |
fb25b9e3 | 1371 | status = BT_FUNC_STATUS_NOT_FOUND; |
55bb57e0 PP |
1372 | } |
1373 | ||
1374 | goto end; | |
1375 | ||
1376 | error: | |
01f50d54 PP |
1377 | BT_ASSERT(status < 0); |
1378 | BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out); | |
55bb57e0 PP |
1379 | |
1380 | end: | |
01f50d54 | 1381 | return status; |
55bb57e0 PP |
1382 | } |
1383 | ||
1384 | BT_HIDDEN | |
fb25b9e3 | 1385 | int bt_plugin_so_create_all_from_static(bool fail_on_load_error, |
01f50d54 | 1386 | struct bt_plugin_set **plugin_set_out) |
55bb57e0 | 1387 | { |
fb25b9e3 | 1388 | int status; |
01f50d54 | 1389 | struct bt_plugin_so_shared_lib_handle *shared_lib_handle = NULL; |
55bb57e0 | 1390 | |
01f50d54 PP |
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); | |
fb25b9e3 | 1395 | if (status != BT_FUNC_STATUS_OK) { |
01f50d54 | 1396 | BT_ASSERT(!shared_lib_handle); |
55bb57e0 PP |
1397 | goto end; |
1398 | } | |
1399 | ||
01f50d54 | 1400 | BT_ASSERT(shared_lib_handle); |
3fe0bf43 | 1401 | BT_LOGD_STR("Creating all SO plugins from built-in plugins."); |
01f50d54 PP |
1402 | status = bt_plugin_so_create_all_from_sections(shared_lib_handle, |
1403 | fail_on_load_error, | |
be3c4e36 MJ |
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(), | |
01f50d54 PP |
1411 | __bt_get_end_section_component_class_descriptor_attributes(), |
1412 | plugin_set_out); | |
fb25b9e3 | 1413 | BT_ASSERT((status == BT_FUNC_STATUS_OK && *plugin_set_out && |
01f50d54 | 1414 | (*plugin_set_out)->plugins->len > 0) || !*plugin_set_out); |
55bb57e0 PP |
1415 | |
1416 | end: | |
8138bfe1 | 1417 | BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle); |
01f50d54 | 1418 | return status; |
55bb57e0 PP |
1419 | } |
1420 | ||
1421 | BT_HIDDEN | |
fb25b9e3 | 1422 | int bt_plugin_so_create_all_from_file(const char *path, |
01f50d54 | 1423 | bool fail_on_load_error, struct bt_plugin_set **plugin_set_out) |
55bb57e0 PP |
1424 | { |
1425 | size_t path_len; | |
fb25b9e3 | 1426 | int status; |
55bb57e0 PP |
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; | |
be3c4e36 MJ |
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); | |
c55a9f58 | 1443 | bt_bool is_libtool_wrapper = BT_FALSE, is_shared_object = BT_FALSE; |
55bb57e0 PP |
1444 | struct bt_plugin_so_shared_lib_handle *shared_lib_handle = NULL; |
1445 | ||
a684a357 | 1446 | BT_ASSERT(path); |
01f50d54 PP |
1447 | BT_ASSERT(plugin_set_out); |
1448 | *plugin_set_out = NULL; | |
55bb57e0 | 1449 | path_len = strlen(path); |
25825bf0 FD |
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 | ||
a684a357 | 1463 | BT_LOGI("Trying to create all SO plugins from file: path=\"%s\"", path); |
55bb57e0 | 1464 | path_len++; |
a684a357 | 1465 | |
55bb57e0 | 1466 | /* |
a684a357 PP |
1467 | * Check if the file ends with a known plugin file type suffix |
1468 | * (i.e. .so or .la on Linux). | |
55bb57e0 PP |
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) { | |
3fe0bf43 | 1477 | /* Name indicates this is not a plugin file; not an error */ |
01f50d54 | 1478 | BT_LOGI("File is not an SO plugin file: path=\"%s\"", path); |
fb25b9e3 | 1479 | status = BT_FUNC_STATUS_NOT_FOUND; |
55bb57e0 PP |
1480 | goto end; |
1481 | } | |
1482 | ||
01f50d54 PP |
1483 | status = bt_plugin_so_shared_lib_handle_create(path, |
1484 | &shared_lib_handle); | |
fb25b9e3 | 1485 | if (status != BT_FUNC_STATUS_OK) { |
a684a357 | 1486 | /* bt_plugin_so_shared_lib_handle_create() logs more details */ |
01f50d54 | 1487 | BT_ASSERT(!shared_lib_handle); |
55bb57e0 PP |
1488 | goto end; |
1489 | } | |
1490 | ||
be3c4e36 MJ |
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 { | |
01f50d54 PP |
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 | */ | |
a684a357 | 1501 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1502 | "symbol=\"%s\"", path, |
be3c4e36 | 1503 | "__bt_get_begin_section_plugin_descriptors"); |
fb25b9e3 | 1504 | status = BT_FUNC_STATUS_NOT_FOUND; |
55bb57e0 PP |
1505 | goto end; |
1506 | } | |
1507 | ||
01f50d54 PP |
1508 | /* |
1509 | * If g_module_symbol() fails for any of the other symbols, fail | |
1510 | * if `fail_on_load_error` is true. | |
1511 | */ | |
be3c4e36 MJ |
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 { | |
a8f90e5d PP |
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"); | |
c24a8f3c | 1521 | status = BT_FUNC_STATUS_ERROR; |
a8f90e5d | 1522 | } else { |
6b076590 | 1523 | BT_LIB_LOGW( |
a8f90e5d PP |
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 | ||
55bb57e0 PP |
1530 | goto end; |
1531 | } | |
1532 | ||
be3c4e36 MJ |
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 { | |
a684a357 | 1537 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1538 | "symbol=\"%s\"", path, |
be3c4e36 | 1539 | "__bt_get_begin_section_plugin_descriptor_attributes"); |
55bb57e0 PP |
1540 | } |
1541 | ||
be3c4e36 MJ |
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 { | |
a684a357 | 1546 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1547 | "symbol=\"%s\"", path, |
be3c4e36 | 1548 | "__bt_get_end_section_plugin_descriptor_attributes"); |
55bb57e0 PP |
1549 | } |
1550 | ||
1551 | if ((!!attrs_begin - !!attrs_end) != 0) { | |
a8f90e5d PP |
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); | |
c24a8f3c | 1561 | status = BT_FUNC_STATUS_ERROR; |
a8f90e5d | 1562 | } else { |
6b076590 | 1563 | BT_LIB_LOGW( |
a8f90e5d PP |
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 | ||
55bb57e0 PP |
1574 | goto end; |
1575 | } | |
1576 | ||
be3c4e36 MJ |
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 { | |
a684a357 | 1581 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1582 | "symbol=\"%s\"", path, |
be3c4e36 | 1583 | "__bt_get_begin_section_component_class_descriptors"); |
55bb57e0 PP |
1584 | } |
1585 | ||
be3c4e36 MJ |
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 { | |
a684a357 | 1590 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1591 | "symbol=\"%s\"", path, |
be3c4e36 | 1592 | "__bt_get_end_section_component_class_descriptors"); |
55bb57e0 PP |
1593 | } |
1594 | ||
1595 | if ((!!cc_descriptors_begin - !!cc_descriptors_end) != 0) { | |
a8f90e5d PP |
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); | |
c24a8f3c | 1605 | status = BT_FUNC_STATUS_ERROR; |
a8f90e5d | 1606 | } else { |
6b076590 | 1607 | BT_LIB_LOGW( |
a8f90e5d PP |
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 | ||
55bb57e0 PP |
1618 | goto end; |
1619 | } | |
1620 | ||
be3c4e36 MJ |
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 { | |
a684a357 | 1625 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1626 | "symbol=\"%s\"", path, |
be3c4e36 | 1627 | "__bt_get_begin_section_component_class_descriptor_attributes"); |
55bb57e0 PP |
1628 | } |
1629 | ||
be3c4e36 MJ |
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 { | |
a684a357 | 1634 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1635 | "symbol=\"%s\"", path, |
be3c4e36 | 1636 | "__bt_get_end_section_component_class_descriptor_attributes"); |
55bb57e0 PP |
1637 | } |
1638 | ||
1639 | if ((!!cc_descr_attrs_begin - !!cc_descr_attrs_end) != 0) { | |
a8f90e5d PP |
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); | |
c24a8f3c | 1649 | status = BT_FUNC_STATUS_ERROR; |
a8f90e5d | 1650 | } else { |
6b076590 | 1651 | BT_LIB_LOGW( |
a8f90e5d PP |
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 | ||
55bb57e0 PP |
1662 | goto end; |
1663 | } | |
1664 | ||
1665 | /* Initialize plugin */ | |
3fe0bf43 | 1666 | BT_LOGD_STR("Initializing plugin object."); |
01f50d54 PP |
1667 | status = bt_plugin_so_create_all_from_sections(shared_lib_handle, |
1668 | fail_on_load_error, | |
55bb57e0 PP |
1669 | descriptors_begin, descriptors_end, attrs_begin, attrs_end, |
1670 | cc_descriptors_begin, cc_descriptors_end, | |
01f50d54 | 1671 | cc_descr_attrs_begin, cc_descr_attrs_end, plugin_set_out); |
55bb57e0 PP |
1672 | |
1673 | end: | |
8138bfe1 | 1674 | BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle); |
01f50d54 | 1675 | return status; |
55bb57e0 PP |
1676 | } |
1677 | ||
1678 | static | |
1679 | void plugin_comp_class_destroy_listener(struct bt_component_class *comp_class, | |
1680 | void *data) | |
1681 | { | |
bfa9a4be | 1682 | bt_list_del(&comp_class->node); |
8138bfe1 | 1683 | BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle); |
a684a357 | 1684 | BT_LOGD("Component class destroyed: removed entry from list: " |
3fe0bf43 | 1685 | "comp-cls-addr=%p", comp_class); |
55bb57e0 PP |
1686 | } |
1687 | ||
3230ee6b | 1688 | void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin, |
55bb57e0 PP |
1689 | struct bt_component_class *comp_class) |
1690 | { | |
55bb57e0 PP |
1691 | struct bt_plugin_so_spec_data *spec = plugin->spec_data; |
1692 | ||
8b45963b PP |
1693 | BT_ASSERT(plugin->spec_data); |
1694 | BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO); | |
55bb57e0 | 1695 | |
bfa9a4be | 1696 | bt_list_add(&comp_class->node, &component_class_list); |
4b70020d | 1697 | comp_class->so_handle = spec->shared_lib_handle; |
864aa43f | 1698 | bt_object_get_ref_no_null_check(comp_class->so_handle); |
55bb57e0 PP |
1699 | |
1700 | /* Add our custom destroy listener */ | |
3230ee6b | 1701 | bt_component_class_add_destroy_listener(comp_class, |
55bb57e0 | 1702 | plugin_comp_class_destroy_listener, NULL); |
55bb57e0 | 1703 | } |