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 { | |
be788861 | 291 | bt_component_class_source_get_supported_mip_versions_method get_supported_mip_versions; |
4175c1d5 | 292 | bt_component_class_source_initialize_method init; |
7b53201c PP |
293 | bt_component_class_source_finalize_method finalize; |
294 | bt_component_class_source_query_method query; | |
7b53201c | 295 | bt_component_class_source_output_port_connected_method output_port_connected; |
4175c1d5 | 296 | bt_component_class_source_message_iterator_initialize_method msg_iter_initialize; |
b09a5592 | 297 | bt_component_class_source_message_iterator_finalize_method msg_iter_finalize; |
15a52f66 PP |
298 | bt_component_class_source_message_iterator_seek_ns_from_origin_method msg_iter_seek_ns_from_origin; |
299 | bt_component_class_source_message_iterator_seek_beginning_method msg_iter_seek_beginning; | |
300 | bt_component_class_source_message_iterator_can_seek_ns_from_origin_method msg_iter_can_seek_ns_from_origin; | |
301 | bt_component_class_source_message_iterator_can_seek_beginning_method msg_iter_can_seek_beginning; | |
834e9996 PP |
302 | } source; |
303 | ||
304 | struct { | |
be788861 | 305 | bt_component_class_filter_get_supported_mip_versions_method get_supported_mip_versions; |
4175c1d5 | 306 | bt_component_class_filter_initialize_method init; |
7b53201c PP |
307 | bt_component_class_filter_finalize_method finalize; |
308 | bt_component_class_filter_query_method query; | |
7b53201c PP |
309 | bt_component_class_filter_input_port_connected_method input_port_connected; |
310 | bt_component_class_filter_output_port_connected_method output_port_connected; | |
4175c1d5 | 311 | bt_component_class_filter_message_iterator_initialize_method msg_iter_initialize; |
b09a5592 | 312 | bt_component_class_filter_message_iterator_finalize_method msg_iter_finalize; |
15a52f66 PP |
313 | bt_component_class_filter_message_iterator_seek_ns_from_origin_method msg_iter_seek_ns_from_origin; |
314 | bt_component_class_filter_message_iterator_seek_beginning_method msg_iter_seek_beginning; | |
315 | bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method msg_iter_can_seek_ns_from_origin; | |
316 | bt_component_class_filter_message_iterator_can_seek_beginning_method msg_iter_can_seek_beginning; | |
834e9996 PP |
317 | } filter; |
318 | ||
319 | struct { | |
be788861 | 320 | bt_component_class_sink_get_supported_mip_versions_method get_supported_mip_versions; |
4175c1d5 | 321 | bt_component_class_sink_initialize_method init; |
7b53201c PP |
322 | bt_component_class_sink_finalize_method finalize; |
323 | bt_component_class_sink_query_method query; | |
7b53201c | 324 | bt_component_class_sink_input_port_connected_method input_port_connected; |
1043fdea | 325 | bt_component_class_sink_graph_is_configured_method graph_is_configured; |
834e9996 PP |
326 | } sink; |
327 | } methods; | |
55bb57e0 PP |
328 | }; |
329 | ||
fb25b9e3 | 330 | int status = BT_FUNC_STATUS_OK; |
55bb57e0 PP |
331 | struct __bt_plugin_descriptor_attribute const * const *cur_attr_ptr; |
332 | struct __bt_plugin_component_class_descriptor const * const *cur_cc_descr_ptr; | |
333 | struct __bt_plugin_component_class_descriptor_attribute const * const *cur_cc_descr_attr_ptr; | |
334 | struct bt_plugin_so_spec_data *spec = plugin->spec_data; | |
335 | GArray *comp_class_full_descriptors; | |
336 | size_t i; | |
337 | int ret; | |
338 | ||
a684a357 | 339 | BT_LOGI("Initializing plugin object from descriptors found in sections: " |
3fe0bf43 PP |
340 | "plugin-addr=%p, plugin-path=\"%s\", " |
341 | "attrs-begin-addr=%p, attrs-end-addr=%p, " | |
342 | "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, " | |
343 | "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p", | |
344 | plugin, | |
345 | spec->shared_lib_handle->path ? | |
346 | spec->shared_lib_handle->path->str : NULL, | |
347 | attrs_begin, attrs_end, | |
348 | cc_descriptors_begin, cc_descriptors_end, | |
349 | cc_descr_attrs_begin, cc_descr_attrs_end); | |
55bb57e0 PP |
350 | comp_class_full_descriptors = g_array_new(FALSE, TRUE, |
351 | sizeof(struct comp_class_full_descriptor)); | |
352 | if (!comp_class_full_descriptors) { | |
a8f90e5d | 353 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray."); |
fb25b9e3 | 354 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
55bb57e0 PP |
355 | goto end; |
356 | } | |
357 | ||
358 | /* Set mandatory attributes */ | |
359 | spec->descriptor = descriptor; | |
360 | bt_plugin_set_name(plugin, descriptor->name); | |
361 | ||
362 | /* | |
363 | * Find and set optional attributes attached to this plugin | |
364 | * descriptor. | |
365 | */ | |
366 | for (cur_attr_ptr = attrs_begin; cur_attr_ptr != attrs_end; cur_attr_ptr++) { | |
367 | const struct __bt_plugin_descriptor_attribute *cur_attr = | |
368 | *cur_attr_ptr; | |
369 | ||
8e01f2d9 | 370 | if (!cur_attr) { |
be3c4e36 MJ |
371 | continue; |
372 | } | |
373 | ||
55bb57e0 PP |
374 | if (cur_attr->plugin_descriptor != descriptor) { |
375 | continue; | |
376 | } | |
377 | ||
378 | switch (cur_attr->type) { | |
379 | case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_INIT: | |
380 | spec->init = cur_attr->value.init; | |
381 | break; | |
382 | case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_EXIT: | |
383 | spec->shared_lib_handle->exit = cur_attr->value.exit; | |
384 | break; | |
385 | case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_AUTHOR: | |
386 | bt_plugin_set_author(plugin, cur_attr->value.author); | |
387 | break; | |
388 | case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_LICENSE: | |
389 | bt_plugin_set_license(plugin, cur_attr->value.license); | |
390 | break; | |
391 | case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION: | |
392 | bt_plugin_set_description(plugin, cur_attr->value.description); | |
393 | break; | |
394 | case BT_PLUGIN_DESCRIPTOR_ATTRIBUTE_TYPE_VERSION: | |
395 | bt_plugin_set_version(plugin, | |
396 | (unsigned int) cur_attr->value.version.major, | |
397 | (unsigned int) cur_attr->value.version.minor, | |
398 | (unsigned int) cur_attr->value.version.patch, | |
399 | cur_attr->value.version.extra); | |
400 | break; | |
401 | default: | |
01f50d54 | 402 | if (fail_on_load_error) { |
a8f90e5d PP |
403 | BT_LIB_LOGW_APPEND_CAUSE( |
404 | "Unknown plugin descriptor attribute: " | |
405 | "plugin-path=\"%s\", plugin-name=\"%s\", " | |
406 | "attr-type-name=\"%s\", attr-type-id=%d", | |
407 | spec->shared_lib_handle->path ? | |
408 | spec->shared_lib_handle->path->str : | |
409 | NULL, | |
410 | descriptor->name, cur_attr->type_name, | |
411 | cur_attr->type); | |
c24a8f3c | 412 | status = BT_FUNC_STATUS_ERROR; |
01f50d54 | 413 | goto end; |
a8f90e5d | 414 | } else { |
6b076590 | 415 | BT_LIB_LOGW( |
a8f90e5d PP |
416 | "Ignoring unknown plugin descriptor attribute: " |
417 | "plugin-path=\"%s\", plugin-name=\"%s\", " | |
418 | "attr-type-name=\"%s\", attr-type-id=%d", | |
419 | spec->shared_lib_handle->path ? | |
420 | spec->shared_lib_handle->path->str : | |
421 | NULL, | |
422 | descriptor->name, cur_attr->type_name, | |
423 | cur_attr->type); | |
01f50d54 PP |
424 | } |
425 | ||
55bb57e0 PP |
426 | break; |
427 | } | |
428 | } | |
429 | ||
430 | /* | |
431 | * Find component class descriptors attached to this plugin | |
432 | * descriptor and initialize corresponding full component class | |
433 | * descriptors in the array. | |
434 | */ | |
435 | for (cur_cc_descr_ptr = cc_descriptors_begin; cur_cc_descr_ptr != cc_descriptors_end; cur_cc_descr_ptr++) { | |
436 | const struct __bt_plugin_component_class_descriptor *cur_cc_descr = | |
437 | *cur_cc_descr_ptr; | |
438 | struct comp_class_full_descriptor full_descriptor = {0}; | |
439 | ||
8e01f2d9 | 440 | if (!cur_cc_descr) { |
be3c4e36 MJ |
441 | continue; |
442 | } | |
443 | ||
55bb57e0 PP |
444 | if (cur_cc_descr->plugin_descriptor != descriptor) { |
445 | continue; | |
446 | } | |
447 | ||
448 | full_descriptor.descriptor = cur_cc_descr; | |
449 | g_array_append_val(comp_class_full_descriptors, | |
450 | full_descriptor); | |
451 | } | |
452 | ||
453 | /* | |
454 | * Find component class descriptor attributes attached to this | |
455 | * plugin descriptor and update corresponding full component | |
456 | * class descriptors in the array. | |
457 | */ | |
458 | for (cur_cc_descr_attr_ptr = cc_descr_attrs_begin; cur_cc_descr_attr_ptr != cc_descr_attrs_end; cur_cc_descr_attr_ptr++) { | |
459 | const struct __bt_plugin_component_class_descriptor_attribute *cur_cc_descr_attr = | |
460 | *cur_cc_descr_attr_ptr; | |
834e9996 | 461 | enum bt_component_class_type cc_type; |
55bb57e0 | 462 | |
8e01f2d9 | 463 | if (!cur_cc_descr_attr) { |
be3c4e36 MJ |
464 | continue; |
465 | } | |
466 | ||
55bb57e0 PP |
467 | if (cur_cc_descr_attr->comp_class_descriptor->plugin_descriptor != |
468 | descriptor) { | |
469 | continue; | |
470 | } | |
471 | ||
834e9996 PP |
472 | cc_type = cur_cc_descr_attr->comp_class_descriptor->type; |
473 | ||
55bb57e0 PP |
474 | /* Find the corresponding component class descriptor entry */ |
475 | for (i = 0; i < comp_class_full_descriptors->len; i++) { | |
476 | struct comp_class_full_descriptor *cc_full_descr = | |
477 | &g_array_index(comp_class_full_descriptors, | |
478 | struct comp_class_full_descriptor, i); | |
479 | ||
834e9996 | 480 | if (cur_cc_descr_attr->comp_class_descriptor != |
55bb57e0 | 481 | cc_full_descr->descriptor) { |
834e9996 PP |
482 | continue; |
483 | } | |
484 | ||
485 | switch (cur_cc_descr_attr->type) { | |
486 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION: | |
487 | cc_full_descr->description = | |
488 | cur_cc_descr_attr->value.description; | |
489 | break; | |
490 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP: | |
491 | cc_full_descr->help = | |
492 | cur_cc_descr_attr->value.help; | |
493 | break; | |
be788861 PP |
494 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_GET_SUPPORTED_MIP_VERSIONS_METHOD: |
495 | switch (cc_type) { | |
496 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
497 | cc_full_descr->methods.source.get_supported_mip_versions = | |
498 | cur_cc_descr_attr->value.source_get_supported_mip_versions_method; | |
499 | break; | |
500 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
501 | cc_full_descr->methods.filter.get_supported_mip_versions = | |
502 | cur_cc_descr_attr->value.filter_get_supported_mip_versions_method; | |
503 | break; | |
504 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
505 | cc_full_descr->methods.sink.get_supported_mip_versions = | |
506 | cur_cc_descr_attr->value.sink_get_supported_mip_versions_method; | |
507 | break; | |
508 | default: | |
509 | abort(); | |
510 | } | |
511 | break; | |
4175c1d5 | 512 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INITIALIZE_METHOD: |
834e9996 PP |
513 | switch (cc_type) { |
514 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
515 | cc_full_descr->methods.source.init = | |
4175c1d5 | 516 | cur_cc_descr_attr->value.source_initialize_method; |
55bb57e0 | 517 | break; |
834e9996 PP |
518 | case BT_COMPONENT_CLASS_TYPE_FILTER: |
519 | cc_full_descr->methods.filter.init = | |
4175c1d5 | 520 | cur_cc_descr_attr->value.filter_initialize_method; |
279b3f15 | 521 | break; |
834e9996 PP |
522 | case BT_COMPONENT_CLASS_TYPE_SINK: |
523 | cc_full_descr->methods.sink.init = | |
4175c1d5 | 524 | cur_cc_descr_attr->value.sink_initialize_method; |
55bb57e0 | 525 | break; |
834e9996 PP |
526 | default: |
527 | abort(); | |
528 | } | |
529 | break; | |
530 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD: | |
531 | switch (cc_type) { | |
532 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
533 | cc_full_descr->methods.source.finalize = | |
534 | cur_cc_descr_attr->value.source_finalize_method; | |
55bb57e0 | 535 | break; |
834e9996 PP |
536 | case BT_COMPONENT_CLASS_TYPE_FILTER: |
537 | cc_full_descr->methods.filter.finalize = | |
538 | cur_cc_descr_attr->value.filter_finalize_method; | |
8463eac2 | 539 | break; |
834e9996 PP |
540 | case BT_COMPONENT_CLASS_TYPE_SINK: |
541 | cc_full_descr->methods.sink.finalize = | |
542 | cur_cc_descr_attr->value.sink_finalize_method; | |
72b913fb | 543 | break; |
834e9996 PP |
544 | default: |
545 | abort(); | |
546 | } | |
547 | break; | |
548 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD: | |
549 | switch (cc_type) { | |
550 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
551 | cc_full_descr->methods.source.query = | |
552 | cur_cc_descr_attr->value.source_query_method; | |
0d8b4d8e | 553 | break; |
834e9996 PP |
554 | case BT_COMPONENT_CLASS_TYPE_FILTER: |
555 | cc_full_descr->methods.filter.query = | |
556 | cur_cc_descr_attr->value.filter_query_method; | |
55bb57e0 | 557 | break; |
834e9996 PP |
558 | case BT_COMPONENT_CLASS_TYPE_SINK: |
559 | cc_full_descr->methods.sink.query = | |
560 | cur_cc_descr_attr->value.sink_query_method; | |
55bb57e0 | 561 | break; |
834e9996 PP |
562 | default: |
563 | abort(); | |
564 | } | |
565 | break; | |
834e9996 PP |
566 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD: |
567 | switch (cc_type) { | |
568 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
569 | cc_full_descr->methods.filter.input_port_connected = | |
570 | cur_cc_descr_attr->value.filter_input_port_connected_method; | |
571 | break; | |
572 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
573 | cc_full_descr->methods.sink.input_port_connected = | |
574 | cur_cc_descr_attr->value.sink_input_port_connected_method; | |
55bb57e0 | 575 | break; |
55bb57e0 | 576 | default: |
834e9996 PP |
577 | abort(); |
578 | } | |
579 | break; | |
580 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD: | |
581 | switch (cc_type) { | |
582 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
583 | cc_full_descr->methods.source.output_port_connected = | |
584 | cur_cc_descr_attr->value.source_output_port_connected_method; | |
585 | break; | |
586 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
587 | cc_full_descr->methods.filter.output_port_connected = | |
588 | cur_cc_descr_attr->value.filter_output_port_connected_method; | |
55bb57e0 | 589 | break; |
834e9996 PP |
590 | default: |
591 | abort(); | |
55bb57e0 | 592 | } |
834e9996 | 593 | break; |
1043fdea PP |
594 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_GRAPH_IS_CONFIGURED_METHOD: |
595 | switch (cc_type) { | |
596 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
597 | cc_full_descr->methods.sink.graph_is_configured = | |
598 | cur_cc_descr_attr->value.sink_graph_is_configured_method; | |
599 | break; | |
600 | default: | |
601 | abort(); | |
602 | } | |
603 | break; | |
4175c1d5 | 604 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INITIALIZE_METHOD: |
834e9996 PP |
605 | switch (cc_type) { |
606 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
4175c1d5 FD |
607 | cc_full_descr->methods.source.msg_iter_initialize = |
608 | cur_cc_descr_attr->value.source_msg_iter_initialize_method; | |
834e9996 PP |
609 | break; |
610 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
4175c1d5 FD |
611 | cc_full_descr->methods.filter.msg_iter_initialize = |
612 | cur_cc_descr_attr->value.filter_msg_iter_initialize_method; | |
834e9996 PP |
613 | break; |
614 | default: | |
615 | abort(); | |
616 | } | |
617 | break; | |
b09a5592 | 618 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_FINALIZE_METHOD: |
834e9996 PP |
619 | switch (cc_type) { |
620 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
b09a5592 PP |
621 | cc_full_descr->methods.source.msg_iter_finalize = |
622 | cur_cc_descr_attr->value.source_msg_iter_finalize_method; | |
834e9996 PP |
623 | break; |
624 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
b09a5592 PP |
625 | cc_full_descr->methods.filter.msg_iter_finalize = |
626 | cur_cc_descr_attr->value.filter_msg_iter_finalize_method; | |
834e9996 PP |
627 | break; |
628 | default: | |
629 | abort(); | |
630 | } | |
631 | break; | |
15a52f66 PP |
632 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_NS_FROM_ORIGIN_METHOD: |
633 | switch (cc_type) { | |
634 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
635 | cc_full_descr->methods.source.msg_iter_seek_ns_from_origin = | |
636 | cur_cc_descr_attr->value.source_msg_iter_seek_ns_from_origin_method; | |
637 | break; | |
638 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
639 | cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin = | |
640 | cur_cc_descr_attr->value.filter_msg_iter_seek_ns_from_origin_method; | |
641 | break; | |
642 | default: | |
643 | abort(); | |
644 | } | |
645 | break; | |
646 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_BEGINNING_METHOD: | |
647 | switch (cc_type) { | |
648 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
649 | cc_full_descr->methods.source.msg_iter_seek_beginning = | |
650 | cur_cc_descr_attr->value.source_msg_iter_seek_beginning_method; | |
651 | break; | |
652 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
653 | cc_full_descr->methods.filter.msg_iter_seek_beginning = | |
654 | cur_cc_descr_attr->value.filter_msg_iter_seek_beginning_method; | |
655 | break; | |
656 | default: | |
657 | abort(); | |
658 | } | |
659 | break; | |
660 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_NS_FROM_ORIGIN_METHOD: | |
661 | switch (cc_type) { | |
662 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
663 | cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin = | |
664 | cur_cc_descr_attr->value.source_msg_iter_can_seek_ns_from_origin_method; | |
665 | break; | |
666 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
667 | cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin = | |
668 | cur_cc_descr_attr->value.filter_msg_iter_can_seek_ns_from_origin_method; | |
669 | break; | |
670 | default: | |
671 | abort(); | |
672 | } | |
673 | break; | |
674 | case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_BEGINNING_METHOD: | |
675 | switch (cc_type) { | |
676 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
677 | cc_full_descr->methods.source.msg_iter_can_seek_beginning = | |
678 | cur_cc_descr_attr->value.source_msg_iter_can_seek_beginning_method; | |
679 | break; | |
680 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
681 | cc_full_descr->methods.filter.msg_iter_can_seek_beginning = | |
682 | cur_cc_descr_attr->value.filter_msg_iter_can_seek_beginning_method; | |
683 | break; | |
684 | default: | |
685 | abort(); | |
686 | } | |
687 | break; | |
834e9996 | 688 | default: |
01f50d54 | 689 | if (fail_on_load_error) { |
a8f90e5d PP |
690 | BT_LIB_LOGW_APPEND_CAUSE( |
691 | "Unknown component class descriptor attribute: " | |
692 | "plugin-path=\"%s\", " | |
693 | "plugin-name=\"%s\", " | |
694 | "comp-class-name=\"%s\", " | |
695 | "comp-class-type=%s, " | |
696 | "attr-type-name=\"%s\", " | |
697 | "attr-type-id=%d", | |
698 | spec->shared_lib_handle->path ? | |
699 | spec->shared_lib_handle->path->str : | |
700 | NULL, | |
701 | descriptor->name, | |
702 | cur_cc_descr_attr->comp_class_descriptor->name, | |
703 | bt_component_class_type_string( | |
704 | cur_cc_descr_attr->comp_class_descriptor->type), | |
705 | cur_cc_descr_attr->type_name, | |
706 | cur_cc_descr_attr->type); | |
c24a8f3c | 707 | status = BT_FUNC_STATUS_ERROR; |
01f50d54 | 708 | goto end; |
a8f90e5d | 709 | } else { |
6b076590 | 710 | BT_LIB_LOGW( |
a8f90e5d PP |
711 | "Ignoring unknown component class descriptor attribute: " |
712 | "plugin-path=\"%s\", " | |
713 | "plugin-name=\"%s\", " | |
714 | "comp-class-name=\"%s\", " | |
715 | "comp-class-type=%s, " | |
716 | "attr-type-name=\"%s\", " | |
717 | "attr-type-id=%d", | |
718 | spec->shared_lib_handle->path ? | |
719 | spec->shared_lib_handle->path->str : | |
720 | NULL, | |
721 | descriptor->name, | |
722 | cur_cc_descr_attr->comp_class_descriptor->name, | |
723 | bt_component_class_type_string( | |
724 | cur_cc_descr_attr->comp_class_descriptor->type), | |
725 | cur_cc_descr_attr->type_name, | |
726 | cur_cc_descr_attr->type); | |
01f50d54 PP |
727 | } |
728 | ||
834e9996 | 729 | break; |
55bb57e0 PP |
730 | } |
731 | } | |
732 | } | |
733 | ||
734 | /* Initialize plugin */ | |
735 | if (spec->init) { | |
4175c1d5 | 736 | enum bt_plugin_initialize_func_status init_status; |
c8750769 | 737 | |
3fe0bf43 | 738 | BT_LOGD_STR("Calling user's plugin initialization function."); |
c8750769 | 739 | init_status = spec->init((void *) plugin); |
01f50d54 | 740 | BT_LOGD("User function returned: status=%s", |
fb25b9e3 | 741 | bt_common_func_status_string(init_status)); |
3fe0bf43 | 742 | |
0ae03127 | 743 | if (init_status < 0) { |
01f50d54 | 744 | if (fail_on_load_error) { |
a8f90e5d PP |
745 | BT_LIB_LOGW_APPEND_CAUSE( |
746 | "User's plugin initialization function failed: " | |
747 | "status=%s", | |
748 | bt_common_func_status_string(init_status)); | |
fb25b9e3 | 749 | status = init_status; |
01f50d54 | 750 | goto end; |
a8f90e5d | 751 | } else { |
6b076590 | 752 | BT_LIB_LOGW( |
a8f90e5d PP |
753 | "User's plugin initialization function failed: " |
754 | "status=%s", | |
755 | bt_common_func_status_string(init_status)); | |
756 | status = BT_FUNC_STATUS_NOT_FOUND; | |
01f50d54 | 757 | } |
a8f90e5d PP |
758 | |
759 | goto end; | |
55bb57e0 PP |
760 | } |
761 | } | |
762 | ||
c55a9f58 | 763 | spec->shared_lib_handle->init_called = BT_TRUE; |
55bb57e0 PP |
764 | |
765 | /* Add described component classes to plugin */ | |
766 | for (i = 0; i < comp_class_full_descriptors->len; i++) { | |
767 | struct comp_class_full_descriptor *cc_full_descr = | |
768 | &g_array_index(comp_class_full_descriptors, | |
769 | struct comp_class_full_descriptor, i); | |
7b53201c PP |
770 | struct bt_component_class *comp_class = NULL; |
771 | struct bt_component_class_source *src_comp_class = NULL; | |
772 | struct bt_component_class_filter *flt_comp_class = NULL; | |
773 | struct bt_component_class_sink *sink_comp_class = NULL; | |
55bb57e0 | 774 | |
a684a357 | 775 | BT_LOGI("Creating and setting properties of plugin's component class: " |
3fe0bf43 PP |
776 | "plugin-path=\"%s\", plugin-name=\"%s\", " |
777 | "comp-class-name=\"%s\", comp-class-type=%s", | |
778 | spec->shared_lib_handle->path ? | |
779 | spec->shared_lib_handle->path->str : | |
780 | NULL, | |
781 | descriptor->name, | |
782 | cc_full_descr->descriptor->name, | |
783 | bt_component_class_type_string( | |
784 | cc_full_descr->descriptor->type)); | |
785 | ||
55bb57e0 PP |
786 | switch (cc_full_descr->descriptor->type) { |
787 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
7b53201c | 788 | src_comp_class = bt_component_class_source_create( |
55bb57e0 | 789 | cc_full_descr->descriptor->name, |
b09a5592 | 790 | cc_full_descr->descriptor->methods.source.msg_iter_next); |
7b53201c | 791 | comp_class = bt_component_class_source_as_component_class( |
834e9996 | 792 | src_comp_class); |
55bb57e0 PP |
793 | break; |
794 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
7b53201c | 795 | flt_comp_class = bt_component_class_filter_create( |
55bb57e0 | 796 | cc_full_descr->descriptor->name, |
b09a5592 | 797 | cc_full_descr->descriptor->methods.source.msg_iter_next); |
7b53201c | 798 | comp_class = bt_component_class_filter_as_component_class( |
834e9996 | 799 | flt_comp_class); |
55bb57e0 PP |
800 | break; |
801 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
7b53201c | 802 | sink_comp_class = bt_component_class_sink_create( |
55bb57e0 PP |
803 | cc_full_descr->descriptor->name, |
804 | cc_full_descr->descriptor->methods.sink.consume); | |
7b53201c | 805 | comp_class = bt_component_class_sink_as_component_class( |
834e9996 | 806 | sink_comp_class); |
55bb57e0 PP |
807 | break; |
808 | default: | |
01f50d54 | 809 | if (fail_on_load_error) { |
a8f90e5d PP |
810 | BT_LIB_LOGW_APPEND_CAUSE( |
811 | "Unknown component class type: " | |
812 | "plugin-path=\"%s\", plugin-name=\"%s\", " | |
813 | "comp-class-name=\"%s\", comp-class-type=%d", | |
814 | spec->shared_lib_handle->path->str ? | |
815 | spec->shared_lib_handle->path->str : | |
816 | NULL, | |
817 | descriptor->name, | |
818 | cc_full_descr->descriptor->name, | |
819 | cc_full_descr->descriptor->type); | |
c24a8f3c | 820 | status = BT_FUNC_STATUS_ERROR; |
01f50d54 | 821 | goto end; |
a8f90e5d | 822 | } else { |
6b076590 | 823 | BT_LIB_LOGW( |
a8f90e5d PP |
824 | "Ignoring unknown component class type: " |
825 | "plugin-path=\"%s\", plugin-name=\"%s\", " | |
826 | "comp-class-name=\"%s\", comp-class-type=%d", | |
827 | spec->shared_lib_handle->path->str ? | |
828 | spec->shared_lib_handle->path->str : | |
829 | NULL, | |
830 | descriptor->name, | |
831 | cc_full_descr->descriptor->name, | |
832 | cc_full_descr->descriptor->type); | |
833 | continue; | |
01f50d54 | 834 | } |
55bb57e0 PP |
835 | } |
836 | ||
837 | if (!comp_class) { | |
a8f90e5d PP |
838 | BT_LIB_LOGE_APPEND_CAUSE( |
839 | "Cannot create component class."); | |
fb25b9e3 | 840 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
55bb57e0 PP |
841 | goto end; |
842 | } | |
843 | ||
844 | if (cc_full_descr->description) { | |
7b53201c | 845 | ret = bt_component_class_set_description( |
834e9996 | 846 | comp_class, cc_full_descr->description); |
55bb57e0 | 847 | if (ret) { |
a8f90e5d PP |
848 | BT_LIB_LOGE_APPEND_CAUSE( |
849 | "Cannot set component class's description."); | |
fb25b9e3 | 850 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
8138bfe1 | 851 | BT_OBJECT_PUT_REF_AND_RESET(comp_class); |
55bb57e0 PP |
852 | goto end; |
853 | } | |
854 | } | |
855 | ||
279b3f15 | 856 | if (cc_full_descr->help) { |
7b53201c | 857 | ret = bt_component_class_set_help(comp_class, |
279b3f15 PP |
858 | cc_full_descr->help); |
859 | if (ret) { | |
a8f90e5d PP |
860 | BT_LIB_LOGE_APPEND_CAUSE( |
861 | "Cannot set component class's help string."); | |
fb25b9e3 | 862 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
8138bfe1 | 863 | BT_OBJECT_PUT_REF_AND_RESET(comp_class); |
279b3f15 PP |
864 | goto end; |
865 | } | |
866 | } | |
867 | ||
834e9996 PP |
868 | switch (cc_full_descr->descriptor->type) { |
869 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
be788861 PP |
870 | if (cc_full_descr->methods.source.get_supported_mip_versions) { |
871 | ret = bt_component_class_source_set_get_supported_mip_versions_method( | |
872 | src_comp_class, | |
873 | cc_full_descr->methods.source.get_supported_mip_versions); | |
874 | if (ret) { | |
875 | BT_LIB_LOGE_APPEND_CAUSE( | |
876 | "Cannot set source component class's \"get supported MIP versions\" method."); | |
877 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
878 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); | |
879 | goto end; | |
880 | } | |
881 | } | |
882 | ||
834e9996 | 883 | if (cc_full_descr->methods.source.init) { |
4175c1d5 | 884 | ret = bt_component_class_source_set_initialize_method( |
834e9996 PP |
885 | src_comp_class, |
886 | cc_full_descr->methods.source.init); | |
887 | if (ret) { | |
a8f90e5d PP |
888 | BT_LIB_LOGE_APPEND_CAUSE( |
889 | "Cannot set source component class's initialization method."); | |
fb25b9e3 | 890 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
891 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
892 | goto end; | |
893 | } | |
55bb57e0 | 894 | } |
55bb57e0 | 895 | |
834e9996 | 896 | if (cc_full_descr->methods.source.finalize) { |
7b53201c | 897 | ret = bt_component_class_source_set_finalize_method( |
834e9996 PP |
898 | src_comp_class, |
899 | cc_full_descr->methods.source.finalize); | |
900 | if (ret) { | |
a8f90e5d PP |
901 | BT_LIB_LOGE_APPEND_CAUSE( |
902 | "Cannot set source component class's finalization method."); | |
fb25b9e3 | 903 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
904 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
905 | goto end; | |
906 | } | |
55bb57e0 | 907 | } |
55bb57e0 | 908 | |
834e9996 | 909 | if (cc_full_descr->methods.source.query) { |
7b53201c | 910 | ret = bt_component_class_source_set_query_method( |
834e9996 PP |
911 | src_comp_class, |
912 | cc_full_descr->methods.source.query); | |
913 | if (ret) { | |
a8f90e5d PP |
914 | BT_LIB_LOGE_APPEND_CAUSE( |
915 | "Cannot set source component class's query method."); | |
fb25b9e3 | 916 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
917 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
918 | goto end; | |
919 | } | |
8463eac2 | 920 | } |
8463eac2 | 921 | |
834e9996 | 922 | if (cc_full_descr->methods.source.output_port_connected) { |
7b53201c | 923 | ret = bt_component_class_source_set_output_port_connected_method( |
834e9996 PP |
924 | src_comp_class, |
925 | cc_full_descr->methods.source.output_port_connected); | |
926 | if (ret) { | |
a8f90e5d PP |
927 | BT_LIB_LOGE_APPEND_CAUSE( |
928 | "Cannot set source component class's \"output port connected\" method."); | |
fb25b9e3 | 929 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
930 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
931 | goto end; | |
932 | } | |
0d8b4d8e | 933 | } |
0d8b4d8e | 934 | |
4175c1d5 FD |
935 | if (cc_full_descr->methods.source.msg_iter_initialize) { |
936 | ret = bt_component_class_source_set_message_iterator_initialize_method( | |
834e9996 | 937 | src_comp_class, |
4175c1d5 | 938 | cc_full_descr->methods.source.msg_iter_initialize); |
55bb57e0 | 939 | if (ret) { |
a8f90e5d PP |
940 | BT_LIB_LOGE_APPEND_CAUSE( |
941 | "Cannot set source component class's message iterator initialization method."); | |
fb25b9e3 | 942 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 | 943 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
55bb57e0 PP |
944 | goto end; |
945 | } | |
946 | } | |
947 | ||
b09a5592 PP |
948 | if (cc_full_descr->methods.source.msg_iter_finalize) { |
949 | ret = bt_component_class_source_set_message_iterator_finalize_method( | |
834e9996 | 950 | src_comp_class, |
b09a5592 | 951 | cc_full_descr->methods.source.msg_iter_finalize); |
55bb57e0 | 952 | if (ret) { |
a8f90e5d PP |
953 | BT_LIB_LOGE_APPEND_CAUSE( |
954 | "Cannot set source component class's message iterator finalization method."); | |
fb25b9e3 | 955 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 | 956 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
55bb57e0 PP |
957 | goto end; |
958 | } | |
959 | } | |
834e9996 | 960 | |
15a52f66 PP |
961 | if (cc_full_descr->methods.source.msg_iter_seek_ns_from_origin) { |
962 | ret = bt_component_class_source_set_message_iterator_seek_ns_from_origin_method( | |
963 | src_comp_class, | |
964 | cc_full_descr->methods.source.msg_iter_seek_ns_from_origin); | |
965 | if (ret) { | |
a8f90e5d PP |
966 | BT_LIB_LOGE_APPEND_CAUSE( |
967 | "Cannot set source component class's message iterator \"seek nanoseconds from origin\" method."); | |
fb25b9e3 | 968 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
15a52f66 PP |
969 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
970 | goto end; | |
971 | } | |
972 | } | |
973 | ||
974 | if (cc_full_descr->methods.source.msg_iter_seek_beginning) { | |
975 | ret = bt_component_class_source_set_message_iterator_seek_beginning_method( | |
976 | src_comp_class, | |
977 | cc_full_descr->methods.source.msg_iter_seek_beginning); | |
978 | if (ret) { | |
a8f90e5d PP |
979 | BT_LIB_LOGE_APPEND_CAUSE( |
980 | "Cannot set source component class's message iterator \"seek beginning\" method."); | |
fb25b9e3 | 981 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
15a52f66 PP |
982 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
983 | goto end; | |
984 | } | |
985 | } | |
986 | ||
987 | if (cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin) { | |
988 | ret = bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method( | |
989 | src_comp_class, | |
990 | cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin); | |
991 | if (ret) { | |
a8f90e5d PP |
992 | BT_LIB_LOGE_APPEND_CAUSE( |
993 | "Cannot set source component class's message iterator \"can seek nanoseconds from origin\" method."); | |
fb25b9e3 | 994 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
15a52f66 PP |
995 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
996 | goto end; | |
997 | } | |
998 | } | |
999 | ||
1000 | if (cc_full_descr->methods.source.msg_iter_can_seek_beginning) { | |
1001 | ret = bt_component_class_source_set_message_iterator_can_seek_beginning_method( | |
1002 | src_comp_class, | |
1003 | cc_full_descr->methods.source.msg_iter_can_seek_beginning); | |
1004 | if (ret) { | |
a8f90e5d PP |
1005 | BT_LIB_LOGE_APPEND_CAUSE( |
1006 | "Cannot set source component class's message iterator \"can seek beginning\" method."); | |
fb25b9e3 | 1007 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
15a52f66 PP |
1008 | BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); |
1009 | goto end; | |
1010 | } | |
1011 | } | |
1012 | ||
55bb57e0 PP |
1013 | break; |
1014 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
be788861 PP |
1015 | if (cc_full_descr->methods.filter.get_supported_mip_versions) { |
1016 | ret = bt_component_class_filter_set_get_supported_mip_versions_method( | |
1017 | flt_comp_class, | |
1018 | cc_full_descr->methods.filter.get_supported_mip_versions); | |
1019 | if (ret) { | |
1020 | BT_LIB_LOGE_APPEND_CAUSE( | |
1021 | "Cannot set filter component class's \"get supported MIP versions\" method."); | |
1022 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
1023 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); | |
1024 | goto end; | |
1025 | } | |
1026 | } | |
1027 | ||
834e9996 | 1028 | if (cc_full_descr->methods.filter.init) { |
4175c1d5 | 1029 | ret = bt_component_class_filter_set_initialize_method( |
834e9996 PP |
1030 | flt_comp_class, |
1031 | cc_full_descr->methods.filter.init); | |
1032 | if (ret) { | |
a8f90e5d PP |
1033 | BT_LIB_LOGE_APPEND_CAUSE( |
1034 | "Cannot set filter component class's initialization method."); | |
fb25b9e3 | 1035 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1036 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1037 | goto end; | |
1038 | } | |
1039 | } | |
1040 | ||
1041 | if (cc_full_descr->methods.filter.finalize) { | |
7b53201c | 1042 | ret = bt_component_class_filter_set_finalize_method( |
834e9996 PP |
1043 | flt_comp_class, |
1044 | cc_full_descr->methods.filter.finalize); | |
1045 | if (ret) { | |
a8f90e5d PP |
1046 | BT_LIB_LOGE_APPEND_CAUSE( |
1047 | "Cannot set filter component class's finalization method."); | |
fb25b9e3 | 1048 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1049 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1050 | goto end; | |
1051 | } | |
1052 | } | |
1053 | ||
1054 | if (cc_full_descr->methods.filter.query) { | |
7b53201c | 1055 | ret = bt_component_class_filter_set_query_method( |
834e9996 PP |
1056 | flt_comp_class, |
1057 | cc_full_descr->methods.filter.query); | |
1058 | if (ret) { | |
a8f90e5d PP |
1059 | BT_LIB_LOGE_APPEND_CAUSE( |
1060 | "Cannot set filter component class's query method."); | |
fb25b9e3 | 1061 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1062 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1063 | goto end; | |
1064 | } | |
1065 | } | |
1066 | ||
834e9996 | 1067 | if (cc_full_descr->methods.filter.input_port_connected) { |
7b53201c | 1068 | ret = bt_component_class_filter_set_input_port_connected_method( |
834e9996 PP |
1069 | flt_comp_class, |
1070 | cc_full_descr->methods.filter.input_port_connected); | |
1071 | if (ret) { | |
a8f90e5d PP |
1072 | BT_LIB_LOGE_APPEND_CAUSE( |
1073 | "Cannot set filter component class's \"input port connected\" method."); | |
fb25b9e3 | 1074 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1075 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1076 | goto end; | |
1077 | } | |
1078 | } | |
1079 | ||
1080 | if (cc_full_descr->methods.filter.output_port_connected) { | |
7b53201c | 1081 | ret = bt_component_class_filter_set_output_port_connected_method( |
834e9996 PP |
1082 | flt_comp_class, |
1083 | cc_full_descr->methods.filter.output_port_connected); | |
1084 | if (ret) { | |
a8f90e5d PP |
1085 | BT_LIB_LOGE_APPEND_CAUSE( |
1086 | "Cannot set filter component class's \"output port connected\" method."); | |
fb25b9e3 | 1087 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1088 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1089 | goto end; | |
1090 | } | |
1091 | } | |
1092 | ||
4175c1d5 FD |
1093 | if (cc_full_descr->methods.filter.msg_iter_initialize) { |
1094 | ret = bt_component_class_filter_set_message_iterator_initialize_method( | |
834e9996 | 1095 | flt_comp_class, |
4175c1d5 | 1096 | cc_full_descr->methods.filter.msg_iter_initialize); |
55bb57e0 | 1097 | if (ret) { |
a8f90e5d PP |
1098 | BT_LIB_LOGE_APPEND_CAUSE( |
1099 | "Cannot set filter component class's message iterator initialization method."); | |
fb25b9e3 | 1100 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 | 1101 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
55bb57e0 PP |
1102 | goto end; |
1103 | } | |
1104 | } | |
1105 | ||
b09a5592 PP |
1106 | if (cc_full_descr->methods.filter.msg_iter_finalize) { |
1107 | ret = bt_component_class_filter_set_message_iterator_finalize_method( | |
834e9996 | 1108 | flt_comp_class, |
b09a5592 | 1109 | cc_full_descr->methods.filter.msg_iter_finalize); |
55bb57e0 | 1110 | if (ret) { |
a8f90e5d PP |
1111 | BT_LIB_LOGE_APPEND_CAUSE( |
1112 | "Cannot set filter component class's message iterator finalization method."); | |
fb25b9e3 | 1113 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 | 1114 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
55bb57e0 PP |
1115 | goto end; |
1116 | } | |
1117 | } | |
834e9996 | 1118 | |
15a52f66 PP |
1119 | if (cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin) { |
1120 | ret = bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method( | |
1121 | flt_comp_class, | |
1122 | cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin); | |
1123 | if (ret) { | |
a8f90e5d PP |
1124 | BT_LIB_LOGE_APPEND_CAUSE( |
1125 | "Cannot set filter component class's message iterator \"seek nanoseconds from origin\" method."); | |
fb25b9e3 | 1126 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
15a52f66 PP |
1127 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1128 | goto end; | |
1129 | } | |
1130 | } | |
1131 | ||
1132 | if (cc_full_descr->methods.filter.msg_iter_seek_beginning) { | |
1133 | ret = bt_component_class_filter_set_message_iterator_seek_beginning_method( | |
1134 | flt_comp_class, | |
1135 | cc_full_descr->methods.filter.msg_iter_seek_beginning); | |
1136 | if (ret) { | |
a8f90e5d PP |
1137 | BT_LIB_LOGE_APPEND_CAUSE( |
1138 | "Cannot set filter component class's message iterator \"seek beginning\" method."); | |
fb25b9e3 | 1139 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
15a52f66 PP |
1140 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1141 | goto end; | |
1142 | } | |
1143 | } | |
1144 | ||
1145 | if (cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin) { | |
1146 | ret = bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method( | |
1147 | flt_comp_class, | |
1148 | cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin); | |
1149 | if (ret) { | |
a8f90e5d PP |
1150 | BT_LIB_LOGE_APPEND_CAUSE( |
1151 | "Cannot set filter component class's message iterator \"can seek nanoseconds from origin\" method."); | |
fb25b9e3 | 1152 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
15a52f66 PP |
1153 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1154 | goto end; | |
1155 | } | |
1156 | } | |
1157 | ||
1158 | if (cc_full_descr->methods.filter.msg_iter_can_seek_beginning) { | |
1159 | ret = bt_component_class_filter_set_message_iterator_can_seek_beginning_method( | |
1160 | flt_comp_class, | |
1161 | cc_full_descr->methods.filter.msg_iter_can_seek_beginning); | |
1162 | if (ret) { | |
a8f90e5d PP |
1163 | BT_LIB_LOGE_APPEND_CAUSE( |
1164 | "Cannot set filter component class's message iterator \"can seek beginning\" method."); | |
fb25b9e3 | 1165 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
15a52f66 PP |
1166 | BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); |
1167 | goto end; | |
1168 | } | |
1169 | } | |
1170 | ||
55bb57e0 PP |
1171 | break; |
1172 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
be788861 PP |
1173 | if (cc_full_descr->methods.sink.get_supported_mip_versions) { |
1174 | ret = bt_component_class_sink_set_get_supported_mip_versions_method( | |
1175 | sink_comp_class, | |
1176 | cc_full_descr->methods.sink.get_supported_mip_versions); | |
1177 | if (ret) { | |
1178 | BT_LIB_LOGE_APPEND_CAUSE( | |
1179 | "Cannot set sink component class's \"get supported MIP versions\" method."); | |
1180 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
1181 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); | |
1182 | goto end; | |
1183 | } | |
1184 | } | |
1185 | ||
834e9996 | 1186 | if (cc_full_descr->methods.sink.init) { |
4175c1d5 | 1187 | ret = bt_component_class_sink_set_initialize_method( |
834e9996 PP |
1188 | sink_comp_class, |
1189 | cc_full_descr->methods.sink.init); | |
1190 | if (ret) { | |
a8f90e5d PP |
1191 | BT_LIB_LOGE_APPEND_CAUSE( |
1192 | "Cannot set sink component class's initialization method."); | |
fb25b9e3 | 1193 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1194 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1195 | goto end; | |
1196 | } | |
1197 | } | |
1198 | ||
1199 | if (cc_full_descr->methods.sink.finalize) { | |
7b53201c | 1200 | ret = bt_component_class_sink_set_finalize_method( |
834e9996 PP |
1201 | sink_comp_class, |
1202 | cc_full_descr->methods.sink.finalize); | |
1203 | if (ret) { | |
a8f90e5d PP |
1204 | BT_LIB_LOGE_APPEND_CAUSE( |
1205 | "Cannot set sink component class's finalization method."); | |
fb25b9e3 | 1206 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1207 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1208 | goto end; | |
1209 | } | |
1210 | } | |
1211 | ||
1212 | if (cc_full_descr->methods.sink.query) { | |
7b53201c | 1213 | ret = bt_component_class_sink_set_query_method( |
834e9996 PP |
1214 | sink_comp_class, |
1215 | cc_full_descr->methods.sink.query); | |
1216 | if (ret) { | |
a8f90e5d PP |
1217 | BT_LIB_LOGE_APPEND_CAUSE( |
1218 | "Cannot set sink component class's query method."); | |
fb25b9e3 | 1219 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1220 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1221 | goto end; | |
1222 | } | |
1223 | } | |
1224 | ||
834e9996 | 1225 | if (cc_full_descr->methods.sink.input_port_connected) { |
7b53201c | 1226 | ret = bt_component_class_sink_set_input_port_connected_method( |
834e9996 PP |
1227 | sink_comp_class, |
1228 | cc_full_descr->methods.sink.input_port_connected); | |
1229 | if (ret) { | |
a8f90e5d PP |
1230 | BT_LIB_LOGE_APPEND_CAUSE( |
1231 | "Cannot set sink component class's \"input port connected\" method."); | |
fb25b9e3 | 1232 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
834e9996 PP |
1233 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1234 | goto end; | |
1235 | } | |
1236 | } | |
1237 | ||
1043fdea PP |
1238 | if (cc_full_descr->methods.sink.graph_is_configured) { |
1239 | ret = bt_component_class_sink_set_graph_is_configured_method( | |
1240 | sink_comp_class, | |
1241 | cc_full_descr->methods.sink.graph_is_configured); | |
1242 | if (ret) { | |
a8f90e5d PP |
1243 | BT_LIB_LOGE_APPEND_CAUSE( |
1244 | "Cannot set sink component class's \"graph is configured\" method."); | |
fb25b9e3 | 1245 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
1043fdea PP |
1246 | BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); |
1247 | goto end; | |
1248 | } | |
1249 | } | |
1250 | ||
55bb57e0 PP |
1251 | break; |
1252 | default: | |
0fbb9a9f | 1253 | abort(); |
55bb57e0 PP |
1254 | } |
1255 | ||
1256 | /* | |
1257 | * Add component class to the plugin object. | |
1258 | * | |
1259 | * This will call back | |
1260 | * bt_plugin_so_on_add_component_class() so that we can | |
834e9996 PP |
1261 | * add a mapping in the component class list when we |
1262 | * know the component class is successfully added. | |
55bb57e0 PP |
1263 | */ |
1264 | status = bt_plugin_add_component_class(plugin, | |
834e9996 | 1265 | (void *) comp_class); |
8138bfe1 | 1266 | BT_OBJECT_PUT_REF_AND_RESET(comp_class); |
55bb57e0 | 1267 | if (status < 0) { |
a8f90e5d PP |
1268 | BT_LIB_LOGE_APPEND_CAUSE( |
1269 | "Cannot add component class to plugin."); | |
55bb57e0 PP |
1270 | goto end; |
1271 | } | |
1272 | } | |
1273 | ||
55bb57e0 PP |
1274 | end: |
1275 | g_array_free(comp_class_full_descriptors, TRUE); | |
1276 | return status; | |
1277 | } | |
1278 | ||
1279 | static | |
1280 | struct bt_plugin *bt_plugin_so_create_empty( | |
1281 | struct bt_plugin_so_shared_lib_handle *shared_lib_handle) | |
1282 | { | |
1283 | struct bt_plugin *plugin; | |
1284 | struct bt_plugin_so_spec_data *spec; | |
1285 | ||
1286 | plugin = bt_plugin_create_empty(BT_PLUGIN_TYPE_SO); | |
1287 | if (!plugin) { | |
1288 | goto error; | |
1289 | } | |
1290 | ||
6fbd4105 | 1291 | plugin->destroy_spec_data = bt_plugin_so_destroy_spec_data; |
55bb57e0 PP |
1292 | plugin->spec_data = g_new0(struct bt_plugin_so_spec_data, 1); |
1293 | if (!plugin->spec_data) { | |
a8f90e5d PP |
1294 | BT_LIB_LOGE_APPEND_CAUSE( |
1295 | "Failed to allocate one SO plugin specific data structure."); | |
55bb57e0 PP |
1296 | goto error; |
1297 | } | |
1298 | ||
1299 | spec = plugin->spec_data; | |
4b70020d PP |
1300 | spec->shared_lib_handle = shared_lib_handle; |
1301 | bt_object_get_no_null_check(spec->shared_lib_handle); | |
55bb57e0 PP |
1302 | goto end; |
1303 | ||
1304 | error: | |
8138bfe1 | 1305 | BT_OBJECT_PUT_REF_AND_RESET(plugin); |
55bb57e0 PP |
1306 | |
1307 | end: | |
1308 | return plugin; | |
1309 | } | |
1310 | ||
be3c4e36 MJ |
1311 | static |
1312 | size_t count_non_null_items_in_section(const void *begin, const void *end) | |
1313 | { | |
1314 | size_t count = 0; | |
1315 | const int * const *begin_int = (const int * const *) begin; | |
1316 | const int * const *end_int = (const int * const *) end; | |
1317 | const int * const *iter; | |
1318 | ||
1319 | for (iter = begin_int; iter != end_int; iter++) { | |
1320 | if (*iter) { | |
1321 | count++; | |
1322 | } | |
1323 | } | |
1324 | ||
1325 | return count; | |
1326 | } | |
1327 | ||
55bb57e0 | 1328 | static |
fb25b9e3 | 1329 | int bt_plugin_so_create_all_from_sections( |
55bb57e0 | 1330 | struct bt_plugin_so_shared_lib_handle *shared_lib_handle, |
01f50d54 | 1331 | bool fail_on_load_error, |
55bb57e0 PP |
1332 | struct __bt_plugin_descriptor const * const *descriptors_begin, |
1333 | struct __bt_plugin_descriptor const * const *descriptors_end, | |
1334 | struct __bt_plugin_descriptor_attribute const * const *attrs_begin, | |
1335 | struct __bt_plugin_descriptor_attribute const * const *attrs_end, | |
1336 | struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_begin, | |
1337 | struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_end, | |
1338 | struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_begin, | |
01f50d54 PP |
1339 | struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_end, |
1340 | struct bt_plugin_set **plugin_set_out) | |
55bb57e0 | 1341 | { |
fb25b9e3 | 1342 | int status = BT_FUNC_STATUS_OK; |
55bb57e0 PP |
1343 | size_t descriptor_count; |
1344 | size_t attrs_count; | |
1345 | size_t cc_descriptors_count; | |
1346 | size_t cc_descr_attrs_count; | |
1347 | size_t i; | |
55bb57e0 | 1348 | |
dbf7ef57 | 1349 | BT_ASSERT(shared_lib_handle); |
01f50d54 PP |
1350 | BT_ASSERT(plugin_set_out); |
1351 | *plugin_set_out = NULL; | |
be3c4e36 MJ |
1352 | descriptor_count = count_non_null_items_in_section(descriptors_begin, descriptors_end); |
1353 | attrs_count = count_non_null_items_in_section(attrs_begin, attrs_end); | |
1354 | cc_descriptors_count = count_non_null_items_in_section(cc_descriptors_begin, cc_descriptors_end); | |
1355 | cc_descr_attrs_count = count_non_null_items_in_section(cc_descr_attrs_begin, cc_descr_attrs_end); | |
a684a357 | 1356 | BT_LOGI("Creating all SO plugins from sections: " |
3fe0bf43 PP |
1357 | "plugin-path=\"%s\", " |
1358 | "descr-begin-addr=%p, descr-end-addr=%p, " | |
1359 | "attrs-begin-addr=%p, attrs-end-addr=%p, " | |
1360 | "cc-descr-begin-addr=%p, cc-descr-end-addr=%p, " | |
1361 | "cc-descr-attrs-begin-addr=%p, cc-descr-attrs-end-addr=%p, " | |
1362 | "descr-count=%zu, attrs-count=%zu, " | |
1363 | "cc-descr-count=%zu, cc-descr-attrs-count=%zu", | |
1364 | shared_lib_handle->path ? shared_lib_handle->path->str : NULL, | |
1365 | descriptors_begin, descriptors_end, | |
1366 | attrs_begin, attrs_end, | |
1367 | cc_descriptors_begin, cc_descriptors_end, | |
1368 | cc_descr_attrs_begin, cc_descr_attrs_end, | |
1369 | descriptor_count, attrs_count, | |
1370 | cc_descriptors_count, cc_descr_attrs_count); | |
01f50d54 PP |
1371 | *plugin_set_out = bt_plugin_set_create(); |
1372 | if (!*plugin_set_out) { | |
a8f90e5d | 1373 | BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set."); |
fb25b9e3 | 1374 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
55bb57e0 PP |
1375 | goto error; |
1376 | } | |
1377 | ||
be3c4e36 | 1378 | for (i = 0; i < descriptors_end - descriptors_begin; i++) { |
55bb57e0 PP |
1379 | const struct __bt_plugin_descriptor *descriptor = |
1380 | descriptors_begin[i]; | |
1381 | struct bt_plugin *plugin; | |
1382 | ||
8e01f2d9 | 1383 | if (!descriptor) { |
be3c4e36 MJ |
1384 | continue; |
1385 | } | |
1386 | ||
a684a357 | 1387 | BT_LOGI("Creating plugin object for plugin: " |
3fe0bf43 PP |
1388 | "name=\"%s\", abi-major=%d, abi-minor=%d", |
1389 | descriptor->name, descriptor->major, descriptor->minor); | |
55bb57e0 PP |
1390 | |
1391 | if (descriptor->major > __BT_PLUGIN_VERSION_MAJOR) { | |
01f50d54 | 1392 | if (fail_on_load_error) { |
a8f90e5d PP |
1393 | BT_LIB_LOGW_APPEND_CAUSE( |
1394 | "Unknown ABI major version: abi-major=%d", | |
1395 | descriptor->major); | |
c24a8f3c | 1396 | status = BT_FUNC_STATUS_ERROR; |
01f50d54 PP |
1397 | goto error; |
1398 | } else { | |
6b076590 | 1399 | BT_LIB_LOGW( |
a8f90e5d PP |
1400 | "Unknown ABI major version: abi-major=%d", |
1401 | descriptor->major); | |
01f50d54 PP |
1402 | continue; |
1403 | } | |
55bb57e0 PP |
1404 | } |
1405 | ||
1406 | plugin = bt_plugin_so_create_empty(shared_lib_handle); | |
1407 | if (!plugin) { | |
a8f90e5d PP |
1408 | BT_LIB_LOGE_APPEND_CAUSE( |
1409 | "Cannot create empty shared library handle."); | |
fb25b9e3 | 1410 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
55bb57e0 PP |
1411 | goto error; |
1412 | } | |
1413 | ||
474039c7 | 1414 | if (shared_lib_handle->path) { |
01f50d54 PP |
1415 | bt_plugin_set_path(plugin, |
1416 | shared_lib_handle->path->str); | |
55bb57e0 PP |
1417 | } |
1418 | ||
01f50d54 PP |
1419 | status = bt_plugin_so_init(plugin, fail_on_load_error, |
1420 | descriptor, attrs_begin, attrs_end, | |
1421 | cc_descriptors_begin, cc_descriptors_end, | |
55bb57e0 | 1422 | cc_descr_attrs_begin, cc_descr_attrs_end); |
fb25b9e3 | 1423 | if (status == BT_FUNC_STATUS_OK) { |
01f50d54 PP |
1424 | /* Add to plugin set */ |
1425 | bt_plugin_set_add_plugin(*plugin_set_out, plugin); | |
1426 | BT_OBJECT_PUT_REF_AND_RESET(plugin); | |
1427 | } else if (status < 0) { | |
50ad9320 | 1428 | /* |
01f50d54 PP |
1429 | * bt_plugin_so_init() handles |
1430 | * `fail_on_load_error`, so this is a "real" | |
1431 | * error. | |
50ad9320 | 1432 | */ |
a8f90e5d PP |
1433 | BT_LIB_LOGW_APPEND_CAUSE( |
1434 | "Cannot initialize SO plugin object from sections."); | |
8138bfe1 | 1435 | BT_OBJECT_PUT_REF_AND_RESET(plugin); |
55bb57e0 PP |
1436 | goto error; |
1437 | } | |
1438 | ||
01f50d54 PP |
1439 | BT_ASSERT(!plugin); |
1440 | } | |
1441 | ||
1442 | BT_ASSERT(*plugin_set_out); | |
1443 | ||
1444 | if ((*plugin_set_out)->plugins->len == 0) { | |
1445 | BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out); | |
fb25b9e3 | 1446 | status = BT_FUNC_STATUS_NOT_FOUND; |
55bb57e0 PP |
1447 | } |
1448 | ||
1449 | goto end; | |
1450 | ||
1451 | error: | |
01f50d54 PP |
1452 | BT_ASSERT(status < 0); |
1453 | BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out); | |
55bb57e0 PP |
1454 | |
1455 | end: | |
01f50d54 | 1456 | return status; |
55bb57e0 PP |
1457 | } |
1458 | ||
1459 | BT_HIDDEN | |
fb25b9e3 | 1460 | int bt_plugin_so_create_all_from_static(bool fail_on_load_error, |
01f50d54 | 1461 | struct bt_plugin_set **plugin_set_out) |
55bb57e0 | 1462 | { |
fb25b9e3 | 1463 | int status; |
01f50d54 | 1464 | struct bt_plugin_so_shared_lib_handle *shared_lib_handle = NULL; |
55bb57e0 | 1465 | |
01f50d54 PP |
1466 | BT_ASSERT(plugin_set_out); |
1467 | *plugin_set_out = NULL; | |
1468 | status = bt_plugin_so_shared_lib_handle_create(NULL, | |
1469 | &shared_lib_handle); | |
fb25b9e3 | 1470 | if (status != BT_FUNC_STATUS_OK) { |
01f50d54 | 1471 | BT_ASSERT(!shared_lib_handle); |
55bb57e0 PP |
1472 | goto end; |
1473 | } | |
1474 | ||
01f50d54 | 1475 | BT_ASSERT(shared_lib_handle); |
3fe0bf43 | 1476 | BT_LOGD_STR("Creating all SO plugins from built-in plugins."); |
01f50d54 PP |
1477 | status = bt_plugin_so_create_all_from_sections(shared_lib_handle, |
1478 | fail_on_load_error, | |
be3c4e36 MJ |
1479 | __bt_get_begin_section_plugin_descriptors(), |
1480 | __bt_get_end_section_plugin_descriptors(), | |
1481 | __bt_get_begin_section_plugin_descriptor_attributes(), | |
1482 | __bt_get_end_section_plugin_descriptor_attributes(), | |
1483 | __bt_get_begin_section_component_class_descriptors(), | |
1484 | __bt_get_end_section_component_class_descriptors(), | |
1485 | __bt_get_begin_section_component_class_descriptor_attributes(), | |
01f50d54 PP |
1486 | __bt_get_end_section_component_class_descriptor_attributes(), |
1487 | plugin_set_out); | |
fb25b9e3 | 1488 | BT_ASSERT((status == BT_FUNC_STATUS_OK && *plugin_set_out && |
01f50d54 | 1489 | (*plugin_set_out)->plugins->len > 0) || !*plugin_set_out); |
55bb57e0 PP |
1490 | |
1491 | end: | |
8138bfe1 | 1492 | BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle); |
01f50d54 | 1493 | return status; |
55bb57e0 PP |
1494 | } |
1495 | ||
1496 | BT_HIDDEN | |
fb25b9e3 | 1497 | int bt_plugin_so_create_all_from_file(const char *path, |
01f50d54 | 1498 | bool fail_on_load_error, struct bt_plugin_set **plugin_set_out) |
55bb57e0 PP |
1499 | { |
1500 | size_t path_len; | |
fb25b9e3 | 1501 | int status; |
55bb57e0 PP |
1502 | struct __bt_plugin_descriptor const * const *descriptors_begin = NULL; |
1503 | struct __bt_plugin_descriptor const * const *descriptors_end = NULL; | |
1504 | struct __bt_plugin_descriptor_attribute const * const *attrs_begin = NULL; | |
1505 | struct __bt_plugin_descriptor_attribute const * const *attrs_end = NULL; | |
1506 | struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_begin = NULL; | |
1507 | struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_end = NULL; | |
1508 | struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_begin = NULL; | |
1509 | struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_end = NULL; | |
be3c4e36 MJ |
1510 | struct __bt_plugin_descriptor const * const *(*get_begin_section_plugin_descriptors)(void); |
1511 | struct __bt_plugin_descriptor const * const *(*get_end_section_plugin_descriptors)(void); | |
1512 | struct __bt_plugin_descriptor_attribute const * const *(*get_begin_section_plugin_descriptor_attributes)(void); | |
1513 | struct __bt_plugin_descriptor_attribute const * const *(*get_end_section_plugin_descriptor_attributes)(void); | |
1514 | struct __bt_plugin_component_class_descriptor const * const *(*get_begin_section_component_class_descriptors)(void); | |
1515 | struct __bt_plugin_component_class_descriptor const * const *(*get_end_section_component_class_descriptors)(void); | |
1516 | struct __bt_plugin_component_class_descriptor_attribute const * const *(*get_begin_section_component_class_descriptor_attributes)(void); | |
1517 | struct __bt_plugin_component_class_descriptor_attribute const * const *(*get_end_section_component_class_descriptor_attributes)(void); | |
c55a9f58 | 1518 | bt_bool is_libtool_wrapper = BT_FALSE, is_shared_object = BT_FALSE; |
55bb57e0 PP |
1519 | struct bt_plugin_so_shared_lib_handle *shared_lib_handle = NULL; |
1520 | ||
a684a357 | 1521 | BT_ASSERT(path); |
01f50d54 PP |
1522 | BT_ASSERT(plugin_set_out); |
1523 | *plugin_set_out = NULL; | |
55bb57e0 | 1524 | path_len = strlen(path); |
25825bf0 FD |
1525 | |
1526 | /* | |
1527 | * An SO plugin file must have a known plugin file suffix. So the file | |
1528 | * path must be longer than the suffix length. | |
1529 | */ | |
1530 | if (path_len <= PLUGIN_SUFFIX_LEN) { | |
1531 | BT_LOGI("Path is too short to be an `.so` or `.la` plugin file:" | |
1532 | "path=%s, path-length=%zu, min-length=%zu", | |
1533 | path, path_len, PLUGIN_SUFFIX_LEN); | |
1534 | status = BT_FUNC_STATUS_NOT_FOUND; | |
1535 | goto end; | |
1536 | } | |
1537 | ||
a684a357 | 1538 | BT_LOGI("Trying to create all SO plugins from file: path=\"%s\"", path); |
55bb57e0 | 1539 | path_len++; |
a684a357 | 1540 | |
55bb57e0 | 1541 | /* |
a684a357 PP |
1542 | * Check if the file ends with a known plugin file type suffix |
1543 | * (i.e. .so or .la on Linux). | |
55bb57e0 PP |
1544 | */ |
1545 | is_libtool_wrapper = !strncmp(LIBTOOL_PLUGIN_SUFFIX, | |
1546 | path + path_len - LIBTOOL_PLUGIN_SUFFIX_LEN, | |
1547 | LIBTOOL_PLUGIN_SUFFIX_LEN); | |
1548 | is_shared_object = !strncmp(NATIVE_PLUGIN_SUFFIX, | |
1549 | path + path_len - NATIVE_PLUGIN_SUFFIX_LEN, | |
1550 | NATIVE_PLUGIN_SUFFIX_LEN); | |
1551 | if (!is_shared_object && !is_libtool_wrapper) { | |
3fe0bf43 | 1552 | /* Name indicates this is not a plugin file; not an error */ |
01f50d54 | 1553 | BT_LOGI("File is not an SO plugin file: path=\"%s\"", path); |
fb25b9e3 | 1554 | status = BT_FUNC_STATUS_NOT_FOUND; |
55bb57e0 PP |
1555 | goto end; |
1556 | } | |
1557 | ||
01f50d54 PP |
1558 | status = bt_plugin_so_shared_lib_handle_create(path, |
1559 | &shared_lib_handle); | |
fb25b9e3 | 1560 | if (status != BT_FUNC_STATUS_OK) { |
a684a357 | 1561 | /* bt_plugin_so_shared_lib_handle_create() logs more details */ |
01f50d54 | 1562 | BT_ASSERT(!shared_lib_handle); |
55bb57e0 PP |
1563 | goto end; |
1564 | } | |
1565 | ||
be3c4e36 MJ |
1566 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_plugin_descriptors", |
1567 | (gpointer *) &get_begin_section_plugin_descriptors)) { | |
1568 | descriptors_begin = get_begin_section_plugin_descriptors(); | |
1569 | } else { | |
01f50d54 PP |
1570 | /* |
1571 | * Use this first symbol to know whether or not this | |
1572 | * shared object _looks like_ a Babeltrace plugin. Since | |
1573 | * g_module_symbol() failed, assume that this is not a | |
1574 | * Babeltrace plugin, so it's not an error. | |
1575 | */ | |
a684a357 | 1576 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1577 | "symbol=\"%s\"", path, |
be3c4e36 | 1578 | "__bt_get_begin_section_plugin_descriptors"); |
fb25b9e3 | 1579 | status = BT_FUNC_STATUS_NOT_FOUND; |
55bb57e0 PP |
1580 | goto end; |
1581 | } | |
1582 | ||
01f50d54 PP |
1583 | /* |
1584 | * If g_module_symbol() fails for any of the other symbols, fail | |
1585 | * if `fail_on_load_error` is true. | |
1586 | */ | |
be3c4e36 MJ |
1587 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_plugin_descriptors", |
1588 | (gpointer *) &get_end_section_plugin_descriptors)) { | |
1589 | descriptors_end = get_end_section_plugin_descriptors(); | |
1590 | } else { | |
a8f90e5d PP |
1591 | if (fail_on_load_error) { |
1592 | BT_LIB_LOGW_APPEND_CAUSE( | |
1593 | "Cannot resolve plugin symbol: path=\"%s\", " | |
1594 | "symbol=\"%s\"", path, | |
1595 | "__bt_get_end_section_plugin_descriptors"); | |
c24a8f3c | 1596 | status = BT_FUNC_STATUS_ERROR; |
a8f90e5d | 1597 | } else { |
6b076590 | 1598 | BT_LIB_LOGW( |
a8f90e5d PP |
1599 | "Cannot resolve plugin symbol: path=\"%s\", " |
1600 | "symbol=\"%s\"", path, | |
1601 | "__bt_get_end_section_plugin_descriptors"); | |
1602 | status = BT_FUNC_STATUS_NOT_FOUND; | |
1603 | } | |
1604 | ||
55bb57e0 PP |
1605 | goto end; |
1606 | } | |
1607 | ||
be3c4e36 MJ |
1608 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_plugin_descriptor_attributes", |
1609 | (gpointer *) &get_begin_section_plugin_descriptor_attributes)) { | |
1610 | attrs_begin = get_begin_section_plugin_descriptor_attributes(); | |
1611 | } else { | |
a684a357 | 1612 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1613 | "symbol=\"%s\"", path, |
be3c4e36 | 1614 | "__bt_get_begin_section_plugin_descriptor_attributes"); |
55bb57e0 PP |
1615 | } |
1616 | ||
be3c4e36 MJ |
1617 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_plugin_descriptor_attributes", |
1618 | (gpointer *) &get_end_section_plugin_descriptor_attributes)) { | |
1619 | attrs_end = get_end_section_plugin_descriptor_attributes(); | |
1620 | } else { | |
a684a357 | 1621 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1622 | "symbol=\"%s\"", path, |
be3c4e36 | 1623 | "__bt_get_end_section_plugin_descriptor_attributes"); |
55bb57e0 PP |
1624 | } |
1625 | ||
1626 | if ((!!attrs_begin - !!attrs_end) != 0) { | |
a8f90e5d PP |
1627 | if (fail_on_load_error) { |
1628 | BT_LIB_LOGW_APPEND_CAUSE( | |
1629 | "Found section start or end symbol, but not both: " | |
1630 | "path=\"%s\", symbol-start=\"%s\", " | |
1631 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1632 | "symbol-end-addr=%p", | |
1633 | path, "__bt_get_begin_section_plugin_descriptor_attributes", | |
1634 | "__bt_get_end_section_plugin_descriptor_attributes", | |
1635 | attrs_begin, attrs_end); | |
c24a8f3c | 1636 | status = BT_FUNC_STATUS_ERROR; |
a8f90e5d | 1637 | } else { |
6b076590 | 1638 | BT_LIB_LOGW( |
a8f90e5d PP |
1639 | "Found section start or end symbol, but not both: " |
1640 | "path=\"%s\", symbol-start=\"%s\", " | |
1641 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1642 | "symbol-end-addr=%p", | |
1643 | path, "__bt_get_begin_section_plugin_descriptor_attributes", | |
1644 | "__bt_get_end_section_plugin_descriptor_attributes", | |
1645 | attrs_begin, attrs_end); | |
1646 | status = BT_FUNC_STATUS_NOT_FOUND; | |
1647 | } | |
1648 | ||
55bb57e0 PP |
1649 | goto end; |
1650 | } | |
1651 | ||
be3c4e36 MJ |
1652 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_component_class_descriptors", |
1653 | (gpointer *) &get_begin_section_component_class_descriptors)) { | |
1654 | cc_descriptors_begin = get_begin_section_component_class_descriptors(); | |
1655 | } else { | |
a684a357 | 1656 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1657 | "symbol=\"%s\"", path, |
be3c4e36 | 1658 | "__bt_get_begin_section_component_class_descriptors"); |
55bb57e0 PP |
1659 | } |
1660 | ||
be3c4e36 MJ |
1661 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_component_class_descriptors", |
1662 | (gpointer *) &get_end_section_component_class_descriptors)) { | |
1663 | cc_descriptors_end = get_end_section_component_class_descriptors(); | |
1664 | } else { | |
a684a357 | 1665 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1666 | "symbol=\"%s\"", path, |
be3c4e36 | 1667 | "__bt_get_end_section_component_class_descriptors"); |
55bb57e0 PP |
1668 | } |
1669 | ||
1670 | if ((!!cc_descriptors_begin - !!cc_descriptors_end) != 0) { | |
a8f90e5d PP |
1671 | if (fail_on_load_error) { |
1672 | BT_LIB_LOGW_APPEND_CAUSE( | |
1673 | "Found section start or end symbol, but not both: " | |
1674 | "path=\"%s\", symbol-start=\"%s\", " | |
1675 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1676 | "symbol-end-addr=%p", | |
1677 | path, "__bt_get_begin_section_component_class_descriptors", | |
1678 | "__bt_get_end_section_component_class_descriptors", | |
1679 | cc_descriptors_begin, cc_descriptors_end); | |
c24a8f3c | 1680 | status = BT_FUNC_STATUS_ERROR; |
a8f90e5d | 1681 | } else { |
6b076590 | 1682 | BT_LIB_LOGW( |
a8f90e5d PP |
1683 | "Found section start or end symbol, but not both: " |
1684 | "path=\"%s\", symbol-start=\"%s\", " | |
1685 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1686 | "symbol-end-addr=%p", | |
1687 | path, "__bt_get_begin_section_component_class_descriptors", | |
1688 | "__bt_get_end_section_component_class_descriptors", | |
1689 | cc_descriptors_begin, cc_descriptors_end); | |
1690 | status = BT_FUNC_STATUS_NOT_FOUND; | |
1691 | } | |
1692 | ||
55bb57e0 PP |
1693 | goto end; |
1694 | } | |
1695 | ||
be3c4e36 MJ |
1696 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_component_class_descriptor_attributes", |
1697 | (gpointer *) &get_begin_section_component_class_descriptor_attributes)) { | |
1698 | cc_descr_attrs_begin = get_begin_section_component_class_descriptor_attributes(); | |
1699 | } else { | |
a684a357 | 1700 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1701 | "symbol=\"%s\"", path, |
be3c4e36 | 1702 | "__bt_get_begin_section_component_class_descriptor_attributes"); |
55bb57e0 PP |
1703 | } |
1704 | ||
be3c4e36 MJ |
1705 | if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_component_class_descriptor_attributes", |
1706 | (gpointer *) &get_end_section_component_class_descriptor_attributes)) { | |
1707 | cc_descr_attrs_end = get_end_section_component_class_descriptor_attributes(); | |
1708 | } else { | |
a684a357 | 1709 | BT_LOGI("Cannot resolve plugin symbol: path=\"%s\", " |
3fe0bf43 | 1710 | "symbol=\"%s\"", path, |
be3c4e36 | 1711 | "__bt_get_end_section_component_class_descriptor_attributes"); |
55bb57e0 PP |
1712 | } |
1713 | ||
1714 | if ((!!cc_descr_attrs_begin - !!cc_descr_attrs_end) != 0) { | |
a8f90e5d PP |
1715 | if (fail_on_load_error) { |
1716 | BT_LIB_LOGW_APPEND_CAUSE( | |
1717 | "Found section start or end symbol, but not both: " | |
1718 | "path=\"%s\", symbol-start=\"%s\", " | |
1719 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1720 | "symbol-end-addr=%p", | |
1721 | path, "__bt_get_begin_section_component_class_descriptor_attributes", | |
1722 | "__bt_get_end_section_component_class_descriptor_attributes", | |
1723 | cc_descr_attrs_begin, cc_descr_attrs_end); | |
c24a8f3c | 1724 | status = BT_FUNC_STATUS_ERROR; |
a8f90e5d | 1725 | } else { |
6b076590 | 1726 | BT_LIB_LOGW( |
a8f90e5d PP |
1727 | "Found section start or end symbol, but not both: " |
1728 | "path=\"%s\", symbol-start=\"%s\", " | |
1729 | "symbol-end=\"%s\", symbol-start-addr=%p, " | |
1730 | "symbol-end-addr=%p", | |
1731 | path, "__bt_get_begin_section_component_class_descriptor_attributes", | |
1732 | "__bt_get_end_section_component_class_descriptor_attributes", | |
1733 | cc_descr_attrs_begin, cc_descr_attrs_end); | |
1734 | status = BT_FUNC_STATUS_NOT_FOUND; | |
1735 | } | |
1736 | ||
55bb57e0 PP |
1737 | goto end; |
1738 | } | |
1739 | ||
1740 | /* Initialize plugin */ | |
3fe0bf43 | 1741 | BT_LOGD_STR("Initializing plugin object."); |
01f50d54 PP |
1742 | status = bt_plugin_so_create_all_from_sections(shared_lib_handle, |
1743 | fail_on_load_error, | |
55bb57e0 PP |
1744 | descriptors_begin, descriptors_end, attrs_begin, attrs_end, |
1745 | cc_descriptors_begin, cc_descriptors_end, | |
01f50d54 | 1746 | cc_descr_attrs_begin, cc_descr_attrs_end, plugin_set_out); |
55bb57e0 PP |
1747 | |
1748 | end: | |
8138bfe1 | 1749 | BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle); |
01f50d54 | 1750 | return status; |
55bb57e0 PP |
1751 | } |
1752 | ||
1753 | static | |
1754 | void plugin_comp_class_destroy_listener(struct bt_component_class *comp_class, | |
1755 | void *data) | |
1756 | { | |
bfa9a4be | 1757 | bt_list_del(&comp_class->node); |
8138bfe1 | 1758 | BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle); |
a684a357 | 1759 | BT_LOGD("Component class destroyed: removed entry from list: " |
3fe0bf43 | 1760 | "comp-cls-addr=%p", comp_class); |
55bb57e0 PP |
1761 | } |
1762 | ||
3230ee6b | 1763 | void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin, |
55bb57e0 PP |
1764 | struct bt_component_class *comp_class) |
1765 | { | |
55bb57e0 PP |
1766 | struct bt_plugin_so_spec_data *spec = plugin->spec_data; |
1767 | ||
8b45963b PP |
1768 | BT_ASSERT(plugin->spec_data); |
1769 | BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO); | |
55bb57e0 | 1770 | |
bfa9a4be | 1771 | bt_list_add(&comp_class->node, &component_class_list); |
4b70020d PP |
1772 | comp_class->so_handle = spec->shared_lib_handle; |
1773 | bt_object_get_no_null_check(comp_class->so_handle); | |
55bb57e0 PP |
1774 | |
1775 | /* Add our custom destroy listener */ | |
3230ee6b | 1776 | bt_component_class_add_destroy_listener(comp_class, |
55bb57e0 | 1777 | plugin_comp_class_destroy_listener, NULL); |
55bb57e0 | 1778 | } |