Commit | Line | Data |
---|---|---|
abe30a8f PP |
1 | #ifndef BABELTRACE_GRAPH_GRAPH_INTERNAL_H |
2 | #define BABELTRACE_GRAPH_GRAPH_INTERNAL_H | |
c0418dd9 JG |
3 | |
4 | /* | |
f60c8b34 | 5 | * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
c0418dd9 JG |
6 | * |
7 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
8 | * | |
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: | |
15 | * | |
16 | * The above copyright notice and this permission notice shall be included in | |
17 | * all copies or substantial portions of the Software. | |
18 | * | |
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 | |
25 | * SOFTWARE. | |
26 | */ | |
27 | ||
b2e0c907 | 28 | #include <babeltrace/graph/graph.h> |
8d750b42 | 29 | #include <babeltrace/graph/connection-internal.h> |
7b53201c | 30 | #include <babeltrace/graph/notification-const.h> |
c0418dd9 JG |
31 | #include <babeltrace/babeltrace-internal.h> |
32 | #include <babeltrace/object-internal.h> | |
f7c3ac09 | 33 | #include <babeltrace/object-pool-internal.h> |
8b45963b | 34 | #include <babeltrace/assert-internal.h> |
a256a42d | 35 | #include <stdlib.h> |
c0418dd9 JG |
36 | #include <glib.h> |
37 | ||
1bf957a0 PP |
38 | struct bt_component; |
39 | struct bt_port; | |
40 | ||
f60c8b34 JG |
41 | struct bt_graph { |
42 | /** | |
43 | * A component graph contains components and point-to-point connection | |
44 | * between these components. | |
c0418dd9 | 45 | * |
f60c8b34 JG |
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. | |
c0418dd9 | 51 | */ |
f60c8b34 JG |
52 | struct bt_object base; |
53 | ||
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; | |
1bf957a0 | 60 | |
834e9996 PP |
61 | bool canceled; |
62 | bool in_remove_listener; | |
63 | bool has_sink; | |
c3ac0193 PP |
64 | |
65 | /* | |
834e9996 | 66 | * If this is false, then the public API's consuming |
c3ac0193 PP |
67 | * functions (bt_graph_consume() and bt_graph_run()) return |
68 | * BT_GRAPH_STATUS_CANNOT_CONSUME. The internal "no check" | |
69 | * functions always work. | |
70 | * | |
834e9996 | 71 | * In bt_port_output_notification_iterator_create(), on success, |
c3ac0193 PP |
72 | * this flag is cleared so that the iterator remains the only |
73 | * consumer for the graph's lifetime. | |
74 | */ | |
834e9996 | 75 | bool can_consume; |
202a3a13 | 76 | |
1bf957a0 | 77 | struct { |
834e9996 PP |
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; | |
1bf957a0 | 92 | } listeners; |
f7c3ac09 PP |
93 | |
94 | /* Pool of `struct bt_notification_event *` */ | |
95 | struct bt_object_pool event_notif_pool; | |
96 | ||
e18f019b | 97 | /* Pool of `struct bt_notification_packet_beginning *` */ |
f7c3ac09 PP |
98 | struct bt_object_pool packet_begin_notif_pool; |
99 | ||
100 | /* Pool of `struct bt_notification_packet_end *` */ | |
101 | struct bt_object_pool packet_end_notif_pool; | |
102 | ||
103 | /* | |
104 | * Array of `struct bt_notification *` (weak). | |
105 | * | |
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 | |
111 | * destruction. | |
112 | * | |
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). | |
116 | */ | |
117 | GPtrArray *notifications; | |
c0418dd9 JG |
118 | }; |
119 | ||
c3ac0193 | 120 | static inline |
834e9996 | 121 | void _bt_graph_set_can_consume(struct bt_graph *graph, bool can_consume) |
c3ac0193 | 122 | { |
8b45963b | 123 | BT_ASSERT(graph); |
c3ac0193 PP |
124 | graph->can_consume = can_consume; |
125 | } | |
126 | ||
371361a1 PP |
127 | #ifdef BT_DEV_MODE |
128 | # define bt_graph_set_can_consume _bt_graph_set_can_consume | |
129 | #else | |
130 | # define bt_graph_set_can_consume(_graph, _can_consume) | |
131 | #endif | |
c3ac0193 PP |
132 | |
133 | BT_HIDDEN | |
134 | enum bt_graph_status bt_graph_consume_sink_no_check(struct bt_graph *graph, | |
834e9996 | 135 | struct bt_component_sink *sink); |
c3ac0193 | 136 | |
1bf957a0 PP |
137 | BT_HIDDEN |
138 | void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port); | |
139 | ||
140 | BT_HIDDEN | |
141 | void bt_graph_notify_port_removed(struct bt_graph *graph, | |
142 | struct bt_component *comp, struct bt_port *port); | |
143 | ||
144 | BT_HIDDEN | |
f345f8bb PP |
145 | void bt_graph_notify_ports_connected(struct bt_graph *graph, |
146 | struct bt_port *upstream_port, struct bt_port *downstream_port); | |
1bf957a0 PP |
147 | |
148 | BT_HIDDEN | |
f345f8bb PP |
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); | |
1bf957a0 | 154 | |
f167d3c0 PP |
155 | BT_HIDDEN |
156 | void bt_graph_remove_connection(struct bt_graph *graph, | |
157 | struct bt_connection *connection); | |
158 | ||
c3ac0193 PP |
159 | /* |
160 | * This only works with a component which is not connected at this | |
161 | * point. | |
162 | * | |
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. | |
166 | */ | |
167 | BT_HIDDEN | |
168 | int bt_graph_remove_unconnected_component(struct bt_graph *graph, | |
169 | struct bt_component *component); | |
170 | ||
f7c3ac09 PP |
171 | BT_HIDDEN |
172 | void bt_graph_add_notification(struct bt_graph *graph, | |
173 | struct bt_notification *notif); | |
174 | ||
262e5473 PP |
175 | static inline |
176 | const char *bt_graph_status_string(enum bt_graph_status status) | |
177 | { | |
178 | switch (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"; | |
262e5473 PP |
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"; | |
a256a42d PP |
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"; | |
262e5473 PP |
195 | default: |
196 | return "(unknown)"; | |
197 | } | |
198 | } | |
199 | ||
abe30a8f | 200 | #endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */ |