Notification iterator: transform precondition checks to BT_ASSERT_PRE()
[babeltrace.git] / lib / ctf-ir / event-class.c
index 8ff8bc0394ed9f5f2b69d62ba74d219f7c5e5747..4152a0b88293cd736e4fe24f2cd46a81df2bbde9 100644 (file)
 #include <babeltrace/ctf-ir/trace-internal.h>
 #include <babeltrace/ctf-ir/validation-internal.h>
 #include <babeltrace/ctf-ir/utils.h>
+#include <babeltrace/ctf-ir/utils-internal.h>
 #include <babeltrace/ref.h>
 #include <babeltrace/ctf-ir/attributes-internal.h>
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/endian-internal.h>
 #include <babeltrace/types.h>
 #include <babeltrace/values-internal.h>
+#include <babeltrace/assert-internal.h>
 #include <inttypes.h>
 #include <stdlib.h>
 
@@ -409,7 +411,7 @@ int bt_event_class_add_field(struct bt_event_class *event_class,
                goto end;
        }
 
-       assert(bt_field_type_get_type_id(event_class->fields) ==
+       BT_ASSERT(bt_field_type_get_type_id(event_class->fields) ==
                BT_FIELD_TYPE_ID_STRUCT);
        ret = bt_field_type_structure_add_field(event_class->fields,
                type, name);
@@ -442,7 +444,7 @@ int64_t bt_event_class_get_payload_type_field_count(
                goto end;
        }
 
-       assert(bt_field_type_get_type_id(event_class->fields) ==
+       BT_ASSERT(bt_field_type_get_type_id(event_class->fields) ==
                BT_FIELD_TYPE_ID_STRUCT);
        ret = bt_field_type_structure_get_field_count(event_class->fields);
 end:
@@ -471,7 +473,7 @@ int bt_event_class_get_payload_type_field_by_index(
                goto end;
        }
 
-       assert(bt_field_type_get_type_id(event_class->fields) ==
+       BT_ASSERT(bt_field_type_get_type_id(event_class->fields) ==
                BT_FIELD_TYPE_ID_STRUCT);
        ret = bt_field_type_structure_get_field_by_index(event_class->fields,
                field_name, field_type, index);
@@ -501,7 +503,7 @@ bt_event_class_get_payload_type_field_type_by_name(
                goto end;
        }
 
-       assert(bt_field_type_get_type_id(event_class->fields) ==
+       BT_ASSERT(bt_field_type_get_type_id(event_class->fields) ==
                BT_FIELD_TYPE_ID_STRUCT);
        name_quark = g_quark_try_string(name);
        if (!name_quark) {
@@ -622,7 +624,7 @@ void bt_event_class_destroy(struct bt_object *obj)
 BT_HIDDEN
 void bt_event_class_freeze(struct bt_event_class *event_class)
 {
-       assert(event_class);
+       BT_ASSERT(event_class);
 
        if (event_class->frozen) {
                return;
@@ -645,8 +647,8 @@ int bt_event_class_serialize(struct bt_event_class *event_class,
        int ret = 0;
        struct bt_value *attr_value = NULL;
 
-       assert(event_class);
-       assert(context);
+       BT_ASSERT(event_class);
+       BT_ASSERT(context);
        BT_LOGD("Serializing event class's metadata: "
                "event-class-addr=%p, event-class-name=\"%s\", "
                "event-class-id=%" PRId64 ", metadata-context-addr=%p",
@@ -659,7 +661,7 @@ int bt_event_class_serialize(struct bt_event_class *event_class,
        /* Serialize attributes */
        g_string_append_printf(context->string, "\tname = \"%s\";\n",
                event_class->name->str);
-       assert(event_class->id >= 0);
+       BT_ASSERT(event_class->id >= 0);
        g_string_append_printf(context->string, "\tid = %" PRId64 ";\n",
                event_class->id);
        g_string_append_printf(context->string, "\tstream_id = %" PRId64 ";\n",
@@ -709,3 +711,50 @@ end:
        BT_PUT(attr_value);
        return ret;
 }
+
+BT_HIDDEN
+int bt_event_class_validate_single_clock_class(
+               struct bt_event_class *event_class,
+               struct bt_clock_class **expected_clock_class)
+{
+       int ret = 0;
+
+       BT_ASSERT(event_class);
+       BT_ASSERT(expected_clock_class);
+       ret = bt_validate_single_clock_class(event_class->context,
+               expected_clock_class);
+       if (ret) {
+               BT_LOGW("Event class's context field type "
+                       "is not recursively mapped to the "
+                       "expected clock class: "
+                       "event-class-addr=%p, "
+                       "event-class-name=\"%s\", "
+                       "event-class-id=%" PRId64 ", "
+                       "ft-addr=%p",
+                       event_class,
+                       bt_event_class_get_name(event_class),
+                       event_class->id,
+                       event_class->context);
+               goto end;
+       }
+
+       ret = bt_validate_single_clock_class(event_class->fields,
+               expected_clock_class);
+       if (ret) {
+               BT_LOGW("Event class's payload field type "
+                       "is not recursively mapped to the "
+                       "expected clock class: "
+                       "event-class-addr=%p, "
+                       "event-class-name=\"%s\", "
+                       "event-class-id=%" PRId64 ", "
+                       "ft-addr=%p",
+                       event_class,
+                       bt_event_class_get_name(event_class),
+                       event_class->id,
+                       event_class->fields);
+               goto end;
+       }
+
+end:
+       return ret;
+}
This page took 0.025429 seconds and 4 git commands to generate.