lib: rename `bt_*_labels_by_value` -> `bt_*_labels_for_value`
[babeltrace.git] / src / lib / trace-ir / field.c
index ff5c65a683656dfd856c16261a715a7cc90e204f..805de0f8f63779f20c383a4115d7c07651a586b9 100644 (file)
@@ -22,7 +22,7 @@
  */
 
 #define BT_LOG_TAG "LIB/FIELD"
-#include "lib/lib-logging.h"
+#include "lib/logging.h"
 
 #include "lib/assert-pre.h"
 #include <babeltrace2/trace-ir/field.h>
@@ -36,6 +36,7 @@
 
 #include "field.h"
 #include "field-class.h"
+#include "lib/func-status.h"
 
 static
 void reset_single_field(struct bt_field *field);
@@ -210,7 +211,7 @@ struct bt_field *bt_field_create(struct bt_field_class *fc)
        BT_ASSERT(bt_field_class_has_known_type(fc));
        field = field_create_funcs[fc->type](fc);
        if (!field) {
-               BT_LIB_LOGE("Cannot create field object from field class: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create field object from field class: "
                        "%![fc-]+F", fc);
                goto end;
        }
@@ -239,7 +240,8 @@ struct bt_field *create_integer_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating integer field object: %![fc-]+F", fc);
        int_field = g_new0(struct bt_field_integer, 1);
        if (!int_field) {
-               BT_LOGE_STR("Failed to allocate one integer field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one integer field.");
                goto end;
        }
 
@@ -258,7 +260,7 @@ struct bt_field *create_real_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating real field object: %![fc-]+F", fc);
        real_field = g_new0(struct bt_field_real, 1);
        if (!real_field) {
-               BT_LOGE_STR("Failed to allocate one real field.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one real field.");
                goto end;
        }
 
@@ -277,7 +279,8 @@ struct bt_field *create_string_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating string field object: %![fc-]+F", fc);
        string_field = g_new0(struct bt_field_string, 1);
        if (!string_field) {
-               BT_LOGE_STR("Failed to allocate one string field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one string field.");
                goto end;
        }
 
@@ -285,7 +288,7 @@ struct bt_field *create_string_field(struct bt_field_class *fc)
        string_field->buf = g_array_sized_new(FALSE, FALSE,
                sizeof(char), 1);
        if (!string_field->buf) {
-               BT_LOGE_STR("Failed to allocate a GArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
                BT_OBJECT_PUT_REF_AND_RESET(string_field);
                goto end;
        }
@@ -308,7 +311,7 @@ int create_fields_from_named_field_classes(
        *fields = g_ptr_array_new_with_free_func(
                (GDestroyNotify) bt_field_destroy);
        if (!*fields) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                ret = -1;
                goto end;
        }
@@ -322,7 +325,8 @@ int create_fields_from_named_field_classes(
 
                field = bt_field_create(named_fc->fc);
                if (!field) {
-                       BT_LIB_LOGE("Failed to create structure member or variant option field: "
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Failed to create structure member or variant option field: "
                                "name=\"%s\", %![fc-]+F",
                                named_fc->name->str, named_fc->fc);
                        ret = -1;
@@ -344,7 +348,8 @@ struct bt_field *create_structure_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating structure field object: %![fc-]+F", fc);
        struct_field = g_new0(struct bt_field_structure, 1);
        if (!struct_field) {
-               BT_LOGE_STR("Failed to allocate one structure field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one structure field.");
                goto end;
        }
 
@@ -352,8 +357,8 @@ struct bt_field *create_structure_field(struct bt_field_class *fc)
 
        if (create_fields_from_named_field_classes((void *) fc,
                        &struct_field->fields)) {
-               BT_LIB_LOGE("Cannot create structure member fields: "
-                       "%![fc-]+F", fc);
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Cannot create structure member fields: %![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(struct_field);
                goto end;
        }
@@ -372,7 +377,8 @@ struct bt_field *create_variant_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating variant field object: %![fc-]+F", fc);
        var_field = g_new0(struct bt_field_variant, 1);
        if (!var_field) {
-               BT_LOGE_STR("Failed to allocate one variant field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one variant field.");
                goto end;
        }
 
@@ -380,7 +386,7 @@ struct bt_field *create_variant_field(struct bt_field_class *fc)
 
        if (create_fields_from_named_field_classes((void *) fc,
                        &var_field->fields)) {
-               BT_LIB_LOGE("Cannot create variant member fields: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create variant member fields: "
                        "%![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(var_field);
                goto end;
@@ -403,7 +409,7 @@ int init_array_field_fields(struct bt_field_array *array_field)
        array_fc = (void *) array_field->common.class;
        array_field->fields = g_ptr_array_sized_new(array_field->length);
        if (!array_field->fields) {
-               BT_LOGE_STR("Failed to allocate a GPtrArray.");
+               BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
                ret = -1;
                goto end;
        }
@@ -416,7 +422,8 @@ int init_array_field_fields(struct bt_field_array *array_field)
                array_field->fields->pdata[i] = bt_field_create(
                        array_fc->element_fc);
                if (!array_field->fields->pdata[i]) {
-                       BT_LIB_LOGE("Cannot create array field's element field: "
+                       BT_LIB_LOGE_APPEND_CAUSE(
+                               "Cannot create array field's element field: "
                                "index=%" PRIu64 ", %![fc-]+F", i, array_fc);
                        ret = -1;
                        goto end;
@@ -436,7 +443,8 @@ struct bt_field *create_static_array_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating static array field object: %![fc-]+F", fc);
        array_field = g_new0(struct bt_field_array, 1);
        if (!array_field) {
-               BT_LOGE_STR("Failed to allocate one static array field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one static array field.");
                goto end;
        }
 
@@ -444,7 +452,7 @@ struct bt_field *create_static_array_field(struct bt_field_class *fc)
        array_field->length = array_fc->length;
 
        if (init_array_field_fields(array_field)) {
-               BT_LIB_LOGE("Cannot create static array fields: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create static array fields: "
                        "%![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(array_field);
                goto end;
@@ -464,14 +472,15 @@ struct bt_field *create_dynamic_array_field(struct bt_field_class *fc)
        BT_LIB_LOGD("Creating dynamic array field object: %![fc-]+F", fc);
        array_field = g_new0(struct bt_field_array, 1);
        if (!array_field) {
-               BT_LOGE_STR("Failed to allocate one dynamic array field.");
+               BT_LIB_LOGE_APPEND_CAUSE(
+                       "Failed to allocate one dynamic array field.");
                goto end;
        }
 
        init_field((void *) array_field, fc, &array_field_methods);
 
        if (init_array_field_fields(array_field)) {
-               BT_LIB_LOGE("Cannot create dynamic array fields: "
+               BT_LIB_LOGE_APPEND_CAUSE("Cannot create dynamic array fields: "
                        "%![fc-]+F", fc);
                BT_OBJECT_PUT_REF_AND_RESET(array_field);
                goto end;
@@ -559,7 +568,8 @@ void bt_field_real_set_value(struct bt_field *field, double value)
        bt_field_set_single(field, true);
 }
 
-enum bt_field_status bt_field_unsigned_enumeration_get_mapping_labels(
+enum bt_field_enumeration_get_mapping_labels_status
+bt_field_unsigned_enumeration_get_mapping_labels(
                const struct bt_field *field,
                bt_field_class_enumeration_mapping_label_array *label_array,
                uint64_t *count)
@@ -573,11 +583,12 @@ enum bt_field_status bt_field_unsigned_enumeration_get_mapping_labels(
        BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_UNSIGNED_ENUMERATION, "Field");
        return (int)
-               bt_field_class_unsigned_enumeration_get_mapping_labels_by_value(
+               bt_field_class_unsigned_enumeration_get_mapping_labels_for_value(
                        field->class, int_field->value.u, label_array, count);
 }
 
-enum bt_field_status bt_field_signed_enumeration_get_mapping_labels(
+enum bt_field_enumeration_get_mapping_labels_status
+bt_field_signed_enumeration_get_mapping_labels(
                const struct bt_field *field,
                bt_field_class_enumeration_mapping_label_array *label_array,
                uint64_t *count)
@@ -591,7 +602,7 @@ enum bt_field_status bt_field_signed_enumeration_get_mapping_labels(
        BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_SIGNED_ENUMERATION, "Field");
        return (int)
-               bt_field_class_signed_enumeration_get_mapping_labels_by_value(
+               bt_field_class_signed_enumeration_get_mapping_labels_for_value(
                        field->class, int_field->value.i, label_array, count);
 }
 
@@ -627,8 +638,8 @@ void clear_string_field(struct bt_field *field)
        bt_field_set_single(field, true);
 }
 
-enum bt_field_status bt_field_string_set_value(struct bt_field *field,
-               const char *value)
+enum bt_field_string_set_value_status bt_field_string_set_value(
+               struct bt_field *field, const char *value)
 {
        BT_ASSERT_PRE_NON_NULL(field, "Field");
        BT_ASSERT_PRE_NON_NULL(value, "Value");
@@ -636,18 +647,19 @@ enum bt_field_status bt_field_string_set_value(struct bt_field *field,
        BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field, BT_FIELD_CLASS_TYPE_STRING,
                "Field");
        clear_string_field(field);
-       return bt_field_string_append_with_length(field, value,
+       return (int) bt_field_string_append_with_length(field, value,
                (uint64_t) strlen(value));
 }
 
-enum bt_field_status bt_field_string_append(struct bt_field *field, const char *value)
+enum bt_field_string_append_status bt_field_string_append(
+               struct bt_field *field, const char *value)
 {
        return bt_field_string_append_with_length(field,
                value, (uint64_t) strlen(value));
 }
 
-enum bt_field_status bt_field_string_append_with_length(struct bt_field *field,
-               const char *value, uint64_t length)
+enum bt_field_string_append_status bt_field_string_append_with_length(
+               struct bt_field *field, const char *value, uint64_t length)
 {
        struct bt_field_string *string_field = (void *) field;
        char *data;
@@ -675,17 +687,16 @@ enum bt_field_status bt_field_string_append_with_length(struct bt_field *field,
        ((char *) string_field->buf->data)[new_length] = '\0';
        string_field->length = new_length;
        bt_field_set_single(field, true);
-       return BT_FIELD_STATUS_OK;
+       return BT_FUNC_STATUS_OK;
 }
 
-enum bt_field_status bt_field_string_clear(struct bt_field *field)
+void bt_field_string_clear(struct bt_field *field)
 {
        BT_ASSERT_PRE_NON_NULL(field, "Field");
        BT_ASSERT_PRE_FIELD_HOT(field, "Field");
        BT_ASSERT_PRE_FIELD_HAS_CLASS_TYPE(field,
                BT_FIELD_CLASS_TYPE_STRING, "Field");
        clear_string_field(field);
-       return BT_FIELD_STATUS_OK;
 }
 
 uint64_t bt_field_array_get_length(const struct bt_field *field)
@@ -697,10 +708,10 @@ uint64_t bt_field_array_get_length(const struct bt_field *field)
        return array_field->length;
 }
 
-enum bt_field_status bt_field_dynamic_array_set_length(struct bt_field *field,
-               uint64_t length)
+enum bt_field_dynamic_array_set_length_status bt_field_dynamic_array_set_length(
+               struct bt_field *field, uint64_t length)
 {
-       int ret = BT_FIELD_STATUS_OK;
+       int ret = BT_FUNC_STATUS_OK;
        struct bt_field_array *array_field = (void *) field;
 
        BT_ASSERT_PRE_NON_NULL(field, "Field");
@@ -722,11 +733,12 @@ enum bt_field_status bt_field_dynamic_array_set_length(struct bt_field *field,
                                array_fc->element_fc);
 
                        if (!elem_field) {
-                               BT_LIB_LOGE("Cannot create element field for "
+                               BT_LIB_LOGE_APPEND_CAUSE(
+                                       "Cannot create element field for "
                                        "dynamic array field: "
                                        "index=%" PRIu64 ", "
                                        "%![array-field-]+f", i, field);
-                               ret = BT_FIELD_STATUS_NOMEM;
+                               ret = BT_FUNC_STATUS_MEMORY_ERROR;
                                goto end;
                        }
 
@@ -861,7 +873,8 @@ const struct bt_field *bt_field_variant_borrow_selected_option_field_const(
        return borrow_variant_field_selected_option_field((void *) field);
 }
 
-enum bt_field_status bt_field_variant_select_option_field(
+enum bt_field_variant_select_option_field_status
+bt_field_variant_select_option_field(
                struct bt_field *field, uint64_t index)
 {
        struct bt_field_variant *var_field = (void *) field;
@@ -873,7 +886,7 @@ enum bt_field_status bt_field_variant_select_option_field(
        BT_ASSERT_PRE_VALID_INDEX(index, var_field->fields->len);
        var_field->selected_field = var_field->fields->pdata[index];
        var_field->selected_index = index;
-       return BT_FIELD_STATUS_OK;
+       return BT_FUNC_STATUS_OK;
 }
 
 uint64_t bt_field_variant_get_selected_option_field_index(
This page took 0.028179 seconds and 4 git commands to generate.