lib: add "get supported MIP versions" method support
[babeltrace.git] / src / lib / plugin / plugin-so.c
index 92f47825e72ed1bc6f556b60c86f955905f1f0f6..260fd687e8c086df6c6d7eefacd7948e98e4bc34 100644 (file)
@@ -125,7 +125,7 @@ void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj)
        }
 
        if (shared_lib_handle->module) {
-#ifndef BT_DEBUG_MODE
+#ifdef BT_DEBUG_MODE
                /*
                 * Valgrind shows incomplete stack traces when
                 * dynamically loaded libraries are closed before it
@@ -149,7 +149,7 @@ void bt_plugin_so_shared_lib_handle_destroy(struct bt_object *obj)
                        }
 
                        shared_lib_handle->module = NULL;
-#ifndef BT_DEBUG_MODE
+#ifdef BT_DEBUG_MODE
                } else {
                        BT_LOGI("Not closing GModule because `LIBBABELTRACE2_NO_DLCLOSE=1`: "
                                "path=\"%s\"", path);
@@ -288,6 +288,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
 
                union {
                        struct {
+                               bt_component_class_source_get_supported_mip_versions_method get_supported_mip_versions;
                                bt_component_class_source_init_method init;
                                bt_component_class_source_finalize_method finalize;
                                bt_component_class_source_query_method query;
@@ -301,6 +302,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                        } source;
 
                        struct {
+                               bt_component_class_filter_get_supported_mip_versions_method get_supported_mip_versions;
                                bt_component_class_filter_init_method init;
                                bt_component_class_filter_finalize_method finalize;
                                bt_component_class_filter_query_method query;
@@ -315,6 +317,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                        } filter;
 
                        struct {
+                               bt_component_class_sink_get_supported_mip_versions_method get_supported_mip_versions;
                                bt_component_class_sink_init_method init;
                                bt_component_class_sink_finalize_method finalize;
                                bt_component_class_sink_query_method query;
@@ -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,10 +409,10 @@ 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_LOGI(
+                               BT_LIB_LOGW(
                                        "Ignoring unknown plugin descriptor attribute: "
                                        "plugin-path=\"%s\", plugin-name=\"%s\", "
                                        "attr-type-name=\"%s\", attr-type-id=%d",
@@ -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,6 +491,24 @@ 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_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_INIT_METHOD:
                                switch (cc_type) {
                                case BT_COMPONENT_CLASS_TYPE_SOURCE:
@@ -683,10 +704,10 @@ 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_LOGI(
+                                       BT_LIB_LOGW(
                                                "Ignoring unknown component class descriptor attribute: "
                                                "plugin-path=\"%s\", "
                                                "plugin-name=\"%s\", "
@@ -728,7 +749,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                status = init_status;
                                goto end;
                        } else {
-                               BT_LIB_LOGI(
+                               BT_LIB_LOGW(
                                        "User's plugin initialization function failed: "
                                        "status=%s",
                                        bt_common_func_status_string(init_status));
@@ -796,10 +817,10 @@ 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_LOGI(
+                               BT_LIB_LOGW(
                                        "Ignoring unknown component class type: "
                                        "plugin-path=\"%s\", plugin-name=\"%s\", "
                                        "comp-class-name=\"%s\", comp-class-type=%d",
@@ -846,6 +867,19 @@ 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(
                                        src_comp_class,
@@ -978,6 +1012,19 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
 
                        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 filter component class's \"get supported MIP versions\" method.");
+                                       status = BT_FUNC_STATUS_MEMORY_ERROR;
+                                       BT_OBJECT_PUT_REF_AND_RESET(flt_comp_class);
+                                       goto end;
+                               }
+                       }
+
                        if (cc_full_descr->methods.filter.init) {
                                ret = bt_component_class_filter_set_init_method(
                                        flt_comp_class,
@@ -1123,6 +1170,19 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
 
                        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 sink component class's \"get supported MIP versions\" method.");
+                                       status = BT_FUNC_STATUS_MEMORY_ERROR;
+                                       BT_OBJECT_PUT_REF_AND_RESET(sink_comp_class);
+                                       goto end;
+                               }
+                       }
+
                        if (cc_full_descr->methods.sink.init) {
                                ret = bt_component_class_sink_set_init_method(
                                        sink_comp_class,
@@ -1286,6 +1346,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,7 +1380,7 @@ int bt_plugin_so_create_all_from_sections(
                        descriptors_begin[i];
                struct bt_plugin *plugin;
 
-               if (descriptor == NULL) {
+               if (!descriptor) {
                        continue;
                }
 
@@ -1332,10 +1393,10 @@ int bt_plugin_so_create_all_from_sections(
                                BT_LIB_LOGW_APPEND_CAUSE(
                                        "Unknown ABI major version: abi-major=%d",
                                                descriptor->major);
-                               status = BT_FUNC_STATUS_LOADING_ERROR;
+                               status = BT_FUNC_STATUS_ERROR;
                                goto error;
                        } else {
-                               BT_LIB_LOGI(
+                               BT_LIB_LOGW(
                                        "Unknown ABI major version: abi-major=%d",
                                                descriptor->major);
                                continue;
@@ -1350,7 +1411,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);
                }
@@ -1489,8 +1550,6 @@ int bt_plugin_so_create_all_from_file(const char *path,
        if (status != BT_FUNC_STATUS_OK) {
                /* bt_plugin_so_shared_lib_handle_create() logs more details */
                BT_ASSERT(!shared_lib_handle);
-               BT_LIB_LOGE_APPEND_CAUSE(
-                       "Cannot create shared library handle.");
                goto end;
        }
 
@@ -1524,9 +1583,9 @@ 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_LOGI(
+                       BT_LIB_LOGW(
                                "Cannot resolve plugin symbol: path=\"%s\", "
                                "symbol=\"%s\"", path,
                                "__bt_get_end_section_plugin_descriptors");
@@ -1564,9 +1623,9 @@ 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_LOGI(
+                       BT_LIB_LOGW(
                                "Found section start or end symbol, but not both: "
                                "path=\"%s\", symbol-start=\"%s\", "
                                "symbol-end=\"%s\", symbol-start-addr=%p, "
@@ -1608,9 +1667,9 @@ 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_LOGI(
+                       BT_LIB_LOGW(
                                "Found section start or end symbol, but not both: "
                                "path=\"%s\", symbol-start=\"%s\", "
                                "symbol-end=\"%s\", symbol-start-addr=%p, "
@@ -1652,9 +1711,9 @@ 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_LOGI(
+                       BT_LIB_LOGW(
                                "Found section start or end symbol, but not both: "
                                "path=\"%s\", symbol-start=\"%s\", "
                                "symbol-end=\"%s\", symbol-start-addr=%p, "
This page took 0.028043 seconds and 4 git commands to generate.