struct ctf_stream_class *stream_class = stream->stream_class;
struct ctf_event *event_class;
uint64_t id = 0;
- int len_index;
int ret;
if (pos->offset == EOF)
/* Read event header */
if (stream_class->event_header) {
+ struct definition_integer *integer_definition;
+
ret = generic_rw(ppos, &stream_class->event_header->p);
if (ret)
goto error;
/* lookup event id */
- len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl,
- g_quark_from_static_string("id"));
- if (len_index >= 0) {
- struct definition_integer *defint;
- struct definition *field;
+ integer_definition = lookup_integer(&stream_class->event_header->p, "id", FALSE);
+ if (integer_definition) {
+ id = integer_definition->value._unsigned;
+ } else {
+ struct definition_enum *enum_definition;
- field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
- assert(field->declaration->id == CTF_TYPE_INTEGER);
- defint = container_of(field, struct definition_integer, p);
- assert(defint->declaration->signedness == FALSE);
- id = defint->value._unsigned; /* set id */
+ enum_definition = lookup_enum(&stream_class->event_header->p, "id", FALSE);
+ if (enum_definition) {
+ id = enum_definition->integer->value._unsigned;
+ }
}
/* lookup timestamp */
- len_index = struct_declaration_lookup_field_index(stream_class->event_header_decl,
- g_quark_from_static_string("timestamp"));
- if (len_index >= 0) {
- struct definition_integer *defint;
- struct definition *field;
+ integer_definition = lookup_integer(&stream_class->event_header->p, "timestamp", FALSE);
+ if (integer_definition) {
+ stream->timestamp = integer_definition->value._unsigned;
+ } else {
+ struct definition *definition;
- field = struct_definition_get_field_from_index(stream_class->event_header, len_index);
- assert(field->declaration->id == CTF_TYPE_INTEGER);
- defint = container_of(field, struct definition_integer, p);
- assert(defint->declaration->signedness == FALSE);
- /* update timestamp */
- stream->timestamp = defint->value._unsigned;
+ definition = lookup_variant(&stream_class->event_header->p, "v");
+ if (definition) {
+ integer_definition = lookup_integer(definition, "id", FALSE);
+ if (integer_definition) {
+ id = integer_definition->value._unsigned;
+ }
+ integer_definition = lookup_integer(definition, "timestamp", FALSE);
+ if (integer_definition) {
+ stream->timestamp = integer_definition->value._unsigned;
+ }
+ }
}
-
}
/* Read stream-declared event context */
}
event->context = container_of(definition,
struct definition_struct, p);
- parent_def_scope = event->context->scope;
+ parent_def_scope = event->context->p.scope;
}
if (event->fields_decl) {
struct definition *definition =
}
event->fields = container_of(definition,
struct definition_struct, p);
- parent_def_scope = event->fields->scope;
+ parent_def_scope = event->fields->p.scope;
}
return 0;
}
stream->packet_context = container_of(definition,
struct definition_struct, p);
- parent_def_scope = stream->packet_context->scope;
+ parent_def_scope = stream->packet_context->p.scope;
}
if (stream->event_header_decl) {
struct definition *definition =
}
stream->event_header =
container_of(definition, struct definition_struct, p);
- parent_def_scope = stream->event_header->scope;
+ parent_def_scope = stream->event_header->p.scope;
}
if (stream->event_context_decl) {
struct definition *definition =
}
stream->event_context =
container_of(definition, struct definition_struct, p);
- parent_def_scope = stream->event_context->scope;
+ parent_def_scope = stream->event_context->p.scope;
}
stream->definition_scope = parent_def_scope;
}
trace->packet_header =
container_of(definition, struct definition_struct, p);
- parent_def_scope = trace->packet_header->scope;
+ parent_def_scope = trace->packet_header->p.scope;
}
trace->definition_scope = parent_def_scope;
GQuark name; /* Field name in its container (or 0 if unset) */
int ref; /* number of references to the definition */
GQuark path;
+ struct definition_scope *scope;
};
typedef int (*rw_dispatch)(struct stream_pos *pos,
struct definition_integer *sign;
struct definition_integer *mantissa;
struct definition_integer *exp;
- struct definition_scope *scope;
/* Last values read */
long double value;
};
struct definition p;
struct definition_integer *integer;
struct declaration_enum *declaration;
- struct definition_scope *scope;
/* Last GQuark values read. Keeping a reference on the GQuark array. */
GArray *value;
};
struct definition_struct {
struct definition p;
struct declaration_struct *declaration;
- struct definition_scope *scope;
GPtrArray *fields; /* Array of pointers to struct definition */
};
struct definition_variant {
struct definition p;
struct declaration_variant *declaration;
- struct definition_scope *scope;
struct definition *enum_tag;
GPtrArray *fields; /* Array of pointers to struct definition */
struct definition *current_field; /* Last field read */
struct definition_array {
struct definition p;
struct declaration_array *declaration;
- struct definition_scope *scope;
GPtrArray *elems; /* Array of pointers to struct definition */
GString *string; /* String for encoded integer children */
};
struct definition_sequence {
struct definition p;
struct declaration_sequence *declaration;
- struct definition_scope *scope;
struct definition_integer *length;
GPtrArray *elems; /* Array of pointers to struct definition */
GString *string; /* String for encoded integer children */
* definition scopes.
*/
struct definition *
- lookup_definition(GArray *cur_path, /* array of GQuark */
- GArray *lookup_path, /* array of GQuark */
- struct definition_scope *scope);
+ lookup_path_definition(GArray *cur_path, /* array of GQuark */
+ GArray *lookup_path, /* array of GQuark */
+ struct definition_scope *scope);
int register_field_definition(GQuark field_name,
struct definition *definition,
struct definition_scope *scope);
*/
void append_scope_path(const char *path, GArray *q);
+/*
+ * Lookup helpers.
+ */
+struct definition_integer *lookup_integer(struct definition *definition,
+ const char *field_name,
+ int signedness);
+struct definition_enum *lookup_enum(struct definition *definition,
+ const char *field_name,
+ int signedness);
+struct definition *lookup_variant(struct definition *definition,
+ const char *field_name);
+
#endif /* _BABELTRACE_TYPES_H */
array->p.index = root_name ? INT_MAX : index;
array->p.name = field_name;
array->p.path = new_definition_path(parent_scope, field_name, root_name);
- array->scope = new_definition_scope(parent_scope, field_name, root_name);
+ array->p.scope = new_definition_scope(parent_scope, field_name, root_name);
ret = register_field_definition(field_name, &array->p,
parent_scope);
assert(!ret);
field = (struct definition **) &g_ptr_array_index(array->elems, i);
*field = array_declaration->elem->definition_new(array_declaration->elem,
- array->scope,
+ array->p.scope,
name, i, NULL);
if (!*field)
goto error;
field->declaration->definition_free(field);
}
(void) g_ptr_array_free(array->elems, TRUE);
- free_definition_scope(array->scope);
+ free_definition_scope(array->p.scope);
declaration_unref(array->p.declaration);
g_free(array);
return NULL;
}
(void) g_ptr_array_free(array->elems, TRUE);
}
- free_definition_scope(array->scope);
+ free_definition_scope(array->p.scope);
declaration_unref(array->p.declaration);
g_free(array);
}
_enum->p.index = root_name ? INT_MAX : index;
_enum->p.name = field_name;
_enum->p.path = new_definition_path(parent_scope, field_name, root_name);
- _enum->scope = new_definition_scope(parent_scope, field_name, root_name);
+ _enum->p.scope = new_definition_scope(parent_scope, field_name, root_name);
_enum->value = NULL;
ret = register_field_definition(field_name, &_enum->p,
parent_scope);
assert(!ret);
definition_integer_parent =
enum_declaration->integer_declaration->p.definition_new(&enum_declaration->integer_declaration->p,
- _enum->scope,
+ _enum->p.scope,
g_quark_from_static_string("container"), 0, NULL);
_enum->integer = container_of(definition_integer_parent,
struct definition_integer, p);
container_of(definition, struct definition_enum, p);
definition_unref(&_enum->integer->p);
+ free_definition_scope(_enum->p.scope);
declaration_unref(_enum->p.declaration);
if (_enum->value)
g_array_unref(_enum->value);
declaration_ref(&float_declaration->p);
_float->p.declaration = declaration;
_float->declaration = float_declaration;
- _float->scope = new_definition_scope(parent_scope, field_name, root_name);
+ _float->p.scope = new_definition_scope(parent_scope, field_name, root_name);
_float->p.path = new_definition_path(parent_scope, field_name, root_name);
if (float_declaration->byte_order == LITTLE_ENDIAN) {
tmp = float_declaration->mantissa->p.definition_new(&float_declaration->mantissa->p,
- _float->scope, g_quark_from_static_string("mantissa"), 0, NULL);
+ _float->p.scope, g_quark_from_static_string("mantissa"), 0, NULL);
_float->mantissa = container_of(tmp, struct definition_integer, p);
tmp = float_declaration->exp->p.definition_new(&float_declaration->exp->p,
- _float->scope, g_quark_from_static_string("exp"), 1, NULL);
+ _float->p.scope, g_quark_from_static_string("exp"), 1, NULL);
_float->exp = container_of(tmp, struct definition_integer, p);
tmp = float_declaration->sign->p.definition_new(&float_declaration->sign->p,
- _float->scope, g_quark_from_static_string("sign"), 2, NULL);
+ _float->p.scope, g_quark_from_static_string("sign"), 2, NULL);
_float->sign = container_of(tmp, struct definition_integer, p);
} else {
tmp = float_declaration->sign->p.definition_new(&float_declaration->sign->p,
- _float->scope, g_quark_from_static_string("sign"), 0, NULL);
+ _float->p.scope, g_quark_from_static_string("sign"), 0, NULL);
_float->sign = container_of(tmp, struct definition_integer, p);
tmp = float_declaration->exp->p.definition_new(&float_declaration->exp->p,
- _float->scope, g_quark_from_static_string("exp"), 1, NULL);
+ _float->p.scope, g_quark_from_static_string("exp"), 1, NULL);
_float->exp = container_of(tmp, struct definition_integer, p);
tmp = float_declaration->mantissa->p.definition_new(&float_declaration->mantissa->p,
- _float->scope, g_quark_from_static_string("mantissa"), 2, NULL);
+ _float->p.scope, g_quark_from_static_string("mantissa"), 2, NULL);
_float->mantissa = container_of(tmp, struct definition_integer, p);
}
_float->p.ref = 1;
definition_unref(&_float->sign->p);
definition_unref(&_float->exp->p);
definition_unref(&_float->mantissa->p);
+ free_definition_scope(_float->p.scope);
declaration_unref(_float->p.declaration);
g_free(_float);
}
integer->p.name = field_name;
integer->p.path = new_definition_path(parent_scope, field_name,
root_name);
+ integer->p.scope = NULL;
integer->value._unsigned = 0;
ret = register_field_definition(field_name, &integer->p,
parent_scope);
field = (struct definition **) &g_ptr_array_index(sequence_definition->elems, i);
*field = sequence_declaration->elem->definition_new(sequence_declaration->elem,
- sequence_definition->scope,
+ sequence_definition->p.scope,
name, i, NULL);
ret = generic_rw(pos, *field);
if (ret)
sequence->p.index = root_name ? INT_MAX : index;
sequence->p.name = field_name;
sequence->p.path = new_definition_path(parent_scope, field_name, root_name);
- sequence->scope = new_definition_scope(parent_scope, field_name, root_name);
+ sequence->p.scope = new_definition_scope(parent_scope, field_name, root_name);
ret = register_field_definition(field_name, &sequence->p,
parent_scope);
assert(!ret);
- len_parent = lookup_definition(sequence->scope->scope_path,
- sequence_declaration->length_name,
- parent_scope);
+ len_parent = lookup_path_definition(sequence->p.scope->scope_path,
+ sequence_declaration->length_name,
+ parent_scope);
if (!len_parent) {
printf("[error] Lookup for sequence length field failed.\n");
goto error;
return &sequence->p;
error:
- free_definition_scope(sequence->scope);
+ free_definition_scope(sequence->p.scope);
declaration_unref(&sequence_declaration->p);
g_free(sequence);
return NULL;
}
(void) g_ptr_array_free(sequence->elems, TRUE);
definition_unref(len_definition);
- free_definition_scope(sequence->scope);
+ free_definition_scope(sequence->p.scope);
declaration_unref(sequence->p.declaration);
g_free(sequence);
}
string->p.name = field_name;
string->p.path = new_definition_path(parent_scope, field_name,
root_name);
+ string->p.scope = NULL;
string->value = NULL;
string->len = 0;
string->alloc_len = 0;
_struct->p.index = root_name ? INT_MAX : index;
_struct->p.name = field_name;
_struct->p.path = new_definition_path(parent_scope, field_name, root_name);
- _struct->scope = new_definition_scope(parent_scope, field_name, root_name);
+ _struct->p.scope = new_definition_scope(parent_scope, field_name, root_name);
ret = register_field_definition(field_name, &_struct->p,
parent_scope);
(struct definition **) &g_ptr_array_index(_struct->fields, i);
*field = declaration_field->declaration->definition_new(declaration_field->declaration,
- _struct->scope,
+ _struct->p.scope,
declaration_field->name, i, NULL);
if (!*field)
goto error;
struct definition *field = g_ptr_array_index(_struct->fields, i);
definition_unref(field);
}
- free_definition_scope(_struct->scope);
+ free_definition_scope(_struct->p.scope);
declaration_unref(&struct_declaration->p);
g_free(_struct);
return NULL;
struct definition *field = g_ptr_array_index(_struct->fields, i);
definition_unref(field);
}
- free_definition_scope(_struct->scope);
+ free_definition_scope(_struct->p.scope);
declaration_unref(_struct->p.declaration);
g_free(_struct);
}
static struct definition_scope *
get_definition_scope(struct definition *definition)
{
- switch (definition->declaration->id) {
- case CTF_TYPE_STRUCT:
- {
- struct definition_struct *def =
- container_of(definition, struct definition_struct, p);
- return def->scope;
- }
- case CTF_TYPE_VARIANT:
- {
- struct definition_variant *def =
- container_of(definition, struct definition_variant, p);
- return def->scope;
- }
- case CTF_TYPE_ARRAY:
- {
- struct definition_array *def =
- container_of(definition, struct definition_array, p);
- return def->scope;
- }
- case CTF_TYPE_SEQUENCE:
- {
- struct definition_sequence *def =
- container_of(definition, struct definition_sequence, p);
- return def->scope;
- }
-
- case CTF_TYPE_INTEGER:
- case CTF_TYPE_FLOAT:
- case CTF_TYPE_ENUM:
- case CTF_TYPE_STRING:
- case CTF_TYPE_UNKNOWN:
- default:
- return NULL;
- }
+ return definition->scope;
}
/*
* scope: the definition scope containing the variant definition.
*/
struct definition *
- lookup_definition(GArray *cur_path,
- GArray *lookup_path,
- struct definition_scope *scope)
+ lookup_path_definition(GArray *cur_path,
+ GArray *lookup_path,
+ struct definition_scope *scope)
{
struct definition *definition, *lookup_definition;
GQuark last;
g_hash_table_destroy(scope->definitions);
g_free(scope);
}
+
+static
+struct definition *lookup_definition(struct definition *definition,
+ const char *field_name)
+{
+ struct definition_scope *scope = get_definition_scope(definition);
+
+ if (!scope)
+ return NULL;
+
+ return lookup_field_definition_scope(g_quark_from_string(field_name),
+ scope);
+}
+
+struct definition_integer *lookup_integer(struct definition *definition,
+ const char *field_name,
+ int signedness)
+{
+ struct definition *lookup;
+ struct definition_integer *lookup_integer;
+
+ lookup = lookup_definition(definition, field_name);
+ if (!lookup)
+ return NULL;
+ if (lookup->declaration->id != CTF_TYPE_INTEGER)
+ return NULL;
+ lookup_integer = container_of(lookup, struct definition_integer, p);
+ if (lookup_integer->declaration->signedness != signedness)
+ return NULL;
+ return lookup_integer;
+}
+
+struct definition_enum *lookup_enum(struct definition *definition,
+ const char *field_name,
+ int signedness)
+{
+ struct definition *lookup;
+ struct definition_enum *lookup_enum;
+
+ lookup = lookup_definition(definition, field_name);
+ if (!lookup)
+ return NULL;
+ if (lookup->declaration->id != CTF_TYPE_ENUM)
+ return NULL;
+ lookup_enum = container_of(lookup, struct definition_enum, p);
+ if (lookup_enum->integer->declaration->signedness != signedness)
+ return NULL;
+ return lookup_enum;
+}
+
+struct definition *lookup_variant(struct definition *definition,
+ const char *field_name)
+{
+ struct definition *lookup;
+ struct definition_variant *lookup_variant;
+
+ lookup = lookup_definition(definition, field_name);
+ if (!lookup)
+ return NULL;
+ if (lookup->declaration->id != CTF_TYPE_VARIANT)
+ return NULL;
+ lookup_variant = container_of(lookup, struct definition_variant, p);
+ lookup = variant_get_current_field(lookup_variant);
+ assert(lookup);
+ return lookup;
+}
variant->p.index = root_name ? INT_MAX : index;
variant->p.name = field_name;
variant->p.path = new_definition_path(parent_scope, field_name, root_name);
- variant->scope = new_definition_scope(parent_scope, field_name, root_name);
+ variant->p.scope = new_definition_scope(parent_scope, field_name, root_name);
ret = register_field_definition(field_name, &variant->p,
parent_scope);
assert(!ret);
- variant->enum_tag = lookup_definition(variant->scope->scope_path,
- variant_declaration->tag_name,
- parent_scope);
+ variant->enum_tag = lookup_path_definition(variant->p.scope->scope_path,
+ variant_declaration->tag_name,
+ parent_scope);
if (!variant->enum_tag
|| check_enum_tag(variant, variant->enum_tag) < 0)
* various choices of the same field.
*/
*field = declaration_field->declaration->definition_new(declaration_field->declaration,
- variant->scope,
+ variant->p.scope,
declaration_field->name, 0, NULL);
if (!*field)
goto error;
variant->current_field = NULL;
return &variant->p;
error:
- free_definition_scope(variant->scope);
+ free_definition_scope(variant->p.scope);
declaration_unref(&variant_declaration->p);
g_free(variant);
return NULL;
definition_unref(field);
}
definition_unref(variant->enum_tag);
- free_definition_scope(variant->scope);
+ free_definition_scope(variant->p.scope);
declaration_unref(variant->p.declaration);
g_free(variant);
}