X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fplugin%2Fplugin-so.c;h=ec69646f99fd38f3bb4c4bc20472698aa0aebe18;hb=3fadfbc0c91f82c46bd36e6e0657ea93570c9db1;hp=648f95d1e5af7521a3e5b7fb52d30d5a0b78e3d9;hpb=3fea54f69edd1780566230255da196cb6e82df62;p=babeltrace.git diff --git a/lib/plugin/plugin-so.c b/lib/plugin/plugin-so.c index 648f95d1..ec69646f 100644 --- a/lib/plugin/plugin-so.c +++ b/lib/plugin/plugin-so.c @@ -1,10 +1,6 @@ /* - * plugin-so.c - * - * Babeltrace Plugin (shared object) - * + * Copyright 2017-2018 Philippe Proulx * Copyright 2016 Jérémie Galarneau - * Copyright 2017 Philippe Proulx * * Author: Jérémie Galarneau * @@ -28,18 +24,22 @@ */ #define BT_LOG_TAG "PLUGIN-SO" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -71,7 +71,7 @@ BT_PLUGIN_MODULE(); * * It allows this use-case: * - * my_plugins = bt_plugin_create_all_from_file("/path/to/my-plugin.so"); + * my_plugins = bt_plugin_find_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 @@ -96,11 +96,27 @@ void fini_comp_class_list(void) bt_list_for_each_entry_safe(comp_class, tmp, &component_class_list, node) { bt_list_del(&comp_class->node); - BT_PUT(comp_class->so_handle); + BT_OBJECT_PUT_REF_AND_RESET(comp_class->so_handle); } + BT_LOGD_STR("Released references from all component classes to shared library handles."); } +static inline +const char *bt_self_plugin_status_string(enum bt_self_plugin_status status) +{ + switch (status) { + case BT_SELF_PLUGIN_STATUS_OK: + return "BT_SELF_PLUGIN_STATUS_OK"; + case BT_SELF_PLUGIN_STATUS_ERROR: + return "BT_SELF_PLUGIN_STATUS_ERROR"; + case BT_SELF_PLUGIN_STATUS_NOMEM: + return "BT_SELF_PLUGIN_STATUS_NOMEM"; + default: + return "(unknown)"; + } +} + static void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj) { @@ -116,17 +132,9 @@ void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj) shared_lib_handle, path); if (shared_lib_handle->init_called && shared_lib_handle->exit) { - enum bt_plugin_status status; - BT_LOGD_STR("Calling user's plugin exit function."); - status = shared_lib_handle->exit(); - BT_LOGD("User function returned: %s", - bt_plugin_status_string(status)); - - if (status < 0) { - BT_LOGW("User's plugin exit function failed: " - "path=\"%s\"", path); - } + shared_lib_handle->exit(); + BT_LOGD_STR("User function returned."); } if (shared_lib_handle->module) { @@ -147,6 +155,8 @@ void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj) 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`: " @@ -157,6 +167,7 @@ void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj) if (shared_lib_handle->path) { g_string_free(shared_lib_handle->path, TRUE); + shared_lib_handle->path = NULL; } g_free(shared_lib_handle); @@ -194,7 +205,7 @@ struct bt_plugin_so_shared_lib_handle *bt_plugin_so_shared_lib_handle_create( * 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 + * during bt_plugin_find_all_from_dir(), it's not even * a warning. */ BT_LOGD("Cannot open GModule: %s: path=\"%s\"", @@ -205,7 +216,7 @@ struct bt_plugin_so_shared_lib_handle *bt_plugin_so_shared_lib_handle_create( goto end; error: - BT_PUT(shared_lib_handle); + BT_OBJECT_PUT_REF_AND_RESET(shared_lib_handle); end: if (shared_lib_handle) { @@ -227,7 +238,7 @@ void bt_plugin_so_destroy_spec_data(struct bt_plugin *plugin) BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO); BT_ASSERT(spec); - BT_PUT(spec->shared_lib_handle); + BT_OBJECT_PUT_REF_AND_RESET(spec->shared_lib_handle); g_free(plugin->spec_data); plugin->spec_data = NULL; } @@ -278,13 +289,47 @@ enum bt_plugin_status bt_plugin_so_init( 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_notification_iterator_methods iterator_methods; + + union { + struct { + bt_component_class_source_init_method init; + bt_component_class_source_finalize_method finalize; + bt_component_class_source_query_method query; + bt_component_class_source_accept_output_port_connection_method accept_output_port_connection; + bt_component_class_source_output_port_connected_method output_port_connected; + bt_component_class_source_message_iterator_init_method msg_iter_init; + bt_component_class_source_message_iterator_finalize_method msg_iter_finalize; + bt_component_class_source_message_iterator_seek_ns_from_origin_method msg_iter_seek_ns_from_origin; + bt_component_class_source_message_iterator_seek_beginning_method msg_iter_seek_beginning; + bt_component_class_source_message_iterator_can_seek_ns_from_origin_method msg_iter_can_seek_ns_from_origin; + bt_component_class_source_message_iterator_can_seek_beginning_method msg_iter_can_seek_beginning; + } source; + + struct { + bt_component_class_filter_init_method init; + bt_component_class_filter_finalize_method finalize; + bt_component_class_filter_query_method query; + bt_component_class_filter_accept_input_port_connection_method accept_input_port_connection; + bt_component_class_filter_accept_output_port_connection_method accept_output_port_connection; + bt_component_class_filter_input_port_connected_method input_port_connected; + bt_component_class_filter_output_port_connected_method output_port_connected; + bt_component_class_filter_message_iterator_init_method msg_iter_init; + bt_component_class_filter_message_iterator_finalize_method msg_iter_finalize; + bt_component_class_filter_message_iterator_seek_ns_from_origin_method msg_iter_seek_ns_from_origin; + bt_component_class_filter_message_iterator_seek_beginning_method msg_iter_seek_beginning; + bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method msg_iter_can_seek_ns_from_origin; + bt_component_class_filter_message_iterator_can_seek_beginning_method msg_iter_can_seek_beginning; + } filter; + + struct { + bt_component_class_sink_init_method init; + bt_component_class_sink_finalize_method finalize; + bt_component_class_sink_query_method query; + bt_component_class_sink_accept_input_port_connection_method accept_input_port_connection; + bt_component_class_sink_input_port_connected_method input_port_connected; + bt_component_class_sink_graph_is_configured_method graph_is_configured; + } sink; + } methods; }; enum bt_plugin_status status = BT_PLUGIN_STATUS_OK; @@ -409,6 +454,7 @@ enum bt_plugin_status bt_plugin_so_init( 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; @@ -419,96 +465,274 @@ enum bt_plugin_status bt_plugin_so_init( 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_COMPONENT_CLASS_TYPE_SINK: + cc_full_descr->methods.sink.init = + cur_cc_descr_attr->value.sink_init_method; + break; + 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_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.finalize = + cur_cc_descr_attr->value.filter_finalize_method; + break; + 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_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.query = + cur_cc_descr_attr->value.filter_query_method; + break; + 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_HELP: - cc_full_descr->help = - cur_cc_descr_attr->value.help; + 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_INIT_METHOD: - cc_full_descr->init_method = - cur_cc_descr_attr->value.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_FINALIZE_METHOD: - cc_full_descr->finalize_method = - cur_cc_descr_attr->value.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_QUERY_METHOD: - cc_full_descr->query_method = - cur_cc_descr_attr->value.query_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; - 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; + default: + 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_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.input_port_connected = + cur_cc_descr_attr->value.sink_input_port_connected_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_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_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_FILTER: + cc_full_descr->methods.filter.output_port_connected = + cur_cc_descr_attr->value.filter_output_port_connected_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_GRAPH_IS_CONFIGURED_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SINK: + cc_full_descr->methods.sink.graph_is_configured = + cur_cc_descr_attr->value.sink_graph_is_configured_method; 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); + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INIT_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.msg_iter_init = + cur_cc_descr_attr->value.source_msg_iter_init_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.msg_iter_init = + cur_cc_descr_attr->value.filter_msg_iter_init_method; break; + default: + abort(); } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_FINALIZE_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.msg_iter_finalize = + cur_cc_descr_attr->value.source_msg_iter_finalize_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.msg_iter_finalize = + cur_cc_descr_attr->value.filter_msg_iter_finalize_method; + break; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_NS_FROM_ORIGIN_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.msg_iter_seek_ns_from_origin = + cur_cc_descr_attr->value.source_msg_iter_seek_ns_from_origin_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin = + cur_cc_descr_attr->value.filter_msg_iter_seek_ns_from_origin_method; + break; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_SEEK_BEGINNING_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.msg_iter_seek_beginning = + cur_cc_descr_attr->value.source_msg_iter_seek_beginning_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.msg_iter_seek_beginning = + cur_cc_descr_attr->value.filter_msg_iter_seek_beginning_method; + break; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_NS_FROM_ORIGIN_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin = + cur_cc_descr_attr->value.source_msg_iter_can_seek_ns_from_origin_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin = + cur_cc_descr_attr->value.filter_msg_iter_can_seek_ns_from_origin_method; + break; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_CAN_SEEK_BEGINNING_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.msg_iter_can_seek_beginning = + cur_cc_descr_attr->value.source_msg_iter_can_seek_beginning_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.msg_iter_can_seek_beginning = + cur_cc_descr_attr->value.filter_msg_iter_can_seek_beginning_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; } } } /* Initialize plugin */ if (spec->init) { + enum bt_self_plugin_status init_status; + BT_LOGD_STR("Calling user's plugin initialization function."); - status = spec->init(plugin); + init_status = spec->init((void *) plugin); BT_LOGD("User function returned: %s", - bt_plugin_status_string(status)); + bt_self_plugin_status_string(init_status)); - if (status < 0) { + if (init_status < 0) { BT_LOGW_STR("User's plugin initialization function failed."); + status = BT_PLUGIN_STATUS_ERROR; goto end; } } @@ -520,7 +744,10 @@ enum bt_plugin_status bt_plugin_so_init( 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_component_class *comp_class = NULL; + struct bt_component_class_source *src_comp_class = NULL; + struct bt_component_class_filter *flt_comp_class = NULL; + struct bt_component_class_sink *sink_comp_class = NULL; BT_LOGD("Creating and setting properties of plugin's component class: " "plugin-path=\"%s\", plugin-name=\"%s\", " @@ -535,19 +762,25 @@ enum bt_plugin_status bt_plugin_so_init( switch (cc_full_descr->descriptor->type) { case BT_COMPONENT_CLASS_TYPE_SOURCE: - comp_class = bt_component_class_source_create( + src_comp_class = bt_component_class_source_create( cc_full_descr->descriptor->name, - cc_full_descr->descriptor->methods.source.notif_iter_next); + cc_full_descr->descriptor->methods.source.msg_iter_next); + comp_class = bt_component_class_source_as_component_class( + src_comp_class); break; case BT_COMPONENT_CLASS_TYPE_FILTER: - comp_class = bt_component_class_filter_create( + flt_comp_class = bt_component_class_filter_create( cc_full_descr->descriptor->name, - cc_full_descr->descriptor->methods.source.notif_iter_next); + cc_full_descr->descriptor->methods.source.msg_iter_next); + comp_class = bt_component_class_filter_as_component_class( + flt_comp_class); break; case BT_COMPONENT_CLASS_TYPE_SINK: - comp_class = bt_component_class_sink_create( + sink_comp_class = bt_component_class_sink_create( cc_full_descr->descriptor->name, cc_full_descr->descriptor->methods.sink.consume); + comp_class = bt_component_class_sink_as_component_class( + sink_comp_class); break; default: /* @@ -576,12 +809,12 @@ enum bt_plugin_status bt_plugin_so_init( } if (cc_full_descr->description) { - ret = bt_component_class_set_description(comp_class, - cc_full_descr->description); + ret = bt_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; } } @@ -592,129 +825,377 @@ enum bt_plugin_status bt_plugin_so_init( 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_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_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_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_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_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.msg_iter_init) { + ret = bt_component_class_source_set_message_iterator_init_method( + src_comp_class, + cc_full_descr->methods.source.msg_iter_init); + if (ret) { + BT_LOGE_STR("Cannot set source component class's message iterator initialization 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.msg_iter_finalize) { + ret = bt_component_class_source_set_message_iterator_finalize_method( + src_comp_class, + cc_full_descr->methods.source.msg_iter_finalize); if (ret) { - BT_LOGE_STR("Cannot set component class's notification iterator initialization method."); + BT_LOGE_STR("Cannot set source component class's message 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.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.msg_iter_seek_ns_from_origin) { + ret = bt_component_class_source_set_message_iterator_seek_ns_from_origin_method( + src_comp_class, + cc_full_descr->methods.source.msg_iter_seek_ns_from_origin); if (ret) { - BT_LOGE_STR("Cannot set source component class's notification iterator finalization method."); + BT_LOGE_STR("Cannot set source component class's message iterator \"seek nanoseconds from origin\" 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->methods.source.msg_iter_seek_beginning) { + ret = bt_component_class_source_set_message_iterator_seek_beginning_method( + src_comp_class, + cc_full_descr->methods.source.msg_iter_seek_beginning); + if (ret) { + BT_LOGE_STR("Cannot set source component class's message iterator \"seek beginning\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin) { + ret = bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method( + src_comp_class, + cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin); + if (ret) { + BT_LOGE_STR("Cannot set source component class's message iterator \"can seek nanoseconds from origin\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.source.msg_iter_can_seek_beginning) { + ret = bt_component_class_source_set_message_iterator_can_seek_beginning_method( + src_comp_class, + cc_full_descr->methods.source.msg_iter_can_seek_beginning); + if (ret) { + BT_LOGE_STR("Cannot set source component class's message iterator \"can seek beginning\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(src_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.init) { + ret = bt_component_class_filter_set_init_method( + flt_comp_class, + cc_full_descr->methods.filter.init); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's initialization method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.finalize) { + ret = bt_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 finalization method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.query) { + ret = bt_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 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_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_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_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_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_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.msg_iter_init) { + ret = bt_component_class_filter_set_message_iterator_init_method( + flt_comp_class, + cc_full_descr->methods.filter.msg_iter_init); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's message 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.msg_iter_finalize) { + ret = bt_component_class_filter_set_message_iterator_finalize_method( + flt_comp_class, + cc_full_descr->methods.filter.msg_iter_finalize); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's message iterator finalization method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin) { + ret = bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method( + flt_comp_class, + cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin); if (ret) { - BT_LOGE_STR("Cannot set filter component class's notification iterator initialization method."); + BT_LOGE_STR("Cannot set filter component class's message iterator \"seek nanoseconds from origin\" 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.msg_iter_seek_beginning) { + ret = bt_component_class_filter_set_message_iterator_seek_beginning_method( + flt_comp_class, + cc_full_descr->methods.filter.msg_iter_seek_beginning); if (ret) { - BT_LOGE_STR("Cannot set filter component class's notification iterator finalization method."); + BT_LOGE_STR("Cannot set filter component class's message iterator \"seek beginning\" 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.msg_iter_can_seek_ns_from_origin) { + ret = bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method( + flt_comp_class, + cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's message iterator \"can seek nanoseconds from origin\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + goto end; + } + } + + if (cc_full_descr->methods.filter.msg_iter_can_seek_beginning) { + ret = bt_component_class_filter_set_message_iterator_can_seek_beginning_method( + flt_comp_class, + cc_full_descr->methods.filter.msg_iter_can_seek_beginning); + if (ret) { + BT_LOGE_STR("Cannot set filter component class's message iterator \"can seek beginning\" 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_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_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_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_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_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.graph_is_configured) { + ret = bt_component_class_sink_set_graph_is_configured_method( + sink_comp_class, + cc_full_descr->methods.sink.graph_is_configured); + if (ret) { + BT_LOGE_STR("Cannot set sink component class's \"graph is configured\" method."); + status = BT_PLUGIN_STATUS_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class); + goto end; + } + } + break; default: abort(); @@ -725,26 +1206,18 @@ enum bt_plugin_status bt_plugin_so_init( * * This will call back * bt_plugin_so_on_add_component_class() so that we can - * add a mapping in the component class list 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; @@ -770,11 +1243,12 @@ struct bt_plugin *bt_plugin_so_create_empty( } spec = plugin->spec_data; - spec->shared_lib_handle = bt_get(shared_lib_handle); + spec->shared_lib_handle = shared_lib_handle; + bt_object_get_no_null_check(spec->shared_lib_handle); goto end; error: - BT_PUT(plugin); + BT_OBJECT_PUT_REF_AND_RESET(plugin); end: return plugin; @@ -862,7 +1336,7 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_sections( * _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 + * bt_plugin_find_all_from_dir(), it's not * even a warning. */ BT_LOGD("Unknown ABI major version: abi-major=%d", @@ -889,23 +1363,23 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_sections( * _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 + * bt_plugin_find_all_from_dir(), it's not * even a warning. */ BT_LOGD_STR("Cannot initialize SO plugin object from sections."); - BT_PUT(plugin); + 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; @@ -934,7 +1408,7 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_static(void) __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; } @@ -1114,7 +1588,7 @@ struct bt_plugin_set *bt_plugin_so_create_all_from_file(const char *path) 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; } @@ -1123,12 +1597,11 @@ void plugin_comp_class_destroy_listener(struct bt_component_class *comp_class, void *data) { bt_list_del(&comp_class->node); - BT_PUT(comp_class->so_handle); + 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); } -BT_HIDDEN void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin, struct bt_component_class *comp_class) { @@ -1138,7 +1611,8 @@ void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin, BT_ASSERT(plugin->type == BT_PLUGIN_TYPE_SO); bt_list_add(&comp_class->node, &component_class_list); - comp_class->so_handle = bt_get(spec->shared_lib_handle); + comp_class->so_handle = spec->shared_lib_handle; + bt_object_get_no_null_check(comp_class->so_handle); /* Add our custom destroy listener */ bt_component_class_add_destroy_listener(comp_class,