X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fctf-writer%2Fwriter.c;h=a69b1d695ff5d34e250856dbe8b9d529a26065dc;hb=6f4eefbe19bceb8190b0a09d93d554805ef08b63;hp=ce884ea6d56e9c1e7d8a1e8708c68f8abb0c59bd;hpb=839d52a5c5c1fdd66cee9bf7d06c0c0acdd4c2a3;p=babeltrace.git diff --git a/lib/ctf-writer/writer.c b/lib/ctf-writer/writer.c index ce884ea6..a69b1d69 100644 --- a/lib/ctf-writer/writer.c +++ b/lib/ctf-writer/writer.c @@ -29,78 +29,76 @@ #define BT_LOG_TAG "CTF-WRITER" #include +#include +#include +#include #include -#include -#include -#include +#include +#include #include -#include -#include -#include -#include +#include +#include +#include +#include #include -#include -#include +#include +#include +#include +#include #include #include #include -#include #include -#include -#include static -void bt_ctf_writer_destroy(struct bt_object *obj); +void bt_ctf_writer_destroy(struct bt_ctf_object *obj); static -int init_trace_packet_header(struct bt_trace *trace) +int init_trace_packet_header(struct bt_ctf_trace *trace) { int ret = 0; - struct bt_field *magic = NULL, *uuid_array = NULL; - struct bt_field_type *_uint32_t = + struct bt_ctf_field_type *_uint32_t = get_field_type(FIELD_TYPE_ALIAS_UINT32_T); - struct bt_field_type *_uint8_t = + struct bt_ctf_field_type *_uint8_t = get_field_type(FIELD_TYPE_ALIAS_UINT8_T); - struct bt_field_type *trace_packet_header_type = - bt_field_type_structure_create(); - struct bt_field_type *uuid_array_type = - bt_field_type_array_create(_uint8_t, 16); + struct bt_ctf_field_type *trace_packet_header_type = + bt_ctf_field_type_structure_create(); + struct bt_ctf_field_type *uuid_array_type = + bt_ctf_field_type_array_create(_uint8_t, 16); if (!trace_packet_header_type || !uuid_array_type) { ret = -1; goto end; } - ret = bt_field_type_structure_add_field(trace_packet_header_type, + ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, _uint32_t, "magic"); if (ret) { goto end; } - ret = bt_field_type_structure_add_field(trace_packet_header_type, + ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, uuid_array_type, "uuid"); if (ret) { goto end; } - ret = bt_field_type_structure_add_field(trace_packet_header_type, + ret = bt_ctf_field_type_structure_add_field(trace_packet_header_type, _uint32_t, "stream_id"); if (ret) { goto end; } - ret = bt_trace_set_packet_header_type(trace, + ret = bt_ctf_trace_set_packet_header_field_type(trace, trace_packet_header_type); if (ret) { goto end; } end: - bt_put(uuid_array_type); - bt_put(_uint32_t); - bt_put(_uint8_t); - bt_put(magic); - bt_put(uuid_array); - bt_put(trace_packet_header_type); + bt_ctf_object_put_ref(uuid_array_type); + bt_ctf_object_put_ref(_uint32_t); + bt_ctf_object_put_ref(_uint8_t); + bt_ctf_object_put_ref(trace_packet_header_type); return ret; } @@ -122,13 +120,13 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path) metadata_path = g_build_filename(path, "metadata", NULL); - bt_object_init(writer, bt_ctf_writer_destroy); + bt_ctf_object_init_shared(&writer->base, bt_ctf_writer_destroy); writer->path = g_string_new(path); if (!writer->path) { goto error_destroy; } - writer->trace = bt_trace_create(); + writer->trace = bt_ctf_trace_create(); if (!writer->trace) { goto error_destroy; } @@ -145,18 +143,17 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path) goto error_destroy; } - ret = bt_trace_set_uuid(writer->trace, uuid); + ret = bt_ctf_trace_set_uuid(writer->trace, uuid); if (ret) { goto error_destroy; } - writer->trace->is_created_by_writer = 1; - bt_object_set_parent(writer->trace, writer); - bt_put(writer->trace); + bt_ctf_object_set_parent(&writer->trace->common.base, &writer->base); + bt_ctf_object_put_ref(writer->trace); /* Default to little-endian */ - ret = bt_ctf_writer_set_byte_order(writer, BT_BYTE_ORDER_NATIVE); - assert(ret == 0); + ret = bt_ctf_writer_set_byte_order(writer, BT_CTF_BYTE_ORDER_NATIVE); + BT_ASSERT(ret == 0); /* Create trace directory if necessary and open a metadata file */ if (g_mkdir_with_parents(path, S_IRWXU | S_IRWXG)) { @@ -176,13 +173,13 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path) return writer; error_destroy: - BT_PUT(writer); + BT_CTF_OBJECT_PUT_REF_AND_RESET(writer); error: g_free(metadata_path); return writer; } -void bt_ctf_writer_destroy(struct bt_object *obj) +void bt_ctf_writer_destroy(struct bt_ctf_object *obj) { struct bt_ctf_writer *writer; @@ -198,28 +195,28 @@ void bt_ctf_writer_destroy(struct bt_object *obj) } } - bt_object_release(writer->trace); + bt_ctf_object_try_spec_release(&writer->trace->common.base); g_free(writer); } -struct bt_trace *bt_ctf_writer_get_trace(struct bt_ctf_writer *writer) +struct bt_ctf_trace *bt_ctf_writer_get_trace(struct bt_ctf_writer *writer) { - struct bt_trace *trace = NULL; + struct bt_ctf_trace *trace = NULL; if (!writer) { goto end; } trace = writer->trace; - bt_get(trace); + bt_ctf_object_get_ref(trace); end: return trace; } -struct bt_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, - struct bt_stream_class *stream_class) +struct bt_ctf_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, + struct bt_ctf_stream_class *stream_class) { - struct bt_stream *stream = NULL; + struct bt_ctf_stream *stream = NULL; int stream_class_count; bt_bool stream_class_found = BT_FALSE; int i; @@ -229,21 +226,21 @@ struct bt_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, } /* Make sure the stream class is part of the writer's trace */ - stream_class_count = bt_trace_get_stream_class_count(writer->trace); + stream_class_count = bt_ctf_trace_get_stream_class_count(writer->trace); if (stream_class_count < 0) { goto error; } for (i = 0; i < stream_class_count; i++) { - struct bt_stream_class *existing_stream_class = - bt_trace_get_stream_class_by_index( + struct bt_ctf_stream_class *existing_stream_class = + bt_ctf_trace_get_stream_class_by_index( writer->trace, i); if (existing_stream_class == stream_class) { stream_class_found = BT_TRUE; } - BT_PUT(existing_stream_class); + BT_CTF_OBJECT_PUT_REF_AND_RESET(existing_stream_class); if (stream_class_found) { break; @@ -251,7 +248,7 @@ struct bt_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, } if (!stream_class_found) { - int ret = bt_trace_add_stream_class(writer->trace, + int ret = bt_ctf_trace_add_stream_class(writer->trace, stream_class); if (ret) { @@ -259,7 +256,7 @@ struct bt_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, } } - stream = bt_stream_create(stream_class, NULL); + stream = bt_ctf_stream_create_with_id(stream_class, NULL, -1ULL); if (!stream) { goto error; } @@ -267,7 +264,7 @@ struct bt_stream *bt_ctf_writer_create_stream(struct bt_ctf_writer *writer, return stream; error: - BT_PUT(stream); + BT_CTF_OBJECT_PUT_REF_AND_RESET(stream); return stream; } @@ -281,7 +278,7 @@ int bt_ctf_writer_add_environment_field(struct bt_ctf_writer *writer, goto end; } - ret = bt_trace_set_environment_field_string(writer->trace, + ret = bt_ctf_trace_set_environment_field_string(writer->trace, name, value); end: return ret; @@ -296,7 +293,7 @@ int bt_ctf_writer_add_environment_field_int64(struct bt_ctf_writer *writer, goto end; } - ret = bt_trace_set_environment_field_integer(writer->trace, name, + ret = bt_ctf_trace_set_environment_field_integer(writer->trace, name, value); end: return ret; @@ -311,7 +308,7 @@ int bt_ctf_writer_add_clock(struct bt_ctf_writer *writer, goto end; } - ret = bt_trace_add_clock_class(writer->trace, clock->clock_class); + ret = bt_ctf_trace_add_clock_class(writer->trace, clock->clock_class); end: return ret; } @@ -324,7 +321,7 @@ char *bt_ctf_writer_get_metadata_string(struct bt_ctf_writer *writer) goto end; } - metadata_string = bt_trace_get_metadata_string( + metadata_string = bt_ctf_trace_get_metadata_string( writer->trace); end: return metadata_string; @@ -339,7 +336,7 @@ void bt_ctf_writer_flush_metadata(struct bt_ctf_writer *writer) goto end; } - metadata_string = bt_trace_get_metadata_string( + metadata_string = bt_ctf_trace_get_metadata_string( writer->trace); if (!metadata_string) { goto end; @@ -366,7 +363,7 @@ end: } int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, - enum bt_byte_order byte_order) + enum bt_ctf_byte_order byte_order) { int ret = 0; @@ -375,28 +372,84 @@ int bt_ctf_writer_set_byte_order(struct bt_ctf_writer *writer, goto end; } - if (byte_order == BT_BYTE_ORDER_NATIVE) { - byte_order = BT_MY_BYTE_ORDER; + if (byte_order == BT_CTF_BYTE_ORDER_NATIVE) { + if (BYTE_ORDER == LITTLE_ENDIAN) { + byte_order = BT_CTF_BYTE_ORDER_LITTLE_ENDIAN; + } else { + byte_order = BT_CTF_BYTE_ORDER_BIG_ENDIAN; + } } - ret = bt_trace_set_native_byte_order(writer->trace, + ret = bt_ctf_trace_set_native_byte_order(writer->trace, byte_order); end: return ret; } -void bt_ctf_writer_get(struct bt_ctf_writer *writer) +BT_HIDDEN +void bt_ctf_writer_freeze(struct bt_ctf_writer *writer) { - bt_get(writer); + writer->frozen = 1; } -void bt_ctf_writer_put(struct bt_ctf_writer *writer) +static +const unsigned int field_type_aliases_alignments[] = { + [FIELD_TYPE_ALIAS_UINT5_T] = 1, + [FIELD_TYPE_ALIAS_UINT8_T ... FIELD_TYPE_ALIAS_UINT16_T] = 8, + [FIELD_TYPE_ALIAS_UINT27_T] = 1, + [FIELD_TYPE_ALIAS_UINT32_T ... FIELD_TYPE_ALIAS_UINT64_T] = 8, +}; + +static +const unsigned int field_type_aliases_sizes[] = { + [FIELD_TYPE_ALIAS_UINT5_T] = 5, + [FIELD_TYPE_ALIAS_UINT8_T] = 8, + [FIELD_TYPE_ALIAS_UINT16_T] = 16, + [FIELD_TYPE_ALIAS_UINT27_T] = 27, + [FIELD_TYPE_ALIAS_UINT32_T] = 32, + [FIELD_TYPE_ALIAS_UINT64_T] = 64, +}; + +BT_HIDDEN +struct bt_ctf_field_type *get_field_type(enum field_type_alias alias) { - bt_put(writer); + int ret; + unsigned int alignment, size; + struct bt_ctf_field_type *field_type = NULL; + + if (alias >= NR_FIELD_TYPE_ALIAS) { + goto end; + } + + alignment = field_type_aliases_alignments[alias]; + size = field_type_aliases_sizes[alias]; + field_type = bt_ctf_field_type_integer_create(size); + ret = bt_ctf_field_type_set_alignment(field_type, alignment); + if (ret) { + BT_CTF_OBJECT_PUT_REF_AND_RESET(field_type); + } +end: + return field_type; } BT_HIDDEN -void bt_ctf_writer_freeze(struct bt_ctf_writer *writer) +const char *bt_ctf_get_byte_order_string(enum bt_ctf_byte_order byte_order) { - writer->frozen = 1; + const char *string; + + switch (byte_order) { + case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN: + string = "le"; + break; + case BT_CTF_BYTE_ORDER_BIG_ENDIAN: + string = "be"; + break; + case BT_CTF_BYTE_ORDER_NATIVE: + string = "native"; + break; + default: + abort(); + } + + return string; }