X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Fplugin%2Fplugin-so.c;h=bbd91692df285045695ff6eec2492b973b1aefa6;hb=f488daa2dcd1cc728456e00bf19200fb6b3a5d0d;hp=319988beeb2dbd1be0406e7a94d89021ddc17cb5;hpb=6b0765905e56acc4abc02903e2d5ba55b3d78265;p=babeltrace.git diff --git a/src/lib/plugin/plugin-so.c b/src/lib/plugin/plugin-so.c index 319988be..bbd91692 100644 --- a/src/lib/plugin/plugin-so.c +++ b/src/lib/plugin/plugin-so.c @@ -288,11 +288,12 @@ int bt_plugin_so_init(struct bt_plugin *plugin, union { struct { - bt_component_class_source_init_method init; + bt_component_class_source_get_supported_mip_versions_method get_supported_mip_versions; + bt_component_class_source_initialize_method init; bt_component_class_source_finalize_method finalize; bt_component_class_source_query_method query; 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_initialize_method msg_iter_initialize; 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; @@ -301,12 +302,13 @@ int bt_plugin_so_init(struct bt_plugin *plugin, } source; struct { - bt_component_class_filter_init_method init; + bt_component_class_filter_get_supported_mip_versions_method get_supported_mip_versions; + bt_component_class_filter_initialize_method init; bt_component_class_filter_finalize_method finalize; bt_component_class_filter_query_method query; 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_initialize_method msg_iter_initialize; 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; @@ -315,7 +317,8 @@ int bt_plugin_so_init(struct bt_plugin *plugin, } filter; struct { - bt_component_class_sink_init_method init; + bt_component_class_sink_get_supported_mip_versions_method get_supported_mip_versions; + bt_component_class_sink_initialize_method init; bt_component_class_sink_finalize_method finalize; bt_component_class_sink_query_method query; bt_component_class_sink_input_port_connected_method input_port_connected; @@ -364,7 +367,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, const struct __bt_plugin_descriptor_attribute *cur_attr = *cur_attr_ptr; - if (cur_attr == NULL) { + if (!cur_attr) { continue; } @@ -406,7 +409,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, NULL, descriptor->name, cur_attr->type_name, cur_attr->type); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; goto end; } else { BT_LIB_LOGW( @@ -434,7 +437,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, *cur_cc_descr_ptr; struct comp_class_full_descriptor full_descriptor = {0}; - if (cur_cc_descr == NULL) { + if (!cur_cc_descr) { continue; } @@ -457,7 +460,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, *cur_cc_descr_attr_ptr; enum bt_component_class_type cc_type; - if (cur_cc_descr_attr == NULL) { + if (!cur_cc_descr_attr) { continue; } @@ -488,19 +491,37 @@ int bt_plugin_so_init(struct bt_plugin *plugin, cc_full_descr->help = cur_cc_descr_attr->value.help; break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INIT_METHOD: + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_GET_SUPPORTED_MIP_VERSIONS_METHOD: + switch (cc_type) { + case BT_COMPONENT_CLASS_TYPE_SOURCE: + cc_full_descr->methods.source.get_supported_mip_versions = + cur_cc_descr_attr->value.source_get_supported_mip_versions_method; + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + cc_full_descr->methods.filter.get_supported_mip_versions = + cur_cc_descr_attr->value.filter_get_supported_mip_versions_method; + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + cc_full_descr->methods.sink.get_supported_mip_versions = + cur_cc_descr_attr->value.sink_get_supported_mip_versions_method; + break; + default: + abort(); + } + break; + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_INITIALIZE_METHOD: switch (cc_type) { case BT_COMPONENT_CLASS_TYPE_SOURCE: cc_full_descr->methods.source.init = - cur_cc_descr_attr->value.source_init_method; + cur_cc_descr_attr->value.source_initialize_method; break; case BT_COMPONENT_CLASS_TYPE_FILTER: cc_full_descr->methods.filter.init = - cur_cc_descr_attr->value.filter_init_method; + cur_cc_descr_attr->value.filter_initialize_method; break; case BT_COMPONENT_CLASS_TYPE_SINK: cc_full_descr->methods.sink.init = - cur_cc_descr_attr->value.sink_init_method; + cur_cc_descr_attr->value.sink_initialize_method; break; default: abort(); @@ -580,15 +601,15 @@ int bt_plugin_so_init(struct bt_plugin *plugin, abort(); } break; - case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INIT_METHOD: + case BT_PLUGIN_COMPONENT_CLASS_DESCRIPTOR_ATTRIBUTE_TYPE_MSG_ITER_INITIALIZE_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; + cc_full_descr->methods.source.msg_iter_initialize = + cur_cc_descr_attr->value.source_msg_iter_initialize_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; + cc_full_descr->methods.filter.msg_iter_initialize = + cur_cc_descr_attr->value.filter_msg_iter_initialize_method; break; default: abort(); @@ -683,7 +704,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, cur_cc_descr_attr->comp_class_descriptor->type), cur_cc_descr_attr->type_name, cur_cc_descr_attr->type); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; goto end; } else { BT_LIB_LOGW( @@ -712,7 +733,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, /* Initialize plugin */ if (spec->init) { - enum bt_plugin_init_func_status init_status; + enum bt_plugin_initialize_func_status init_status; BT_LOGD_STR("Calling user's plugin initialization function."); init_status = spec->init((void *) plugin); @@ -796,7 +817,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin, descriptor->name, cc_full_descr->descriptor->name, cc_full_descr->descriptor->type); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; goto end; } else { BT_LIB_LOGW( @@ -846,8 +867,21 @@ int bt_plugin_so_init(struct bt_plugin *plugin, switch (cc_full_descr->descriptor->type) { case BT_COMPONENT_CLASS_TYPE_SOURCE: + if (cc_full_descr->methods.source.get_supported_mip_versions) { + ret = bt_component_class_source_set_get_supported_mip_versions_method( + src_comp_class, + cc_full_descr->methods.source.get_supported_mip_versions); + if (ret) { + BT_LIB_LOGE_APPEND_CAUSE( + "Cannot set source component class's \"get supported MIP versions\" method."); + status = BT_FUNC_STATUS_MEMORY_ERROR; + BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); + goto end; + } + } + if (cc_full_descr->methods.source.init) { - ret = bt_component_class_source_set_init_method( + ret = bt_component_class_source_set_initialize_method( src_comp_class, cc_full_descr->methods.source.init); if (ret) { @@ -898,10 +932,10 @@ int bt_plugin_so_init(struct bt_plugin *plugin, } } - if (cc_full_descr->methods.source.msg_iter_init) { - ret = bt_component_class_source_set_message_iterator_init_method( + if (cc_full_descr->methods.source.msg_iter_initialize) { + ret = bt_component_class_source_set_message_iterator_initialize_method( src_comp_class, - cc_full_descr->methods.source.msg_iter_init); + cc_full_descr->methods.source.msg_iter_initialize); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( "Cannot set source component class's message iterator initialization method."); @@ -925,12 +959,13 @@ int bt_plugin_so_init(struct bt_plugin *plugin, } 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( + ret = bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods( src_comp_class, - cc_full_descr->methods.source.msg_iter_seek_ns_from_origin); + cc_full_descr->methods.source.msg_iter_seek_ns_from_origin, + cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set source component class's message iterator \"seek nanoseconds from origin\" method."); + "Cannot set source component class's message iterator \"seek nanoseconds from origin\" methods."); status = BT_FUNC_STATUS_MEMORY_ERROR; BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); goto end; @@ -938,48 +973,36 @@ int bt_plugin_so_init(struct bt_plugin *plugin, } 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_LIB_LOGE_APPEND_CAUSE( - "Cannot set source component class's message iterator \"seek beginning\" method."); - status = BT_FUNC_STATUS_MEMORY_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( + ret = bt_component_class_source_set_message_iterator_seek_beginning_methods( src_comp_class, - cc_full_descr->methods.source.msg_iter_can_seek_ns_from_origin); + cc_full_descr->methods.source.msg_iter_seek_beginning, + cc_full_descr->methods.source.msg_iter_can_seek_beginning); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set source component class's message iterator \"can seek nanoseconds from origin\" method."); + "Cannot set source component class's message iterator \"seek beginning\" methods."); status = BT_FUNC_STATUS_MEMORY_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); + break; + case BT_COMPONENT_CLASS_TYPE_FILTER: + if (cc_full_descr->methods.filter.get_supported_mip_versions) { + ret = bt_component_class_filter_set_get_supported_mip_versions_method( + flt_comp_class, + cc_full_descr->methods.filter.get_supported_mip_versions); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set source component class's message iterator \"can seek beginning\" method."); + "Cannot set filter component class's \"get supported MIP versions\" method."); status = BT_FUNC_STATUS_MEMORY_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(src_comp_class); + BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); goto end; } } - break; - case BT_COMPONENT_CLASS_TYPE_FILTER: if (cc_full_descr->methods.filter.init) { - ret = bt_component_class_filter_set_init_method( + ret = bt_component_class_filter_set_initialize_method( flt_comp_class, cc_full_descr->methods.filter.init); if (ret) { @@ -1043,10 +1066,10 @@ int bt_plugin_so_init(struct bt_plugin *plugin, } } - if (cc_full_descr->methods.filter.msg_iter_init) { - ret = bt_component_class_filter_set_message_iterator_init_method( + if (cc_full_descr->methods.filter.msg_iter_initialize) { + ret = bt_component_class_filter_set_message_iterator_initialize_method( flt_comp_class, - cc_full_descr->methods.filter.msg_iter_init); + cc_full_descr->methods.filter.msg_iter_initialize); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( "Cannot set filter component class's message iterator initialization method."); @@ -1070,12 +1093,13 @@ int bt_plugin_so_init(struct bt_plugin *plugin, } 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( + ret = bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods( flt_comp_class, - cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin); + cc_full_descr->methods.filter.msg_iter_seek_ns_from_origin, + cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set filter component class's message iterator \"seek nanoseconds from origin\" method."); + "Cannot set filter component class's message iterator \"seek nanoseconds from origin\" methods."); status = BT_FUNC_STATUS_MEMORY_ERROR; BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); goto end; @@ -1083,48 +1107,36 @@ int bt_plugin_so_init(struct bt_plugin *plugin, } 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_LIB_LOGE_APPEND_CAUSE( - "Cannot set filter component class's message iterator \"seek beginning\" method."); - status = BT_FUNC_STATUS_MEMORY_ERROR; - 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( + ret = bt_component_class_filter_set_message_iterator_seek_beginning_methods( flt_comp_class, - cc_full_descr->methods.filter.msg_iter_can_seek_ns_from_origin); + cc_full_descr->methods.filter.msg_iter_seek_beginning, + cc_full_descr->methods.filter.msg_iter_can_seek_beginning); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set filter component class's message iterator \"can seek nanoseconds from origin\" method."); + "Cannot set filter component class's message iterator \"seek beginning\" methods."); status = BT_FUNC_STATUS_MEMORY_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); + break; + case BT_COMPONENT_CLASS_TYPE_SINK: + if (cc_full_descr->methods.sink.get_supported_mip_versions) { + ret = bt_component_class_sink_set_get_supported_mip_versions_method( + sink_comp_class, + cc_full_descr->methods.sink.get_supported_mip_versions); if (ret) { BT_LIB_LOGE_APPEND_CAUSE( - "Cannot set filter component class's message iterator \"can seek beginning\" method."); + "Cannot set sink component class's \"get supported MIP versions\" method."); status = BT_FUNC_STATUS_MEMORY_ERROR; - BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class); + BT_OBJECT_PUT_REF_AND_RESET(sink_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( + ret = bt_component_class_sink_set_initialize_method( sink_comp_class, cc_full_descr->methods.sink.init); if (ret) { @@ -1238,7 +1250,7 @@ struct bt_plugin *bt_plugin_so_create_empty( spec = plugin->spec_data; spec->shared_lib_handle = shared_lib_handle; - bt_object_get_no_null_check(spec->shared_lib_handle); + bt_object_get_ref_no_null_check(spec->shared_lib_handle); goto end; error: @@ -1286,6 +1298,7 @@ int bt_plugin_so_create_all_from_sections( size_t cc_descr_attrs_count; size_t i; + BT_ASSERT(shared_lib_handle); BT_ASSERT(plugin_set_out); *plugin_set_out = NULL; descriptor_count = count_non_null_items_in_section(descriptors_begin, descriptors_end); @@ -1319,29 +1332,12 @@ int bt_plugin_so_create_all_from_sections( descriptors_begin[i]; struct bt_plugin *plugin; - if (descriptor == NULL) { + if (!descriptor) { continue; } - BT_LOGI("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) { - if (fail_on_load_error) { - BT_LIB_LOGW_APPEND_CAUSE( - "Unknown ABI major version: abi-major=%d", - descriptor->major); - status = BT_FUNC_STATUS_LOADING_ERROR; - goto error; - } else { - BT_LIB_LOGW( - "Unknown ABI major version: abi-major=%d", - descriptor->major); - continue; - } - } - + BT_LOGI("Creating plugin object for plugin: name=\"%s\"", + descriptor->name); plugin = bt_plugin_so_create_empty(shared_lib_handle); if (!plugin) { BT_LIB_LOGE_APPEND_CAUSE( @@ -1350,7 +1346,7 @@ int bt_plugin_so_create_all_from_sections( goto error; } - if (shared_lib_handle && shared_lib_handle->path) { + if (shared_lib_handle->path) { bt_plugin_set_path(plugin, shared_lib_handle->path->str); } @@ -1461,9 +1457,19 @@ int bt_plugin_so_create_all_from_file(const char *path, BT_ASSERT(plugin_set_out); *plugin_set_out = NULL; path_len = strlen(path); - BT_ASSERT_PRE(path_len > PLUGIN_SUFFIX_LEN, - "Path length is too short: path-length=%zu, min-length=%zu", - path_len, PLUGIN_SUFFIX_LEN); + + /* + * An SO plugin file must have a known plugin file suffix. So the file + * path must be longer than the suffix length. + */ + if (path_len <= PLUGIN_SUFFIX_LEN) { + BT_LOGI("Path is too short to be an `.so` or `.la` plugin file:" + "path=%s, path-length=%zu, min-length=%zu", + path, path_len, PLUGIN_SUFFIX_LEN); + status = BT_FUNC_STATUS_NOT_FOUND; + goto end; + } + BT_LOGI("Trying to create all SO plugins from file: path=\"%s\"", path); path_len++; @@ -1522,7 +1528,7 @@ int bt_plugin_so_create_all_from_file(const char *path, "Cannot resolve plugin symbol: path=\"%s\", " "symbol=\"%s\"", path, "__bt_get_end_section_plugin_descriptors"); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { BT_LIB_LOGW( "Cannot resolve plugin symbol: path=\"%s\", " @@ -1562,7 +1568,7 @@ int bt_plugin_so_create_all_from_file(const char *path, path, "__bt_get_begin_section_plugin_descriptor_attributes", "__bt_get_end_section_plugin_descriptor_attributes", attrs_begin, attrs_end); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { BT_LIB_LOGW( "Found section start or end symbol, but not both: " @@ -1606,7 +1612,7 @@ int bt_plugin_so_create_all_from_file(const char *path, path, "__bt_get_begin_section_component_class_descriptors", "__bt_get_end_section_component_class_descriptors", cc_descriptors_begin, cc_descriptors_end); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { BT_LIB_LOGW( "Found section start or end symbol, but not both: " @@ -1650,7 +1656,7 @@ int bt_plugin_so_create_all_from_file(const char *path, 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); - status = BT_FUNC_STATUS_LOADING_ERROR; + status = BT_FUNC_STATUS_ERROR; } else { BT_LIB_LOGW( "Found section start or end symbol, but not both: " @@ -1699,7 +1705,7 @@ void bt_plugin_so_on_add_component_class(struct bt_plugin *plugin, bt_list_add(&comp_class->node, &component_class_list); comp_class->so_handle = spec->shared_lib_handle; - bt_object_get_no_null_check(comp_class->so_handle); + bt_object_get_ref_no_null_check(comp_class->so_handle); /* Add our custom destroy listener */ bt_component_class_add_destroy_listener(comp_class,