lib: make trace IR API const-correct
[babeltrace.git] / plugins / lttng-utils / copy.c
index 12e3d89c02d1be2e726d60c57bd238c44ba12b9a..adb6619e184f365fbdad592c26fefb3846d013a5 100644 (file)
 #include "logging.h"
 
 #include <inttypes.h>
-#include <assert.h>
+#include <babeltrace/assert-internal.h>
 #include <babeltrace/babeltrace.h>
 
 #include <ctfcopytrace.h>
 #include "debug-info.h"
 
 static
-struct bt_stream *insert_new_stream(
+const struct bt_stream *insert_new_stream(
                struct debug_info_iterator *debug_it,
-               struct bt_stream *stream,
+               const struct bt_stream *stream,
                struct debug_info_trace *di_trace);
 
 static
-void unref_stream(struct bt_stream *stream)
+void unref_stream(const struct bt_stream *stream)
 {
-       bt_put(stream);
+       bt_object_put_ref(stream);
 }
 
 static
-void unref_packet(struct bt_packet *packet)
+void unref_packet(const struct bt_packet *packet)
 {
-       bt_put(packet);
+       bt_object_put_ref(packet);
 }
 
 static
-void unref_stream_class(struct bt_stream_class *stream_class)
+void unref_stream_class(const struct bt_stream_class *stream_class)
 {
-       bt_put(stream_class);
+       bt_object_put_ref(stream_class);
 }
 
 static
@@ -73,19 +73,19 @@ void destroy_stream_state_key(gpointer key)
 }
 
 static
-struct bt_field *get_payload_field(FILE *err,
-               struct bt_event *event, const char *field_name)
+const struct bt_field *get_payload_field(FILE *err,
+               const struct bt_event *event, const char *field_name)
 {
-       struct bt_field *field = NULL, *payload = NULL;
-       struct bt_field_type *payload_type = NULL;
+       const struct bt_field *field = NULL, *payload = NULL;
+       const struct bt_field_class *payload_class = NULL;
 
        payload = bt_event_get_payload(event, NULL);
-       assert(payload);
+       BT_ASSERT(payload);
 
-       payload_type = bt_field_get_type(payload);
-       assert(payload_type);
+       payload_class = bt_field_get_class(payload);
+       BT_ASSERT(payload_class);
 
-       if (bt_field_type_get_type_id(payload_type) != BT_FIELD_TYPE_ID_STRUCT) {
+       if (bt_field_class_id(payload_class) != BT_FIELD_CLASS_TYPE_STRUCT) {
                BT_LOGE("Wrong type, expected struct: field-name=\"%s\"",
                                field_name);
                goto end;
@@ -94,27 +94,27 @@ struct bt_field *get_payload_field(FILE *err,
        field = bt_field_structure_get_field_by_name(payload, field_name);
 
 end:
-       bt_put(payload_type);
-       bt_put(payload);
+       bt_object_put_ref(payload_class);
+       bt_object_put_ref(payload);
        return field;
 }
 
 static
-struct bt_field *get_stream_event_context_field(FILE *err,
-               struct bt_event *event, const char *field_name)
+const struct bt_field *get_stream_event_context_field(FILE *err,
+               const struct bt_event *event, const char *field_name)
 {
-       struct bt_field *field = NULL, *sec = NULL;
-       struct bt_field_type *sec_type = NULL;
+       const struct bt_field *field = NULL, *sec = NULL;
+       const struct bt_field_class *sec_class = NULL;
 
        sec = bt_event_get_stream_event_context(event);
        if (!sec) {
                goto end;
        }
 
-       sec_type = bt_field_get_type(sec);
-       assert(sec_type);
+       sec_class = bt_field_get_class(sec);
+       BT_ASSERT(sec_class);
 
-       if (bt_field_type_get_type_id(sec_type) != BT_FIELD_TYPE_ID_STRUCT) {
+       if (bt_field_class_id(sec_class) != BT_FIELD_CLASS_TYPE_STRUCT) {
                BT_LOGE("Wrong type, expected struct, field-name=\"%s\"",
                                field_name);
                goto end;
@@ -123,35 +123,35 @@ struct bt_field *get_stream_event_context_field(FILE *err,
        field = bt_field_structure_get_field_by_name(sec, field_name);
 
 end:
-       bt_put(sec_type);
-       bt_put(sec);
+       bt_object_put_ref(sec_class);
+       bt_object_put_ref(sec);
        return field;
 }
 
 BT_HIDDEN
 int get_stream_event_context_unsigned_int_field_value(FILE *err,
-               struct bt_event *event, const char *field_name,
+               const struct bt_event *event, const char *field_name,
                uint64_t *value)
 {
        int ret;
-       struct bt_field *field = NULL;
-       struct bt_field_type *field_type = NULL;
+       const struct bt_field *field = NULL;
+       const struct bt_field_class *field_class = NULL;
 
        field = get_stream_event_context_field(err, event, field_name);
        if (!field) {
                goto error;
        }
 
-       field_type = bt_field_get_type(field);
-       assert(field_type);
+       field_class = bt_field_get_class(field);
+       BT_ASSERT(field_class);
 
-       if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_INTEGER) {
+       if (bt_field_class_id(field_class) != BT_FIELD_CLASS_TYPE_INTEGER) {
                BT_LOGE("Wrong type, expected integer: field-name=\"%s\"",
                                field_name);
                goto error;
        }
 
-       if (bt_ctf_field_type_integer_get_signed(field_type) != 0) {
+       if (bt_ctf_field_class_integer_get_signed(field_class) != 0) {
                BT_LOGE("Wrong type, expected unsigned integer: field-name=\"%s\"",
                                field_name);
                goto error;
@@ -168,17 +168,17 @@ int get_stream_event_context_unsigned_int_field_value(FILE *err,
 error:
        ret = -1;
 end:
-       bt_put(field_type);
-       bt_put(field);
+       bt_object_put_ref(field_class);
+       bt_object_put_ref(field);
        return ret;
 }
 
 BT_HIDDEN
-int get_stream_event_context_int_field_value(FILE *err, struct bt_event *event,
+int get_stream_event_context_int_field_value(FILE *err, const struct bt_event *event,
                const char *field_name, int64_t *value)
 {
-       struct bt_field *field = NULL;
-       struct bt_field_type *field_type = NULL;
+       const struct bt_field *field = NULL;
+       const struct bt_field_class *field_class = NULL;
        int ret;
 
        field = get_stream_event_context_field(err, event, field_name);
@@ -186,15 +186,15 @@ int get_stream_event_context_int_field_value(FILE *err, struct bt_event *event,
                goto error;
        }
 
-       field_type = bt_field_get_type(field);
-       assert(field_type);
+       field_class = bt_field_get_class(field);
+       BT_ASSERT(field_class);
 
-       if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_INTEGER) {
+       if (bt_field_class_id(field_class) != BT_FIELD_CLASS_TYPE_INTEGER) {
                BT_LOGE("Wrong type, expected integer: field-name=\"%s\"", field_name);
                goto error;
        }
 
-       if (bt_ctf_field_type_integer_get_signed(field_type) != 1) {
+       if (bt_ctf_field_class_integer_get_signed(field_class) != 1) {
                BT_LOGE("Wrong type, expected signed integer: field-name=\"%s\"",
                                field_name);
                goto error;
@@ -206,18 +206,18 @@ int get_stream_event_context_int_field_value(FILE *err, struct bt_event *event,
 error:
        ret = -1;
 end:
-       bt_put(field_type);
-       bt_put(field);
+       bt_object_put_ref(field_class);
+       bt_object_put_ref(field);
        return ret;
 }
 
 BT_HIDDEN
 int get_payload_unsigned_int_field_value(FILE *err,
-               struct bt_event *event, const char *field_name,
+               const struct bt_event *event, const char *field_name,
                uint64_t *value)
 {
-       struct bt_field *field = NULL;
-       struct bt_field_type *field_type = NULL;
+       const struct bt_field *field = NULL;
+       const struct bt_field_class *field_class = NULL;
        int ret;
 
        field = get_payload_field(err, event, field_name);
@@ -226,16 +226,16 @@ int get_payload_unsigned_int_field_value(FILE *err,
                goto error;
        }
 
-       field_type = bt_field_get_type(field);
-       assert(field_type);
+       field_class = bt_field_get_class(field);
+       BT_ASSERT(field_class);
 
-       if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_INTEGER) {
+       if (bt_field_class_id(field_class) != BT_FIELD_CLASS_TYPE_INTEGER) {
                BT_LOGE("Wrong type, expected integer: field-name=\"%s\"",
                                field_name);
                goto error;
        }
 
-       if (bt_ctf_field_type_integer_get_signed(field_type) != 0) {
+       if (bt_ctf_field_class_integer_get_signed(field_class) != 0) {
                BT_LOGE("Wrong type, expected unsigned integer: field-name=\"%s\"",
                                field_name);
                goto error;
@@ -252,17 +252,17 @@ int get_payload_unsigned_int_field_value(FILE *err,
 error:
        ret = -1;
 end:
-       bt_put(field_type);
-       bt_put(field);
+       bt_object_put_ref(field_class);
+       bt_object_put_ref(field);
        return ret;
 }
 
 BT_HIDDEN
-int get_payload_int_field_value(FILE *err, struct bt_event *event,
+int get_payload_int_field_value(FILE *err, const struct bt_event *event,
                const char *field_name, int64_t *value)
 {
-       struct bt_field *field = NULL;
-       struct bt_field_type *field_type = NULL;
+       const struct bt_field *field = NULL;
+       const struct bt_field_class *field_class = NULL;
        int ret;
 
        field = get_payload_field(err, event, field_name);
@@ -271,15 +271,15 @@ int get_payload_int_field_value(FILE *err, struct bt_event *event,
                goto error;
        }
 
-       field_type = bt_field_get_type(field);
-       assert(field_type);
+       field_class = bt_field_get_class(field);
+       BT_ASSERT(field_class);
 
-       if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_INTEGER) {
+       if (bt_field_class_id(field_class) != BT_FIELD_CLASS_TYPE_INTEGER) {
                BT_LOGE("Wrong type, expected integer: field-name=\"%s\"", field_name);
                goto error;
        }
 
-       if (bt_ctf_field_type_integer_get_signed(field_type) != 1) {
+       if (bt_ctf_field_class_integer_get_signed(field_class) != 1) {
                BT_LOGE("Wrong type, expected signed integer field-name=\"%s\"",
                                field_name);
                goto error;
@@ -296,18 +296,18 @@ int get_payload_int_field_value(FILE *err, struct bt_event *event,
 error:
        ret = -1;
 end:
-       bt_put(field_type);
-       bt_put(field);
+       bt_object_put_ref(field_class);
+       bt_object_put_ref(field);
        return ret;
 }
 
 BT_HIDDEN
 int get_payload_string_field_value(FILE *err,
-               struct bt_event *event, const char *field_name,
+               const struct bt_event *event, const char *field_name,
                const char **value)
 {
-       struct bt_field *field = NULL;
-       struct bt_field_type *field_type = NULL;
+       const struct bt_field *field = NULL;
+       const struct bt_field_class *field_class = NULL;
        int ret;
 
        /*
@@ -318,10 +318,10 @@ int get_payload_string_field_value(FILE *err,
                goto error;
        }
 
-       field_type = bt_field_get_type(field);
-       assert(field_type);
+       field_class = bt_field_get_class(field);
+       BT_ASSERT(field_class);
 
-       if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_STRING) {
+       if (bt_field_class_id(field_class) != BT_FIELD_CLASS_TYPE_STRING) {
                BT_LOGE("Wrong type, expected string: field-name=\"%s\"",
                                field_name);
                goto error;
@@ -340,19 +340,19 @@ int get_payload_string_field_value(FILE *err,
 error:
        ret = -1;
 end:
-       bt_put(field_type);
-       bt_put(field);
+       bt_object_put_ref(field_class);
+       bt_object_put_ref(field);
        return ret;
 }
 
 BT_HIDDEN
 int get_payload_build_id_field_value(FILE *err,
-               struct bt_event *event, const char *field_name,
+               const struct bt_event *event, const char *field_name,
                uint8_t **build_id, uint64_t *build_id_len)
 {
-       struct bt_field *field = NULL, *seq_len = NULL;
-       struct bt_field_type *field_type = NULL;
-       struct bt_field *seq_field = NULL;
+       const struct bt_field *field = NULL, *seq_len = NULL;
+       const struct bt_field_class *field_class = NULL;
+       const struct bt_field *seq_field = NULL;
        uint64_t i;
        int ret;
 
@@ -364,17 +364,17 @@ int get_payload_build_id_field_value(FILE *err,
                goto error;
        }
 
-       field_type = bt_field_get_type(field);
-       assert(field_type);
+       field_class = bt_field_get_class(field);
+       BT_ASSERT(field_class);
 
-       if (bt_field_type_get_type_id(field_type) != BT_FIELD_TYPE_ID_SEQUENCE) {
+       if (bt_field_class_id(field_class) != BT_FIELD_CLASS_TYPE_SEQUENCE) {
                BT_LOGE("Wrong type, expected sequence: field-name=\"%s\"", field_name);
                goto error;
        }
-       BT_PUT(field_type);
+       BT_OBJECT_PUT_REF_AND_RESET(field_class);
 
        seq_len = bt_field_sequence_get_length(field);
-       assert(seq_len);
+       BT_ASSERT(seq_len);
 
        ret = bt_field_unsigned_integer_get_value(seq_len, build_id_len);
        if (ret) {
@@ -382,7 +382,7 @@ int get_payload_build_id_field_value(FILE *err,
                                field_name);
                goto error;
        }
-       BT_PUT(seq_len);
+       BT_OBJECT_PUT_REF_AND_RESET(seq_len);
 
        *build_id = g_new0(uint8_t, *build_id_len);
        if (!*build_id) {
@@ -407,7 +407,7 @@ int get_payload_build_id_field_value(FILE *err,
                        goto error;
                }
 
-               BT_PUT(seq_field);
+               BT_OBJECT_PUT_REF_AND_RESET(seq_field);
                (*build_id)[i] = (uint8_t) tmp;
        }
        ret = 0;
@@ -417,14 +417,14 @@ error:
        g_free(*build_id);
        ret = -1;
 end:
-       bt_put(field_type);
-       bt_put(field);
+       bt_object_put_ref(field_class);
+       bt_object_put_ref(field);
        return ret;
 }
 
 static
 struct debug_info *lookup_trace_debug_info(struct debug_info_iterator *debug_it,
-               struct bt_trace *writer_trace,
+               const struct bt_trace *writer_trace,
                struct debug_info_trace *di_trace)
 {
        return (struct debug_info *) g_hash_table_lookup(
@@ -434,7 +434,7 @@ struct debug_info *lookup_trace_debug_info(struct debug_info_iterator *debug_it,
 
 static
 struct debug_info *insert_new_debug_info(struct debug_info_iterator *debug_it,
-               struct bt_trace *writer_trace,
+               const struct bt_trace *writer_trace,
                struct debug_info_trace *di_trace)
 {
        struct debug_info *debug_info = NULL;
@@ -448,14 +448,13 @@ struct debug_info *insert_new_debug_info(struct debug_info_iterator *debug_it,
        if (!field) {
                goto end;
        }
-       ret = bt_value_string_get(field, &str_value);
-       assert(ret == BT_VALUE_STATUS_OK);
+       str_value = bt_value_string_get(field);
 
        /* Domain not ust, no debug info */
        if (strcmp(str_value, "ust") != 0) {
                goto end;
        }
-       BT_PUT(field);
+       BT_OBJECT_PUT_REF_AND_RESET(field);
 
        /* No tracer_name, no debug info */
        field = bt_trace_get_environment_field_value_by_name(writer_trace,
@@ -464,14 +463,13 @@ struct debug_info *insert_new_debug_info(struct debug_info_iterator *debug_it,
        if (!field) {
                goto end;
        }
-       ret = bt_value_string_get(field, &str_value);
-       assert(ret == BT_VALUE_STATUS_OK);
+       str_value = bt_value_string_get(field);
 
        /* Tracer_name not lttng-ust, no debug info */
        if (strcmp(str_value, "lttng-ust") != 0) {
                goto end;
        }
-       BT_PUT(field);
+       BT_OBJECT_PUT_REF_AND_RESET(field);
 
        debug_info = debug_info_create(debug_it->debug_info_component);
        if (!debug_info) {
@@ -483,13 +481,13 @@ struct debug_info *insert_new_debug_info(struct debug_info_iterator *debug_it,
                        debug_info);
 
 end:
-       bt_put(field);
+       bt_object_put_ref(field);
        return debug_info;
 }
 
 static
 struct debug_info *get_trace_debug_info(struct debug_info_iterator *debug_it,
-               struct bt_trace *writer_trace,
+               const struct bt_trace *writer_trace,
                struct debug_info_trace *di_trace)
 {
        struct debug_info *debug_info;
@@ -507,7 +505,7 @@ end:
 
 static
 struct debug_info_trace *lookup_trace(struct debug_info_iterator *debug_it,
-               struct bt_trace *trace)
+               const struct bt_trace *trace)
 {
        return (struct debug_info_trace *) g_hash_table_lookup(
                        debug_it->trace_map,
@@ -517,7 +515,7 @@ struct debug_info_trace *lookup_trace(struct debug_info_iterator *debug_it,
 static
 enum debug_info_stream_state *insert_new_stream_state(
                struct debug_info_iterator *debug_it,
-               struct debug_info_trace *di_trace, struct bt_stream *stream)
+               struct debug_info_trace *di_trace, const struct bt_stream *stream)
 {
        enum debug_info_stream_state *v = NULL;
 
@@ -588,19 +586,19 @@ void debug_info_close_trace(struct debug_info_iterator *debug_it,
 
 static
 int sync_event_classes(struct debug_info_iterator *debug_it,
-               struct bt_stream *stream,
-               struct bt_stream *writer_stream)
+               const struct bt_stream *stream,
+               const struct bt_stream *writer_stream)
 {
        int int_ret;
-       struct bt_stream_class *stream_class = NULL,
+       const struct bt_stream_class *stream_class = NULL,
                                   *writer_stream_class = NULL;
        enum bt_component_status ret;
 
        stream_class = bt_stream_get_class(stream);
-       assert(stream_class);
+       BT_ASSERT(stream_class);
 
        writer_stream_class = bt_stream_get_class(writer_stream);
-       assert(writer_stream_class);
+       BT_ASSERT(writer_stream_class);
 
        ret = ctf_copy_event_classes(debug_it->err, stream_class,
                        writer_stream_class);
@@ -615,18 +613,18 @@ int sync_event_classes(struct debug_info_iterator *debug_it,
 error:
        int_ret = -1;
 end:
-       bt_put(stream_class);
-       bt_put(writer_stream_class);
+       bt_object_put_ref(stream_class);
+       bt_object_put_ref(writer_stream_class);
        return int_ret;
 }
 
 static
-void trace_is_static_listener(struct bt_trace *trace, void *data)
+void trace_is_static_listener(const struct bt_trace *trace, void *data)
 {
        struct debug_info_trace *di_trace = data;
        int trace_completed = 1, ret, nr_stream, i;
-       struct bt_stream *stream = NULL, *writer_stream = NULL;
-       struct bt_trace *writer_trace = di_trace->writer_trace;
+       const struct bt_stream *stream = NULL, *writer_stream = NULL;
+       const struct bt_trace *writer_trace = di_trace->writer_trace;
 
        /*
         * When the trace becomes static, make sure that we have all
@@ -636,18 +634,18 @@ void trace_is_static_listener(struct bt_trace *trace, void *data)
        nr_stream = bt_trace_get_stream_count(trace);
        for (i = 0; i < nr_stream; i++) {
                stream = bt_trace_get_stream_by_index(trace, i);
-               assert(stream);
+               BT_ASSERT(stream);
 
                writer_stream = bt_trace_get_stream_by_index(writer_trace, i);
-               assert(writer_stream);
+               BT_ASSERT(writer_stream);
 
                ret = sync_event_classes(di_trace->debug_it, stream, writer_stream);
                if (ret) {
                        BT_LOGE_STR("Failed to synchronize the event classes.");
                        goto error;
                }
-               BT_PUT(stream);
-               BT_PUT(writer_stream);
+               BT_OBJECT_PUT_REF_AND_RESET(stream);
+               BT_OBJECT_PUT_REF_AND_RESET(writer_stream);
        }
 
        bt_trace_set_is_static(di_trace->writer_trace);
@@ -662,18 +660,18 @@ void trace_is_static_listener(struct bt_trace *trace, void *data)
        }
 
 error:
-       bt_put(writer_stream);
-       bt_put(stream);
+       bt_object_put_ref(writer_stream);
+       bt_object_put_ref(stream);
 }
 
 static
 struct debug_info_trace *insert_new_trace(struct debug_info_iterator *debug_it,
-               struct bt_stream *stream) {
-       struct bt_trace *writer_trace = NULL;
+               const struct bt_stream *stream) {
+       const struct bt_trace *writer_trace = NULL;
        struct debug_info_trace *di_trace = NULL;
-       struct bt_trace *trace = NULL;
-       struct bt_stream_class *stream_class = NULL;
-       struct bt_stream *writer_stream = NULL;
+       const struct bt_trace *trace = NULL;
+       const struct bt_stream_class *stream_class = NULL;
+       const struct bt_stream *writer_stream = NULL;
        int ret, nr_stream, i;
 
        writer_trace = bt_trace_create();
@@ -683,10 +681,10 @@ struct debug_info_trace *insert_new_trace(struct debug_info_iterator *debug_it,
        }
 
        stream_class = bt_stream_get_class(stream);
-       assert(stream_class);
+       BT_ASSERT(stream_class);
 
        trace = bt_stream_class_get_trace(stream_class);
-       assert(trace);
+       BT_ASSERT(trace);
 
        ret = ctf_copy_trace(debug_it->err, trace, writer_trace);
        if (ret != BT_COMPONENT_STATUS_OK) {
@@ -720,7 +718,7 @@ struct debug_info_trace *insert_new_trace(struct debug_info_iterator *debug_it,
        nr_stream = bt_trace_get_stream_count(trace);
        for (i = 0; i < nr_stream; i++) {
                stream = bt_trace_get_stream_by_index(trace, i);
-               assert(stream);
+               BT_ASSERT(stream);
 
                insert_new_stream_state(debug_it, di_trace, stream);
                writer_stream = insert_new_stream(debug_it, stream, di_trace);
@@ -728,14 +726,14 @@ struct debug_info_trace *insert_new_trace(struct debug_info_iterator *debug_it,
                        BT_LOGE_STR("Failed to insert new stream.");
                        goto error;
                }
-               bt_get(writer_stream);
+               bt_object_get_ref(writer_stream);
                ret = sync_event_classes(debug_it, stream, writer_stream);
                if (ret) {
                        BT_LOGE_STR("Failed to synchronize event classes.");
                        goto error;
                }
-               BT_PUT(writer_stream);
-               BT_PUT(stream);
+               BT_OBJECT_PUT_REF_AND_RESET(writer_stream);
+               BT_OBJECT_PUT_REF_AND_RESET(stream);
        }
 
        /* Check if the trace is already static or register a listener. */
@@ -746,7 +744,7 @@ struct debug_info_trace *insert_new_trace(struct debug_info_iterator *debug_it,
        } else {
                ret = bt_trace_add_is_static_listener(trace,
                                trace_is_static_listener, NULL, di_trace);
-               assert(ret >= 0);
+               BT_ASSERT(ret >= 0);
                di_trace->static_listener_id = ret;
        }
 
@@ -754,34 +752,34 @@ struct debug_info_trace *insert_new_trace(struct debug_info_iterator *debug_it,
        goto end;
 
 error:
-       BT_PUT(writer_trace);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_trace);
        g_free(di_trace);
        di_trace = NULL;
 end:
-       bt_put(stream);
-       bt_put(writer_stream);
-       bt_put(stream_class);
-       bt_put(trace);
+       bt_object_put_ref(stream);
+       bt_object_put_ref(writer_stream);
+       bt_object_put_ref(stream_class);
+       bt_object_put_ref(trace);
        return di_trace;
 }
 
 static
-struct bt_packet *lookup_packet(struct debug_info_iterator *debug_it,
-               struct bt_packet *packet,
+const struct bt_packet *lookup_packet(struct debug_info_iterator *debug_it,
+               const struct bt_packet *packet,
                struct debug_info_trace *di_trace)
 {
-       return (struct bt_packet *) g_hash_table_lookup(
+       return (const struct bt_packet *) g_hash_table_lookup(
                        di_trace->packet_map,
                        (gpointer) packet);
 }
 
 static
-struct bt_packet *insert_new_packet(struct debug_info_iterator *debug_it,
-               struct bt_packet *packet,
-               struct bt_stream *writer_stream,
+const struct bt_packet *insert_new_packet(struct debug_info_iterator *debug_it,
+               const struct bt_packet *packet,
+               const struct bt_stream *writer_stream,
                struct debug_info_trace *di_trace)
 {
-       struct bt_packet *writer_packet;
+       const struct bt_packet *writer_packet;
        int ret;
 
        writer_packet = bt_packet_create(writer_stream);
@@ -801,84 +799,84 @@ struct bt_packet *insert_new_packet(struct debug_info_iterator *debug_it,
        goto end;
 
 error:
-       BT_PUT(writer_packet);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_packet);
 end:
        return writer_packet;
 }
 
 static
 int add_debug_info_fields(FILE *err,
-               struct bt_field_type *writer_event_context_type,
+               const struct bt_field_class *writer_event_context_class,
                struct debug_info_component *component)
 {
-       struct bt_field_type *ip_field = NULL, *debug_field_type = NULL,
-                                *bin_field_type = NULL, *func_field_type = NULL,
-                                *src_field_type = NULL;
+       const struct bt_field_class *ip_field = NULL, *debug_field_class = NULL,
+                                *bin_field_class = NULL, *func_field_class = NULL,
+                                *src_field_class = NULL;
        int ret = 0;
 
-       ip_field = bt_field_type_structure_get_field_type_by_name(
-                       writer_event_context_type, "_ip");
+       ip_field = bt_field_class_structure_get_field_class_by_name(
+                       writer_event_context_class, IP_FIELD_NAME);
        /* No ip field, so no debug info. */
        if (!ip_field) {
                goto end;
        }
-       BT_PUT(ip_field);
+       BT_OBJECT_PUT_REF_AND_RESET(ip_field);
 
-       debug_field_type = bt_field_type_structure_get_field_type_by_name(
-                       writer_event_context_type,
+       debug_field_class = bt_field_class_structure_get_field_class_by_name(
+                       writer_event_context_class,
                        component->arg_debug_info_field_name);
        /* Already existing debug_info field, no need to add it. */
-       if (debug_field_type) {
+       if (debug_field_class) {
                goto end;
        }
 
-       debug_field_type = bt_field_type_structure_create();
-       if (!debug_field_type) {
+       debug_field_class = bt_field_class_structure_create();
+       if (!debug_field_class) {
                BT_LOGE_STR("Failed to create debug_info structure.");
                goto error;
        }
 
-       bin_field_type = bt_field_type_string_create();
-       if (!bin_field_type) {
+       bin_field_class = bt_field_class_string_create();
+       if (!bin_field_class) {
                BT_LOGE_STR("Failed to create string for field=bin.");
                goto error;
        }
 
-       func_field_type = bt_field_type_string_create();
-       if (!func_field_type) {
+       func_field_class = bt_field_class_string_create();
+       if (!func_field_class) {
                BT_LOGE_STR("Failed to create string for field=func.");
                goto error;
        }
 
-       src_field_type = bt_field_type_string_create();
-       if (!src_field_type) {
+       src_field_class = bt_field_class_string_create();
+       if (!src_field_class) {
                BT_LOGE_STR("Failed to create string for field=src.");
                goto error;
        }
 
-       ret = bt_field_type_structure_add_field(debug_field_type,
-                       bin_field_type, "bin");
+       ret = bt_field_class_structure_add_field(debug_field_class,
+                       bin_field_class, "bin");
        if (ret) {
                BT_LOGE_STR("Failed to add a field to debug_info struct: field=bin.");
                goto error;
        }
 
-       ret = bt_field_type_structure_add_field(debug_field_type,
-                       func_field_type, "func");
+       ret = bt_field_class_structure_add_field(debug_field_class,
+                       func_field_class, "func");
        if (ret) {
                BT_LOGE_STR("Failed to add a field to debug_info struct: field=func.");
                goto error;
        }
 
-       ret = bt_field_type_structure_add_field(debug_field_type,
-                       src_field_type, "src");
+       ret = bt_field_class_structure_add_field(debug_field_class,
+                       src_field_class, "src");
        if (ret) {
                BT_LOGE_STR("Failed to add a field to debug_info struct: field=src.");
                goto error;
        }
 
-       ret = bt_field_type_structure_add_field(writer_event_context_type,
-                       debug_field_type, component->arg_debug_info_field_name);
+       ret = bt_field_class_structure_add_field(writer_event_context_class,
+                       debug_field_class, component->arg_debug_info_field_name);
        if (ret) {
                BT_LOGE_STR("Failed to add debug_info field to event_context.");
                goto error;
@@ -888,39 +886,39 @@ int add_debug_info_fields(FILE *err,
        goto end;
 
 error:
-       BT_PUT(debug_field_type);
+       BT_OBJECT_PUT_REF_AND_RESET(debug_field_class);
        ret = -1;
 end:
-       bt_put(src_field_type);
-       bt_put(func_field_type);
-       bt_put(bin_field_type);
-       bt_put(debug_field_type);
+       bt_object_put_ref(src_field_class);
+       bt_object_put_ref(func_field_class);
+       bt_object_put_ref(bin_field_class);
+       bt_object_put_ref(debug_field_class);
        return ret;
 }
 
 static
-int create_debug_info_event_context_type(FILE *err,
-               struct bt_field_type *event_context_type,
-               struct bt_field_type *writer_event_context_type,
+int create_debug_info_event_context_class(FILE *err,
+               const struct bt_field_class *event_context_class,
+               const struct bt_field_class *writer_event_context_class,
                struct debug_info_component *component)
 {
        int ret, nr_fields, i;
 
-       nr_fields = bt_field_type_structure_get_field_count(event_context_type);
+       nr_fields = bt_field_class_structure_get_field_count(event_context_class);
        for (i = 0; i < nr_fields; i++) {
-               struct bt_field_type *field_type = NULL;
+               const struct bt_field_class *field_class = NULL;
                const char *field_name;
 
-               if (bt_field_type_structure_get_field_by_index(event_context_type,
-                                       &field_name, &field_type, i) < 0) {
+               if (bt_field_class_structure_get_field_by_index(event_context_class,
+                                       &field_name, &field_class, i) < 0) {
                        BT_LOGE("Failed to get a field from the event-context: field-name=\"%s\"",
                                        field_name);
                        goto error;
                }
 
-               ret = bt_field_type_structure_add_field(writer_event_context_type,
-                               field_type, field_name);
-               BT_PUT(field_type);
+               ret = bt_field_class_structure_add_field(writer_event_context_class,
+                               field_class, field_name);
+               BT_OBJECT_PUT_REF_AND_RESET(field_class);
                if (ret) {
                        BT_LOGE("Failed to add a field to the event-context: field-name=\"%s\"",
                                        field_name);
@@ -928,7 +926,7 @@ int create_debug_info_event_context_type(FILE *err,
                }
        }
 
-       ret = add_debug_info_fields(err, writer_event_context_type,
+       ret = add_debug_info_fields(err, writer_event_context_class,
                        component);
        goto end;
 
@@ -939,14 +937,14 @@ end:
 }
 
 static
-struct bt_stream_class *copy_stream_class_debug_info(FILE *err,
-               struct bt_stream_class *stream_class,
-               struct bt_trace *writer_trace,
+const struct bt_stream_class *copy_stream_class_debug_info(FILE *err,
+               const struct bt_stream_class *stream_class,
+               const struct bt_trace *writer_trace,
                struct debug_info_component *component)
 {
-       struct bt_field_type *type = NULL;
-       struct bt_stream_class *writer_stream_class = NULL;
-       struct bt_field_type *writer_event_context_type = NULL;
+       const struct bt_field_class *cls = NULL;
+       const struct bt_stream_class *writer_stream_class = NULL;
+       const struct bt_field_class *writer_event_context_class = NULL;
        int ret_int;
        const char *name = bt_stream_class_get_name(stream_class);
 
@@ -956,15 +954,15 @@ struct bt_stream_class *copy_stream_class_debug_info(FILE *err,
                goto error;
        }
 
-       type = bt_stream_class_get_packet_context_type(stream_class);
+       type = bt_stream_class_get_packet_context_class(stream_class);
        if (type) {
-               ret_int = bt_stream_class_set_packet_context_type(
+               ret_int = bt_stream_class_set_packet_context_class(
                                writer_stream_class, type);
                if (ret_int < 0) {
                        BT_LOGE_STR("Failed to set packet_context type.");
                        goto error;
                }
-               BT_PUT(type);
+               BT_OBJECT_PUT_REF_AND_RESET(type);
        }
 
        type = bt_stream_class_get_event_header_type(stream_class);
@@ -975,40 +973,40 @@ struct bt_stream_class *copy_stream_class_debug_info(FILE *err,
                        BT_LOGE_STR("Failed to set event_header type.");
                        goto error;
                }
-               BT_PUT(type);
+               BT_OBJECT_PUT_REF_AND_RESET(type);
        }
 
-       type = bt_stream_class_get_event_context_type(stream_class);
+       type = bt_stream_class_get_event_context_class(stream_class);
        if (type) {
-               writer_event_context_type = bt_field_type_structure_create();
-               if (!writer_event_context_type) {
+               writer_event_context_class = bt_field_class_structure_create();
+               if (!writer_event_context_class) {
                        BT_LOGE_STR("Failed to create writer_event_context struct type.");
                        goto error;
                }
-               ret_int = create_debug_info_event_context_type(err, type,
-                               writer_event_context_type, component);
+               ret_int = create_debug_info_event_context_class(err, type,
+                               writer_event_context_class, component);
                if (ret_int) {
                        BT_LOGE_STR("Failed to create debug_info event_context type.");
                        goto error;
                }
-               BT_PUT(type);
+               BT_OBJECT_PUT_REF_AND_RESET(type);
 
-               ret_int = bt_stream_class_set_event_context_type(
-                               writer_stream_class, writer_event_context_type);
+               ret_int = bt_stream_class_set_event_context_class(
+                               writer_stream_class, writer_event_context_class);
                if (ret_int < 0) {
                        BT_LOGE_STR("Failed to set event_context type.");
                        goto error;
                }
-               BT_PUT(writer_event_context_type);
+               BT_OBJECT_PUT_REF_AND_RESET(writer_event_context_class);
        }
 
        goto end;
 
 error:
-       BT_PUT(writer_stream_class);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_stream_class);
 end:
-       bt_put(writer_event_context_type);
-       bt_put(type);
+       bt_object_put_ref(writer_event_context_class);
+       bt_object_put_ref(type);
        return writer_stream_class;
 }
 
@@ -1018,31 +1016,31 @@ end:
  * to update the integers mapping to a clock.
  */
 static
-int add_clock_classes(FILE *err, struct bt_trace *writer_trace,
-               struct bt_stream_class *writer_stream_class,
-               struct bt_trace *trace)
+int add_clock_classes(FILE *err, const struct bt_trace *writer_trace,
+               const struct bt_stream_class *writer_stream_class,
+               const struct bt_trace *trace)
 {
        int ret, clock_class_count, i;
 
        clock_class_count = bt_trace_get_clock_class_count(trace);
 
        for (i = 0; i < clock_class_count; i++) {
-               struct bt_clock_class *clock_class =
+               const struct bt_clock_class *clock_class =
                        bt_trace_get_clock_class_by_index(trace, i);
-               struct bt_clock_class *existing_clock_class = NULL;
+               const struct bt_clock_class *existing_clock_class = NULL;
 
-               assert(clock_class);
+               BT_ASSERT(clock_class);
 
                existing_clock_class = bt_trace_get_clock_class_by_name(
                        writer_trace, bt_clock_class_get_name(clock_class));
-               bt_put(existing_clock_class);
+               bt_object_put_ref(existing_clock_class);
                if (existing_clock_class) {
-                       bt_put(clock_class);
+                       bt_object_put_ref(clock_class);
                        continue;
                }
 
                ret = bt_trace_add_clock_class(writer_trace, clock_class);
-               BT_PUT(clock_class);
+               BT_OBJECT_PUT_REF_AND_RESET(clock_class);
                if (ret != 0) {
                        BT_LOGE_STR("Failed to add clock_class.");
                        goto error;
@@ -1060,18 +1058,18 @@ end:
 }
 
 static
-struct bt_stream_class *insert_new_stream_class(
+const struct bt_stream_class *insert_new_stream_class(
                struct debug_info_iterator *debug_it,
-               struct bt_stream_class *stream_class)
+               const struct bt_stream_class *stream_class)
 {
-       struct bt_stream_class *writer_stream_class = NULL;
-       struct bt_trace *trace, *writer_trace = NULL;
+       const struct bt_stream_class *writer_stream_class = NULL;
+       const struct bt_trace *trace, *writer_trace = NULL;
        struct debug_info_trace *di_trace;
        enum bt_component_status ret;
        int int_ret;
 
        trace = bt_stream_class_get_trace(stream_class);
-       assert(trace);
+       BT_ASSERT(trace);
 
        di_trace = lookup_trace(debug_it, trace);
        if (!di_trace) {
@@ -1080,7 +1078,7 @@ struct bt_stream_class *insert_new_stream_class(
                goto error;
        }
        writer_trace = di_trace->writer_trace;
-       bt_get(writer_trace);
+       bt_object_get_ref(writer_trace);
 
        writer_stream_class = copy_stream_class_debug_info(debug_it->err, stream_class,
                        writer_trace, debug_it->debug_info_component);
@@ -1108,26 +1106,26 @@ struct bt_stream_class *insert_new_stream_class(
        goto end;
 
 error:
-       BT_PUT(writer_stream_class);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_stream_class);
 end:
-       bt_put(trace);
-       bt_put(writer_trace);
+       bt_object_put_ref(trace);
+       bt_object_put_ref(writer_trace);
        return writer_stream_class;
 }
 
 static
-struct bt_stream *insert_new_stream(
+const struct bt_stream *insert_new_stream(
                struct debug_info_iterator *debug_it,
-               struct bt_stream *stream,
+               const struct bt_stream *stream,
                struct debug_info_trace *di_trace)
 {
-       struct bt_stream *writer_stream = NULL;
-       struct bt_stream_class *stream_class = NULL;
-       struct bt_stream_class *writer_stream_class = NULL;
+       const struct bt_stream *writer_stream = NULL;
+       const struct bt_stream_class *stream_class = NULL;
+       const struct bt_stream_class *writer_stream_class = NULL;
        int64_t id;
 
        stream_class = bt_stream_get_class(stream);
-       assert(stream_class);
+       BT_ASSERT(stream_class);
 
        writer_stream_class = g_hash_table_lookup(
                        di_trace->stream_class_map,
@@ -1141,7 +1139,7 @@ struct bt_stream *insert_new_stream(
                        goto error;
                }
        }
-       bt_get(writer_stream_class);
+       bt_object_get_ref(writer_stream_class);
 
        id = bt_stream_get_id(stream);
        if (id < 0) {
@@ -1164,26 +1162,26 @@ struct bt_stream *insert_new_stream(
        goto end;
 
 error:
-       BT_PUT(writer_stream);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_stream);
 end:
-       bt_put(stream_class);
-       bt_put(writer_stream_class);
+       bt_object_put_ref(stream_class);
+       bt_object_put_ref(writer_stream_class);
        return writer_stream;
 }
 
 static
-struct bt_stream *lookup_stream(struct debug_info_iterator *debug_it,
-               struct bt_stream *stream,
+const struct bt_stream *lookup_stream(struct debug_info_iterator *debug_it,
+               const struct bt_stream *stream,
                struct debug_info_trace *di_trace)
 {
-       return (struct bt_stream *) g_hash_table_lookup(
+       return (const struct bt_stream *) g_hash_table_lookup(
                        di_trace->stream_map, (gpointer) stream);
 }
 
 static
-struct bt_event_class *get_event_class(struct debug_info_iterator *debug_it,
-               struct bt_stream_class *writer_stream_class,
-               struct bt_event_class *event_class)
+const struct bt_event_class *get_event_class(struct debug_info_iterator *debug_it,
+               const struct bt_stream_class *writer_stream_class,
+               const struct bt_event_class *event_class)
 {
        return bt_stream_class_get_event_class_by_id(writer_stream_class,
                        bt_event_class_get_id(event_class));
@@ -1192,37 +1190,37 @@ struct bt_event_class *get_event_class(struct debug_info_iterator *debug_it,
 static
 struct debug_info_trace *lookup_di_trace_from_stream(
                struct debug_info_iterator *debug_it,
-               struct bt_stream *stream)
+               const struct bt_stream *stream)
 {
-       struct bt_stream_class *stream_class = NULL;
-       struct bt_trace *trace = NULL;
+       const struct bt_stream_class *stream_class = NULL;
+       const struct bt_trace *trace = NULL;
        struct debug_info_trace *di_trace = NULL;
 
        stream_class = bt_stream_get_class(stream);
-       assert(stream_class);
+       BT_ASSERT(stream_class);
 
        trace = bt_stream_class_get_trace(stream_class);
-       assert(trace);
+       BT_ASSERT(trace);
 
        di_trace = (struct debug_info_trace *) g_hash_table_lookup(
                        debug_it->trace_map, (gpointer) trace);
 
-       BT_PUT(stream_class);
-       BT_PUT(trace);
+       BT_OBJECT_PUT_REF_AND_RESET(stream_class);
+       BT_OBJECT_PUT_REF_AND_RESET(trace);
        return di_trace;
 }
 
 static
-struct bt_stream *get_writer_stream(
+const struct bt_stream *get_writer_stream(
                struct debug_info_iterator *debug_it,
-               struct bt_packet *packet, struct bt_stream *stream)
+               const struct bt_packet *packet, const struct bt_stream *stream)
 {
-       struct bt_stream_class *stream_class = NULL;
-       struct bt_stream *writer_stream = NULL;
+       const struct bt_stream_class *stream_class = NULL;
+       const struct bt_stream *writer_stream = NULL;
        struct debug_info_trace *di_trace = NULL;
 
        stream_class = bt_stream_get_class(stream);
-       assert(stream_class);
+       BT_ASSERT(stream_class);
 
        di_trace = lookup_di_trace_from_stream(debug_it, stream);
        if (!di_trace) {
@@ -1235,30 +1233,30 @@ struct bt_stream *get_writer_stream(
                BT_LOGE_STR("Failed to find existing stream.");
                goto error;
        }
-       bt_get(writer_stream);
+       bt_object_get_ref(writer_stream);
 
        goto end;
 
 error:
-       BT_PUT(writer_stream);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_stream);
 end:
-       bt_put(stream_class);
+       bt_object_put_ref(stream_class);
        return writer_stream;
 }
 
 BT_HIDDEN
-struct bt_packet *debug_info_new_packet(
+const struct bt_packet *debug_info_new_packet(
                struct debug_info_iterator *debug_it,
-               struct bt_packet *packet)
+               const struct bt_packet *packet)
 {
-       struct bt_stream *stream = NULL, *writer_stream = NULL;
-       struct bt_packet *writer_packet = NULL;
-       struct bt_field *packet_context = NULL;
+       const struct bt_stream *stream = NULL, *writer_stream = NULL;
+       const struct bt_packet *writer_packet = NULL;
+       const struct bt_field *packet_context = NULL;
        struct debug_info_trace *di_trace;
        int int_ret;
 
        stream = bt_packet_get_stream(packet);
-       assert(stream);
+       BT_ASSERT(stream);
 
        writer_stream = get_writer_stream(debug_it, packet, stream);
        if (!writer_stream) {
@@ -1279,7 +1277,7 @@ struct bt_packet *debug_info_new_packet(
        writer_packet = lookup_packet(debug_it, packet, di_trace);
        if (writer_packet) {
                g_hash_table_remove(di_trace->packet_map, packet);
-               BT_PUT(writer_packet);
+               BT_OBJECT_PUT_REF_AND_RESET(writer_packet);
        }
 
        writer_packet = insert_new_packet(debug_it, packet, writer_stream,
@@ -1297,32 +1295,32 @@ struct bt_packet *debug_info_new_packet(
                        BT_LOGE_STR("Failed to copy packet context.");
                        goto error;
                }
-               BT_PUT(packet_context);
+               BT_OBJECT_PUT_REF_AND_RESET(packet_context);
        }
 
-       bt_get(writer_packet);
+       bt_object_get_ref(writer_packet);
        goto end;
 
 error:
 
 end:
-       bt_put(packet_context);
-       bt_put(writer_stream);
-       bt_put(stream);
+       bt_object_put_ref(packet_context);
+       bt_object_put_ref(writer_stream);
+       bt_object_put_ref(stream);
        return writer_packet;
 }
 
 BT_HIDDEN
-struct bt_packet *debug_info_close_packet(
+const struct bt_packet *debug_info_close_packet(
                struct debug_info_iterator *debug_it,
-               struct bt_packet *packet)
+               const struct bt_packet *packet)
 {
-       struct bt_packet *writer_packet = NULL;
-       struct bt_stream *stream = NULL;
+       const struct bt_packet *writer_packet = NULL;
+       const struct bt_stream *stream = NULL;
        struct debug_info_trace *di_trace;
 
        stream = bt_packet_get_stream(packet);
-       assert(stream);
+       BT_ASSERT(stream);
 
        di_trace = lookup_di_trace_from_stream(debug_it, stream);
        if (!di_trace) {
@@ -1335,20 +1333,20 @@ struct bt_packet *debug_info_close_packet(
                BT_LOGE_STR("Failed to find existing packet.");
                goto end;
        }
-       bt_get(writer_packet);
+       bt_object_get_ref(writer_packet);
        g_hash_table_remove(di_trace->packet_map, packet);
 
 end:
-       bt_put(stream);
+       bt_object_put_ref(stream);
        return writer_packet;
 }
 
 BT_HIDDEN
-struct bt_stream *debug_info_stream_begin(
+const struct bt_stream *debug_info_stream_begin(
                struct debug_info_iterator *debug_it,
-               struct bt_stream *stream)
+               const struct bt_stream *stream)
 {
-       struct bt_stream *writer_stream = NULL;
+       const struct bt_stream *writer_stream = NULL;
        enum debug_info_stream_state *state;
        struct debug_info_trace *di_trace = NULL;
 
@@ -1385,21 +1383,21 @@ struct bt_stream *debug_info_stream_begin(
        if (!writer_stream) {
                writer_stream = insert_new_stream(debug_it, stream, di_trace);
        }
-       bt_get(writer_stream);
+       bt_object_get_ref(writer_stream);
 
        goto end;
 
 error:
-       BT_PUT(writer_stream);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_stream);
 end:
        return writer_stream;
 }
 
 BT_HIDDEN
-struct bt_stream *debug_info_stream_end(struct debug_info_iterator *debug_it,
-               struct bt_stream *stream)
+const struct bt_stream *debug_info_stream_end(struct debug_info_iterator *debug_it,
+               const struct bt_stream *stream)
 {
-       struct bt_stream *writer_stream = NULL;
+       const struct bt_stream *writer_stream = NULL;
        struct debug_info_trace *di_trace = NULL;
        enum debug_info_stream_state *state;
 
@@ -1418,7 +1416,7 @@ struct bt_stream *debug_info_stream_end(struct debug_info_iterator *debug_it,
         * Take the ref on the stream and keep it until the notification
         * is created.
         */
-       bt_get(writer_stream);
+       bt_object_get_ref(writer_stream);
 
        state = g_hash_table_lookup(di_trace->stream_states, stream);
        if (*state != DEBUG_INFO_ACTIVE_STREAM) {
@@ -1444,7 +1442,7 @@ struct bt_stream *debug_info_stream_end(struct debug_info_iterator *debug_it,
        goto end;
 
 error:
-       BT_PUT(writer_stream);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_stream);
 
 end:
        return writer_stream;
@@ -1452,7 +1450,7 @@ end:
 
 static
 struct debug_info_source *lookup_debug_info(FILE *err,
-               struct bt_event *event,
+               const struct bt_event *event,
                struct debug_info *debug_info)
 {
        int64_t vpid;
@@ -1461,13 +1459,13 @@ struct debug_info_source *lookup_debug_info(FILE *err,
        int ret;
 
        ret = get_stream_event_context_int_field_value(err, event,
-                       "_vpid", &vpid);
+                       VPID_FIELD_NAME, &vpid);
        if (ret) {
                goto end;
        }
 
        ret = get_stream_event_context_unsigned_int_field_value(err, event,
-                       "_ip", &ip);
+                       IP_FIELD_NAME, &ip);
        if (ret) {
                goto end;
        }
@@ -1480,29 +1478,29 @@ end:
 }
 
 static
-int set_debug_info_field(FILE *err, struct bt_field *debug_field,
+int set_debug_info_field(FILE *err, const struct bt_field *debug_field,
                struct debug_info_source *dbg_info_src,
                struct debug_info_component *component)
 {
        int i, nr_fields, ret = 0;
-       struct bt_field_type *debug_field_type = NULL;
-       struct bt_field *field = NULL;
-       struct bt_field_type *field_type = NULL;
+       const struct bt_field_class *debug_field_class = NULL;
+       const struct bt_field *field = NULL;
+       const struct bt_field_class *field_class = NULL;
 
-       debug_field_type = bt_field_get_type(debug_field);
-       assert(debug_field_type);
+       debug_field_class = bt_field_get_class(debug_field);
+       BT_ASSERT(debug_field_class);
 
-       nr_fields = bt_field_type_structure_get_field_count(debug_field_type);
+       nr_fields = bt_field_class_structure_get_field_count(debug_field_class);
        for (i = 0; i < nr_fields; i++) {
                const char *field_name;
 
-               if (bt_field_type_structure_get_field_by_index(debug_field_type,
-                                       &field_name, &field_type, i) < 0) {
+               if (bt_field_class_structure_get_field_by_index(debug_field_class,
+                                       &field_name, &field_class, i) < 0) {
                        BT_LOGE("Failed to get field from debug_info struct: field-name=\"%s\"",
                                        field_name);
                        goto error;
                }
-               BT_PUT(field_type);
+               BT_OBJECT_PUT_REF_AND_RESET(field_class);
 
                field = bt_field_structure_get_field_by_index(debug_field, i);
                if (!strcmp(field_name, "bin")) {
@@ -1549,7 +1547,7 @@ int set_debug_info_field(FILE *err, struct bt_field *debug_field,
                                ret = bt_field_string_set_value(field, "");
                        }
                }
-               BT_PUT(field);
+               BT_OBJECT_PUT_REF_AND_RESET(field);
                if (ret) {
                        BT_LOGE("Failed to set value in debug-info struct: field-name=\"%s\"",
                                        field_name);
@@ -1562,54 +1560,54 @@ int set_debug_info_field(FILE *err, struct bt_field *debug_field,
 error:
        ret = -1;
 end:
-       bt_put(field_type);
-       bt_put(field);
-       bt_put(debug_field_type);
+       bt_object_put_ref(field_class);
+       bt_object_put_ref(field);
+       bt_object_put_ref(debug_field_class);
        return ret;
 }
 
 static
 int copy_set_debug_info_stream_event_context(FILE *err,
-               struct bt_field *event_context,
-               struct bt_event *event,
-               struct bt_event *writer_event,
+               const struct bt_field *event_context,
+               const struct bt_event *event,
+               const struct bt_event *writer_event,
                struct debug_info *debug_info,
                struct debug_info_component *component)
 {
-       struct bt_field_type *writer_event_context_type = NULL,
-                                *event_context_type = NULL;
-       struct bt_field *writer_event_context = NULL;
-       struct bt_field *field = NULL, *copy_field = NULL, *debug_field = NULL;
-       struct bt_field_type *field_type = NULL;
+       const struct bt_field_class *writer_event_context_class = NULL,
+                                *event_context_class = NULL;
+       const struct bt_field *writer_event_context = NULL;
+       const struct bt_field *field = NULL, *copy_field = NULL, *debug_field = NULL;
+       const struct bt_field_class *field_class = NULL;
        struct debug_info_source *dbg_info_src;
        int ret, nr_fields, i;
 
        writer_event_context = bt_event_get_stream_event_context(writer_event);
-       assert(writer_event_context);
+       BT_ASSERT(writer_event_context);
 
-       writer_event_context_type = bt_field_get_type(writer_event_context);
-       assert(writer_event_context_type);
+       writer_event_context_class = bt_field_get_class(writer_event_context);
+       BT_ASSERT(writer_event_context_class);
 
-       event_context_type = bt_field_get_type(event_context);
-       assert(event_context_type);
+       event_context_class = bt_field_get_class(event_context);
+       BT_ASSERT(event_context_class);
 
        /*
         * If it is not a structure, we did not modify it to add the debug info
         * fields, so just assign it as is.
         */
-       if (bt_field_type_get_type_id(writer_event_context_type) != BT_FIELD_TYPE_ID_STRUCT) {
+       if (bt_field_class_id(writer_event_context_class) != BT_FIELD_CLASS_TYPE_STRUCT) {
                ret = bt_event_set_event_context(writer_event, event_context);
                goto end;
        }
 
        dbg_info_src = lookup_debug_info(err, event, debug_info);
 
-       nr_fields = bt_field_type_structure_get_field_count(writer_event_context_type);
+       nr_fields = bt_field_class_structure_get_field_count(writer_event_context_class);
        for (i = 0; i < nr_fields; i++) {
                const char *field_name;
 
-               if (bt_field_type_structure_get_field_by_index(writer_event_context_type,
-                                       &field_name, &field_type, i) < 0) {
+               if (bt_field_class_structure_get_field_by_index(writer_event_context_class,
+                                       &field_name, &field_class, i) < 0) {
                        BT_LOGE("Failed to get field from event-context: field-name=\"%s\"",
                                        field_name);
                        goto error;
@@ -1618,7 +1616,7 @@ int copy_set_debug_info_stream_event_context(FILE *err,
                /*
                 * Prevent illegal access in the event_context.
                 */
-               if (i < bt_field_type_structure_get_field_count(event_context_type)) {
+               if (i < bt_field_class_structure_get_field_count(event_context_class)) {
                        field = bt_field_structure_get_field_by_index(event_context, i);
                }
                /*
@@ -1629,7 +1627,7 @@ int copy_set_debug_info_stream_event_context(FILE *err,
                                !field) {
                        debug_field = bt_field_structure_get_field_by_index(
                                        writer_event_context, i);
-                       assert(debug_field);
+                       BT_ASSERT(debug_field);
 
                        ret = set_debug_info_field(err, debug_field,
                                        dbg_info_src, component);
@@ -1637,7 +1635,7 @@ int copy_set_debug_info_stream_event_context(FILE *err,
                                BT_LOGE_STR("Failed to set debug_info field.");
                                goto error;
                        }
-                       BT_PUT(debug_field);
+                       BT_OBJECT_PUT_REF_AND_RESET(debug_field);
                } else {
                        copy_field = bt_field_copy(field);
                        if (!copy_field) {
@@ -1654,10 +1652,10 @@ int copy_set_debug_info_stream_event_context(FILE *err,
                                                field_name);
                                goto error;
                        }
-                       BT_PUT(copy_field);
+                       BT_OBJECT_PUT_REF_AND_RESET(copy_field);
                }
-               BT_PUT(field_type);
-               BT_PUT(field);
+               BT_OBJECT_PUT_REF_AND_RESET(field_class);
+               BT_OBJECT_PUT_REF_AND_RESET(field);
        }
 
        ret = 0;
@@ -1666,25 +1664,25 @@ int copy_set_debug_info_stream_event_context(FILE *err,
 error:
        ret = -1;
 end:
-       bt_put(event_context_type);
-       bt_put(writer_event_context_type);
-       bt_put(writer_event_context);
-       bt_put(field);
-       bt_put(copy_field);
-       bt_put(debug_field);
-       bt_put(field_type);
+       bt_object_put_ref(event_context_class);
+       bt_object_put_ref(writer_event_context_class);
+       bt_object_put_ref(writer_event_context);
+       bt_object_put_ref(field);
+       bt_object_put_ref(copy_field);
+       bt_object_put_ref(debug_field);
+       bt_object_put_ref(field_class);
        return ret;
 }
 
 static
-struct bt_clock_class *stream_class_get_clock_class(FILE *err,
-               struct bt_stream_class *stream_class)
+const struct bt_clock_class *stream_class_get_clock_class(FILE *err,
+               const struct bt_stream_class *stream_class)
 {
-       struct bt_trace *trace = NULL;
-       struct bt_clock_class *clock_class = NULL;
+       const struct bt_trace *trace = NULL;
+       const struct bt_clock_class *clock_class = NULL;
 
        trace = bt_stream_class_get_trace(stream_class);
-       assert(trace);
+       BT_ASSERT(trace);
 
        if (!bt_trace_get_clock_class_count(trace)) {
                /* No clock. */
@@ -1694,39 +1692,39 @@ struct bt_clock_class *stream_class_get_clock_class(FILE *err,
        /* FIXME multi-clock? */
        clock_class = bt_trace_get_clock_class_by_index(trace, 0);
 
-       bt_put(trace);
+       bt_object_put_ref(trace);
 
 end:
        return clock_class;
 }
 
 static
-struct bt_clock_class *event_get_clock_class(FILE *err, struct bt_event *event)
+const struct bt_clock_class *event_get_clock_class(FILE *err, const struct bt_event *event)
 {
-       struct bt_event_class *event_class = NULL;
-       struct bt_stream_class *stream_class = NULL;
-       struct bt_clock_class *clock_class = NULL;
+       const struct bt_event_class *event_class = NULL;
+       const struct bt_stream_class *stream_class = NULL;
+       const struct bt_clock_class *clock_class = NULL;
 
        event_class = bt_event_get_class(event);
-       assert(event_class);
+       BT_ASSERT(event_class);
 
        stream_class = bt_event_class_get_stream_class(event_class);
-       assert(stream_class);
+       BT_ASSERT(stream_class);
 
        clock_class = stream_class_get_clock_class(err, stream_class);
        goto end;
 
 end:
-       bt_put(stream_class);
-       bt_put(event_class);
+       bt_object_put_ref(stream_class);
+       bt_object_put_ref(event_class);
        return clock_class;
 }
 
 static
-int set_event_clock_value(FILE *err, struct bt_event *event,
-               struct bt_event *writer_event)
+int set_event_clock_value(FILE *err, const struct bt_event *event,
+               const struct bt_event *writer_event)
 {
-       struct bt_clock_class *clock_class = NULL;
+       const struct bt_clock_class *clock_class = NULL;
        struct bt_clock_value *clock_value = NULL;
        int ret = 0;
 
@@ -1758,19 +1756,19 @@ int set_event_clock_value(FILE *err, struct bt_event *event,
 error:
        ret = -1;
 end:
-       bt_put(clock_class);
-       bt_put(clock_value);
+       bt_object_put_ref(clock_class);
+       bt_object_put_ref(clock_value);
        return ret;
 }
 
 static
-struct bt_event *debug_info_copy_event(FILE *err, struct bt_event *event,
-               struct bt_event_class *writer_event_class,
+const struct bt_event *debug_info_copy_event(FILE *err, const struct bt_event *event,
+               const struct bt_event_class *writer_event_class,
                struct debug_info *debug_info,
                struct debug_info_component *component)
 {
-       struct bt_event *writer_event = NULL;
-       struct bt_field *field = NULL, *copy_field = NULL;
+       const struct bt_event *writer_event = NULL;
+       const struct bt_field *field = NULL, *copy_field = NULL;
        int ret;
 
        writer_event = bt_event_create(writer_event_class);
@@ -1794,7 +1792,7 @@ struct bt_event *debug_info_copy_event(FILE *err, struct bt_event *event,
                        BT_LOGE_STR("Failed to copy event header.");
                        goto error;
                }
-               BT_PUT(field);
+               BT_OBJECT_PUT_REF_AND_RESET(field);
        }
 
        /* Optional field, so it can fail silently. */
@@ -1807,7 +1805,7 @@ struct bt_event *debug_info_copy_event(FILE *err, struct bt_event *event,
                        BT_LOGE_STR("Failed to debug_info stream event context.");
                        goto error;
                }
-               BT_PUT(field);
+               BT_OBJECT_PUT_REF_AND_RESET(field);
        }
 
        /* Optional field, so it can fail silently. */
@@ -1823,12 +1821,12 @@ struct bt_event *debug_info_copy_event(FILE *err, struct bt_event *event,
                        BT_LOGE_STR("Failed to set event_context.");
                        goto error;
                }
-               BT_PUT(copy_field);
-               BT_PUT(field);
+               BT_OBJECT_PUT_REF_AND_RESET(copy_field);
+               BT_OBJECT_PUT_REF_AND_RESET(field);
        }
 
        field = bt_event_get_event_payload(event);
-       assert(field);
+       BT_ASSERT(field);
 
        copy_field = bt_field_copy(field);
        if (copy_field) {
@@ -1837,43 +1835,43 @@ struct bt_event *debug_info_copy_event(FILE *err, struct bt_event *event,
                        BT_LOGE_STR("Failed to set event payload.");
                        goto error;
                }
-               BT_PUT(copy_field);
+               BT_OBJECT_PUT_REF_AND_RESET(copy_field);
        }
-       BT_PUT(field);
+       BT_OBJECT_PUT_REF_AND_RESET(field);
 
        goto end;
 
 error:
-       BT_PUT(writer_event);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_event);
 end:
-       bt_put(copy_field);
-       bt_put(field);
+       bt_object_put_ref(copy_field);
+       bt_object_put_ref(field);
        return writer_event;
 }
 
 BT_HIDDEN
-struct bt_event *debug_info_output_event(
+const struct bt_event *debug_info_output_event(
                struct debug_info_iterator *debug_it,
-               struct bt_event *event)
+               const struct bt_event *event)
 {
-       struct bt_event_class *event_class = NULL, *writer_event_class = NULL;
-       struct bt_stream_class *stream_class = NULL, *writer_stream_class = NULL;
-       struct bt_event *writer_event = NULL;
-       struct bt_packet *packet = NULL, *writer_packet = NULL;
-       struct bt_trace *writer_trace = NULL;
-       struct bt_stream *stream = NULL;
+       const struct bt_event_class *event_class = NULL, *writer_event_class = NULL;
+       const struct bt_stream_class *stream_class = NULL, *writer_stream_class = NULL;
+       const struct bt_event *writer_event = NULL;
+       const struct bt_packet *packet = NULL, *writer_packet = NULL;
+       const struct bt_trace *writer_trace = NULL;
+       const struct bt_stream *stream = NULL;
        struct debug_info_trace *di_trace;
        struct debug_info *debug_info;
        int int_ret;
 
        event_class = bt_event_get_class(event);
-       assert(event_class);
+       BT_ASSERT(event_class);
 
        stream_class = bt_event_class_get_stream_class(event_class);
-       assert(stream_class);
+       BT_ASSERT(stream_class);
 
        stream = bt_event_get_stream(event);
-       assert(stream);
+       BT_ASSERT(stream);
 
        di_trace = lookup_di_trace_from_stream(debug_it, stream);
        if (!di_trace) {
@@ -1888,13 +1886,14 @@ struct bt_event *debug_info_output_event(
                BT_LOGE_STR("Failed to find existing stream_class.");
                goto error;
        }
-       bt_get(writer_stream_class);
-
+       bt_object_get_ref(writer_stream_class);
+       writer_trace = bt_stream_class_get_trace(writer_stream_class);
+       BT_ASSERT(writer_trace);
        writer_event_class = get_event_class(debug_it,
                        writer_stream_class, event_class);
        if (!writer_event_class) {
                writer_event_class = ctf_copy_event_class(debug_it->err,
-                               event_class);
+                               writer_trace, event_class);
                if (!writer_event_class) {
                        BT_LOGE_STR("Failed to copy event_class.");
                        goto error;
@@ -1907,9 +1906,6 @@ struct bt_event *debug_info_output_event(
                }
        }
 
-       writer_trace = bt_stream_class_get_trace(writer_stream_class);
-       assert(writer_trace);
-
        debug_info = get_trace_debug_info(debug_it, writer_trace, di_trace);
        if (debug_info) {
                debug_info_handle_event(debug_it->err, event, debug_info);
@@ -1925,14 +1921,14 @@ struct bt_event *debug_info_output_event(
        }
 
        packet = bt_event_get_packet(event);
-       assert(packet);
+       BT_ASSERT(packet);
 
        writer_packet = lookup_packet(debug_it, packet, di_trace);
        if (!writer_packet) {
                BT_LOGE_STR("Failed to find existing packet.");
                goto error;
        }
-       bt_get(writer_packet);
+       bt_object_get_ref(writer_packet);
 
        int_ret = bt_event_set_packet(writer_event, writer_packet);
        if (int_ret < 0) {
@@ -1945,16 +1941,16 @@ struct bt_event *debug_info_output_event(
        goto end;
 
 error:
-       BT_PUT(writer_event);
+       BT_OBJECT_PUT_REF_AND_RESET(writer_event);
 
 end:
-       bt_put(stream);
-       bt_put(writer_trace);
-       bt_put(writer_packet);
-       bt_put(packet);
-       bt_put(writer_event_class);
-       bt_put(writer_stream_class);
-       bt_put(stream_class);
-       bt_put(event_class);
+       bt_object_put_ref(stream);
+       bt_object_put_ref(writer_trace);
+       bt_object_put_ref(writer_packet);
+       bt_object_put_ref(packet);
+       bt_object_put_ref(writer_event_class);
+       bt_object_put_ref(writer_stream_class);
+       bt_object_put_ref(stream_class);
+       bt_object_put_ref(event_class);
        return writer_event;
 }
This page took 0.055321 seconds and 4 git commands to generate.