src.ctf.fs: make ctf_fs_make_port_name return std::string
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 9 Apr 2024 21:08:37 +0000 (17:08 -0400)
committerSimon Marchi <simon.marchi@efficios.com>
Wed, 17 Apr 2024 17:57:53 +0000 (13:57 -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>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/12332
Tested-by: jenkins <jenkins@lttng.org>
src/plugins/ctf/fs-src/fs.cpp
src/plugins/ctf/fs-src/fs.hpp
src/plugins/ctf/fs-src/query.cpp

index 07752f718845022fe395b30037a8dffe3c322e98..7d96e6a46fbf8de54b068f1c04032efe6990cf88 100644 (file)
@@ -7,14 +7,16 @@
  * Babeltrace CTF file system Reader Component
  */
 
+#include <sstream>
+
 #include <glib.h>
-#include <inttypes.h>
 
 #include <babeltrace2/babeltrace.h>
 
 #include "common/assert.h"
 #include "common/common.h"
 #include "common/uuid.h"
+#include "cpp-common/bt2c/glib-up.hpp"
 #include "cpp-common/bt2s/make-unique.hpp"
 
 #include "plugins/common/param-validation/param-validation.h"
@@ -266,9 +268,9 @@ void ctf_fs_finalize(bt_self_component_source *component)
         bt_self_component_get_data(bt_self_component_source_as_self_component(component)))};
 }
 
-bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group)
+std::string ctf_fs_make_port_name(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
@@ -284,9 +286,9 @@ bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group)
         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;
     }
 
     /*
@@ -294,19 +296,19 @@ bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group)
      * 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 auto& 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 bt2c::GCharUP {g_string_free(name, FALSE)};
+    return name.str();
 }
 
 static int create_one_port_for_trace(struct ctf_fs_component *ctf_fs,
@@ -316,19 +318,15 @@ static int create_one_port_for_trace(struct ctf_fs_component *ctf_fs,
     int ret = 0;
     ctf_fs_port_data::UP port_data;
 
-    bt2c::GCharUP port_name = ctf_fs_make_port_name(ds_file_group);
-    if (!port_name) {
-        goto error;
-    }
-
-    BT_CPPLOGI_SPEC(ctf_fs->logger, "Creating one port named `{}`", port_name.get());
+    const auto port_name = ctf_fs_make_port_name(ds_file_group);
+    BT_CPPLOGI_SPEC(ctf_fs->logger, "Creating one port named `{}`", port_name);
 
     /* Create output port for this file */
     port_data = bt2s::make_unique<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 9f9f605ee433a1338a900b7ce25fac7025c01c39..5d43b38f5bcaf4a9c3ac346e70a07201da471ce1 100644 (file)
@@ -14,7 +14,6 @@
 
 #include <babeltrace2/babeltrace.h>
 
-#include "cpp-common/bt2c/glib-up.hpp"
 #include "cpp-common/bt2c/logging.hpp"
 
 #include "data-stream-file.hpp"
@@ -189,6 +188,6 @@ bool read_src_fs_parameters(const bt_value *params, const bt_value **paths,
  * Generate the port name to be used for a given data stream file group.
  */
 
-bt2c::GCharUP ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group);
+std::string ctf_fs_make_port_name(ctf_fs_ds_file_group *ds_file_group);
 
 #endif /* BABELTRACE_PLUGIN_CTF_FS_H */
index 9245ce38dabadb2b7f039ac7676961aa987d78d5..bb31b17d38c4b498894760fdc94805104d4e1b3b 100644 (file)
@@ -115,7 +115,7 @@ static void add_range(const bt2::MapValue info, struct range *range, const char
 }
 
 static void populate_stream_info(struct ctf_fs_ds_file_group *group, const bt2::MapValue groupInfo,
-                                 struct range *stream_range, const bt2c::Logger& logger)
+                                 struct range *stream_range)
 {
     /*
      * Since each `struct ctf_fs_ds_file_group` has a sorted array of
@@ -144,13 +144,7 @@ static void populate_stream_info(struct ctf_fs_ds_file_group *group, const bt2::
         stream_range->begin_ns != UINT64_C(-1) && stream_range->end_ns != UINT64_C(-1);
 
     add_range(groupInfo, stream_range, "range-ns");
-
-    bt2c::GCharUP portName = ctf_fs_make_port_name(group);
-    if (!portName) {
-        BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(logger, bt2::Error, "Failed to make port name");
-    }
-
-    groupInfo.insert("port-name", portName.get());
+    groupInfo.insert("port-name", ctf_fs_make_port_name(group));
 }
 
 static void populate_trace_info(const struct ctf_fs_trace *trace, const bt2::MapValue traceInfo,
@@ -168,7 +162,7 @@ static void populate_trace_info(const struct ctf_fs_trace *trace, const bt2::Map
     for (const auto& group : trace->ds_file_groups) {
         range group_range;
         const auto groupInfo = fileGroups.appendEmptyMap();
-        populate_stream_info(group.get(), groupInfo, &group_range, logger);
+        populate_stream_info(group.get(), groupInfo, &group_range);
     }
 }
 
This page took 0.027899 seconds and 4 git commands to generate.