lib: do not allow any mapped clock class in trace's packet header FT
[babeltrace.git] / lib / ctf-ir / trace.c
index e21bf0eb4ef03485fbcda336dbd725b60729e534..7a583862e7a76b8aeab3ca2484bb78bcafdcc589 100644 (file)
@@ -43,6 +43,7 @@
 #include <babeltrace/ctf-ir/validation-internal.h>
 #include <babeltrace/ctf-ir/visitor-internal.h>
 #include <babeltrace/ctf-ir/utils.h>
+#include <babeltrace/ctf-ir/utils-internal.h>
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/values.h>
 #include <babeltrace/values-internal.h>
@@ -1108,6 +1109,34 @@ end:
        return is_valid;
 }
 
+static
+int check_packet_header_type_has_no_clock_class(struct bt_trace *trace)
+{
+       int ret = 0;
+
+       if (trace->packet_header_type) {
+               struct bt_clock_class *clock_class = NULL;
+
+               ret = bt_validate_single_clock_class(trace->packet_header_type,
+                       &clock_class);
+               bt_put(clock_class);
+               if (ret || clock_class) {
+                       BT_LOGW("Trace's packet header field type cannot "
+                               "contain a field type which is mapped to "
+                               "a clock class: "
+                               "trace-addr=%p, trace-name=\"%s\", "
+                               "clock-class-name=\"%s\"",
+                               trace, bt_trace_get_name(trace),
+                               clock_class ?
+                                       bt_clock_class_get_name(clock_class) :
+                                       NULL);
+                       ret = -1;
+               }
+       }
+
+       return ret;
+}
+
 int bt_trace_add_stream_class(struct bt_trace *trace,
                struct bt_stream_class *stream_class)
 {
@@ -1216,6 +1245,12 @@ int bt_trace_add_stream_class(struct bt_trace *trace,
                }
        }
 
+       ret = check_packet_header_type_has_no_clock_class(trace);
+       if (ret) {
+               /* check_packet_header_type_has_no_clock_class() logs errors */
+               goto end;
+       }
+
        /*
         * We're about to freeze both the trace and the stream class.
         * Also, each event class contained in this stream class are
@@ -2164,6 +2199,12 @@ int bt_trace_set_is_static(struct bt_trace *trace)
                goto end;
        }
 
+       ret = check_packet_header_type_has_no_clock_class(trace);
+       if (ret) {
+               /* check_packet_header_type_has_no_clock_class() logs errors */
+               goto end;
+       }
+
        trace->is_static = BT_TRUE;
        bt_trace_freeze(trace);
        BT_LOGV("Set trace static: addr=%p, name=\"%s\"",
This page took 0.02424 seconds and 4 git commands to generate.