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 "lib/object.h"
19 #include "lib/object-pool.h"
20 #include "common/assert.h"
24 #include "component.h"
25 #include "component-sink.h"
26 #include "connection.h"
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.
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
,
46 * A component graph contains components and point-to-point connection
47 * between these components.
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.
55 struct bt_object base
;
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
;
67 * Array of `struct bt_interrupter *`, each one owned by this.
68 * If any interrupter is set, then this graph is deemed
71 GPtrArray
*interrupters
;
74 * Default interrupter, owned by this.
76 struct bt_interrupter
*default_interrupter
;
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.
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.
92 enum bt_graph_configuration_state config_state
;
95 GArray
*source_output_port_added
;
96 GArray
*filter_output_port_added
;
97 GArray
*filter_input_port_added
;
98 GArray
*sink_input_port_added
;
101 /* Pool of `struct bt_message_event *` */
102 struct bt_object_pool event_msg_pool
;
104 /* Pool of `struct bt_message_packet_beginning *` */
105 struct bt_object_pool packet_begin_msg_pool
;
107 /* Pool of `struct bt_message_packet_end *` */
108 struct bt_object_pool packet_end_msg_pool
;
111 * Array of `struct bt_message *` (weak).
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
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).
128 void bt_graph_set_can_consume(struct bt_graph
*graph
, bool can_consume
)
130 BT_ASSERT_DBG(graph
);
131 graph
->can_consume
= can_consume
;
134 int bt_graph_consume_sink_no_check(struct bt_graph
*graph
,
135 struct bt_component_sink
*sink
);
137 enum bt_graph_listener_func_status
bt_graph_notify_port_added(struct bt_graph
*graph
,
138 struct bt_port
*port
);
140 void bt_graph_remove_connection(struct bt_graph
*graph
,
141 struct bt_connection
*connection
);
143 void bt_graph_add_message(struct bt_graph
*graph
,
144 struct bt_message
*msg
);
146 bool bt_graph_is_interrupted(const struct bt_graph
*graph
);
149 const char *bt_graph_configuration_state_string(
150 enum bt_graph_configuration_state 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
:
159 case BT_GRAPH_CONFIGURATION_STATE_FAULTY
:
161 case BT_GRAPH_CONFIGURATION_STATE_DESTROYING
:
169 void bt_graph_make_faulty(struct bt_graph
*graph
)
171 graph
->config_state
= BT_GRAPH_CONFIGURATION_STATE_FAULTY
;
172 BT_LIB_LOGI("Set graph's state to faulty: %![graph-]+g", graph
);
175 #endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */