#define BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H
/*
- * BabelTrace - CTF Writer: Stream internal
- *
- * Copyright 2013 EfficiOS Inc.
+ * Copyright 2013, 2014 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
+ *
+ * The Common Trace Format (CTF) Specification is available at
+ * http://www.efficios.com/ctf
*/
-#include <babeltrace/ctf-writer/ref-internal.h>
-#include <babeltrace/ctf-writer/clock.h>
-#include <babeltrace/ctf-writer/event-fields.h>
-#include <babeltrace/ctf-writer/event-types.h>
+#include <babeltrace/assert-internal.h>
+#include <babeltrace/assert-pre-internal.h>
#include <babeltrace/babeltrace-internal.h>
-#include <babeltrace/ctf/types.h>
-#include <glib.h>
+#include <babeltrace/ctf-writer/serialize-internal.h>
+#include <babeltrace/ctf-writer/stream-internal.h>
+#include <babeltrace/ctf-writer/stream.h>
+#include <babeltrace/ctf-writer/utils-internal.h>
+#include <babeltrace/ctf-writer/object-internal.h>
+#include <stdint.h>
-typedef void(*flush_func)(struct bt_ctf_stream *, void *);
+struct bt_ctf_stream_common;
-struct bt_ctf_stream_class {
- struct bt_ctf_ref ref_count;
+struct bt_ctf_stream_common {
+ struct bt_ctf_object base;
+ int64_t id;
+ struct bt_ctf_stream_class_common *stream_class;
GString *name;
- struct bt_ctf_clock *clock;
- GPtrArray *event_classes; /* Array of pointers to bt_ctf_event_class */
- int id_set;
- uint32_t id;
- uint32_t next_event_id;
- uint32_t next_stream_id;
- struct bt_ctf_field_type *event_header_type;
- struct bt_ctf_field *event_header;
- struct bt_ctf_field_type *packet_context_type;
- struct bt_ctf_field *packet_context;
- struct bt_ctf_field_type *event_context_type;
- struct bt_ctf_field *event_context;
- int frozen;
-};
-
-struct flush_callback {
- flush_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 */
- GPtrArray *events;
- struct ctf_stream_pos pos;
- unsigned int flushed_packet_count;
- uint64_t events_discarded;
};
BT_HIDDEN
-void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class);
+int bt_ctf_stream_common_initialize(
+ struct bt_ctf_stream_common *stream,
+ struct bt_ctf_stream_class_common *stream_class, const char *name,
+ uint64_t id, bt_ctf_object_release_func release_func);
BT_HIDDEN
-int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class,
- uint32_t id);
+void bt_ctf_stream_common_finalize(struct bt_ctf_stream_common *stream);
-BT_HIDDEN
-int bt_ctf_stream_class_serialize(struct bt_ctf_stream_class *stream_class,
- struct metadata_context *context);
+static inline
+struct bt_ctf_stream_class_common *bt_ctf_stream_common_borrow_class(
+ struct bt_ctf_stream_common *stream)
+{
+ BT_ASSERT(stream);
+ return stream->stream_class;
+}
-BT_HIDDEN
-int bt_ctf_stream_class_set_byte_order(struct bt_ctf_stream_class *stream_class,
- enum bt_ctf_byte_order byte_order);
+static inline
+const char *bt_ctf_stream_common_get_name(struct bt_ctf_stream_common *stream)
+{
+ BT_ASSERT_PRE_NON_NULL(stream, "Stream");
+ return stream->name ? stream->name->str : NULL;
+}
-BT_HIDDEN
-struct bt_ctf_stream *bt_ctf_stream_create(
- struct bt_ctf_stream_class *stream_class);
+static inline
+int64_t bt_ctf_stream_common_get_id(struct bt_ctf_stream_common *stream)
+{
+ int64_t ret;
-BT_HIDDEN
-int bt_ctf_stream_set_flush_callback(struct bt_ctf_stream *stream,
- flush_func callback, void *data);
+ BT_ASSERT_PRE_NON_NULL(stream, "Stream");
+ ret = stream->id;
+ if (ret < 0) {
+ BT_LOGV("Stream's ID is not set: addr=%p, name=\"%s\"",
+ stream, bt_ctf_stream_common_get_name(stream));
+ }
+
+ return ret;
+}
+
+struct bt_ctf_stream {
+ struct bt_ctf_stream_common common;
+ struct bt_ctf_field *packet_header;
+ struct bt_ctf_field *packet_context;
+
+ /* Array of pointers to bt_ctf_event for the current packet */
+ GPtrArray *events;
+ struct bt_ctf_stream_pos pos;
+ unsigned int flushed_packet_count;
+ uint64_t discarded_events;
+ uint64_t size;
+ uint64_t last_ts_end;
+};
BT_HIDDEN
int bt_ctf_stream_set_fd(struct bt_ctf_stream *stream, int fd);
+BT_HIDDEN
+struct bt_ctf_stream *bt_ctf_stream_create_with_id(
+ struct bt_ctf_stream_class *stream_class,
+ const char *name, uint64_t id);
+
#endif /* BABELTRACE_CTF_WRITER_STREAM_INTERNAL_H */