+ assert(stream_class->packet_context_type);
+ bt_get(stream_class->packet_context_type);
+ ret = stream_class->packet_context_type;
+end:
+ return ret;
+}
+
+int bt_ctf_stream_class_set_packet_context_type(
+ struct bt_ctf_stream_class *stream_class,
+ struct bt_ctf_field_type *packet_context_type)
+{
+ int ret = 0;
+
+ if (!stream_class || !packet_context_type || 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 */
+ ret = -1;
+ goto end;
+ }
+
+ bt_put(stream_class->packet_context_type);
+ bt_get(packet_context_type);
+ stream_class->packet_context_type = packet_context_type;
+end:
+ return ret;
+}
+
+struct bt_ctf_field_type *bt_ctf_stream_class_get_event_header_type(
+ struct bt_ctf_stream_class *stream_class)
+{
+ struct bt_ctf_field_type *ret = NULL;
+
+ if (!stream_class || !stream_class->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:
+ return ret;
+}
+
+int bt_ctf_stream_class_set_event_header_type(
+ struct bt_ctf_stream_class *stream_class,
+ struct bt_ctf_field_type *event_header_type)
+{
+ int ret = 0;
+
+ if (!stream_class || !event_header_type || 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 */
+ ret = -1;
+ goto end;
+ }
+
+ bt_put(stream_class->event_header_type);
+ bt_get(event_header_type);
+ stream_class->event_header_type = event_header_type;
+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_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) !=
+ 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;
+end:
+ return ret;
+}
+
+void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class)
+{
+ bt_get(stream_class);
+}
+
+void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class)
+{
+ bt_put(stream_class);
+}
+
+static
+int get_event_class_count(void *element)
+{
+ return bt_ctf_stream_class_get_event_class_count(
+ (struct bt_ctf_stream_class *) element);
+}
+
+static
+void *get_event_class(void *element, int i)
+{
+ return bt_ctf_stream_class_get_event_class(
+ (struct bt_ctf_stream_class *) element, i);
+}
+
+static
+int visit_event_class(void *element, bt_ctf_ir_visitor visitor,void *data)
+{
+ struct bt_ctf_ir_element ir_element =
+ { .element = element,
+ .type = BT_CTF_IR_TYPE_EVENT_CLASS };
+
+ return visitor(&ir_element, data);
+}
+
+int bt_ctf_stream_class_visit(struct bt_ctf_stream_class *stream_class,
+ bt_ctf_ir_visitor visitor, void *data)
+{
+ int ret;
+ struct bt_ctf_ir_element element =
+ { .element = stream_class,
+ .type = BT_CTF_IR_TYPE_STREAM_CLASS };
+
+ if (!stream_class || !visitor) {
+ ret = -1;
+ goto end;
+ }
+
+ ret = visitor_helper(&element, get_event_class_count,
+ get_event_class,
+ visit_event_class, visitor, data);
+end:
+ return ret;