lib: move trace class's name, UUID, and environment props to trace API
[babeltrace.git] / src / plugins / ctf / fs-sink / translate-trace-ir-to-ctf-ir.c
index a4f9761de76f6c7e5c0e87f868794ebb85a7d093..1534c96cf2da7caf118ffc7f20f45297da821646 100644 (file)
  * SOFTWARE.
  */
 
+#define BT_COMP_LOG_SELF_COMP (ctx->self_comp)
 #define BT_LOG_OUTPUT_LEVEL (ctx->log_level)
 #define BT_LOG_TAG "PLUGIN/SINK.CTF.FS/TRANSLATE-TRACE-IR-TO-CTF-IR"
-#include "logging/log.h"
+#include "plugins/comp-logging.h"
 
 #include <babeltrace2/babeltrace.h>
 #include "common/macros.h"
@@ -33,6 +34,7 @@
 #include <string.h>
 #include <glib.h>
 
+#include "fs-sink.h"
 #include "fs-sink-ctf-meta.h"
 
 struct field_path_elem {
@@ -48,6 +50,7 @@ struct field_path_elem {
 
 struct ctx {
        bt_logging_level log_level;
+       bt_self_component *self_comp;
 
        /* Weak */
        struct fs_sink_ctf_stream_class *cur_sc;
@@ -117,7 +120,7 @@ int cur_path_stack_push(struct ctx *ctx,
                                        is_reserved_member_name(ir_name, "timestamp_end") ||
                                        is_reserved_member_name(ir_name, "events_discarded") ||
                                        is_reserved_member_name(ir_name, "packet_seq_num")) {
-                               BT_LOGE("Unsupported reserved TSDL structure field class member "
+                               BT_COMP_LOGE("Unsupported reserved TSDL structure field class member "
                                        "or variant field class option name: name=\"%s\"",
                                        ir_name);
                                ret = -1;
@@ -127,7 +130,7 @@ int cur_path_stack_push(struct ctx *ctx,
 
                ret = fs_sink_ctf_protect_name(field_path_elem->name);
                if (ret) {
-                       BT_LOGE("Unsupported non-TSDL structure field class member "
+                       BT_COMP_LOGE("Unsupported non-TSDL structure field class member "
                                "or variant field class option name: name=\"%s\"",
                                ir_name);
                        goto end;
@@ -551,14 +554,14 @@ int translate_structure_field_class_members(struct ctx *ctx,
                ret = cur_path_stack_push(ctx, i, name, memb_ir_fc,
                        (void *) struct_fc);
                if (ret) {
-                       BT_LOGE("Cannot translate structure field class member: "
+                       BT_COMP_LOGE("Cannot translate structure field class member: "
                                "name=\"%s\"", name);
                        goto end;
                }
 
                ret = translate_field_class(ctx);
                if (ret) {
-                       BT_LOGE("Cannot translate structure field class member: "
+                       BT_COMP_LOGE("Cannot translate structure field class member: "
                                "name=\"%s\"", name);
                        goto end;
                }
@@ -624,14 +627,14 @@ int translate_variant_field_class(struct ctx *ctx)
                        opt);
                ret = cur_path_stack_push(ctx, i, name, opt_ir_fc, (void *) fc);
                if (ret) {
-                       BT_LOGE("Cannot translate variant field class option: "
+                       BT_COMP_LOGE("Cannot translate variant field class option: "
                                "name=\"%s\"", name);
                        goto end;
                }
 
                ret = translate_field_class(ctx);
                if (ret) {
-                       BT_LOGE("Cannot translate variant field class option: "
+                       BT_COMP_LOGE("Cannot translate variant field class option: "
                                "name=\"%s\"", name);
                        goto end;
                }
@@ -660,13 +663,13 @@ int translate_static_array_field_class(struct ctx *ctx)
        ret = cur_path_stack_push(ctx, UINT64_C(-1), NULL, elem_ir_fc,
                (void *) fc);
        if (ret) {
-               BT_LOGE_STR("Cannot translate static array field class element.");
+               BT_COMP_LOGE_STR("Cannot translate static array field class element.");
                goto end;
        }
 
        ret = translate_field_class(ctx);
        if (ret) {
-               BT_LOGE_STR("Cannot translate static array field class element.");
+               BT_COMP_LOGE_STR("Cannot translate static array field class element.");
                goto end;
        }
 
@@ -701,13 +704,13 @@ int translate_dynamic_array_field_class(struct ctx *ctx)
        ret = cur_path_stack_push(ctx, UINT64_C(-1), NULL, elem_ir_fc,
                (void *) fc);
        if (ret) {
-               BT_LOGE_STR("Cannot translate dynamic array field class element.");
+               BT_COMP_LOGE_STR("Cannot translate dynamic array field class element.");
                goto end;
        }
 
        ret = translate_field_class(ctx);
        if (ret) {
-               BT_LOGE_STR("Cannot translate dynamic array field class element.");
+               BT_COMP_LOGE_STR("Cannot translate dynamic array field class element.");
                goto end;
        }
 
@@ -1008,14 +1011,14 @@ int translate_scope_field_class(struct ctx *ctx, bt_scope scope,
        BT_ASSERT(ctx->cur_path->len == 0);
        ret = cur_path_stack_push(ctx, UINT64_C(-1), NULL, ir_fc, NULL);
        if (ret) {
-               BT_LOGE("Cannot translate scope structure field class: "
+               BT_COMP_LOGE("Cannot translate scope structure field class: "
                        "scope=%d", scope);
                goto end;
        }
 
        ret = translate_structure_field_class_members(ctx, (void *) *fc, ir_fc);
        if (ret) {
-               BT_LOGE("Cannot translate scope structure field class: "
+               BT_COMP_LOGE("Cannot translate scope structure field class: "
                        "scope=%d", scope);
                goto end;
        }
@@ -1030,13 +1033,14 @@ end:
 }
 
 static inline
-void ctx_init(struct ctx *ctx, bt_logging_level log_level)
+void ctx_init(struct ctx *ctx, struct fs_sink_comp *fs_sink)
 {
        memset(ctx, 0, sizeof(struct ctx));
        ctx->cur_path = g_array_new(FALSE, TRUE,
                sizeof(struct field_path_elem));
        BT_ASSERT(ctx->cur_path);
-       ctx->log_level = log_level;
+       ctx->log_level = fs_sink->log_level;
+       ctx->self_comp = fs_sink->self_comp;
 }
 
 static inline
@@ -1049,10 +1053,10 @@ void ctx_fini(struct ctx *ctx)
 }
 
 static
-int translate_event_class(struct fs_sink_ctf_stream_class *sc,
+int translate_event_class(struct fs_sink_comp *fs_sink,
+               struct fs_sink_ctf_stream_class *sc,
                const bt_event_class *ir_ec,
-               struct fs_sink_ctf_event_class **out_ec,
-               bt_logging_level log_level)
+               struct fs_sink_ctf_event_class **out_ec)
 {
        int ret = 0;
        struct ctx ctx;
@@ -1061,7 +1065,7 @@ int translate_event_class(struct fs_sink_ctf_stream_class *sc,
        BT_ASSERT(sc);
        BT_ASSERT(ir_ec);
 
-       ctx_init(&ctx, log_level);
+       ctx_init(&ctx, fs_sink);
        ec = fs_sink_ctf_event_class_create(sc, ir_ec);
        BT_ASSERT(ec);
        ctx.cur_sc = sc;
@@ -1089,10 +1093,10 @@ end:
 
 BT_HIDDEN
 int try_translate_event_class_trace_ir_to_ctf_ir(
+               struct fs_sink_comp *fs_sink,
                struct fs_sink_ctf_stream_class *sc,
                const bt_event_class *ir_ec,
-               struct fs_sink_ctf_event_class **out_ec,
-               bt_logging_level log_level)
+               struct fs_sink_ctf_event_class **out_ec)
 {
        int ret = 0;
 
@@ -1105,21 +1109,21 @@ int try_translate_event_class_trace_ir_to_ctf_ir(
                goto end;
        }
 
-       ret = translate_event_class(sc, ir_ec, out_ec, log_level);
+       ret = translate_event_class(fs_sink, sc, ir_ec, out_ec);
 
 end:
        return ret;
 }
 
-bool default_clock_class_name_exists(struct fs_sink_ctf_trace_class *tc,
+bool default_clock_class_name_exists(struct fs_sink_ctf_trace *trace,
                const char *name)
 {
        bool exists = false;
        uint64_t i;
 
-       for (i = 0; i < tc->stream_classes->len; i++) {
+       for (i = 0; i < trace->stream_classes->len; i++) {
                struct fs_sink_ctf_stream_class *sc =
-                       tc->stream_classes->pdata[i];
+                       trace->stream_classes->pdata[i];
 
                if (sc->default_clock_class_name->len == 0) {
                        /* No default clock class */
@@ -1145,7 +1149,7 @@ void make_unique_default_clock_class_name(struct fs_sink_ctf_stream_class *sc)
        g_string_assign(sc->default_clock_class_name, "");
        sprintf(buf, "default");
 
-       while (default_clock_class_name_exists(sc->tc, buf)) {
+       while (default_clock_class_name_exists(sc->trace, buf)) {
                sprintf(buf, "default%u", suffix);
                suffix++;
        }
@@ -1154,18 +1158,18 @@ void make_unique_default_clock_class_name(struct fs_sink_ctf_stream_class *sc)
 }
 
 static
-int translate_stream_class(struct fs_sink_ctf_trace_class *tc,
+int translate_stream_class(struct fs_sink_comp *fs_sink,
+               struct fs_sink_ctf_trace *trace,
                const bt_stream_class *ir_sc,
-               struct fs_sink_ctf_stream_class **out_sc,
-               bt_logging_level log_level)
+               struct fs_sink_ctf_stream_class **out_sc)
 {
        int ret = 0;
        struct ctx ctx;
 
-       BT_ASSERT(tc);
+       BT_ASSERT(trace);
        BT_ASSERT(ir_sc);
-       ctx_init(&ctx, log_level);
-       *out_sc = fs_sink_ctf_stream_class_create(tc, ir_sc);
+       ctx_init(&ctx, fs_sink);
+       *out_sc = fs_sink_ctf_stream_class_create(trace, ir_sc);
        BT_ASSERT(*out_sc);
 
        /* Set default clock class's protected name, if any */
@@ -1229,51 +1233,51 @@ end:
 
 BT_HIDDEN
 int try_translate_stream_class_trace_ir_to_ctf_ir(
-               struct fs_sink_ctf_trace_class *tc,
+               struct fs_sink_comp *fs_sink,
+               struct fs_sink_ctf_trace *trace,
                const bt_stream_class *ir_sc,
-               struct fs_sink_ctf_stream_class **out_sc,
-               bt_logging_level log_level)
+               struct fs_sink_ctf_stream_class **out_sc)
 {
        int ret = 0;
        uint64_t i;
 
-       BT_ASSERT(tc);
+       BT_ASSERT(trace);
        BT_ASSERT(ir_sc);
 
-       for (i = 0; i < tc->stream_classes->len; i++) {
-               *out_sc = tc->stream_classes->pdata[i];
+       for (i = 0; i < trace->stream_classes->len; i++) {
+               *out_sc = trace->stream_classes->pdata[i];
 
                if ((*out_sc)->ir_sc == ir_sc) {
                        goto end;
                }
        }
 
-       ret = translate_stream_class(tc, ir_sc, out_sc, log_level);
+       ret = translate_stream_class(fs_sink, trace, ir_sc, out_sc);
 
 end:
        return ret;
 }
 
 BT_HIDDEN
-struct fs_sink_ctf_trace_class *translate_trace_class_trace_ir_to_ctf_ir(
-               const bt_trace_class *ir_tc, bt_logging_level log_level)
+struct fs_sink_ctf_trace *translate_trace_trace_ir_to_ctf_ir(
+               struct fs_sink_comp *fs_sink, const bt_trace *ir_trace)
 {
        uint64_t count;
        uint64_t i;
-       struct fs_sink_ctf_trace_class *tc = NULL;
+       struct fs_sink_ctf_trace *trace = NULL;
 
-       /* Check that trace class's environment is TSDL-compatible */
-       count = bt_trace_class_get_environment_entry_count(ir_tc);
+       /* Check that trace's environment is TSDL-compatible */
+       count = bt_trace_get_environment_entry_count(ir_trace);
        for (i = 0; i < count; i++) {
                const char *name;
                const bt_value *val;
 
-               bt_trace_class_borrow_environment_entry_by_index_const(
-                       ir_tc, i, &name, &val);
+               bt_trace_borrow_environment_entry_by_index_const(
+                       ir_trace, i, &name, &val);
 
                if (!fs_sink_ctf_ist_valid_identifier(name)) {
-                       BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level,
-                               BT_LOG_TAG,
+                       BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, fs_sink->log_level,
+                               fs_sink->self_comp,
                                "Unsupported trace class's environment entry name: "
                                "name=\"%s\"", name);
                        goto end;
@@ -1284,8 +1288,8 @@ struct fs_sink_ctf_trace_class *translate_trace_class_trace_ir_to_ctf_ir(
                case BT_VALUE_TYPE_STRING:
                        break;
                default:
-                       BT_LOG_WRITE_CUR_LVL(BT_LOG_ERROR, log_level,
-                               BT_LOG_TAG,
+                       BT_COMP_LOG_CUR_LVL(BT_LOG_ERROR, fs_sink->log_level,
+                               fs_sink->self_comp,
                                "Unsupported trace class's environment entry value type: "
                                "type=%s",
                                bt_common_value_type_string(
@@ -1294,9 +1298,9 @@ struct fs_sink_ctf_trace_class *translate_trace_class_trace_ir_to_ctf_ir(
                }
        }
 
-       tc = fs_sink_ctf_trace_class_create(ir_tc);
-       BT_ASSERT(tc);
+       trace = fs_sink_ctf_trace_create(ir_trace);
+       BT_ASSERT(trace);
 
 end:
-       return tc;
+       return trace;
 }
This page took 0.031457 seconds and 4 git commands to generate.