src.ctf.fs: make ctf_fs_make_port_name return std::string
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 26 Jul 2022 21:19:05 +0000 (17:19 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Tue, 23 Aug 2022 16:06:16 +0000 (12:06 -0400)
Change-Id: I9e2f4d2ac47e4f061e5dda1a3813d1a092ffe433
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8296
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/plugins/ctf/fs-src/fs.cpp
src/plugins/ctf/fs-src/fs.hpp
src/plugins/ctf/fs-src/query.cpp

index e10d1b53689e2d88fa0811adc65f49e7ebfa5299..79e313be22b9fd6282cc657b77b75ab7beb6a6a1 100644 (file)
@@ -31,6 +31,7 @@
 #include "cpp-common/exc.hpp"
 #include "cpp-common/make-unique.hpp"
 #include <vector>
+#include <sstream>
 
 struct tracer_info
 {
@@ -284,9 +285,9 @@ void ctf_fs_finalize(bt_self_component_source *component)
         bt_self_component_source_as_self_component(component))};
 }
 
-bt2_common::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group)
+std::string ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group)
 {
-    GString *name = g_string_new(NULL);
+    std::stringstream name;
 
     /*
      * The unique port name is generated by concatenating unique identifiers
@@ -302,9 +303,9 @@ bt2_common::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_g
         char uuid_str[BT_UUID_STR_LEN + 1];
 
         bt_uuid_to_str(ds_file_group->ctf_fs_trace->metadata->tc->uuid, uuid_str);
-        g_string_assign(name, uuid_str);
+        name << uuid_str;
     } else {
-        g_string_assign(name, ds_file_group->ctf_fs_trace->path.c_str());
+        name << ds_file_group->ctf_fs_trace->path;
     }
 
     /*
@@ -312,19 +313,19 @@ bt2_common::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_g
      * otherwise, as there will only be a single stream class.
      */
     if (ds_file_group->sc->id != UINT64_C(-1)) {
-        g_string_append_printf(name, " | %" PRIu64, ds_file_group->sc->id);
+        name << " | " << ds_file_group->sc->id;
     }
 
     /* For the stream, use the id if present, else, use the path. */
     if (ds_file_group->stream_id != UINT64_C(-1)) {
-        g_string_append_printf(name, " | %" PRIu64, ds_file_group->stream_id);
+        name << " | " << ds_file_group->stream_id;
     } else {
         BT_ASSERT(ds_file_group->ds_file_infos.size() == 1);
         const ctf_fs_ds_file_info& ds_file_info = *ds_file_group->ds_file_infos[0];
-        g_string_append_printf(name, " | %s", ds_file_info.path.c_str());
+        name << " | " << ds_file_info.path;
     }
 
-    return bt2_common::GCharUP {g_string_free(name, FALSE)};
+    return name.str();
 }
 
 static int create_one_port_for_trace(struct ctf_fs_component *ctf_fs,
@@ -336,19 +337,15 @@ static int create_one_port_for_trace(struct ctf_fs_component *ctf_fs,
     ctf_fs_port_data::UP port_data;
     const bt2_common::LogCfg& logCfg = ctf_fs->logCfg;
 
-    bt2_common::GCharUP port_name = ctf_fs_make_port_name(ds_file_group);
-    if (!port_name) {
-        goto error;
-    }
-
-    BT_CLOGI("Creating one port named `%s`", port_name.get());
+    std::string port_name = ctf_fs_make_port_name(ds_file_group);
+    BT_CLOGI("Creating one port named `%s`", port_name.c_str());
 
     /* Create output port for this file */
     port_data = bt2_common::makeUnique<ctf_fs_port_data>();
     port_data->ctf_fs = ctf_fs;
     port_data->ds_file_group = ds_file_group;
-    ret = bt_self_component_source_add_output_port(self_comp_src, port_name.get(), port_data.get(),
-                                                   NULL);
+    ret = bt_self_component_source_add_output_port(self_comp_src, port_name.c_str(),
+                                                   port_data.get(), NULL);
     if (ret) {
         goto error;
     }
index eb049ad118f24bb3c58cd77002ecdc46cc2f1e85..dd5a91cd181353b7370337c4f6ed3f8a756645db 100644 (file)
@@ -202,6 +202,6 @@ bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
  */
 
 BT_HIDDEN
-bt2_common::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
+std::string ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
 
 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */
index f1bf27cd3c57aeed86d9341b450a0eb9c7246b1c..28ece6b323f67a03ffbe21d2da83878e87e1ab2b 100644 (file)
@@ -142,12 +142,8 @@ static void populate_stream_info(struct ctf_fs_ds_file_group *group, bt2::MapVal
 
     add_range(groupInfo, stream_range, "range-ns");
 
-    bt2_common::GCharUP portName = ctf_fs_make_port_name(group);
-    if (!portName) {
-        BT_CLOGE_APPEND_CAUSE_AND_THROW(bt2_common::Error, "Failed to make port name");
-    }
-
-    groupInfo.insert("port-name", portName.get());
+    std::string portName = ctf_fs_make_port_name(group);
+    groupInfo.insert("port-name", portName.c_str());
 }
 
 static void populate_trace_info(const struct ctf_fs_trace *trace, bt2::MapValue traceInfo,
This page took 0.027616 seconds and 5 git commands to generate.