Add stream_event_context accessors
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 10 Dec 2014 00:05:47 +0000 (19:05 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 15 Dec 2014 23:50:19 +0000 (18:50 -0500)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
formats/ctf/ir/event-fields.c
formats/ctf/ir/stream-class.c
formats/ctf/ir/stream.c
include/babeltrace/ctf-ir/stream-class-internal.h
include/babeltrace/ctf-ir/stream-class.h
include/babeltrace/ctf-ir/stream-internal.h
include/babeltrace/ctf-ir/stream.h

index e49a17be9b147f732b36e58b739cccef6e33893a..bde69a224bfb6e06b190a07f0472865639a1fe11 100644 (file)
@@ -993,13 +993,11 @@ struct bt_ctf_field *bt_ctf_field_copy(struct bt_ctf_field *field)
        enum ctf_type_id type_id;
 
        if (!field) {
-               ret = -1;
                goto end;
        }
 
        type_id = bt_ctf_field_type_get_type_id(field->type);
        if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES) {
-               ret = -1;
                goto end;
        }
 
index 6ccaac3c41d60eb6ae308f49e7c56a9c7514139b..edbd43b6948ab2747a6e635144dd01a53c5921b9 100644 (file)
@@ -306,6 +306,47 @@ end:
        return ret;
 }
 
+struct bt_ctf_field_type *bt_ctf_stream_class_get_event_context_type(
+               struct bt_ctf_stream_class *stream_class)
+{
+       struct bt_ctf_field_type *ret = NULL;
+
+       if (!stream_class || !stream_class->event_context_type) {
+               goto end;
+       }
+
+       assert(stream_class->event_context_type);
+       bt_ctf_field_type_get(stream_class->event_context_type);
+       ret = stream_class->event_context_type;
+end:
+       return ret;
+}
+
+int bt_ctf_stream_class_set_event_context_type(
+               struct bt_ctf_stream_class *stream_class,
+               struct bt_ctf_field_type *event_context_type)
+{
+       int ret = 0;
+
+       if (!stream_class || !event_context_type || stream_class->frozen) {
+               ret = -1;
+               goto end;
+       }
+
+       if (bt_ctf_field_type_get_type_id(event_context_type) !=
+               CTF_TYPE_STRUCT) {
+               /* A packet context must be a structure */
+               ret = -1;
+               goto end;
+       }
+
+       bt_ctf_field_type_put(stream_class->event_context_type);
+       bt_ctf_field_type_get(event_context_type);
+       stream_class->event_context_type = event_context_type;
+end:
+       return ret;
+}
+
 void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class)
 {
        if (!stream_class) {
@@ -333,6 +374,7 @@ void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class)
 
        stream_class->frozen = 1;
        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);
        g_ptr_array_foreach(stream_class->event_classes,
                (GFunc)bt_ctf_event_class_freeze, NULL);
@@ -440,8 +482,9 @@ void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref)
        bt_ctf_field_type_put(stream_class->event_header_type);
        bt_ctf_field_put(stream_class->event_header);
        bt_ctf_field_type_put(stream_class->packet_context_type);
-       bt_ctf_field_type_put(stream_class->event_context_type);
-       bt_ctf_field_put(stream_class->event_context);
+       if (stream_class->event_context_type) {
+               bt_ctf_field_type_put(stream_class->event_context_type);
+       }
        g_free(stream_class);
 }
 
index 57b893790ae36ca2a8e2122b72f083111ad31adf..d4e1be159330b4dda5eb22606d898ed93b142338 100644 (file)
@@ -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;
index 67a9d17b487b565e0f4de4959ac062cc70910880..55ad787e50723d11548f04d9d0e0bfa9d88bbdeb 100644 (file)
@@ -48,7 +48,6 @@ struct bt_ctf_stream_class {
        struct bt_ctf_field *event_header;
        struct bt_ctf_field_type *packet_context_type;
        struct bt_ctf_field_type *event_context_type;
-       struct bt_ctf_field *event_context;
        int frozen;
 };
 
index d64e71413df61bd62491bf3dcd7fa51c60147570..71b10679ceac550ed0a1f4f197489daf7300cf3d 100644 (file)
@@ -194,6 +194,31 @@ extern int bt_ctf_stream_class_set_packet_context_type(
                struct bt_ctf_stream_class *stream_class,
                struct bt_ctf_field_type *packet_context_type);
 
+/*
+ * bt_ctf_stream_class_get_event_context_type: get the stream class'
+ * event context type.
+ *
+ * @param stream_class Stream class.
+ *
+ * Returns the stream event context's type (a structure), NULL on error.
+ */
+extern struct bt_ctf_field_type *
+bt_ctf_stream_class_get_event_context_type(
+               struct bt_ctf_stream_class *stream_class);
+
+/*
+ * bt_ctf_stream_class_set_event_context_type: set the stream class'
+ * event context type.
+ *
+ * @param stream_class Stream class.
+ * @param event_context_type Event context type (must be a structure).
+ *
+ * Returns 0 on success, a negative value on error.
+ */
+extern int bt_ctf_stream_class_set_event_context_type(
+               struct bt_ctf_stream_class *stream_class,
+               struct bt_ctf_field_type *event_context_type);
+
 /*
  * bt_ctf_stream_class_get and bt_ctf_stream_class_put: increment and
  * decrement the stream class' reference count.
index afbb9ff51bea6ff68168f12fde1f7b3555e5d8fe..0bd39ba49964b368dd78e0ca2c88fed64e9a1be3 100644 (file)
@@ -53,6 +53,7 @@ struct bt_ctf_stream {
        struct ctf_stream_pos pos;
        unsigned int flushed_packet_count;
        struct bt_ctf_field *packet_context;
+       struct bt_ctf_field *event_context;
 };
 
 BT_HIDDEN
index d9e2bc26e3a00b4b749801904ef3571acbfbc624..ab0a8c7e534b5d290f9d3c2f8064430095dc4edb 100644 (file)
@@ -109,6 +109,31 @@ extern int bt_ctf_stream_set_packet_context(
                struct bt_ctf_stream *stream,
                struct bt_ctf_field *packet_context);
 
+/*
+ * bt_ctf_stream_get_event_context: get a stream's event context.
+ *
+ * @param stream Stream instance.
+ *
+ * Returns a field instance on success, NULL on error.
+ */
+extern struct bt_ctf_field *bt_ctf_stream_get_event_context(
+               struct bt_ctf_stream *stream);
+
+/*
+ * bt_ctf_stream_set_event_context: set a stream's event context.
+ *
+ * The event context's type must match the stream class' event
+ * context type.
+ *
+ * @param stream Stream instance.
+ * @param event_context Event context field instance.
+ *
+ * Returns a field instance on success, NULL on error.
+ */
+extern int bt_ctf_stream_set_event_context(
+               struct bt_ctf_stream *stream,
+               struct bt_ctf_field *event_context);
+
 /*
  * bt_ctf_stream_flush: flush a stream.
  *
This page took 0.029066 seconds and 4 git commands to generate.