Fix API : functions to access fields properties
authorJulien Desfossez <julien.desfossez@efficios.com>
Thu, 1 Mar 2012 14:10:50 +0000 (09:10 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 1 Mar 2012 14:10:50 +0000 (09:10 -0500)
Add the ability to know :
- the signedness of an int
- the base of an int
- the encoding of an int
- the len of an array
- the encoding of a string

refs #139

Signed-off-by: Julien Desfossez <julien.desfossez@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
formats/ctf/events.c
include/babeltrace/ctf/events.h
include/babeltrace/types.h
types/array.c
types/integer.c
types/string.c

index 39620383879b3aae0076bb9aedf710e2d9c88d22..eea58cfd796ffeec39d13c381d4216dcb4128c14 100644 (file)
@@ -351,6 +351,84 @@ int bt_ctf_field_get_error(void)
        return ret;
 }
 
+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;
index 01ee7a99dbd35c97d1ee2dd6119a67736719ea57..a08518b8a0e0aad7cc29485a283508816d4626e4 100644 (file)
@@ -60,6 +60,16 @@ enum ctf_type_id {
        NR_CTF_TYPES,
 };
 
+/*
+ * the supported CTF string encodings
+ */
+enum ctf_string_encoding {
+       CTF_STRING_NONE = 0,
+       CTF_STRING_UTF8,
+       CTF_STRING_ASCII,
+       CTF_STRING_UNKNOWN,
+};
+
 /*
  * the structure to manipulate events
  */
@@ -169,6 +179,38 @@ const char *bt_ctf_field_name(const struct definition *def);
  */
 enum ctf_type_id bt_ctf_field_type(const struct definition *def);
 
+/*
+ * bt_ctf_get_int_signedness: return the signedness of an integer
+ *
+ * return 0 if unsigned
+ * return 1 if signed
+ * return -1 on error
+ */
+int bt_ctf_get_int_signedness(const struct definition *field);
+
+/*
+ * bt_ctf_get_int_base: return the base of an int or a negative value on error
+ */
+int bt_ctf_get_int_base(const struct definition *field);
+
+/*
+ * bt_ctf_get_int_byte_order: return the byte order of an int or a negative
+ * value on error
+ */
+int bt_ctf_get_int_byte_order(const struct definition *field);
+
+/*
+ * bt_ctf_get_encoding: return the encoding of an int or a string.
+ * return a negative value on error
+ */
+enum ctf_string_encoding bt_ctf_get_encoding(const struct definition *field);
+
+/*
+ * bt_ctf_get_array_len: return the len of an array or a negative
+ * value on error
+ */
+int bt_ctf_get_array_len(const struct definition *field);
+
 /*
  * Field access functions
  *
index ad2b42d0a92d7d020ff8ab17f36a88b605122ff7..cfc74a2f6206c72cfb3805bf139b81dbd0dba719 100644 (file)
@@ -120,13 +120,6 @@ int generic_rw(struct stream_pos *pos, struct definition *definition)
        return call(pos, definition);
 }
 
-enum ctf_string_encoding {
-       CTF_STRING_NONE = 0,
-       CTF_STRING_UTF8,
-       CTF_STRING_ASCII,
-       CTF_STRING_UNKNOWN,
-};
-
 /*
  * Because we address in bits, bitfields end up being exactly the same as
  * integers, except that their read/write functions must be able to deal with
@@ -375,6 +368,10 @@ struct declaration_integer *integer_declaration_new(size_t len, int byte_order,
                                  struct ctf_clock *clock);
 uint64_t get_unsigned_int(const struct definition *field);
 int64_t get_signed_int(const struct definition *field);
+int get_int_signedness(const struct definition *field);
+int get_int_byte_order(const struct definition *field);
+int get_int_base(const struct definition *field);
+enum ctf_string_encoding get_int_encoding(const struct definition *field);
 
 /*
  * mantissa_len is the length of the number of bytes represented by the mantissa
@@ -422,6 +419,7 @@ struct declaration_enum *
 struct declaration_string *
        string_declaration_new(enum ctf_string_encoding encoding);
 char *get_string(const struct definition *field);
+enum ctf_string_encoding get_string_encoding(const struct definition *field);
 
 struct declaration_struct *
        struct_declaration_new(struct declaration_scope *parent_scope,
@@ -487,6 +485,7 @@ 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(const struct definition *field);
+int get_array_len(const struct definition *field);
 
 /*
  * int_declaration and elem_declaration passed as parameter now belong
index dbdcb4be8efd2161e8df6bcc42a3db2711db489c..047adac21902c7d7f438fc14a1e55099181280f1 100644 (file)
@@ -207,6 +207,17 @@ struct definition *array_index(struct definition_array *array, uint64_t i)
        return g_ptr_array_index(array->elems, i);
 }
 
+int get_array_len(const struct definition *field)
+{
+       struct definition_array *array_definition;
+       struct declaration_array *array_declaration;
+
+       array_definition = container_of(field, struct definition_array, p);
+       array_declaration = array_definition->declaration;
+
+       return array_declaration->len;
+}
+
 GString *get_char_array(const struct definition *field)
 {
        struct definition_array *array_definition;
index 6e1243059b51ce533d598d1b8ed5652598c22571..808a4893680d3dc302a62d93f9b400299da9cffd 100644 (file)
@@ -107,6 +107,50 @@ void _integer_definition_free(struct definition *definition)
        g_free(integer);
 }
 
+enum ctf_string_encoding get_int_encoding(const 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;
+
+       return integer_declaration->encoding;
+}
+
+int get_int_base(const 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;
+
+       return integer_declaration->base;
+}
+
+int get_int_byte_order(const 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;
+
+       return integer_declaration->byte_order;
+}
+
+int get_int_signedness(const 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;
+
+       return integer_declaration->signedness;
+}
+
 uint64_t get_unsigned_int(const struct definition *field)
 {
        struct definition_integer *integer_definition;
index dadcd080e71fc69cd7ae5b704b13d45014121940..daaeef5aa7514f00762e08b9cb79835663647645 100644 (file)
@@ -101,6 +101,17 @@ void _string_definition_free(struct definition *definition)
        g_free(string);
 }
 
+enum ctf_string_encoding get_string_encoding(const struct definition *field)
+{
+       struct definition_string *string_definition;
+       const struct declaration_string *string_declaration;
+
+       string_definition = container_of(field, struct definition_string, p);
+       string_declaration = string_definition->declaration;
+
+       return string_declaration->encoding;
+}
+
 char *get_string(const struct definition *field)
 {
        struct definition_string *string_definition =
This page took 0.029835 seconds and 4 git commands to generate.