Commit | Line | Data |
---|---|---|
55bb57e0 | 1 | /* |
e2f7325d | 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 | ||
350ad6c1 | 26 | #define BT_LOG_TAG "LIB/PLUGIN-SO" |
c2d9d9cf | 27 | #include "lib/logging.h" |
3fe0bf43 | 28 | |
578e048b MJ |
29 | #include "common/assert.h" |
30 | #include "lib/assert-pre.h" | |
31 | #include "compat/compiler.h" | |
3fadfbc0 | 32 | #include <babeltrace2/plugin/plugin-dev.h> |
578e048b | 33 | #include "lib/graph/component-class.h" |
3fadfbc0 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> | |
578e048b | 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 | ||
578e048b MJ |
45 | #include "plugin.h" |
46 | #include "plugin-so.h" | |
d24d5663 PP |
47 | #include "lib/func-status.h" |
48 | #include "common/common.h" | |
578e048b | 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 | ||
91d81473 | 55 | #define PLUGIN_SUFFIX_LEN bt_max_t(size_t, sizeof(NATIVE_PLUGIN_SUFFIX), \ |
55bb57e0 PP |
56 | sizeof(LIBTOOL_PLUGIN_SUFFIX)) |
57 | ||
52238017 | 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 | * |
c8db3219 | 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); | |
65300d60 | 101 | BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle); |
55bb57e0 | 102 | } |
d94d92ac | 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 | ||
f6ccaed9 | 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 | ||
3f7d4d90 | 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."); |
9724cce9 PP |
123 | shared_lib_handle->exit(); |
124 | BT_LOGD_STR("User function returned."); | |
55bb57e0 PP |
125 | } |
126 | ||
127 | if (shared_lib_handle->module) { | |
21e6ffa5 | 128 | #ifdef BT_DEBUG_MODE |
f1447220 PP |
129 | /* |
130 | * Valgrind shows incomplete stack traces when | |
131 | * dynamically loaded libraries are closed before it | |
16b7b5e7 | 132 | * finishes. Use the LIBBABELTRACE2_NO_DLCLOSE in a debug |
f1447220 PP |
133 | * build to avoid this. |
134 | */ | |
16b7b5e7 | 135 | const char *var = getenv("LIBBABELTRACE2_NO_DLCLOSE"); |
f1447220 PP |
136 | |
137 | if (!var || strcmp(var, "1") != 0) { | |
138 | #endif | |
3f7d4d90 | 139 | BT_LOGI("Closing GModule: path=\"%s\"", path); |
3fe0bf43 | 140 | |
f1447220 | 141 | if (!g_module_close(shared_lib_handle->module)) { |
870631a2 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 | } |
db5504f9 PP |
150 | |
151 | shared_lib_handle->module = NULL; | |
21e6ffa5 | 152 | #ifdef BT_DEBUG_MODE |
3fe0bf43 | 153 | } else { |
16b7b5e7 | 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); | |
db5504f9 | 162 | shared_lib_handle->path = NULL; |
55bb57e0 PP |
163 | } |
164 | ||
165 | g_free(shared_lib_handle); | |
166 | } | |
167 | ||
168 | static | |
d24d5663 | 169 | int bt_plugin_so_shared_lib_handle_create( |
9736d991 PP |
170 | const char *path, |
171 | struct bt_plugin_so_shared_lib_handle **shared_lib_handle) | |
55bb57e0 | 172 | { |
d24d5663 | 173 | int status = BT_FUNC_STATUS_OK; |
55bb57e0 | 174 | |
9736d991 | 175 | BT_ASSERT(shared_lib_handle); |
3f7d4d90 | 176 | BT_LOGI("Creating shared library handle: path=\"%s\"", path); |
9736d991 PP |
177 | *shared_lib_handle = g_new0(struct bt_plugin_so_shared_lib_handle, 1); |
178 | if (!*shared_lib_handle) { | |
870631a2 | 179 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one shared library handle."); |
d24d5663 | 180 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
9736d991 | 181 | goto end; |
55bb57e0 PP |
182 | } |
183 | ||
9736d991 | 184 | bt_object_init_shared(&(*shared_lib_handle)->base, |
3fea54f6 | 185 | bt_plugin_so_shared_lib_handle_destroy); |
55bb57e0 PP |
186 | |
187 | if (!path) { | |
188 | goto end; | |
189 | } | |
190 | ||
9736d991 PP |
191 | (*shared_lib_handle)->path = g_string_new(path); |
192 | if (!(*shared_lib_handle)->path) { | |
870631a2 | 193 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
d24d5663 | 194 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
9736d991 | 195 | goto end; |
55bb57e0 PP |
196 | } |
197 | ||
9736d991 PP |
198 | (*shared_lib_handle)->module = g_module_open(path, G_MODULE_BIND_LOCAL); |
199 | if (!(*shared_lib_handle)->module) { | |
50ad9320 | 200 | /* |
3f7d4d90 | 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 | |
3f7d4d90 PP |
204 | * during bt_plugin_find_all_from_dir(), it's not even a |
205 | * warning. | |
50ad9320 | 206 | */ |
3f7d4d90 | 207 | BT_LOGI("Cannot open GModule: %s: path=\"%s\"", |
3fe0bf43 | 208 | g_module_error(), path); |
9736d991 | 209 | BT_OBJECT_PUT_REF_AND_RESET(*shared_lib_handle); |
d24d5663 | 210 | status = BT_FUNC_STATUS_NOT_FOUND; |
9736d991 | 211 | goto end; |
55bb57e0 PP |
212 | } |
213 | ||
214 | goto end; | |
215 | ||
55bb57e0 | 216 | end: |
d24d5663 | 217 | BT_ASSERT(*shared_lib_handle || status != BT_FUNC_STATUS_OK); |
9736d991 | 218 | if (*shared_lib_handle) { |
3f7d4d90 | 219 | BT_LOGI("Created shared library handle: path=\"%s\", addr=%p", |
9736d991 | 220 | path, *shared_lib_handle); |
3fe0bf43 PP |
221 | } |
222 | ||
9736d991 | 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 | ||
f6ccaed9 PP |
235 | BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO); |
236 | BT_ASSERT(spec); | |
65300d60 | 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 | |
d24d5663 | 270 | int bt_plugin_so_init(struct bt_plugin *plugin, |
9736d991 | 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; |
d94d92ac PP |
288 | |
289 | union { | |
290 | struct { | |
0d72b8c3 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; | |
0d72b8c3 | 294 | bt_component_class_source_output_port_connected_method output_port_connected; |
d6e69534 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; | |
7474e7d3 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; | |
d94d92ac PP |
301 | } source; |
302 | ||
303 | struct { | |
0d72b8c3 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; | |
0d72b8c3 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; | |
d6e69534 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; | |
7474e7d3 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; | |
d94d92ac PP |
315 | } filter; |
316 | ||
317 | struct { | |
0d72b8c3 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; | |
0d72b8c3 | 321 | bt_component_class_sink_input_port_connected_method input_port_connected; |
5badd463 | 322 | bt_component_class_sink_graph_is_configured_method graph_is_configured; |
d94d92ac PP |
323 | } sink; |
324 | } methods; | |
55bb57e0 PP |
325 | }; |
326 | ||
d24d5663 | 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 | ||
3f7d4d90 | 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) { | |
870631a2 | 350 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray."); |
d24d5663 | 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 | ||
5084732e | 367 | if (!cur_attr) { |
52238017 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: | |
9736d991 | 399 | if (fail_on_load_error) { |
870631a2 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); | |
d24d5663 | 409 | status = BT_FUNC_STATUS_LOADING_ERROR; |
9736d991 | 410 | goto end; |
870631a2 | 411 | } else { |
a0cdfce8 | 412 | BT_LIB_LOGW( |
870631a2 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); | |
9736d991 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 | ||
5084732e | 437 | if (!cur_cc_descr) { |
52238017 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; | |
d94d92ac | 458 | enum bt_component_class_type cc_type; |
55bb57e0 | 459 | |
5084732e | 460 | if (!cur_cc_descr_attr) { |
52238017 MJ |
461 | continue; |
462 | } | |
463 | ||
55bb57e0 PP |
464 | if (cur_cc_descr_attr->comp_class_descriptor->plugin_descriptor != |
465 | descriptor) { | |
466 | continue; | |
467 | } | |
468 | ||
d94d92ac 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 | ||
d94d92ac | 477 | if (cur_cc_descr_attr->comp_class_descriptor != |
55bb57e0 | 478 | cc_full_descr->descriptor) { |
d94d92ac 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; |
d94d92ac 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; |
d94d92ac 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; |
d94d92ac 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; |
d94d92ac 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; |
d94d92ac 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; |
d94d92ac 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; |
d94d92ac 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; |
d94d92ac 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; |
d94d92ac PP |
541 | default: |
542 | abort(); | |
543 | } | |
544 | break; | |
d94d92ac 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: |
d94d92ac 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; |
d94d92ac PP |
569 | default: |
570 | abort(); | |
55bb57e0 | 571 | } |
d94d92ac | 572 | break; |
5badd463 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; | |
d6e69534 | 583 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INIT_METHOD: |
d94d92ac PP |
584 | switch (cc_type) { |
585 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
d6e69534 PP |
586 | cc_full_descr->methods.source.msg_iter_init = |
587 | cur_cc_descr_attr->value.source_msg_iter_init_method; | |
d94d92ac PP |
588 | break; |
589 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
d6e69534 PP |
590 | cc_full_descr->methods.filter.msg_iter_init = |
591 | cur_cc_descr_attr->value.filter_msg_iter_init_method; | |
d94d92ac PP |
592 | break; |
593 | default: | |
594 | abort(); | |
595 | } | |
596 | break; | |
d6e69534 | 597 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_FINALIZE_METHOD: |
d94d92ac PP |
598 | switch (cc_type) { |
599 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
d6e69534 PP |
600 | cc_full_descr->methods.source.msg_iter_finalize = |
601 | cur_cc_descr_attr->value.source_msg_iter_finalize_method; | |
d94d92ac PP |
602 | break; |
603 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
d6e69534 PP |
604 | cc_full_descr->methods.filter.msg_iter_finalize = |
605 | cur_cc_descr_attr->value.filter_msg_iter_finalize_method; | |
d94d92ac PP |
606 | break; |
607 | default: | |
608 | abort(); | |
609 | } | |
610 | break; | |
7474e7d3 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; | |
d94d92ac | 667 | default: |
9736d991 | 668 | if (fail_on_load_error) { |
870631a2 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); | |
d24d5663 | 686 | status = BT_FUNC_STATUS_LOADING_ERROR; |
9736d991 | 687 | goto end; |
870631a2 | 688 | } else { |
a0cdfce8 | 689 | BT_LIB_LOGW( |
870631a2 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); | |
9736d991 PP |
706 | } |
707 | ||
d94d92ac | 708 | break; |
55bb57e0 PP |
709 | } |
710 | } | |
711 | } | |
712 | ||
713 | /* Initialize plugin */ | |
714 | if (spec->init) { | |
d24d5663 | 715 | enum bt_plugin_init_func_status init_status; |
a21d1cb8 | 716 | |
3fe0bf43 | 717 | BT_LOGD_STR("Calling user's plugin initialization function."); |
a21d1cb8 | 718 | init_status = spec->init((void *) plugin); |
9736d991 | 719 | BT_LOGD("User function returned: status=%s", |
d24d5663 | 720 | bt_common_func_status_string(init_status)); |
3fe0bf43 | 721 | |
9724cce9 | 722 | if (init_status < 0) { |
9736d991 | 723 | if (fail_on_load_error) { |
870631a2 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)); | |
d24d5663 | 728 | status = init_status; |
9736d991 | 729 | goto end; |
870631a2 | 730 | } else { |
a0cdfce8 | 731 | BT_LIB_LOGW( |
870631a2 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; | |
9736d991 | 736 | } |
870631a2 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); | |
0d72b8c3 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 | |
3f7d4d90 | 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: | |
0d72b8c3 | 767 | src_comp_class = bt_component_class_source_create( |
55bb57e0 | 768 | cc_full_descr->descriptor->name, |
d6e69534 | 769 | cc_full_descr->descriptor->methods.source.msg_iter_next); |
0d72b8c3 | 770 | comp_class = bt_component_class_source_as_component_class( |
d94d92ac | 771 | src_comp_class); |
55bb57e0 PP |
772 | break; |
773 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
0d72b8c3 | 774 | flt_comp_class = bt_component_class_filter_create( |
55bb57e0 | 775 | cc_full_descr->descriptor->name, |
d6e69534 | 776 | cc_full_descr->descriptor->methods.source.msg_iter_next); |
0d72b8c3 | 777 | comp_class = bt_component_class_filter_as_component_class( |
d94d92ac | 778 | flt_comp_class); |
55bb57e0 PP |
779 | break; |
780 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
0d72b8c3 | 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); | |
0d72b8c3 | 784 | comp_class = bt_component_class_sink_as_component_class( |
d94d92ac | 785 | sink_comp_class); |
55bb57e0 PP |
786 | break; |
787 | default: | |
9736d991 | 788 | if (fail_on_load_error) { |
870631a2 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); | |
d24d5663 | 799 | status = BT_FUNC_STATUS_LOADING_ERROR; |
9736d991 | 800 | goto end; |
870631a2 | 801 | } else { |
a0cdfce8 | 802 | BT_LIB_LOGW( |
870631a2 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; | |
9736d991 | 813 | } |
55bb57e0 PP |
814 | } |
815 | ||
816 | if (!comp_class) { | |
870631a2 PP |
817 | BT_LIB_LOGE_APPEND_CAUSE( |
818 | "Cannot create component class."); | |
d24d5663 | 819 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
55bb57e0 PP |
820 | goto end; |
821 | } | |
822 | ||
823 | if (cc_full_descr->description) { | |
0d72b8c3 | 824 | ret = bt_component_class_set_description( |
d94d92ac | 825 | comp_class, cc_full_descr->description); |
55bb57e0 | 826 | if (ret) { |
870631a2 PP |
827 | BT_LIB_LOGE_APPEND_CAUSE( |
828 | "Cannot set component class's description."); | |
d24d5663 | 829 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
65300d60 | 830 | BT_OBJECT_PUT_REF_AND_RESET(comp_class); |
55bb57e0 PP |
831 | goto end; |
832 | } | |
833 | } | |
834 | ||
279b3f15 | 835 | if (cc_full_descr->help) { |
0d72b8c3 | 836 | ret = bt_component_class_set_help(comp_class, |
279b3f15 PP |
837 | cc_full_descr->help); |
838 | if (ret) { | |
870631a2 PP |
839 | BT_LIB_LOGE_APPEND_CAUSE( |
840 | "Cannot set component class's help string."); | |
d24d5663 | 841 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
65300d60 | 842 | BT_OBJECT_PUT_REF_AND_RESET(comp_class); |
279b3f15 PP |
843 | goto end; |
844 | } | |
845 | } | |
846 | ||
d94d92ac PP |
847 | switch (cc_full_descr->descriptor->type) { |
848 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
849 | if (cc_full_descr->methods.source.init) { | |
0d72b8c3 | 850 | ret = bt_component_class_source_set_init_method( |
d94d92ac PP |
851 | src_comp_class, |
852 | cc_full_descr->methods.source.init); | |
853 | if (ret) { | |
870631a2 PP |
854 | BT_LIB_LOGE_APPEND_CAUSE( |
855 | "Cannot set source component class's initialization method."); | |
d24d5663 | 856 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac PP |
857 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
858 | goto end; | |
859 | } | |
55bb57e0 | 860 | } |
55bb57e0 | 861 | |
d94d92ac | 862 | if (cc_full_descr->methods.source.finalize) { |
0d72b8c3 | 863 | ret = bt_component_class_source_set_finalize_method( |
d94d92ac PP |
864 | src_comp_class, |
865 | cc_full_descr->methods.source.finalize); | |
866 | if (ret) { | |
870631a2 PP |
867 | BT_LIB_LOGE_APPEND_CAUSE( |
868 | "Cannot set source component class's finalization method."); | |
d24d5663 | 869 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac PP |
870 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
871 | goto end; | |
872 | } | |
55bb57e0 | 873 | } |
55bb57e0 | 874 | |
d94d92ac | 875 | if (cc_full_descr->methods.source.query) { |
0d72b8c3 | 876 | ret = bt_component_class_source_set_query_method( |
d94d92ac PP |
877 | src_comp_class, |
878 | cc_full_descr->methods.source.query); | |
879 | if (ret) { | |
870631a2 PP |
880 | BT_LIB_LOGE_APPEND_CAUSE( |
881 | "Cannot set source component class's query method."); | |
d24d5663 | 882 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac PP |
883 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
884 | goto end; | |
885 | } | |
8463eac2 | 886 | } |
8463eac2 | 887 | |
d94d92ac | 888 | if (cc_full_descr->methods.source.output_port_connected) { |
0d72b8c3 | 889 | ret = bt_component_class_source_set_output_port_connected_method( |
d94d92ac PP |
890 | src_comp_class, |
891 | cc_full_descr->methods.source.output_port_connected); | |
892 | if (ret) { | |
870631a2 PP |
893 | BT_LIB_LOGE_APPEND_CAUSE( |
894 | "Cannot set source component class's \"output port connected\" method."); | |
d24d5663 | 895 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac PP |
896 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
897 | goto end; | |
898 | } | |
0d8b4d8e | 899 | } |
0d8b4d8e | 900 | |
d6e69534 PP |
901 | if (cc_full_descr->methods.source.msg_iter_init) { |
902 | ret = bt_component_class_source_set_message_iterator_init_method( | |
d94d92ac | 903 | src_comp_class, |
d6e69534 | 904 | cc_full_descr->methods.source.msg_iter_init); |
55bb57e0 | 905 | if (ret) { |
870631a2 PP |
906 | BT_LIB_LOGE_APPEND_CAUSE( |
907 | "Cannot set source component class's message iterator initialization method."); | |
d24d5663 | 908 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac | 909 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
55bb57e0 PP |
910 | goto end; |
911 | } | |
912 | } | |
913 | ||
d6e69534 PP |
914 | if (cc_full_descr->methods.source.msg_iter_finalize) { |
915 | ret = bt_component_class_source_set_message_iterator_finalize_method( | |
d94d92ac | 916 | src_comp_class, |
d6e69534 | 917 | cc_full_descr->methods.source.msg_iter_finalize); |
55bb57e0 | 918 | if (ret) { |
870631a2 PP |
919 | BT_LIB_LOGE_APPEND_CAUSE( |
920 | "Cannot set source component class's message iterator finalization method."); | |
d24d5663 | 921 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac | 922 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
55bb57e0 PP |
923 | goto end; |
924 | } | |
925 | } | |
d94d92ac | 926 | |
7474e7d3 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) { | |
870631a2 PP |
932 | BT_LIB_LOGE_APPEND_CAUSE( |
933 | "Cannot set source component class's message iterator \"seek nanoseconds from origin\" method."); | |
d24d5663 | 934 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
7474e7d3 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) { | |
870631a2 PP |
945 | BT_LIB_LOGE_APPEND_CAUSE( |
946 | "Cannot set source component class's message iterator \"seek beginning\" method."); | |
d24d5663 | 947 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
7474e7d3 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) { | |
870631a2 PP |
958 | BT_LIB_LOGE_APPEND_CAUSE( |
959 | "Cannot set source component class's message iterator \"can seek nanoseconds from origin\" method."); | |
d24d5663 | 960 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
7474e7d3 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) { | |
870631a2 PP |
971 | BT_LIB_LOGE_APPEND_CAUSE( |
972 | "Cannot set source component class's message iterator \"can seek beginning\" method."); | |
d24d5663 | 973 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
7474e7d3 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: | |
d94d92ac | 981 | if (cc_full_descr->methods.filter.init) { |
0d72b8c3 | 982 | ret = bt_component_class_filter_set_init_method( |
d94d92ac PP |
983 | flt_comp_class, |
984 | cc_full_descr->methods.filter.init); | |
985 | if (ret) { | |
870631a2 PP |
986 | BT_LIB_LOGE_APPEND_CAUSE( |
987 | "Cannot set filter component class's initialization method."); | |
d24d5663 | 988 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac 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) { | |
0d72b8c3 | 995 | ret = bt_component_class_filter_set_finalize_method( |
d94d92ac PP |
996 | flt_comp_class, |
997 | cc_full_descr->methods.filter.finalize); | |
998 | if (ret) { | |
870631a2 PP |
999 | BT_LIB_LOGE_APPEND_CAUSE( |
1000 | "Cannot set filter component class's finalization method."); | |
d24d5663 | 1001 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac 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) { | |
0d72b8c3 | 1008 | ret = bt_component_class_filter_set_query_method( |
d94d92ac PP |
1009 | flt_comp_class, |
1010 | cc_full_descr->methods.filter.query); | |
1011 | if (ret) { | |
870631a2 PP |
1012 | BT_LIB_LOGE_APPEND_CAUSE( |
1013 | "Cannot set filter component class's query method."); | |
d24d5663 | 1014 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac PP |
1015 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1016 | goto end; | |
1017 | } | |
1018 | } | |
1019 | ||
d94d92ac | 1020 | if (cc_full_descr->methods.filter.input_port_connected) { |
0d72b8c3 | 1021 | ret = bt_component_class_filter_set_input_port_connected_method( |
d94d92ac PP |
1022 | flt_comp_class, |
1023 | cc_full_descr->methods.filter.input_port_connected); | |
1024 | if (ret) { | |
870631a2 PP |
1025 | BT_LIB_LOGE_APPEND_CAUSE( |
1026 | "Cannot set filter component class's \"input port connected\" method."); | |
d24d5663 | 1027 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac 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) { | |
0d72b8c3 | 1034 | ret = bt_component_class_filter_set_output_port_connected_method( |
d94d92ac PP |
1035 | flt_comp_class, |
1036 | cc_full_descr->methods.filter.output_port_connected); | |
1037 | if (ret) { | |
870631a2 PP |
1038 | BT_LIB_LOGE_APPEND_CAUSE( |
1039 | "Cannot set filter component class's \"output port connected\" method."); | |
d24d5663 | 1040 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac PP |
1041 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1042 | goto end; | |
1043 | } | |
1044 | } | |
1045 | ||
d6e69534 PP |
1046 | if (cc_full_descr->methods.filter.msg_iter_init) { |
1047 | ret = bt_component_class_filter_set_message_iterator_init_method( | |
d94d92ac | 1048 | flt_comp_class, |
d6e69534 | 1049 | cc_full_descr->methods.filter.msg_iter_init); |
55bb57e0 | 1050 | if (ret) { |
870631a2 PP |
1051 | BT_LIB_LOGE_APPEND_CAUSE( |
1052 | "Cannot set filter component class's message iterator initialization method."); | |
d24d5663 | 1053 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac | 1054 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
55bb57e0 PP |
1055 | goto end; |
1056 | } | |
1057 | } | |
1058 | ||
d6e69534 PP |
1059 | if (cc_full_descr->methods.filter.msg_iter_finalize) { |
1060 | ret = bt_component_class_filter_set_message_iterator_finalize_method( | |
d94d92ac | 1061 | flt_comp_class, |
d6e69534 | 1062 | cc_full_descr->methods.filter.msg_iter_finalize); |
55bb57e0 | 1063 | if (ret) { |
870631a2 PP |
1064 | BT_LIB_LOGE_APPEND_CAUSE( |
1065 | "Cannot set filter component class's message iterator finalization method."); | |
d24d5663 | 1066 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac | 1067 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
55bb57e0 PP |
1068 | goto end; |
1069 | } | |
1070 | } | |
d94d92ac | 1071 | |
7474e7d3 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) { | |
870631a2 PP |
1077 | BT_LIB_LOGE_APPEND_CAUSE( |
1078 | "Cannot set filter component class's message iterator \"seek nanoseconds from origin\" method."); | |
d24d5663 | 1079 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
7474e7d3 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) { | |
870631a2 PP |
1090 | BT_LIB_LOGE_APPEND_CAUSE( |
1091 | "Cannot set filter component class's message iterator \"seek beginning\" method."); | |
d24d5663 | 1092 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
7474e7d3 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) { | |
870631a2 PP |
1103 | BT_LIB_LOGE_APPEND_CAUSE( |
1104 | "Cannot set filter component class's message iterator \"can seek nanoseconds from origin\" method."); | |
d24d5663 | 1105 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
7474e7d3 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) { | |
870631a2 PP |
1116 | BT_LIB_LOGE_APPEND_CAUSE( |
1117 | "Cannot set filter component class's message iterator \"can seek beginning\" method."); | |
d24d5663 | 1118 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
7474e7d3 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: | |
d94d92ac | 1126 | if (cc_full_descr->methods.sink.init) { |
0d72b8c3 | 1127 | ret = bt_component_class_sink_set_init_method( |
d94d92ac PP |
1128 | sink_comp_class, |
1129 | cc_full_descr->methods.sink.init); | |
1130 | if (ret) { | |
870631a2 PP |
1131 | BT_LIB_LOGE_APPEND_CAUSE( |
1132 | "Cannot set sink component class's initialization method."); | |
d24d5663 | 1133 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac 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) { | |
0d72b8c3 | 1140 | ret = bt_component_class_sink_set_finalize_method( |
d94d92ac PP |
1141 | sink_comp_class, |
1142 | cc_full_descr->methods.sink.finalize); | |
1143 | if (ret) { | |
870631a2 PP |
1144 | BT_LIB_LOGE_APPEND_CAUSE( |
1145 | "Cannot set sink component class's finalization method."); | |
d24d5663 | 1146 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac 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) { | |
0d72b8c3 | 1153 | ret = bt_component_class_sink_set_query_method( |
d94d92ac PP |
1154 | sink_comp_class, |
1155 | cc_full_descr->methods.sink.query); | |
1156 | if (ret) { | |
870631a2 PP |
1157 | BT_LIB_LOGE_APPEND_CAUSE( |
1158 | "Cannot set sink component class's query method."); | |
d24d5663 | 1159 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac PP |
1160 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1161 | goto end; | |
1162 | } | |
1163 | } | |
1164 | ||
d94d92ac | 1165 | if (cc_full_descr->methods.sink.input_port_connected) { |
0d72b8c3 | 1166 | ret = bt_component_class_sink_set_input_port_connected_method( |
d94d92ac PP |
1167 | sink_comp_class, |
1168 | cc_full_descr->methods.sink.input_port_connected); | |
1169 | if (ret) { | |
870631a2 PP |
1170 | BT_LIB_LOGE_APPEND_CAUSE( |
1171 | "Cannot set sink component class's \"input port connected\" method."); | |
d24d5663 | 1172 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
d94d92ac PP |
1173 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1174 | goto end; | |
1175 | } | |
1176 | } | |
1177 | ||
5badd463 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) { | |
870631a2 PP |
1183 | BT_LIB_LOGE_APPEND_CAUSE( |
1184 | "Cannot set sink component class's \"graph is configured\" method."); | |
d24d5663 | 1185 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
5badd463 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 | |
d94d92ac 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, | |
d94d92ac | 1205 | (void *) comp_class); |
65300d60 | 1206 | BT_OBJECT_PUT_REF_AND_RESET(comp_class); |
55bb57e0 | 1207 | if (status < 0) { |
870631a2 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) { | |
870631a2 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; | |
398454ed 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: | |
65300d60 | 1245 | BT_OBJECT_PUT_REF_AND_RESET(plugin); |
55bb57e0 PP |
1246 | |
1247 | end: | |
1248 | return plugin; | |
1249 | } | |
1250 | ||
52238017 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 |
d24d5663 | 1269 | int bt_plugin_so_create_all_from_sections( |
55bb57e0 | 1270 | struct bt_plugin_so_shared_lib_handle *shared_lib_handle, |
9736d991 | 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, | |
9736d991 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 | { |
d24d5663 | 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 | |
9736d991 PP |
1289 | BT_ASSERT(plugin_set_out); |
1290 | *plugin_set_out = NULL; | |
52238017 MJ |
1291 | descriptor_count = count_non_null_items_in_section(descriptors_begin, descriptors_end); |
1292 | attrs_count = count_non_null_items_in_section(attrs_begin, attrs_end); | |
1293 | cc_descriptors_count = count_non_null_items_in_section(cc_descriptors_begin, cc_descriptors_end); | |
1294 | cc_descr_attrs_count = count_non_null_items_in_section(cc_descr_attrs_begin, cc_descr_attrs_end); | |
3f7d4d90 | 1295 | BT_LOGI("Creating all SO plugins from sections: " |
3fe0bf43 PP |
1296 | "plugin-path=\"%s\", " |
1297 | "descr-begin-addr=%p, descr-end-addr=%p, " | |
1298 | "attrs-begin-addr=%p, attrs-end-addr=%p, " | |
1299 | "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, " | |
1300 | "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p, " | |
1301 | "descr-count=%zu, attrs-count=%zu, " | |
1302 | "cc-descr-count=%zu, cc-descr-attrs-count=%zu", | |
1303 | shared_lib_handle->path ? shared_lib_handle->path->str : NULL, | |
1304 | descriptors_begin, descriptors_end, | |
1305 | attrs_begin, attrs_end, | |
1306 | cc_descriptors_begin, cc_descriptors_end, | |
1307 | cc_descr_attrs_begin, cc_descr_attrs_end, | |
1308 | descriptor_count, attrs_count, | |
1309 | cc_descriptors_count, cc_descr_attrs_count); | |
9736d991 PP |
1310 | *plugin_set_out = bt_plugin_set_create(); |
1311 | if (!*plugin_set_out) { | |
870631a2 | 1312 | BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set."); |
d24d5663 | 1313 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
55bb57e0 PP |
1314 | goto error; |
1315 | } | |
1316 | ||
52238017 | 1317 | for (i = 0; i < descriptors_end - descriptors_begin; i++) { |
55bb57e0 PP |
1318 | const struct __bt_plugin_descriptor *descriptor = |
1319 | descriptors_begin[i]; | |
1320 | struct bt_plugin *plugin; | |
1321 | ||
5084732e | 1322 | if (!descriptor) { |
52238017 MJ |
1323 | continue; |
1324 | } | |
1325 | ||
3f7d4d90 | 1326 | BT_LOGI("Creating plugin object for plugin: " |
3fe0bf43 PP |
1327 | "name=\"%s\", abi-major=%d, abi-minor=%d", |
1328 | descriptor->name, descriptor->major, descriptor->minor); | |
55bb57e0 PP |
1329 | |
1330 | if (descriptor->major > __BT_PLUGIN_VERSION_MAJOR) { | |
9736d991 | 1331 | if (fail_on_load_error) { |
870631a2 PP |
1332 | BT_LIB_LOGW_APPEND_CAUSE( |
1333 | "Unknown ABI major version: abi-major=%d", | |
1334 | descriptor->major); | |
d24d5663 | 1335 | status = BT_FUNC_STATUS_LOADING_ERROR; |
9736d991 PP |
1336 | goto error; |
1337 | } else { | |
a0cdfce8 | 1338 | BT_LIB_LOGW( |
870631a2 PP |
1339 | "Unknown ABI major version: abi-major=%d", |
1340 | descriptor->major); | |
9736d991 PP |
1341 | continue; |
1342 | } | |
55bb57e0 PP |
1343 | } |
1344 | ||
1345 | plugin = bt_plugin_so_create_empty(shared_lib_handle); | |
1346 | if (!plugin) { | |
870631a2 PP |
1347 | BT_LIB_LOGE_APPEND_CAUSE( |
1348 | "Cannot create empty shared library handle."); | |
d24d5663 | 1349 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
55bb57e0 PP |
1350 | goto error; |
1351 | } | |
1352 | ||
1353 | if (shared_lib_handle && shared_lib_handle->path) { | |
9736d991 PP |
1354 | bt_plugin_set_path(plugin, |
1355 | shared_lib_handle->path->str); | |
55bb57e0 PP |
1356 | } |
1357 | ||
9736d991 PP |
1358 | status = bt_plugin_so_init(plugin, fail_on_load_error, |
1359 | descriptor, attrs_begin, attrs_end, | |
1360 | cc_descriptors_begin, cc_descriptors_end, | |
55bb57e0 | 1361 | cc_descr_attrs_begin, cc_descr_attrs_end); |
d24d5663 | 1362 | if (status == BT_FUNC_STATUS_OK) { |
9736d991 PP |
1363 | /* Add to plugin set */ |
1364 | bt_plugin_set_add_plugin(*plugin_set_out, plugin); | |
1365 | BT_OBJECT_PUT_REF_AND_RESET(plugin); | |
1366 | } else if (status < 0) { | |
50ad9320 | 1367 | /* |
9736d991 PP |
1368 | * bt_plugin_so_init() handles |
1369 | * `fail_on_load_error`, so this is a "real" | |
1370 | * error. | |
50ad9320 | 1371 | */ |
870631a2 PP |
1372 | BT_LIB_LOGW_APPEND_CAUSE( |
1373 | "Cannot initialize SO plugin object from sections."); | |
65300d60 | 1374 | BT_OBJECT_PUT_REF_AND_RESET(plugin); |
55bb57e0 PP |
1375 | goto error; |
1376 | } | |
1377 | ||
9736d991 PP |
1378 | BT_ASSERT(!plugin); |
1379 | } | |
1380 | ||
1381 | BT_ASSERT(*plugin_set_out); | |
1382 | ||
1383 | if ((*plugin_set_out)->plugins->len == 0) { | |
1384 | BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out); | |
d24d5663 | 1385 | status = BT_FUNC_STATUS_NOT_FOUND; |
55bb57e0 PP |
1386 | } |
1387 | ||
1388 | goto end; | |
1389 | ||
1390 | error: | |
9736d991 PP |
1391 | BT_ASSERT(status < 0); |
1392 | BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out); | |
55bb57e0 PP |
1393 | |
1394 | end: | |
9736d991 | 1395 | return status; |
55bb57e0 PP |
1396 | } |
1397 | ||
1398 | BT_HIDDEN | |
d24d5663 | 1399 | int bt_plugin_so_create_all_from_static(bool fail_on_load_error, |
9736d991 | 1400 | struct bt_plugin_set **plugin_set_out) |
55bb57e0 | 1401 | { |
d24d5663 | 1402 | int status; |
9736d991 | 1403 | struct bt_plugin_so_shared_lib_handle *shared_lib_handle = NULL; |
55bb57e0 | 1404 | |
9736d991 PP |
1405 | BT_ASSERT(plugin_set_out); |
1406 | *plugin_set_out = NULL; | |
1407 | status = bt_plugin_so_shared_lib_handle_create(NULL, | |
1408 | &shared_lib_handle); | |
d24d5663 | 1409 | if (status != BT_FUNC_STATUS_OK) { |
9736d991 | 1410 | BT_ASSERT(!shared_lib_handle); |
55bb57e0 PP |
1411 | goto end; |
1412 | } | |
1413 | ||
9736d991 | 1414 | BT_ASSERT(shared_lib_handle); |
3fe0bf43 | 1415 | BT_LOGD_STR("Creating all SO plugins from built-in plugins."); |
9736d991 PP |
1416 | status = bt_plugin_so_create_all_from_sections(shared_lib_handle, |
1417 | fail_on_load_error, | |
52238017 MJ |
1418 | __bt_get_begin_section_plugin_descriptors(), |
1419 | __bt_get_end_section_plugin_descriptors(), | |
1420 | __bt_get_begin_section_plugin_descriptor_attributes(), | |
1421 | __bt_get_end_section_plugin_descriptor_attributes(), | |
1422 | __bt_get_begin_section_component_class_descriptors(), | |
1423 | __bt_get_end_section_component_class_descriptors(), | |
1424 | __bt_get_begin_section_component_class_descriptor_attributes(), | |
9736d991 PP |
1425 | __bt_get_end_section_component_class_descriptor_attributes(), |
1426 | plugin_set_out); | |
d24d5663 | 1427 | BT_ASSERT((status == BT_FUNC_STATUS_OK && *plugin_set_out && |
9736d991 | 1428 | (*plugin_set_out)->plugins->len > 0) || !*plugin_set_out); |
55bb57e0 PP |
1429 | |
1430 | end: | |
65300d60 | 1431 | BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle); |
9736d991 | 1432 | return status; |
55bb57e0 PP |
1433 | } |
1434 | ||
1435 | BT_HIDDEN | |
d24d5663 | 1436 | int bt_plugin_so_create_all_from_file(const char *path, |
9736d991 | 1437 | bool fail_on_load_error, struct bt_plugin_set **plugin_set_out) |
55bb57e0 PP |
1438 | { |
1439 | size_t path_len; | |
d24d5663 | 1440 | int status; |
55bb57e0 PP |
1441 | struct __bt_plugin_descriptor const * const *descriptors_begin = NULL; |
1442 | struct __bt_plugin_descriptor const * const *descriptors_end = NULL; | |
1443 | struct __bt_plugin_descriptor_attribute const * const *attrs_begin = NULL; | |
1444 | struct __bt_plugin_descriptor_attribute const * const *attrs_end = NULL; | |
1445 | struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_begin = NULL; | |
1446 | struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_end = NULL; | |
1447 | struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_begin = NULL; | |
1448 | struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_end = NULL; | |
52238017 MJ |
1449 | struct __bt_plugin_descriptor const * const *(*get_begin_section_plugin_descriptors)(void); |
1450 | struct __bt_plugin_descriptor const * const *(*get_end_section_plugin_descriptors)(void); | |
1451 | struct __bt_plugin_descriptor_attribute const * const *(*get_begin_section_plugin_descriptor_attributes)(void); | |
1452 | struct __bt_plugin_descriptor_attribute const * const *(*get_end_section_plugin_descriptor_attributes)(void); | |
1453 | struct __bt_plugin_component_class_descriptor const * const *(*get_begin_section_component_class_descriptors)(void); | |
1454 | struct __bt_plugin_component_class_descriptor const * const *(*get_end_section_component_class_descriptors)(void); | |
1455 | struct __bt_plugin_component_class_descriptor_attribute const * const *(*get_begin_section_component_class_descriptor_attributes)(void); | |
1456 | struct __bt_plugin_component_class_descriptor_attribute const * const *(*get_end_section_component_class_descriptor_attributes)(void); | |
c55a9f58 | 1457 | bt_bool is_libtool_wrapper = BT_FALSE, is_shared_object = BT_FALSE; |
55bb57e0 PP |
1458 | struct bt_plugin_so_shared_lib_handle *shared_lib_handle = NULL; |
1459 | ||
3f7d4d90 | 1460 | BT_ASSERT(path); |
9736d991 PP |
1461 | BT_ASSERT(plugin_set_out); |
1462 | *plugin_set_out = NULL; | |
55bb57e0 | 1463 | path_len = strlen(path); |
3f7d4d90 PP |
1464 | BT_ASSERT_PRE(path_len > PLUGIN_SUFFIX_LEN, |
1465 | "Path length is too short: path-length=%zu, min-length=%zu", | |
1466 | path_len, PLUGIN_SUFFIX_LEN); | |
1467 | BT_LOGI("Trying to create all SO plugins from file: path=\"%s\"", path); | |
55bb57e0 | 1468 | path_len++; |
3f7d4d90 | 1469 | |
55bb57e0 | 1470 | /* |
3f7d4d90 PP |
1471 | * Check if the file ends with a known plugin file type suffix |
1472 | * (i.e. .so or .la on Linux). | |
55bb57e0 PP |
1473 | */ |
1474 | is_libtool_wrapper = !strncmp(LIBTOOL_PLUGIN_SUFFIX, | |
1475 | path + path_len - LIBTOOL_PLUGIN_SUFFIX_LEN, | |
1476 | LIBTOOL_PLUGIN_SUFFIX_LEN); | |
1477 | is_shared_object = !strncmp(NATIVE_PLUGIN_SUFFIX, | |
1478 | path + path_len - NATIVE_PLUGIN_SUFFIX_LEN, | |
1479 | NATIVE_PLUGIN_SUFFIX_LEN); | |
1480 | if (!is_shared_object && !is_libtool_wrapper) { | |
3fe0bf43 | 1481 | /* Name indicates this is not a plugin file; not an error */ |
9736d991 | 1482 | BT_LOGI("File is not an SO plugin file: path=\"%s\"", path); |
d24d5663 | 1483 | status = BT_FUNC_STATUS_NOT_FOUND; |
55bb57e0 PP |
1484 | goto end; |
1485 | } | |
1486 | ||
9736d991 PP |
1487 | status = bt_plugin_so_shared_lib_handle_create(path, |
1488 | &shared_lib_handle); | |
d24d5663 | 1489 | if (status != BT_FUNC_STATUS_OK) { |
3f7d4d90 | 1490 | /* bt_plugin_so_shared_lib_handle_create() logs more details */ |
9736d991 | 1491 | BT_ASSERT(!shared_lib_handle); |
55bb57e0 PP |
1492 | goto end; |
1493 | } | |
1494 | ||
52238017 MJ |
1495 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_plugin_descriptors", |
1496 | (gpointer *) &get_begin_section_plugin_descriptors)) { | |
1497 | descriptors_begin = get_begin_section_plugin_descriptors(); | |
1498 | } else { | |
9736d991 PP |
1499 | /* |
1500 | * Use this first symbol to know whether or not this | |
1501 | * shared object _looks like_ a Babeltrace plugin. Since | |
1502 | * g_module_symbol() failed, assume that this is not a | |
1503 | * Babeltrace plugin, so it's not an error. | |
1504 | */ | |
3f7d4d90 | 1505 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1506 | "symbol=\"%s\"", path, |
52238017 | 1507 | "__bt_get_begin_section_plugin_descriptors"); |
d24d5663 | 1508 | status = BT_FUNC_STATUS_NOT_FOUND; |
55bb57e0 PP |
1509 | goto end; |
1510 | } | |
1511 | ||
9736d991 PP |
1512 | /* |
1513 | * If g_module_symbol() fails for any of the other symbols, fail | |
1514 | * if `fail_on_load_error` is true. | |
1515 | */ | |
52238017 MJ |
1516 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_plugin_descriptors", |
1517 | (gpointer *) &get_end_section_plugin_descriptors)) { | |
1518 | descriptors_end = get_end_section_plugin_descriptors(); | |
1519 | } else { | |
870631a2 PP |
1520 | if (fail_on_load_error) { |
1521 | BT_LIB_LOGW_APPEND_CAUSE( | |
1522 | "Cannot resolve plugin symbol: path=\"%s\", " | |
1523 | "symbol=\"%s\"", path, | |
1524 | "__bt_get_end_section_plugin_descriptors"); | |
1525 | status = BT_FUNC_STATUS_LOADING_ERROR; | |
1526 | } else { | |
a0cdfce8 | 1527 | BT_LIB_LOGW( |
870631a2 PP |
1528 | "Cannot resolve plugin symbol: path=\"%s\", " |
1529 | "symbol=\"%s\"", path, | |
1530 | "__bt_get_end_section_plugin_descriptors"); | |
1531 | status = BT_FUNC_STATUS_NOT_FOUND; | |
1532 | } | |
1533 | ||
55bb57e0 PP |
1534 | goto end; |
1535 | } | |
1536 | ||
52238017 MJ |
1537 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_plugin_descriptor_attributes", |
1538 | (gpointer *) &get_begin_section_plugin_descriptor_attributes)) { | |
1539 | attrs_begin = get_begin_section_plugin_descriptor_attributes(); | |
1540 | } else { | |
3f7d4d90 | 1541 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1542 | "symbol=\"%s\"", path, |
52238017 | 1543 | "__bt_get_begin_section_plugin_descriptor_attributes"); |
55bb57e0 PP |
1544 | } |
1545 | ||
52238017 MJ |
1546 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_plugin_descriptor_attributes", |
1547 | (gpointer *) &get_end_section_plugin_descriptor_attributes)) { | |
1548 | attrs_end = get_end_section_plugin_descriptor_attributes(); | |
1549 | } else { | |
3f7d4d90 | 1550 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1551 | "symbol=\"%s\"", path, |
52238017 | 1552 | "__bt_get_end_section_plugin_descriptor_attributes"); |
55bb57e0 PP |
1553 | } |
1554 | ||
1555 | if ((!!attrs_begin - !!attrs_end) != 0) { | |
870631a2 PP |
1556 | if (fail_on_load_error) { |
1557 | BT_LIB_LOGW_APPEND_CAUSE( | |
1558 | "Found section start or end symbol, but not both: " | |
1559 | "path=\"%s\", symbol-start=\"%s\", " | |
1560 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1561 | "symbol-end-addr=%p", | |
1562 | path, "__bt_get_begin_section_plugin_descriptor_attributes", | |
1563 | "__bt_get_end_section_plugin_descriptor_attributes", | |
1564 | attrs_begin, attrs_end); | |
1565 | status = BT_FUNC_STATUS_LOADING_ERROR; | |
1566 | } else { | |
a0cdfce8 | 1567 | BT_LIB_LOGW( |
870631a2 PP |
1568 | "Found section start or end symbol, but not both: " |
1569 | "path=\"%s\", symbol-start=\"%s\", " | |
1570 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1571 | "symbol-end-addr=%p", | |
1572 | path, "__bt_get_begin_section_plugin_descriptor_attributes", | |
1573 | "__bt_get_end_section_plugin_descriptor_attributes", | |
1574 | attrs_begin, attrs_end); | |
1575 | status = BT_FUNC_STATUS_NOT_FOUND; | |
1576 | } | |
1577 | ||
55bb57e0 PP |
1578 | goto end; |
1579 | } | |
1580 | ||
52238017 MJ |
1581 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_component_class_descriptors", |
1582 | (gpointer *) &get_begin_section_component_class_descriptors)) { | |
1583 | cc_descriptors_begin = get_begin_section_component_class_descriptors(); | |
1584 | } else { | |
3f7d4d90 | 1585 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1586 | "symbol=\"%s\"", path, |
52238017 | 1587 | "__bt_get_begin_section_component_class_descriptors"); |
55bb57e0 PP |
1588 | } |
1589 | ||
52238017 MJ |
1590 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_component_class_descriptors", |
1591 | (gpointer *) &get_end_section_component_class_descriptors)) { | |
1592 | cc_descriptors_end = get_end_section_component_class_descriptors(); | |
1593 | } else { | |
3f7d4d90 | 1594 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1595 | "symbol=\"%s\"", path, |
52238017 | 1596 | "__bt_get_end_section_component_class_descriptors"); |
55bb57e0 PP |
1597 | } |
1598 | ||
1599 | if ((!!cc_descriptors_begin - !!cc_descriptors_end) != 0) { | |
870631a2 PP |
1600 | if (fail_on_load_error) { |
1601 | BT_LIB_LOGW_APPEND_CAUSE( | |
1602 | "Found section start or end symbol, but not both: " | |
1603 | "path=\"%s\", symbol-start=\"%s\", " | |
1604 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1605 | "symbol-end-addr=%p", | |
1606 | path, "__bt_get_begin_section_component_class_descriptors", | |
1607 | "__bt_get_end_section_component_class_descriptors", | |
1608 | cc_descriptors_begin, cc_descriptors_end); | |
1609 | status = BT_FUNC_STATUS_LOADING_ERROR; | |
1610 | } else { | |
a0cdfce8 | 1611 | BT_LIB_LOGW( |
870631a2 PP |
1612 | "Found section start or end symbol, but not both: " |
1613 | "path=\"%s\", symbol-start=\"%s\", " | |
1614 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1615 | "symbol-end-addr=%p", | |
1616 | path, "__bt_get_begin_section_component_class_descriptors", | |
1617 | "__bt_get_end_section_component_class_descriptors", | |
1618 | cc_descriptors_begin, cc_descriptors_end); | |
1619 | status = BT_FUNC_STATUS_NOT_FOUND; | |
1620 | } | |
1621 | ||
55bb57e0 PP |
1622 | goto end; |
1623 | } | |
1624 | ||
52238017 MJ |
1625 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_component_class_descriptor_attributes", |
1626 | (gpointer *) &get_begin_section_component_class_descriptor_attributes)) { | |
1627 | cc_descr_attrs_begin = get_begin_section_component_class_descriptor_attributes(); | |
1628 | } else { | |
3f7d4d90 | 1629 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1630 | "symbol=\"%s\"", path, |
52238017 | 1631 | "__bt_get_begin_section_component_class_descriptor_attributes"); |
55bb57e0 PP |
1632 | } |
1633 | ||
52238017 MJ |
1634 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_component_class_descriptor_attributes", |
1635 | (gpointer *) &get_end_section_component_class_descriptor_attributes)) { | |
1636 | cc_descr_attrs_end = get_end_section_component_class_descriptor_attributes(); | |
1637 | } else { | |
3f7d4d90 | 1638 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1639 | "symbol=\"%s\"", path, |
52238017 | 1640 | "__bt_get_end_section_component_class_descriptor_attributes"); |
55bb57e0 PP |
1641 | } |
1642 | ||
1643 | if ((!!cc_descr_attrs_begin - !!cc_descr_attrs_end) != 0) { | |
870631a2 PP |
1644 | if (fail_on_load_error) { |
1645 | BT_LIB_LOGW_APPEND_CAUSE( | |
1646 | "Found section start or end symbol, but not both: " | |
1647 | "path=\"%s\", symbol-start=\"%s\", " | |
1648 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1649 | "symbol-end-addr=%p", | |
1650 | path, "__bt_get_begin_section_component_class_descriptor_attributes", | |
1651 | "__bt_get_end_section_component_class_descriptor_attributes", | |
1652 | cc_descr_attrs_begin, cc_descr_attrs_end); | |
1653 | status = BT_FUNC_STATUS_LOADING_ERROR; | |
1654 | } else { | |
a0cdfce8 | 1655 | BT_LIB_LOGW( |
870631a2 PP |
1656 | "Found section start or end symbol, but not both: " |
1657 | "path=\"%s\", symbol-start=\"%s\", " | |
1658 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1659 | "symbol-end-addr=%p", | |
1660 | path, "__bt_get_begin_section_component_class_descriptor_attributes", | |
1661 | "__bt_get_end_section_component_class_descriptor_attributes", | |
1662 | cc_descr_attrs_begin, cc_descr_attrs_end); | |
1663 | status = BT_FUNC_STATUS_NOT_FOUND; | |
1664 | } | |
1665 | ||
55bb57e0 PP |
1666 | goto end; |
1667 | } | |
1668 | ||
1669 | /* Initialize plugin */ | |
3fe0bf43 | 1670 | BT_LOGD_STR("Initializing plugin object."); |
9736d991 PP |
1671 | status = bt_plugin_so_create_all_from_sections(shared_lib_handle, |
1672 | fail_on_load_error, | |
55bb57e0 PP |
1673 | descriptors_begin, descriptors_end, attrs_begin, attrs_end, |
1674 | cc_descriptors_begin, cc_descriptors_end, | |
9736d991 | 1675 | cc_descr_attrs_begin, cc_descr_attrs_end, plugin_set_out); |
55bb57e0 PP |
1676 | |
1677 | end: | |
65300d60 | 1678 | BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle); |
9736d991 | 1679 | return status; |
55bb57e0 PP |
1680 | } |
1681 | ||
1682 | static | |
1683 | void plugin_comp_class_destroy_listener(struct bt_component_class *comp_class, | |
1684 | void *data) | |
1685 | { | |
bfa9a4be | 1686 | bt_list_del(&comp_class->node); |
65300d60 | 1687 | BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle); |
3f7d4d90 | 1688 | BT_LOGD("Component class destroyed: removed entry from list: " |
3fe0bf43 | 1689 | "comp-cls-addr=%p", comp_class); |
55bb57e0 PP |
1690 | } |
1691 | ||
3230ee6b | 1692 | void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin, |
55bb57e0 PP |
1693 | struct bt_component_class *comp_class) |
1694 | { | |
55bb57e0 PP |
1695 | struct bt_plugin_so_spec_data *spec = plugin->spec_data; |
1696 | ||
f6ccaed9 PP |
1697 | BT_ASSERT(plugin->spec_data); |
1698 | BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO); | |
55bb57e0 | 1699 | |
bfa9a4be | 1700 | bt_list_add(&comp_class->node, &component_class_list); |
398454ed PP |
1701 | comp_class->so_handle = spec->shared_lib_handle; |
1702 | bt_object_get_no_null_check(comp_class->so_handle); | |
55bb57e0 PP |
1703 | |
1704 | /* Add our custom destroy listener */ | |
3230ee6b | 1705 | bt_component_class_add_destroy_listener(comp_class, |
55bb57e0 | 1706 | plugin_comp_class_destroy_listener, NULL); |
55bb57e0 | 1707 | } |