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