1 #ifndef BABELTRACE_COMPONENT_COMPONENT_GRAPH_INTERNAL_H
2 #define BABELTRACE_COMPONENT_COMPONENT_GRAPH_INTERNAL_H
5 * BabelTrace - Component Graph Internal
7 * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
18 * The above copyright notice and this permission notice shall be included in
19 * all copies or substantial portions of the Software.
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
30 #include <babeltrace/graph/graph.h>
31 #include <babeltrace/graph/component-status.h>
32 #include <babeltrace/babeltrace-internal.h>
33 #include <babeltrace/object-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 bt_bool in_remove_listener
;
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.
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.
80 GArray
*ports_connected
;
81 GArray
*ports_disconnected
;
86 void bt_graph_set_can_consume(struct bt_graph
*graph
, bt_bool can_consume
)
89 graph
->can_consume
= can_consume
;
93 enum bt_graph_status
bt_graph_consume_no_check(struct bt_graph
*graph
);
96 enum bt_graph_status
bt_graph_consume_sink_no_check(struct bt_graph
*graph
,
97 struct bt_component
*sink
);
100 void bt_graph_notify_port_added(struct bt_graph
*graph
, struct bt_port
*port
);
103 void bt_graph_notify_port_removed(struct bt_graph
*graph
,
104 struct bt_component
*comp
, struct bt_port
*port
);
107 void bt_graph_notify_ports_connected(struct bt_graph
*graph
,
108 struct bt_port
*upstream_port
, struct bt_port
*downstream_port
);
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
);
118 void bt_graph_remove_connection(struct bt_graph
*graph
,
119 struct bt_connection
*connection
);
122 * This only works with a component which is not connected at this
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.
130 int bt_graph_remove_unconnected_component(struct bt_graph
*graph
,
131 struct bt_component
*component
);
134 const char *bt_graph_status_string(enum bt_graph_status 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";
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";
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";
155 case BT_GRAPH_STATUS_CANNOT_CONSUME
:
156 return "BT_GRAPH_STATUS_CANNOT_CONSUME";
163 enum bt_graph_status
bt_graph_status_from_component_status(
164 enum bt_component_status comp_status
)
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
;
187 BT_LOGF("Unknown component status: status=%d", comp_status
);
193 #endif /* BABELTRACE_COMPONENT_COMPONENT_GRAPH_INTERNAL_H */