lib: rename bt_plugin_create_all_*() -> bt_plugin_find_all_*()
[babeltrace.git] / include / babeltrace / graph / graph-internal.h
CommitLineData
6ac74c0c
PP
1#ifndef BABELTRACE_GRAPH_GRAPH_INTERNAL_H
2#define BABELTRACE_GRAPH_GRAPH_INTERNAL_H
c0418dd9
JG
3
4/*
e2f7325d 5 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
f60c8b34 6 * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
c0418dd9 7 *
c0418dd9
JG
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * SOFTWARE.
25 */
26
b2e0c907 27#include <babeltrace/graph/graph.h>
a2d06fd5 28#include <babeltrace/graph/connection-internal.h>
0d72b8c3 29#include <babeltrace/graph/notification-const.h>
c0418dd9
JG
30#include <babeltrace/babeltrace-internal.h>
31#include <babeltrace/object-internal.h>
5c563278 32#include <babeltrace/object-pool-internal.h>
f6ccaed9 33#include <babeltrace/assert-internal.h>
a256a42d 34#include <stdlib.h>
c0418dd9
JG
35#include <glib.h>
36
1bf957a0
PP
37struct bt_component;
38struct bt_port;
39
f60c8b34
JG
40struct bt_graph {
41 /**
42 * A component graph contains components and point-to-point connection
43 * between these components.
c0418dd9 44 *
f60c8b34
JG
45 * In terms of ownership:
46 * 1) The graph is the components' parent,
47 * 2) The graph is the connnections' parent,
48 * 3) Components share the ownership of their connections,
49 * 4) A connection holds weak references to its two component endpoints.
c0418dd9 50 */
f60c8b34
JG
51 struct bt_object base;
52
53 /* Array of pointers to bt_connection. */
54 GPtrArray *connections;
55 /* Array of pointers to bt_component. */
56 GPtrArray *components;
57 /* Queue of pointers (weak references) to sink bt_components. */
58 GQueue *sinks_to_consume;
1bf957a0 59
d94d92ac
PP
60 bool canceled;
61 bool in_remove_listener;
62 bool has_sink;
8ed535b5
PP
63
64 /*
d94d92ac 65 * If this is false, then the public API's consuming
8ed535b5
PP
66 * functions (bt_graph_consume() and bt_graph_run()) return
67 * BT_GRAPH_STATUS_CANNOT_CONSUME. The internal "no check"
68 * functions always work.
69 *
d94d92ac 70 * In bt_port_output_notification_iterator_create(), on success,
8ed535b5
PP
71 * this flag is cleared so that the iterator remains the only
72 * consumer for the graph's lifetime.
73 */
d94d92ac 74 bool can_consume;
202a3a13 75
1bf957a0 76 struct {
d94d92ac
PP
77 GArray *source_output_port_added;
78 GArray *filter_output_port_added;
79 GArray *filter_input_port_added;
80 GArray *sink_input_port_added;
81 GArray *source_output_port_removed;
82 GArray *filter_output_port_removed;
83 GArray *filter_input_port_removed;
84 GArray *sink_input_port_removed;
85 GArray *source_filter_ports_connected;
86 GArray *source_sink_ports_connected;
87 GArray *filter_sink_ports_connected;
88 GArray *source_filter_ports_disconnected;
89 GArray *source_sink_ports_disconnected;
90 GArray *filter_sink_ports_disconnected;
1bf957a0 91 } listeners;
5c563278
PP
92
93 /* Pool of `struct bt_notification_event *` */
94 struct bt_object_pool event_notif_pool;
95
bb5bb160 96 /* Pool of `struct bt_notification_packet_beginning *` */
5c563278
PP
97 struct bt_object_pool packet_begin_notif_pool;
98
99 /* Pool of `struct bt_notification_packet_end *` */
100 struct bt_object_pool packet_end_notif_pool;
101
102 /*
103 * Array of `struct bt_notification *` (weak).
104 *
105 * This is an array of all the notifications ever created from
106 * this graph. Some of them can be in one of the pools above,
107 * some of them can be at large. Because each notification has a
108 * weak pointer to the graph containing its pool, we need to
109 * notify each notification that the graph is gone on graph
110 * destruction.
111 *
112 * TODO: When we support a maximum size for object pools,
113 * add a way for a notification to remove itself from this
114 * array (on destruction).
115 */
116 GPtrArray *notifications;
c0418dd9
JG
117};
118
8ed535b5 119static inline
d94d92ac 120void _bt_graph_set_can_consume(struct bt_graph *graph, bool can_consume)
8ed535b5 121{
f6ccaed9 122 BT_ASSERT(graph);
8ed535b5
PP
123 graph->can_consume = can_consume;
124}
125
ad847455
PP
126#ifdef BT_DEV_MODE
127# define bt_graph_set_can_consume _bt_graph_set_can_consume
128#else
129# define bt_graph_set_can_consume(_graph, _can_consume)
130#endif
8ed535b5
PP
131
132BT_HIDDEN
133enum bt_graph_status bt_graph_consume_sink_no_check(struct bt_graph *graph,
d94d92ac 134 struct bt_component_sink *sink);
8ed535b5 135
1bf957a0
PP
136BT_HIDDEN
137void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port);
138
139BT_HIDDEN
140void bt_graph_notify_port_removed(struct bt_graph *graph,
141 struct bt_component *comp, struct bt_port *port);
142
143BT_HIDDEN
f345f8bb
PP
144void bt_graph_notify_ports_connected(struct bt_graph *graph,
145 struct bt_port *upstream_port, struct bt_port *downstream_port);
1bf957a0
PP
146
147BT_HIDDEN
f345f8bb
PP
148void bt_graph_notify_ports_disconnected(struct bt_graph *graph,
149 struct bt_component *upstream_comp,
150 struct bt_component *downstream_comp,
151 struct bt_port *upstream_port,
152 struct bt_port *downstream_port);
1bf957a0 153
f167d3c0
PP
154BT_HIDDEN
155void bt_graph_remove_connection(struct bt_graph *graph,
156 struct bt_connection *connection);
157
8ed535b5
PP
158/*
159 * This only works with a component which is not connected at this
160 * point.
161 *
162 * Also the reference count of `component` should be 0 when you call
163 * this function, which means only `graph` owns the component, so it
164 * is safe to destroy.
165 */
166BT_HIDDEN
167int bt_graph_remove_unconnected_component(struct bt_graph *graph,
168 struct bt_component *component);
169
5c563278
PP
170BT_HIDDEN
171void bt_graph_add_notification(struct bt_graph *graph,
172 struct bt_notification *notif);
173
262e5473
PP
174static inline
175const char *bt_graph_status_string(enum bt_graph_status status)
176{
177 switch (status) {
178 case BT_GRAPH_STATUS_CANCELED:
179 return "BT_GRAPH_STATUS_CANCELED";
180 case BT_GRAPH_STATUS_AGAIN:
181 return "BT_GRAPH_STATUS_AGAIN";
182 case BT_GRAPH_STATUS_END:
183 return "BT_GRAPH_STATUS_END";
184 case BT_GRAPH_STATUS_OK:
185 return "BT_GRAPH_STATUS_OK";
262e5473
PP
186 case BT_GRAPH_STATUS_NO_SINK:
187 return "BT_GRAPH_STATUS_NO_SINK";
188 case BT_GRAPH_STATUS_ERROR:
189 return "BT_GRAPH_STATUS_ERROR";
a256a42d
PP
190 case BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION:
191 return "BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION";
192 case BT_GRAPH_STATUS_NOMEM:
193 return "BT_GRAPH_STATUS_NOMEM";
262e5473
PP
194 default:
195 return "(unknown)";
196 }
197}
198
6ac74c0c 199#endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */
This page took 0.045753 seconds and 4 git commands to generate.