src.ctf.fs: pass clkClsCfg to ctf_fs_component constructor
[babeltrace.git] / src / plugins / ctf / fs-src / query.cpp
index 2a6057db0ced589898d833b5212bf2bcb8c07328..3467931096624c78e2aef1aa0481c851e198ff9b 100644 (file)
@@ -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
@@ -123,17 +123,16 @@ static void populate_stream_info(struct ctf_fs_ds_file_group *group, const bt2::
      * the timestamp_begin of the first index entry and the timestamp_end
      * of the last index entry.
      */
-    BT_ASSERT(group->index);
-    BT_ASSERT(!group->index->entries.empty());
+    BT_ASSERT(!group->index.entries.empty());
 
     /* First entry. */
-    const auto first_ds_index_entry = group->index->entries.front().get();
+    const auto& first_ds_index_entry = group->index.entries.front();
 
     /* Last entry. */
-    const auto last_ds_index_entry = group->index->entries.back().get();
+    const auto& last_ds_index_entry = group->index.entries.back();
 
-    stream_range->begin_ns = first_ds_index_entry->timestamp_begin_ns;
-    stream_range->end_ns = last_ds_index_entry->timestamp_end_ns;
+    stream_range->begin_ns = first_ds_index_entry.timestamp_begin_ns;
+    stream_range->end_ns = last_ds_index_entry.timestamp_end_ns;
 
     /*
      * If any of the begin and end timestamps is not set it means that
@@ -144,13 +143,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,
@@ -158,8 +151,8 @@ static void populate_trace_info(const struct ctf_fs_trace *trace, const bt2::Map
 {
     /* Add trace range info only if it contains streams. */
     if (trace->ds_file_groups.empty()) {
-        BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(
-            logger, bt2::Error, "Trace has no streams: trace-path={}", trace->path->str);
+        BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(logger, bt2::Error,
+                                               "Trace has no streams: trace-path={}", trace->path);
     }
 
     const auto fileGroups = traceInfo.insertEmptyArray("stream-infos");
@@ -168,33 +161,24 @@ 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);
     }
 }
 
 bt2::Value::Shared trace_infos_query(const bt2::ConstMapValue params, const bt2c::Logger& logger)
 {
-    ctf_fs_component::UP ctf_fs = ctf_fs_component_create(logger);
-    if (!ctf_fs) {
-        BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(logger, bt2::Error,
-                                               "Cannot create ctf_fs_component");
-    }
-
-    const bt_value *inputs_value = NULL;
-    const bt_value *trace_name_value;
-
-    if (!read_src_fs_parameters(params.libObjPtr(), &inputs_value, &trace_name_value,
-                                ctf_fs.get())) {
-        BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(logger, bt2::Error, "Failed to read parameters");
-    }
+    const auto parameters = read_src_fs_parameters(params, logger);
+    ctf_fs_component ctf_fs {parameters.clkClsCfg, logger};
 
-    if (ctf_fs_component_create_ctf_fs_trace(ctf_fs.get(), inputs_value, trace_name_value, NULL)) {
+    if (ctf_fs_component_create_ctf_fs_trace(
+            &ctf_fs, parameters.inputs,
+            parameters.traceName ? parameters.traceName->c_str() : nullptr, nullptr)) {
         BT_CPPLOGE_APPEND_CAUSE_AND_THROW_SPEC(logger, bt2::Error, "Failed to create trace");
     }
 
     const auto result = bt2::ArrayValue::create();
     const auto traceInfo = result->appendEmptyMap();
-    populate_trace_info(ctf_fs->trace.get(), traceInfo, logger);
+    populate_trace_info(ctf_fs.trace.get(), traceInfo, logger);
 
     return result;
 }
This page took 0.025205 seconds and 4 git commands to generate.