X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fctf-writer%2Fevent-class.c;h=f918b86dfef64a1d79f19263109741cf9a87e12b;hb=3fadfbc0c91f82c46bd36e6e0657ea93570c9db1;hp=057fc12a44616213d7dcd5de894a53948517e5f4;hpb=094ff7c009937bb23c056333baffe734308a6b06;p=babeltrace.git diff --git a/lib/ctf-writer/event-class.c b/lib/ctf-writer/event-class.c index 057fc12a..f918b86d 100644 --- a/lib/ctf-writer/event-class.c +++ b/lib/ctf-writer/event-class.c @@ -22,26 +22,169 @@ */ #define BT_LOG_TAG "CTF-WRITER-EVENT-CLASS" -#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 +#include +#include #include +#include +#include +#include + +BT_HIDDEN +void bt_ctf_event_class_common_finalize(struct bt_ctf_object *obj) +{ + struct bt_ctf_event_class_common *event_class; + + event_class = container_of(obj, struct bt_ctf_event_class_common, base); + BT_LOGD("Finalizing common event class: addr=%p, name=\"%s\", id=%" PRId64, + event_class, bt_ctf_event_class_common_get_name(event_class), + bt_ctf_event_class_common_get_id(event_class)); + + if (event_class->name) { + g_string_free(event_class->name, TRUE); + } + + if (event_class->emf_uri) { + g_string_free(event_class->emf_uri, TRUE); + } + + BT_LOGD_STR("Putting context field type."); + bt_ctf_object_put_ref(event_class->context_field_type); + BT_LOGD_STR("Putting payload field type."); + bt_ctf_object_put_ref(event_class->payload_field_type); +} + +BT_HIDDEN +int bt_ctf_event_class_common_initialize(struct bt_ctf_event_class_common *event_class, + const char *name, bt_ctf_object_release_func release_func, + bt_ctf_field_type_structure_create_func ft_struct_create_func) +{ + int ret = 0; + + BT_LOGD("Initializing common event class object: name=\"%s\"", + name); + bt_ctf_object_init_shared_with_parent(&event_class->base, release_func); + event_class->payload_field_type = ft_struct_create_func(); + if (!event_class->payload_field_type) { + BT_LOGE_STR("Cannot create event class's initial payload field type object."); + goto error; + } + + event_class->id = -1; + event_class->name = g_string_new(name); + if (!event_class->name) { + BT_LOGE_STR("Failed to allocate a GString."); + goto error; + } + + event_class->emf_uri = g_string_new(NULL); + if (!event_class->emf_uri) { + BT_LOGE_STR("Failed to allocate a GString."); + goto error; + } + + event_class->log_level = BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED; + BT_LOGD("Initialized common event class object: addr=%p, name=\"%s\"", + event_class, bt_ctf_event_class_common_get_name(event_class)); + return ret; + +error: + ret = -1; + return ret; +} + +BT_HIDDEN +void bt_ctf_event_class_common_freeze(struct bt_ctf_event_class_common *event_class) +{ + BT_ASSERT(event_class); + + if (event_class->frozen) { + return; + } + + BT_LOGD("Freezing event class: addr=%p, name=\"%s\", id=%" PRId64, + event_class, bt_ctf_event_class_common_get_name(event_class), + bt_ctf_event_class_common_get_id(event_class)); + event_class->frozen = 1; + BT_LOGD_STR("Freezing event class's context field type."); + bt_ctf_field_type_common_freeze(event_class->context_field_type); + BT_LOGD_STR("Freezing event class's payload field type."); + bt_ctf_field_type_common_freeze(event_class->payload_field_type); +} + +BT_HIDDEN +int bt_ctf_event_class_common_validate_single_clock_class( + struct bt_ctf_event_class_common *event_class, + struct bt_ctf_clock_class **expected_clock_class) +{ + int ret = 0; + + BT_ASSERT(event_class); + BT_ASSERT(expected_clock_class); + ret = bt_ctf_field_type_common_validate_single_clock_class( + event_class->context_field_type, + expected_clock_class); + if (ret) { + BT_LOGW("Event class's context field type " + "is not recursively mapped to the " + "expected clock class: " + "event-class-addr=%p, " + "event-class-name=\"%s\", " + "event-class-id=%" PRId64 ", " + "ft-addr=%p", + event_class, + bt_ctf_event_class_common_get_name(event_class), + event_class->id, + event_class->context_field_type); + goto end; + } + + ret = bt_ctf_field_type_common_validate_single_clock_class( + event_class->payload_field_type, + expected_clock_class); + if (ret) { + BT_LOGW("Event class's payload field type " + "is not recursively mapped to the " + "expected clock class: " + "event-class-addr=%p, " + "event-class-name=\"%s\", " + "event-class-id=%" PRId64 ", " + "ft-addr=%p", + event_class, + bt_ctf_event_class_common_get_name(event_class), + event_class->id, + event_class->payload_field_type); + goto end; + } + +end: + return ret; +} static -void bt_ctf_event_class_destroy(struct bt_object *obj) +void bt_ctf_event_class_destroy(struct bt_ctf_object *obj) { - bt_event_class_common_finalize(obj); + bt_ctf_event_class_common_finalize(obj); g_free(obj); } @@ -63,9 +206,9 @@ struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name) goto error; } - ret = bt_event_class_common_initialize(BT_TO_COMMON(ctf_event_class), + ret = bt_ctf_event_class_common_initialize(BT_CTF_TO_COMMON(ctf_event_class), name, bt_ctf_event_class_destroy, - (bt_field_type_structure_create_func) + (bt_ctf_field_type_structure_create_func) bt_ctf_field_type_structure_create); if (ret) { goto error; @@ -74,7 +217,7 @@ struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name) goto end; error: - bt_put(ctf_event_class); + bt_ctf_object_put_ref(ctf_event_class); end: return ctf_event_class; @@ -82,43 +225,43 @@ end: const char *bt_ctf_event_class_get_name(struct bt_ctf_event_class *event_class) { - return bt_event_class_common_get_name(BT_TO_COMMON(event_class)); + return bt_ctf_event_class_common_get_name(BT_CTF_TO_COMMON(event_class)); } int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class) { - return bt_event_class_common_get_id(BT_TO_COMMON(event_class)); + return bt_ctf_event_class_common_get_id(BT_CTF_TO_COMMON(event_class)); } int bt_ctf_event_class_set_id(struct bt_ctf_event_class *event_class, uint64_t id) { - return bt_event_class_common_set_id(BT_TO_COMMON(event_class), id); + return bt_ctf_event_class_common_set_id(BT_CTF_TO_COMMON(event_class), id); } enum bt_ctf_event_class_log_level bt_ctf_event_class_get_log_level( struct bt_ctf_event_class *event_class) { - return bt_event_class_common_get_log_level(BT_TO_COMMON(event_class)); + return bt_ctf_event_class_common_get_log_level(BT_CTF_TO_COMMON(event_class)); } int bt_ctf_event_class_set_log_level(struct bt_ctf_event_class *event_class, enum bt_ctf_event_class_log_level log_level) { - return bt_event_class_common_set_log_level(BT_TO_COMMON(event_class), + return bt_ctf_event_class_common_set_log_level(BT_CTF_TO_COMMON(event_class), log_level); } const char *bt_ctf_event_class_get_emf_uri( struct bt_ctf_event_class *event_class) { - return bt_event_class_common_get_emf_uri(BT_TO_COMMON(event_class)); + return bt_ctf_event_class_common_get_emf_uri(BT_CTF_TO_COMMON(event_class)); } int bt_ctf_event_class_set_emf_uri(struct bt_ctf_event_class *event_class, const char *emf_uri) { - return bt_event_class_common_set_emf_uri(BT_TO_COMMON(event_class), + return bt_ctf_event_class_common_set_emf_uri(BT_CTF_TO_COMMON(event_class), emf_uri); } @@ -126,38 +269,38 @@ struct bt_ctf_stream_class *bt_ctf_event_class_get_stream_class( struct bt_ctf_event_class *event_class) { BT_ASSERT_PRE_NON_NULL(event_class, "Event class"); - return bt_get(bt_event_class_common_borrow_stream_class( - BT_TO_COMMON(event_class))); + return bt_ctf_object_get_ref(bt_ctf_event_class_common_borrow_stream_class( + BT_CTF_TO_COMMON(event_class))); } struct bt_ctf_field_type *bt_ctf_event_class_get_payload_field_type( struct bt_ctf_event_class *event_class) { - return bt_get(bt_event_class_common_borrow_payload_field_type( - BT_TO_COMMON(event_class))); + return bt_ctf_object_get_ref(bt_ctf_event_class_common_borrow_payload_field_type( + BT_CTF_TO_COMMON(event_class))); } int bt_ctf_event_class_set_payload_field_type( struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *field_type) { - return bt_event_class_common_set_payload_field_type( - BT_TO_COMMON(event_class), (void *) field_type); + return bt_ctf_event_class_common_set_payload_field_type( + BT_CTF_TO_COMMON(event_class), (void *) field_type); } struct bt_ctf_field_type *bt_ctf_event_class_get_context_field_type( struct bt_ctf_event_class *event_class) { - return bt_get(bt_event_class_common_borrow_context_field_type( - BT_TO_COMMON(event_class))); + return bt_ctf_object_get_ref(bt_ctf_event_class_common_borrow_context_field_type( + BT_CTF_TO_COMMON(event_class))); } int bt_ctf_event_class_set_context_field_type( struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *field_type) { - return bt_event_class_common_set_context_field_type( - BT_TO_COMMON(event_class), (void *) field_type); + return bt_ctf_event_class_common_set_context_field_type( + BT_CTF_TO_COMMON(event_class), (void *) field_type); } int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, @@ -174,7 +317,7 @@ int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, goto end; } - if (!bt_identifier_is_valid(name)) { + if (!bt_ctf_identifier_is_valid(name)) { BT_LOGW("Invalid parameter: event class's payload field type's field name is not a valid CTF identifier: " "addr=%p, name=\"%s\", id=%" PRId64 ", field-name=\"%s\"", event_class, bt_ctf_event_class_get_name(event_class), @@ -202,9 +345,9 @@ int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, goto end; } - BT_ASSERT(bt_field_type_common_get_type_id( + BT_ASSERT(bt_ctf_field_type_common_get_type_id( event_class->common.payload_field_type) == - BT_FIELD_TYPE_ID_STRUCT); + BT_CTF_FIELD_TYPE_ID_STRUCT); ret = bt_ctf_field_type_structure_add_field( (void *) event_class->common.payload_field_type, (void *) type, name); @@ -237,10 +380,10 @@ int64_t bt_ctf_event_class_get_payload_type_field_count( goto end; } - BT_ASSERT(bt_field_type_common_get_type_id( + BT_ASSERT(bt_ctf_field_type_common_get_type_id( event_class->common.payload_field_type) == - BT_FIELD_TYPE_ID_STRUCT); - ret = bt_field_type_common_structure_get_field_count( + BT_CTF_FIELD_TYPE_ID_STRUCT); + ret = bt_ctf_field_type_common_structure_get_field_count( event_class->common.payload_field_type); end: return ret; @@ -268,9 +411,9 @@ int bt_ctf_event_class_get_payload_type_field_by_index( goto end; } - BT_ASSERT(bt_field_type_common_get_type_id( + BT_ASSERT(bt_ctf_field_type_common_get_type_id( event_class->common.payload_field_type) == - BT_FIELD_TYPE_ID_STRUCT); + BT_CTF_FIELD_TYPE_ID_STRUCT); ret = bt_ctf_field_type_structure_get_field_by_index( (void *) event_class->common.payload_field_type, field_name, (void *) field_type, index); @@ -279,12 +422,12 @@ end: return ret; } -struct bt_field_type * +struct bt_ctf_field_type * bt_ctf_event_class_get_payload_type_field_type_by_name( struct bt_ctf_event_class *event_class, const char *name) { GQuark name_quark; - struct bt_field_type *field_type = NULL; + struct bt_ctf_field_type *field_type = NULL; if (!event_class || !name) { BT_LOGW("Invalid parameter: event class or name is NULL: " @@ -301,9 +444,9 @@ bt_ctf_event_class_get_payload_type_field_type_by_name( goto end; } - BT_ASSERT(bt_field_type_common_get_type_id( + BT_ASSERT(bt_ctf_field_type_common_get_type_id( event_class->common.payload_field_type) == - BT_FIELD_TYPE_ID_STRUCT); + BT_CTF_FIELD_TYPE_ID_STRUCT); name_quark = g_quark_try_string(name); if (!name_quark) { BT_LOGE("Cannot get GQuark: string=\"%s\"", name); @@ -327,7 +470,7 @@ int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class, struct metadata_context *context) { int ret = 0; - struct bt_value *attr_value = NULL; + struct bt_ctf_value *attr_value = NULL; BT_ASSERT(event_class); BT_ASSERT(context); @@ -347,12 +490,12 @@ int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class, g_string_append_printf(context->string, "\tid = %" PRId64 ";\n", event_class->common.id); g_string_append_printf(context->string, "\tstream_id = %" PRId64 ";\n", - bt_stream_class_common_get_id( - bt_event_class_common_borrow_stream_class( - BT_TO_COMMON(event_class)))); + bt_ctf_stream_class_common_get_id( + bt_ctf_event_class_common_borrow_stream_class( + BT_CTF_TO_COMMON(event_class)))); if (event_class->common.log_level != - BT_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED) { + BT_CTF_EVENT_CLASS_LOG_LEVEL_UNSPECIFIED) { g_string_append_printf(context->string, "\tloglevel = %d;\n", (int) event_class->common.log_level); } @@ -396,7 +539,7 @@ int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class, end: context->current_indentation_level = 0; - BT_PUT(attr_value); + BT_CTF_OBJECT_PUT_REF_AND_RESET(attr_value); return ret; } @@ -423,7 +566,7 @@ struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name( } BT_ASSERT(event_class->common.payload_field_type->id == - BT_FIELD_TYPE_ID_STRUCT); + BT_CTF_FIELD_TYPE_ID_STRUCT); name_quark = g_quark_try_string(name); if (!name_quark) { BT_LOGE("Cannot get GQuark: string=\"%s\"", name); @@ -434,8 +577,8 @@ struct bt_ctf_field_type *bt_ctf_event_class_get_field_by_name( * No need to increment field_type's reference count since getting it * from the structure already does. */ - field_type = bt_get( - bt_field_type_common_structure_borrow_field_type_by_name( + field_type = bt_ctf_object_get_ref( + bt_ctf_field_type_common_structure_borrow_field_type_by_name( event_class->common.payload_field_type, name)); end: