/*
* 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;
enum bt_ctf_scope scope)
{
struct definition *tmp = NULL;
- struct ctf_event_definition *event = ctf_event->parent;
+ struct ctf_event_definition *event;
+ if (!ctf_event)
+ return NULL;
+
+ event = ctf_event->parent;
switch (scope) {
case BT_TRACE_PACKET_HEADER:
if (!event->stream)
struct 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 = 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);
}
- return NULL;
+ 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;
}
const struct definition *bt_ctf_get_index(const struct bt_ctf_event *ctf_event,
{
struct definition *ret = NULL;
+ if (!ctf_event || !field)
+ return NULL;
+
if (bt_ctf_field_type(field) == CTF_TYPE_ARRAY) {
struct definition_array *array_definition;
array_definition = container_of(field,
{
struct ctf_event_declaration *event_class;
struct ctf_stream_declaration *stream_class;
- struct ctf_event_definition *event = ctf_event->parent;
+ 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);
const char *bt_ctf_field_name(const struct definition *def)
{
- if (def)
- return rem_(g_quark_to_string(def->name));
- return NULL;
+ if (!def)
+ return NULL;
+
+ return rem_(g_quark_to_string(def->name));
}
enum ctf_type_id bt_ctf_field_type(const struct definition *def)
{
- if (def)
- return def->declaration->id;
- return CTF_TYPE_UNKNOWN;
+ if (!def)
+ return CTF_TYPE_UNKNOWN;
+
+ return def->declaration->id;
}
int bt_ctf_get_field_list(const struct bt_ctf_event *ctf_event,
struct definition const * const **list,
unsigned int *count)
{
+ if (!ctf_event || !scope || !list || !count)
+ return -EINVAL;
+
switch (bt_ctf_field_type(scope)) {
case CTF_TYPE_INTEGER:
case CTF_TYPE_FLOAT:
} else {
goto error;
}
+ break;
}
case CTF_TYPE_UNTAGGED_VARIANT:
goto error;
} else {
goto error;
}
+ break;
}
case CTF_TYPE_ARRAY:
{
} else {
goto error;
}
+ break;
}
case CTF_TYPE_SEQUENCE:
{
} else {
goto error;
}
+ break;
}
default:
break;
struct bt_context *ret = NULL;
struct ctf_file_stream *cfs;
struct ctf_trace *trace;
- struct ctf_event_definition *event = ctf_event->parent;
+ struct ctf_event_definition *event;
+ if (!ctf_event)
+ return NULL;
+
+ event = ctf_event->parent;
cfs = container_of(event->stream, struct ctf_file_stream,
parent);
trace = cfs->parent.stream_class->trace;
int ret = -1;
struct ctf_file_stream *cfs;
struct ctf_trace *trace;
- struct ctf_event_definition *event = ctf_event->parent;
+ struct ctf_event_definition *event;
+ if (!ctf_event)
+ return -EINVAL;
+
+ event = ctf_event->parent;
cfs = container_of(event->stream, struct ctf_file_stream,
parent);
trace = cfs->parent.stream_class->trace;
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;
+ 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;
+ 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;
}
if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
ret = get_int_signedness(field);
} else {
- ret = -1;
+ ret = -EINVAL;
bt_ctf_field_set_error(-EINVAL);
}
if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
ret = get_int_base(field);
} else {
- ret = -1;
+ ret = -EINVAL;
bt_ctf_field_set_error(-EINVAL);
}
if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
ret = get_int_byte_order(field);
} else {
- ret = -1;
+ ret = -EINVAL;
+ bt_ctf_field_set_error(-EINVAL);
+ }
+
+ return ret;
+}
+
+ssize_t bt_ctf_get_int_len(const struct definition *field)
+{
+ ssize_t ret;
+
+ if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER) {
+ ret = (ssize_t) get_int_len(field);
+ } else {
+ ret = -EINVAL;
bt_ctf_field_set_error(-EINVAL);
}
enum ctf_string_encoding ret = 0;
if (!field)
- goto end;
+ goto error;
if (bt_ctf_field_type(field) == CTF_TYPE_INTEGER)
ret = get_int_encoding(field);
ret = get_string_encoding(field);
else
goto error;
-
-end:
return ret;
error:
uint64_t bt_ctf_get_uint64(const struct 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);
int64_t bt_ctf_get_int64(const struct definition *field)
{
- int ret = 0;
+ int64_t ret = 0;
if (field && bt_ctf_field_type(field) == CTF_TYPE_INTEGER)
ret = get_signed_int(field);
struct trace_descriptor *td;
struct ctf_trace *tin;
- if (!ctx)
+ if (!ctx || !list || !count)
goto error;
handle = g_hash_table_lookup(ctx->trace_handles,
{
if (!event)
return NULL;
+
return g_quark_to_string(event->parent.name);
}
int ret = 0;
*count = 0;
+ if (!event_decl || !list || !count)
+ return -EINVAL;
+
switch (scope) {
case BT_EVENT_CONTEXT:
if (event_decl->context_decl) {
const char *bt_ctf_get_decl_field_name(const struct bt_ctf_field_decl *field)
{
- if (field)
- return rem_(g_quark_to_string(((struct declaration_field *) field)->name));
- return NULL;
+ if (!field)
+ return NULL;
+
+ return rem_(g_quark_to_string(((struct declaration_field *) field)->name));
}