src.ctf.fs: make ctf_fs_trace::path an std::string
[babeltrace.git] / src / plugins / ctf / fs-src / metadata.cpp
index cbe4172b21a6fab4ebb4f34c73e3f3781b9e5a31..5ca3b7997d0a6dbcbbf565046d675706a9e05917 100644 (file)
@@ -35,48 +35,40 @@ end:
     return fp;
 }
 
-static struct ctf_fs_file *get_file(const char *trace_path, const bt2c::Logger& logger)
+static ctf_fs_file::UP get_file(const bt2c::CStringView trace_path, const bt2c::Logger& logger)
 {
-    struct ctf_fs_file *file = ctf_fs_file_create(logger);
+    auto file = ctf_fs_file_create(logger);
 
     if (!file) {
         goto error;
     }
 
-    g_string_append(file->path, trace_path);
-    g_string_append(file->path, G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME);
+    file->path = fmt::format("{}" G_DIR_SEPARATOR_S CTF_FS_METADATA_FILENAME, trace_path);
 
-    if (ctf_fs_file_open(file, "rb")) {
+    if (ctf_fs_file_open(file.get(), "rb")) {
         goto error;
     }
 
     goto end;
 
 error:
-    if (file) {
-        ctf_fs_file_destroy(file);
-        file = NULL;
-    }
+    file.reset();
 
 end:
     return file;
 }
 
 int ctf_fs_metadata_set_trace_class(bt_self_component *self_comp, struct ctf_fs_trace *ctf_fs_trace,
-                                    struct ctf_fs_metadata_config *config)
+                                    const ctf::src::ClkClsCfg& clkClsCfg)
 {
     int ret = 0;
-    struct ctf_fs_file *file = NULL;
     ctf_metadata_decoder_config decoder_config {ctf_fs_trace->logger};
 
     decoder_config.self_comp = self_comp;
-    decoder_config.clock_class_offset_s = config ? config->clock_class_offset_s : 0;
-    decoder_config.clock_class_offset_ns = config ? config->clock_class_offset_ns : 0;
-    decoder_config.force_clock_class_origin_unix_epoch =
-        config ? config->force_clock_class_origin_unix_epoch : false;
+    decoder_config.clkClsCfg = clkClsCfg;
     decoder_config.create_trace_class = true;
 
-    file = get_file(ctf_fs_trace->path->str, ctf_fs_trace->logger);
+    const auto file = get_file(ctf_fs_trace->path, ctf_fs_trace->logger);
     if (!file) {
         BT_CPPLOGE_SPEC(ctf_fs_trace->logger, "Cannot create metadata file object.");
         ret = -1;
@@ -90,7 +82,8 @@ int ctf_fs_metadata_set_trace_class(bt_self_component *self_comp, struct ctf_fs_
         goto end;
     }
 
-    ret = ctf_metadata_decoder_append_content(ctf_fs_trace->metadata->decoder.get(), file->fp);
+    ret =
+        ctf_metadata_decoder_append_content(ctf_fs_trace->metadata->decoder.get(), file->fp.get());
     if (ret) {
         BT_CPPLOGE_SPEC(ctf_fs_trace->logger, "Cannot update metadata decoder's content.");
         goto end;
@@ -104,7 +97,6 @@ int ctf_fs_metadata_set_trace_class(bt_self_component *self_comp, struct ctf_fs_
     BT_ASSERT(ctf_fs_trace->metadata->tc);
 
 end:
-    ctf_fs_file_destroy(file);
     return ret;
 }
 
This page took 0.0242 seconds and 4 git commands to generate.