+int bt_stream_class_common_visit(struct bt_stream_class_common *stream_class,
+ bt_visitor visitor, void *data);
+
+static inline
+struct bt_trace_common *bt_stream_class_common_borrow_trace(
+ struct bt_stream_class_common *stream_class)
+{
+ BT_ASSERT(stream_class);
+ return (void *) bt_object_borrow_parent(&stream_class->base);
+}
+
+static inline
+int bt_stream_class_common_set_name(struct bt_stream_class_common *stream_class,
+ const char *name)
+{
+ int ret = 0;
+
+ if (!stream_class) {
+ BT_LOGW_STR("Invalid parameter: stream class is NULL.");
+ ret = -1;
+ goto end;
+ }
+
+ if (stream_class->frozen) {
+ BT_LOGW("Invalid parameter: stream class is frozen: "
+ "addr=%p, name=\"%s\", id=%" PRId64,
+ stream_class,
+ bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class));
+ ret = -1;
+ goto end;
+ }
+
+ if (!name) {
+ g_string_assign(stream_class->name, "");
+ } else {
+ if (strlen(name) == 0) {
+ BT_LOGW("Invalid parameter: name is empty.");
+ ret = -1;
+ goto end;
+ }
+
+ g_string_assign(stream_class->name, name);
+ }
+
+ BT_LOGV("Set stream class's name: "
+ "addr=%p, name=\"%s\", id=%" PRId64,
+ stream_class, bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class));
+end:
+ return ret;
+}
+
+static inline
+void _bt_stream_class_common_set_id(
+ struct bt_stream_class_common *stream_class, int64_t id)
+{
+ BT_ASSERT(stream_class);
+ stream_class->id = id;
+ stream_class->id_set = 1;
+ BT_LOGV("Set stream class's ID (internal): "
+ "addr=%p, name=\"%s\", id=%" PRId64,
+ stream_class, bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class));
+}
+
+static inline
+int bt_stream_class_common_set_id_no_check(
+ struct bt_stream_class_common *stream_class, int64_t id)
+{
+ _bt_stream_class_common_set_id(stream_class, id);
+ return 0;
+}
+
+static inline
+int bt_stream_class_common_set_id(struct bt_stream_class_common *stream_class,
+ uint64_t id_param)
+{
+ int ret = 0;
+ int64_t id = (int64_t) id_param;
+
+ if (!stream_class) {
+ BT_LOGW_STR("Invalid parameter: stream class is NULL.");
+ ret = -1;
+ goto end;
+ }
+
+ if (stream_class->frozen) {
+ BT_LOGW("Invalid parameter: stream class is frozen: "
+ "addr=%p, name=\"%s\", id=%" PRId64,
+ stream_class,
+ bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class));
+ ret = -1;
+ goto end;
+ }
+
+ if (id < 0) {
+ BT_LOGW("Invalid parameter: invalid stream class's ID: "
+ "stream-class-addr=%p, stream-class-name=\"%s\", "
+ "stream-class-id=%" PRId64 ", id=%" PRIu64,
+ stream_class,
+ bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class),
+ id_param);
+ ret = -1;
+ goto end;
+ }
+
+ ret = bt_stream_class_common_set_id_no_check(stream_class, id);
+ if (ret == 0) {
+ BT_LOGV("Set stream class's ID: "
+ "addr=%p, name=\"%s\", id=%" PRId64,
+ stream_class,
+ bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class));
+ }
+end:
+ return ret;
+}
+
+static inline
+int64_t bt_stream_class_common_get_event_class_count(
+ struct bt_stream_class_common *stream_class)
+{
+ int64_t ret;
+
+ if (!stream_class) {
+ BT_LOGW_STR("Invalid parameter: stream class is NULL.");
+ ret = (int64_t) -1;
+ goto end;
+ }
+
+ ret = (int64_t) stream_class->event_classes->len;
+end:
+ return ret;
+}
+
+static inline
+struct bt_event_class_common *bt_stream_class_common_borrow_event_class_by_index(
+ struct bt_stream_class_common *stream_class, uint64_t index)
+{
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE(index < stream_class->event_classes->len,
+ "Index is out of bounds: index=%" PRIu64 ", "
+ "count=%u",
+ index, stream_class->event_classes->len);
+ return g_ptr_array_index(stream_class->event_classes, index);
+}
+
+static inline
+struct bt_event_class_common *bt_stream_class_common_borrow_event_class_by_id(
+ struct bt_stream_class_common *stream_class, uint64_t id)
+{
+ int64_t id_key = (int64_t) id;
+
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ BT_ASSERT_PRE(id_key >= 0,
+ "Invalid event class ID: %" PRIu64, id);
+ return g_hash_table_lookup(stream_class->event_classes_ht,
+ &id_key);
+}
+
+static inline
+struct bt_field_type_common *
+bt_stream_class_common_borrow_packet_context_field_type(
+ struct bt_stream_class_common *stream_class)
+{
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+ return stream_class->packet_context_field_type;
+}
+
+static inline
+int bt_stream_class_common_set_packet_context_field_type(
+ struct bt_stream_class_common *stream_class,
+ struct bt_field_type_common *packet_context_type)
+{
+ int ret = 0;
+
+ if (!stream_class) {
+ BT_LOGW_STR("Invalid parameter: stream class is NULL.");
+ ret = -1;
+ goto end;
+ }
+
+ if (stream_class->frozen) {
+ BT_LOGW("Invalid parameter: stream class is frozen: "
+ "addr=%p, name=\"%s\", id=%" PRId64,
+ stream_class, bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class));
+ ret = -1;
+ goto end;
+ }
+
+ if (packet_context_type &&
+ bt_field_type_common_get_type_id(packet_context_type) !=
+ BT_FIELD_TYPE_ID_STRUCT) {
+ /* A packet context must be a structure. */
+ BT_LOGW("Invalid parameter: stream class's packet context field type must be a structure: "
+ "addr=%p, name=\"%s\", id=%" PRId64 ", "
+ "packet-context-ft-addr=%p, packet-context-ft-id=%s",
+ stream_class, bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class),
+ packet_context_type,
+ bt_common_field_type_id_string(
+ bt_field_type_common_get_type_id(packet_context_type)));
+ ret = -1;
+ goto end;
+ }
+
+ bt_put(stream_class->packet_context_field_type);
+ bt_get(packet_context_type);
+ stream_class->packet_context_field_type = packet_context_type;
+ BT_LOGV("Set stream class's packet context field type: "
+ "addr=%p, name=\"%s\", id=%" PRId64 ", "
+ "packet-context-ft-addr=%p",
+ stream_class, bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class),
+ packet_context_type);
+
+end:
+ return ret;
+}
+
+static inline
+struct bt_field_type_common *
+bt_stream_class_common_borrow_event_header_field_type(
+ struct bt_stream_class_common *stream_class)
+{
+ struct bt_field_type_common *ret = NULL;
+
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+
+ if (!stream_class->event_header_field_type) {
+ BT_LOGV("Stream class has no event header field type: "
+ "addr=%p, name=\"%s\", id=%" PRId64,
+ stream_class,
+ bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class));
+ goto end;
+ }
+
+ ret = stream_class->event_header_field_type;
+
+end:
+ return ret;
+}
+
+static inline
+int bt_stream_class_common_set_event_header_field_type(
+ struct bt_stream_class_common *stream_class,
+ struct bt_field_type_common *event_header_type)
+{
+ int ret = 0;
+
+ if (!stream_class) {
+ BT_LOGW_STR("Invalid parameter: stream class is NULL.");
+ ret = -1;
+ goto end;
+ }
+
+ if (stream_class->frozen) {
+ BT_LOGW("Invalid parameter: stream class is frozen: "
+ "addr=%p, name=\"%s\", id=%" PRId64,
+ stream_class,
+ bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class));
+ ret = -1;
+ goto end;
+ }
+
+ if (event_header_type &&
+ bt_field_type_common_get_type_id(event_header_type) !=
+ BT_FIELD_TYPE_ID_STRUCT) {
+ /* An event header must be a structure. */
+ BT_LOGW("Invalid parameter: stream class's event header field type must be a structure: "
+ "addr=%p, name=\"%s\", id=%" PRId64 ", "
+ "event-header-ft-addr=%p, event-header-ft-id=%s",
+ stream_class, bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class),
+ event_header_type,
+ bt_common_field_type_id_string(
+ bt_field_type_common_get_type_id(event_header_type)));
+ ret = -1;
+ goto end;
+ }
+
+ bt_put(stream_class->event_header_field_type);
+ stream_class->event_header_field_type = bt_get(event_header_type);
+ BT_LOGV("Set stream class's event header field type: "
+ "addr=%p, name=\"%s\", id=%" PRId64 ", "
+ "event-header-ft-addr=%p",
+ stream_class, bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class),
+ event_header_type);
+end:
+ return ret;
+}
+
+static inline
+struct bt_field_type_common *
+bt_stream_class_common_borrow_event_context_field_type(
+ struct bt_stream_class_common *stream_class)
+{
+ struct bt_field_type_common *ret = NULL;
+
+ BT_ASSERT_PRE_NON_NULL(stream_class, "Stream class");
+
+ if (!stream_class->event_context_field_type) {
+ goto end;
+ }
+
+ ret = stream_class->event_context_field_type;
+
+end:
+ return ret;
+}
+
+static inline
+int bt_stream_class_common_set_event_context_field_type(
+ struct bt_stream_class_common *stream_class,
+ struct bt_field_type_common *event_context_type)
+{
+ int ret = 0;
+
+ if (!stream_class) {
+ BT_LOGW_STR("Invalid parameter: stream class is NULL.");
+ ret = -1;
+ goto end;
+ }
+
+ if (stream_class->frozen) {
+ BT_LOGW("Invalid parameter: stream class is frozen: "
+ "addr=%p, name=\"%s\", id=%" PRId64,
+ stream_class, bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class));
+ ret = -1;
+ goto end;
+ }
+
+ if (event_context_type &&
+ bt_field_type_common_get_type_id(event_context_type) !=
+ BT_FIELD_TYPE_ID_STRUCT) {
+ /* A packet context must be a structure. */
+ BT_LOGW("Invalid parameter: stream class's event context field type must be a structure: "
+ "addr=%p, name=\"%s\", id=%" PRId64 ", "
+ "event-context-ft-addr=%p, event-context-ft-id=%s",
+ stream_class, bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class),
+ event_context_type,
+ bt_common_field_type_id_string(
+ bt_field_type_common_get_type_id(event_context_type)));
+ ret = -1;
+ goto end;
+ }
+
+ bt_put(stream_class->event_context_field_type);
+ stream_class->event_context_field_type = bt_get(event_context_type);
+ BT_LOGV("Set stream class's event context field type: "
+ "addr=%p, name=\"%s\", id=%" PRId64 ", "
+ "event-context-ft-addr=%p",
+ stream_class, bt_stream_class_common_get_name(stream_class),
+ bt_stream_class_common_get_id(stream_class),
+ event_context_type);
+end:
+ return ret;
+}