lib: rename plural file names to singular
[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/*
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>
a2d06fd5 29#include <babeltrace/graph/connection-internal.h>
0d72b8c3 30#include <babeltrace/graph/notification-const.h>
c0418dd9
JG
31#include <babeltrace/babeltrace-internal.h>
32#include <babeltrace/object-internal.h>
5c563278 33#include <babeltrace/object-pool-internal.h>
f6ccaed9 34#include <babeltrace/assert-internal.h>
a256a42d 35#include <stdlib.h>
c0418dd9
JG
36#include <glib.h>
37
1bf957a0
PP
38struct bt_component;
39struct bt_port;
40
f60c8b34
JG
41struct 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
d94d92ac
PP
61 bool canceled;
62 bool in_remove_listener;
63 bool has_sink;
8ed535b5
PP
64
65 /*
d94d92ac 66 * If this is false, then the public API's consuming
8ed535b5
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 *
d94d92ac 71 * In bt_port_output_notification_iterator_create(), on success,
8ed535b5
PP
72 * this flag is cleared so that the iterator remains the only
73 * consumer for the graph's lifetime.
74 */
d94d92ac 75 bool can_consume;
202a3a13 76
1bf957a0 77 struct {
d94d92ac
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;
5c563278
PP
93
94 /* Pool of `struct bt_notification_event *` */
95 struct bt_object_pool event_notif_pool;
96
bb5bb160 97 /* Pool of `struct bt_notification_packet_beginning *` */
5c563278
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
8ed535b5 120static inline
d94d92ac 121void _bt_graph_set_can_consume(struct bt_graph *graph, bool can_consume)
8ed535b5 122{
f6ccaed9 123 BT_ASSERT(graph);
8ed535b5
PP
124 graph->can_consume = can_consume;
125}
126
ad847455
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
8ed535b5
PP
132
133BT_HIDDEN
134enum bt_graph_status bt_graph_consume_sink_no_check(struct bt_graph *graph,
d94d92ac 135 struct bt_component_sink *sink);
8ed535b5 136
1bf957a0
PP
137BT_HIDDEN
138void bt_graph_notify_port_added(struct bt_graph *graph, struct bt_port *port);
139
140BT_HIDDEN
141void bt_graph_notify_port_removed(struct bt_graph *graph,
142 struct bt_component *comp, struct bt_port *port);
143
144BT_HIDDEN
f345f8bb
PP
145void bt_graph_notify_ports_connected(struct bt_graph *graph,
146 struct bt_port *upstream_port, struct bt_port *downstream_port);
1bf957a0
PP
147
148BT_HIDDEN
f345f8bb
PP
149void 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
155BT_HIDDEN
156void bt_graph_remove_connection(struct bt_graph *graph,
157 struct bt_connection *connection);
158
8ed535b5
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 */
167BT_HIDDEN
168int bt_graph_remove_unconnected_component(struct bt_graph *graph,
169 struct bt_component *component);
170
5c563278
PP
171BT_HIDDEN
172void bt_graph_add_notification(struct bt_graph *graph,
173 struct bt_notification *notif);
174
262e5473
PP
175static inline
176const 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
6ac74c0c 200#endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */
This page took 0.045884 seconds and 4 git commands to generate.