From: Simon Marchi Date: Tue, 9 Apr 2024 21:08:37 +0000 (-0400) Subject: src.ctf.fs: make ctf_fs_make_port_name return std::string X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=3045bbcb17348d9f79213c9976631fd189cbc9b8 src.ctf.fs: make ctf_fs_make_port_name return std::string Change-Id: I9e2f4d2ac47e4f061e5dda1a3813d1a092ffe433 Signed-off-by: Simon Marchi Reviewed-on: https://review.lttng.org/c/babeltrace/+/8296 Reviewed-by: Philippe Proulx Reviewed-on: https://review.lttng.org/c/babeltrace/+/12332 Tested-by: jenkins --- diff --git a/src/plugins/ctf/fs-src/fs.cpp b/src/plugins/ctf/fs-src/fs.cpp index 07752f71..7d96e6a4 100644 --- a/src/plugins/ctf/fs-src/fs.cpp +++ b/src/plugins/ctf/fs-src/fs.cpp @@ -7,14 +7,16 @@ * Babeltrace CTF file system Reader Component */ +#include + #include -#include #include #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(); 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; } diff --git a/src/plugins/ctf/fs-src/fs.hpp b/src/plugins/ctf/fs-src/fs.hpp index 9f9f605e..5d43b38f 100644 --- a/src/plugins/ctf/fs-src/fs.hpp +++ b/src/plugins/ctf/fs-src/fs.hpp @@ -14,7 +14,6 @@ #include -#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 */ diff --git a/src/plugins/ctf/fs-src/query.cpp b/src/plugins/ctf/fs-src/query.cpp index 9245ce38..bb31b17d 100644 --- a/src/plugins/ctf/fs-src/query.cpp +++ b/src/plugins/ctf/fs-src/query.cpp @@ -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); } }