*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
*/
#include <babeltrace/babeltrace.h>
/*
* thread local storage to store the last error that occured
* while reading a field, this variable must be accessed by
- * bt_ctf_field_error only
+ * bt_ctf_field_get_error only
*/
__thread int bt_ctf_last_field_error = 0;
-const struct definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
+const struct bt_definition *bt_ctf_get_top_level_scope(const struct bt_ctf_event *ctf_event,
enum bt_ctf_scope scope)
{
- struct definition *tmp = NULL;
- struct ctf_event_definition *event = ctf_event->parent;
+ const struct bt_definition *tmp = NULL;
+ const struct ctf_event_definition *event;
+
+ if (!ctf_event)
+ return NULL;
+ event = ctf_event->parent;
switch (scope) {
case BT_TRACE_PACKET_HEADER:
if (!event->stream)
return NULL;
}
-const struct definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
- const struct definition *scope,
+const struct bt_definition *bt_ctf_get_field(const struct bt_ctf_event *ctf_event,
+ const struct bt_definition *scope,
const char *field)
{
- struct definition *def;
+ const struct bt_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,
- struct definition_variant, p);
- return variant_definition->current_field;
- }
- return def;
+ if (!ctf_event || !scope || !field)
+ return NULL;
+
+ def = bt_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 = bt_lookup_definition(scope, field_underscore);
+ g_free(field_underscore);
}
- return NULL;
+ if (bt_ctf_field_type(bt_ctf_get_decl_from_def(def)) == CTF_TYPE_VARIANT) {
+ const struct definition_variant *variant_definition;
+ variant_definition = container_of(def,
+ const struct definition_variant, p);
+ return variant_definition->current_field;
+ }
+ return def;
}
-const struct definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
- const struct definition *field,
+const struct bt_definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
+ const struct bt_definition *field,
unsigned int index)
{
- struct definition *ret = NULL;
+ struct bt_definition *ret = NULL;
+
+ if (!ctf_event || !field)
+ return NULL;
- if (bt_ctf_field_type(field) == CTF_TYPE_ARRAY) {
+ if (bt_ctf_field_type(bt_ctf_get_decl_from_def(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) {
+ ret = bt_array_index(array_definition, index);
+ } else if (bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_SEQUENCE) {
struct definition_sequence *sequence_definition;
sequence_definition = container_of(field,
struct definition_sequence, p);
- ret = sequence_index(sequence_definition, index);
+ ret = bt_sequence_index(sequence_definition, index);
}
return ret;
}
const char *bt_ctf_event_name(const struct bt_ctf_event *ctf_event)
{
- struct ctf_event_declaration *event_class;
- struct ctf_stream_declaration *stream_class;
- struct ctf_event_definition *event = ctf_event->parent;
+ const struct ctf_event_declaration *event_class;
+ const struct ctf_stream_declaration *stream_class;
+ const struct ctf_event_definition *event;
- if (!event)
+ if (!ctf_event)
return NULL;
+
+ event = ctf_event->parent;
stream_class = event->stream->stream_class;
event_class = g_ptr_array_index(stream_class->events_by_id,
event->stream->event_id);
return g_quark_to_string(event_class->name);
}
-const char *bt_ctf_field_name(const struct definition *def)
+const char *bt_ctf_field_name(const struct bt_definition *def)
{
- if (def)
- return rem_(g_quark_to_string(def->name));
- return NULL;
+ if (!def || !def->name)
+ return NULL;
+
+ 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 bt_declaration *decl)
{
- if (def)
- return def->declaration->id;
- return CTF_TYPE_UNKNOWN;
+ if (!decl)
+ return CTF_TYPE_UNKNOWN;
+
+ return decl->id;
}
int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event,
- const struct definition *scope,
- struct definition const * const **list,
+ const struct bt_definition *scope,
+ struct bt_definition const * const **list,
unsigned int *count)
{
- switch (bt_ctf_field_type(scope)) {
+ if (!ctf_event || !scope || !list || !count)
+ return -EINVAL;
+
+ switch (bt_ctf_field_type(bt_ctf_get_decl_from_def(scope))) {
case CTF_TYPE_INTEGER:
case CTF_TYPE_FLOAT:
case CTF_TYPE_STRING:
if (!def_struct)
goto error;
if (def_struct->fields->pdata) {
- *list = (struct definition const* const*) def_struct->fields->pdata;
+ *list = (struct bt_definition const* const*) def_struct->fields->pdata;
*count = def_struct->fields->len;
goto end;
} else {
goto error;
}
+ break;
}
case CTF_TYPE_UNTAGGED_VARIANT:
goto error;
if (!def_variant)
goto error;
if (def_variant->fields->pdata) {
- *list = (struct definition const* const*) def_variant->fields->pdata;
+ *list = (struct bt_definition const* const*) def_variant->fields->pdata;
*count = def_variant->fields->len;
goto end;
} else {
goto error;
}
+ break;
}
case CTF_TYPE_ARRAY:
{
if (!def_array)
goto error;
if (def_array->elems->pdata) {
- *list = (struct definition const* const*) def_array->elems->pdata;
+ *list = (struct bt_definition const* const*) def_array->elems->pdata;
*count = def_array->elems->len;
goto end;
} else {
goto error;
}
+ break;
}
case CTF_TYPE_SEQUENCE:
{
if (!def_sequence)
goto error;
if (def_sequence->elems->pdata) {
- *list = (struct definition const* const*) def_sequence->elems->pdata;
- *count = def_sequence->elems->len;
+ *list = (struct bt_definition const* const*) def_sequence->elems->pdata;
+ *count = (unsigned int) def_sequence->length->value._unsigned;
goto end;
} else {
goto error;
}
+ break;
}
default:
break;
struct bt_context *bt_ctf_event_get_context(const struct bt_ctf_event *ctf_event)
{
struct bt_context *ret = NULL;
- struct ctf_file_stream *cfs;
- struct ctf_trace *trace;
- struct ctf_event_definition *event = ctf_event->parent;
+ const struct ctf_file_stream *cfs;
+ const struct ctf_trace *trace;
+ const struct ctf_event_definition *event;
- cfs = container_of(event->stream, struct ctf_file_stream,
+ if (!ctf_event)
+ return NULL;
+
+ event = ctf_event->parent;
+ cfs = container_of(event->stream, const struct ctf_file_stream,
parent);
trace = cfs->parent.stream_class->trace;
- if (trace->ctx)
- ret = trace->ctx;
+ if (trace->parent.ctx)
+ ret = trace->parent.ctx;
return ret;
}
int bt_ctf_event_get_handle_id(const struct bt_ctf_event *ctf_event)
{
int ret = -1;
- struct ctf_file_stream *cfs;
- struct ctf_trace *trace;
- struct ctf_event_definition *event = ctf_event->parent;
+ const struct ctf_file_stream *cfs;
+ const struct ctf_trace *trace;
+ const struct ctf_event_definition *event;
- cfs = container_of(event->stream, struct ctf_file_stream,
+ if (!ctf_event)
+ return -EINVAL;
+
+ event = ctf_event->parent;
+ cfs = container_of(event->stream, const struct ctf_file_stream,
parent);
trace = cfs->parent.stream_class->trace;
- if (trace->handle)
- ret = trace->handle->id;
+ if (trace->parent.handle)
+ ret = trace->parent.handle->id;
return ret;
}
-uint64_t bt_ctf_get_timestamp_raw(const struct bt_ctf_event *ctf_event)
+uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event)
{
- struct ctf_event_definition *event = ctf_event->parent;
+ const struct ctf_event_definition *event;
+
+ if (!ctf_event)
+ return -1ULL;
+
+ event = ctf_event->parent;
if (event && event->stream->has_timestamp)
- return ctf_get_timestamp_raw(event->stream,
- event->stream->timestamp);
+ return event->stream->real_timestamp;
else
return -1ULL;
}
-uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event)
+uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event)
{
- struct ctf_event_definition *event = ctf_event->parent;
+ const struct ctf_event_definition *event;
+
+ if (!ctf_event)
+ return -1ULL;
+
+ event = ctf_event->parent;
if (event && event->stream->has_timestamp)
- return ctf_get_timestamp(event->stream,
- event->stream->timestamp);
+ return event->stream->cycles_timestamp;
else
return -1ULL;
}
return ret;
}
-int bt_ctf_get_int_signedness(const struct definition *field)
+static const struct declaration_integer *
+get_declaration_integer(const struct bt_declaration *decl)
{
- int ret;
+ if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_INTEGER)
+ return NULL;
+ return container_of(decl, const struct declaration_integer, p);
+}
- if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
- ret = get_int_signedness(field);
- } else {
- ret = -1;
+static const struct declaration_string *
+get_declaration_string(const struct bt_declaration *decl)
+{
+ if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_STRING)
+ return NULL;
+ return container_of(decl, const struct declaration_string, p);
+}
+
+static const struct declaration_array *
+get_declaration_array(const struct bt_declaration *decl)
+{
+ if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_ARRAY)
+ return NULL;
+ return container_of(decl, const struct declaration_array, p);
+}
+
+static const struct declaration_sequence *
+get_declaration_sequence(const struct bt_declaration *decl)
+{
+ if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_SEQUENCE)
+ return NULL;
+ return container_of(decl, const struct declaration_sequence, p);
+}
+
+int bt_ctf_get_int_signedness(const struct bt_declaration *decl)
+{
+ const struct declaration_integer *integer;
+
+ integer = get_declaration_integer(decl);
+ if (!integer) {
bt_ctf_field_set_error(-EINVAL);
+ return -EINVAL;
}
+ return integer->signedness;
+}
- return ret;
+int bt_ctf_get_int_base(const struct bt_declaration *decl)
+{
+ const struct declaration_integer *integer;
+
+ integer = get_declaration_integer(decl);
+ if (!integer) {
+ bt_ctf_field_set_error(-EINVAL);
+ return -EINVAL;
+ }
+ return integer->base;
}
-int bt_ctf_get_int_base(const struct definition *field)
+int bt_ctf_get_int_byte_order(const struct bt_declaration *decl)
{
- int ret;
+ const struct declaration_integer *integer;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
- ret = get_int_base(field);
- } else {
- ret = -1;
+ integer = get_declaration_integer(decl);
+ if (!integer) {
bt_ctf_field_set_error(-EINVAL);
+ return -EINVAL;
}
+ return integer->byte_order;
+}
- return ret;
+ssize_t bt_ctf_get_int_len(const struct bt_declaration *decl)
+{
+ const struct declaration_integer *integer;
+
+ integer = get_declaration_integer(decl);
+ if (!integer) {
+ bt_ctf_field_set_error(-EINVAL);
+ return -EINVAL;
+ }
+ return (ssize_t) integer->len;
}
-int bt_ctf_get_int_byte_order(const struct definition *field)
+const struct bt_definition *bt_ctf_get_enum_int(const struct bt_definition *field)
{
- int ret;
+ const struct definition_enum *def_enum;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
- ret = get_int_byte_order(field);
- } else {
- ret = -1;
+ if (!field || bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) != CTF_TYPE_ENUM) {
+ bt_ctf_field_set_error(-EINVAL);
+ return NULL;
+ }
+ def_enum = container_of(field, const struct definition_enum, p);
+ return &def_enum->integer->p;
+}
+
+const char *bt_ctf_get_enum_str(const struct bt_definition *field)
+{
+ const struct definition_enum *def_enum;
+ const struct declaration_enum *decl_enum;
+ GArray *array;
+ const char *ret;
+
+ if (!field || bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) != CTF_TYPE_ENUM) {
bt_ctf_field_set_error(-EINVAL);
+ return NULL;
+ }
+ def_enum = container_of(field, const struct definition_enum, p);
+ decl_enum = def_enum->declaration;
+ if (bt_get_int_signedness(&def_enum->integer->p)) {
+ array = bt_enum_int_to_quark_set(decl_enum,
+ bt_get_signed_int(&def_enum->integer->p));
+ } else {
+ array = bt_enum_uint_to_quark_set(decl_enum,
+ bt_get_unsigned_int(&def_enum->integer->p));
+ }
+ if (!array) {
+ bt_ctf_field_set_error(-ENOENT);
+ return NULL;
}
+ if (array->len == 0) {
+ g_array_unref(array);
+ bt_ctf_field_set_error(-ENOENT);
+ return NULL;
+ }
+ /* Return first string. Arbitrary choice. */
+ ret = g_quark_to_string(g_array_index(array, GQuark, 0));
+ g_array_unref(array);
return ret;
}
-enum ctf_string_encoding bt_ctf_get_encoding(const struct definition *field)
+enum ctf_string_encoding bt_ctf_get_encoding(const struct bt_declaration *decl)
{
enum ctf_string_encoding ret = 0;
+ enum ctf_type_id type;
+ const struct declaration_integer *integer;
+ const struct declaration_string *string;
+ const struct declaration_array *array;
+ const struct declaration_sequence *sequence;
- 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
+ if (!decl)
goto error;
-end:
+ type = bt_ctf_field_type(decl);
+
+ switch (type) {
+ case CTF_TYPE_ARRAY:
+ array = get_declaration_array(decl);
+ if (!array)
+ goto error;
+ integer = get_declaration_integer(array->elem);
+ if (!integer)
+ goto error;
+ ret = integer->encoding;
+ break;
+ case CTF_TYPE_SEQUENCE:
+ sequence = get_declaration_sequence(decl);
+ if (!sequence)
+ goto error;
+ integer = get_declaration_integer(sequence->elem);
+ if (!integer)
+ goto error;
+ ret = integer->encoding;
+ break;
+ case CTF_TYPE_STRING:
+ string = get_declaration_string(decl);
+ if (!string)
+ goto error;
+ ret = string->encoding;
+ break;
+ case CTF_TYPE_INTEGER:
+ integer = get_declaration_integer(decl);
+ if (!integer)
+ goto error;
+ ret = integer->encoding;
+ break;
+ default:
+ 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 bt_declaration *decl)
{
- int ret;
+ const struct declaration_array *array;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_ARRAY) {
- ret = get_array_len(field);
- } else {
- ret = -1;
- bt_ctf_field_set_error(-EINVAL);
- }
+ array = get_declaration_array(decl);
+ if (!array)
+ goto error;
+ return array->len;
- return ret;
+error:
+ bt_ctf_field_set_error(-EINVAL);
+ return -1;
}
-uint64_t bt_ctf_get_uint64(const struct definition *field)
+uint64_t bt_ctf_get_uint64(const struct bt_definition *field)
{
- unsigned int ret = 0;
+ uint64_t ret = 0;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER)
- ret = get_unsigned_int(field);
+ if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_INTEGER)
+ ret = bt_get_unsigned_int(field);
else
bt_ctf_field_set_error(-EINVAL);
return ret;
}
-int64_t bt_ctf_get_int64(const struct definition *field)
+int64_t bt_ctf_get_int64(const struct bt_definition *field)
{
- int ret = 0;
+ int64_t ret = 0;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER)
- ret = get_signed_int(field);
+ if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_INTEGER)
+ ret = bt_get_signed_int(field);
else
bt_ctf_field_set_error(-EINVAL);
return ret;
+}
+
+char *bt_ctf_get_char_array(const struct bt_definition *field)
+{
+ char *ret = NULL;
+ GString *char_array;
+ if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_ARRAY) {
+ char_array = bt_get_char_array(field);
+ if (char_array) {
+ ret = char_array->str;
+ goto end;
+ }
+ }
+ bt_ctf_field_set_error(-EINVAL);
+
+end:
+ return ret;
}
-char *bt_ctf_get_char_array(const struct definition *field)
+char *bt_ctf_get_string(const struct bt_definition *field)
{
char *ret = NULL;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_ARRAY)
- ret = get_char_array(field)->str;
+ if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_STRING)
+ ret = bt_get_string(field);
else
bt_ctf_field_set_error(-EINVAL);
return ret;
}
-char *bt_ctf_get_string(const struct definition *field)
+double bt_ctf_get_float(const struct bt_definition *field)
{
- char *ret = NULL;
+ double ret = 0.0;
- if (field && bt_ctf_field_type(field) == CTF_TYPE_STRING)
- ret = get_string(field);
- else
+ if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_FLOAT) {
+ ret = bt_get_float(field);
+ } else {
+ bt_ctf_field_set_error(-EINVAL);
+ }
+
+ return ret;
+}
+
+const struct bt_definition *bt_ctf_get_variant(const struct bt_definition *field)
+{
+ const struct bt_definition *ret = NULL;
+
+ if (field && bt_ctf_field_type(
+ bt_ctf_get_decl_from_def(field)) == CTF_TYPE_VARIANT) {
+ struct definition_variant *variant = container_of(field,
+ struct definition_variant, p);
+
+ ret = bt_variant_get_current_field(variant);
+ } else {
+ bt_ctf_field_set_error(-EINVAL);
+ }
+
+ return ret;
+}
+
+uint64_t bt_ctf_get_struct_field_count(const struct bt_definition *field)
+{
+ uint64_t ret = -1;
+ const struct bt_declaration *declaration =
+ bt_ctf_get_decl_from_def(field);
+
+ if (field && bt_ctf_field_type(declaration) == CTF_TYPE_STRUCT) {
+ const struct declaration_struct *struct_declaration =
+ container_of(declaration, struct declaration_struct, p);
+
+ ret = bt_struct_declaration_len(struct_declaration);
+ } else {
+ bt_ctf_field_set_error(-EINVAL);
+ }
+
+ return ret;
+}
+
+const struct bt_definition *bt_ctf_get_struct_field_index(
+ const struct bt_definition *field, uint64_t i)
+{
+ const struct bt_definition *ret = NULL;
+
+ if (field && bt_ctf_field_type(
+ bt_ctf_get_decl_from_def(field)) == CTF_TYPE_STRUCT &&
+ i < bt_ctf_get_struct_field_count(field)) {
+ const struct definition_struct *structure = container_of(
+ field, struct definition_struct, p);
+
+ ret = bt_struct_definition_get_field_from_index(structure, i);
+ }
+
+ if (!ret) {
bt_ctf_field_set_error(-EINVAL);
+ }
return ret;
}
+
+int bt_ctf_get_event_decl_list(int handle_id, struct bt_context *ctx,
+ struct bt_ctf_event_decl * const **list,
+ unsigned int *count)
+{
+ struct bt_trace_handle *handle;
+ struct bt_trace_descriptor *td;
+ struct ctf_trace *tin;
+
+ if (!ctx || !list || !count)
+ goto error;
+
+ handle = g_hash_table_lookup(ctx->trace_handles,
+ (gpointer) (unsigned long) handle_id);
+ if (!handle)
+ goto error;
+
+ td = handle->td;
+ tin = container_of(td, struct ctf_trace, parent);
+
+ *list = (struct bt_ctf_event_decl * const*) tin->event_declarations->pdata;
+ *count = tin->event_declarations->len;
+ return 0;
+
+error:
+ return -1;
+}
+
+const char *bt_ctf_get_decl_event_name(const struct bt_ctf_event_decl *event)
+{
+ if (!event)
+ return NULL;
+
+ return g_quark_to_string(event->parent.name);
+}
+
+uint64_t bt_ctf_get_decl_event_id(const struct bt_ctf_event_decl *event)
+{
+ if (!event)
+ return (uint64_t)(-1);
+
+ return event->parent.id;
+}
+
+int bt_ctf_get_decl_fields(struct bt_ctf_event_decl *event_decl,
+ enum bt_ctf_scope scope,
+ struct bt_ctf_field_decl const * const **list,
+ unsigned int *count)
+{
+ int i;
+ GArray *fields = NULL;
+ gpointer *ret_list = NULL;
+ GPtrArray *fields_array = NULL;
+ int ret = 0;
+
+ if (!event_decl || !list || !count)
+ return -EINVAL;
+
+ *count = 0;
+ switch (scope) {
+ case BT_EVENT_CONTEXT:
+ if (event_decl->context_decl) {
+ ret_list = event_decl->context_decl->pdata;
+ *count = event_decl->context_decl->len;
+ goto end;
+ }
+ event_decl->context_decl = g_ptr_array_new();
+ if (!event_decl->parent.context_decl) {
+ ret = -1;
+ goto end;
+ }
+ fields = event_decl->parent.context_decl->fields;
+ fields_array = event_decl->context_decl;
+ break;
+ case BT_EVENT_FIELDS:
+ if (event_decl->fields_decl) {
+ ret_list = event_decl->fields_decl->pdata;
+ *count = event_decl->fields_decl->len;
+ goto end;
+ }
+ event_decl->fields_decl = g_ptr_array_new();
+ if (!event_decl->parent.fields_decl) {
+ ret = -1;
+ goto end;
+ }
+ fields = event_decl->parent.fields_decl->fields;
+ fields_array = event_decl->fields_decl;
+ break;
+ case BT_STREAM_PACKET_CONTEXT:
+ if (event_decl->packet_context_decl) {
+ ret_list = event_decl->packet_context_decl->pdata;
+ *count = event_decl->packet_context_decl->len;
+ goto end;
+ }
+ event_decl->packet_context_decl = g_ptr_array_new();
+ if (!event_decl->parent.stream->packet_context_decl) {
+ ret = -1;
+ goto end;
+ }
+ fields = event_decl->parent.stream->packet_context_decl->fields;
+ fields_array = event_decl->packet_context_decl;
+ break;
+ case BT_STREAM_EVENT_CONTEXT:
+ if (event_decl->event_context_decl) {
+ ret_list = event_decl->event_context_decl->pdata;
+ *count = event_decl->event_context_decl->len;
+ goto end;
+ }
+ event_decl->event_context_decl = g_ptr_array_new();
+ if (!event_decl->parent.stream->event_context_decl) {
+ ret = -1;
+ goto end;
+ }
+ fields = event_decl->parent.stream->event_context_decl->fields;
+ fields_array = event_decl->event_context_decl;
+ break;
+ case BT_STREAM_EVENT_HEADER:
+ if (event_decl->event_header_decl) {
+ ret_list = event_decl->event_header_decl->pdata;
+ *count = event_decl->event_header_decl->len;
+ goto end;
+ }
+ event_decl->event_header_decl = g_ptr_array_new();
+ if (!event_decl->parent.stream->event_header_decl) {
+ ret = -1;
+ goto end;
+ }
+ fields = event_decl->parent.stream->event_header_decl->fields;
+ fields_array = event_decl->event_header_decl;
+ break;
+ case BT_TRACE_PACKET_HEADER:
+ if (event_decl->packet_header_decl) {
+ ret_list = event_decl->packet_header_decl->pdata;
+ *count = event_decl->packet_header_decl->len;
+ goto end;
+ }
+ event_decl->packet_header_decl = g_ptr_array_new();
+ if (!event_decl->parent.stream->trace->packet_header_decl) {
+ ret = -1;
+ goto end;
+ }
+ fields = event_decl->parent.stream->trace->packet_header_decl->fields;
+ fields_array = event_decl->packet_header_decl;
+ break;
+ }
+
+ for (i = 0; i < fields->len; i++) {
+ g_ptr_array_add(fields_array,
+ &g_array_index(fields,
+ struct declaration_field, i));
+ }
+ ret_list = fields_array->pdata;
+ *count = fields->len;
+
+end:
+ *list = (struct bt_ctf_field_decl const* const*) ret_list;
+
+ return ret;
+}
+
+const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field)
+{
+ if (!field)
+ return NULL;
+
+ return rem_(g_quark_to_string(((struct declaration_field *) field)->name));
+}
+
+const struct bt_declaration *bt_ctf_get_decl_from_def(const struct bt_definition *def)
+{
+ if (def)
+ return def->declaration;
+
+ return NULL;
+}
+
+const struct bt_declaration *bt_ctf_get_decl_from_field_decl(
+ const struct bt_ctf_field_decl *field)
+{
+ if (field)
+ return ((struct declaration_field *) field)->declaration;
+
+ return NULL;
+}