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