1 #ifndef BABELTRACE_GRAPH_GRAPH_INTERNAL_H
2 #define BABELTRACE_GRAPH_GRAPH_INTERNAL_H
5 * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 #include <babeltrace/graph/graph.h>
29 #include <babeltrace/graph/connection-internal.h>
30 #include <babeltrace/graph/notification.h>
31 #include <babeltrace/babeltrace-internal.h>
32 #include <babeltrace/object-internal.h>
33 #include <babeltrace/object-pool-internal.h>
34 #include <babeltrace/assert-internal.h>
43 * A component graph contains components and point-to-point connection
44 * between these components.
46 * In terms of ownership:
47 * 1) The graph is the components' parent,
48 * 2) The graph is the connnections' parent,
49 * 3) Components share the ownership of their connections,
50 * 4) A connection holds weak references to its two component endpoints.
52 struct bt_object base
;
54 /* Array of pointers to bt_connection. */
55 GPtrArray
*connections
;
56 /* Array of pointers to bt_component. */
57 GPtrArray
*components
;
58 /* Queue of pointers (weak references) to sink bt_components. */
59 GQueue
*sinks_to_consume
;
62 bool in_remove_listener
;
66 * If this is false, then the public API's consuming
67 * functions (bt_graph_consume() and bt_graph_run()) return
68 * BT_GRAPH_STATUS_CANNOT_CONSUME. The internal "no check"
69 * functions always work.
71 * In bt_port_output_notification_iterator_create(), on success,
72 * this flag is cleared so that the iterator remains the only
73 * consumer for the graph's lifetime.
78 GArray
*source_output_port_added
;
79 GArray
*filter_output_port_added
;
80 GArray
*filter_input_port_added
;
81 GArray
*sink_input_port_added
;
82 GArray
*source_output_port_removed
;
83 GArray
*filter_output_port_removed
;
84 GArray
*filter_input_port_removed
;
85 GArray
*sink_input_port_removed
;
86 GArray
*source_filter_ports_connected
;
87 GArray
*source_sink_ports_connected
;
88 GArray
*filter_sink_ports_connected
;
89 GArray
*source_filter_ports_disconnected
;
90 GArray
*source_sink_ports_disconnected
;
91 GArray
*filter_sink_ports_disconnected
;
94 /* Pool of `struct bt_notification_event *` */
95 struct bt_object_pool event_notif_pool
;
97 /* Pool of `struct bt_notification_packet_begin *` */
98 struct bt_object_pool packet_begin_notif_pool
;
100 /* Pool of `struct bt_notification_packet_end *` */
101 struct bt_object_pool packet_end_notif_pool
;
104 * Array of `struct bt_notification *` (weak).
106 * This is an array of all the notifications ever created from
107 * this graph. Some of them can be in one of the pools above,
108 * some of them can be at large. Because each notification has a
109 * weak pointer to the graph containing its pool, we need to
110 * notify each notification that the graph is gone on graph
113 * TODO: When we support a maximum size for object pools,
114 * add a way for a notification to remove itself from this
115 * array (on destruction).
117 GPtrArray
*notifications
;
121 void _bt_graph_set_can_consume(struct bt_graph
*graph
, bool can_consume
)
124 graph
->can_consume
= can_consume
;
128 # define bt_graph_set_can_consume _bt_graph_set_can_consume
130 # define bt_graph_set_can_consume(_graph, _can_consume)
134 enum bt_graph_status
bt_graph_consume_sink_no_check(struct bt_graph
*graph
,
135 struct bt_component_sink
*sink
);
138 void bt_graph_notify_port_added(struct bt_graph
*graph
, struct bt_port
*port
);
141 void bt_graph_notify_port_removed(struct bt_graph
*graph
,
142 struct bt_component
*comp
, struct bt_port
*port
);
145 void bt_graph_notify_ports_connected(struct bt_graph
*graph
,
146 struct bt_port
*upstream_port
, struct bt_port
*downstream_port
);
149 void bt_graph_notify_ports_disconnected(struct bt_graph
*graph
,
150 struct bt_component
*upstream_comp
,
151 struct bt_component
*downstream_comp
,
152 struct bt_port
*upstream_port
,
153 struct bt_port
*downstream_port
);
156 void bt_graph_remove_connection(struct bt_graph
*graph
,
157 struct bt_connection
*connection
);
160 * This only works with a component which is not connected at this
163 * Also the reference count of `component` should be 0 when you call
164 * this function, which means only `graph` owns the component, so it
165 * is safe to destroy.
168 int bt_graph_remove_unconnected_component(struct bt_graph
*graph
,
169 struct bt_component
*component
);
172 void bt_graph_add_notification(struct bt_graph
*graph
,
173 struct bt_notification
*notif
);
176 const char *bt_graph_status_string(enum bt_graph_status status
)
179 case BT_GRAPH_STATUS_CANCELED
:
180 return "BT_GRAPH_STATUS_CANCELED";
181 case BT_GRAPH_STATUS_AGAIN
:
182 return "BT_GRAPH_STATUS_AGAIN";
183 case BT_GRAPH_STATUS_END
:
184 return "BT_GRAPH_STATUS_END";
185 case BT_GRAPH_STATUS_OK
:
186 return "BT_GRAPH_STATUS_OK";
187 case BT_GRAPH_STATUS_NO_SINK
:
188 return "BT_GRAPH_STATUS_NO_SINK";
189 case BT_GRAPH_STATUS_ERROR
:
190 return "BT_GRAPH_STATUS_ERROR";
191 case BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION
:
192 return "BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION";
193 case BT_GRAPH_STATUS_NOMEM
:
194 return "BT_GRAPH_STATUS_NOMEM";
200 #endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */