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;
}
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) {
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);
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);
}
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) {
{
int ret = 0;
uint64_t timestamp;
+ struct bt_ctf_field *event_context_copy = NULL;
if (!stream || !event) {
ret = -1;
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;
};
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.
struct ctf_stream_pos pos;
unsigned int flushed_packet_count;
struct bt_ctf_field *packet_context;
+ struct bt_ctf_field *event_context;
};
BT_HIDDEN
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.
*