g_free(trace);
}
-struct bt_ctf_stream *bt_ctf_trace_create_stream(struct bt_ctf_trace *trace,
- struct bt_ctf_stream_class *stream_class)
-{
- int ret;
- int stream_class_found = 0;
- size_t i;
- struct bt_ctf_stream *stream = NULL;
-
- if (!trace || !stream_class) {
- goto error;
- }
-
- for (i = 0; i < trace->stream_classes->len; i++) {
- if (trace->stream_classes->pdata[i] == stream_class) {
- stream_class_found = 1;
- }
- }
-
- if (!stream_class_found) {
- ret = bt_ctf_trace_add_stream_class(trace, stream_class);
- if (ret) {
- goto error;
- }
- }
-
- stream = bt_ctf_stream_create(stream_class, trace);
- if (!stream) {
- goto error;
- }
-
- g_ptr_array_add(trace->streams, stream);
- return stream;
-error:
- BT_PUT(stream);
- return stream;
-}
-
int bt_ctf_trace_set_environment_field(struct bt_ctf_trace *trace,
const char *name, struct bt_value *value)
{
bt_get(clock);
g_ptr_array_add(trace->clocks, clock);
+ if (!trace->is_created_by_writer) {
+ /*
+ * Non-writer mode trace: disable clock value functions
+ * because clock values are per-stream in that
+ * situation.
+ */
+ clock->has_value = 0;
+ }
+
if (trace->frozen) {
bt_ctf_clock_freeze(clock);
}
struct bt_ctf_field_type *event_header_type = NULL;
struct bt_ctf_field_type *stream_event_ctx_type = NULL;
int event_class_count;
+ struct bt_ctf_clock *clock_to_add_to_trace = NULL;
if (!trace || !stream_class) {
ret = -1;
}
}
+ /*
+ * If the stream class has a clock, register this clock to this
+ * trace if not already done.
+ */
+ if (stream_class->clock) {
+ const char *clock_name =
+ bt_ctf_clock_get_name(stream_class->clock);
+ struct bt_ctf_clock *trace_clock;
+
+ assert(clock_name);
+ trace_clock = bt_ctf_trace_get_clock_by_name(trace, clock_name);
+ bt_put(trace_clock);
+ if (trace_clock) {
+ if (trace_clock != stream_class->clock) {
+ /*
+ * Error: two different clocks in the
+ * trace would share the same name.
+ */
+ ret = -1;
+ goto end;
+ }
+ } else {
+ clock_to_add_to_trace = bt_get(stream_class->clock);
+ }
+ }
+
/*
* We're about to freeze both the trace and the stream class.
* Also, each event class contained in this stream class are
trace->byte_order);
bt_ctf_stream_class_set_byte_order(stream_class, trace->byte_order);
+ /* Add stream class's clock if it exists */
+ if (clock_to_add_to_trace) {
+ int add_clock_ret =
+ bt_ctf_trace_add_clock(trace, clock_to_add_to_trace);
+ assert(add_clock_ret == 0);
+ }
+
/*
* Freeze the trace and the stream class.
*/
g_free(ec_validation_outputs);
bt_ctf_validation_output_put_types(&trace_sc_validation_output);
+ BT_PUT(clock_to_add_to_trace);
assert(!packet_header_type);
assert(!packet_context_type);
assert(!event_header_type);