lib: split trace API into trace class and trace APIs
[babeltrace.git] / plugins / ctf / common / metadata / ctf-meta-translate.c
index 08b7499edd5550133c199322df4303aa48bbb8da..ddd24f4fc23082fbcf682a1717b53c723119a87b 100644 (file)
@@ -35,17 +35,15 @@ static inline
 void ctf_field_class_int_set_props(struct ctf_field_class_int *fc,
                struct bt_field_class *ir_fc)
 {
-       int ret;
-
-       ret = bt_field_class_integer_set_field_value_range(ir_fc, fc->base.size);
-       BT_ASSERT(ret == 0);
-       ret = bt_field_class_integer_set_preferred_display_base(ir_fc,
+       bt_field_class_integer_set_field_value_range(ir_fc,
+               fc->base.size);
+       bt_field_class_integer_set_preferred_display_base(ir_fc,
                fc->disp_base);
-       BT_ASSERT(ret == 0);
 }
 
 static inline
-struct bt_field_class *ctf_field_class_int_to_ir(struct ctf_field_class_int *fc)
+struct bt_field_class *ctf_field_class_int_to_ir(
+               struct ctf_field_class_int *fc)
 {
        struct bt_field_class *ir_fc;
 
@@ -61,7 +59,8 @@ struct bt_field_class *ctf_field_class_int_to_ir(struct ctf_field_class_int *fc)
 }
 
 static inline
-struct bt_field_class *ctf_field_class_enum_to_ir(struct ctf_field_class_enum *fc)
+struct bt_field_class *ctf_field_class_enum_to_ir(
+               struct ctf_field_class_enum *fc)
 {
        int ret;
        struct bt_field_class *ir_fc;
@@ -101,15 +100,13 @@ struct bt_field_class *ctf_field_class_float_to_ir(
                struct ctf_field_class_float *fc)
 {
        struct bt_field_class *ir_fc;
-       int ret;
 
        ir_fc = bt_field_class_real_create();
        BT_ASSERT(ir_fc);
 
        if (fc->base.size == 32) {
-               ret = bt_field_class_real_set_is_single_precision(ir_fc,
+               bt_field_class_real_set_is_single_precision(ir_fc,
                        BT_TRUE);
-               BT_ASSERT(ret == 0);
        }
 
        return ir_fc;
@@ -119,7 +116,8 @@ static inline
 struct bt_field_class *ctf_field_class_string_to_ir(
                struct ctf_field_class_string *fc)
 {
-       struct bt_field_class *ir_fc = bt_field_class_string_create();
+       struct bt_field_class *ir_fc =
+               bt_field_class_string_create();
 
        BT_ASSERT(ir_fc);
        return ir_fc;
@@ -133,7 +131,8 @@ struct bt_field_class *ctf_field_class_struct_to_ir(
                struct ctf_event_class *ec)
 {
        int ret;
-       struct bt_field_class *ir_fc = bt_field_class_structure_create();
+       struct bt_field_class *ir_fc =
+               bt_field_class_structure_create();
        uint64_t i;
 
        BT_ASSERT(ir_fc);
@@ -149,8 +148,8 @@ struct bt_field_class *ctf_field_class_struct_to_ir(
 
                member_ir_fc = ctf_field_class_to_ir(named_fc->fc, tc, sc, ec);
                BT_ASSERT(member_ir_fc);
-               ret = bt_field_class_structure_append_member(ir_fc,
-                       named_fc->name->str, member_ir_fc);
+               ret = bt_field_class_structure_append_member(
+                       ir_fc, named_fc->name->str, member_ir_fc);
                BT_ASSERT(ret == 0);
                bt_object_put_ref(member_ir_fc);
        }
@@ -186,12 +185,13 @@ struct bt_field_class *ctf_field_class_variant_to_ir(
                struct ctf_event_class *ec)
 {
        int ret;
-       struct bt_field_class *ir_fc = bt_field_class_variant_create();
+       struct bt_field_class *ir_fc =
+               bt_field_class_variant_create();
        uint64_t i;
 
        BT_ASSERT(ir_fc);
-       ret = bt_field_class_variant_set_selector_field_class(ir_fc,
-               borrow_ir_ft_from_field_path(&fc->tag_path, tc, sc, ec));
+       ret = bt_field_class_variant_set_selector_field_class(
+               ir_fc, borrow_ir_ft_from_field_path(&fc->tag_path, tc, sc, ec));
        BT_ASSERT(ret == 0);
 
        for (i = 0; i < fc->options->len; i++) {
@@ -202,8 +202,8 @@ struct bt_field_class *ctf_field_class_variant_to_ir(
                BT_ASSERT(named_fc->fc->in_ir);
                option_ir_fc = ctf_field_class_to_ir(named_fc->fc, tc, sc, ec);
                BT_ASSERT(option_ir_fc);
-               ret = bt_field_class_variant_append_option(ir_fc,
-                       named_fc->name->str, option_ir_fc);
+               ret = bt_field_class_variant_append_option(
+                       ir_fc, named_fc->name->str, option_ir_fc);
                BT_ASSERT(ret == 0);
                bt_object_put_ref(option_ir_fc);
        }
@@ -229,7 +229,8 @@ struct bt_field_class *ctf_field_class_array_to_ir(
 
        elem_ir_fc = ctf_field_class_to_ir(fc->base.elem_fc, tc, sc, ec);
        BT_ASSERT(elem_ir_fc);
-       ir_fc = bt_field_class_static_array_create(elem_ir_fc, fc->length);
+       ir_fc = bt_field_class_static_array_create(elem_ir_fc,
+               fc->length);
        BT_ASSERT(ir_fc);
        bt_object_put_ref(elem_ir_fc);
 
@@ -260,7 +261,8 @@ struct bt_field_class *ctf_field_class_sequence_to_ir(
        BT_ASSERT(ir_fc);
        bt_object_put_ref(elem_ir_fc);
        BT_ASSERT(ir_fc);
-       ret = bt_field_class_dynamic_array_set_length_field_class(ir_fc,
+       ret = bt_field_class_dynamic_array_set_length_field_class(
+               ir_fc,
                borrow_ir_ft_from_field_path(&fc->length_path, tc, sc, ec));
        BT_ASSERT(ret == 0);
 
@@ -442,8 +444,7 @@ struct bt_event_class *ctf_event_class_to_ir(struct ctf_event_class *ec,
        }
 
        if (ec->log_level != -1) {
-               ret = bt_event_class_set_log_level(ir_ec, ec->log_level);
-               BT_ASSERT(ret == 0);
+               bt_event_class_set_log_level(ir_ec, ec->log_level);
        }
 
        ec->is_translated = true;
@@ -456,19 +457,19 @@ end:
 
 static inline
 struct bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc,
-               struct bt_trace *ir_trace, struct ctf_trace_class *tc)
+               struct bt_trace_class *ir_tc, struct ctf_trace_class *tc)
 {
        int ret;
        struct bt_stream_class *ir_sc = NULL;
        struct ctf_field_class_int *int_fc;
 
        if (sc->is_translated) {
-               ir_sc = bt_trace_borrow_stream_class_by_id(ir_trace, sc->id);
+               ir_sc = bt_trace_class_borrow_stream_class_by_id(ir_tc, sc->id);
                BT_ASSERT(ir_sc);
                goto end;
        }
 
-       ir_sc = bt_stream_class_create_with_id(ir_trace, sc->id);
+       ir_sc = bt_stream_class_create_with_id(ir_tc, sc->id);
        BT_ASSERT(ir_sc);
        bt_object_put_ref(ir_sc);
 
@@ -489,8 +490,8 @@ struct bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc,
                        sc->event_header_fc, tc, sc, NULL);
 
                if (ir_fc) {
-                       ret = bt_stream_class_set_event_header_field_class(ir_sc,
-                               ir_fc);
+                       ret = bt_stream_class_set_event_header_field_class(
+                               ir_sc, ir_fc);
                        BT_ASSERT(ret == 0);
                        bt_object_put_ref(ir_fc);
                }
@@ -508,11 +509,9 @@ struct bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc,
                }
        }
 
-       ret = bt_stream_class_set_assigns_automatic_event_class_id(ir_sc,
+       bt_stream_class_set_assigns_automatic_event_class_id(ir_sc,
                BT_FALSE);
-       BT_ASSERT(ret == 0);
-       ret = bt_stream_class_set_assigns_automatic_stream_id(ir_sc, BT_FALSE);
-       BT_ASSERT(ret == 0);
+       bt_stream_class_set_assigns_automatic_stream_id(ir_sc, BT_FALSE);
 
        if (sc->default_clock_class) {
                ret = bt_stream_class_set_default_clock_class(ir_sc,
@@ -524,9 +523,8 @@ struct bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc,
                "events_discarded");
        if (int_fc) {
                if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_DISC_EV_REC_COUNTER_SNAPSHOT) {
-                       ret = bt_stream_class_set_packets_have_discarded_event_counter_snapshot(
+                       bt_stream_class_set_packets_have_discarded_event_counter_snapshot(
                                ir_sc, BT_TRUE);
-                       BT_ASSERT(ret == 0);
                }
        }
 
@@ -534,9 +532,8 @@ struct bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc,
                "packet_seq_num");
        if (int_fc) {
                if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_COUNTER_SNAPSHOT) {
-                       ret = bt_stream_class_set_packets_have_packet_counter_snapshot(
+                       bt_stream_class_set_packets_have_packet_counter_snapshot(
                                ir_sc, BT_TRUE);
-                       BT_ASSERT(ret == 0);
                }
        }
 
@@ -544,9 +541,8 @@ struct bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc,
                "timestamp_begin");
        if (int_fc) {
                if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_BEGINNING_TIME) {
-                       ret = bt_stream_class_set_packets_have_default_beginning_clock_value(
+                       bt_stream_class_set_packets_have_default_beginning_clock_value(
                                ir_sc, BT_TRUE);
-                       BT_ASSERT(ret == 0);
                }
        }
 
@@ -554,9 +550,8 @@ struct bt_stream_class *ctf_stream_class_to_ir(struct ctf_stream_class *sc,
                "timestamp_end");
        if (int_fc) {
                if (int_fc->meaning == CTF_FIELD_CLASS_MEANING_PACKET_END_TIME) {
-                       ret = bt_stream_class_set_packets_have_default_end_clock_value(
+                       bt_stream_class_set_packets_have_default_end_clock_value(
                                ir_sc, BT_TRUE);
-                       BT_ASSERT(ret == 0);
                }
        }
 
@@ -568,7 +563,7 @@ end:
 }
 
 static inline
-int ctf_trace_class_to_ir(struct bt_trace *ir_trace,
+int ctf_trace_class_to_ir(struct bt_trace_class *ir_tc,
                struct ctf_trace_class *tc)
 {
        int ret = 0;
@@ -583,25 +578,15 @@ int ctf_trace_class_to_ir(struct bt_trace *ir_trace,
                        tc->packet_header_fc, tc, NULL, NULL);
 
                if (ir_fc) {
-                       ret = bt_trace_set_packet_header_field_class(ir_trace,
-                               ir_fc);
+                       ret = bt_trace_class_set_packet_header_field_class(
+                               ir_tc, ir_fc);
                        BT_ASSERT(ret == 0);
                        bt_object_put_ref(ir_fc);
                }
        }
 
-       if (tc->name->len > 0) {
-               ret = bt_trace_set_name(ir_trace, tc->name->str);
-               if (ret) {
-                       goto end;
-               }
-       }
-
        if (tc->is_uuid_set) {
-               ret = bt_trace_set_uuid(ir_trace, tc->uuid);
-               if (ret) {
-                       goto end;
-               }
+               bt_trace_class_set_uuid(ir_tc, tc->uuid);
        }
 
        for (i = 0; i < tc->env_entries->len; i++) {
@@ -610,13 +595,13 @@ int ctf_trace_class_to_ir(struct bt_trace *ir_trace,
 
                switch (env_entry->type) {
                case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_INT:
-                       ret = bt_trace_set_environment_entry_integer(
-                               ir_trace, env_entry->name->str,
+                       ret = bt_trace_class_set_environment_entry_integer(
+                               ir_tc, env_entry->name->str,
                                env_entry->value.i);
                        break;
                case CTF_TRACE_CLASS_ENV_ENTRY_TYPE_STR:
-                       ret = bt_trace_set_environment_entry_string(
-                               ir_trace, env_entry->name->str,
+                       ret = bt_trace_class_set_environment_entry_string(
+                               ir_tc, env_entry->name->str,
                                env_entry->value.str->str);
                        break;
                default:
@@ -628,27 +613,23 @@ int ctf_trace_class_to_ir(struct bt_trace *ir_trace,
                }
        }
 
-       ret = bt_trace_set_assigns_automatic_stream_class_id(ir_trace,
+       bt_trace_class_set_assigns_automatic_stream_class_id(ir_tc,
                BT_FALSE);
-       if (ret) {
-               goto end;
-       }
-
        tc->is_translated = true;
-       tc->ir_tc = ir_trace;
+       tc->ir_tc = ir_tc;
 
 end:
        return ret;
 }
 
 BT_HIDDEN
-int ctf_trace_class_translate(struct bt_trace *ir_trace,
+int ctf_trace_class_translate(struct bt_trace_class *ir_tc,
                struct ctf_trace_class *tc)
 {
        int ret = 0;
        uint64_t i;
 
-       ret = ctf_trace_class_to_ir(ir_trace, tc);
+       ret = ctf_trace_class_to_ir(ir_tc, tc);
        if (ret) {
                goto end;
        }
@@ -658,7 +639,7 @@ int ctf_trace_class_translate(struct bt_trace *ir_trace,
                struct ctf_stream_class *sc = tc->stream_classes->pdata[i];
                struct bt_stream_class *ir_sc;
 
-               ir_sc = ctf_stream_class_to_ir(sc, ir_trace, tc);
+               ir_sc = ctf_stream_class_to_ir(sc, ir_tc, tc);
                if (!ir_sc) {
                        ret = -1;
                        goto end;
This page took 0.027549 seconds and 4 git commands to generate.