2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 #ifndef BABELTRACE_GRAPH_GRAPH_INTERNAL_H
9 #define BABELTRACE_GRAPH_GRAPH_INTERNAL_H
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.
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"
27 #include "component.h"
28 #include "component-sink.h"
29 #include "connection.h"
30 #include "lib/func-status.h"
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.
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
,
50 * A component graph contains components and point-to-point connection
51 * between these components.
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.
59 struct bt_object base
;
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
;
71 * Array of `struct bt_interrupter *`, each one owned by this.
72 * If any interrupter is set, then this graph is deemed
75 GPtrArray
*interrupters
;
78 * Default interrupter, owned by this.
80 struct bt_interrupter
*default_interrupter
;
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.
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.
96 enum bt_graph_configuration_state config_state
;
99 GArray
*source_output_port_added
;
100 GArray
*filter_output_port_added
;
101 GArray
*filter_input_port_added
;
102 GArray
*sink_input_port_added
;
105 /* Pool of `struct bt_message_event *` */
106 struct bt_object_pool event_msg_pool
;
108 /* Pool of `struct bt_message_packet_beginning *` */
109 struct bt_object_pool packet_begin_msg_pool
;
111 /* Pool of `struct bt_message_packet_end *` */
112 struct bt_object_pool packet_end_msg_pool
;
115 * Array of `struct bt_message *` (weak).
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
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).
132 void bt_graph_set_can_consume(struct bt_graph
*graph
, bool can_consume
)
134 BT_ASSERT_DBG(graph
);
135 graph
->can_consume
= can_consume
;
138 int bt_graph_consume_sink_no_check(struct bt_graph
*graph
,
139 struct bt_component_sink
*sink
);
141 enum bt_graph_listener_func_status
bt_graph_notify_port_added(struct bt_graph
*graph
,
142 struct bt_port
*port
);
144 void bt_graph_remove_connection(struct bt_graph
*graph
,
145 struct bt_connection
*connection
);
147 void bt_graph_add_message(struct bt_graph
*graph
,
148 struct bt_message
*msg
);
150 bool bt_graph_is_interrupted(const struct bt_graph
*graph
);
153 const char *bt_graph_configuration_state_string(
154 enum bt_graph_configuration_state 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
:
163 case BT_GRAPH_CONFIGURATION_STATE_FAULTY
:
165 case BT_GRAPH_CONFIGURATION_STATE_DESTROYING
:
173 void bt_graph_make_faulty(struct bt_graph
*graph
)
175 graph
->config_state
= BT_GRAPH_CONFIGURATION_STATE_FAULTY
;
176 BT_LIB_LOGI("Set graph's state to faulty: %![graph-]+g", graph
);
179 #endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */