* Julien Desfossez ([email protected]) wrote: > Three helper functions to ease the extraction of basic types from event > fields. For now we support signed and unsigned integers and strings. > Other functions could be added following the same principle for other > types.
FYI, I already started cleaning up ctf.c using these functions. Thanks! Mathieu > > Signed-off-by: Julien Desfossez <[email protected]> > --- > include/babeltrace/types.h | 3 +++ > types/array.c | 27 +++++++++++++++++++++++++++ > types/integer.c | 30 ++++++++++++++++++++++++++++++ > 3 files changed, 60 insertions(+), 0 deletions(-) > > diff --git a/include/babeltrace/types.h b/include/babeltrace/types.h > index a9fb5fe..62a0d4f 100644 > --- a/include/babeltrace/types.h > +++ b/include/babeltrace/types.h > @@ -383,6 +383,8 @@ void definition_unref(struct definition *definition); > struct declaration_integer *integer_declaration_new(size_t len, int > byte_order, > int signedness, size_t alignment, > int base, enum ctf_string_encoding encoding); > +uint64_t get_unsigned_int(struct definition *field); > +int64_t get_signed_int(struct definition *field); > > /* > * mantissa_len is the length of the number of bytes represented by the > mantissa > @@ -493,6 +495,7 @@ struct declaration_array * > uint64_t array_len(struct definition_array *array); > struct definition *array_index(struct definition_array *array, uint64_t i); > int array_rw(struct stream_pos *pos, struct definition *definition); > +GString *get_char_array(struct definition *field); > > /* > * int_declaration and elem_declaration passed as parameter now belong > diff --git a/types/array.c b/types/array.c > index db6853f..87b2083 100644 > --- a/types/array.c > +++ b/types/array.c > @@ -205,3 +205,30 @@ struct definition *array_index(struct definition_array > *array, uint64_t i) > return NULL; > return g_ptr_array_index(array->elems, i); > } > + > +GString *get_char_array(struct definition *field) > +{ > + struct definition_array *array_definition; > + struct declaration_array *array_declaration; > + struct declaration *elem; > + > + array_definition = container_of(field, struct definition_array, p); > + array_declaration = array_definition->declaration; > + elem = array_declaration->elem; > + if (elem->id == CTF_TYPE_INTEGER) { > + struct declaration_integer *integer_declaration = > + container_of(elem, struct declaration_integer, p); > + > + if (integer_declaration->encoding == CTF_STRING_UTF8 > + || integer_declaration->encoding == > CTF_STRING_ASCII) { > + > + if (integer_declaration->len == CHAR_BIT > + && integer_declaration->p.alignment == > CHAR_BIT) { > + > + return array_definition->string; > + } > + } > + } > + fprintf(stderr, "[warning] Extracting string\n"); > + return NULL; > +} > diff --git a/types/integer.c b/types/integer.c > index e55c03e..9e6df58 100644 > --- a/types/integer.c > +++ b/types/integer.c > @@ -103,3 +103,33 @@ void _integer_definition_free(struct definition > *definition) > declaration_unref(integer->p.declaration); > g_free(integer); > } > + > +uint64_t get_unsigned_int(struct definition *field) > +{ > + struct definition_integer *integer_definition; > + const struct declaration_integer *integer_declaration; > + > + integer_definition = container_of(field, struct definition_integer, p); > + integer_declaration = integer_definition->declaration; > + > + if (!integer_declaration->signedness) { > + return integer_definition->value._unsigned; > + } > + fprintf(stderr, "[warning] Extracting unsigned value in a signed > int\n"); > + return (uint64_t)integer_definition->value._signed; > +} > + > +int64_t get_signed_int(struct definition *field) > +{ > + struct definition_integer *integer_definition; > + const struct declaration_integer *integer_declaration; > + > + integer_definition = container_of(field, struct definition_integer, p); > + integer_declaration = integer_definition->declaration; > + > + if (integer_declaration->signedness) { > + return integer_definition->value._signed; > + } > + fprintf(stderr, "[warning] Extracting signed value in an unsigned > int\n"); > + return (int64_t)integer_definition->value._unsigned; > +} > -- > 1.7.5.4 > -- Mathieu Desnoyers Operating System Efficiency R&D Consultant EfficiOS Inc. http://www.efficios.com _______________________________________________ ltt-dev mailing list [email protected] http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
