/*
- * plugin-so.c
- *
- * Babeltrace Plugin (shared object)
- *
* Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
* Copyright 2017 Philippe Proulx <pproulx@efficios.com>
*
#include <babeltrace/lib-logging-internal.h>
#include <babeltrace/compiler-internal.h>
-#include <babeltrace/ref.h>
+#include <babeltrace/object.h>
#include <babeltrace/plugin/plugin-internal.h>
#include <babeltrace/plugin/plugin-so-internal.h>
#include <babeltrace/plugin/plugin-dev.h>
#include <babeltrace/plugin/plugin-internal.h>
#include <babeltrace/graph/component-class-internal.h>
+#include <babeltrace/graph/private-component-class.h>
+#include <babeltrace/graph/private-component-class-source.h>
+#include <babeltrace/graph/private-component-class-filter.h>
+#include <babeltrace/graph/private-component-class-sink.h>
#include <babeltrace/types.h>
+#include <babeltrace/list-internal.h>
+#include <babeltrace/assert-internal.h>
#include <string.h>
#include <stdlib.h>
#include <glib.h>
#include <gmodule.h>
-#define NATIVE_PLUGIN_SUFFIX ".so"
+#define NATIVE_PLUGIN_SUFFIX "." G_MODULE_SUFFIX
#define NATIVE_PLUGIN_SUFFIX_LEN sizeof(NATIVE_PLUGIN_SUFFIX)
#define LIBTOOL_PLUGIN_SUFFIX ".la"
#define LIBTOOL_PLUGIN_SUFFIX_LEN sizeof(LIBTOOL_PLUGIN_SUFFIX)
#define PLUGIN_SUFFIX_LEN max_t(size_t, sizeof(NATIVE_PLUGIN_SUFFIX), \
sizeof(LIBTOOL_PLUGIN_SUFFIX))
-#define SECTION_BEGIN(_name) (&(__start_##_name))
-#define SECTION_END(_name) (&(__stop_##_name))
-#define SECTION_ELEMENT_COUNT(_name) (SECTION_END(_name) - SECTION_BEGIN(_name))
-
-#define DECLARE_SECTION(_type, _name) \
- extern _type __start_##_name __attribute((weak)); \
- extern _type __stop_##_name __attribute((weak))
-
-DECLARE_SECTION(struct __bt_plugin_descriptor const *, __bt_plugin_descriptors);
-DECLARE_SECTION(struct __bt_plugin_descriptor_attribute const *, __bt_plugin_descriptor_attributes);
-DECLARE_SECTION(struct __bt_plugin_component_class_descriptor const *, __bt_plugin_component_class_descriptors);
-DECLARE_SECTION(struct __bt_plugin_component_class_descriptor_attribute const *, __bt_plugin_component_class_descriptor_attributes);
+BT_PLUGIN_MODULE();
/*
- * This hash table, global to the library, maps component class pointers
- * to shared library handles.
+ * This list, global to the library, keeps all component classes that
+ * have a reference to their shared library handles. It allows iteration
+ * on all component classes still present when the destructor executes
+ * to release the shared library handle references they might still have.
*
- * The keys (component classes) are NOT owned by this hash table, whereas
- * the values (shared library handles) are owned by this hash table.
- *
- * The keys are the component classes created with
+ * The list items are the component classes created with
* bt_plugin_add_component_class(). They keep the shared library handle
* object created by their plugin alive so that the plugin's code is
* not discarded when it could still be in use by living components
* created from those component classes:
*
- * [component] --ref-> [component class] --through this HT-> [shlib handle]
- *
- * This hash table exists for two reasons:
+ * [component] --ref-> [component class]-> [shlib handle]
*
- * 1. To allow this application:
+ * It allows this use-case:
*
* my_plugins = bt_plugin_create_all_from_file("/path/to/my-plugin.so");
* // instantiate components from a plugin's component classes
* // put plugins and free my_plugins here
* // user code of instantiated components still exists
*
- * 2. To decouple the plugin subsystem from the component subsystem:
- * while plugins objects need to know component class objects, the
- * opposite is not necessary, thus it makes no sense for a component
- * class to keep a reference to the plugin object from which it was
- * created.
- *
- * An entry is removed from this HT when a component class is destroyed
- * thanks to a custom destroy listener. When the entry is removed, the
- * GLib function calls the value destroy notifier of the HT, which is
- * bt_put(). This decreases the reference count of the mapped shared
- * library handle. Assuming the original plugin object which contained
- * some component classes is put first, when the last component class is
- * removed from this HT, the shared library handle object's reference
- * count falls to zero and the shared library is finally closed.
+ * An entry is removed from this list when a component class is
+ * destroyed thanks to a custom destroy listener. When the entry is
+ * removed, the entry is removed from the list, and we release the
+ * reference on the shlib handle. Assuming the original plugin object
+ * which contained some component classes is put first, when the last
+ * component class is removed from this list, the shared library handle
+ * object's reference count falls to zero and the shared library is
+ * finally closed.
*/
+
static
-GHashTable *comp_classes_to_shlib_handles;
-
-__attribute__((constructor)) static
-void init_comp_classes_to_shlib_handles(void) {
- comp_classes_to_shlib_handles = g_hash_table_new_full(g_direct_hash,
- g_direct_equal, NULL, bt_put);
- assert(comp_classes_to_shlib_handles);
- BT_LOGD_STR("Initialized component class to shared library handle hash table.");
-}
+BT_LIST_HEAD(component_class_list);
__attribute__((destructor)) static
-void fini_comp_classes_to_shlib_handles(void) {
- if (comp_classes_to_shlib_handles) {
- g_hash_table_destroy(comp_classes_to_shlib_handles);
- BT_LOGD_STR("Destroyed component class to shared library handle hash table.");
+void fini_comp_class_list(void)
+{
+ struct bt_component_class *comp_class, *tmp;
+
+ bt_list_for_each_entry_safe(comp_class, tmp, &component_class_list, node) {
+ bt_list_del(&comp_class->node);
+ BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle);
}
+
+ BT_LOGD_STR("Released references from all component classes to shared library handles.");
}
static
{
struct bt_plugin_so_shared_lib_handle *shared_lib_handle;
- assert(obj);
+ BT_ASSERT(obj);
shared_lib_handle = container_of(obj,
struct bt_plugin_so_shared_lib_handle, base);
const char *path = shared_lib_handle->path ?
BT_LOGE("Cannot close GModule: %s: path=\"%s\"",
g_module_error(), path);
}
+
+ shared_lib_handle->module = NULL;
#ifndef NDEBUG
} else {
BT_LOGD("Not closing GModule because `BABELTRACE_NO_DLCLOSE=1`: "
if (shared_lib_handle->path) {
g_string_free(shared_lib_handle->path, TRUE);
+ shared_lib_handle->path = NULL;
}
g_free(shared_lib_handle);
goto error;
}
- bt_object_init(shared_lib_handle, bt_plugin_so_shared_lib_handle_destroy);
+ bt_object_init_shared(&shared_lib_handle->base,
+ bt_plugin_so_shared_lib_handle_destroy);
if (!path) {
goto end;
goto error;
}
- shared_lib_handle->module = g_module_open(path, 0);
+ shared_lib_handle->module = g_module_open(path, G_MODULE_BIND_LOCAL);
if (!shared_lib_handle->module) {
- BT_LOGW("Cannot open GModule: %s: path=\"%s\"",
+ /*
+ * DEBUG-level logging because we're only _trying_ to
+ * open this file as a Babeltrace plugin: if it's not,
+ * it's not an error. And because this can be tried
+ * during bt_plugin_create_all_from_dir(), it's not even
+ * a warning.
+ */
+ BT_LOGD("Cannot open GModule: %s: path=\"%s\"",
g_module_error(), path);
goto error;
}
goto end;
error:
- BT_PUT(shared_lib_handle);
+ BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle);
end:
if (shared_lib_handle) {
return;
}
- assert(plugin->type == BT_PLUGIN_TYPE_SO);
- assert(spec);
- BT_PUT(spec->shared_lib_handle);
+ BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO);
+ BT_ASSERT(spec);
+ BT_OBJECT_PUT_REF_AND_RESET(spec->shared_lib_handle);
g_free(plugin->spec_data);
plugin->spec_data = NULL;
}
const struct __bt_plugin_component_class_descriptor *descriptor;
const char *description;
const char *help;
- bt_component_class_init_method init_method;
- bt_component_class_finalize_method finalize_method;
- bt_component_class_query_method query_method;
- bt_component_class_accept_port_connection_method accept_port_connection_method;
- bt_component_class_port_connected_method port_connected_method;
- bt_component_class_port_disconnected_method port_disconnected_method;
- struct bt_component_class_iterator_methods iterator_methods;
+
+ union {
+ struct {
+ bt_private_component_class_source_init_method init;
+ bt_private_component_class_source_finalize_method finalize;
+ bt_private_component_class_source_query_method query;
+ bt_private_component_class_source_accept_output_port_connection_method accept_output_port_connection;
+ bt_private_component_class_source_output_port_connected_method output_port_connected;
+ bt_private_component_class_source_output_port_disconnected_method output_port_disconnected;
+ bt_private_component_class_source_notification_iterator_init_method notif_iter_init;
+ bt_private_component_class_source_notification_iterator_finalize_method notif_iter_finalize;
+ } source;
+
+ struct {
+ bt_private_component_class_filter_init_method init;
+ bt_private_component_class_filter_finalize_method finalize;
+ bt_private_component_class_filter_query_method query;
+ bt_private_component_class_filter_accept_input_port_connection_method accept_input_port_connection;
+ bt_private_component_class_filter_accept_output_port_connection_method accept_output_port_connection;
+ bt_private_component_class_filter_input_port_connected_method input_port_connected;
+ bt_private_component_class_filter_output_port_connected_method output_port_connected;
+ bt_private_component_class_filter_input_port_disconnected_method input_port_disconnected;
+ bt_private_component_class_filter_output_port_disconnected_method output_port_disconnected;
+ bt_private_component_class_filter_notification_iterator_init_method notif_iter_init;
+ bt_private_component_class_filter_notification_iterator_finalize_method notif_iter_finalize;
+ } filter;
+
+ struct {
+ bt_private_component_class_sink_init_method init;
+ bt_private_component_class_sink_finalize_method finalize;
+ bt_private_component_class_sink_query_method query;
+ bt_private_component_class_sink_accept_input_port_connection_method accept_input_port_connection;
+ bt_private_component_class_sink_input_port_connected_method input_port_connected;
+ bt_private_component_class_sink_input_port_disconnected_method input_port_disconnected;
+ } sink;
+ } methods;
};
enum bt_plugin_status status = BT_PLUGIN_STATUS_OK;
const struct __bt_plugin_descriptor_attribute *cur_attr =
*cur_attr_ptr;
+ if (cur_attr == NULL) {
+ continue;
+ }
+
if (cur_attr->plugin_descriptor != descriptor) {
continue;
}
cur_attr->value.version.extra);
break;
default:
+ /*
+ * WARN-level logging because this should not
+ * happen with the appropriate ABI version. If
+ * we're here, we know that for the reported
+ * version of the ABI, this attribute is
+ * unknown.
+ */
BT_LOGW("Ignoring unknown plugin descriptor attribute: "
"plugin-path=\"%s\", plugin-name=\"%s\", "
"attr-type-name=\"%s\", attr-type-id=%d",
*cur_cc_descr_ptr;
struct comp_class_full_descriptor full_descriptor = {0};
+ if (cur_cc_descr == NULL) {
+ continue;
+ }
+
if (cur_cc_descr->plugin_descriptor != descriptor) {
continue;
}
for (cur_cc_descr_attr_ptr = cc_descr_attrs_begin; cur_cc_descr_attr_ptr != cc_descr_attrs_end; cur_cc_descr_attr_ptr++) {
const struct __bt_plugin_component_class_descriptor_attribute *cur_cc_descr_attr =
*cur_cc_descr_attr_ptr;
+ enum bt_component_class_type cc_type;
+
+ if (cur_cc_descr_attr == NULL) {
+ continue;
+ }
if (cur_cc_descr_attr->comp_class_descriptor->plugin_descriptor !=
descriptor) {
continue;
}
+ cc_type = cur_cc_descr_attr->comp_class_descriptor->type;
+
/* Find the corresponding component class descriptor entry */
for (i = 0; i < comp_class_full_descriptors->len; i++) {
struct comp_class_full_descriptor *cc_full_descr =
&g_array_index(comp_class_full_descriptors,
struct comp_class_full_descriptor, i);
- if (cur_cc_descr_attr->comp_class_descriptor ==
+ if (cur_cc_descr_attr->comp_class_descriptor !=
cc_full_descr->descriptor) {
- switch (cur_cc_descr_attr->type) {
- case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION:
- cc_full_descr->description =
- cur_cc_descr_attr->value.description;
+ continue;
+ }
+
+ switch (cur_cc_descr_attr->type) {
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_DESCRIPTION:
+ cc_full_descr->description =
+ cur_cc_descr_attr->value.description;
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP:
+ cc_full_descr->help =
+ cur_cc_descr_attr->value.help;
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD:
+ switch (cc_type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ cc_full_descr->methods.source.init =
+ cur_cc_descr_attr->value.source_init_method;
+ break;
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ cc_full_descr->methods.filter.init =
+ cur_cc_descr_attr->value.filter_init_method;
break;
- case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_HELP:
- cc_full_descr->help =
- cur_cc_descr_attr->value.help;
+ case BT_COMPONENT_CLASS_TYPE_SINK:
+ cc_full_descr->methods.sink.init =
+ cur_cc_descr_attr->value.sink_init_method;
break;
- case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD:
- cc_full_descr->init_method =
- cur_cc_descr_attr->value.init_method;
+ default:
+ abort();
+ }
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD:
+ switch (cc_type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ cc_full_descr->methods.source.finalize =
+ cur_cc_descr_attr->value.source_finalize_method;
break;
- case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_FINALIZE_METHOD:
- cc_full_descr->finalize_method =
- cur_cc_descr_attr->value.finalize_method;
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ cc_full_descr->methods.filter.finalize =
+ cur_cc_descr_attr->value.filter_finalize_method;
break;
- case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD:
- cc_full_descr->query_method =
- cur_cc_descr_attr->value.query_method;
+ case BT_COMPONENT_CLASS_TYPE_SINK:
+ cc_full_descr->methods.sink.finalize =
+ cur_cc_descr_attr->value.sink_finalize_method;
+ break;
+ default:
+ abort();
+ }
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_QUERY_METHOD:
+ switch (cc_type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ cc_full_descr->methods.source.query =
+ cur_cc_descr_attr->value.source_query_method;
break;
- case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_PORT_CONNECTION_METHOD:
- cc_full_descr->accept_port_connection_method =
- cur_cc_descr_attr->value.accept_port_connection_method;
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ cc_full_descr->methods.filter.query =
+ cur_cc_descr_attr->value.filter_query_method;
break;
- case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_CONNECTED_METHOD:
- cc_full_descr->port_connected_method =
- cur_cc_descr_attr->value.port_connected_method;
+ case BT_COMPONENT_CLASS_TYPE_SINK:
+ cc_full_descr->methods.sink.query =
+ cur_cc_descr_attr->value.sink_query_method;
break;
- case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_PORT_DISCONNECTED_METHOD:
- cc_full_descr->port_disconnected_method =
- cur_cc_descr_attr->value.port_disconnected_method;
+ default:
+ abort();
+ }
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_INPUT_PORT_CONNECTION_METHOD:
+ switch (cc_type) {
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ cc_full_descr->methods.filter.accept_input_port_connection =
+ cur_cc_descr_attr->value.filter_accept_input_port_connection_method;
break;
- case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD:
- cc_full_descr->iterator_methods.init =
- cur_cc_descr_attr->value.notif_iter_init_method;
+ case BT_COMPONENT_CLASS_TYPE_SINK:
+ cc_full_descr->methods.sink.accept_input_port_connection =
+ cur_cc_descr_attr->value.sink_accept_input_port_connection_method;
break;
- case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD:
- cc_full_descr->iterator_methods.finalize =
- cur_cc_descr_attr->value.notif_iter_finalize_method;
+ default:
+ abort();
+ }
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_ACCEPT_OUTPUT_PORT_CONNECTION_METHOD:
+ switch (cc_type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ cc_full_descr->methods.source.accept_output_port_connection =
+ cur_cc_descr_attr->value.source_accept_output_port_connection_method;
break;
- case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_SEEK_TIME_METHOD:
- cc_full_descr->iterator_methods.seek_time =
- cur_cc_descr_attr->value.notif_iter_seek_time_method;
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ cc_full_descr->methods.filter.accept_output_port_connection =
+ cur_cc_descr_attr->value.filter_accept_output_port_connection_method;
break;
default:
- BT_LOGW("Ignoring unknown component class descriptor attribute: "
- "plugin-path=\"%s\", "
- "plugin-name=\"%s\", "
- "comp-class-name=\"%s\", "
- "comp-class-type=%s, "
- "attr-type-name=\"%s\", "
- "attr-type-id=%d",
- spec->shared_lib_handle->path ?
- spec->shared_lib_handle->path->str :
- NULL,
- descriptor->name,
- cur_cc_descr_attr->comp_class_descriptor->name,
- bt_component_class_type_string(
- cur_cc_descr_attr->comp_class_descriptor->type),
- cur_cc_descr_attr->type_name,
- cur_cc_descr_attr->type);
+ abort();
+ }
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_CONNECTED_METHOD:
+ switch (cc_type) {
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ cc_full_descr->methods.filter.input_port_connected =
+ cur_cc_descr_attr->value.filter_input_port_connected_method;
+ break;
+ case BT_COMPONENT_CLASS_TYPE_SINK:
+ cc_full_descr->methods.sink.input_port_connected =
+ cur_cc_descr_attr->value.sink_input_port_connected_method;
break;
+ default:
+ abort();
}
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_CONNECTED_METHOD:
+ switch (cc_type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ cc_full_descr->methods.source.output_port_connected =
+ cur_cc_descr_attr->value.source_output_port_connected_method;
+ break;
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ cc_full_descr->methods.filter.output_port_connected =
+ cur_cc_descr_attr->value.filter_output_port_connected_method;
+ break;
+ default:
+ abort();
+ }
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INPUT_PORT_DISCONNECTED_METHOD:
+ switch (cc_type) {
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ cc_full_descr->methods.filter.input_port_disconnected =
+ cur_cc_descr_attr->value.filter_input_port_disconnected_method;
+ break;
+ case BT_COMPONENT_CLASS_TYPE_SINK:
+ cc_full_descr->methods.sink.input_port_disconnected =
+ cur_cc_descr_attr->value.sink_input_port_disconnected_method;
+ break;
+ default:
+ abort();
+ }
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_OUTPUT_PORT_DISCONNECTED_METHOD:
+ switch (cc_type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ cc_full_descr->methods.source.output_port_disconnected =
+ cur_cc_descr_attr->value.source_output_port_disconnected_method;
+ break;
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ cc_full_descr->methods.filter.output_port_disconnected =
+ cur_cc_descr_attr->value.filter_output_port_disconnected_method;
+ break;
+ default:
+ abort();
+ }
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_INIT_METHOD:
+ switch (cc_type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ cc_full_descr->methods.source.notif_iter_init =
+ cur_cc_descr_attr->value.source_notif_iter_init_method;
+ break;
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ cc_full_descr->methods.filter.notif_iter_init =
+ cur_cc_descr_attr->value.filter_notif_iter_init_method;
+ break;
+ default:
+ abort();
+ }
+ break;
+ case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_NOTIF_ITER_FINALIZE_METHOD:
+ switch (cc_type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ cc_full_descr->methods.source.notif_iter_finalize =
+ cur_cc_descr_attr->value.source_notif_iter_finalize_method;
+ break;
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ cc_full_descr->methods.filter.notif_iter_finalize =
+ cur_cc_descr_attr->value.filter_notif_iter_finalize_method;
+ break;
+ default:
+ abort();
+ }
+ break;
+ default:
+ /*
+ * WARN-level logging because this
+ * should not happen with the
+ * appropriate ABI version. If we're
+ * here, we know that for the reported
+ * version of the ABI, this attribute is
+ * unknown.
+ */
+ BT_LOGW("Ignoring unknown component class descriptor attribute: "
+ "plugin-path=\"%s\", "
+ "plugin-name=\"%s\", "
+ "comp-class-name=\"%s\", "
+ "comp-class-type=%s, "
+ "attr-type-name=\"%s\", "
+ "attr-type-id=%d",
+ spec->shared_lib_handle->path ?
+ spec->shared_lib_handle->path->str :
+ NULL,
+ descriptor->name,
+ cur_cc_descr_attr->comp_class_descriptor->name,
+ bt_component_class_type_string(
+ cur_cc_descr_attr->comp_class_descriptor->type),
+ cur_cc_descr_attr->type_name,
+ cur_cc_descr_attr->type);
+ break;
}
}
}
struct comp_class_full_descriptor *cc_full_descr =
&g_array_index(comp_class_full_descriptors,
struct comp_class_full_descriptor, i);
- struct bt_component_class *comp_class;
+ struct bt_private_component_class *comp_class = NULL;
+ struct bt_private_component_class_source *src_comp_class = NULL;
+ struct bt_private_component_class_filter *flt_comp_class = NULL;
+ struct bt_private_component_class_sink *sink_comp_class = NULL;
BT_LOGD("Creating and setting properties of plugin's component class: "
"plugin-path=\"%s\", plugin-name=\"%s\", "
switch (cc_full_descr->descriptor->type) {
case BT_COMPONENT_CLASS_TYPE_SOURCE:
- comp_class = bt_component_class_source_create(
+ src_comp_class = bt_private_component_class_source_create(
cc_full_descr->descriptor->name,
cc_full_descr->descriptor->methods.source.notif_iter_next);
+ comp_class = bt_private_component_class_source_as_private_component_class(
+ src_comp_class);
break;
case BT_COMPONENT_CLASS_TYPE_FILTER:
- comp_class = bt_component_class_filter_create(
+ flt_comp_class = bt_private_component_class_filter_create(
cc_full_descr->descriptor->name,
cc_full_descr->descriptor->methods.source.notif_iter_next);
+ comp_class = bt_private_component_class_filter_as_private_component_class(
+ flt_comp_class);
break;
case BT_COMPONENT_CLASS_TYPE_SINK:
- comp_class = bt_component_class_sink_create(
+ sink_comp_class = bt_private_component_class_sink_create(
cc_full_descr->descriptor->name,
cc_full_descr->descriptor->methods.sink.consume);
+ comp_class = bt_private_component_class_sink_as_private_component_class(
+ sink_comp_class);
break;
default:
+ /*
+ * WARN-level logging because this should not
+ * happen with the appropriate ABI version. If
+ * we're here, we know that for the reported
+ * version of the ABI, this component class type
+ * is unknown.
+ */
BT_LOGW("Ignoring unknown component class type: "
"plugin-path=\"%s\", plugin-name=\"%s\", "
"comp-class-name=\"%s\", comp-class-type=%d",
}
if (cc_full_descr->description) {
- ret = bt_component_class_set_description(comp_class,
- cc_full_descr->description);
+ ret = bt_private_component_class_set_description(
+ comp_class, cc_full_descr->description);
if (ret) {
BT_LOGE_STR("Cannot set component class's description.");
status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
+ BT_OBJECT_PUT_REF_AND_RESET(comp_class);
goto end;
}
}
if (cc_full_descr->help) {
- ret = bt_component_class_set_help(comp_class,
+ ret = bt_private_component_class_set_help(comp_class,
cc_full_descr->help);
if (ret) {
BT_LOGE_STR("Cannot set component class's help string.");
status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
+ BT_OBJECT_PUT_REF_AND_RESET(comp_class);
goto end;
}
}
- if (cc_full_descr->init_method) {
- ret = bt_component_class_set_init_method(comp_class,
- cc_full_descr->init_method);
- if (ret) {
- BT_LOGE_STR("Cannot set component class's initialization method.");
- status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
- goto end;
+ switch (cc_full_descr->descriptor->type) {
+ case BT_COMPONENT_CLASS_TYPE_SOURCE:
+ if (cc_full_descr->methods.source.init) {
+ ret = bt_private_component_class_source_set_init_method(
+ src_comp_class,
+ cc_full_descr->methods.source.init);
+ if (ret) {
+ BT_LOGE_STR("Cannot set source component class's initialization method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
+ goto end;
+ }
}
- }
- if (cc_full_descr->finalize_method) {
- ret = bt_component_class_set_finalize_method(comp_class,
- cc_full_descr->finalize_method);
- if (ret) {
- BT_LOGE_STR("Cannot set component class's finalization method.");
- status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
- goto end;
+ if (cc_full_descr->methods.source.finalize) {
+ ret = bt_private_component_class_source_set_finalize_method(
+ src_comp_class,
+ cc_full_descr->methods.source.finalize);
+ if (ret) {
+ BT_LOGE_STR("Cannot set source component class's finalization method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
+ goto end;
+ }
}
- }
- if (cc_full_descr->query_method) {
- ret = bt_component_class_set_query_method(
- comp_class, cc_full_descr->query_method);
- if (ret) {
- BT_LOGE_STR("Cannot set component class's query method.");
- status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
- goto end;
+ if (cc_full_descr->methods.source.query) {
+ ret = bt_private_component_class_source_set_query_method(
+ src_comp_class,
+ cc_full_descr->methods.source.query);
+ if (ret) {
+ BT_LOGE_STR("Cannot set source component class's query method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
+ goto end;
+ }
}
- }
- if (cc_full_descr->accept_port_connection_method) {
- ret = bt_component_class_set_accept_port_connection_method(
- comp_class, cc_full_descr->accept_port_connection_method);
- if (ret) {
- BT_LOGE_STR("Cannot set component class's \"accept port connection\" method.");
- status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
- goto end;
+ if (cc_full_descr->methods.source.accept_output_port_connection) {
+ ret = bt_private_component_class_source_set_accept_output_port_connection_method(
+ src_comp_class,
+ cc_full_descr->methods.source.accept_output_port_connection);
+ if (ret) {
+ BT_LOGE_STR("Cannot set source component class's \"accept input output connection\" method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
+ goto end;
+ }
}
- }
- if (cc_full_descr->port_connected_method) {
- ret = bt_component_class_set_port_connected_method(
- comp_class, cc_full_descr->port_connected_method);
- if (ret) {
- BT_LOGE_STR("Cannot set component class's \"port connected\" method.");
- status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
- goto end;
+ if (cc_full_descr->methods.source.output_port_connected) {
+ ret = bt_private_component_class_source_set_output_port_connected_method(
+ src_comp_class,
+ cc_full_descr->methods.source.output_port_connected);
+ if (ret) {
+ BT_LOGE_STR("Cannot set source component class's \"output port connected\" method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
+ goto end;
+ }
}
- }
- if (cc_full_descr->port_disconnected_method) {
- ret = bt_component_class_set_port_disconnected_method(
- comp_class, cc_full_descr->port_disconnected_method);
- if (ret) {
- BT_LOGE_STR("Cannot set component class's \"port disconnected\" method.");
- status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
- goto end;
+ if (cc_full_descr->methods.source.output_port_disconnected) {
+ ret = bt_private_component_class_source_set_output_port_disconnected_method(
+ src_comp_class,
+ cc_full_descr->methods.source.output_port_disconnected);
+ if (ret) {
+ BT_LOGE_STR("Cannot set source component class's \"output port disconnected\" method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
+ goto end;
+ }
}
- }
- switch (cc_full_descr->descriptor->type) {
- case BT_COMPONENT_CLASS_TYPE_SOURCE:
- if (cc_full_descr->iterator_methods.init) {
- ret = bt_component_class_source_set_notification_iterator_init_method(
- comp_class,
- cc_full_descr->iterator_methods.init);
+ if (cc_full_descr->methods.source.notif_iter_init) {
+ ret = bt_private_component_class_source_set_notification_iterator_init_method(
+ src_comp_class,
+ cc_full_descr->methods.source.notif_iter_init);
if (ret) {
- BT_LOGE_STR("Cannot set component class's notification iterator initialization method.");
+ BT_LOGE_STR("Cannot set source component class's notification iterator initialization method.");
status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
+ BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
goto end;
}
}
- if (cc_full_descr->iterator_methods.finalize) {
- ret = bt_component_class_source_set_notification_iterator_finalize_method(
- comp_class,
- cc_full_descr->iterator_methods.finalize);
+ if (cc_full_descr->methods.source.notif_iter_finalize) {
+ ret = bt_private_component_class_source_set_notification_iterator_finalize_method(
+ src_comp_class,
+ cc_full_descr->methods.source.notif_iter_finalize);
if (ret) {
BT_LOGE_STR("Cannot set source component class's notification iterator finalization method.");
status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
+ BT_OBJECT_PUT_REF_AND_RESET(src_comp_class);
goto end;
}
}
- if (cc_full_descr->iterator_methods.seek_time) {
- ret = bt_component_class_source_set_notification_iterator_seek_time_method(
- comp_class,
- cc_full_descr->iterator_methods.seek_time);
+ break;
+ case BT_COMPONENT_CLASS_TYPE_FILTER:
+ if (cc_full_descr->methods.filter.init) {
+ ret = bt_private_component_class_filter_set_init_method(
+ flt_comp_class,
+ cc_full_descr->methods.filter.init);
if (ret) {
- BT_LOGE_STR("Cannot set source component class's notification iterator seek to time method.");
+ BT_LOGE_STR("Cannot set filter component class's initialization method.");
status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
+ BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
goto end;
}
}
- break;
- case BT_COMPONENT_CLASS_TYPE_FILTER:
- if (cc_full_descr->iterator_methods.init) {
- ret = bt_component_class_filter_set_notification_iterator_init_method(
- comp_class,
- cc_full_descr->iterator_methods.init);
+
+ if (cc_full_descr->methods.filter.finalize) {
+ ret = bt_private_component_class_filter_set_finalize_method(
+ flt_comp_class,
+ cc_full_descr->methods.filter.finalize);
if (ret) {
- BT_LOGE_STR("Cannot set filter component class's notification iterator initialization method.");
+ BT_LOGE_STR("Cannot set filter component class's finalization method.");
status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
+ BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
goto end;
}
}
- if (cc_full_descr->iterator_methods.finalize) {
- ret = bt_component_class_filter_set_notification_iterator_finalize_method(
- comp_class,
- cc_full_descr->iterator_methods.finalize);
+ if (cc_full_descr->methods.filter.query) {
+ ret = bt_private_component_class_filter_set_query_method(
+ flt_comp_class,
+ cc_full_descr->methods.filter.query);
if (ret) {
- BT_LOGE_STR("Cannot set filter component class's notification iterator finalization method.");
+ BT_LOGE_STR("Cannot set filter component class's query method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
+ goto end;
+ }
+ }
+
+ if (cc_full_descr->methods.filter.accept_input_port_connection) {
+ ret = bt_private_component_class_filter_set_accept_input_port_connection_method(
+ flt_comp_class,
+ cc_full_descr->methods.filter.accept_input_port_connection);
+ if (ret) {
+ BT_LOGE_STR("Cannot set filter component class's \"accept input port connection\" method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
+ goto end;
+ }
+ }
+
+ if (cc_full_descr->methods.filter.accept_output_port_connection) {
+ ret = bt_private_component_class_filter_set_accept_output_port_connection_method(
+ flt_comp_class,
+ cc_full_descr->methods.filter.accept_output_port_connection);
+ if (ret) {
+ BT_LOGE_STR("Cannot set filter component class's \"accept input output connection\" method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
+ goto end;
+ }
+ }
+
+ if (cc_full_descr->methods.filter.input_port_connected) {
+ ret = bt_private_component_class_filter_set_input_port_connected_method(
+ flt_comp_class,
+ cc_full_descr->methods.filter.input_port_connected);
+ if (ret) {
+ BT_LOGE_STR("Cannot set filter component class's \"input port connected\" method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
+ goto end;
+ }
+ }
+
+ if (cc_full_descr->methods.filter.output_port_connected) {
+ ret = bt_private_component_class_filter_set_output_port_connected_method(
+ flt_comp_class,
+ cc_full_descr->methods.filter.output_port_connected);
+ if (ret) {
+ BT_LOGE_STR("Cannot set filter component class's \"output port connected\" method.");
status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
+ BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
goto end;
}
}
- if (cc_full_descr->iterator_methods.seek_time) {
- ret = bt_component_class_filter_set_notification_iterator_seek_time_method(
- comp_class,
- cc_full_descr->iterator_methods.seek_time);
+ if (cc_full_descr->methods.filter.input_port_disconnected) {
+ ret = bt_private_component_class_filter_set_input_port_disconnected_method(
+ flt_comp_class,
+ cc_full_descr->methods.filter.input_port_disconnected);
if (ret) {
- BT_LOGE_STR("Cannot set filter component class's notification iterator seek to time method.");
+ BT_LOGE_STR("Cannot set filter component class's \"input port disconnected\" method.");
status = BT_PLUGIN_STATUS_ERROR;
- BT_PUT(comp_class);
+ BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
goto end;
}
}
+
+ if (cc_full_descr->methods.filter.output_port_disconnected) {
+ ret = bt_private_component_class_filter_set_output_port_disconnected_method(
+ flt_comp_class,
+ cc_full_descr->methods.filter.output_port_disconnected);
+ if (ret) {
+ BT_LOGE_STR("Cannot set filter component class's \"output port disconnected\" method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
+ goto end;
+ }
+ }
+
+ if (cc_full_descr->methods.filter.notif_iter_init) {
+ ret = bt_private_component_class_filter_set_notification_iterator_init_method(
+ flt_comp_class,
+ cc_full_descr->methods.filter.notif_iter_init);
+ if (ret) {
+ BT_LOGE_STR("Cannot set filter component class's notification iterator initialization method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
+ goto end;
+ }
+ }
+
+ if (cc_full_descr->methods.filter.notif_iter_finalize) {
+ ret = bt_private_component_class_filter_set_notification_iterator_finalize_method(
+ flt_comp_class,
+ cc_full_descr->methods.filter.notif_iter_finalize);
+ if (ret) {
+ BT_LOGE_STR("Cannot set filter component class's notification iterator finalization method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
+ goto end;
+ }
+ }
+
break;
case BT_COMPONENT_CLASS_TYPE_SINK:
+ if (cc_full_descr->methods.sink.init) {
+ ret = bt_private_component_class_sink_set_init_method(
+ sink_comp_class,
+ cc_full_descr->methods.sink.init);
+ if (ret) {
+ BT_LOGE_STR("Cannot set sink component class's initialization method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
+ goto end;
+ }
+ }
+
+ if (cc_full_descr->methods.sink.finalize) {
+ ret = bt_private_component_class_sink_set_finalize_method(
+ sink_comp_class,
+ cc_full_descr->methods.sink.finalize);
+ if (ret) {
+ BT_LOGE_STR("Cannot set sink component class's finalization method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
+ goto end;
+ }
+ }
+
+ if (cc_full_descr->methods.sink.query) {
+ ret = bt_private_component_class_sink_set_query_method(
+ sink_comp_class,
+ cc_full_descr->methods.sink.query);
+ if (ret) {
+ BT_LOGE_STR("Cannot set sink component class's query method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
+ goto end;
+ }
+ }
+
+ if (cc_full_descr->methods.sink.accept_input_port_connection) {
+ ret = bt_private_component_class_sink_set_accept_input_port_connection_method(
+ sink_comp_class,
+ cc_full_descr->methods.sink.accept_input_port_connection);
+ if (ret) {
+ BT_LOGE_STR("Cannot set sink component class's \"accept input port connection\" method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
+ goto end;
+ }
+ }
+
+ if (cc_full_descr->methods.sink.input_port_connected) {
+ ret = bt_private_component_class_sink_set_input_port_connected_method(
+ sink_comp_class,
+ cc_full_descr->methods.sink.input_port_connected);
+ if (ret) {
+ BT_LOGE_STR("Cannot set sink component class's \"input port connected\" method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
+ goto end;
+ }
+ }
+
+ if (cc_full_descr->methods.sink.input_port_disconnected) {
+ ret = bt_private_component_class_sink_set_input_port_disconnected_method(
+ sink_comp_class,
+ cc_full_descr->methods.sink.input_port_disconnected);
+ if (ret) {
+ BT_LOGE_STR("Cannot set sink component class's \"input port disconnected\" method.");
+ status = BT_PLUGIN_STATUS_ERROR;
+ BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
+ goto end;
+ }
+ }
+
break;
default:
abort();
*
* This will call back
* bt_plugin_so_on_add_component_class() so that we can
- * add a mapping in comp_classes_to_shlib_handles when
- * we know the component class is successfully added.
+ * add a mapping in the component class list when we
+ * know the component class is successfully added.
*/
status = bt_plugin_add_component_class(plugin,
- comp_class);
- BT_PUT(comp_class);
+ (void *) comp_class);
+ BT_OBJECT_PUT_REF_AND_RESET(comp_class);
if (status < 0) {
BT_LOGE("Cannot add component class to plugin.");
goto end;
}
}
- /*
- * All the plugin's component classes should be added at this
- * point. We freeze the plugin so that it's not possible to add
- * component classes to this plugin object after this stage
- * (plugin object becomes immutable).
- */
- bt_plugin_freeze(plugin);
-
end:
g_array_free(comp_class_full_descriptors, TRUE);
return status;
}
spec = plugin->spec_data;
- spec->shared_lib_handle = bt_get(shared_lib_handle);
+ spec->shared_lib_handle = bt_object_get_ref(shared_lib_handle);
goto end;
error:
- BT_PUT(plugin);
+ BT_OBJECT_PUT_REF_AND_RESET(plugin);
end:
return plugin;
}
+static
+size_t count_non_null_items_in_section(const void *begin, const void *end)
+{
+ size_t count = 0;
+ const int * const *begin_int = (const int * const *) begin;
+ const int * const *end_int = (const int * const *) end;
+ const int * const *iter;
+
+ for (iter = begin_int; iter != end_int; iter++) {
+ if (*iter) {
+ count++;
+ }
+ }
+
+ return count;
+}
+
static
struct bt_plugin_set *bt_plugin_so_create_all_from_sections(
struct bt_plugin_so_shared_lib_handle *shared_lib_handle,
size_t i;
struct bt_plugin_set *plugin_set = NULL;
- descriptor_count = descriptors_end - descriptors_begin;
- attrs_count = attrs_end - attrs_begin;
- cc_descriptors_count = cc_descriptors_end - cc_descriptors_begin;
- cc_descr_attrs_count = cc_descr_attrs_end - cc_descr_attrs_begin;
+ descriptor_count = count_non_null_items_in_section(descriptors_begin, descriptors_end);
+ attrs_count = count_non_null_items_in_section(attrs_begin, attrs_end);
+ cc_descriptors_count = count_non_null_items_in_section(cc_descriptors_begin, cc_descriptors_end);
+ cc_descr_attrs_count = count_non_null_items_in_section(cc_descr_attrs_begin, cc_descr_attrs_end);
BT_LOGD("Creating all SO plugins from sections: "
"plugin-path=\"%s\", "
goto error;
}
- for (i = 0; i < descriptor_count; i++) {
+ for (i = 0; i < descriptors_end - descriptors_begin; i++) {
enum bt_plugin_status status;
const struct __bt_plugin_descriptor *descriptor =
descriptors_begin[i];
struct bt_plugin *plugin;
+ if (descriptor == NULL) {
+ continue;
+ }
+
BT_LOGD("Creating plugin object for plugin: "
"name=\"%s\", abi-major=%d, abi-minor=%d",
descriptor->name, descriptor->major, descriptor->minor);
if (descriptor->major > __BT_PLUGIN_VERSION_MAJOR) {
- BT_LOGW("Unknown ABI major version: abi-major=%d",
+ /*
+ * DEBUG-level logging because we're only
+ * _trying_ to open this file as a compatible
+ * Babeltrace plugin: if it's not, it's not an
+ * error. And because this can be tried during
+ * bt_plugin_create_all_from_dir(), it's not
+ * even a warning.
+ */
+ BT_LOGD("Unknown ABI major version: abi-major=%d",
descriptor->major);
goto error;
}
attrs_end, cc_descriptors_begin, cc_descriptors_end,
cc_descr_attrs_begin, cc_descr_attrs_end);
if (status < 0) {
- BT_LOGW_STR("Cannot initialize SO plugin object from sections.");
- BT_PUT(plugin);
+ /*
+ * DEBUG-level logging because we're only
+ * _trying_ to open this file as a compatible
+ * Babeltrace plugin: if it's not, it's not an
+ * error. And because this can be tried during
+ * bt_plugin_create_all_from_dir(), it's not
+ * even a warning.
+ */
+ BT_LOGD_STR("Cannot initialize SO plugin object from sections.");
+ BT_OBJECT_PUT_REF_AND_RESET(plugin);
goto error;
}
/* Add to plugin set */
bt_plugin_set_add_plugin(plugin_set, plugin);
- bt_put(plugin);
+ bt_object_put_ref(plugin);
}
goto end;
error:
- BT_PUT(plugin_set);
+ BT_OBJECT_PUT_REF_AND_RESET(plugin_set);
end:
return plugin_set;
BT_LOGD_STR("Creating all SO plugins from built-in plugins.");
plugin_set = bt_plugin_so_create_all_from_sections(shared_lib_handle,
- SECTION_BEGIN(__bt_plugin_descriptors),
- SECTION_END(__bt_plugin_descriptors),
- SECTION_BEGIN(__bt_plugin_descriptor_attributes),
- SECTION_END(__bt_plugin_descriptor_attributes),
- SECTION_BEGIN(__bt_plugin_component_class_descriptors),
- SECTION_END(__bt_plugin_component_class_descriptors),
- SECTION_BEGIN(__bt_plugin_component_class_descriptor_attributes),
- SECTION_END(__bt_plugin_component_class_descriptor_attributes));
+ __bt_get_begin_section_plugin_descriptors(),
+ __bt_get_end_section_plugin_descriptors(),
+ __bt_get_begin_section_plugin_descriptor_attributes(),
+ __bt_get_end_section_plugin_descriptor_attributes(),
+ __bt_get_begin_section_component_class_descriptors(),
+ __bt_get_end_section_component_class_descriptors(),
+ __bt_get_begin_section_component_class_descriptor_attributes(),
+ __bt_get_end_section_component_class_descriptor_attributes());
end:
- BT_PUT(shared_lib_handle);
+ BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle);
return plugin_set;
}
struct __bt_plugin_component_class_descriptor const * const *cc_descriptors_end = NULL;
struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_begin = NULL;
struct __bt_plugin_component_class_descriptor_attribute const * const *cc_descr_attrs_end = NULL;
+ struct __bt_plugin_descriptor const * const *(*get_begin_section_plugin_descriptors)(void);
+ struct __bt_plugin_descriptor const * const *(*get_end_section_plugin_descriptors)(void);
+ struct __bt_plugin_descriptor_attribute const * const *(*get_begin_section_plugin_descriptor_attributes)(void);
+ struct __bt_plugin_descriptor_attribute const * const *(*get_end_section_plugin_descriptor_attributes)(void);
+ struct __bt_plugin_component_class_descriptor const * const *(*get_begin_section_component_class_descriptors)(void);
+ struct __bt_plugin_component_class_descriptor const * const *(*get_end_section_component_class_descriptors)(void);
+ struct __bt_plugin_component_class_descriptor_attribute const * const *(*get_begin_section_component_class_descriptor_attributes)(void);
+ struct __bt_plugin_component_class_descriptor_attribute const * const *(*get_end_section_component_class_descriptor_attributes)(void);
bt_bool is_libtool_wrapper = BT_FALSE, is_shared_object = BT_FALSE;
struct bt_plugin_so_shared_lib_handle *shared_lib_handle = NULL;
shared_lib_handle = bt_plugin_so_shared_lib_handle_create(path);
if (!shared_lib_handle) {
- BT_LOGW_STR("Cannot create shared library handle.");
+ BT_LOGD_STR("Cannot create shared library handle.");
goto end;
}
- if (!g_module_symbol(shared_lib_handle->module, "__start___bt_plugin_descriptors",
- (gpointer *) &descriptors_begin)) {
+ if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_plugin_descriptors",
+ (gpointer *) &get_begin_section_plugin_descriptors)) {
+ descriptors_begin = get_begin_section_plugin_descriptors();
+ } else {
BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
"symbol=\"%s\"", path,
- "__start___bt_plugin_descriptors");
+ "__bt_get_begin_section_plugin_descriptors");
goto end;
}
- if (!g_module_symbol(shared_lib_handle->module, "__stop___bt_plugin_descriptors",
- (gpointer *) &descriptors_end)) {
+ if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_plugin_descriptors",
+ (gpointer *) &get_end_section_plugin_descriptors)) {
+ descriptors_end = get_end_section_plugin_descriptors();
+ } else {
BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
"symbol=\"%s\"", path,
- "__stop___bt_plugin_descriptors");
+ "__bt_get_end_section_plugin_descriptors");
goto end;
}
- if (!g_module_symbol(shared_lib_handle->module, "__start___bt_plugin_descriptor_attributes",
- (gpointer *) &attrs_begin)) {
+ if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_plugin_descriptor_attributes",
+ (gpointer *) &get_begin_section_plugin_descriptor_attributes)) {
+ attrs_begin = get_begin_section_plugin_descriptor_attributes();
+ } else {
BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
"symbol=\"%s\"", path,
- "__start___bt_plugin_descriptor_attributes");
+ "__bt_get_begin_section_plugin_descriptor_attributes");
}
- if (!g_module_symbol(shared_lib_handle->module, "__stop___bt_plugin_descriptor_attributes",
- (gpointer *) &attrs_end)) {
+ if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_plugin_descriptor_attributes",
+ (gpointer *) &get_end_section_plugin_descriptor_attributes)) {
+ attrs_end = get_end_section_plugin_descriptor_attributes();
+ } else {
BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
"symbol=\"%s\"", path,
- "__stop___bt_plugin_descriptor_attributes");
+ "__bt_get_end_section_plugin_descriptor_attributes");
}
if ((!!attrs_begin - !!attrs_end) != 0) {
"path=\"%s\", symbol-start=\"%s\", "
"symbol-end=\"%s\", symbol-start-addr=%p, "
"symbol-end-addr=%p",
- path, "__start___bt_plugin_descriptor_attributes",
- "__stop___bt_plugin_descriptor_attributes",
+ path, "__bt_get_begin_section_plugin_descriptor_attributes",
+ "__bt_get_end_section_plugin_descriptor_attributes",
attrs_begin, attrs_end);
goto end;
}
- if (!g_module_symbol(shared_lib_handle->module, "__start___bt_plugin_component_class_descriptors",
- (gpointer *) &cc_descriptors_begin)) {
+ if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_component_class_descriptors",
+ (gpointer *) &get_begin_section_component_class_descriptors)) {
+ cc_descriptors_begin = get_begin_section_component_class_descriptors();
+ } else {
BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
"symbol=\"%s\"", path,
- "__start___bt_plugin_component_class_descriptors");
+ "__bt_get_begin_section_component_class_descriptors");
}
- if (!g_module_symbol(shared_lib_handle->module, "__stop___bt_plugin_component_class_descriptors",
- (gpointer *) &cc_descriptors_end)) {
+ if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_component_class_descriptors",
+ (gpointer *) &get_end_section_component_class_descriptors)) {
+ cc_descriptors_end = get_end_section_component_class_descriptors();
+ } else {
BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
"symbol=\"%s\"", path,
- "__stop___bt_plugin_component_class_descriptors");
+ "__bt_get_end_section_component_class_descriptors");
}
if ((!!cc_descriptors_begin - !!cc_descriptors_end) != 0) {
"path=\"%s\", symbol-start=\"%s\", "
"symbol-end=\"%s\", symbol-start-addr=%p, "
"symbol-end-addr=%p",
- path, "__start___bt_plugin_component_class_descriptors",
- "__stop___bt_plugin_component_class_descriptors",
+ path, "__bt_get_begin_section_component_class_descriptors",
+ "__bt_get_end_section_component_class_descriptors",
cc_descriptors_begin, cc_descriptors_end);
goto end;
}
- if (!g_module_symbol(shared_lib_handle->module, "__start___bt_plugin_component_class_descriptor_attributes",
- (gpointer *) &cc_descr_attrs_begin)) {
+ if (g_module_symbol(shared_lib_handle->module, "__bt_get_begin_section_component_class_descriptor_attributes",
+ (gpointer *) &get_begin_section_component_class_descriptor_attributes)) {
+ cc_descr_attrs_begin = get_begin_section_component_class_descriptor_attributes();
+ } else {
BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
"symbol=\"%s\"", path,
- "__start___bt_plugin_component_class_descriptor_attributes");
+ "__bt_get_begin_section_component_class_descriptor_attributes");
}
- if (!g_module_symbol(shared_lib_handle->module, "__stop___bt_plugin_component_class_descriptor_attributes",
- (gpointer *) &cc_descr_attrs_end)) {
+ if (g_module_symbol(shared_lib_handle->module, "__bt_get_end_section_component_class_descriptor_attributes",
+ (gpointer *) &get_end_section_component_class_descriptor_attributes)) {
+ cc_descr_attrs_end = get_end_section_component_class_descriptor_attributes();
+ } else {
BT_LOGD("Cannot resolve plugin symbol: path=\"%s\", "
"symbol=\"%s\"", path,
- "__stop___bt_plugin_component_class_descriptor_attributes");
+ "__bt_get_end_section_component_class_descriptor_attributes");
}
if ((!!cc_descr_attrs_begin - !!cc_descr_attrs_end) != 0) {
"path=\"%s\", symbol-start=\"%s\", "
"symbol-end=\"%s\", symbol-start-addr=%p, "
"symbol-end-addr=%p",
- path, "__start___bt_plugin_component_class_descriptor_attributes",
- "__stop___bt_plugin_component_class_descriptor_attributes",
+ path, "__bt_get_begin_section_component_class_descriptor_attributes",
+ "__bt_get_end_section_component_class_descriptor_attributes",
cc_descr_attrs_begin, cc_descr_attrs_end);
goto end;
}
cc_descr_attrs_begin, cc_descr_attrs_end);
end:
- BT_PUT(shared_lib_handle);
+ BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle);
return plugin_set;
}
void plugin_comp_class_destroy_listener(struct bt_component_class *comp_class,
void *data)
{
- gboolean exists = g_hash_table_remove(comp_classes_to_shlib_handles,
- comp_class);
- assert(exists);
- BT_LOGV("Component class destroyed: removed entry from hash table: "
+ bt_list_del(&comp_class->node);
+ BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle);
+ BT_LOGV("Component class destroyed: removed entry from list: "
"comp-cls-addr=%p", comp_class);
}
{
struct bt_plugin_so_spec_data *spec = plugin->spec_data;
- assert(plugin->spec_data);
- assert(plugin->type == BT_PLUGIN_TYPE_SO);
+ BT_ASSERT(plugin->spec_data);
+ BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO);
- /* Map component class pointer to shared lib handle in global HT */
- g_hash_table_insert(comp_classes_to_shlib_handles, comp_class,
- bt_get(spec->shared_lib_handle));
+ bt_list_add(&comp_class->node, &component_class_list);
+ comp_class->so_handle = bt_object_get_ref(spec->shared_lib_handle);
/* Add our custom destroy listener */
bt_component_class_add_destroy_listener(comp_class,