X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fir%2Fstream-class.c;h=07f15651361280752a38998033b55ace8e5d03c7;hb=9f476966aa40bd0de2cd0654623ea03f8a3254eb;hp=10095a2ce6053b9accc6998e3b8b00074caa50fa;hpb=12c8a1a3121ed7125e8758065c44658d8eda1333;p=babeltrace.git diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 10095a2c..07f15651 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -1,7 +1,7 @@ /* * stream-class.c * - * Babeltrace CTF Writer + * Babeltrace CTF IR - Stream Class * * Copyright 2013, 2014 Jérémie Galarneau * @@ -151,7 +151,7 @@ int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, { int ret = 0; - if (!stream_class) { + if (!stream_class || stream_class->frozen) { ret = -1; goto end; } @@ -203,27 +203,28 @@ end: return ret; } -int64_t bt_ctf_stream_class_get_event_class_count( +int bt_ctf_stream_class_get_event_class_count( struct bt_ctf_stream_class *stream_class) { - int64_t ret; + int ret; if (!stream_class) { ret = -1; goto end; } - ret = (int64_t) stream_class->event_classes->len; + ret = (int) stream_class->event_classes->len; end: return ret; } struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class( - struct bt_ctf_stream_class *stream_class, size_t index) + struct bt_ctf_stream_class *stream_class, int index) { struct bt_ctf_event_class *event_class = NULL; - if (!stream_class || index >= stream_class->event_classes->len) { + if (!stream_class || index < 0 || + index >= stream_class->event_classes->len) { goto end; } @@ -285,13 +286,13 @@ int bt_ctf_stream_class_set_packet_context_type( { int ret = 0; - if (!stream_class || !packet_context_type) { + if (!stream_class || !packet_context_type || stream_class->frozen) { ret = -1; goto end; } assert(stream_class->packet_context_type); - if (bt_ctf_field_type_get_type_id(stream_class->packet_context_type) != + if (bt_ctf_field_type_get_type_id(packet_context_type) != CTF_TYPE_STRUCT) { /* A packet context must be a structure */ ret = -1; @@ -305,6 +306,88 @@ end: return ret; } +struct bt_ctf_field_type *bt_ctf_stream_class_get_event_header_type( + struct bt_ctf_stream_class *stream_class) +{ + struct bt_ctf_field_type *ret = NULL; + + if (!stream_class || !stream_class->event_header_type) { + goto end; + } + + assert(stream_class->event_header_type); + bt_ctf_field_type_get(stream_class->event_header_type); + ret = stream_class->event_header_type; +end: + return ret; +} + +int bt_ctf_stream_class_set_event_header_type( + struct bt_ctf_stream_class *stream_class, + struct bt_ctf_field_type *event_header_type) +{ + int ret = 0; + + if (!stream_class || !event_header_type || stream_class->frozen) { + ret = -1; + goto end; + } + + if (bt_ctf_field_type_get_type_id(event_header_type) != + CTF_TYPE_STRUCT) { + /* An event header must be a structure */ + ret = -1; + goto end; + } + + bt_ctf_field_type_put(stream_class->event_header_type); + bt_ctf_field_type_get(event_header_type); + stream_class->event_header_type = event_header_type; +end: + return ret; +} + +struct bt_ctf_field_type *bt_ctf_stream_class_get_event_context_type( + struct bt_ctf_stream_class *stream_class) +{ + struct bt_ctf_field_type *ret = NULL; + + if (!stream_class || !stream_class->event_context_type) { + goto end; + } + + assert(stream_class->event_context_type); + bt_ctf_field_type_get(stream_class->event_context_type); + ret = stream_class->event_context_type; +end: + return ret; +} + +int bt_ctf_stream_class_set_event_context_type( + struct bt_ctf_stream_class *stream_class, + struct bt_ctf_field_type *event_context_type) +{ + int ret = 0; + + if (!stream_class || !event_context_type || stream_class->frozen) { + ret = -1; + goto end; + } + + if (bt_ctf_field_type_get_type_id(event_context_type) != + CTF_TYPE_STRUCT) { + /* A packet context must be a structure */ + ret = -1; + goto end; + } + + bt_ctf_field_type_put(stream_class->event_context_type); + bt_ctf_field_type_get(event_context_type); + stream_class->event_context_type = event_context_type; +end: + return ret; +} + void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class) { if (!stream_class) { @@ -332,6 +415,7 @@ void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class) stream_class->frozen = 1; bt_ctf_field_type_freeze(stream_class->packet_context_type); + bt_ctf_field_type_freeze(stream_class->event_context_type); bt_ctf_clock_freeze(stream_class->clock); g_ptr_array_foreach(stream_class->event_classes, (GFunc)bt_ctf_event_class_freeze, NULL); @@ -437,10 +521,10 @@ void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref) } bt_ctf_field_type_put(stream_class->event_header_type); - bt_ctf_field_put(stream_class->event_header); bt_ctf_field_type_put(stream_class->packet_context_type); - bt_ctf_field_type_put(stream_class->event_context_type); - bt_ctf_field_put(stream_class->event_context); + if (stream_class->event_context_type) { + bt_ctf_field_type_put(stream_class->event_context_type); + } g_free(stream_class); } @@ -484,11 +568,6 @@ int init_event_header(struct bt_ctf_stream_class *stream_class, } stream_class->event_header_type = event_header_type; - stream_class->event_header = bt_ctf_field_create( - stream_class->event_header_type); - if (!stream_class->event_header) { - ret = -1; - } end: if (ret) { bt_ctf_field_type_put(event_header_type);