X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fevents.c;h=ebc4f1b057143d046ccee603b11e5da2eafabdd7;hp=5ac74e6e1617cff6961713498d7cb21cff282033;hb=04ae3991741c634481fc3fa069664ae28bbdbaa6;hpb=5c5facc70af60670ec8f53b9d90d13722a8477f4 diff --git a/formats/ctf/events.c b/formats/ctf/events.c index 5ac74e6e..ebc4f1b0 100644 --- a/formats/ctf/events.c +++ b/formats/ctf/events.c @@ -23,8 +23,14 @@ #include #include #include +#include +#include +#include +#include #include +#include "events-private.h" + /* * thread local storage to store the last error that occured * while reading a field, this variable must be accessed by @@ -32,7 +38,7 @@ */ __thread int bt_ctf_last_field_error = 0; -struct definition *bt_ctf_get_top_level_scope(struct bt_ctf_event *event, +const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *event, enum bt_ctf_scope scope) { struct definition *tmp = NULL; @@ -81,14 +87,26 @@ error: return NULL; } -struct definition *bt_ctf_get_field(struct bt_ctf_event *event, - struct definition *scope, +const struct definition *bt_ctf_get_field(const struct bt_ctf_event *event, + const struct definition *scope, const char *field) { struct definition *def; + char *field_underscore; if (scope) { def = lookup_definition(scope, field); + /* + * optionally a field can have an underscore prefix, try + * to lookup the field with this prefix if it failed + */ + if (!def) { + field_underscore = g_new(char, strlen(field) + 2); + field_underscore[0] = '_'; + strcpy(&field_underscore[1], field); + def = lookup_definition(scope, field_underscore); + g_free(field_underscore); + } if (bt_ctf_field_type(def) == CTF_TYPE_VARIANT) { struct definition_variant *variant_definition; variant_definition = container_of(def, @@ -100,8 +118,8 @@ struct definition *bt_ctf_get_field(struct bt_ctf_event *event, return NULL; } -struct definition *bt_ctf_get_index(struct bt_ctf_event *event, - struct definition *field, +const struct definition *bt_ctf_get_index(const struct bt_ctf_event *event, + const struct definition *field, unsigned int index) { struct definition *ret = NULL; @@ -120,7 +138,7 @@ struct definition *bt_ctf_get_index(struct bt_ctf_event *event, return ret; } -const char *bt_ctf_event_name(struct bt_ctf_event *event) +const char *bt_ctf_event_name(const struct bt_ctf_event *event) { struct ctf_event *event_class; struct ctf_stream_class *stream_class; @@ -136,19 +154,19 @@ const char *bt_ctf_event_name(struct bt_ctf_event *event) const char *bt_ctf_field_name(const struct definition *def) { if (def) - return g_quark_to_string(def->name); + return rem_(g_quark_to_string(def->name)); return NULL; } -enum ctf_type_id bt_ctf_field_type(struct definition *def) +enum ctf_type_id bt_ctf_field_type(const struct definition *def) { if (def) return def->declaration->id; return CTF_TYPE_UNKNOWN; } -int bt_ctf_get_field_list(struct bt_ctf_event *event, - struct definition *scope, +int bt_ctf_get_field_list(const struct bt_ctf_event *event, + const struct definition *scope, struct definition const * const **list, unsigned int *count) { @@ -160,9 +178,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, goto error; case CTF_TYPE_STRUCT: { - struct definition_struct *def_struct; + const struct definition_struct *def_struct; - def_struct = container_of(scope, struct definition_struct, p); + def_struct = container_of(scope, const struct definition_struct, p); if (!def_struct) goto error; if (def_struct->fields->pdata) { @@ -177,9 +195,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, goto error; case CTF_TYPE_VARIANT: { - struct definition_variant *def_variant; + const struct definition_variant *def_variant; - def_variant = container_of(scope, struct definition_variant, p); + def_variant = container_of(scope, const struct definition_variant, p); if (!def_variant) goto error; if (def_variant->fields->pdata) { @@ -192,9 +210,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, } case CTF_TYPE_ARRAY: { - struct definition_array *def_array; + const struct definition_array *def_array; - def_array = container_of(scope, struct definition_array, p); + def_array = container_of(scope, const struct definition_array, p); if (!def_array) goto error; if (def_array->elems->pdata) { @@ -207,9 +225,9 @@ int bt_ctf_get_field_list(struct bt_ctf_event *event, } case CTF_TYPE_SEQUENCE: { - struct definition_sequence *def_sequence; + const struct definition_sequence *def_sequence; - def_sequence = container_of(scope, struct definition_sequence, p); + def_sequence = container_of(scope, const struct definition_sequence, p); if (!def_sequence) goto error; if (def_sequence->elems->pdata) { @@ -233,12 +251,22 @@ error: return -1; } -uint64_t bt_ctf_get_timestamp(struct bt_ctf_event *event) +uint64_t bt_ctf_get_timestamp_raw(const struct bt_ctf_event *event) +{ + if (event && event->stream->has_timestamp) + return ctf_get_timestamp_raw(event->stream, + event->stream->timestamp); + else + return -1ULL; +} + +uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *event) { if (event && event->stream->has_timestamp) - return event->stream->timestamp; + return ctf_get_timestamp(event->stream, + event->stream->timestamp); else - return 0; + return -1ULL; } static void bt_ctf_field_set_error(int error) @@ -255,7 +283,85 @@ int bt_ctf_field_get_error(void) return ret; } -uint64_t bt_ctf_get_uint64(struct definition *field) +int bt_ctf_get_int_signedness(const struct definition *field) +{ + int ret; + + if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) { + ret = get_int_signedness(field); + } else { + ret = -1; + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + +int bt_ctf_get_int_base(const struct definition *field) +{ + int ret; + + if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) { + ret = get_int_base(field); + } else { + ret = -1; + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + +int bt_ctf_get_int_byte_order(const struct definition *field) +{ + int ret; + + if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) { + ret = get_int_byte_order(field); + } else { + ret = -1; + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + +enum ctf_string_encoding bt_ctf_get_encoding(const struct definition *field) +{ + enum ctf_string_encoding ret = 0; + + if (!field) + goto end; + + if (bt_ctf_field_type(field) == CTF_TYPE_INTEGER) + ret = get_int_encoding(field); + else if (bt_ctf_field_type(field) == CTF_TYPE_STRING) + ret = get_string_encoding(field); + else + goto error; + +end: + return ret; + +error: + bt_ctf_field_set_error(-EINVAL); + return -1; +} + +int bt_ctf_get_array_len(const struct definition *field) +{ + int ret; + + if (field && bt_ctf_field_type(field) == CTF_TYPE_ARRAY) { + ret = get_array_len(field); + } else { + ret = -1; + bt_ctf_field_set_error(-EINVAL); + } + + return ret; +} + +uint64_t bt_ctf_get_uint64(const struct definition *field) { unsigned int ret = 0; @@ -267,7 +373,7 @@ uint64_t bt_ctf_get_uint64(struct definition *field) return ret; } -int64_t bt_ctf_get_int64(struct definition *field) +int64_t bt_ctf_get_int64(const struct definition *field) { int ret = 0; @@ -280,7 +386,7 @@ int64_t bt_ctf_get_int64(struct definition *field) } -char *bt_ctf_get_char_array(struct definition *field) +char *bt_ctf_get_char_array(const struct definition *field) { char *ret = NULL; @@ -292,7 +398,7 @@ char *bt_ctf_get_char_array(struct definition *field) return ret; } -char *bt_ctf_get_string(struct definition *field) +char *bt_ctf_get_string(const struct definition *field) { char *ret = NULL;