*/
#include <babeltrace/ctf-ir/stream.h>
-#include <babeltrace/ctf-writer/ref-internal.h>
+#include <babeltrace/object-internal.h>
#include <babeltrace/ctf-writer/clock.h>
#include <babeltrace/ctf-writer/event-fields.h>
#include <babeltrace/ctf-writer/event-types.h>
+#include <babeltrace/ctf-writer/serialize-internal.h>
#include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/ctf/types.h>
#include <glib.h>
-typedef void(*flush_func)(struct bt_ctf_stream *, void *);
+struct bt_port;
+struct bt_component;
-struct flush_callback {
- flush_func func;
+typedef void (*bt_stream_destroy_listener_func)(
+ struct bt_stream *stream, void *data);
+
+struct bt_stream_destroy_listener {
+ bt_stream_destroy_listener_func func;
void *data;
};
-struct bt_ctf_stream {
- struct bt_ctf_ref ref_count;
- uint32_t id;
- struct bt_ctf_stream_class *stream_class;
- struct flush_callback flush;
- /* Array of pointers to bt_ctf_event for the current packet */
+struct bt_stream {
+ struct bt_object base;
+ int64_t id;
+ struct bt_stream_class *stream_class;
+ GString *name;
+ struct bt_field *packet_header;
+ struct bt_field *packet_context;
+
+ /*
+ * When a notification which contains a reference to a stream
+ * object (event notification, for example) is returned by the
+ * "next" method of a sink or filter component's notification
+ * iterator, it must NOT be returned by the "next" method of a
+ * notification iterator which iterates on the notifications of
+ * another output port of the same component.
+ *
+ * To ensure this, the stream object keeps a hash table which
+ * indicates which port, for a given component, is currently
+ * allowed to emit notifications which contain a reference to
+ * this stream.
+ *
+ * This is a `struct bt_component *` to `struct bt_port *` hash
+ * table. Both pointers are weak references because there's no
+ * need to keep one or the other alive as far as this stream is
+ * concerned.
+ */
+ GHashTable *comp_cur_port;
+
+ /* Writer-specific members. */
+ /* Array of pointers to bt_event for the current packet */
GPtrArray *events;
- struct ctf_stream_pos pos;
+ struct bt_stream_pos pos;
unsigned int flushed_packet_count;
- struct bt_ctf_field *packet_context;
+ uint64_t discarded_events;
+ uint64_t size;
+ uint64_t last_ts_end;
+
+ /* Array of struct bt_stream_destroy_listener */
+ GArray *destroy_listeners;
};
BT_HIDDEN
-struct bt_ctf_stream *bt_ctf_stream_create(
- struct bt_ctf_stream_class *stream_class);
+int bt_stream_set_fd(struct bt_stream *stream, int fd);
BT_HIDDEN
-int bt_ctf_stream_set_flush_callback(struct bt_ctf_stream *stream,
- flush_func callback, void *data);
+void bt_stream_map_component_to_port(struct bt_stream *stream,
+ struct bt_component *comp,
+ struct bt_port *port);
BT_HIDDEN
-int bt_ctf_stream_set_fd(struct bt_ctf_stream *stream, int fd);
+struct bt_port *bt_stream_port_for_component(struct bt_stream *stream,
+ struct bt_component *comp);
+
+BT_HIDDEN
+void bt_stream_add_destroy_listener(struct bt_stream *stream,
+ bt_stream_destroy_listener_func func, void *data);
+
+BT_HIDDEN
+void bt_stream_remove_destroy_listener(struct bt_stream *stream,
+ bt_stream_destroy_listener_func func, void *data);
+
+static inline
+struct bt_stream_class *bt_stream_borrow_stream_class(
+ struct bt_stream *stream)
+{
+ assert(stream);
+ return stream->stream_class;
+}
#endif /* BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H */