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