lib: remove CTF concepts of packet and event headers
[babeltrace.git] / plugins / ctf / fs-src / data-stream-file.c
index da4d1fa57b4f89e988b4d0bef9637882096f8fd1..280a5d398ceb5f7b480d9fb4bcde4cc48f7e2722 100644 (file)
@@ -293,11 +293,12 @@ struct ctf_fs_ds_index_entry *ctf_fs_ds_index_add_new_entry(
 }
 
 static
-int convert_cycles_to_ns(bt_clock_class *clock_class,
+int convert_cycles_to_ns(struct ctf_clock_class *clock_class,
                uint64_t cycles, int64_t *ns)
 {
-       return bt_clock_class_cycles_to_ns_from_origin(clock_class, cycles,
-                                                      ns);
+       return bt_util_clock_cycles_to_ns_from_origin(cycles,
+                       clock_class->frequency, clock_class->offset_seconds,
+                       clock_class->offset_cycles, ns);
 }
 
 static
@@ -324,17 +325,12 @@ struct ctf_fs_ds_index *build_index_from_idx_file(
 
        BT_LOGD("Building index from .idx file of stream file %s",
                        ds_file->file->path->str);
-
-       ret = bt_msg_iter_borrow_packet_header_context_fields(
-               ds_file->msg_iter, NULL, NULL);
+       ret = bt_msg_iter_get_packet_properties(ds_file->msg_iter, &props);
        if (ret) {
-               BT_LOGD_STR("Cannot borrow first packet's header and context "
-                       "fields.");
+               BT_LOGD_STR("Cannot read first packet's header and context fields.");
                goto error;
        }
 
-       ret = bt_msg_iter_get_packet_properties(ds_file->msg_iter, &props);
-       BT_ASSERT(ret == 0);
        sc = ctf_trace_class_borrow_stream_class_by_id(ds_file->metadata->tc,
                props.stream_class_id);
        BT_ASSERT(sc);
@@ -507,21 +503,29 @@ int init_index_entry(struct ctf_fs_ds_index_entry *entry,
        BT_ASSERT(packet_size >= 0);
        entry->packet_size = packet_size;
 
-       /* Convert the packet's bound to nanoseconds since Epoch. */
-       ret = convert_cycles_to_ns(sc->default_clock_class,
-                                  props->snapshots.beginning_clock,
-                                  &entry->timestamp_begin_ns);
-       if (ret) {
-               BT_LOGD_STR("Failed to convert raw timestamp to nanoseconds since Epoch.");
-               goto end;
+       if (props->snapshots.beginning_clock != UINT64_C(-1)) {
+               /* Convert the packet's bound to nanoseconds since Epoch. */
+               ret = convert_cycles_to_ns(sc->default_clock_class,
+                                          props->snapshots.beginning_clock,
+                                          &entry->timestamp_begin_ns);
+               if (ret) {
+                       BT_LOGD_STR("Failed to convert raw timestamp to nanoseconds since Epoch.");
+                       goto end;
+               }
+       } else {
+               entry->timestamp_begin_ns = UINT64_C(-1);
        }
 
-       ret = convert_cycles_to_ns(sc->default_clock_class,
-                                  props->snapshots.end_clock,
-                                  &entry->timestamp_end_ns);
-       if (ret) {
-               BT_LOGD_STR("Failed to convert raw timestamp to nanoseconds since Epoch.");
-               goto end;
+       if (props->snapshots.end_clock != UINT64_C(-1)) {
+               ret = convert_cycles_to_ns(sc->default_clock_class,
+                                          props->snapshots.end_clock,
+                                          &entry->timestamp_end_ns);
+               if (ret) {
+                       BT_LOGD_STR("Failed to convert raw timestamp to nanoseconds since Epoch.");
+                       goto end;
+               }
+       } else {
+               entry->timestamp_end_ns = UINT64_C(-1);
        }
 
 end:
@@ -550,8 +554,8 @@ struct ctf_fs_ds_index *build_index_from_stream_file(
                struct ctf_fs_ds_index_entry *entry;
                struct bt_msg_iter_packet_properties props;
 
-               iter_status = bt_msg_iter_borrow_packet_header_context_fields(
-                       ds_file->msg_iter, NULL, NULL);
+               iter_status = bt_msg_iter_get_packet_properties(
+                       ds_file->msg_iter, &props);
                if (iter_status != BT_MSG_ITER_STATUS_OK) {
                        if (iter_status == BT_MSG_ITER_STATUS_EOF) {
                                break;
@@ -559,10 +563,6 @@ struct ctf_fs_ds_index *build_index_from_stream_file(
                        goto error;
                }
 
-               ret = bt_msg_iter_get_packet_properties(ds_file->msg_iter,
-                       &props);
-               BT_ASSERT(ret == 0);
-
                current_packet_offset =
                        bt_msg_iter_get_current_packet_offset(
                                ds_file->msg_iter);
@@ -706,12 +706,12 @@ void ctf_fs_ds_file_destroy(struct ctf_fs_ds_file *ds_file)
 }
 
 BT_HIDDEN
-enum bt_message_iterator_status ctf_fs_ds_file_next(
+bt_message_iterator_status ctf_fs_ds_file_next(
                struct ctf_fs_ds_file *ds_file,
                bt_message **msg)
 {
        enum bt_msg_iter_status msg_iter_status;
-       enum bt_message_iterator_status status;
+       bt_message_iterator_status status;
 
        msg_iter_status = bt_msg_iter_get_next_message(
                ds_file->msg_iter, ds_file->pc_msg_iter, msg);
@@ -739,40 +739,6 @@ enum bt_message_iterator_status ctf_fs_ds_file_next(
        return status;
 }
 
-BT_HIDDEN
-int ctf_fs_ds_file_borrow_packet_header_context_fields(
-               struct ctf_fs_ds_file *ds_file,
-               bt_field **packet_header_field,
-               bt_field **packet_context_field)
-{
-       enum bt_msg_iter_status msg_iter_status;
-       int ret = 0;
-
-       BT_ASSERT(ds_file);
-       msg_iter_status = bt_msg_iter_borrow_packet_header_context_fields(
-               ds_file->msg_iter, packet_header_field, packet_context_field);
-       switch (msg_iter_status) {
-       case BT_MSG_ITER_STATUS_EOF:
-       case BT_MSG_ITER_STATUS_OK:
-               break;
-       case BT_MSG_ITER_STATUS_AGAIN:
-               abort();
-       case BT_MSG_ITER_STATUS_INVAL:
-       case BT_MSG_ITER_STATUS_ERROR:
-       default:
-               goto error;
-               break;
-       }
-
-       goto end;
-
-error:
-       ret = -1;
-
-end:
-       return ret;
-}
-
 BT_HIDDEN
 void ctf_fs_ds_index_destroy(struct ctf_fs_ds_index *index)
 {
This page took 0.02639 seconds and 4 git commands to generate.