Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: to enable access to sequence_text field type data from API. #98

Open
wants to merge 1 commit into
base: stable-1.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions formats/ctf/events.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,12 +600,34 @@ char *bt_ctf_get_string(const struct bt_definition *field)
{
char *ret = NULL;

if (field && bt_ctf_field_type(bt_ctf_get_decl_from_def(field)) == CTF_TYPE_STRING)
if(!field)
goto error;

struct bt_declaration *field_decl = bt_ctf_get_decl_from_def(field);
enum ctf_string_encoding sequence_encoding;

switch(bt_ctf_field_type(field_decl))
{
case CTF_TYPE_STRING:
ret = bt_get_string(field);
else
bt_ctf_field_set_error(-EINVAL);
goto end;
case CTF_TYPE_SEQUENCE:
sequence_encoding = bt_ctf_get_encoding(field_decl);
if(sequence_encoding == CTF_STRING_UTF8 || sequence_encoding == CTF_STRING_ASCII)
{
ret = bt_get_sequence_text(field);
goto end;
}
goto error;
default:
goto error;
}

return ret;
error:
bt_ctf_field_set_error(-EINVAL);
end:
return ret;
}

double bt_ctf_get_float(const struct bt_definition *field)
Expand Down
1 change: 1 addition & 0 deletions include/babeltrace/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ struct declaration_enum *
struct declaration_string *
bt_string_declaration_new(enum ctf_string_encoding encoding);
char *bt_get_string(const struct bt_definition *field);
char *bt_get_sequence_text(const struct bt_definition *field);
enum ctf_string_encoding bt_get_string_encoding(const struct bt_definition *field);

double bt_get_float(const struct bt_definition *field);
Expand Down
10 changes: 10 additions & 0 deletions types/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,13 @@ char *bt_get_string(const struct bt_definition *field)

return string_definition->value;
}

char *bt_get_sequence_text(const struct bt_definition *field)
{
struct definition_sequence *sequence_definition =
container_of(field, struct definition_sequence, p);

assert(sequence_definition->string != NULL);

return sequence_definition->string->str;
}