def = lookup_definition(scope, field_underscore);
g_free(field_underscore);
}
- if (bt_ctf_field_type(def) == CTF_TYPE_VARIANT) {
+ if (bt_ctf_field_type(bt_ctf_get_field_decl(def)) == CTF_TYPE_VARIANT) {
struct definition_variant *variant_definition;
variant_definition = container_of(def,
struct definition_variant, p);
if (!ctf_event || !field)
return NULL;
- if (bt_ctf_field_type(field) == CTF_TYPE_ARRAY) {
+ if (bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_ARRAY) {
struct definition_array *array_definition;
array_definition = container_of(field,
struct definition_array, p);
ret = array_index(array_definition, index);
- } else if (bt_ctf_field_type(field) == CTF_TYPE_SEQUENCE) {
+ } else if (bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_SEQUENCE) {
struct definition_sequence *sequence_definition;
sequence_definition = container_of(field,
struct definition_sequence, p);
return rem_(g_quark_to_string(def->name));
}
-enum ctf_type_id bt_ctf_field_type(const struct definition *def)
+enum ctf_type_id bt_ctf_field_type(const struct declaration *decl)
{
- if (!def)
+ if (!decl)
return CTF_TYPE_UNKNOWN;
- return def->declaration->id;
+ return decl->id;
}
int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event,
if (!ctf_event || !scope || !list || !count)
return -EINVAL;
- switch (bt_ctf_field_type(scope)) {
+ switch (bt_ctf_field_type(bt_ctf_get_field_decl(scope))) {
case CTF_TYPE_INTEGER:
case CTF_TYPE_FLOAT:
case CTF_TYPE_STRING:
return ret;
}
-int bt_ctf_get_int_signedness(const struct definition *field)
+static struct declaration_integer *get_declaration_integer(const struct declaration *decl)
+{
+ struct declaration_field *field_decl;
+ struct declaration_integer *ret = NULL;
+
+ if (decl && bt_ctf_field_type(decl) == CTF_TYPE_INTEGER) {
+ field_decl = (struct declaration_field *) decl;
+ ret = ((struct declaration_integer *) field_decl->declaration);
+ }
+
+ return ret;
+}
+
+static struct declaration_string *get_declaration_string(const struct declaration *decl)
+{
+ struct declaration_field *field_decl;
+ struct declaration_string *ret = NULL;
+
+ if (decl && bt_ctf_field_type(decl) == CTF_TYPE_STRING) {
+ field_decl = (struct declaration_field *) decl;
+ ret = ((struct declaration_string *) field_decl->declaration);
+ }
+
+ return ret;
+}
+
+static struct declaration_array *get_declaration_array(const struct declaration *decl)
+{
+ struct declaration_field *field_decl;
+ struct declaration_array *ret = NULL;
+
+ if (decl && bt_ctf_field_type(decl) == CTF_TYPE_ARRAY) {
+ field_decl = (struct declaration_field *) decl;
+ ret = ((struct declaration_array *) field_decl->declaration);
+ }
+
+ return ret;
+}
+
+int bt_ctf_get_int_signedness(const struct declaration *decl)
{
int ret;
+ struct declaration_integer *integer;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
- ret = get_int_signedness(field);
+ integer = get_declaration_integer(decl);
+ if (integer) {
+ ret = integer->signedness;
} else {
ret = -EINVAL;
bt_ctf_field_set_error(-EINVAL);
return ret;
}
-int bt_ctf_get_int_base(const struct definition *field)
+int bt_ctf_get_int_base(const struct declaration *decl)
{
int ret;
+ struct declaration_integer *integer;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
- ret = get_int_base(field);
+ integer = get_declaration_integer(decl);
+ if (integer) {
+ ret = integer->base;
} else {
ret = -EINVAL;
bt_ctf_field_set_error(-EINVAL);
return ret;
}
-int bt_ctf_get_int_byte_order(const struct definition *field)
+int bt_ctf_get_int_byte_order(const struct declaration *decl)
{
int ret;
+ struct declaration_integer *integer;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
- ret = get_int_byte_order(field);
+ integer = get_declaration_integer(decl);
+ if (integer) {
+ ret = integer->byte_order;
} else {
ret = -EINVAL;
bt_ctf_field_set_error(-EINVAL);
return ret;
}
-ssize_t bt_ctf_get_int_len(const struct definition *field)
+ssize_t bt_ctf_get_int_len(const struct declaration *decl)
{
ssize_t ret;
+ struct declaration_integer *integer;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
- ret = (ssize_t) get_int_len(field);
+ integer = get_declaration_integer(decl);
+ if (integer) {
+ ret = (ssize_t) integer->len;
} else {
ret = -EINVAL;
bt_ctf_field_set_error(-EINVAL);
{
struct definition_enum *def_enum;
- if (!field || bt_ctf_field_type(field) != CTF_TYPE_ENUM) {
+ if (!field || bt_ctf_field_type(bt_ctf_get_field_decl(field)) != CTF_TYPE_ENUM) {
bt_ctf_field_set_error(-EINVAL);
return NULL;
}
GArray *array;
const char *ret;
- if (!field || bt_ctf_field_type(field) != CTF_TYPE_ENUM) {
+ if (!field || bt_ctf_field_type(bt_ctf_get_field_decl(field)) != CTF_TYPE_ENUM) {
bt_ctf_field_set_error(-EINVAL);
return NULL;
}
return ret;
}
-enum ctf_string_encoding bt_ctf_get_encoding(const struct definition *field)
+enum ctf_string_encoding bt_ctf_get_encoding(const struct declaration *decl)
{
enum ctf_string_encoding ret = 0;
+ struct declaration_integer *integer;
+ struct declaration_string *string;
- if (!field)
+ if (!decl)
goto error;
- 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
+ if (bt_ctf_field_type(decl) == CTF_TYPE_INTEGER) {
+ integer = get_declaration_integer(decl);
+ if (integer) {
+ ret = integer->encoding;
+ } else {
+ goto error;
+ }
+ } else if (bt_ctf_field_type(decl) == CTF_TYPE_STRING) {
+ string = get_declaration_string(decl);
+ if (string) {
+ ret = string->encoding;
+ } else {
+ goto error;
+ }
+ } else {
goto error;
+ }
return ret;
error:
return -1;
}
-int bt_ctf_get_array_len(const struct definition *field)
+int bt_ctf_get_array_len(const struct declaration *decl)
{
int ret;
+ struct declaration_array *array;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_ARRAY) {
- ret = get_array_len(field);
+ if (decl && bt_ctf_field_type(decl) == CTF_TYPE_ARRAY) {
+ array = get_declaration_array(decl);
+ if (array) {
+ ret = array->len;
+ } else {
+ goto error;
+ }
} else {
- ret = -1;
- bt_ctf_field_set_error(-EINVAL);
+ goto error;
}
return ret;
+
+error:
+ bt_ctf_field_set_error(-EINVAL);
+ return -1;
}
uint64_t bt_ctf_get_uint64(const struct definition *field)
{
uint64_t ret = 0;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER)
+ if (field && bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_INTEGER)
ret = get_unsigned_int(field);
else
bt_ctf_field_set_error(-EINVAL);
{
int64_t ret = 0;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER)
+ if (field && bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_INTEGER)
ret = get_signed_int(field);
else
bt_ctf_field_set_error(-EINVAL);
char *ret = NULL;
GString *char_array;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_ARRAY) {
+ if (field && bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_ARRAY) {
char_array = get_char_array(field);
if (char_array) {
ret = char_array->str;
{
char *ret = NULL;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_STRING)
+ if (field && bt_ctf_field_type(bt_ctf_get_field_decl(field)) == CTF_TYPE_STRING)
ret = get_string(field);
else
bt_ctf_field_set_error(-EINVAL);
return rem_(g_quark_to_string(((struct declaration_field *) field)->name));
}
+
+const struct declaration *bt_ctf_get_field_decl(const struct definition *def)
+{
+ if (def)
+ return def->declaration;
+
+ return NULL;
+}
#endif
struct definition;
+struct declaration;
struct bt_ctf_event;
struct bt_ctf_event_decl;
struct bt_ctf_field_decl;
*/
const char *bt_ctf_field_name(const struct definition *def);
+/*
+ * bt_ctf_get_field_decl: return the declaration of a field or NULL
+ * on error
+ */
+const struct declaration *bt_ctf_get_field_decl(const struct definition *def);
+
/*
* bt_ctf_field_type: returns the type of a field or -1 if unknown
*/
-enum ctf_type_id bt_ctf_field_type(const struct definition *def);
+enum ctf_type_id bt_ctf_field_type(const struct declaration *decl);
/*
* bt_ctf_get_int_signedness: return the signedness of an integer
* return 1 if signed
* return -1 on error
*/
-int bt_ctf_get_int_signedness(const struct definition *field);
+int bt_ctf_get_int_signedness(const struct declaration *decl);
/*
* 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);
+int bt_ctf_get_int_base(const struct declaration *decl);
/*
* 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);
+int bt_ctf_get_int_byte_order(const struct declaration *decl);
/*
* bt_ctf_get_int_len: return the size, in bits, of an int or a negative
* value on error
*/
-ssize_t bt_ctf_get_int_len(const struct definition *field);
+ssize_t bt_ctf_get_int_len(const struct declaration *decl);
/*
* 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);
+enum ctf_string_encoding bt_ctf_get_encoding(const struct declaration *decl);
/*
* 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);
+int bt_ctf_get_array_len(const struct declaration *decl);
/*
* Field access functions