clock_class->offset_cycles, ns);
}
-static struct ctf_fs_ds_index *build_index_from_idx_file(struct ctf_fs_ds_file *ds_file,
- struct ctf_fs_ds_file_info *file_info,
- struct ctf_msg_iter *msg_iter)
+static ctf_fs_ds_index::UP build_index_from_idx_file(struct ctf_fs_ds_file *ds_file,
+ struct ctf_fs_ds_file_info *file_info,
+ struct ctf_msg_iter *msg_iter)
{
int ret;
gchar *directory = NULL;
gsize filesize;
const char *mmap_begin = NULL, *file_pos = NULL;
const struct ctf_packet_index_file_hdr *header = NULL;
- struct ctf_fs_ds_index *index = NULL;
+ ctf_fs_ds_index::UP index;
struct ctf_fs_ds_index_entry *index_entry = NULL, *prev_index_entry = NULL;
auto totalPacketsSize = bt2c::DataLen::fromBytes(0);
size_t file_index_entry_size;
}
return index;
error:
- ctf_fs_ds_index_destroy(index);
+ index.reset();
ctf_fs_ds_index_entry_destroy(index_entry);
- index = NULL;
goto end;
}
return ret;
}
-static struct ctf_fs_ds_index *build_index_from_stream_file(struct ctf_fs_ds_file *ds_file,
- struct ctf_fs_ds_file_info *file_info,
- struct ctf_msg_iter *msg_iter)
+static ctf_fs_ds_index::UP build_index_from_stream_file(struct ctf_fs_ds_file *ds_file,
+ struct ctf_fs_ds_file_info *file_info,
+ struct ctf_msg_iter *msg_iter)
{
int ret;
- struct ctf_fs_ds_index *index = NULL;
+ ctf_fs_ds_index::UP index;
enum ctf_msg_iter_status iter_status = CTF_MSG_ITER_STATUS_OK;
auto currentPacketOffset = bt2c::DataLen::fromBytes(0);
return index;
error:
- ctf_fs_ds_index_destroy(index);
- index = NULL;
+ index.reset();
goto end;
}
return ds_file;
}
-struct ctf_fs_ds_index *ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file,
- struct ctf_fs_ds_file_info *file_info,
- struct ctf_msg_iter *msg_iter)
+ctf_fs_ds_index::UP ctf_fs_ds_file_build_index(struct ctf_fs_ds_file *ds_file,
+ struct ctf_fs_ds_file_info *file_info,
+ struct ctf_msg_iter *msg_iter)
{
- struct ctf_fs_ds_index *index;
-
- index = build_index_from_idx_file(ds_file, file_info, msg_iter);
+ auto index = build_index_from_idx_file(ds_file, file_info, msg_iter);
if (index) {
goto end;
}
return index;
}
-struct ctf_fs_ds_index *ctf_fs_ds_index_create(const bt2c::Logger& logger)
+ctf_fs_ds_index::UP ctf_fs_ds_index_create(const bt2c::Logger& logger)
{
- ctf_fs_ds_index *index = new ctf_fs_ds_index;
+ ctf_fs_ds_index::UP index {new ctf_fs_ds_index};
+
index->entries = g_ptr_array_new_with_free_func((GDestroyNotify) ctf_fs_ds_index_entry_destroy);
if (!index->entries) {
BT_CPPLOGE_SPEC(logger, "Failed to allocate index entries.");
goto end;
error:
- ctf_fs_ds_index_destroy(index);
- index = NULL;
+ index.reset();
+
end:
return index;
}
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>();