Commit | Line | Data |
---|---|---|
6ac74c0c PP |
1 | #ifndef BABELTRACE_GRAPH_GRAPH_INTERNAL_H |
2 | #define BABELTRACE_GRAPH_GRAPH_INTERNAL_H | |
c0418dd9 JG |
3 | |
4 | /* | |
5 | * BabelTrace - Component Graph Internal | |
6 | * | |
f60c8b34 | 7 | * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
c0418dd9 JG |
8 | * |
9 | * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com> | |
10 | * | |
11 | * Permission is hereby granted, free of charge, to any person obtaining a copy | |
12 | * of this software and associated documentation files (the "Software"), to deal | |
13 | * in the Software without restriction, including without limitation the rights | |
14 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
15 | * copies of the Software, and to permit persons to whom the Software is | |
16 | * furnished to do so, subject to the following conditions: | |
17 | * | |
18 | * The above copyright notice and this permission notice shall be included in | |
19 | * all copies or substantial portions of the Software. | |
20 | * | |
21 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
22 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
23 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
24 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
25 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
26 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
27 | * SOFTWARE. | |
28 | */ | |
29 | ||
b2e0c907 | 30 | #include <babeltrace/graph/graph.h> |
a256a42d | 31 | #include <babeltrace/graph/component-status.h> |
c0418dd9 JG |
32 | #include <babeltrace/babeltrace-internal.h> |
33 | #include <babeltrace/object-internal.h> | |
f6ccaed9 | 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 | |
202a3a13 | 61 | bt_bool canceled; |
8cc092c9 | 62 | bt_bool in_remove_listener; |
2de524b3 | 63 | bt_bool has_sink; |
8ed535b5 PP |
64 | |
65 | /* | |
66 | * If this is BT_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. | |
70 | * | |
71 | * In bt_output_port_notification_iterator_create(), on success, | |
72 | * this flag is cleared so that the iterator remains the only | |
73 | * consumer for the graph's lifetime. | |
74 | */ | |
1d915789 | 75 | bt_bool can_consume; |
202a3a13 | 76 | |
1bf957a0 PP |
77 | struct { |
78 | GArray *port_added; | |
79 | GArray *port_removed; | |
f345f8bb PP |
80 | GArray *ports_connected; |
81 | GArray *ports_disconnected; | |
1bf957a0 | 82 | } listeners; |
c0418dd9 JG |
83 | }; |
84 | ||
8ed535b5 PP |
85 | static inline |
86 | void bt_graph_set_can_consume(struct bt_graph *graph, bt_bool can_consume) | |
87 | { | |
f6ccaed9 | 88 | BT_ASSERT(graph); |
8ed535b5 PP |
89 | graph->can_consume = can_consume; |
90 | } | |
91 | ||
92 | BT_HIDDEN | |
93 | enum bt_graph_status bt_graph_consume_no_check(struct bt_graph *graph); | |
94 | ||
95 | BT_HIDDEN | |
96 | enum bt_graph_status bt_graph_consume_sink_no_check(struct bt_graph *graph, | |
97 | struct bt_component *sink); | |
98 | ||
1bf957a0 PP |
99 | BT_HIDDEN |
100 | void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port); | |
101 | ||
102 | BT_HIDDEN | |
103 | void bt_graph_notify_port_removed(struct bt_graph *graph, | |
104 | struct bt_component *comp, struct bt_port *port); | |
105 | ||
106 | BT_HIDDEN | |
f345f8bb PP |
107 | void bt_graph_notify_ports_connected(struct bt_graph *graph, |
108 | struct bt_port *upstream_port, struct bt_port *downstream_port); | |
1bf957a0 PP |
109 | |
110 | BT_HIDDEN | |
f345f8bb PP |
111 | void bt_graph_notify_ports_disconnected(struct bt_graph *graph, |
112 | struct bt_component *upstream_comp, | |
113 | struct bt_component *downstream_comp, | |
114 | struct bt_port *upstream_port, | |
115 | struct bt_port *downstream_port); | |
1bf957a0 | 116 | |
f167d3c0 PP |
117 | BT_HIDDEN |
118 | void bt_graph_remove_connection(struct bt_graph *graph, | |
119 | struct bt_connection *connection); | |
120 | ||
8ed535b5 PP |
121 | /* |
122 | * This only works with a component which is not connected at this | |
123 | * point. | |
124 | * | |
125 | * Also the reference count of `component` should be 0 when you call | |
126 | * this function, which means only `graph` owns the component, so it | |
127 | * is safe to destroy. | |
128 | */ | |
129 | BT_HIDDEN | |
130 | int bt_graph_remove_unconnected_component(struct bt_graph *graph, | |
131 | struct bt_component *component); | |
132 | ||
262e5473 PP |
133 | static inline |
134 | const char *bt_graph_status_string(enum bt_graph_status status) | |
135 | { | |
136 | switch (status) { | |
137 | case BT_GRAPH_STATUS_CANCELED: | |
138 | return "BT_GRAPH_STATUS_CANCELED"; | |
139 | case BT_GRAPH_STATUS_AGAIN: | |
140 | return "BT_GRAPH_STATUS_AGAIN"; | |
141 | case BT_GRAPH_STATUS_END: | |
142 | return "BT_GRAPH_STATUS_END"; | |
143 | case BT_GRAPH_STATUS_OK: | |
144 | return "BT_GRAPH_STATUS_OK"; | |
262e5473 PP |
145 | case BT_GRAPH_STATUS_INVALID: |
146 | return "BT_GRAPH_STATUS_INVALID"; | |
147 | case BT_GRAPH_STATUS_NO_SINK: | |
148 | return "BT_GRAPH_STATUS_NO_SINK"; | |
149 | case BT_GRAPH_STATUS_ERROR: | |
150 | return "BT_GRAPH_STATUS_ERROR"; | |
a256a42d PP |
151 | case BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION: |
152 | return "BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION"; | |
153 | case BT_GRAPH_STATUS_NOMEM: | |
154 | return "BT_GRAPH_STATUS_NOMEM"; | |
1d915789 PP |
155 | case BT_GRAPH_STATUS_CANNOT_CONSUME: |
156 | return "BT_GRAPH_STATUS_CANNOT_CONSUME"; | |
262e5473 PP |
157 | default: |
158 | return "(unknown)"; | |
159 | } | |
160 | } | |
161 | ||
a256a42d PP |
162 | static inline |
163 | enum bt_graph_status bt_graph_status_from_component_status( | |
164 | enum bt_component_status comp_status) | |
165 | { | |
166 | switch (comp_status) { | |
167 | case BT_COMPONENT_STATUS_OK: | |
168 | return BT_GRAPH_STATUS_OK; | |
169 | case BT_COMPONENT_STATUS_END: | |
170 | return BT_GRAPH_STATUS_END; | |
171 | case BT_COMPONENT_STATUS_AGAIN: | |
172 | return BT_GRAPH_STATUS_AGAIN; | |
173 | case BT_COMPONENT_STATUS_REFUSE_PORT_CONNECTION: | |
174 | return BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION; | |
175 | case BT_COMPONENT_STATUS_ERROR: | |
176 | return BT_GRAPH_STATUS_ERROR; | |
177 | case BT_COMPONENT_STATUS_UNSUPPORTED: | |
178 | return BT_GRAPH_STATUS_ERROR; | |
179 | case BT_COMPONENT_STATUS_INVALID: | |
180 | return BT_GRAPH_STATUS_INVALID; | |
181 | case BT_COMPONENT_STATUS_NOMEM: | |
182 | return BT_GRAPH_STATUS_NOMEM; | |
183 | case BT_COMPONENT_STATUS_NOT_FOUND: | |
184 | return BT_GRAPH_STATUS_ERROR; | |
185 | default: | |
186 | #ifdef BT_LOGF | |
187 | BT_LOGF("Unknown component status: status=%d", comp_status); | |
188 | #endif | |
189 | abort(); | |
190 | } | |
191 | } | |
192 | ||
6ac74c0c | 193 | #endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */ |