Commit | Line | Data |
---|---|---|
1ca80abd PP |
1 | #ifndef BABELTRACE_GRAPH_GRAPH_H |
2 | #define BABELTRACE_GRAPH_GRAPH_H | |
c0418dd9 JG |
3 | |
4 | /* | |
f60c8b34 | 5 | * BabelTrace - Babeltrace Graph Interface |
c0418dd9 | 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 | ||
9d408fca | 30 | /* For bt_bool */ |
202a3a13 | 31 | #include <babeltrace/types.h> |
c0418dd9 | 32 | |
ad847455 PP |
33 | /* For enum bt_component_status */ |
34 | #include <babeltrace/graph/component-status.h> | |
35 | ||
c0418dd9 JG |
36 | #ifdef __cplusplus |
37 | extern "C" { | |
38 | #endif | |
39 | ||
f60c8b34 JG |
40 | struct bt_port; |
41 | struct bt_connection; | |
9d408fca PP |
42 | struct bt_component; |
43 | struct bt_component_class; | |
5c563278 | 44 | struct bt_value; |
c0418dd9 | 45 | |
f60c8b34 | 46 | enum bt_graph_status { |
a256a42d | 47 | BT_GRAPH_STATUS_COMPONENT_REFUSES_PORT_CONNECTION = 111, |
4a6b963e | 48 | /** Canceled. */ |
ad847455 | 49 | BT_GRAPH_STATUS_CANCELED = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED, |
72b913fb | 50 | /** No sink can consume at the moment. */ |
ad847455 | 51 | BT_GRAPH_STATUS_AGAIN = BT_COMPONENT_STATUS_AGAIN, |
f60c8b34 | 52 | /** Downstream component does not support multiple inputs. */ |
ad847455 PP |
53 | BT_GRAPH_STATUS_END = BT_COMPONENT_STATUS_END, |
54 | BT_GRAPH_STATUS_OK = BT_COMPONENT_STATUS_OK, | |
f60c8b34 | 55 | /** Invalid arguments. */ |
ad847455 | 56 | BT_GRAPH_STATUS_INVALID = BT_COMPONENT_STATUS_INVALID, |
f60c8b34 | 57 | /** No sink in graph. */ |
fe8ad2b6 | 58 | BT_GRAPH_STATUS_NO_SINK = -6, |
f60c8b34 | 59 | /** General error. */ |
ad847455 PP |
60 | BT_GRAPH_STATUS_ERROR = BT_COMPONENT_STATUS_ERROR, |
61 | BT_GRAPH_STATUS_NOMEM = BT_COMPONENT_STATUS_NOMEM, | |
f60c8b34 | 62 | }; |
c0418dd9 | 63 | |
1bf957a0 PP |
64 | typedef void (*bt_graph_port_added_listener)(struct bt_port *port, |
65 | void *data); | |
66 | typedef void (*bt_graph_port_removed_listener)(struct bt_component *component, | |
67 | struct bt_port *port, void *data); | |
f345f8bb PP |
68 | typedef void (*bt_graph_ports_connected_listener)(struct bt_port *upstream_port, |
69 | struct bt_port *downstream_port, void *data); | |
70 | typedef void (*bt_graph_ports_disconnected_listener)( | |
71 | struct bt_component *upstream_component, | |
72 | struct bt_component *downstream_component, | |
73 | struct bt_port *upstream_port, struct bt_port *downstream_port, | |
1bf957a0 | 74 | void *data); |
8cc092c9 | 75 | typedef void (* bt_graph_listener_removed)(void *data); |
1bf957a0 | 76 | |
f60c8b34 | 77 | extern struct bt_graph *bt_graph_create(void); |
c0418dd9 | 78 | |
36712f1d PP |
79 | extern enum bt_graph_status bt_graph_add_component( |
80 | struct bt_graph *graph, | |
81 | struct bt_component_class *component_class, | |
82 | const char *name, struct bt_value *params, | |
83 | struct bt_component **component); | |
84 | ||
85 | extern enum bt_graph_status bt_graph_add_component_with_init_method_data( | |
86 | struct bt_graph *graph, | |
87 | struct bt_component_class *component_class, | |
88 | const char *name, struct bt_value *params, | |
89 | void *init_method_data, | |
90 | struct bt_component **component); | |
91 | ||
c0418dd9 | 92 | /** |
f60c8b34 JG |
93 | * Creates a connection between two components using the two ports specified |
94 | * and adds the connection and components (if not already added) to the graph. | |
c0418dd9 | 95 | */ |
a256a42d PP |
96 | extern enum bt_graph_status bt_graph_connect_ports(struct bt_graph *graph, |
97 | struct bt_port *upstream, struct bt_port *downstream, | |
98 | struct bt_connection **connection); | |
c0418dd9 | 99 | |
c0418dd9 | 100 | /** |
f60c8b34 JG |
101 | * Run graph to completion or until a single sink is left and "AGAIN" is received. |
102 | * | |
c0418dd9 | 103 | * Runs "bt_component_sink_consume()" on all sinks in round-robin until they all |
f60c8b34 JG |
104 | * indicate that the end is reached or that an error occured. |
105 | */ | |
72b913fb | 106 | extern enum bt_graph_status bt_graph_run(struct bt_graph *graph); |
f60c8b34 JG |
107 | |
108 | /** | |
109 | * Runs "bt_component_sink_consume()" on the graph's sinks. Each invokation will | |
110 | * invoke "bt_component_sink_consume()" on the next sink, in round-robin, until | |
111 | * they all indicated that the end is reached. | |
c0418dd9 | 112 | */ |
72b913fb | 113 | extern enum bt_graph_status bt_graph_consume(struct bt_graph *graph); |
c0418dd9 | 114 | |
0d107cdd | 115 | extern int bt_graph_add_port_added_listener(struct bt_graph *graph, |
8cc092c9 PP |
116 | bt_graph_port_added_listener listener, |
117 | bt_graph_listener_removed listener_removed, void *data); | |
1bf957a0 | 118 | |
0d107cdd | 119 | extern int bt_graph_add_port_removed_listener(struct bt_graph *graph, |
8cc092c9 PP |
120 | bt_graph_port_removed_listener listener, |
121 | bt_graph_listener_removed listener_removed, void *data); | |
1bf957a0 | 122 | |
0d107cdd | 123 | extern int bt_graph_add_ports_connected_listener(struct bt_graph *graph, |
8cc092c9 PP |
124 | bt_graph_ports_connected_listener listener, |
125 | bt_graph_listener_removed listener_removed, void *data); | |
1bf957a0 | 126 | |
0d107cdd | 127 | extern int bt_graph_add_ports_disconnected_listener(struct bt_graph *graph, |
8cc092c9 PP |
128 | bt_graph_ports_disconnected_listener listener, |
129 | bt_graph_listener_removed listener_removed, void *data); | |
1bf957a0 | 130 | |
202a3a13 PP |
131 | extern enum bt_graph_status bt_graph_cancel(struct bt_graph *graph); |
132 | extern bt_bool bt_graph_is_canceled(struct bt_graph *graph); | |
133 | ||
c0418dd9 JG |
134 | #ifdef __cplusplus |
135 | } | |
136 | #endif | |
137 | ||
1ca80abd | 138 | #endif /* BABELTRACE_GRAPH_GRAPH_H */ |