X-Git-Url: http://drtracing.org/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ftrace-ir%2Fattributes.c;h=8c1a0823e1ce23d99c6949e420b47740c33097b0;hb=35fa110e5bea4a35497313adf3e3d0fa09db9ff7;hp=b38677394f340ec11a1dfbca71b5a6b716860296;hpb=bb61965be5ec1bfe6977d0eca85e2e83da65af5f;p=babeltrace.git diff --git a/lib/trace-ir/attributes.c b/lib/trace-ir/attributes.c index b3867739..8c1a0823 100644 --- a/lib/trace-ir/attributes.c +++ b/lib/trace-ir/attributes.c @@ -24,11 +24,13 @@ #define BT_LOG_TAG "ATTRS" #include -#include #include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -37,9 +39,9 @@ #define BT_ATTR_VALUE_INDEX 1 BT_HIDDEN -struct bt_private_value *bt_attributes_create(void) +struct bt_value *bt_attributes_create(void) { - struct bt_private_value *attr_obj; + struct bt_value *attr_obj; /* * Attributes: array value object of array value objects, each one @@ -56,7 +58,7 @@ struct bt_private_value *bt_attributes_create(void) * ] */ BT_LOGD_STR("Creating attributes object."); - attr_obj = bt_private_value_array_create(); + attr_obj = bt_value_array_create(); if (!attr_obj) { BT_LOGE_STR("Failed to create array value."); } else { @@ -68,41 +70,39 @@ struct bt_private_value *bt_attributes_create(void) } BT_HIDDEN -void bt_attributes_destroy(struct bt_private_value *attr_obj) +void bt_attributes_destroy(struct bt_value *attr_obj) { BT_LOGD("Destroying attributes object: addr=%p", attr_obj); BT_OBJECT_PUT_REF_AND_RESET(attr_obj); } BT_HIDDEN -int64_t bt_attributes_get_count(struct bt_private_value *attr_obj) +int64_t bt_attributes_get_count(const struct bt_value *attr_obj) { - return bt_value_array_get_size(bt_private_value_as_value(attr_obj)); + return bt_value_array_get_size(attr_obj); } BT_HIDDEN -const char *bt_attributes_get_field_name(struct bt_private_value *attr_obj, +const char *bt_attributes_get_field_name(const struct bt_value *attr_obj, uint64_t index) { const char *ret = NULL; - struct bt_private_value *attr_field_obj = NULL; - struct bt_private_value *attr_field_name_obj = NULL; + const struct bt_value *attr_field_obj = NULL; + const struct bt_value *attr_field_name_obj = NULL; if (!attr_obj) { BT_LOGW_STR("Invalid parameter: attributes object is NULL."); goto end; } - if (index >= bt_value_array_get_size( - bt_private_value_as_value(attr_obj))) { + if (index >= bt_value_array_get_size(attr_obj)) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_get_size( - bt_private_value_as_value(attr_obj))); + index, bt_value_array_get_size(attr_obj)); goto end; } - attr_field_obj = bt_private_value_array_borrow_element_by_index( + attr_field_obj = bt_value_array_borrow_element_by_index_const( attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " @@ -111,7 +111,7 @@ const char *bt_attributes_get_field_name(struct bt_private_value *attr_obj, } attr_field_name_obj = - bt_private_value_array_borrow_element_by_index(attr_field_obj, + bt_value_array_borrow_element_by_index_const(attr_field_obj, BT_ATTR_NAME_INDEX); if (!attr_field_name_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -120,42 +120,40 @@ const char *bt_attributes_get_field_name(struct bt_private_value *attr_obj, goto end; } - ret = bt_value_string_get( - bt_private_value_as_value(attr_field_name_obj)); + ret = bt_value_string_get(attr_field_name_obj); end: return ret; } BT_HIDDEN -struct bt_private_value *bt_attributes_borrow_field_value( - struct bt_private_value *attr_obj, uint64_t index) +struct bt_value *bt_attributes_borrow_field_value( + struct bt_value *attr_obj, uint64_t index) { - struct bt_private_value *value_obj = NULL; - struct bt_private_value *attr_field_obj = NULL; + struct bt_value *value_obj = NULL; + struct bt_value *attr_field_obj = NULL; if (!attr_obj) { BT_LOGW_STR("Invalid parameter: attributes object is NULL."); goto end; } - if (index >= bt_value_array_get_size(bt_private_value_as_value(attr_obj))) { + if (index >= bt_value_array_get_size(attr_obj)) { BT_LOGW("Invalid parameter: index is out of bounds: " "index=%" PRIu64 ", count=%" PRId64, - index, bt_value_array_get_size( - bt_private_value_as_value(attr_obj))); + index, bt_value_array_get_size(attr_obj)); goto end; } attr_field_obj = - bt_private_value_array_borrow_element_by_index(attr_obj, index); + bt_value_array_borrow_element_by_index(attr_obj, index); if (!attr_field_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " "value-addr=%p, index=%" PRIu64, attr_obj, index); goto end; } - value_obj = bt_private_value_array_borrow_element_by_index( + value_obj = bt_value_array_borrow_element_by_index( attr_field_obj, BT_ATTR_VALUE_INDEX); if (!value_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -168,16 +166,15 @@ end: } static -struct bt_private_value *bt_attributes_borrow_field_by_name( - struct bt_private_value *attr_obj, const char *name) +struct bt_value *bt_attributes_borrow_field_by_name( + struct bt_value *attr_obj, const char *name) { uint64_t i; int64_t attr_size; - struct bt_private_value *value_obj = NULL; - struct bt_private_value *attr_field_name_obj = NULL; + struct bt_value *value_obj = NULL; + struct bt_value *attr_field_name_obj = NULL; - attr_size = bt_value_array_get_size( - bt_private_value_as_value(attr_obj)); + attr_size = bt_value_array_get_size(attr_obj); if (attr_size < 0) { BT_LOGE("Cannot get array value's size: value-addr=%p", attr_obj); @@ -187,7 +184,7 @@ struct bt_private_value *bt_attributes_borrow_field_by_name( for (i = 0; i < attr_size; ++i) { const char *field_name; - value_obj = bt_private_value_array_borrow_element_by_index( + value_obj = bt_value_array_borrow_element_by_index( attr_obj, i); if (!value_obj) { BT_LOGE("Cannot get attributes object's array value's element by index: " @@ -196,7 +193,7 @@ struct bt_private_value *bt_attributes_borrow_field_by_name( } attr_field_name_obj = - bt_private_value_array_borrow_element_by_index( + bt_value_array_borrow_element_by_index( value_obj, BT_ATTR_NAME_INDEX); if (!attr_field_name_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -205,8 +202,7 @@ struct bt_private_value *bt_attributes_borrow_field_by_name( goto error; } - field_name = bt_value_string_get( - bt_private_value_as_value(attr_field_name_obj)); + field_name = bt_value_string_get(attr_field_name_obj); if (!strcmp(field_name, name)) { break; @@ -223,11 +219,11 @@ error: } BT_HIDDEN -int bt_attributes_set_field_value(struct bt_private_value *attr_obj, - const char *name, struct bt_private_value *value_obj) +int bt_attributes_set_field_value(struct bt_value *attr_obj, + const char *name, struct bt_value *value_obj) { int ret = 0; - struct bt_private_value *attr_field_obj = NULL; + struct bt_value *attr_field_obj = NULL; if (!attr_obj || !name || !value_obj) { BT_LOGW("Invalid parameter: attributes object, name, or value object is NULL: " @@ -239,32 +235,32 @@ int bt_attributes_set_field_value(struct bt_private_value *attr_obj, attr_field_obj = bt_attributes_borrow_field_by_name(attr_obj, name); if (attr_field_obj) { - ret = bt_private_value_array_set_element_by_index( + ret = bt_value_array_set_element_by_index( attr_field_obj, BT_ATTR_VALUE_INDEX, - bt_private_value_as_value(value_obj)); + value_obj); attr_field_obj = NULL; goto end; } - attr_field_obj = bt_private_value_array_create(); + attr_field_obj = bt_value_array_create(); if (!attr_field_obj) { BT_LOGE_STR("Failed to create empty array value."); ret = -1; goto end; } - ret = bt_private_value_array_append_string_element(attr_field_obj, + ret = bt_value_array_append_string_element(attr_field_obj, name); - ret |= bt_private_value_array_append_element(attr_field_obj, - bt_private_value_as_value(value_obj)); + ret |= bt_value_array_append_element(attr_field_obj, + value_obj); if (ret) { BT_LOGE("Cannot append elements to array value: addr=%p", attr_field_obj); goto end; } - ret = bt_private_value_array_append_element(attr_obj, - bt_private_value_as_value(attr_field_obj)); + ret = bt_value_array_append_element(attr_obj, + attr_field_obj); if (ret) { BT_LOGE("Cannot append element to array value: " "array-value-addr=%p, element-value-addr=%p", @@ -277,11 +273,11 @@ end: } BT_HIDDEN -struct bt_private_value *bt_attributes_borrow_field_value_by_name( - struct bt_private_value *attr_obj, const char *name) +struct bt_value *bt_attributes_borrow_field_value_by_name( + struct bt_value *attr_obj, const char *name) { - struct bt_private_value *value_obj = NULL; - struct bt_private_value *attr_field_obj = NULL; + struct bt_value *value_obj = NULL; + struct bt_value *attr_field_obj = NULL; if (!attr_obj || !name) { BT_LOGW("Invalid parameter: attributes object or name is NULL: " @@ -296,7 +292,7 @@ struct bt_private_value *bt_attributes_borrow_field_value_by_name( goto end; } - value_obj = bt_private_value_array_borrow_element_by_index( + value_obj = bt_value_array_borrow_element_by_index( attr_field_obj, BT_ATTR_VALUE_INDEX); if (!value_obj) { BT_LOGE("Cannot get attribute array value's element by index: " @@ -309,7 +305,7 @@ end: } BT_HIDDEN -int bt_attributes_freeze(struct bt_private_value *attr_obj) +int bt_attributes_freeze(const struct bt_value *attr_obj) { uint64_t i; int64_t count; @@ -322,7 +318,7 @@ int bt_attributes_freeze(struct bt_private_value *attr_obj) } BT_LOGD("Freezing attributes object: value-addr=%p", attr_obj); - count = bt_value_array_get_size(bt_private_value_as_value(attr_obj)); + count = bt_value_array_get_size(attr_obj); BT_ASSERT(count >= 0); /* @@ -331,9 +327,10 @@ int bt_attributes_freeze(struct bt_private_value *attr_obj) * attribute is frozen one by one. */ for (i = 0; i < count; ++i) { - struct bt_private_value *obj = NULL; + struct bt_value *obj = NULL; - obj = bt_attributes_borrow_field_value(attr_obj, i); + obj = bt_attributes_borrow_field_value( + (void *) attr_obj, i); if (!obj) { BT_LOGE("Cannot get attributes object's field value by index: " "value-addr=%p, index=%" PRIu64, @@ -342,7 +339,7 @@ int bt_attributes_freeze(struct bt_private_value *attr_obj) goto end; } - bt_value_freeze(bt_private_value_as_value(obj)); + bt_value_freeze(obj); } end: