Fix: define macros for logging levels
[babeltrace.git] / src / plugins / ctf / common / metadata / decoder.c
index 17b2aa4bd211be1474d4d7da288207f7cc7fc2a7..a62beebfcd99cce5dacafe88d96883c8492c14b4 100644 (file)
 #include "decoder.h"
 #include "scanner.h"
 #include "logging.h"
+#include "parser-wrap.h"
 
 #define TSDL_MAGIC     0x75d11d57
 
-extern
-int yydebug;
-
 struct ctf_metadata_decoder {
        struct ctf_scanner *scanner;
        GString *text;
@@ -271,9 +269,11 @@ enum ctf_metadata_decoder_status ctf_metadata_decoder_append_content(
                }
        }
 
+#if YYDEBUG
        if (BT_LOG_ON_TRACE) {
                yydebug = 1;
        }
+#endif
 
        /* Save the file's position: we'll seek back to append the plain text */
        BT_ASSERT(fp);
@@ -341,7 +341,9 @@ enum ctf_metadata_decoder_status ctf_metadata_decoder_append_content(
        }
 
 end:
+#if YYDEBUG
        yydebug = 0;
+#endif
 
        if (fp && close_fp) {
                if (fclose(fp)) {
@@ -359,8 +361,8 @@ BT_HIDDEN
 bt_trace_class *ctf_metadata_decoder_get_ir_trace_class(
                struct ctf_metadata_decoder *mdec)
 {
-       BT_ASSERT(mdec);
-       BT_ASSERT(mdec->config.create_trace_class);
+       BT_ASSERT_DBG(mdec);
+       BT_ASSERT_DBG(mdec->config.create_trace_class);
        return ctf_visitor_generate_ir_get_ir_trace_class(mdec->visitor);
 }
 
@@ -368,23 +370,23 @@ BT_HIDDEN
 struct ctf_trace_class *ctf_metadata_decoder_borrow_ctf_trace_class(
                struct ctf_metadata_decoder *mdec)
 {
-       BT_ASSERT(mdec);
-       BT_ASSERT(mdec->config.create_trace_class);
+       BT_ASSERT_DBG(mdec);
+       BT_ASSERT_DBG(mdec->config.create_trace_class);
        return ctf_visitor_generate_ir_borrow_ctf_trace_class(mdec->visitor);
 }
 
 BT_HIDDEN
 const char *ctf_metadata_decoder_get_text(struct ctf_metadata_decoder *mdec)
 {
-       BT_ASSERT(mdec);
-       BT_ASSERT(mdec->config.keep_plain_text);
+       BT_ASSERT_DBG(mdec);
+       BT_ASSERT_DBG(mdec->config.keep_plain_text);
        return mdec->text->str;
 }
 
 BT_HIDDEN
 int ctf_metadata_decoder_get_byte_order(struct ctf_metadata_decoder *mdec)
 {
-       BT_ASSERT(mdec);
+       BT_ASSERT_DBG(mdec);
        return mdec->bo;
 }
 
@@ -394,7 +396,7 @@ int ctf_metadata_decoder_get_uuid(struct ctf_metadata_decoder *mdec,
 {
        int ret = 0;
 
-       BT_ASSERT(mdec);
+       BT_ASSERT_DBG(mdec);
 
        if (!mdec->is_uuid_set) {
                ret = -1;
@@ -406,3 +408,80 @@ int ctf_metadata_decoder_get_uuid(struct ctf_metadata_decoder *mdec,
 end:
        return ret;
 }
+
+static
+enum ctf_metadata_decoder_status find_uuid_in_trace_decl(
+               struct ctf_metadata_decoder *mdec, struct ctf_node *trace_node,
+               bt_uuid_t uuid)
+{
+       enum ctf_metadata_decoder_status status =
+               CTF_METADATA_DECODER_STATUS_OK;
+       struct ctf_node *entry_node;
+       struct bt_list_head *decl_list = &trace_node->u.trace.declaration_list;
+       char *left = NULL;
+
+       bt_list_for_each_entry(entry_node, decl_list, siblings) {
+               if (entry_node->type == NODE_CTF_EXPRESSION) {
+                       int ret;
+
+                       left = ctf_ast_concatenate_unary_strings(
+                               &entry_node->u.ctf_expression.left);
+                       if (!left) {
+                               BT_COMP_LOGE("Cannot concatenate unary strings.");
+                               status = CTF_METADATA_DECODER_STATUS_ERROR;
+                               goto end;
+                       }
+
+                       if (strcmp(left, "uuid") == 0) {
+                               ret = ctf_ast_get_unary_uuid(
+                                       &entry_node->u.ctf_expression.right,
+                                       uuid, mdec->config.log_level,
+                                       mdec->config.self_comp);
+                               if (ret) {
+                                       BT_COMP_LOGE("Invalid trace's `uuid` attribute.");
+                                       status = CTF_METADATA_DECODER_STATUS_ERROR;
+                                       goto end;
+                               }
+
+                               goto end;
+                       }
+
+                       g_free(left);
+                       left = NULL;
+               }
+       }
+
+       status = CTF_METADATA_DECODER_STATUS_NONE;
+
+end:
+       g_free(left);
+       return status;
+}
+
+BT_HIDDEN
+enum ctf_metadata_decoder_status ctf_metadata_decoder_get_trace_class_uuid(
+               struct ctf_metadata_decoder *mdec, bt_uuid_t uuid)
+{
+       enum ctf_metadata_decoder_status status =
+               CTF_METADATA_DECODER_STATUS_INCOMPLETE;
+       struct ctf_node *root_node = &mdec->scanner->ast->root;
+       struct ctf_node *trace_node;
+
+       if (!root_node) {
+               status = CTF_METADATA_DECODER_STATUS_INCOMPLETE;
+               goto end;
+       }
+
+       trace_node =
+               bt_list_entry(root_node->u.root.trace.next,
+                       struct ctf_node, siblings);
+       if (!trace_node) {
+               status = CTF_METADATA_DECODER_STATUS_INCOMPLETE;
+               goto end;
+       }
+
+       status = find_uuid_in_trace_decl(mdec, trace_node, uuid);
+
+end:
+       return status;
+}
This page took 0.025398 seconds and 4 git commands to generate.