common: move bt_component_class_type_string here, use it more
authorSimon Marchi <simon.marchi@efficios.com>
Fri, 10 Sep 2021 03:25:19 +0000 (23:25 -0400)
committerPhilippe Proulx <eeppeliteloop@gmail.com>
Fri, 10 Sep 2021 11:43:37 +0000 (07:43 -0400)
I spotted some messages in the CLI code that could print the component
class type as a string rather than an integer.
bt_component_class_type_string is not accessible to the CLI code,
because it's in a lib header.  Move it to common/common.h, and rename it
accordingly.

Adjust all existing callers, and use it in cli/babeltrace2.c.

Before:

    $ ./src/cli/babeltrace2 query src.ctf.fs foo
    ...
    Failed to query component class: unknown query object: plugin-name="ctf", comp-cls-name="fs", comp-cls-type=1 object="foo"

After:

    $ ./src/cli/babeltrace2 query src.ctf.fs foo
    ...
    Failed to query component class: unknown query object: plugin-name="ctf", comp-cls-name="fs", comp-cls-type=SOURCE object="foo"

Change-Id: I88f01ac7cae9723ce11dbf2ec0843a06d761abb6
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/6273
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/cli/babeltrace2.c
src/common/common.h
src/lib/graph/component-class.c
src/lib/graph/component-class.h
src/lib/lib-logging.c
src/lib/plugin/plugin-so.c
src/python-plugin-provider/python-plugin-provider.c
tests/cli/query/test_query
tests/cli/test_help

index c0acce97e7978446fee28da4e565173def719037..bf6c49d53ede25b6e81ef4a7d877b9dedc5aebe4 100644 (file)
@@ -636,10 +636,11 @@ enum bt_cmd_status cmd_query(struct bt_config *cfg)
        if (!comp_cls) {
                BT_CLI_LOGE_APPEND_CAUSE(
                        "Cannot find component class: plugin-name=\"%s\", "
-                       "comp-cls-name=\"%s\", comp-cls-type=%d",
+                       "comp-cls-name=\"%s\", comp-cls-type=%s",
                        cfg->cmd_data.query.cfg_component->plugin_name->str,
                        cfg->cmd_data.query.cfg_component->comp_cls_name->str,
-                       cfg->cmd_data.query.cfg_component->type);
+                       bt_common_component_class_type_string(
+                               cfg->cmd_data.query.cfg_component->type));
                goto error;
        }
 
@@ -649,11 +650,12 @@ enum bt_cmd_status cmd_query(struct bt_config *cfg)
        if (ret) {
                BT_CLI_LOGE_APPEND_CAUSE(
                        "Failed to query component class: %s: plugin-name=\"%s\", "
-                       "comp-cls-name=\"%s\", comp-cls-type=%d "
+                       "comp-cls-name=\"%s\", comp-cls-type=%s "
                        "object=\"%s\"", fail_reason,
                        cfg->cmd_data.query.cfg_component->plugin_name->str,
                        cfg->cmd_data.query.cfg_component->comp_cls_name->str,
-                       cfg->cmd_data.query.cfg_component->type,
+                       bt_common_component_class_type_string(
+                               cfg->cmd_data.query.cfg_component->type),
                        cfg->cmd_data.query.object->str);
                goto error;
        }
@@ -743,10 +745,11 @@ enum bt_cmd_status cmd_help(struct bt_config *cfg)
        if (!needed_comp_cls) {
                BT_CLI_LOGE_APPEND_CAUSE(
                        "Cannot find component class: plugin-name=\"%s\", "
-                       "comp-cls-name=\"%s\", comp-cls-type=%d",
+                       "comp-cls-name=\"%s\", comp-cls-type=%s",
                        cfg->cmd_data.help.cfg_component->plugin_name->str,
                        cfg->cmd_data.help.cfg_component->comp_cls_name->str,
-                       cfg->cmd_data.help.cfg_component->type);
+                       bt_common_component_class_type_string(
+                               cfg->cmd_data.help.cfg_component->type));
                goto error;
        }
 
@@ -904,9 +907,10 @@ enum bt_cmd_status cmd_print_lttng_live_sessions(struct bt_config *cfg)
        if (!comp_cls) {
                BT_CLI_LOGE_APPEND_CAUSE(
                        "Cannot find component class: plugin-name=\"%s\", "
-                       "comp-cls-name=\"%s\", comp-cls-type=%d",
+                       "comp-cls-name=\"%s\", comp-cls-type=%s",
                        plugin_name, comp_cls_name,
-                       BT_COMPONENT_CLASS_TYPE_SOURCE);
+                       bt_common_component_class_type_string(
+                               BT_COMPONENT_CLASS_TYPE_SOURCE));
                goto error;
        }
 
@@ -1043,9 +1047,10 @@ enum bt_cmd_status cmd_print_ctf_metadata(struct bt_config *cfg)
        if (!comp_cls) {
                BT_CLI_LOGE_APPEND_CAUSE(
                        "Cannot find component class: plugin-name=\"%s\", "
-                       "comp-cls-name=\"%s\", comp-cls-type=%d",
+                       "comp-cls-name=\"%s\", comp-cls-type=%s",
                        plugin_name, comp_cls_name,
-                       BT_COMPONENT_CLASS_TYPE_SOURCE);
+                       bt_common_component_class_type_string(
+                               BT_COMPONENT_CLASS_TYPE_SOURCE));
                goto error;
        }
 
@@ -1702,8 +1707,9 @@ int add_descriptor_to_component_descriptor_set(
        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);
+                       "comp-cls-name=\"%s\", comp-cls-type=%s",
+                       plugin_name, comp_cls_name,
+                       bt_common_component_class_type_string(comp_cls_type));
                status = -1;
                goto end;
        }
@@ -2239,10 +2245,10 @@ int cmd_run_ctx_create_components_from_config_components(
                if (!comp_cls) {
                        BT_CLI_LOGE_APPEND_CAUSE(
                                "Cannot find component class: plugin-name=\"%s\", "
-                               "comp-cls-name=\"%s\", comp-cls-type=%d",
+                               "comp-cls-name=\"%s\", comp-cls-type=%s",
                                cfg_comp->plugin_name->str,
                                cfg_comp->comp_cls_name->str,
-                               cfg_comp->type);
+                               bt_common_component_class_type_string(cfg_comp->type));
                        goto error;
                }
 
@@ -2277,11 +2283,12 @@ int cmd_run_ctx_create_components_from_config_components(
                if (ret) {
                        BT_CLI_LOGE_APPEND_CAUSE(
                                "Cannot create component: plugin-name=\"%s\", "
-                               "comp-cls-name=\"%s\", comp-cls-type=%d, "
+                               "comp-cls-name=\"%s\", comp-cls-type=%s, "
                                "comp-name=\"%s\"",
                                cfg_comp->plugin_name->str,
                                cfg_comp->comp_cls_name->str,
-                               cfg_comp->type, cfg_comp->instance_name->str);
+                               bt_common_component_class_type_string(cfg_comp->type),
+                               cfg_comp->instance_name->str);
                        goto error;
                }
 
index 5266404c934e9e945a129a08c122ecc6cd4f3889..19f4c128443acafbac5b0efe1bd8f6dd42d61539 100644 (file)
@@ -853,6 +853,22 @@ void bt_common_g_string_append_c(GString *str, char c)
        str->str[len + 1] = '\0';
 }
 
+static inline
+const char *bt_common_component_class_type_string(
+               enum bt_component_class_type type)
+{
+       switch (type) {
+       case BT_COMPONENT_CLASS_TYPE_SOURCE:
+               return "SOURCE";
+       case BT_COMPONENT_CLASS_TYPE_SINK:
+               return "SINK";
+       case BT_COMPONENT_CLASS_TYPE_FILTER:
+               return "FILTER";
+       default:
+               return "(unknown)";
+       }
+}
+
 #ifdef __cplusplus
 }
 #endif
index dcdd8e7dd8b4aa46c4c4fa6dbcc186dabd20136b..c3a47291ca0ec86d739e7169d0654015bc36a9fc 100644 (file)
@@ -540,7 +540,7 @@ bt_component_class_set_description(
                "addr=%p, name=\"%s\", type=%s",
                comp_cls,
                bt_component_class_get_name(comp_cls),
-               bt_component_class_type_string(comp_cls->type));
+               bt_common_component_class_type_string(comp_cls->type));
        return BT_FUNC_STATUS_OK;
 }
 
index ac51bcfb064e600b7946211bfa1cc512a0dccaf1..17000909e2535f427a873ef1c85bdcae73eb7acd 100644 (file)
@@ -98,21 +98,6 @@ void _bt_component_class_freeze(
 # define bt_component_class_freeze(_cc)
 #endif
 
-static inline
-const char *bt_component_class_type_string(enum bt_component_class_type type)
-{
-       switch (type) {
-       case BT_COMPONENT_CLASS_TYPE_SOURCE:
-               return "SOURCE";
-       case BT_COMPONENT_CLASS_TYPE_SINK:
-               return "SINK";
-       case BT_COMPONENT_CLASS_TYPE_FILTER:
-               return "FILTER";
-       default:
-               return "(unknown)";
-       }
-}
-
 static inline
 bool bt_component_class_has_message_iterator_class(
        struct bt_component_class *component_class)
index 4085cd26f6a8885c80a513543f46cb2ba6a384c2..8766e4463ef2058f2d30ee1339a7d3a5f9a672d6 100644 (file)
@@ -1057,7 +1057,7 @@ static inline void format_component_class(char **buf_ch, bool extended,
        char tmp_prefix[TMP_PREFIX_LEN];
 
        BUF_APPEND(", %stype=%s, %sname=\"%s\"",
-               PRFIELD(bt_component_class_type_string(comp_class->type)),
+               PRFIELD(bt_common_component_class_type_string(comp_class->type)),
                PRFIELD_GSTRING(comp_class->name));
 
        if (comp_class->description) {
@@ -1335,7 +1335,7 @@ static inline void format_error_cause(char **buf_ch, bool extended,
        if (comp_class_id) {
                BUF_APPEND(", %scomp-cls-type=%s, %scomp-cls-name=\"%s\", "
                        "%splugin-name=\"%s\"",
-                       PRFIELD(bt_component_class_type_string(
+                       PRFIELD(bt_common_component_class_type_string(
                                comp_class_id->type)),
                        PRFIELD_GSTRING(comp_class_id->name),
                        PRFIELD_GSTRING(comp_class_id->plugin_name));
index 02428c2ad072173e2fb2a59fa0ba353a4b1441a2..3017e6c0af167d5850b134cf6321f2e1c675b62c 100644 (file)
@@ -686,7 +686,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                                        NULL,
                                                descriptor->name,
                                                cur_cc_descr_attr->comp_class_descriptor->name,
-                                               bt_component_class_type_string(
+                                               bt_common_component_class_type_string(
                                                        cur_cc_descr_attr->comp_class_descriptor->type),
                                                cur_cc_descr_attr->type_name,
                                                cur_cc_descr_attr->type);
@@ -706,7 +706,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                                        NULL,
                                                descriptor->name,
                                                cur_cc_descr_attr->comp_class_descriptor->name,
-                                               bt_component_class_type_string(
+                                               bt_common_component_class_type_string(
                                                        cur_cc_descr_attr->comp_class_descriptor->type),
                                                cur_cc_descr_attr->type_name,
                                                cur_cc_descr_attr->type);
@@ -766,7 +766,7 @@ int bt_plugin_so_init(struct bt_plugin *plugin,
                                NULL,
                        descriptor->name,
                        cc_full_descr->descriptor->name,
-                       bt_component_class_type_string(
+                       bt_common_component_class_type_string(
                                cc_full_descr->descriptor->type));
 
                if (cc_full_descr->descriptor->type == BT_COMPONENT_CLASS_TYPE_SOURCE ||
index 78026d6a1fd87e6ddb6883c0ff61fae4eecc964b..e6e31099713393acfb35e864529ad581bd0a7193 100644 (file)
@@ -571,7 +571,7 @@ int bt_plugin_from_python_plugin_info(PyObject *plugin_info,
                                        bt_plugin_get_name(*plugin_out),
                                        comp_class,
                                        bt_component_class_get_name(comp_class),
-                                       bt_component_class_type_string(
+                                       bt_common_component_class_type_string(
                                                bt_component_class_get_type(comp_class)));
                                goto error;
                        }
index 3227650b122b037d9bbb10445e4ef18559e7218d..21a3546758b4521722e843ff8ea015d77cc383be 100755 (executable)
@@ -79,7 +79,7 @@ expect_failure "ValueError: catastrophic failure" \
        'src.query.SourceWithQueryThatPrintsParams' 'please-fail' '-p' 'a=2'
 
 # Non-existent component class.
-expect_failure 'Cannot find component class: plugin-name="query", comp-cls-name="NonExistentSource", comp-cls-type=1' \
+expect_failure 'Cannot find component class: plugin-name="query", comp-cls-name="NonExistentSource", comp-cls-type=SOURCE' \
        'src.query.NonExistentSource' 'the-object' '-p' 'a=2'
 
 # Wrong parameter syntax.
index 3445269bd9ecb1259a21414eb874dc61129c2c48..fb7cb59834adb78bb3e471b7f4071db454f6badc 100755 (executable)
@@ -82,7 +82,7 @@ ok $? "help with unknown plugin name produces no output"
 bt_cli "${stdout}" "${stderr}" help src.ctf.bob
 isnt $? 0 "help with unknown component class name"
 
-grep --silent 'Cannot find component class: plugin-name="ctf", comp-cls-name="bob", comp-cls-type=1' "${stderr}"
+grep --silent 'Cannot find component class: plugin-name="ctf", comp-cls-name="bob", comp-cls-type=SOURCE' "${stderr}"
 ok $? "help with unknown component class name produces expected error"
 
 grep --silent 'Description: CTF input and output' "${stdout}"
This page took 0.031273 seconds and 4 git commands to generate.