lib: rename bt_value_array_get_size() -> bt_value_array_get_length()
[babeltrace.git] / src / cli / babeltrace2.c
index 1675446eaee7f6e772eec48fead761d3ad56879a..11f63494bc074c6cdc8b858c97c06987652e6a12 100644 (file)
@@ -375,7 +375,7 @@ void print_value_rec(FILE *fp, const bt_value *value, size_t indent)
                        bt_common_color_reset());
                break;
        case BT_VALUE_TYPE_ARRAY:
-               size = bt_value_array_get_size(value);
+               size = bt_value_array_get_length(value);
                if (size < 0) {
                        goto error;
                }
@@ -966,7 +966,7 @@ int cmd_print_lttng_live_sessions(struct bt_config *cfg)
                }
        }
 
-       array_size = bt_value_array_get_size(results);
+       array_size = bt_value_array_get_length(results);
        for (i = 0; i < array_size; i++) {
                const char *url_text;
                int64_t timer_us, streams, clients;
@@ -1710,11 +1710,138 @@ void cmd_run_ctx_destroy(struct cmd_run_ctx *ctx)
        ctx->cfg = NULL;
 }
 
+static
+int add_descriptor_to_component_descriptor_set(
+               bt_component_descriptor_set *comp_descr_set,
+               const char *plugin_name, const char *comp_cls_name,
+               bt_component_class_type comp_cls_type,
+               const bt_value *params)
+{
+       const bt_component_class *comp_cls;
+       int status = 0;
+
+       comp_cls = find_component_class(plugin_name, comp_cls_name,
+               comp_cls_type);
+       if (!comp_cls) {
+               BT_CLI_LOGE_APPEND_CAUSE(
+                       "Cannot find component class: plugin-name=\"%s\", "
+                       "comp-cls-name=\"%s\", comp-cls-type=%d",
+                       plugin_name, comp_cls_name, comp_cls_type);
+               status = -1;
+               goto end;
+       }
+
+       status = bt_component_descriptor_set_add_descriptor(
+               comp_descr_set, comp_cls, params);
+       if (status != BT_COMPONENT_DESCRIPTOR_SET_ADD_DESCRIPTOR_STATUS_OK) {
+               BT_CLI_LOGE_APPEND_CAUSE(
+                       "Cannot append descriptor to component descriptor set: "
+                       "status=%s", bt_common_func_status_string(status));
+               goto end;
+       }
+
+end:
+       bt_component_class_put_ref(comp_cls);
+       return status;
+}
+
+static
+int append_descriptors_from_bt_config_component_array(
+               bt_component_descriptor_set *comp_descr_set,
+               GPtrArray *component_configs)
+{
+       int ret = 0;
+       uint64_t i;
+
+       for (i = 0; i < component_configs->len; i++) {
+               struct bt_config_component *cfg_comp =
+                       component_configs->pdata[i];
+
+               ret = add_descriptor_to_component_descriptor_set(
+                       comp_descr_set,
+                       cfg_comp->plugin_name->str,
+                       cfg_comp->comp_cls_name->str,
+                       cfg_comp->type, cfg_comp->params);
+               if (ret) {
+                       goto end;
+               }
+       }
+
+end:
+       return ret;
+}
+
+static
+bt_get_greatest_operative_mip_version_status get_greatest_operative_mip_version(
+               struct bt_config *cfg, uint64_t *mip_version)
+{
+       bt_get_greatest_operative_mip_version_status status =
+               BT_GET_GREATEST_OPERATIVE_MIP_VERSION_STATUS_OK;
+       bt_component_descriptor_set *comp_descr_set = NULL;
+       int ret;
+
+       BT_ASSERT(cfg);
+       BT_ASSERT(mip_version);
+       comp_descr_set = bt_component_descriptor_set_create();
+       if (!comp_descr_set) {
+               BT_CLI_LOGE_APPEND_CAUSE(
+                       "Failed to create a component descriptor set object.");
+               status = BT_GET_GREATEST_OPERATIVE_MIP_VERSION_STATUS_MEMORY_ERROR;
+               goto end;
+       }
+
+       ret = append_descriptors_from_bt_config_component_array(
+               comp_descr_set, cfg->cmd_data.run.sources);
+       if (ret) {
+               status = BT_GET_GREATEST_OPERATIVE_MIP_VERSION_STATUS_ERROR;
+               goto end;
+       }
+
+       ret = append_descriptors_from_bt_config_component_array(
+               comp_descr_set, cfg->cmd_data.run.filters);
+       if (ret) {
+               status = BT_GET_GREATEST_OPERATIVE_MIP_VERSION_STATUS_ERROR;
+               goto end;
+       }
+
+       ret = append_descriptors_from_bt_config_component_array(
+               comp_descr_set, cfg->cmd_data.run.sinks);
+       if (ret) {
+               status = BT_GET_GREATEST_OPERATIVE_MIP_VERSION_STATUS_ERROR;
+               goto end;
+       }
+
+       if (cfg->cmd_data.run.stream_intersection_mode) {
+               /*
+                * Stream intersection mode adds `flt.utils.trimmer`
+                * components; we need to include this type of component
+                * in the component descriptor set to get the real
+                * greatest operative MIP version.
+                */
+               ret = add_descriptor_to_component_descriptor_set(
+                       comp_descr_set, "utils", "trimmer",
+                       BT_COMPONENT_CLASS_TYPE_FILTER, NULL);
+               if (ret) {
+                       status = BT_GET_GREATEST_OPERATIVE_MIP_VERSION_STATUS_ERROR;
+                       goto end;
+               }
+       }
+
+       status = bt_get_greatest_operative_mip_version(comp_descr_set,
+               bt_cli_log_level, mip_version);
+
+end:
+       bt_component_descriptor_set_put_ref(comp_descr_set);
+       return status;
+}
+
 static
 int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg)
 {
        int ret = 0;
        bt_graph_add_listener_status add_listener_status;
+       bt_get_greatest_operative_mip_version_status mip_version_status;
+       uint64_t mip_version = UINT64_C(-1);
 
        ctx->cfg = cfg;
        ctx->connect_ports = false;
@@ -1745,7 +1872,32 @@ int cmd_run_ctx_init(struct cmd_run_ctx *ctx, struct bt_config *cfg)
                }
        }
 
-       ctx->graph = bt_graph_create();
+       /*
+        * Get the greatest operative MIP version to use to configure
+        * the graph to create.
+        */
+       mip_version_status = get_greatest_operative_mip_version(
+               cfg, &mip_version);
+       if (mip_version_status == BT_GET_GREATEST_OPERATIVE_MIP_VERSION_STATUS_NO_MATCH) {
+               BT_CLI_LOGE_APPEND_CAUSE(
+                       "Failed to find an operative message interchange "
+                       "protocol version to use to create the `run` command's "
+                       "graph (components are not interoperable).");
+               goto error;
+       } else if (mip_version_status < 0) {
+               BT_CLI_LOGE_APPEND_CAUSE(
+                       "Cannot find an operative message interchange "
+                       "protocol version to use to create the `run` command's "
+                       "graph: status=%s",
+                       bt_common_func_status_string(mip_version_status));
+               goto error;
+       }
+
+       BT_ASSERT(mip_version_status == BT_GET_GREATEST_OPERATIVE_MIP_VERSION_STATUS_OK);
+       BT_LOGI("Found operative message interchange protocol version to "
+               "configure the `run` command's graph: mip-version=%" PRIu64,
+               mip_version);
+       ctx->graph = bt_graph_create(mip_version);
        if (!ctx->graph) {
                goto error;
        }
@@ -1822,7 +1974,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx,
                goto error;
        }
 
-       trace_count = bt_value_array_get_size(query_result);
+       trace_count = bt_value_array_get_length(query_result);
        if (trace_count < 0) {
                ret = -1;
                goto error;
@@ -1886,7 +2038,7 @@ int set_stream_intersections(struct cmd_run_ctx *ctx,
                        goto error;
                }
 
-               stream_count = bt_value_array_get_size(stream_infos);
+               stream_count = bt_value_array_get_length(stream_infos);
                if (stream_count < 0) {
                        ret = -1;
                        goto error;
@@ -2531,9 +2683,7 @@ void print_error_causes(void)
        }
 
 end:
-       if (folded) {
-               g_string_free(folded, TRUE);
-       }
+       BT_ASSERT(!folded);
 
        if (error) {
                bt_error_release(error);
This page took 0.025674 seconds and 4 git commands to generate.