lib: use object pool for event and packet notifications
[babeltrace.git] / include / babeltrace / graph / connection-internal.h
index ac75320d6cf4480f397eca1780129f068a89866f..c1eea4b18a25f71004fcb4f5e5b33f60c9886677 100644 (file)
@@ -1,5 +1,5 @@
-#ifndef BABELTRACE_COMPONENT_CONNECTION_INTERNAL_H
-#define BABELTRACE_COMPONENT_CONNECTION_INTERNAL_H
+#ifndef BABELTRACE_GRAPH_CONNECTION_INTERNAL_H
+#define BABELTRACE_GRAPH_CONNECTION_INTERNAL_H
 
 /*
  * BabelTrace - Component Connection Internal
  */
 
 #include <babeltrace/graph/connection.h>
+#include <babeltrace/graph/notification-iterator.h>
+#include <babeltrace/graph/notification-iterator-internal.h>
 #include <babeltrace/graph/private-connection.h>
 #include <babeltrace/object-internal.h>
+#include <babeltrace/assert-internal.h>
+#include <stdbool.h>
 
 struct bt_graph;
 
@@ -48,14 +52,13 @@ struct bt_connection {
        struct bt_port *downstream_port;
        /* Upstream port. */
        struct bt_port *upstream_port;
-};
 
-static inline
-struct bt_connection *bt_connection_from_private(
-               struct bt_private_connection *private_connection)
-{
-       return (void *) private_connection;
-}
+       /*
+        * Weak references to all the notification iterators that were
+        * created on this connection.
+        */
+       GPtrArray *iterators;
+};
 
 static inline
 struct bt_private_connection *bt_private_connection_from_connection(
@@ -70,6 +73,69 @@ struct bt_connection *bt_connection_create(struct bt_graph *graph,
                struct bt_port *downstream_port);
 
 BT_HIDDEN
-void bt_connection_disconnect_ports(struct bt_connection *conn);
+void bt_connection_end(struct bt_connection *conn, bool try_remove_from_graph);
+
+BT_HIDDEN
+void bt_connection_remove_iterator(struct bt_connection *conn,
+               struct bt_notification_iterator_private_connection *iterator);
+
+static inline
+struct bt_graph *bt_connection_borrow_graph(struct bt_connection *conn)
+{
+       BT_ASSERT(conn);
+       return (void *) conn->base.parent;
+}
+
+static inline
+enum bt_connection_status
+bt_connection_status_from_notification_iterator_status(
+               enum bt_notification_iterator_status iter_status)
+{
+       switch (iter_status) {
+       case BT_NOTIFICATION_ITERATOR_STATUS_CANCELED:
+               return BT_CONNECTION_STATUS_ERROR;
+       case BT_NOTIFICATION_ITERATOR_STATUS_AGAIN:
+               return BT_CONNECTION_STATUS_ERROR;
+       case BT_NOTIFICATION_ITERATOR_STATUS_END:
+               return BT_CONNECTION_STATUS_ERROR;
+       case BT_NOTIFICATION_ITERATOR_STATUS_OK:
+               return BT_CONNECTION_STATUS_OK;
+       case BT_NOTIFICATION_ITERATOR_STATUS_INVALID:
+               return BT_CONNECTION_STATUS_INVALID;
+       case BT_NOTIFICATION_ITERATOR_STATUS_ERROR:
+               return BT_CONNECTION_STATUS_ERROR;
+       case BT_NOTIFICATION_ITERATOR_STATUS_NOMEM:
+               return BT_CONNECTION_STATUS_NOMEM;
+       case BT_NOTIFICATION_ITERATOR_STATUS_UNSUPPORTED:
+               return BT_CONNECTION_STATUS_ERROR;
+       default:
+#ifdef BT_LOGF
+               BT_LOGF("Unknown notification iterator status: status=%d",
+                       iter_status);
+#endif
+               abort();
+       }
+}
+
+static inline
+const char *bt_connection_status_string(enum bt_connection_status status)
+{
+       switch (status) {
+       case BT_CONNECTION_STATUS_GRAPH_IS_CANCELED:
+               return "BT_CONNECTION_STATUS_GRAPH_IS_CANCELED";
+       case BT_CONNECTION_STATUS_OK:
+               return "BT_CONNECTION_STATUS_OK";
+       case BT_CONNECTION_STATUS_INVALID:
+               return "BT_CONNECTION_STATUS_INVALID";
+       case BT_CONNECTION_STATUS_ERROR:
+               return "BT_CONNECTION_STATUS_ERROR";
+       case BT_CONNECTION_STATUS_NOMEM:
+               return "BT_CONNECTION_STATUS_NOMEM";
+       case BT_CONNECTION_STATUS_IS_ENDED:
+               return "BT_CONNECTION_STATUS_IS_ENDED";
+       default:
+               return "(unknown)";
+       }
+}
 
-#endif /* BABELTRACE_COMPONENT_CONNECTION_INTERNAL_H */
+#endif /* BABELTRACE_GRAPH_CONNECTION_INTERNAL_H */
This page took 0.028708 seconds and 4 git commands to generate.