bt_trace_class_create(): accept mandatory self component
[babeltrace.git] / plugins / ctf / common / metadata / visitor-generate-ir.c
index e57d0b30648128eebb8f9b80b489ddb25c1795cf..e009b4437aa0a40ec170e514e3b98f0a9e8540f0 100644 (file)
@@ -194,7 +194,7 @@ struct ctx_decl_scope {
  */
 struct ctx {
        /* Trace IR trace class being filled (owned by this) */
-       struct bt_trace_class *trace_class;
+       bt_trace_class *trace_class;
 
        /* CTF meta trace being filled (owned by this) */
        struct ctf_trace_class *ctf_tc;
@@ -551,7 +551,7 @@ void ctx_destroy(struct ctx *ctx)
                scope = parent_scope;
        }
 
-       bt_object_put_ref(ctx->trace_class);
+       bt_trace_class_put_ref(ctx->trace_class);
 
        if (ctx->ctf_tc) {
                ctf_trace_class_destroy(ctx->ctf_tc);
@@ -570,7 +570,7 @@ end:
  * @returns    New visitor context, or NULL on error
  */
 static
-struct ctx *ctx_create(
+struct ctx *ctx_create(bt_self_component_source *self_comp,
                const struct ctf_metadata_decoder_config *decoder_config)
 {
        struct ctx *ctx = NULL;
@@ -583,10 +583,13 @@ struct ctx *ctx_create(
                goto error;
        }
 
-       ctx->trace_class = bt_trace_class_create();
-       if (!ctx->trace_class) {
-               BT_LOGE_STR("Cannot create empty trace class.");
-               goto error;
+       if (self_comp) {
+               ctx->trace_class = bt_trace_class_create(
+                       bt_self_component_source_as_self_component(self_comp));
+               if (!ctx->trace_class) {
+                       BT_LOGE_STR("Cannot create empty trace class.");
+                       goto error;
+               }
        }
 
        ctx->ctf_tc = ctf_trace_class_create();
@@ -2350,9 +2353,9 @@ int visit_integer_decl(struct ctx *ctx,
        int signedness = 0;
        struct ctf_node *expression;
        uint64_t alignment = 0, size = 0;
-       struct bt_clock_class *mapped_clock_class = NULL;
+       bt_clock_class *mapped_clock_class = NULL;
        enum ctf_encoding encoding = CTF_ENCODING_NONE;
-       enum bt_field_class_integer_preferred_display_base base =
+       bt_field_class_integer_preferred_display_base base =
                BT_FIELD_CLASS_INTEGER_PREFERRED_DISPLAY_BASE_DECIMAL;
        enum ctf_byte_order byte_order = ctx->ctf_tc->default_byte_order;
 
@@ -2705,7 +2708,7 @@ int visit_integer_decl(struct ctx *ctx,
        (*integer_decl)->disp_base = base;
        (*integer_decl)->encoding = encoding;
        (*integer_decl)->mapped_clock_class = mapped_clock_class;
-       bt_object_get_ref((*integer_decl)->mapped_clock_class);
+       bt_clock_class_get_ref((*integer_decl)->mapped_clock_class);
        return 0;
 
 error:
@@ -3252,7 +3255,7 @@ int visit_event_decl_entry(struct ctx *ctx, struct ctf_node *node,
                        _SET(set, _EVENT_FIELDS_SET);
                } else if (!strcmp(left, "loglevel")) {
                        uint64_t loglevel_value;
-                       enum bt_event_class_log_level log_level = -1;
+                       bt_event_class_log_level log_level = -1;
 
                        if (_IS_SET(set, _EVENT_LOG_LEVEL_SET)) {
                                _BT_LOGE_DUP_ATTR(node, "loglevel",
@@ -3562,7 +3565,7 @@ static
 int auto_map_field_to_trace_clock_class(struct ctx *ctx,
                struct ctf_field_class *fc)
 {
-       struct bt_clock_class *clock_class_to_map_to = NULL;
+       bt_clock_class *clock_class_to_map_to = NULL;
        struct ctf_field_class_int *int_fc = (void *) fc;
        int ret = 0;
        uint64_t clock_class_count;
@@ -3599,7 +3602,7 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx,
                BT_ASSERT(ret == 0);
                g_ptr_array_add(ctx->ctf_tc->clock_classes,
                        clock_class_to_map_to);
-               bt_object_get_ref(clock_class_to_map_to);
+               bt_clock_class_get_ref(clock_class_to_map_to);
                break;
        case 1:
                /*
@@ -3607,7 +3610,7 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx,
                 * this one.
                 */
                clock_class_to_map_to = ctx->ctf_tc->clock_classes->pdata[0];
-               bt_object_get_ref(clock_class_to_map_to);
+               bt_clock_class_get_ref(clock_class_to_map_to);
                break;
        default:
                /*
@@ -3622,10 +3625,10 @@ int auto_map_field_to_trace_clock_class(struct ctx *ctx,
 
        BT_ASSERT(clock_class_to_map_to);
        int_fc->mapped_clock_class = clock_class_to_map_to;
-       bt_object_get_ref(int_fc->mapped_clock_class);
+       bt_clock_class_get_ref(int_fc->mapped_clock_class);
 
 end:
-       bt_object_put_ref(clock_class_to_map_to);
+       bt_clock_class_put_ref(clock_class_to_map_to);
        return ret;
 }
 
@@ -4355,7 +4358,7 @@ error:
 
 static
 int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
-       struct bt_clock_class *clock, int *set, int64_t *offset_seconds,
+       bt_clock_class *clock, int *set, int64_t *offset_seconds,
        uint64_t *offset_cycles)
 {
        int ret = 0;
@@ -4602,7 +4605,7 @@ void calibrate_clock_class_offsets(int64_t *offset_seconds,
 
 static
 void apply_clock_class_offset(struct ctx *ctx,
-               struct bt_clock_class *clock)
+               bt_clock_class *clock)
 {
        uint64_t freq;
        int64_t offset_s_to_apply = ctx->decoder_config.clock_class_offset_s;
@@ -4663,7 +4666,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
 {
        int ret = 0;
        int set = 0;
-       struct bt_clock_class *clock;
+       bt_clock_class *clock;
        struct ctf_node *entry_node;
        struct bt_list_head *decl_list = &clock_node->u.clock.declaration_list;
        const char *clock_class_name;
@@ -4713,7 +4716,7 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
                /*
                 * Old versions of LTTng forgot to set its clock class
                 * as absolute, even if it is. This is important because
-                * it's a condition to be able to sort notifications
+                * it's a condition to be able to sort messages
                 * from different sources.
                 */
                bt_clock_class_set_is_absolute(clock, BT_TRUE);
@@ -4729,10 +4732,10 @@ int visit_clock_decl(struct ctx *ctx, struct ctf_node *clock_node)
        bt_clock_class_set_offset(clock, offset_seconds, offset_cycles);
        apply_clock_class_offset(ctx, clock);
        g_ptr_array_add(ctx->ctf_tc->clock_classes, clock);
-       bt_object_get_ref(clock);
+       bt_clock_class_get_ref(clock);
 
 end:
-       BT_OBJECT_PUT_REF_AND_RESET(clock);
+       BT_CLOCK_CLASS_PUT_REF_AND_RESET(clock);
        return ret;
 }
 
@@ -4802,12 +4805,13 @@ end:
 
 BT_HIDDEN
 struct ctf_visitor_generate_ir *ctf_visitor_generate_ir_create(
+               bt_self_component_source *self_comp,
                const struct ctf_metadata_decoder_config *decoder_config)
 {
        struct ctx *ctx = NULL;
 
        /* Create visitor's context */
-       ctx = ctx_create(decoder_config);
+       ctx = ctx_create(self_comp, decoder_config);
        if (!ctx) {
                BT_LOGE_STR("Cannot create visitor's context.");
                goto error;
@@ -4830,14 +4834,17 @@ void ctf_visitor_generate_ir_destroy(struct ctf_visitor_generate_ir *visitor)
 }
 
 BT_HIDDEN
-struct bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class(
+bt_trace_class *ctf_visitor_generate_ir_get_ir_trace_class(
                struct ctf_visitor_generate_ir *visitor)
 {
        struct ctx *ctx = (void *) visitor;
 
        BT_ASSERT(ctx);
-       BT_ASSERT(ctx->trace_class);
-       bt_object_get_ref(ctx->trace_class);
+
+       if (ctx->trace_class) {
+               bt_trace_class_get_ref(ctx->trace_class);
+       }
+
        return ctx->trace_class;
 }
 
@@ -5042,11 +5049,19 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                goto end;
        }
 
-       /* Update "in IR" for field classes */
-       ret = ctf_trace_class_update_in_ir(ctx->ctf_tc);
-       if (ret) {
-               ret = -EINVAL;
-               goto end;
+       if (ctx->trace_class) {
+               /*
+                * Update "in IR" for field classes.
+                *
+                * If we have no IR trace class, then we'll have no way
+                * to create IR fields anyway, so we leave all the
+                * `in_ir` members false.
+                */
+               ret = ctf_trace_class_update_in_ir(ctx->ctf_tc);
+               if (ret) {
+                       ret = -EINVAL;
+                       goto end;
+               }
        }
 
        /* Update saved value indexes */
@@ -5063,11 +5078,13 @@ int ctf_visitor_generate_ir_visit_node(struct ctf_visitor_generate_ir *visitor,
                goto end;
        }
 
-       /* Copy new CTF metadata -> new IR metadata */
-       ret = ctf_trace_class_translate(ctx->trace_class, ctx->ctf_tc);
-       if (ret) {
-               ret = -EINVAL;
-               goto end;
+       if (ctx->trace_class) {
+               /* Copy new CTF metadata -> new IR metadata */
+               ret = ctf_trace_class_translate(ctx->trace_class, ctx->ctf_tc);
+               if (ret) {
+                       ret = -EINVAL;
+                       goto end;
+               }
        }
 
 end:
This page took 0.030337 seconds and 4 git commands to generate.