struct bt_ctf_field *bt_ctf_field_create(struct bt_ctf_field_type *type) { struct bt_ctf_field *field = NULL; enum ctf_type_id type_id; if (!type) { goto error; } type_id = bt_ctf_field_type_get_type_id(type); if (type_id <= CTF_TYPE_UNKNOWN || type_id >= NR_CTF_TYPES || bt_ctf_field_type_validate(type)) { goto error; } field = field_create_funcs[type_id](type); if (!field) { goto error; } /* The type's declaration can't change after this point */ bt_ctf_field_type_freeze(type); bt_ctf_field_type_get(type); bt_ctf_ref_init(&field->ref_count); field->type = type; error: return field; }
BT_HIDDEN struct bt_ctf_clock *_bt_ctf_clock_create(void) { struct bt_ctf_clock *clock = g_new0( struct bt_ctf_clock, 1); if (!clock) { goto end; } clock->precision = 1; clock->frequency = 1000000000; bt_ctf_ref_init(&clock->ref_count); end: return clock; }
struct bt_ctf_trace *bt_ctf_trace_create(void) { struct bt_ctf_trace *trace = NULL; trace = g_new0(struct bt_ctf_trace, 1); if (!trace) { goto error; } bt_ctf_trace_set_byte_order(trace, BT_CTF_BYTE_ORDER_NATIVE); bt_ctf_ref_init(&trace->ref_count); trace->environment = g_ptr_array_new_with_free_func( (GDestroyNotify)environment_variable_destroy); trace->clocks = g_ptr_array_new_with_free_func( (GDestroyNotify)bt_ctf_clock_put); trace->streams = g_ptr_array_new_with_free_func( (GDestroyNotify)bt_ctf_stream_put); trace->stream_classes = g_ptr_array_new_with_free_func( (GDestroyNotify)bt_ctf_stream_class_put); if (!trace->environment || !trace->clocks || !trace->stream_classes || !trace->streams) { goto error_destroy; } /* Generate a trace UUID */ uuid_generate(trace->uuid); if (init_trace_packet_header(trace)) { goto error_destroy; } return trace; error_destroy: bt_ctf_trace_destroy(&trace->ref_count); trace = NULL; error: return trace; }
struct bt_ctf_writer *bt_ctf_writer_create(const char *path) { struct bt_ctf_writer *writer = NULL; if (!path) { goto error; } writer = g_new0(struct bt_ctf_writer, 1); if (!writer) { goto error; } bt_ctf_writer_set_byte_order(writer, BT_CTF_BYTE_ORDER_NATIVE); bt_ctf_ref_init(&writer->ref_count); writer->path = g_string_new(path); if (!writer->path) { goto error_destroy; } /* Create trace directory if necessary and open a metadata file */ if (g_mkdir_with_parents(path, S_IRWXU | S_IRWXG)) { perror("g_mkdir_with_parents"); goto error_destroy; } writer->trace_dir_fd = open(path, O_RDONLY, S_IRWXU | S_IRWXG); if (writer->trace_dir_fd < 0) { perror("open"); goto error_destroy; } writer->metadata_fd = openat(writer->trace_dir_fd, "metadata", O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); writer->environment = g_ptr_array_new_with_free_func( (GDestroyNotify)environment_variable_destroy); writer->clocks = g_ptr_array_new_with_free_func( (GDestroyNotify)bt_ctf_clock_put); writer->streams = g_ptr_array_new_with_free_func( (GDestroyNotify)bt_ctf_stream_put); writer->stream_classes = g_ptr_array_new_with_free_func( (GDestroyNotify)bt_ctf_stream_class_put); if (!writer->environment || !writer->clocks || !writer->stream_classes || !writer->streams) { goto error_destroy; } /* Generate a trace UUID */ uuid_generate(writer->uuid); if (init_trace_packet_header(writer)) { goto error_destroy; } return writer; error_destroy: unlinkat(writer->trace_dir_fd, "metadata", 0); bt_ctf_writer_destroy(&writer->ref_count); writer = NULL; error: return writer; }