X-Git-Url: http://drtracing.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ftrace-ir%2Ftrace-class.c;h=78a7161bb56c2c632521115364bcf8cfcf80ad00;hb=35fa110e5bea4a35497313adf3e3d0fa09db9ff7;hp=b8c99470063016fc177d31055280626e2daa4053;hpb=10b7a2e4edf77cb8a63062e151c580b1157a40e8;p=babeltrace.git diff --git a/lib/trace-ir/trace-class.c b/lib/trace-ir/trace-class.c index b8c99470..78a7161b 100644 --- a/lib/trace-ir/trace-class.c +++ b/lib/trace-ir/trace-class.c @@ -1,8 +1,7 @@ /* + * Copyright 2017-2018 Philippe Proulx * Copyright 2014 Jérémie Galarneau * - * Author: Jérémie Galarneau - * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights @@ -38,15 +37,14 @@ #include #include #include -#include +#include #include #include #include #include -#include -#include -#include -#include +#include +#include +#include #include #include #include @@ -85,7 +83,7 @@ void destroy_trace_class(struct bt_object *obj) tc->stream_classes = NULL; } - BT_LOGD_STR("Putting packet header field classe."); + BT_LOGD_STR("Putting packet header field class."); bt_object_put_ref(tc->packet_header_fc); tc->packet_header_fc = NULL; g_free(tc); @@ -98,11 +96,12 @@ void free_packet_header_field(struct bt_field_wrapper *field_wrapper, bt_field_wrapper_destroy(field_wrapper); } -struct bt_trace_class *bt_trace_class_create(void) +struct bt_trace_class *bt_trace_class_create(bt_self_component *self_comp) { struct bt_trace_class *tc = NULL; int ret; + BT_ASSERT_PRE_NON_NULL(self_comp, "Self component"); BT_LOGD_STR("Creating default trace class object."); tc = g_new0(struct bt_trace_class, 1); if (!tc) { @@ -158,7 +157,8 @@ const char *bt_trace_class_get_name(const struct bt_trace_class *tc) return tc->name.value; } -int bt_trace_class_set_name(struct bt_trace_class *tc, const char *name) +enum bt_trace_class_status bt_trace_class_set_name( + struct bt_trace_class *tc, const char *name) { BT_ASSERT_PRE_NON_NULL(tc, "Trace class"); BT_ASSERT_PRE_NON_NULL(name, "Name"); @@ -166,7 +166,7 @@ int bt_trace_class_set_name(struct bt_trace_class *tc, const char *name) g_string_assign(tc->name.str, name); tc->name.value = tc->name.str->str; BT_LIB_LOGV("Set trace class's name: %!+T", tc); - return 0; + return BT_TRACE_CLASS_STATUS_OK; } bt_uuid bt_trace_class_get_uuid(const struct bt_trace_class *tc) @@ -196,8 +196,8 @@ bool trace_has_environment_entry(const struct bt_trace_class *tc, const char *na } static -int set_environment_entry(struct bt_trace_class *tc, const char *name, - struct bt_value *value) +enum bt_trace_class_status set_environment_entry(struct bt_trace_class *tc, + const char *name, struct bt_value *value) { int ret; @@ -210,11 +210,12 @@ int set_environment_entry(struct bt_trace_class *tc, const char *name, "%![tc-]+T, entry-name=\"%s\"", tc, name); ret = bt_attributes_set_field_value(tc->environment, name, value); - bt_value_freeze(value); if (ret) { + ret = BT_TRACE_CLASS_STATUS_NOMEM; BT_LIB_LOGE("Cannot set trace class's environment entry: " "%![tc-]+T, entry-name=\"%s\"", tc, name); } else { + bt_value_freeze(value); BT_LIB_LOGV("Set trace class's environment entry: " "%![tc-]+T, entry-name=\"%s\"", tc, name); } @@ -222,7 +223,7 @@ int set_environment_entry(struct bt_trace_class *tc, const char *name, return ret; } -int bt_trace_class_set_environment_entry_string( +enum bt_trace_class_status bt_trace_class_set_environment_entry_string( struct bt_trace_class *tc, const char *name, const char *value) { int ret; @@ -245,8 +246,8 @@ end: return ret; } -int bt_trace_class_set_environment_entry_integer(struct bt_trace_class *tc, - const char *name, int64_t value) +enum bt_trace_class_status bt_trace_class_set_environment_entry_integer( + struct bt_trace_class *tc, const char *name, int64_t value) { int ret; struct bt_value *value_obj; @@ -255,7 +256,7 @@ int bt_trace_class_set_environment_entry_integer(struct bt_trace_class *tc, value_obj = bt_value_integer_create_init(value); if (!value_obj) { BT_LOGE_STR("Cannot create an integer value object."); - ret = -1; + ret = BT_TRACE_CLASS_STATUS_NOMEM; goto end; } @@ -359,7 +360,7 @@ const struct bt_field_class *bt_trace_class_borrow_packet_header_field_class_con return tc->packet_header_fc; } -int bt_trace_class_set_packet_header_field_class( +enum bt_trace_class_status bt_trace_class_set_packet_header_field_class( struct bt_trace_class *tc, struct bt_field_class *field_class) { @@ -378,10 +379,16 @@ int bt_trace_class_set_packet_header_field_class( BT_ASSERT_PRE_TRACE_CLASS_HOT(tc); BT_ASSERT_PRE(bt_field_class_get_type(field_class) == BT_FIELD_CLASS_TYPE_STRUCTURE, - "Packet header field classe is not a structure field classe: %!+F", + "Packet header field class is not a structure field class: %!+F", field_class); ret = bt_resolve_field_paths(field_class, &resolve_ctx); if (ret) { + /* + * This is the only reason for which + * bt_resolve_field_paths() can fail: anything else + * would be because a precondition is not satisfied. + */ + ret = BT_TRACE_CLASS_STATUS_NOMEM; goto end; } @@ -390,7 +397,7 @@ int bt_trace_class_set_packet_header_field_class( tc->packet_header_fc = field_class; bt_object_get_no_null_check(tc->packet_header_fc); bt_field_class_freeze(field_class); - BT_LIB_LOGV("Set trace class's packet header field classe: %!+T", tc); + BT_LIB_LOGV("Set trace class's packet header field class: %!+T", tc); end: return ret; @@ -399,7 +406,7 @@ end: BT_HIDDEN void _bt_trace_class_freeze(const struct bt_trace_class *tc) { - /* The packet header field classe is already frozen */ + /* The packet header field class is already frozen */ BT_ASSERT(tc); BT_LIB_LOGD("Freezing trace class: %!+T", tc); ((struct bt_trace_class *) tc)->frozen = true; @@ -420,3 +427,13 @@ void bt_trace_class_set_assigns_automatic_stream_class_id(struct bt_trace_class BT_LIB_LOGV("Set trace class's automatic stream class ID " "assignment property: %!+T", tc); } + +void bt_trace_class_get_ref(const struct bt_trace_class *trace_class) +{ + bt_object_get_ref(trace_class); +} + +void bt_trace_class_put_ref(const struct bt_trace_class *trace_class) +{ + bt_object_put_ref(trace_class); +}