const struct 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;
+ const struct definition *tmp = NULL;
+ const struct ctf_event_definition *event;
if (!ctf_event)
return NULL;
const struct definition *scope,
const char *field)
{
- struct definition *def;
+ const struct definition *def;
char *field_underscore;
if (!ctf_event || !scope || !field)
g_free(field_underscore);
}
if (bt_ctf_field_type(bt_ctf_get_field_decl(def)) == CTF_TYPE_VARIANT) {
- struct definition_variant *variant_definition;
+ const struct definition_variant *variant_definition;
variant_definition = container_of(def,
- struct definition_variant, p);
+ const struct definition_variant, p);
return variant_definition->current_field;
}
return def;
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;
+ const struct ctf_event_declaration *event_class;
+ const struct ctf_stream_declaration *stream_class;
+ const struct ctf_event_definition *event;
if (!ctf_event)
return NULL;
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;
+ const struct ctf_file_stream *cfs;
+ const struct ctf_trace *trace;
+ const struct ctf_event_definition *event;
if (!ctf_event)
return NULL;
event = ctf_event->parent;
- cfs = container_of(event->stream, struct ctf_file_stream,
+ cfs = container_of(event->stream, const struct ctf_file_stream,
parent);
trace = cfs->parent.stream_class->trace;
if (trace->ctx)
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;
+ const struct ctf_file_stream *cfs;
+ const struct ctf_trace *trace;
+ const struct ctf_event_definition *event;
if (!ctf_event)
return -EINVAL;
event = ctf_event->parent;
- cfs = container_of(event->stream, struct ctf_file_stream,
+ cfs = container_of(event->stream, const struct ctf_file_stream,
parent);
trace = cfs->parent.stream_class->trace;
if (trace->handle)
uint64_t bt_ctf_get_timestamp(const struct bt_ctf_event *ctf_event)
{
- struct ctf_event_definition *event;
+ const struct ctf_event_definition *event;
if (!ctf_event)
return -1ULL;
uint64_t bt_ctf_get_cycles(const struct bt_ctf_event *ctf_event)
{
- struct ctf_event_definition *event;
+ const struct ctf_event_definition *event;
if (!ctf_event)
return -1ULL;
return ret;
}
-static struct declaration_integer *get_declaration_integer(const struct declaration *decl)
+static const 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;
+ if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_INTEGER)
+ return NULL;
+ return container_of(decl, const struct declaration_integer, p);
}
-static struct declaration_string *get_declaration_string(const struct declaration *decl)
+static const 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;
+ if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_STRING)
+ return NULL;
+ return container_of(decl, const struct declaration_string, p);
}
-static struct declaration_array *get_declaration_array(const struct declaration *decl)
+static const 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;
+ if (!decl || bt_ctf_field_type(decl) != CTF_TYPE_ARRAY)
+ return NULL;
+ return container_of(decl, const struct declaration_array, p);
}
int bt_ctf_get_int_signedness(const struct declaration *decl)
{
- int ret;
- struct declaration_integer *integer;
+ const struct declaration_integer *integer;
integer = get_declaration_integer(decl);
- if (integer) {
- ret = integer->signedness;
- } else {
- ret = -EINVAL;
+ if (!integer) {
bt_ctf_field_set_error(-EINVAL);
+ return -EINVAL;
}
-
- return ret;
+ return integer->signedness;
}
int bt_ctf_get_int_base(const struct declaration *decl)
{
- int ret;
- struct declaration_integer *integer;
+ const struct declaration_integer *integer;
integer = get_declaration_integer(decl);
- if (integer) {
- ret = integer->base;
- } else {
- ret = -EINVAL;
+ if (!integer) {
bt_ctf_field_set_error(-EINVAL);
+ return -EINVAL;
}
-
- return ret;
+ return integer->base;
}
int bt_ctf_get_int_byte_order(const struct declaration *decl)
{
- int ret;
- struct declaration_integer *integer;
+ const struct declaration_integer *integer;
integer = get_declaration_integer(decl);
- if (integer) {
- ret = integer->byte_order;
- } else {
- ret = -EINVAL;
+ if (!integer) {
bt_ctf_field_set_error(-EINVAL);
+ return -EINVAL;
}
-
- return ret;
+ return integer->byte_order;
}
ssize_t bt_ctf_get_int_len(const struct declaration *decl)
{
- ssize_t ret;
- struct declaration_integer *integer;
+ const struct declaration_integer *integer;
integer = get_declaration_integer(decl);
- if (integer) {
- ret = (ssize_t) integer->len;
- } else {
- ret = -EINVAL;
+ if (!integer) {
bt_ctf_field_set_error(-EINVAL);
+ return -EINVAL;
}
-
- return ret;
+ return (ssize_t) integer->len;
}
const struct definition *bt_ctf_get_enum_int(const struct definition *field)
{
- struct definition_enum *def_enum;
+ const struct definition_enum *def_enum;
if (!field || bt_ctf_field_type(bt_ctf_get_field_decl(field)) != CTF_TYPE_ENUM) {
bt_ctf_field_set_error(-EINVAL);
return NULL;
}
- def_enum = container_of(field, struct definition_enum, p);
+ def_enum = container_of(field, const struct definition_enum, p);
return &def_enum->integer->p;
}
const char *bt_ctf_get_enum_str(const struct definition *field)
{
- struct definition_enum *def_enum;
- struct declaration_enum *decl_enum;
+ const struct definition_enum *def_enum;
+ const struct declaration_enum *decl_enum;
GArray *array;
const char *ret;
bt_ctf_field_set_error(-EINVAL);
return NULL;
}
- def_enum = container_of(field, struct definition_enum, p);
+ def_enum = container_of(field, const struct definition_enum, p);
decl_enum = def_enum->declaration;
if (get_int_signedness(&def_enum->integer->p)) {
array = enum_int_to_quark_set(decl_enum,
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;
+ const struct declaration_integer *integer;
+ const struct declaration_string *string;
if (!decl)
goto error;
int bt_ctf_get_array_len(const struct declaration *decl)
{
- int ret;
- struct declaration_array *array;
+ const struct declaration_array *array;
- if (decl && bt_ctf_field_type(decl) == CTF_TYPE_ARRAY) {
- array = get_declaration_array(decl);
- if (array) {
- ret = array->len;
- } else {
- goto error;
- }
- } else {
+ array = get_declaration_array(decl);
+ if (!array)
goto error;
- }
-
- return ret;
+ return array->len;
error:
bt_ctf_field_set_error(-EINVAL);
bt_ctf_field_set_error(-EINVAL);
return ret;
-
}
char *bt_ctf_get_char_array(const struct definition *field)