lib: remove BT_ASSERT_COND_SUPPORTED check in graph/graph.h
[babeltrace.git] / src / lib / graph / graph.h
CommitLineData
c0418dd9 1/*
0235b0db
MJ
2 * SPDX-License-Identifier: MIT
3 *
e2f7325d 4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
f60c8b34 5 * Copyright 2017 Jérémie Galarneau <jeremie.galarneau@efficios.com>
c0418dd9
JG
6 */
7
0235b0db
MJ
8#ifndef BABELTRACE_GRAPH_GRAPH_INTERNAL_H
9#define BABELTRACE_GRAPH_GRAPH_INTERNAL_H
10
870631a2
PP
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
3fadfbc0 16#include <babeltrace2/graph/graph.h>
43c59509 17#include <babeltrace2/graph/message.h>
91d81473 18#include "common/macros.h"
578e048b
MJ
19#include "lib/object.h"
20#include "lib/object-pool.h"
21#include "common/assert.h"
de625d1c 22#include "common/common.h"
c4f23e30 23#include <stdbool.h>
a256a42d 24#include <stdlib.h>
c0418dd9
JG
25#include <glib.h>
26
578e048b
MJ
27#include "component.h"
28#include "component-sink.h"
29#include "connection.h"
d24d5663 30#include "lib/func-status.h"
578e048b 31
51375aa9
PP
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
1bf957a0
PP
37struct bt_component;
38struct bt_port;
39
5badd463
PP
40enum bt_graph_configuration_state {
41 BT_GRAPH_CONFIGURATION_STATE_CONFIGURING,
42 BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED,
43 BT_GRAPH_CONFIGURATION_STATE_CONFIGURED,
38cda5da 44 BT_GRAPH_CONFIGURATION_STATE_FAULTY,
9b4f9b42 45 BT_GRAPH_CONFIGURATION_STATE_DESTROYING,
5badd463
PP
46};
47
f60c8b34
JG
48struct bt_graph {
49 /**
50 * A component graph contains components and point-to-point connection
51 * between these components.
c0418dd9 52 *
f60c8b34
JG
53 * In terms of ownership:
54 * 1) The graph is the components' parent,
e7401568 55 * 2) The graph is the connections' parent,
f60c8b34
JG
56 * 3) Components share the ownership of their connections,
57 * 4) A connection holds weak references to its two component endpoints.
c0418dd9 58 */
f60c8b34
JG
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;
1bf957a0 67
056deb59
PP
68 uint64_t mip_version;
69
9b4f9b42
PP
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 /*
c513d240 78 * Default interrupter, owned by this.
9b4f9b42
PP
79 */
80 struct bt_interrupter *default_interrupter;
81
d94d92ac 82 bool has_sink;
8ed535b5
PP
83
84 /*
d94d92ac 85 * If this is false, then the public API's consuming
8ed535b5 86 * functions (bt_graph_consume() and bt_graph_run()) return
d24d5663 87 * BT_FUNC_STATUS_CANNOT_CONSUME. The internal "no check"
8ed535b5
PP
88 * functions always work.
89 *
d6e69534 90 * In bt_port_output_message_iterator_create(), on success,
8ed535b5
PP
91 * this flag is cleared so that the iterator remains the only
92 * consumer for the graph's lifetime.
93 */
d94d92ac 94 bool can_consume;
202a3a13 95
5badd463 96 enum bt_graph_configuration_state config_state;
4725a201 97
1bf957a0 98 struct {
d94d92ac
PP
99 GArray *source_output_port_added;
100 GArray *filter_output_port_added;
101 GArray *filter_input_port_added;
102 GArray *sink_input_port_added;
1bf957a0 103 } listeners;
5c563278 104
d6e69534
PP
105 /* Pool of `struct bt_message_event *` */
106 struct bt_object_pool event_msg_pool;
5c563278 107
d6e69534
PP
108 /* Pool of `struct bt_message_packet_beginning *` */
109 struct bt_object_pool packet_begin_msg_pool;
5c563278 110
d6e69534
PP
111 /* Pool of `struct bt_message_packet_end *` */
112 struct bt_object_pool packet_end_msg_pool;
5c563278
PP
113
114 /*
d6e69534 115 * Array of `struct bt_message *` (weak).
5c563278 116 *
d6e69534 117 * This is an array of all the messages ever created from
5c563278 118 * this graph. Some of them can be in one of the pools above,
d6e69534 119 * some of them can be at large. Because each message has a
5c563278 120 * weak pointer to the graph containing its pool, we need to
d6e69534 121 * notify each message that the graph is gone on graph
5c563278
PP
122 * destruction.
123 *
124 * TODO: When we support a maximum size for object pools,
d6e69534 125 * add a way for a message to remove itself from this
5c563278
PP
126 * array (on destruction).
127 */
d6e69534 128 GPtrArray *messages;
c0418dd9
JG
129};
130
8ed535b5 131static inline
bdb288b3 132void bt_graph_set_can_consume(struct bt_graph *graph, bool can_consume)
8ed535b5 133{
98b15851 134 BT_ASSERT_DBG(graph);
8ed535b5
PP
135 graph->can_consume = can_consume;
136}
137
d24d5663 138int bt_graph_consume_sink_no_check(struct bt_graph *graph,
d94d92ac 139 struct bt_component_sink *sink);
8ed535b5 140
d24d5663 141enum bt_graph_listener_func_status bt_graph_notify_port_added(struct bt_graph *graph,
8cc56726 142 struct bt_port *port);
1bf957a0 143
f167d3c0
PP
144void bt_graph_remove_connection(struct bt_graph *graph,
145 struct bt_connection *connection);
146
d6e69534
PP
147void bt_graph_add_message(struct bt_graph *graph,
148 struct bt_message *msg);
5c563278 149
9b4f9b42
PP
150bool bt_graph_is_interrupted(const struct bt_graph *graph);
151
5badd463
PP
152static inline
153const char *bt_graph_configuration_state_string(
154 enum bt_graph_configuration_state state)
155{
156 switch (state) {
157 case BT_GRAPH_CONFIGURATION_STATE_CONFIGURING:
8a432889 158 return "CONFIGURING";
5badd463 159 case BT_GRAPH_CONFIGURATION_STATE_PARTIALLY_CONFIGURED:
8a432889 160 return "PARTIALLY_CONFIGURED";
5badd463 161 case BT_GRAPH_CONFIGURATION_STATE_CONFIGURED:
8a432889
PP
162 return "CONFIGURED";
163 case BT_GRAPH_CONFIGURATION_STATE_FAULTY:
164 return "FAULTY";
165 case BT_GRAPH_CONFIGURATION_STATE_DESTROYING:
166 return "DESTROYING";
5badd463
PP
167 default:
168 return "(unknown)";
169 }
170}
171
8cc56726
SM
172static inline
173void bt_graph_make_faulty(struct bt_graph *graph)
174{
175 graph->config_state = BT_GRAPH_CONFIGURATION_STATE_FAULTY;
3f7d4d90 176 BT_LIB_LOGI("Set graph's state to faulty: %![graph-]+g", graph);
8cc56726
SM
177}
178
6ac74c0c 179#endif /* BABELTRACE_GRAPH_GRAPH_INTERNAL_H */
This page took 0.106318 seconds and 4 git commands to generate.