src.ctf.fs: make ctf_fs_file_create return a unique_ptr
[babeltrace.git] / src / plugins / ctf / fs-src / data-stream-file.cpp
index f62bbd292b2acbf34bb9fc2da1986f01121f5660..cea4a620cab624856e347998d716f5ae39ba782d 100644 (file)
@@ -225,7 +225,7 @@ static bt_stream *medop_borrow_stream(bt_stream_class *stream_class, int64_t, vo
     bt_stream_class *ds_file_stream_class;
     bt_stream *stream = NULL;
 
-    ds_file_stream_class = bt_stream_borrow_class(ds_file->stream);
+    ds_file_stream_class = ds_file->stream->cls().libObjPtr();
 
     if (stream_class != ds_file_stream_class) {
         /*
@@ -235,7 +235,7 @@ static bt_stream *medop_borrow_stream(bt_stream_class *stream_class, int64_t, vo
         goto end;
     }
 
-    stream = ds_file->stream;
+    stream = ds_file->stream->libObjPtr();
 
 end:
     return stream;
@@ -811,8 +811,9 @@ error:
     goto end;
 }
 
-struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace, bt_stream *stream,
-                                             const char *path, const bt2c::Logger& parentLogger)
+struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace,
+                                             bt2::Stream::Shared stream, const char *path,
+                                             const bt2c::Logger& parentLogger)
 {
     int ret;
     size_t offset_align;
@@ -822,13 +823,12 @@ struct ctf_fs_ds_file *ctf_fs_ds_file_create(struct ctf_fs_trace *ctf_fs_trace,
         goto error;
     }
 
-    ds_file->file = ctf_fs_file_create(parentLogger);
+    ds_file->file = ctf_fs_file_create(parentLogger).release();
     if (!ds_file->file) {
         goto error;
     }
 
-    ds_file->stream = stream;
-    bt_stream_get_ref(ds_file->stream);
+    ds_file->stream = std::move(stream);
     ds_file->metadata = ctf_fs_trace->metadata;
     g_string_assign(ds_file->file->path, path);
     ret = ctf_fs_file_open(ds_file->file, "rb");
@@ -868,7 +868,7 @@ end:
 
 ctf_fs_ds_index::UP ctf_fs_ds_index_create()
 {
-    return ctf_fs_ds_index::UP {new ctf_fs_ds_index};
+    return bt2s::make_unique<ctf_fs_ds_index>();
 }
 
 void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *ds_file)
@@ -877,7 +877,6 @@ void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *ds_file)
         return;
     }
 
-    bt_stream_put_ref(ds_file->stream);
     (void) ds_file_munmap(ds_file);
 
     if (ds_file->file) {
@@ -887,20 +886,6 @@ void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *ds_file)
     delete ds_file;
 }
 
-void ctf_fs_ds_index_destroy(struct ctf_fs_ds_index *index)
-{
-    if (!index) {
-        return;
-    }
-
-    delete index;
-}
-
-void ctf_fs_ds_index_deleter::operator()(ctf_fs_ds_index * const index) noexcept
-{
-    ctf_fs_ds_index_destroy(index);
-}
-
 ctf_fs_ds_file_info::UP ctf_fs_ds_file_info_create(const char *path, int64_t begin_ns)
 {
     ctf_fs_ds_file_info::UP ds_file_info = bt2s::make_unique<ctf_fs_ds_file_info>();
@@ -910,21 +895,6 @@ ctf_fs_ds_file_info::UP ctf_fs_ds_file_info_create(const char *path, int64_t beg
     return ds_file_info;
 }
 
-static void ctf_fs_ds_file_group_destroy(struct ctf_fs_ds_file_group *ds_file_group)
-{
-    if (!ds_file_group) {
-        return;
-    }
-
-    bt_stream_put_ref(ds_file_group->stream);
-    delete ds_file_group;
-}
-
-void ctf_fs_ds_file_group_deleter::operator()(ctf_fs_ds_file_group *group) noexcept
-{
-    ctf_fs_ds_file_group_destroy(group);
-}
-
 ctf_fs_ds_file_group::UP ctf_fs_ds_file_group_create(struct ctf_fs_trace *ctf_fs_trace,
                                                      struct ctf_stream_class *sc,
                                                      uint64_t stream_instance_id,
This page took 0.024878 seconds and 4 git commands to generate.