lib: make trace IR API const-correct
[babeltrace.git] / lib / graph / iterator.c
index ca0c49d222553f584a6b824bd64c666dd61464b5..82f6957155024a4ca9fc5cf78743eb6e5a8935d7 100644 (file)
@@ -27,7 +27,9 @@
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/object.h>
 #include <babeltrace/trace-ir/fields.h>
+#include <babeltrace/trace-ir/event-const.h>
 #include <babeltrace/trace-ir/event-internal.h>
+#include <babeltrace/trace-ir/packet-const.h>
 #include <babeltrace/trace-ir/packet-internal.h>
 #include <babeltrace/trace-ir/stream-internal.h>
 #include <babeltrace/graph/connection.h>
@@ -67,8 +69,8 @@
 #define NOTIF_BATCH_SIZE       15
 
 struct stream_state {
-       struct bt_stream *stream; /* owned by this */
-       struct bt_packet *cur_packet; /* owned by this */
+       const struct bt_stream *stream; /* owned by this */
+       const struct bt_packet *cur_packet; /* owned by this */
        uint64_t expected_notif_seq_num;
        bt_bool is_ended;
 };
@@ -91,7 +93,7 @@ void destroy_stream_state(struct stream_state *stream_state)
 
 BT_ASSERT_PRE_FUNC
 static
-struct stream_state *create_stream_state(struct bt_stream *stream)
+struct stream_state *create_stream_state(const struct bt_stream *stream)
 {
        struct stream_state *stream_state = g_new0(struct stream_state, 1);
 
@@ -103,7 +105,8 @@ struct stream_state *create_stream_state(struct bt_stream *stream)
        /*
         * We keep a reference to the stream until we know it's ended.
         */
-       stream_state->stream = bt_object_get_ref(stream);
+       stream_state->stream = stream;
+       bt_object_get_no_null_check(stream_state->stream);
        BT_LIB_LOGV("Created stream state: %![stream-]+s, "
                "stream-state-addr=%p",
                stream, stream_state);
@@ -456,15 +459,16 @@ void bt_self_notification_iterator_set_data(
 BT_ASSERT_PRE_FUNC
 static inline
 void bt_notification_borrow_packet_stream(struct bt_notification *notif,
-               struct bt_stream **stream, struct bt_packet **packet)
+               const struct bt_stream **stream,
+               const struct bt_packet **packet)
 {
        BT_ASSERT(notif);
 
        switch (notif->type) {
        case BT_NOTIFICATION_TYPE_EVENT:
-               *packet = bt_event_borrow_packet(
+               *packet = bt_event_borrow_packet_const(
                        bt_notification_event_borrow_event(notif));
-               *stream = bt_packet_borrow_stream(*packet);
+               *stream = bt_packet_borrow_stream_const(*packet);
                break;
        case BT_NOTIFICATION_TYPE_STREAM_BEGIN:
                *stream = bt_notification_stream_begin_borrow_stream(notif);
@@ -474,11 +478,11 @@ void bt_notification_borrow_packet_stream(struct bt_notification *notif,
                break;
        case BT_NOTIFICATION_TYPE_PACKET_BEGIN:
                *packet = bt_notification_packet_begin_borrow_packet(notif);
-               *stream = bt_packet_borrow_stream(*packet);
+               *stream = bt_packet_borrow_stream_const(*packet);
                break;
        case BT_NOTIFICATION_TYPE_PACKET_END:
                *packet = bt_notification_packet_end_borrow_packet(notif);
-               *stream = bt_packet_borrow_stream(*packet);
+               *stream = bt_packet_borrow_stream_const(*packet);
                break;
        default:
                break;
@@ -493,8 +497,8 @@ bool validate_notification(
 {
        bool is_valid = true;
        struct stream_state *stream_state;
-       struct bt_stream *stream = NULL;
-       struct bt_packet *packet = NULL;
+       const struct bt_stream *stream = NULL;
+       const struct bt_packet *packet = NULL;
 
        BT_ASSERT(notif);
        bt_notification_borrow_packet_stream(notif, &stream, &packet);
@@ -540,8 +544,8 @@ bool validate_notification(
                        abort();
                }
 
-               g_hash_table_insert(iterator->stream_states, stream,
-                       stream_state);
+               g_hash_table_insert(iterator->stream_states,
+                       (void *) stream, stream_state);
                stream_state->expected_notif_seq_num++;
                goto end;
        }
@@ -609,7 +613,8 @@ bool validate_notification(
                        goto end;
                }
                stream_state->expected_notif_seq_num++;
-               stream_state->cur_packet = bt_object_get_ref(packet);
+               stream_state->cur_packet = packet;
+               bt_object_get_no_null_check(stream_state->cur_packet);
                goto end;
        case BT_NOTIFICATION_TYPE_PACKET_END:
                if (!stream_state->cur_packet) {
@@ -909,8 +914,7 @@ void bt_port_output_notification_iterator_destroy(struct bt_object *obj)
 struct bt_port_output_notification_iterator *
 bt_port_output_notification_iterator_create(
                struct bt_private_graph *priv_graph,
-               struct bt_port_output *output_port,
-               const char *colander_component_name)
+               struct bt_port_output *output_port)
 {
        struct bt_port_output_notification_iterator *iterator = NULL;
        struct bt_component_class_sink *colander_comp_cls = NULL;
@@ -918,7 +922,6 @@ bt_port_output_notification_iterator_create(
        struct bt_component_sink *colander_comp;
        struct bt_graph *graph = (void *) priv_graph;
        enum bt_graph_status graph_status;
-       const char *colander_comp_name;
        struct bt_port_input *colander_in_port = NULL;
        struct bt_component_class_sink_colander_data colander_data;
        int ret;
@@ -958,14 +961,16 @@ bt_port_output_notification_iterator_create(
                goto error;
        }
 
-       iterator->graph = bt_object_get_ref(graph);
-       colander_comp_name =
-               colander_component_name ? colander_component_name : "colander";
+       iterator->graph = graph;
+       bt_object_get_no_null_check(iterator->graph);
        colander_data.notifs = (void *) iterator->base.notifs->pdata;
        colander_data.count_addr = &iterator->count;
+
+       /* Hope that nobody uses this very unique name */
        graph_status =
                bt_private_graph_add_sink_component_with_init_method_data(
-                       (void *) graph, colander_comp_cls, colander_comp_name,
+                       (void *) graph, colander_comp_cls,
+                       "colander-36ac3409-b1a8-4d60-ab1f-4fdf341a8fb1",
                        NULL, &colander_data, &iterator->colander);
        if (graph_status != BT_GRAPH_STATUS_OK) {
                BT_LIB_LOGW("Cannot add colander sink component to graph: "
This page took 0.024658 seconds and 4 git commands to generate.