Trace IR and notification APIs: split into private and public APIs
[babeltrace.git] / lib / graph / iterator.c
index 0deb40c7721467bd3f40b3b5ca5d93cd1bbc2306..11aca63bab425b4e551c203cd193c0ed0fdcb1ca 100644 (file)
 #include <babeltrace/lib-logging-internal.h>
 
 #include <babeltrace/compiler-internal.h>
-#include <babeltrace/ref.h>
-#include <babeltrace/ctf-ir/fields.h>
-#include <babeltrace/ctf-ir/field-types.h>
-#include <babeltrace/ctf-ir/field-types-internal.h>
-#include <babeltrace/ctf-ir/event-internal.h>
-#include <babeltrace/ctf-ir/packet-internal.h>
-#include <babeltrace/ctf-ir/stream-internal.h>
+#include <babeltrace/object.h>
+#include <babeltrace/trace-ir/fields.h>
+#include <babeltrace/trace-ir/event-internal.h>
+#include <babeltrace/trace-ir/packet-internal.h>
+#include <babeltrace/trace-ir/stream-internal.h>
 #include <babeltrace/graph/connection.h>
 #include <babeltrace/graph/connection-internal.h>
 #include <babeltrace/graph/component.h>
+#include <babeltrace/graph/component-internal.h>
 #include <babeltrace/graph/component-source-internal.h>
 #include <babeltrace/graph/component-class-internal.h>
 #include <babeltrace/graph/component-class-sink-colander-internal.h>
@@ -53,7 +52,6 @@
 #include <babeltrace/graph/notification-packet-internal.h>
 #include <babeltrace/graph/notification-stream.h>
 #include <babeltrace/graph/notification-stream-internal.h>
-#include <babeltrace/graph/notification-discarded-elements-internal.h>
 #include <babeltrace/graph/port.h>
 #include <babeltrace/graph/graph-internal.h>
 #include <babeltrace/types.h>
  */
 #define NOTIF_BATCH_SIZE       15
 
-struct discarded_elements_state {
-       struct bt_clock_value *cur_begin;
-       uint64_t cur_count;
-};
-
 struct stream_state {
        struct bt_stream *stream; /* owned by this */
        struct bt_packet *cur_packet; /* owned by this */
-       struct discarded_elements_state discarded_packets_state;
-       struct discarded_elements_state discarded_events_state;
        uint64_t expected_notif_seq_num;
        bt_bool is_ended;
 };
@@ -93,11 +84,9 @@ void destroy_stream_state(struct stream_state *stream_state)
 
        BT_LOGV("Destroying stream state: stream-state-addr=%p", stream_state);
        BT_LOGV_STR("Putting stream state's current packet.");
-       bt_put(stream_state->cur_packet);
+       bt_object_put_ref(stream_state->cur_packet);
        BT_LOGV_STR("Putting stream state's stream.");
-       bt_put(stream_state->stream);
-       bt_put(stream_state->discarded_packets_state.cur_begin);
-       bt_put(stream_state->discarded_events_state.cur_begin);
+       bt_object_put_ref(stream_state->stream);
        g_free(stream_state);
 }
 
@@ -112,19 +101,10 @@ struct stream_state *create_stream_state(struct bt_stream *stream)
                goto end;
        }
 
-       /*
-        * The packet index is a monotonic counter which may not start
-        * at 0 at the beginning of the stream. We therefore need to
-        * have an internal object initial state of -1ULL to distinguish
-        * between initial state and having seen a packet with
-        * the sequence number 0.
-        */
-       stream_state->discarded_packets_state.cur_count = -1ULL;
-
        /*
         * We keep a reference to the stream until we know it's ended.
         */
-       stream_state->stream = bt_get(stream);
+       stream_state->stream = bt_object_get_ref(stream);
        BT_LOGV("Created stream state: stream-addr=%p, stream-name=\"%s\", "
                "stream-state-addr=%p",
                stream, bt_stream_get_name(stream), stream_state);
@@ -158,9 +138,9 @@ void bt_private_connection_notification_iterator_destroy(struct bt_object *obj)
         * The notification iterator's reference count is 0 if we're
         * here. Increment it to avoid a double-destroy (possibly
         * infinitely recursive). This could happen for example if the
-        * notification iterator's finalization function does bt_get()
-        * (or anything that causes bt_get() to be called) on itself
-        * (ref. count goes from 0 to 1), and then bt_put(): the
+        * notification iterator's finalization function does bt_object_get_ref()
+        * (or anything that causes bt_object_get_ref() to be called) on itself
+        * (ref. count goes from 0 to 1), and then bt_object_put_ref(): the
         * reference count would go from 1 to 0 again and this function
         * would be called again.
         */
@@ -369,7 +349,7 @@ enum bt_connection_status bt_private_connection_notification_iterator_create(
        iterator = NULL;
 
 end:
-       bt_put(iterator);
+       bt_object_put_ref(iterator);
        return status;
 }
 
@@ -565,7 +545,7 @@ bool validate_notification(
                        goto end;
                }
                stream_state->expected_notif_seq_num++;
-               stream_state->cur_packet = bt_get(packet);
+               stream_state->cur_packet = bt_object_get_ref(packet);
                goto end;
        case BT_NOTIFICATION_TYPE_PACKET_END:
                if (!stream_state->cur_packet) {
@@ -580,7 +560,7 @@ bool validate_notification(
                        goto end;
                }
                stream_state->expected_notif_seq_num++;
-               BT_PUT(stream_state->cur_packet);
+               BT_OBJECT_PUT_REF_AND_RESET(stream_state->cur_packet);
                goto end;
        case BT_NOTIFICATION_TYPE_EVENT:
                if (packet != stream_state->cur_packet) {
@@ -739,7 +719,7 @@ bt_private_connection_notification_iterator_next(
                 * created. In this case, said connection is ended, and
                 * all its notification iterators are finalized.
                 *
-                * Only bt_put() the returned notification if
+                * Only bt_object_put_ref() the returned notification if
                 * the status is
                 * BT_NOTIFICATION_ITERATOR_STATUS_OK because
                 * otherwise this field could be garbage.
@@ -750,7 +730,7 @@ bt_private_connection_notification_iterator_next(
                                (void *) user_iterator->notifs->pdata;
 
                        for (i = 0; i < *user_count; i++) {
-                               bt_put(notifs[i]);
+                               bt_object_put_ref(notifs[i]);
                        }
                }
 
@@ -855,7 +835,7 @@ struct bt_component *bt_private_connection_notification_iterator_get_component(
                "Notification iterator was not created from a private connection: "
                "%!+i", iterator);
        iter_priv_conn = (void *) iterator;
-       return bt_get(iter_priv_conn->upstream_component);
+       return bt_object_get_ref(iter_priv_conn->upstream_component);
 }
 
 struct bt_private_component *
@@ -876,9 +856,9 @@ void bt_output_port_notification_iterator_destroy(struct bt_object *obj)
        BT_LOGD("Destroying output port notification iterator object: addr=%p",
                iterator);
        BT_LOGD_STR("Putting graph.");
-       bt_put(iterator->graph);
+       bt_object_put_ref(iterator->graph);
        BT_LOGD_STR("Putting colander sink component.");
-       bt_put(iterator->colander);
+       bt_object_put_ref(iterator->colander);
        destroy_base_notification_iterator(obj);
 }
 
@@ -903,7 +883,7 @@ struct bt_notification_iterator *bt_output_port_notification_iterator_create(
        output_port_comp = bt_port_get_component(output_port);
        BT_ASSERT_PRE(output_port_comp,
                "Output port has no component: %!+p", output_port);
-       graph = bt_component_get_graph(output_port_comp);
+       graph = bt_object_get_ref(bt_component_borrow_graph(output_port_comp));
        BT_ASSERT(graph);
 
        /* Create notification iterator */
@@ -922,7 +902,7 @@ struct bt_notification_iterator *bt_output_port_notification_iterator_create(
                bt_output_port_notification_iterator_destroy);
        if (ret) {
                /* init_notification_iterator() logs errors */
-               BT_PUT(iterator);
+               BT_OBJECT_PUT_REF_AND_RESET(iterator);
                goto end;
        }
 
@@ -933,7 +913,7 @@ struct bt_notification_iterator *bt_output_port_notification_iterator_create(
                goto error;
        }
 
-       BT_MOVE(iterator->graph, graph);
+       BT_OBJECT_MOVE_REF(iterator->graph, graph);
        colander_comp_name =
                colander_component_name ? colander_component_name : "colander";
        colander_data.notifs = (void *) iterator->base.notifs->pdata;
@@ -984,7 +964,7 @@ error:
 
                /* Remove created colander component from graph if any */
                colander_comp = iterator->colander;
-               BT_PUT(iterator->colander);
+               BT_OBJECT_PUT_REF_AND_RESET(iterator->colander);
 
                /*
                 * At this point the colander component's reference
@@ -1002,13 +982,13 @@ error:
                BT_ASSERT(ret == 0);
        }
 
-       BT_PUT(iterator);
+       BT_OBJECT_PUT_REF_AND_RESET(iterator);
 
 end:
-       bt_put(colander_in_port);
-       bt_put(colander_comp_cls);
-       bt_put(output_port_comp);
-       bt_put(graph);
+       bt_object_put_ref(colander_in_port);
+       bt_object_put_ref(colander_comp_cls);
+       bt_object_put_ref(output_port_comp);
+       bt_object_put_ref(graph);
        return (void *) iterator;
 }
 
This page took 0.027964 seconds and 4 git commands to generate.