+struct bt_ctf_field *bt_ctf_event_get_event_header(
+ struct bt_ctf_event *event)
+{
+ struct bt_ctf_field *header = NULL;
+
+ if (!event || !event->event_header) {
+ goto end;
+ }
+
+ header = event->event_header;
+ bt_ctf_field_get(header);
+end:
+ return header;
+}
+
+int bt_ctf_event_set_event_header(struct bt_ctf_event *event,
+ struct bt_ctf_field *header)
+{
+ int ret = 0;
+ struct bt_ctf_field_type *field_type = NULL;
+
+ if (!event || !header) {
+ ret = -1;
+ goto end;
+ }
+
+ /* Could be NULL since an event class doesn't own a stream class */
+ if (!event->event_class->stream_class) {
+ ret = -1;
+ goto end;
+ }
+
+ /*
+ * Ensure the provided header's type matches the one registered to the
+ * stream class.
+ */
+ field_type = bt_ctf_field_get_type(header);
+ if (field_type != event->event_class->stream_class->event_header_type) {
+ ret = -1;
+ goto end;
+ }
+
+ bt_ctf_field_get(header);
+ bt_ctf_field_put(event->event_header);
+ event->event_header = header;
+end:
+ if (field_type) {
+ bt_ctf_field_type_put(field_type);
+ }
+ return ret;
+}
+
+struct bt_ctf_field *bt_ctf_event_get_event_context(
+ struct bt_ctf_event *event)
+{
+ struct bt_ctf_field *context = NULL;
+
+ if (!event || !event->context_payload) {
+ goto end;
+ }
+
+ context = event->context_payload;
+ bt_ctf_field_get(context);
+end:
+ return context;
+}
+
+int bt_ctf_event_set_event_context(struct bt_ctf_event *event,
+ struct bt_ctf_field *context)
+{
+ int ret = 0;
+ struct bt_ctf_field_type *field_type = NULL;
+
+ if (!event || !context) {
+ ret = -1;
+ goto end;
+ }
+
+ field_type = bt_ctf_field_get_type(context);
+ if (field_type != event->event_class->context) {
+ ret = -1;
+ goto end;
+ }
+
+ bt_ctf_field_get(context);
+ bt_ctf_field_put(event->context_payload);
+ event->context_payload = context;
+end:
+ if (field_type) {
+ bt_ctf_field_type_put(field_type);
+ }
+ return ret;
+}
+