BT_HIDDEN int64_t bt_ctf_event_class_get_id(struct bt_ctf_event_class *event_class) { struct bt_value *obj = NULL; int64_t ret = 0; if (!event_class) { ret = -1; goto end; } obj = bt_ctf_attributes_get_field_value(event_class->attributes, BT_CTF_EVENT_CLASS_ATTR_ID_INDEX); if (!obj) { goto end; } if (bt_value_integer_get(obj, &ret)) { ret = -1; } if (ret < 0) { /* means ID is not set */ ret = -1; goto end; } end: BT_PUT(obj); return ret; }
int bt_ctf_event_class_set_attribute( struct bt_ctf_event_class *event_class, const char *name, struct bt_value *value) { int ret = 0; if (!event_class || !name || !value || event_class->frozen) { ret = -1; goto end; } if (!strcmp(name, "id") || !strcmp(name, "loglevel")) { if (!bt_value_is_integer(value)) { ret = -1; goto end; } } else if (!strcmp(name, "name") || !strcmp(name, "model.emf.uri")) { if (!bt_value_is_string(value)) { ret = -1; goto end; } } else { /* unknown attribute */ ret = -1; goto end; } /* "id" special case: >= 0 */ if (!strcmp(name, "id")) { int64_t val; ret = bt_value_integer_get(value, &val); if (ret) { goto end; } if (val < 0) { ret = -1; goto end; } } ret = bt_ctf_attributes_set_field_value(event_class->attributes, name, value); end: return ret; }
static void append_env_metadata(struct bt_ctf_trace *trace, struct metadata_context *context) { int i; int env_size; env_size = bt_ctf_attributes_get_count(trace->environment); if (env_size <= 0) { return; } g_string_append(context->string, "env {\n"); for (i = 0; i < env_size; ++i) { struct bt_value *env_field_value_obj = NULL; const char *entry_name; entry_name = bt_ctf_attributes_get_field_name( trace->environment, i); env_field_value_obj = bt_ctf_attributes_get_field_value( trace->environment, i); if (!entry_name || !env_field_value_obj) { goto loop_next; } switch (bt_value_get_type(env_field_value_obj)) { case BT_VALUE_TYPE_INTEGER: { int ret; int64_t int_value; ret = bt_value_integer_get(env_field_value_obj, &int_value); if (ret) { goto loop_next; } g_string_append_printf(context->string, "\t%s = %" PRId64 ";\n", entry_name, int_value); break; } case BT_VALUE_TYPE_STRING: { int ret; const char *str_value; char *escaped_str = NULL; ret = bt_value_string_get(env_field_value_obj, &str_value); if (ret) { goto loop_next; } escaped_str = g_strescape(str_value, NULL); if (!escaped_str) { goto loop_next; } g_string_append_printf(context->string, "\t%s = \"%s\";\n", entry_name, escaped_str); free(escaped_str); break; } default: goto loop_next; } loop_next: BT_PUT(env_field_value_obj); } g_string_append(context->string, "};\n\n"); }
BT_HIDDEN int bt_ctf_event_class_serialize(struct bt_ctf_event_class *event_class, struct metadata_context *context) { int i; int count; int ret = 0; struct bt_value *attr_value = NULL; assert(event_class); assert(context); context->current_indentation_level = 1; g_string_assign(context->field_name, ""); g_string_append(context->string, "event {\n"); count = bt_ctf_event_class_get_attribute_count(event_class); if (count < 0) { ret = -1; goto end; } for (i = 0; i < count; ++i) { const char *attr_name = NULL; attr_name = bt_ctf_event_class_get_attribute_name( event_class, i); attr_value = bt_ctf_event_class_get_attribute_value( event_class, i); if (!attr_name || !attr_value) { ret = -1; goto end; } switch (bt_value_get_type(attr_value)) { case BT_VALUE_TYPE_INTEGER: { int64_t value; ret = bt_value_integer_get(attr_value, &value); if (ret) { goto end; } g_string_append_printf(context->string, "\t%s = %" PRId64 ";\n", attr_name, value); break; } case BT_VALUE_TYPE_STRING: { const char *value; ret = bt_value_string_get(attr_value, &value); if (ret) { goto end; } g_string_append_printf(context->string, "\t%s = \"%s\";\n", attr_name, value); break; } default: /* should never happen */ assert(false); break; } BT_PUT(attr_value); } if (event_class->context) { g_string_append(context->string, "\tcontext := "); ret = bt_ctf_field_type_serialize(event_class->context, context); if (ret) { goto end; } g_string_append(context->string, ";\n"); } if (event_class->fields) { g_string_append(context->string, "\tfields := "); ret = bt_ctf_field_type_serialize(event_class->fields, context); if (ret) { goto end; } g_string_append(context->string, ";\n"); } g_string_append(context->string, "};\n\n"); end: context->current_indentation_level = 0; BT_PUT(attr_value); return ret; }