}
struct bt_ctf_stream *bt_ctf_stream_create(
- struct bt_ctf_stream_class *stream_class)
+ struct bt_ctf_stream_class *stream_class,
+ const char *name)
{
int ret;
struct bt_ctf_stream *stream = NULL;
struct bt_ctf_writer *writer = NULL;
if (!stream_class) {
- goto end;
+ goto error;
}
trace = bt_ctf_stream_class_get_trace(stream_class);
if (!trace) {
- goto end;
+ goto error;
}
stream = g_new0(struct bt_ctf_stream, 1);
if (!stream) {
- goto end;
+ goto error;
}
bt_object_init(stream, bt_ctf_stream_destroy);
stream->stream_class = stream_class;
stream->pos.fd = -1;
+ if (name) {
+ stream->name = g_string_new(name);
+ if (!stream->name) {
+ goto error;
+ }
+ }
+
if (trace->is_created_by_writer) {
int fd;
writer = (struct bt_ctf_writer *)
/* Add this stream to the trace's streams */
g_ptr_array_add(trace->streams, stream);
-end:
BT_PUT(trace);
BT_PUT(writer);
return stream;
if (stream->events) {
g_ptr_array_free(stream->events, TRUE);
}
+
+ if (stream->name) {
+ g_string_free(stream->name, TRUE);
+ }
bt_put(stream->packet_header);
bt_put(stream->packet_context);
bt_put(stream->event_context);
bt_put(field_type);
return ret;
}
+
+const char *bt_ctf_stream_get_name(struct bt_ctf_stream *stream)
+{
+ const char *name = NULL;
+
+ if (!stream) {
+ goto end;
+ }
+
+ name = stream->name ? stream->name->str : NULL;
+
+end:
+ return name;
+}
}
}
- stream = bt_ctf_stream_create(stream_class);
+ stream = bt_ctf_stream_create(stream_class, NULL);
if (!stream) {
goto error;
}
GPtrArray *events;
struct ctf_stream_pos pos;
unsigned int flushed_packet_count;
+ GString *name;
struct bt_ctf_field *packet_header;
struct bt_ctf_field *packet_context;
struct bt_ctf_field *event_header;
struct bt_ctf_stream;
extern struct bt_ctf_stream *bt_ctf_stream_create(
- struct bt_ctf_stream_class *stream_class);
+ struct bt_ctf_stream_class *stream_class,
+ const char *name);
+
+extern const char *bt_ctf_stream_get_name(struct bt_ctf_stream *stream);
/*
* bt_ctf_stream_get_stream_class: get a stream's class.
#define DEFAULT_CLOCK_TIME 0
#define DEFAULT_CLOCK_VALUE 0
-#define NR_TESTS 589
+#define NR_TESTS 590
static int64_t current_time = 42;
{
int ret;
char trace_path[] = "/tmp/ctfwriter_XXXXXX";
+ const char *writer_stream_name = "writer stream instance";
struct bt_ctf_writer *writer = NULL;
struct bt_ctf_trace *writer_trace = NULL;
struct bt_ctf_stream_class *writer_sc = NULL;
assert(!ret);
ret = bt_ctf_trace_add_stream_class(writer_trace, writer_sc);
assert(!ret);
- writer_stream = bt_ctf_stream_create(writer_sc);
+ writer_stream = bt_ctf_stream_create(writer_sc, writer_stream_name);
assert(writer_stream);
+ ok(!strcmp(bt_ctf_stream_get_name(writer_stream), writer_stream_name),
+ "bt_ctf_stream_get_name() returns the stream's name");
/* Create non-writer trace, stream class, and stream */
non_writer_trace = bt_ctf_trace_create();
assert(!ret);
ret = bt_ctf_trace_add_stream_class(non_writer_trace, non_writer_sc);
assert(!ret);
- non_writer_stream = bt_ctf_stream_create(non_writer_sc);
+ non_writer_stream = bt_ctf_stream_create(non_writer_sc, NULL);
assert(non_writer_stream);
/* Create event class and event */