- /* Add sentinel to array */
- g_ptr_array_add(plugins_array, NULL);
- plugins = (struct bt_plugin **) plugins_array->pdata;
- goto end;
-
-error:
- if (plugins_array) {
- g_ptr_array_free(plugins_array, TRUE);
- plugins_array = NULL;
- }
-
-end:
- if (plugins_array) {
- g_ptr_array_free(plugins_array, FALSE);
- }
-
- return plugins;
-}
-
-static
-struct bt_plugin *bt_plugin_create_from_static_at_index(size_t i)
-{
- struct bt_plugin *plugin = NULL;
-
- plugin = g_new0(struct bt_plugin, 1);
- if (!plugin) {
- goto error;
- }
-
- bt_object_init(plugin, bt_plugin_destroy);
-
- /* Create shared lib handle */
- plugin->shared_lib_handle = bt_plugin_shared_lib_handle_create(NULL);
- if (!plugin->shared_lib_handle) {
- goto error;
- }
-
- /* Fill shared lib handle */
- plugin->shared_lib_handle->init =
- (SECTION_BEGIN(__bt_plugin_init_funcs))[i];
- if (!plugin->shared_lib_handle->init) {
- goto error;
- }
-
- plugin->shared_lib_handle->exit =
- (SECTION_BEGIN(__bt_plugin_exit_funcs))[i];
- if (!plugin->shared_lib_handle->exit) {
- goto error;
- }
-
- plugin->shared_lib_handle->name = (SECTION_BEGIN(__bt_plugin_names))[i];
- plugin->shared_lib_handle->author =
- (SECTION_BEGIN(__bt_plugin_authors))[i];
- plugin->shared_lib_handle->license =
- (SECTION_BEGIN(__bt_plugin_licenses))[i];
- plugin->shared_lib_handle->description =
- (SECTION_BEGIN(__bt_plugin_descriptions))[i];
-
- /* Create empty array of component classes */
- plugin->comp_classes =
- g_ptr_array_new_with_free_func((GDestroyNotify) bt_put);
- if (!plugin->comp_classes) {
- goto error;
- }
-
- /* Initialize plugin */
- if (init_plugin(plugin) < 0) {
- goto error;
- }
-
- goto end;
-
-error:
- BT_PUT(plugin);
-
-end:
- return plugin;
-}
-
-struct bt_plugin **bt_plugin_create_all_from_static(void)
-{
- size_t count, i;
- struct bt_plugin **plugins = NULL;
-
- PRINT_PLUG_IN_SECTIONS(printf_verbose);
- count = SECTION_ELEMENT_COUNT(__bt_plugin_init_funcs);
- if (SECTION_ELEMENT_COUNT(__bt_plugin_exit_funcs) != count ||
- SECTION_ELEMENT_COUNT(__bt_plugin_names) != count ||
- SECTION_ELEMENT_COUNT(__bt_plugin_authors) != count ||
- SECTION_ELEMENT_COUNT(__bt_plugin_licenses) != count ||
- SECTION_ELEMENT_COUNT(__bt_plugin_descriptions) != count) {
- printf_error("Some statically-linked plug-ins do not define all the mandatory symbols\n");
- goto error;
- }
-
- printf_verbose("Detected %zu statically-linked plug-ins\n", count);
- plugins = g_new0(struct bt_plugin *, count + 1);
- if (!plugins) {
- goto error;
- }
-
- for (i = 0; i < count; i++) {
- struct bt_plugin *plugin =
- bt_plugin_create_from_static_at_index(i);
-
- if (!plugin) {
- printf_error("Cannot create statically-linked plug-in at index %zu\n",
- i);
- goto error;
- }
-
- /* Transfer ownership to the array */
- plugins[i] = plugin;
- }
-