common: introduce bt_g_array_index
[babeltrace.git] / src / lib / trace-ir / trace.c
index 897812e7ef64b8ec6104f3db9bd72b0f6b69c0a4..982325f715ce5b0584d658e04e9593ee1cf41d33 100644 (file)
@@ -46,8 +46,11 @@ struct bt_trace_destruction_listener_elem {
        void *data;
 };
 
-#define BT_ASSERT_PRE_DEV_TRACE_HOT(_trace) \
-       BT_ASSERT_PRE_DEV_HOT((_trace), "Trace", ": %!+t", (_trace))
+#define BT_ASSERT_PRE_DEV_TRACE_HOT(_trace)                            \
+       BT_ASSERT_PRE_DEV_HOT("trace", (_trace), "Trace", ": %!+t", (_trace))
+
+#define DESTRUCTION_LISTENER_FUNC_NAME                                 \
+       "bt_trace_class_destruction_listener_func"
 
 static
 void destroy_trace(struct bt_object *obj)
@@ -84,19 +87,24 @@ void destroy_trace(struct bt_object *obj)
                /* Call all the trace destruction listeners */
                for (i = 0; i < trace->destruction_listeners->len; i++) {
                        struct bt_trace_destruction_listener_elem elem =
-                               g_array_index(trace->destruction_listeners,
-                                               struct bt_trace_destruction_listener_elem, i);
+                               bt_g_array_index(trace->destruction_listeners,
+                                       struct bt_trace_destruction_listener_elem, i);
 
                        if (elem.func) {
                                elem.func(trace, elem.data);
-                               BT_ASSERT_POST_NO_ERROR();
+                               BT_ASSERT_POST_NO_ERROR(
+                                       DESTRUCTION_LISTENER_FUNC_NAME);
                        }
 
                        /*
                         * The destruction listener should not have kept a
                         * reference to the trace.
                         */
-                       BT_ASSERT_POST(trace->base.ref_count == 1, "Destruction listener kept a reference to the trace being destroyed: %![trace-]+t", trace);
+                       BT_ASSERT_POST(DESTRUCTION_LISTENER_FUNC_NAME,
+                               "trace-reference-count-not-changed",
+                               trace->base.ref_count == 1,
+                               "Destruction listener kept a reference to the trace being destroyed: %![trace-]+t",
+                               trace);
                }
                g_array_free(trace->destruction_listeners, TRUE);
                trace->destruction_listeners = NULL;
@@ -135,6 +143,7 @@ void destroy_trace(struct bt_object *obj)
        g_free(trace);
 }
 
+BT_EXPORT
 struct bt_trace *bt_trace_create(struct bt_trace_class *tc)
 {
        struct bt_trace *trace = NULL;
@@ -201,12 +210,14 @@ end:
        return trace;
 }
 
+BT_EXPORT
 const char *bt_trace_get_name(const struct bt_trace *trace)
 {
        BT_ASSERT_PRE_DEV_TRACE_NON_NULL(trace);
        return trace->name.value;
 }
 
+BT_EXPORT
 enum bt_trace_set_name_status bt_trace_set_name(struct bt_trace *trace,
                const char *name)
 {
@@ -220,12 +231,14 @@ enum bt_trace_set_name_status bt_trace_set_name(struct bt_trace *trace,
        return BT_FUNC_STATUS_OK;
 }
 
+BT_EXPORT
 bt_uuid bt_trace_get_uuid(const struct bt_trace *trace)
 {
        BT_ASSERT_PRE_DEV_TRACE_NON_NULL(trace);
        return trace->uuid.value;
 }
 
+BT_EXPORT
 void bt_trace_set_uuid(struct bt_trace *trace, bt_uuid uuid)
 {
        BT_ASSERT_PRE_TRACE_NON_NULL(trace);
@@ -255,8 +268,9 @@ enum bt_trace_set_environment_entry_status set_environment_entry(
        BT_ASSERT(trace);
        BT_ASSERT(name);
        BT_ASSERT(value);
-       BT_ASSERT_PRE(!trace->frozen ||
-               !trace_has_environment_entry(trace, name),
+       BT_ASSERT_PRE("not-frozen:trace",
+               !trace->frozen ||
+                       !trace_has_environment_entry(trace, name),
                "Trace is frozen: cannot replace environment entry: "
                "%![trace-]+t, entry-name=\"%s\"", trace, name);
        ret = bt_attributes_set_field_value(trace->environment, name,
@@ -275,6 +289,7 @@ enum bt_trace_set_environment_entry_status set_environment_entry(
        return ret;
 }
 
+BT_EXPORT
 enum bt_trace_set_environment_entry_status
 bt_trace_set_environment_entry_string(
                struct bt_trace *trace, const char *name, const char *value)
@@ -285,7 +300,7 @@ bt_trace_set_environment_entry_string(
        BT_ASSERT_PRE_NO_ERROR();
        BT_ASSERT_PRE_TRACE_NON_NULL(trace);
        BT_ASSERT_PRE_NAME_NON_NULL(name);
-       BT_ASSERT_PRE_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_NON_NULL("value", value, "Value");
 
        value_obj = bt_value_string_create_init(value);
        if (!value_obj) {
@@ -303,6 +318,7 @@ end:
        return ret;
 }
 
+BT_EXPORT
 enum bt_trace_set_environment_entry_status
 bt_trace_set_environment_entry_integer(
                struct bt_trace *trace, const char *name, int64_t value)
@@ -330,19 +346,22 @@ end:
        return ret;
 }
 
+BT_EXPORT
 uint64_t bt_trace_get_environment_entry_count(const struct bt_trace *trace)
 {
        BT_ASSERT_PRE_DEV_TRACE_NON_NULL(trace);
        return bt_attributes_get_count(trace->environment);
 }
 
+BT_EXPORT
 void bt_trace_borrow_environment_entry_by_index_const(
                const struct bt_trace *trace, uint64_t index,
                const char **name, const struct bt_value **value)
 {
        BT_ASSERT_PRE_DEV_TRACE_NON_NULL(trace);
        BT_ASSERT_PRE_DEV_NAME_NON_NULL(name);
-       BT_ASSERT_PRE_DEV_NON_NULL(value, "Value");
+       BT_ASSERT_PRE_DEV_NON_NULL("value-object-output", value,
+               "Value object (output)");
        BT_ASSERT_PRE_DEV_VALID_INDEX(index,
                bt_attributes_get_count(trace->environment));
        *value = bt_attributes_borrow_field_value(trace->environment, index);
@@ -351,6 +370,7 @@ void bt_trace_borrow_environment_entry_by_index_const(
        BT_ASSERT(*name);
 }
 
+BT_EXPORT
 const struct bt_value *bt_trace_borrow_environment_entry_value_by_name_const(
                const struct bt_trace *trace, const char *name)
 {
@@ -360,12 +380,14 @@ const struct bt_value *bt_trace_borrow_environment_entry_value_by_name_const(
                name);
 }
 
+BT_EXPORT
 uint64_t bt_trace_get_stream_count(const struct bt_trace *trace)
 {
        BT_ASSERT_PRE_DEV_TRACE_NON_NULL(trace);
        return (uint64_t) trace->streams->len;
 }
 
+BT_EXPORT
 struct bt_stream *bt_trace_borrow_stream_by_index(
                struct bt_trace *trace, uint64_t index)
 {
@@ -374,12 +396,14 @@ struct bt_stream *bt_trace_borrow_stream_by_index(
        return g_ptr_array_index(trace->streams, index);
 }
 
+BT_EXPORT
 const struct bt_stream *bt_trace_borrow_stream_by_index_const(
                const struct bt_trace *trace, uint64_t index)
 {
        return bt_trace_borrow_stream_by_index((void *) trace, index);
 }
 
+BT_EXPORT
 struct bt_stream *bt_trace_borrow_stream_by_id(struct bt_trace *trace,
                uint64_t id)
 {
@@ -402,12 +426,14 @@ end:
        return stream;
 }
 
+BT_EXPORT
 const struct bt_stream *bt_trace_borrow_stream_by_id_const(
                const struct bt_trace *trace, uint64_t id)
 {
        return bt_trace_borrow_stream_by_id((void *) trace, id);
 }
 
+BT_EXPORT
 enum bt_trace_add_listener_status bt_trace_add_destruction_listener(
                const struct bt_trace *c_trace,
                bt_trace_destruction_listener_func listener,
@@ -427,7 +453,7 @@ enum bt_trace_add_listener_status bt_trace_add_destruction_listener(
        /* Find the next available spot */
        for (i = 0; i < trace->destruction_listeners->len; i++) {
                struct bt_trace_destruction_listener_elem elem =
-                       g_array_index(trace->destruction_listeners,
+                       bt_g_array_index(trace->destruction_listeners,
                                struct bt_trace_destruction_listener_elem, i);
 
                if (!elem.func) {
@@ -454,11 +480,12 @@ static
 bool has_listener_id(const struct bt_trace *trace, uint64_t listener_id)
 {
        BT_ASSERT(listener_id < trace->destruction_listeners->len);
-       return (&g_array_index(trace->destruction_listeners,
+       return (&bt_g_array_index(trace->destruction_listeners,
                        struct bt_trace_destruction_listener_elem,
                        listener_id))->func;
 }
 
+BT_EXPORT
 enum bt_trace_remove_listener_status bt_trace_remove_destruction_listener(
                const struct bt_trace *c_trace, bt_listener_id listener_id)
 {
@@ -467,10 +494,11 @@ enum bt_trace_remove_listener_status bt_trace_remove_destruction_listener(
 
        BT_ASSERT_PRE_NO_ERROR();
        BT_ASSERT_PRE_TRACE_NON_NULL(trace);
-       BT_ASSERT_PRE(has_listener_id(trace, listener_id),
+       BT_ASSERT_PRE("listener-id-exists",
+               has_listener_id(trace, listener_id),
                "Trace has no such trace destruction listener ID: "
                "%![trace-]+t, %" PRIu64, trace, listener_id);
-       elem = &g_array_index(trace->destruction_listeners,
+       elem = &bt_g_array_index(trace->destruction_listeners,
                        struct bt_trace_destruction_listener_elem,
                        listener_id);
        BT_ASSERT(elem->func);
@@ -483,7 +511,6 @@ enum bt_trace_remove_listener_status bt_trace_remove_destruction_listener(
        return BT_FUNC_STATUS_OK;
 }
 
-BT_HIDDEN
 void _bt_trace_freeze(const struct bt_trace *trace)
 {
        BT_ASSERT(trace);
@@ -496,7 +523,6 @@ void _bt_trace_freeze(const struct bt_trace *trace)
        ((struct bt_trace *) trace)->frozen = true;
 }
 
-BT_HIDDEN
 void bt_trace_add_stream(struct bt_trace *trace, struct bt_stream *stream)
 {
        guint count = 0;
@@ -515,7 +541,6 @@ void bt_trace_add_stream(struct bt_trace *trace, struct bt_stream *stream)
                stream->class, GUINT_TO_POINTER(count + 1));
 }
 
-BT_HIDDEN
 uint64_t bt_trace_get_automatic_stream_id(const struct bt_trace *trace,
                const struct bt_stream_class *stream_class)
 {
@@ -533,18 +558,21 @@ uint64_t bt_trace_get_automatic_stream_id(const struct bt_trace *trace,
        return id;
 }
 
+BT_EXPORT
 struct bt_trace_class *bt_trace_borrow_class(struct bt_trace *trace)
 {
        BT_ASSERT_PRE_DEV_TRACE_NON_NULL(trace);
        return trace->class;
 }
 
+BT_EXPORT
 const struct bt_trace_class *bt_trace_borrow_class_const(
                const struct bt_trace *trace)
 {
        return bt_trace_borrow_class((void *) trace);
 }
 
+BT_EXPORT
 const struct bt_value *bt_trace_borrow_user_attributes_const(
                const struct bt_trace *trace)
 {
@@ -552,11 +580,13 @@ const struct bt_value *bt_trace_borrow_user_attributes_const(
        return trace->user_attributes;
 }
 
+BT_EXPORT
 struct bt_value *bt_trace_borrow_user_attributes(struct bt_trace *trace)
 {
        return (void *) bt_trace_borrow_user_attributes_const((void *) trace);
 }
 
+BT_EXPORT
 void bt_trace_set_user_attributes(
                struct bt_trace *trace,
                const struct bt_value *user_attributes)
@@ -570,11 +600,13 @@ void bt_trace_set_user_attributes(
        bt_object_get_ref_no_null_check(trace->user_attributes);
 }
 
+BT_EXPORT
 void bt_trace_get_ref(const struct bt_trace *trace)
 {
        bt_object_get_ref(trace);
 }
 
+BT_EXPORT
 void bt_trace_put_ref(const struct bt_trace *trace)
 {
        bt_object_put_ref(trace);
This page took 0.02665 seconds and 4 git commands to generate.