cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / lib / graph / graph.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 */
7
8 #ifndef BABELTRACE_GRAPH_GRAPH_INTERNAL_H
9 #define BABELTRACE_GRAPH_GRAPH_INTERNAL_H
10
11 /* Protection: this file uses BT_LIB_LOG*() macros directly */
12 #ifndef BT_LIB_LOG_SUPPORTED
13 # error Please include "lib/logging.h" before including this file.
14 #endif
15
16 #include <babeltrace2/graph/graph.h>
17 #include <babeltrace2/graph/message.h>
18 #include "lib/object.h"
19 #include "lib/object-pool.h"
20 #include "common/assert.h"
21 #include <stdbool.h>
22 #include <glib.h>
23
24 #include "component.h"
25 #include "component-sink.h"
26 #include "connection.h"
27
28 /* Protection: this file uses BT_LIB_LOG*() macros directly */
29 #ifndef BT_LIB_LOG_SUPPORTED
30 # error Please include "lib/logging.h" before including this file.
31 #endif
32
33 struct bt_component;
34 struct bt_port;
35
36 enum bt_graph_configuration_state {
37 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
38 BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED,
39 BT_GRAPH_CONFIGURATION_STATE_CONFIGURED,
40 BT_GRAPH_CONFIGURATION_STATE_FAULTY,
41 BT_GRAPH_CONFIGURATION_STATE_DESTROYING,
42 };
43
44 struct bt_graph {
45 /**
46 * A component graph contains components and point-to-point connection
47 * between these components.
48 *
49 * In terms of ownership:
50 * 1) The graph is the components' parent,
51 * 2) The graph is the connections' parent,
52 * 3) Components share the ownership of their connections,
53 * 4) A connection holds weak references to its two component endpoints.
54 */
55 struct bt_object base;
56
57 /* Array of pointers to bt_connection. */
58 GPtrArray *connections;
59 /* Array of pointers to bt_component. */
60 GPtrArray *components;
61 /* Queue of pointers (weak references) to sink bt_components. */
62 GQueue *sinks_to_consume;
63
64 uint64_t mip_version;
65
66 /*
67 * Array of `struct bt_interrupter *`, each one owned by this.
68 * If any interrupter is set, then this graph is deemed
69 * interrupted.
70 */
71 GPtrArray *interrupters;
72
73 /*
74 * Default interrupter, owned by this.
75 */
76 struct bt_interrupter *default_interrupter;
77
78 bool has_sink;
79
80 /*
81 * If this is false, then the public API's consuming
82 * functions (bt_graph_consume() and bt_graph_run()) return
83 * BT_FUNC_STATUS_CANNOT_CONSUME. The internal "no check"
84 * functions always work.
85 *
86 * In bt_port_output_message_iterator_create(), on success,
87 * this flag is cleared so that the iterator remains the only
88 * consumer for the graph's lifetime.
89 */
90 bool can_consume;
91
92 enum bt_graph_configuration_state config_state;
93
94 struct {
95 GArray *source_output_port_added;
96 GArray *filter_output_port_added;
97 GArray *filter_input_port_added;
98 GArray *sink_input_port_added;
99 } listeners;
100
101 /* Pool of `struct bt_message_event *` */
102 struct bt_object_pool event_msg_pool;
103
104 /* Pool of `struct bt_message_packet_beginning *` */
105 struct bt_object_pool packet_begin_msg_pool;
106
107 /* Pool of `struct bt_message_packet_end *` */
108 struct bt_object_pool packet_end_msg_pool;
109
110 /*
111 * Array of `struct bt_message *` (weak).
112 *
113 * This is an array of all the messages ever created from
114 * this graph. Some of them can be in one of the pools above,
115 * some of them can be at large. Because each message has a
116 * weak pointer to the graph containing its pool, we need to
117 * notify each message that the graph is gone on graph
118 * destruction.
119 *
120 * TODO: When we support a maximum size for object pools,
121 * add a way for a message to remove itself from this
122 * array (on destruction).
123 */
124 GPtrArray *messages;
125 };
126
127 static inline
128 void bt_graph_set_can_consume(struct bt_graph *graph, bool can_consume)
129 {
130 BT_ASSERT_DBG(graph);
131 graph->can_consume = can_consume;
132 }
133
134 int bt_graph_consume_sink_no_check(struct bt_graph *graph,
135 struct bt_component_sink *sink);
136
137 enum bt_graph_listener_func_status bt_graph_notify_port_added(struct bt_graph *graph,
138 struct bt_port *port);
139
140 void bt_graph_remove_connection(struct bt_graph *graph,
141 struct bt_connection *connection);
142
143 void bt_graph_add_message(struct bt_graph *graph,
144 struct bt_message *msg);
145
146 bool bt_graph_is_interrupted(const struct bt_graph *graph);
147
148 static inline
149 const char *bt_graph_configuration_state_string(
150 enum bt_graph_configuration_state state)
151 {
152 switch (state) {
153 case BT_GRAPH_CONFIGURATION_STATE_CONFIGURING:
154 return "CONFIGURING";
155 case BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED:
156 return "PARTIALLY_CONFIGURED";
157 case BT_GRAPH_CONFIGURATION_STATE_CONFIGURED:
158 return "CONFIGURED";
159 case BT_GRAPH_CONFIGURATION_STATE_FAULTY:
160 return "FAULTY";
161 case BT_GRAPH_CONFIGURATION_STATE_DESTROYING:
162 return "DESTROYING";
163 default:
164 return "(unknown)";
165 }
166 }
167
168 static inline
169 void bt_graph_make_faulty(struct bt_graph *graph)
170 {
171 graph->config_state = BT_GRAPH_CONFIGURATION_STATE_FAULTY;
172 BT_LIB_LOGI("Set graph's state to faulty: %![graph-]+g", graph);
173 }
174
175 #endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */
This page took 0.032447 seconds and 4 git commands to generate.