X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fir%2Fstream-class.c;h=b5e7e79dca12b2f7330a68ee838101a1da6f4b89;hb=09840de5d022697671dafe2bed427fa5c09b40b9;hp=9ef5ca790d7bbf8c8fec5ed95620b2ec5f422cef;hpb=0d23acbeeb27ebede2278c50c2c7e0fe0b1ae8d2;p=babeltrace.git diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 9ef5ca79..b5e7e79d 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -34,13 +34,16 @@ #include #include #include +#include #include #include +#include #include #include +#include static -void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref); +void bt_ctf_stream_class_destroy(struct bt_object *obj); static int init_event_header(struct bt_ctf_stream_class *stream_class); static @@ -62,31 +65,36 @@ struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name) stream_class->name = g_string_new(name); stream_class->event_classes = g_ptr_array_new_with_free_func( - (GDestroyNotify)bt_ctf_event_class_put); + (GDestroyNotify) bt_object_release); if (!stream_class->event_classes) { - goto error_destroy; + goto error; } ret = init_event_header(stream_class); if (ret) { - goto error_destroy; + goto error; } ret = init_packet_context(stream_class); if (ret) { - goto error_destroy; + goto error; } - bt_ctf_ref_init(&stream_class->ref_count); + bt_object_init(stream_class, bt_ctf_stream_class_destroy); return stream_class; -error_destroy: - bt_ctf_stream_class_destroy(&stream_class->ref_count); - stream_class = NULL; error: + BT_PUT(stream_class); return stream_class; } +struct bt_ctf_trace *bt_ctf_stream_class_get_trace( + struct bt_ctf_stream_class *stream_class) +{ + return (struct bt_ctf_trace *) bt_object_get_parent( + stream_class); +} + const char *bt_ctf_stream_class_get_name( struct bt_ctf_stream_class *stream_class) { @@ -126,7 +134,7 @@ struct bt_ctf_clock *bt_ctf_stream_class_get_clock( } clock = stream_class->clock; - bt_ctf_clock_get(clock); + bt_get(clock); end: return clock; } @@ -155,7 +163,7 @@ int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, mapped_clock = bt_ctf_field_type_integer_get_mapped_clock( timestamp_field); if (mapped_clock) { - bt_ctf_clock_put(mapped_clock); + bt_put(mapped_clock); goto end; } @@ -167,14 +175,14 @@ int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, } if (stream_class->clock) { - bt_ctf_clock_put(stream_class->clock); + bt_put(stream_class->clock); } stream_class->clock = clock; - bt_ctf_clock_get(clock); + bt_get(clock); end: if (timestamp_field) { - bt_ctf_field_type_put(timestamp_field); + bt_put(timestamp_field); } return ret; } @@ -202,13 +210,36 @@ int _bt_ctf_stream_class_set_id( return 0; } -int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, - uint32_t id) +struct event_class_set_stream_id_data { + uint32_t stream_id; + int ret; +}; + +static +void event_class_set_stream_id(gpointer event_class, gpointer data) +{ + struct event_class_set_stream_id_data *typed_data = data; + + typed_data->ret |= bt_ctf_event_class_set_stream_id(event_class, + typed_data->stream_id); +} + +BT_HIDDEN +int bt_ctf_stream_class_set_id_no_check( + struct bt_ctf_stream_class *stream_class, uint32_t id) { int ret = 0; + struct event_class_set_stream_id_data data = + { .stream_id = id, .ret = 0 }; - if (!stream_class || stream_class->frozen) { - ret = -1; + /* + * Make sure all event classes have their "stream_id" attribute + * set to this value. + */ + g_ptr_array_foreach(stream_class->event_classes, + event_class_set_stream_id, &data); + ret = data.ret; + if (ret) { goto end; } @@ -220,6 +251,21 @@ end: return ret; } +int bt_ctf_stream_class_set_id(struct bt_ctf_stream_class *stream_class, + uint32_t id) +{ + int ret = 0; + + if (!stream_class || stream_class->frozen) { + ret = -1; + goto end; + } + + ret = bt_ctf_stream_class_set_id_no_check(stream_class, id); +end: + return ret; +} + static void event_class_exists(gpointer element, gpointer query) { @@ -270,6 +316,17 @@ int bt_ctf_stream_class_add_event_class( { int ret = 0; int64_t event_id; + struct bt_ctf_trace *trace = NULL; + struct bt_ctf_stream_class *old_stream_class = NULL; + struct bt_ctf_validation_output validation_output = { 0 }; + struct bt_ctf_field_type *packet_header_type = NULL; + struct bt_ctf_field_type *packet_context_type = NULL; + struct bt_ctf_field_type *event_header_type = NULL; + struct bt_ctf_field_type *stream_event_ctx_type = NULL; + struct bt_ctf_field_type *event_context_type = NULL; + struct bt_ctf_field_type *event_payload_type = NULL; + const enum bt_ctf_validation_flag validation_flags = + BT_CTF_VALIDATION_FLAG_EVENT; if (!stream_class || !event_class) { ret = -1; @@ -285,7 +342,72 @@ int bt_ctf_stream_class_add_event_class( goto end; } - /* Only set an event id if none was explicitly set before */ + old_stream_class = bt_ctf_event_class_get_stream_class(event_class); + if (old_stream_class) { + /* Event class is already associated to a stream class. */ + ret = -1; + goto end; + } + + trace = bt_ctf_stream_class_get_trace(stream_class); + if (trace) { + /* + * If the stream class is associated with a trace, then + * both those objects are frozen. Also, this event class + * is about to be frozen. + * + * Therefore the event class must be validated here. + * The trace and stream class should be valid at this + * point. + */ + assert(trace->valid); + assert(stream_class->valid); + packet_header_type = + bt_ctf_trace_get_packet_header_type(trace); + packet_context_type = + bt_ctf_stream_class_get_packet_context_type( + stream_class); + event_header_type = + bt_ctf_stream_class_get_event_header_type(stream_class); + stream_event_ctx_type = + bt_ctf_stream_class_get_event_context_type( + stream_class); + event_context_type = + bt_ctf_event_class_get_context_type(event_class); + event_payload_type = + bt_ctf_event_class_get_payload_type(event_class); + ret = bt_ctf_validate_class_types( + trace->environment, packet_header_type, + packet_context_type, event_header_type, + stream_event_ctx_type, event_context_type, + event_payload_type, trace->valid, + stream_class->valid, event_class->valid, + &validation_output, validation_flags); + BT_PUT(packet_header_type); + BT_PUT(packet_context_type); + BT_PUT(event_header_type); + BT_PUT(stream_event_ctx_type); + BT_PUT(event_context_type); + BT_PUT(event_payload_type); + + if (ret) { + /* + * This means something went wrong during the + * validation process, not that the objects are + * invalid. + */ + goto end; + } + + if ((validation_output.valid_flags & validation_flags) != + validation_flags) { + /* Invalid event class */ + ret = -1; + goto end; + } + } + + /* Only set an event ID if none was explicitly set before */ event_id = bt_ctf_event_class_get_id(event_class); if (event_id < 0) { if (bt_ctf_event_class_set_id(event_class, @@ -295,13 +417,35 @@ int bt_ctf_stream_class_add_event_class( } } - ret = bt_ctf_event_class_set_stream_class(event_class, stream_class); + ret = bt_ctf_event_class_set_stream_id(event_class, stream_class->id); if (ret) { goto end; } - bt_ctf_event_class_get(event_class); + bt_object_set_parent(event_class, stream_class); + + if (trace) { + /* + * At this point we know that the function will be + * successful. Therefore we can replace the event + * class's field types with what's in the validation + * output structure and mark this event class as valid. + */ + bt_ctf_validation_replace_types(NULL, NULL, event_class, + &validation_output, validation_flags); + event_class->valid = 1; + + /* + * Put what was not moved in + * bt_ctf_validation_replace_types(). + */ + bt_ctf_validation_output_put_types(&validation_output); + } + + /* Add to the event classes of the stream class */ g_ptr_array_add(stream_class->event_classes, event_class); + + /* Freeze the event class */ bt_ctf_event_class_freeze(event_class); if (stream_class->byte_order) { @@ -310,12 +454,23 @@ int bt_ctf_stream_class_add_event_class( * when the stream class was added to a trace. * * If not set here, this will be set when the stream - * classe will be added to a trace. + * class is added to a trace. */ bt_ctf_event_class_set_native_byte_order(event_class, stream_class->byte_order); } + end: + BT_PUT(trace); + BT_PUT(old_stream_class); + bt_ctf_validation_output_put_types(&validation_output); + assert(!packet_header_type); + assert(!packet_context_type); + assert(!event_header_type); + assert(!stream_event_ctx_type); + assert(!event_context_type); + assert(!event_payload_type); + return ret; } @@ -345,7 +500,7 @@ struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class( } event_class = g_ptr_array_index(stream_class->event_classes, index); - bt_ctf_event_class_get(event_class); + bt_get(event_class); end: return event_class; } @@ -368,7 +523,7 @@ struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_name( if (!strcmp(name, cur_event_class_name)) { event_class = cur_event_class; - bt_ctf_event_class_get(event_class); + bt_get(event_class); goto end; } } @@ -392,7 +547,7 @@ struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_id( if (bt_ctf_event_class_get_id(current_event_class) == id) { event_class = current_event_class; - bt_ctf_event_class_get(event_class); + bt_get(event_class); goto end; } } @@ -410,7 +565,7 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type( } assert(stream_class->packet_context_type); - bt_ctf_field_type_get(stream_class->packet_context_type); + bt_get(stream_class->packet_context_type); ret = stream_class->packet_context_type; end: return ret; @@ -438,8 +593,8 @@ int bt_ctf_stream_class_set_packet_context_type( goto end; } - bt_ctf_field_type_put(stream_class->packet_context_type); - bt_ctf_field_type_get(packet_context_type); + bt_put(stream_class->packet_context_type); + bt_get(packet_context_type); stream_class->packet_context_type = packet_context_type; end: return ret; @@ -455,7 +610,7 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_event_header_type( } assert(stream_class->event_header_type); - bt_ctf_field_type_get(stream_class->event_header_type); + bt_get(stream_class->event_header_type); ret = stream_class->event_header_type; end: return ret; @@ -483,8 +638,8 @@ int bt_ctf_stream_class_set_event_header_type( goto end; } - bt_ctf_field_type_put(stream_class->event_header_type); - bt_ctf_field_type_get(event_header_type); + bt_put(stream_class->event_header_type); + bt_get(event_header_type); stream_class->event_header_type = event_header_type; end: return ret; @@ -500,7 +655,7 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_event_context_type( } assert(stream_class->event_context_type); - bt_ctf_field_type_get(stream_class->event_context_type); + bt_get(stream_class->event_context_type); ret = stream_class->event_context_type; end: return ret; @@ -524,8 +679,8 @@ int bt_ctf_stream_class_set_event_context_type( goto end; } - bt_ctf_field_type_put(stream_class->event_context_type); - bt_ctf_field_type_get(event_context_type); + bt_put(stream_class->event_context_type); + bt_get(event_context_type); stream_class->event_context_type = event_context_type; end: return ret; @@ -533,20 +688,12 @@ end: void bt_ctf_stream_class_get(struct bt_ctf_stream_class *stream_class) { - if (!stream_class) { - return; - } - - bt_ctf_ref_get(&stream_class->ref_count); + bt_get(stream_class); } void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class) { - if (!stream_class) { - return; - } - - bt_ctf_ref_put(&stream_class->ref_count, bt_ctf_stream_class_destroy); + bt_put(stream_class); } BT_HIDDEN @@ -564,52 +711,31 @@ void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class) } BT_HIDDEN -int bt_ctf_stream_class_set_byte_order(struct bt_ctf_stream_class *stream_class, - enum bt_ctf_byte_order byte_order) +void bt_ctf_stream_class_set_byte_order( + struct bt_ctf_stream_class *stream_class, int byte_order) { - int i, ret = 0; - int internal_byte_order; + int i; - /* Note that "NATIVE" means the trace's endianness, not the host's. */ - if (!stream_class || byte_order <= BT_CTF_BYTE_ORDER_UNKNOWN || - byte_order > BT_CTF_BYTE_ORDER_NETWORK) { - ret = -1; - goto end; - } - - switch (byte_order) { - case BT_CTF_BYTE_ORDER_NETWORK: - case BT_CTF_BYTE_ORDER_BIG_ENDIAN: - internal_byte_order = BIG_ENDIAN; - break; - case BT_CTF_BYTE_ORDER_LITTLE_ENDIAN: - internal_byte_order = LITTLE_ENDIAN; - break; - default: - ret = -1; - goto end; - } - - stream_class->byte_order = internal_byte_order; + assert(stream_class); + assert(byte_order == LITTLE_ENDIAN || byte_order == BIG_ENDIAN); + stream_class->byte_order = byte_order; /* Set native byte order to little or big endian */ bt_ctf_field_type_set_native_byte_order( - stream_class->event_header_type, stream_class->byte_order); + stream_class->event_header_type, byte_order); bt_ctf_field_type_set_native_byte_order( - stream_class->packet_context_type, stream_class->byte_order); + stream_class->packet_context_type, byte_order); bt_ctf_field_type_set_native_byte_order( - stream_class->event_context_type, stream_class->byte_order); + stream_class->event_context_type, byte_order); /* Set all events' native byte order */ for (i = 0; i < stream_class->event_classes->len; i++) { - bt_ctf_event_class_set_native_byte_order( - g_ptr_array_index(stream_class->event_classes, i), - stream_class->byte_order); - bt_ctf_event_class_freeze( - g_ptr_array_index(stream_class->event_classes, i)); + struct bt_ctf_event_class *event_class = + g_ptr_array_index(stream_class->event_classes, i); + + bt_ctf_event_class_set_native_byte_order(event_class, + byte_order); } -end: - return ret; } BT_HIDDEN @@ -667,29 +793,14 @@ end: } static -void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref) +void bt_ctf_stream_class_destroy(struct bt_object *obj) { struct bt_ctf_stream_class *stream_class; - if (!ref) { - return; - } - - stream_class = container_of(ref, struct bt_ctf_stream_class, ref_count); - bt_ctf_clock_put(stream_class->clock); + stream_class = container_of(obj, struct bt_ctf_stream_class, base); + bt_put(stream_class->clock); if (stream_class->event_classes) { - size_t i; - - /* Unregister this stream class from the event classes */ - for (i = 0; i < stream_class->event_classes->len; i++) { - struct bt_ctf_event_class *event_class = - g_ptr_array_index(stream_class->event_classes, - i); - - bt_ctf_event_class_set_stream_class(event_class, NULL); - } - g_ptr_array_free(stream_class->event_classes, TRUE); } @@ -697,11 +808,9 @@ void bt_ctf_stream_class_destroy(struct bt_ctf_ref *ref) g_string_free(stream_class->name, TRUE); } - bt_ctf_field_type_put(stream_class->event_header_type); - bt_ctf_field_type_put(stream_class->packet_context_type); - if (stream_class->event_context_type) { - bt_ctf_field_type_put(stream_class->event_context_type); - } + bt_put(stream_class->event_header_type); + bt_put(stream_class->packet_context_type); + bt_put(stream_class->event_context_type); g_free(stream_class); } @@ -734,16 +843,16 @@ int init_event_header(struct bt_ctf_stream_class *stream_class) } if (stream_class->event_header_type) { - bt_ctf_field_type_put(stream_class->event_header_type); + bt_put(stream_class->event_header_type); } stream_class->event_header_type = event_header_type; end: if (ret) { - bt_ctf_field_type_put(event_header_type); + bt_put(event_header_type); } - bt_ctf_field_type_put(_uint32_t); - bt_ctf_field_type_put(_uint64_t); + bt_put(_uint32_t); + bt_put(_uint64_t); return ret; } @@ -795,16 +904,14 @@ int init_packet_context(struct bt_ctf_stream_class *stream_class) goto end; } - if (stream_class->packet_context_type) { - bt_ctf_field_type_put(stream_class->packet_context_type); - } + bt_put(stream_class->packet_context_type); stream_class->packet_context_type = packet_context_type; end: if (ret) { - bt_ctf_field_type_put(packet_context_type); + bt_put(packet_context_type); goto end; } - bt_ctf_field_type_put(_uint64_t); + bt_put(_uint64_t); return ret; }