src.ctf.fs: make ctf_fs_ds_group_medops_data_create return a unique_ptr
[deliverable/babeltrace.git] / src / plugins / ctf / fs-src / fs.cpp
index 309bcf7791f73ffbaa0aef198162f55dad33c15d..a0a87986b8f79fc93182e99dfd606c9018ed2691 100644 (file)
@@ -50,10 +50,6 @@ static void ctf_fs_msg_iter_data_destroy(struct ctf_fs_msg_iter_data *msg_iter_d
         ctf_msg_iter_destroy(msg_iter_data->msg_iter);
     }
 
-    if (msg_iter_data->msg_iter_medops_data) {
-        ctf_fs_ds_group_medops_data_destroy(msg_iter_data->msg_iter_medops_data);
-    }
-
     delete msg_iter_data;
 }
 
@@ -183,7 +179,7 @@ ctf_fs_iterator_seek_beginning(bt_self_message_iterator *it)
 
     try {
         ctf_msg_iter_reset(msg_iter_data->msg_iter);
-        ctf_fs_ds_group_medops_data_reset(msg_iter_data->msg_iter_medops_data);
+        ctf_fs_ds_group_medops_data_reset(msg_iter_data->msg_iter_medops_data.get());
 
         return BT_MESSAGE_ITERATOR_CLASS_SEEK_BEGINNING_METHOD_STATUS_OK;
     } catch (const std::bad_alloc&) {
@@ -243,7 +239,7 @@ ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
 
         medium_status =
             ctf_fs_ds_group_medops_data_create(msg_iter_data->ds_file_group, self_msg_iter, logCfg,
-                                               &msg_iter_data->msg_iter_medops_data);
+                                               msg_iter_data->msg_iter_medops_data);
         BT_ASSERT(medium_status == CTF_MSG_ITER_MEDIUM_STATUS_OK ||
                   medium_status == CTF_MSG_ITER_MEDIUM_STATUS_ERROR ||
                   medium_status == CTF_MSG_ITER_MEDIUM_STATUS_MEMORY_ERROR);
@@ -256,7 +252,7 @@ ctf_fs_iterator_init(bt_self_message_iterator *self_msg_iter,
         msg_iter_data->msg_iter = ctf_msg_iter_create(
             msg_iter_data->ds_file_group->ctf_fs_trace->metadata->tc,
             bt_common_get_page_size(logCfg.logLevel()) * 8, ctf_fs_ds_group_medops,
-            msg_iter_data->msg_iter_medops_data, self_msg_iter, logCfg);
+            msg_iter_data->msg_iter_medops_data.get(), self_msg_iter, logCfg);
         if (!msg_iter_data->msg_iter) {
             BT_CLOGE_APPEND_CAUSE("Cannot create a CTF message iterator.");
             status = BT_MESSAGE_ITERATOR_CLASS_INITIALIZE_METHOD_STATUS_MEMORY_ERROR;
@@ -532,7 +528,6 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
     struct ctf_fs_ds_file_group *ds_file_group = NULL;
     ctf_fs_ds_file_group::UP new_ds_file_group;
     int ret;
-    struct ctf_fs_ds_file *ds_file = NULL;
     ctf_fs_ds_file_info::UP ds_file_info;
     ctf_fs_ds_index::UP index;
     struct ctf_msg_iter *msg_iter = NULL;
@@ -544,7 +539,7 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
      * Create a temporary ds_file to read some properties about the data
      * stream file.
      */
-    ds_file = ctf_fs_ds_file_create(ctf_fs_trace, nonstd::nullopt, path, logCfg);
+    ctf_fs_ds_file::UP ds_file = ctf_fs_ds_file_create(ctf_fs_trace, nonstd::nullopt, path, logCfg);
     if (!ds_file) {
         goto error;
     }
@@ -552,7 +547,7 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
     /* Create a temporary iterator to read the ds_file. */
     msg_iter = ctf_msg_iter_create(ctf_fs_trace->metadata->tc,
                                    bt_common_get_page_size(logCfg.logLevel()) * 8,
-                                   ctf_fs_ds_file_medops, ds_file, nullptr, logCfg);
+                                   ctf_fs_ds_file_medops, ds_file.get(), nullptr, logCfg);
     if (!msg_iter) {
         BT_CLOGE_STR("Cannot create a CTF message iterator.");
         goto error;
@@ -589,9 +584,10 @@ static int add_ds_file_to_ds_file_group(struct ctf_fs_trace *ctf_fs_trace, const
         goto error;
     }
 
-    index = ctf_fs_ds_file_build_index(ds_file, ds_file_info.get(), msg_iter);
+    index = ctf_fs_ds_file_build_index(ds_file.get(), ds_file_info.get(), msg_iter);
     if (!index) {
-        BT_CLOGE_APPEND_CAUSE("Failed to index CTF stream file \'%s\'", ds_file->file->path->str);
+        BT_CLOGE_APPEND_CAUSE("Failed to index CTF stream file \'%s\'",
+                              ds_file->file->path.c_str());
         goto error;
     }
 
@@ -656,8 +652,6 @@ error:
     ret = -1;
 
 end:
-    ctf_fs_ds_file_destroy(ds_file);
-
     if (msg_iter) {
         ctf_msg_iter_destroy(msg_iter);
     }
@@ -682,8 +676,6 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
     }
 
     while ((basename = g_dir_read_name(dir))) {
-        struct ctf_fs_file *file;
-
         if (strcmp(basename, CTF_FS_METADATA_FILENAME) == 0) {
             /* Ignore the metadata stream. */
             BT_CLOGI("Ignoring metadata file `%s" G_DIR_SEPARATOR_S "%s`", ctf_fs_trace->path->str,
@@ -698,7 +690,7 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
         }
 
         /* Create the file. */
-        file = ctf_fs_file_create(logCfg).release();
+        ctf_fs_file::UP file = ctf_fs_file_create(logCfg);
         if (!file) {
             BT_CLOGE_APPEND_CAUSE("Cannot create stream file object for file `%s" G_DIR_SEPARATOR_S
                                   "%s`",
@@ -707,37 +699,33 @@ static int create_ds_file_groups(struct ctf_fs_trace *ctf_fs_trace)
         }
 
         /* Create full path string. */
-        g_string_append_printf(file->path, "%s" G_DIR_SEPARATOR_S "%s", ctf_fs_trace->path->str,
-                               basename);
-        if (!g_file_test(file->path->str, G_FILE_TEST_IS_REGULAR)) {
-            BT_CLOGI("Ignoring non-regular file `%s`", file->path->str);
-            ctf_fs_file_destroy(file);
-            file = NULL;
+        file->path = ctf_fs_trace->path->str;
+        file->path += G_DIR_SEPARATOR;
+        file->path += basename;
+
+        if (!g_file_test(file->path.c_str(), G_FILE_TEST_IS_REGULAR)) {
+            BT_CLOGI("Ignoring non-regular file `%s`", file->path.c_str());
             continue;
         }
 
-        ret = ctf_fs_file_open(file, "rb");
+        ret = ctf_fs_file_open(file.get(), "rb");
         if (ret) {
-            BT_CLOGE_APPEND_CAUSE("Cannot open stream file `%s`", file->path->str);
+            BT_CLOGE_APPEND_CAUSE("Cannot open stream file `%s`", file->path.c_str());
             goto error;
         }
 
         if (file->size == 0) {
             /* Skip empty stream. */
-            BT_CLOGI("Ignoring empty file `%s`", file->path->str);
-            ctf_fs_file_destroy(file);
+            BT_CLOGI("Ignoring empty file `%s`", file->path.c_str());
             continue;
         }
 
-        ret = add_ds_file_to_ds_file_group(ctf_fs_trace, file->path->str);
+        ret = add_ds_file_to_ds_file_group(ctf_fs_trace, file->path.c_str());
         if (ret) {
             BT_CLOGE_APPEND_CAUSE("Cannot add stream file `%s` to stream file group",
-                                  file->path->str);
-            ctf_fs_file_destroy(file);
+                                  file->path.c_str());
             goto error;
         }
-
-        ctf_fs_file_destroy(file);
     }
 
     goto end;
@@ -1138,7 +1126,6 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
                                              int64_t *ts_ns)
 {
     enum ctf_msg_iter_status iter_status = CTF_MSG_ITER_STATUS_OK;
-    struct ctf_fs_ds_file *ds_file = NULL;
     struct ctf_msg_iter *msg_iter = NULL;
     const bt2_common::LogCfg& logCfg = ctf_fs_trace->logCfg;
     int ret = 0;
@@ -1147,7 +1134,8 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
     BT_ASSERT(index_entry);
     BT_ASSERT(index_entry->path);
 
-    ds_file = ctf_fs_ds_file_create(ctf_fs_trace, nonstd::nullopt, index_entry->path, logCfg);
+    ctf_fs_ds_file::UP ds_file =
+        ctf_fs_ds_file_create(ctf_fs_trace, nonstd::nullopt, index_entry->path, logCfg);
     if (!ds_file) {
         BT_CLOGE_APPEND_CAUSE("Failed to create a ctf_fs_ds_file");
         ret = -1;
@@ -1159,7 +1147,7 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
 
     msg_iter = ctf_msg_iter_create(ctf_fs_trace->metadata->tc,
                                    bt_common_get_page_size(logCfg.logLevel()) * 8,
-                                   ctf_fs_ds_file_medops, ds_file, NULL, logCfg);
+                                   ctf_fs_ds_file_medops, ds_file.get(), NULL, logCfg);
     if (!msg_iter) {
         /* ctf_msg_iter_create() logs errors. */
         ret = -1;
@@ -1210,9 +1198,6 @@ static int decode_clock_snapshot_after_event(struct ctf_fs_trace *ctf_fs_trace,
     }
 
 end:
-    if (ds_file) {
-        ctf_fs_ds_file_destroy(ds_file);
-    }
     if (msg_iter) {
         ctf_msg_iter_destroy(msg_iter);
     }
This page took 0.026284 seconds and 5 git commands to generate.