struct bt_ctf_event_class *bt_ctf_event_class_create(const char *name) { int ret; struct bt_value *obj = NULL; struct bt_ctf_event_class *event_class = NULL; if (bt_ctf_validate_identifier(name)) { goto error; } event_class = g_new0(struct bt_ctf_event_class, 1); if (!event_class) { goto error; } bt_object_init(event_class, bt_ctf_event_class_destroy); event_class->fields = bt_ctf_field_type_structure_create(); if (!event_class->fields) { goto error; } event_class->attributes = bt_ctf_attributes_create(); if (!event_class->attributes) { goto error; } obj = bt_value_integer_create_init(-1); if (!obj) { goto error; } ret = bt_ctf_attributes_set_field_value(event_class->attributes, "id", obj); if (ret) { goto error; } BT_PUT(obj); obj = bt_value_string_create_init(name); if (!obj) { goto error; } ret = bt_ctf_attributes_set_field_value(event_class->attributes, "name", obj); if (ret) { goto error; } BT_PUT(obj); return event_class; error: BT_PUT(event_class); BT_PUT(obj); return event_class; }
int bt_ctf_trace_set_environment_field(struct bt_ctf_trace *trace, const char *name, struct bt_value *value) { int ret = 0; if (!trace || !name || !value || bt_ctf_validate_identifier(name) || !(bt_value_is_integer(value) || bt_value_is_string(value))) { ret = -1; goto end; } if (strchr(name, ' ')) { ret = -1; goto end; } if (trace->frozen) { /* * New environment fields may be added to a frozen trace, * but existing fields may not be changed. * * The object passed is frozen like all other attributes. */ struct bt_value *attribute = bt_ctf_attributes_get_field_value_by_name( trace->environment, name); if (attribute) { BT_PUT(attribute); ret = -1; goto end; } bt_value_freeze(value); } ret = bt_ctf_attributes_set_field_value(trace->environment, name, value); end: return ret; }
int bt_ctf_event_class_add_field(struct bt_ctf_event_class *event_class, struct bt_ctf_field_type *type, const char *name) { int ret = 0; if (!event_class || !type || bt_ctf_validate_identifier(name) || event_class->frozen) { ret = -1; goto end; } if (bt_ctf_field_type_get_type_id(event_class->fields) != CTF_TYPE_STRUCT) { ret = -1; goto end; } ret = bt_ctf_field_type_structure_add_field(event_class->fields, type, name); end: return ret; }
BT_HIDDEN int bt_ctf_clock_set_name(struct bt_ctf_clock *clock, const char *name) { int ret = 0; if (bt_ctf_validate_identifier(name)) { ret = -1; goto end; } if (clock->name) { g_string_assign(clock->name, name); } else { clock->name = g_string_new(name); if (!clock->name) { ret = -1; goto end; } } end: return ret; }