ctf.fs: bt_ctf_notif_iter_create(): assert() that all medops exist
[babeltrace.git] / formats / ctf / ir / stream-class.c
index f5b8923360c9d40f6e4a9e76a97fe11a5529b9d9..403f5dbbf51089a5d7783b0701faeaafbd86dff7 100644 (file)
@@ -27,7 +27,8 @@
  */
 
 #include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-ir/clock-internal.h>
+#include <babeltrace/ctf-writer/clock-internal.h>
+#include <babeltrace/ctf-ir/clock-class-internal.h>
 #include <babeltrace/ctf-writer/event.h>
 #include <babeltrace/ctf-ir/event-class-internal.h>
 #include <babeltrace/ctf-ir/event-internal.h>
@@ -138,8 +139,7 @@ struct bt_ctf_clock *bt_ctf_stream_class_get_clock(
                goto end;
        }
 
-       clock = stream_class->clock;
-       bt_get(clock);
+       clock = bt_get(stream_class->clock);
 end:
        return clock;
 }
@@ -150,46 +150,41 @@ int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class,
        int ret = 0;
        struct bt_ctf_field_type *timestamp_field = NULL;
 
-       if (!stream_class || stream_class->frozen ||
-                       !bt_ctf_clock_is_valid(clock)) {
+       if (!stream_class || !clock || stream_class->frozen) {
                ret = -1;
                goto end;
        }
 
        /*
-        * Look for a "timestamp" field in the stream class' event header type
-        * and map the stream's clock to that field if no current mapping is
-        * currently set.
+        * Look for a "timestamp" integer field type in the stream
+        * class's event header field type and map the stream class's
+        * clock's class to that field type if there's no current
+        * mapping.
         */
        timestamp_field = bt_ctf_field_type_structure_get_field_type_by_name(
                stream_class->event_header_type, "timestamp");
        if (timestamp_field) {
-               struct bt_ctf_clock *mapped_clock;
-
-               mapped_clock = bt_ctf_field_type_integer_get_mapped_clock(
-                       timestamp_field);
-               if (mapped_clock) {
-                       bt_put(mapped_clock);
-                       goto end;
+               struct bt_ctf_clock_class *mapped_clock_class =
+                       bt_ctf_field_type_integer_get_mapped_clock_class(
+                               timestamp_field);
+
+               if (!mapped_clock_class) {
+                       ret = bt_ctf_field_type_integer_set_mapped_clock_class(
+                               timestamp_field, clock->clock_class);
+                       if (ret) {
+                               goto end;
+                       }
                }
 
-               ret = bt_ctf_field_type_integer_set_mapped_clock(
-                       timestamp_field, clock);
-               if (ret) {
-                       goto end;
-               }
+               BT_PUT(mapped_clock_class);
        }
 
-       if (stream_class->clock) {
-               bt_put(stream_class->clock);
-       }
+       /* Replace the current clock of this stream class. */
+       bt_put(stream_class->clock);
+       stream_class->clock = bt_get(clock);
 
-       stream_class->clock = clock;
-       bt_get(clock);
 end:
-       if (timestamp_field) {
-               bt_put(timestamp_field);
-       }
+       bt_put(timestamp_field);
        return ret;
 }
 
@@ -478,10 +473,10 @@ int bt_ctf_stream_class_add_event_class(
 
        /* Notifiy listeners of the trace's schema modification. */
        if (trace) {
-               struct bt_ctf_ir_element element = { .element = event_class,
-                               .type = BT_CTF_IR_TYPE_EVENT_CLASS };
+               struct bt_ctf_object obj = { .object = event_class,
+                               .type = BT_CTF_OBJECT_TYPE_EVENT_CLASS };
 
-               (void) bt_ctf_trace_element_modification(&element, trace);
+               (void) bt_ctf_trace_object_modification(&obj, trace);
        }
 end:
        BT_PUT(trace);
@@ -581,7 +576,6 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type(
                goto end;
        }
 
-       assert(stream_class->packet_context_type);
        bt_get(stream_class->packet_context_type);
        ret = stream_class->packet_context_type;
 end:
@@ -594,18 +588,15 @@ int bt_ctf_stream_class_set_packet_context_type(
 {
        int ret = 0;
 
-       if (!stream_class || !packet_context_type || stream_class->frozen) {
+       if (!stream_class || stream_class->frozen) {
                ret = -1;
                goto end;
        }
 
-       assert(stream_class->packet_context_type);
-       if (stream_class->packet_context_type == packet_context_type) {
-               goto end;
-       }
-       if (bt_ctf_field_type_get_type_id(packet_context_type) !=
-               BT_CTF_TYPE_ID_STRUCT) {
-               /* A packet context must be a structure */
+       if (packet_context_type &&
+                       bt_ctf_field_type_get_type_id(packet_context_type) !=
+                               BT_CTF_TYPE_ID_STRUCT) {
+               /* A packet context must be a structure. */
                ret = -1;
                goto end;
        }
@@ -626,7 +617,6 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_event_header_type(
                goto end;
        }
 
-       assert(stream_class->event_header_type);
        bt_get(stream_class->event_header_type);
        ret = stream_class->event_header_type;
 end:
@@ -639,25 +629,21 @@ int bt_ctf_stream_class_set_event_header_type(
 {
        int ret = 0;
 
-       if (!stream_class || !event_header_type || stream_class->frozen) {
+       if (!stream_class || stream_class->frozen) {
                ret = -1;
                goto end;
        }
 
-       assert(stream_class->event_header_type);
-       if (stream_class->event_header_type == event_header_type) {
-               goto end;
-       }
-       if (bt_ctf_field_type_get_type_id(event_header_type) !=
-               BT_CTF_TYPE_ID_STRUCT) {
-               /* An event header must be a structure */
+       if (event_header_type &&
+                       bt_ctf_field_type_get_type_id(event_header_type) !=
+                               BT_CTF_TYPE_ID_STRUCT) {
+               /* An event header must be a structure. */
                ret = -1;
                goto end;
        }
 
        bt_put(stream_class->event_header_type);
-       bt_get(event_header_type);
-       stream_class->event_header_type = event_header_type;
+       stream_class->event_header_type = bt_get(event_header_type);
 end:
        return ret;
 }
@@ -671,7 +657,6 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_event_context_type(
                goto end;
        }
 
-       assert(stream_class->event_context_type);
        bt_get(stream_class->event_context_type);
        ret = stream_class->event_context_type;
 end:
@@ -684,21 +669,21 @@ int bt_ctf_stream_class_set_event_context_type(
 {
        int ret = 0;
 
-       if (!stream_class || !event_context_type || stream_class->frozen) {
+       if (!stream_class || stream_class->frozen) {
                ret = -1;
                goto end;
        }
 
-       if (bt_ctf_field_type_get_type_id(event_context_type) !=
-               BT_CTF_TYPE_ID_STRUCT) {
-               /* A packet context must be a structure */
+       if (event_context_type &&
+                       bt_ctf_field_type_get_type_id(event_context_type) !=
+                               BT_CTF_TYPE_ID_STRUCT) {
+               /* A packet context must be a structure. */
                ret = -1;
                goto end;
        }
 
        bt_put(stream_class->event_context_type);
-       bt_get(event_context_type);
-       stream_class->event_context_type = event_context_type;
+       stream_class->event_context_type = bt_get(event_context_type);
 end:
        return ret;
 }
@@ -728,29 +713,29 @@ void *get_event_class(void *element, int i)
 }
 
 static
-int visit_event_class(void *element, bt_ctf_ir_visitor visitor,void *data)
+int visit_event_class(void *object, bt_ctf_visitor visitor,void *data)
 {
-       struct bt_ctf_ir_element ir_element =
-                       { .element = element,
-                       .type = BT_CTF_IR_TYPE_EVENT_CLASS };
+       struct bt_ctf_object obj =
+                       { .object = object,
+                       .type = BT_CTF_OBJECT_TYPE_EVENT_CLASS };
 
-       return visitor(&ir_element, data);
+       return visitor(&obj, data);
 }
 
 int bt_ctf_stream_class_visit(struct bt_ctf_stream_class *stream_class,
-               bt_ctf_ir_visitor visitor, void *data)
+               bt_ctf_visitor visitor, void *data)
 {
        int ret;
-       struct bt_ctf_ir_element element =
-                       { .element = stream_class,
-                       .type = BT_CTF_IR_TYPE_STREAM_CLASS };
+       struct bt_ctf_object obj =
+                       { .object = stream_class,
+                       .type = BT_CTF_OBJECT_TYPE_STREAM_CLASS };
 
        if (!stream_class || !visitor) {
                ret = -1;
                goto end;
        }
 
-       ret = visitor_helper(&element, get_event_class_count,
+       ret = visitor_helper(&obj, get_event_class_count,
                        get_event_class,
                        visit_event_class, visitor, data);
 end:
@@ -768,7 +753,10 @@ void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class)
        bt_ctf_field_type_freeze(stream_class->event_header_type);
        bt_ctf_field_type_freeze(stream_class->packet_context_type);
        bt_ctf_field_type_freeze(stream_class->event_context_type);
-       bt_ctf_clock_freeze(stream_class->clock);
+
+       if (stream_class->clock) {
+               bt_ctf_clock_class_freeze(stream_class->clock->clock_class);
+       }
 }
 
 BT_HIDDEN
@@ -822,11 +810,13 @@ int bt_ctf_stream_class_serialize(struct bt_ctf_stream_class *stream_class,
                goto end;
        }
 
-       g_string_append(context->string, ";\n\n\tpacket.context := ");
-       ret = bt_ctf_field_type_serialize(stream_class->packet_context_type,
-               context);
-       if (ret) {
-               goto end;
+       if (stream_class->packet_context_type) {
+               g_string_append(context->string, ";\n\n\tpacket.context := ");
+               ret = bt_ctf_field_type_serialize(stream_class->packet_context_type,
+                       context);
+               if (ret) {
+                       goto end;
+               }
        }
 
        if (stream_class->event_context_type) {
This page took 0.027841 seconds and 4 git commands to generate.