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