Add stream_event_context accessors
[babeltrace.git] / formats / ctf / ir / stream.c
index 9b0be90b7b2e97ad96f36e670060cb51192e33a9..d4e1be159330b4dda5eb22606d898ed93b142338 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * stream.c
  *
- * Babeltrace CTF Writer
+ * Babeltrace CTF IR - Stream
  *
  * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
@@ -67,7 +67,20 @@ struct bt_ctf_stream *bt_ctf_stream_create(
                goto error_destroy;
        }
 
-       /* Initialize events_discarded*/
+       /*
+        * A stream class may not have a stream event context defined
+        * in which case this stream will never have a stream_event_context
+        * member since, after a stream's creation, the parent stream class
+        * is "frozen" (immutable).
+        */
+       if (stream_class->event_context_type) {
+               stream->event_context = bt_ctf_field_create(
+                       stream_class->event_context_type);
+               if (!stream->packet_context) {
+                       goto error_destroy;
+               }
+       }
+
        ret = set_structure_field_integer(stream->packet_context,
                "events_discarded", 0);
        if (ret) {
@@ -252,6 +265,7 @@ int bt_ctf_stream_append_event(struct bt_ctf_stream *stream,
 {
        int ret = 0;
        uint64_t timestamp;
+       struct bt_ctf_field *event_context_copy = NULL;
 
        if (!stream || !event) {
                ret = -1;
@@ -326,7 +340,11 @@ int bt_ctf_stream_flush(struct bt_ctf_stream *stream)
        struct bt_ctf_field *integer = NULL;
        struct ctf_stream_pos packet_context_pos;
 
-       if (!stream) {
+       if (!stream || stream->pos.fd < 0) {
+               /*
+                * Stream does not have an associated fd. It is,
+                * therefore, not a stream being used to write events.
+                */
                ret = -1;
                goto end;
        }
This page took 0.025113 seconds and 4 git commands to generate.