X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=formats%2Fctf%2Fir%2Fstream-class.c;h=403f5dbbf51089a5d7783b0701faeaafbd86dff7;hb=f3985ab106d89d8e764c1a8dd0c8bda09b755d10;hp=326e759e23d926769267739a9118af7c95c49bde;hpb=272df73edf74c3d8d6cbbf6450258fdbc9fbad36;p=babeltrace.git diff --git a/formats/ctf/ir/stream-class.c b/formats/ctf/ir/stream-class.c index 326e759e..403f5dbb 100644 --- a/formats/ctf/ir/stream-class.c +++ b/formats/ctf/ir/stream-class.c @@ -27,7 +27,8 @@ */ #include -#include +#include +#include #include #include #include @@ -36,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +73,9 @@ struct bt_ctf_stream_class *bt_ctf_stream_class_create(const char *name) goto error; } + stream_class->event_classes_ht = g_hash_table_new_full(g_int64_hash, + g_int64_equal, g_free, NULL); + ret = init_event_header(stream_class); if (ret) { goto error; @@ -134,8 +139,7 @@ struct bt_ctf_clock *bt_ctf_stream_class_get_clock( goto end; } - clock = stream_class->clock; - bt_get(clock); + clock = bt_get(stream_class->clock); end: return clock; } @@ -152,39 +156,35 @@ int bt_ctf_stream_class_set_clock(struct bt_ctf_stream_class *stream_class, } /* - * Look for a "timestamp" field in the stream class' event header type - * and map the stream's clock to that field if no current mapping is - * currently set. + * Look for a "timestamp" integer field type in the stream + * class's event header field type and map the stream class's + * clock's class to that field type if there's no current + * mapping. */ timestamp_field = bt_ctf_field_type_structure_get_field_type_by_name( stream_class->event_header_type, "timestamp"); if (timestamp_field) { - struct bt_ctf_clock *mapped_clock; - - mapped_clock = bt_ctf_field_type_integer_get_mapped_clock( - timestamp_field); - if (mapped_clock) { - bt_put(mapped_clock); - goto end; + struct bt_ctf_clock_class *mapped_clock_class = + bt_ctf_field_type_integer_get_mapped_clock_class( + timestamp_field); + + if (!mapped_clock_class) { + ret = bt_ctf_field_type_integer_set_mapped_clock_class( + timestamp_field, clock->clock_class); + if (ret) { + goto end; + } } - ret = bt_ctf_field_type_integer_set_mapped_clock( - timestamp_field, clock); - if (ret) { - goto end; - } + BT_PUT(mapped_clock_class); } - if (stream_class->clock) { - bt_put(stream_class->clock); - } + /* Replace the current clock of this stream class. */ + bt_put(stream_class->clock); + stream_class->clock = bt_get(clock); - stream_class->clock = clock; - bt_get(clock); end: - if (timestamp_field) { - bt_put(timestamp_field); - } + bt_put(timestamp_field); return ret; } @@ -316,7 +316,7 @@ int bt_ctf_stream_class_add_event_class( struct bt_ctf_event_class *event_class) { int ret = 0; - int64_t event_id; + int64_t *event_id = NULL; struct bt_ctf_trace *trace = NULL; struct bt_ctf_stream_class *old_stream_class = NULL; struct bt_ctf_validation_output validation_output = { 0 }; @@ -334,6 +334,12 @@ int bt_ctf_stream_class_add_event_class( goto end; } + event_id = g_new(int64_t, 1); + if (!event_id) { + ret = -1; + goto end; + } + /* Check for duplicate event classes */ struct search_query query = { .value = event_class, .found = 0 }; g_ptr_array_foreach(stream_class->event_classes, event_class_exists, @@ -409,13 +415,14 @@ int bt_ctf_stream_class_add_event_class( } /* 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) { + *event_id = bt_ctf_event_class_get_id(event_class); + if (*event_id < 0) { if (bt_ctf_event_class_set_id(event_class, stream_class->next_event_id++)) { ret = -1; goto end; } + *event_id = stream_class->next_event_id; } ret = bt_ctf_event_class_set_stream_id(event_class, stream_class->id); @@ -445,6 +452,9 @@ int bt_ctf_stream_class_add_event_class( /* Add to the event classes of the stream class */ g_ptr_array_add(stream_class->event_classes, event_class); + g_hash_table_insert(stream_class->event_classes_ht, event_id, + event_class); + event_id = NULL; /* Freeze the event class */ bt_ctf_event_class_freeze(event_class); @@ -461,6 +471,13 @@ int bt_ctf_stream_class_add_event_class( stream_class->byte_order); } + /* Notifiy listeners of the trace's schema modification. */ + if (trace) { + struct bt_ctf_object obj = { .object = event_class, + .type = BT_CTF_OBJECT_TYPE_EVENT_CLASS }; + + (void) bt_ctf_trace_object_modification(&obj, trace); + } end: BT_PUT(trace); BT_PUT(old_stream_class); @@ -471,6 +488,7 @@ end: assert(!stream_event_ctx_type); assert(!event_context_type); assert(!event_payload_type); + g_free(event_id); return ret; } @@ -535,23 +553,16 @@ end: struct bt_ctf_event_class *bt_ctf_stream_class_get_event_class_by_id( struct bt_ctf_stream_class *stream_class, uint32_t id) { - size_t i; + int64_t id_key = id; struct bt_ctf_event_class *event_class = NULL; if (!stream_class) { goto end; } - for (i = 0; i < stream_class->event_classes->len; i++) { - struct bt_ctf_event_class *current_event_class = - g_ptr_array_index(stream_class->event_classes, i); - - if (bt_ctf_event_class_get_id(current_event_class) == id) { - event_class = current_event_class; - bt_get(event_class); - goto end; - } - } + event_class = g_hash_table_lookup(stream_class->event_classes_ht, + &id_key); + bt_get(event_class); end: return event_class; } @@ -565,7 +576,6 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_packet_context_type( goto end; } - assert(stream_class->packet_context_type); bt_get(stream_class->packet_context_type); ret = stream_class->packet_context_type; end: @@ -578,18 +588,15 @@ int bt_ctf_stream_class_set_packet_context_type( { int ret = 0; - if (!stream_class || !packet_context_type || stream_class->frozen) { + if (!stream_class || stream_class->frozen) { ret = -1; goto end; } - assert(stream_class->packet_context_type); - if (stream_class->packet_context_type == packet_context_type) { - goto end; - } - if (bt_ctf_field_type_get_type_id(packet_context_type) != - BT_CTF_TYPE_ID_STRUCT) { - /* A packet context must be a structure */ + if (packet_context_type && + bt_ctf_field_type_get_type_id(packet_context_type) != + BT_CTF_TYPE_ID_STRUCT) { + /* A packet context must be a structure. */ ret = -1; goto end; } @@ -610,7 +617,6 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_event_header_type( goto end; } - assert(stream_class->event_header_type); bt_get(stream_class->event_header_type); ret = stream_class->event_header_type; end: @@ -623,25 +629,21 @@ int bt_ctf_stream_class_set_event_header_type( { int ret = 0; - if (!stream_class || !event_header_type || stream_class->frozen) { + if (!stream_class || stream_class->frozen) { ret = -1; goto end; } - assert(stream_class->event_header_type); - if (stream_class->event_header_type == event_header_type) { - goto end; - } - if (bt_ctf_field_type_get_type_id(event_header_type) != - BT_CTF_TYPE_ID_STRUCT) { - /* An event header must be a structure */ + if (event_header_type && + bt_ctf_field_type_get_type_id(event_header_type) != + BT_CTF_TYPE_ID_STRUCT) { + /* An event header must be a structure. */ ret = -1; goto end; } bt_put(stream_class->event_header_type); - bt_get(event_header_type); - stream_class->event_header_type = event_header_type; + stream_class->event_header_type = bt_get(event_header_type); end: return ret; } @@ -655,7 +657,6 @@ struct bt_ctf_field_type *bt_ctf_stream_class_get_event_context_type( goto end; } - assert(stream_class->event_context_type); bt_get(stream_class->event_context_type); ret = stream_class->event_context_type; end: @@ -668,21 +669,21 @@ int bt_ctf_stream_class_set_event_context_type( { int ret = 0; - if (!stream_class || !event_context_type || stream_class->frozen) { + if (!stream_class || stream_class->frozen) { ret = -1; goto end; } - if (bt_ctf_field_type_get_type_id(event_context_type) != - BT_CTF_TYPE_ID_STRUCT) { - /* A packet context must be a structure */ + if (event_context_type && + bt_ctf_field_type_get_type_id(event_context_type) != + BT_CTF_TYPE_ID_STRUCT) { + /* A packet context must be a structure. */ ret = -1; goto end; } bt_put(stream_class->event_context_type); - bt_get(event_context_type); - stream_class->event_context_type = event_context_type; + stream_class->event_context_type = bt_get(event_context_type); end: return ret; } @@ -697,6 +698,50 @@ void bt_ctf_stream_class_put(struct bt_ctf_stream_class *stream_class) bt_put(stream_class); } +static +int get_event_class_count(void *element) +{ + return bt_ctf_stream_class_get_event_class_count( + (struct bt_ctf_stream_class *) element); +} + +static +void *get_event_class(void *element, int i) +{ + return bt_ctf_stream_class_get_event_class( + (struct bt_ctf_stream_class *) element, i); +} + +static +int visit_event_class(void *object, bt_ctf_visitor visitor,void *data) +{ + struct bt_ctf_object obj = + { .object = object, + .type = BT_CTF_OBJECT_TYPE_EVENT_CLASS }; + + return visitor(&obj, data); +} + +int bt_ctf_stream_class_visit(struct bt_ctf_stream_class *stream_class, + bt_ctf_visitor visitor, void *data) +{ + int ret; + struct bt_ctf_object obj = + { .object = stream_class, + .type = BT_CTF_OBJECT_TYPE_STREAM_CLASS }; + + if (!stream_class || !visitor) { + ret = -1; + goto end; + } + + ret = visitor_helper(&obj, get_event_class_count, + get_event_class, + visit_event_class, visitor, data); +end: + return ret; +} + BT_HIDDEN void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class) { @@ -708,7 +753,10 @@ void bt_ctf_stream_class_freeze(struct bt_ctf_stream_class *stream_class) bt_ctf_field_type_freeze(stream_class->event_header_type); 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); + + if (stream_class->clock) { + bt_ctf_clock_class_freeze(stream_class->clock->clock_class); + } } BT_HIDDEN @@ -762,11 +810,13 @@ int bt_ctf_stream_class_serialize(struct bt_ctf_stream_class *stream_class, goto end; } - g_string_append(context->string, ";\n\n\tpacket.context := "); - ret = bt_ctf_field_type_serialize(stream_class->packet_context_type, - context); - if (ret) { - goto end; + if (stream_class->packet_context_type) { + g_string_append(context->string, ";\n\n\tpacket.context := "); + ret = bt_ctf_field_type_serialize(stream_class->packet_context_type, + context); + if (ret) { + goto end; + } } if (stream_class->event_context_type) { @@ -801,6 +851,9 @@ void bt_ctf_stream_class_destroy(struct bt_object *obj) stream_class = container_of(obj, struct bt_ctf_stream_class, base); bt_put(stream_class->clock); + if (stream_class->event_classes_ht) { + g_hash_table_destroy(stream_class->event_classes_ht); + } if (stream_class->event_classes) { g_ptr_array_free(stream_class->event_classes, TRUE); }