Commit | Line | Data |
---|---|---|
90354d3a | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
e2f7325d | 4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
90354d3a | 5 | * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
90354d3a JG |
6 | */ |
7 | ||
0235b0db MJ |
8 | #ifndef BABELTRACE_GRAPH_COMPONENT_INTERNAL_H |
9 | #define BABELTRACE_GRAPH_COMPONENT_INTERNAL_H | |
10 | ||
91d81473 | 11 | #include "common/macros.h" |
43c59509 | 12 | #include <babeltrace2/graph/component.h> |
d24d5663 | 13 | #include <babeltrace2/graph/component-class.h> |
578e048b | 14 | #include "lib/object.h" |
3fadfbc0 | 15 | #include <babeltrace2/types.h> |
e874da19 | 16 | #include <babeltrace2/logging.h> |
578e048b | 17 | #include "common/assert.h" |
0db5ca2c | 18 | #include <glib.h> |
c4f23e30 | 19 | #include <stdbool.h> |
38d02a17 | 20 | #include <stdio.h> |
90354d3a | 21 | |
578e048b MJ |
22 | #include "component-class.h" |
23 | #include "port.h" | |
24 | ||
3230ee6b PP |
25 | typedef void (*bt_component_destroy_listener_func)( |
26 | struct bt_component *class, void *data); | |
27 | ||
28 | struct bt_component_destroy_listener { | |
29 | bt_component_destroy_listener_func func; | |
30 | void *data; | |
31 | }; | |
32 | ||
e5be10ef PP |
33 | struct bt_graph; |
34 | ||
633edee0 | 35 | struct bt_component { |
b8a06801 | 36 | struct bt_object base; |
fb2dcc52 | 37 | struct bt_component_class *class; |
0db5ca2c | 38 | GString *name; |
e874da19 | 39 | bt_logging_level log_level; |
584e4e78 | 40 | |
72b913fb | 41 | /* |
d3e4dcd8 PP |
42 | * Internal destroy function specific to a source, filter, or |
43 | * sink component object. | |
44 | */ | |
890882ef | 45 | void (*destroy)(struct bt_component *); |
d3e4dcd8 | 46 | |
72b913fb | 47 | /* User-defined data */ |
0777b693 | 48 | void *user_data; |
fec2a9f2 | 49 | |
72b913fb PP |
50 | /* Input and output ports (weak references) */ |
51 | GPtrArray *input_ports; | |
52 | GPtrArray *output_ports; | |
3230ee6b PP |
53 | |
54 | /* Array of struct bt_component_destroy_listener */ | |
55 | GArray *destroy_listeners; | |
36712f1d PP |
56 | |
57 | bool initialized; | |
72b913fb | 58 | }; |
38b48196 | 59 | |
e5be10ef PP |
60 | static inline |
61 | struct bt_graph *bt_component_borrow_graph(struct bt_component *comp) | |
62 | { | |
98b15851 | 63 | BT_ASSERT_DBG(comp); |
e5be10ef PP |
64 | return (void *) bt_object_borrow_parent(&comp->base); |
65 | } | |
66 | ||
d94d92ac | 67 | int bt_component_create(struct bt_component_class *component_class, |
e874da19 PP |
68 | const char *name, bt_logging_level log_level, |
69 | struct bt_component **component); | |
36712f1d | 70 | |
d24d5663 PP |
71 | enum bt_component_class_port_connected_method_status |
72 | bt_component_port_connected( | |
bf55043c | 73 | struct bt_component *comp, |
0d8b4d8e PP |
74 | struct bt_port *self_port, struct bt_port *other_port); |
75 | ||
f60c8b34 | 76 | void bt_component_set_graph(struct bt_component *component, |
366e034f JG |
77 | struct bt_graph *graph); |
78 | ||
1778c2a4 PP |
79 | uint64_t bt_component_get_input_port_count(const struct bt_component *comp, |
80 | const char *api_func); | |
366e034f | 81 | |
1778c2a4 PP |
82 | uint64_t bt_component_get_output_port_count(const struct bt_component *comp, |
83 | const char *api_func); | |
366e034f | 84 | |
d94d92ac | 85 | struct bt_port_input *bt_component_borrow_input_port_by_index( |
1778c2a4 PP |
86 | struct bt_component *comp, uint64_t index, |
87 | const char *api_func); | |
366e034f | 88 | |
d94d92ac | 89 | struct bt_port_output *bt_component_borrow_output_port_by_index( |
1778c2a4 PP |
90 | struct bt_component *comp, uint64_t index, |
91 | const char *api_func); | |
366e034f | 92 | |
d94d92ac | 93 | struct bt_port_input *bt_component_borrow_input_port_by_name( |
1778c2a4 PP |
94 | struct bt_component *comp, const char *name, |
95 | const char *api_func); | |
366e034f | 96 | |
d94d92ac | 97 | struct bt_port_output *bt_component_borrow_output_port_by_name( |
1778c2a4 PP |
98 | struct bt_component *comp, const char *name, |
99 | const char *api_func); | |
366e034f | 100 | |
d24d5663 | 101 | enum bt_self_component_add_port_status bt_component_add_input_port( |
3e9b0023 | 102 | struct bt_component *component, const char *name, |
1778c2a4 PP |
103 | void *user_data, struct bt_port **port, |
104 | const char *api_func); | |
72b913fb | 105 | |
d24d5663 | 106 | enum bt_self_component_add_port_status bt_component_add_output_port( |
3e9b0023 | 107 | struct bt_component *component, const char *name, |
1778c2a4 PP |
108 | void *user_data, struct bt_port **port, |
109 | const char *api_func); | |
72b913fb | 110 | |
d94d92ac PP |
111 | void bt_component_remove_port(struct bt_component *component, |
112 | struct bt_port *port); | |
72b913fb | 113 | |
3230ee6b PP |
114 | void bt_component_add_destroy_listener(struct bt_component *component, |
115 | bt_component_destroy_listener_func func, void *data); | |
116 | ||
3230ee6b PP |
117 | void bt_component_remove_destroy_listener(struct bt_component *component, |
118 | bt_component_destroy_listener_func func, void *data); | |
119 | ||
6ac74c0c | 120 | #endif /* BABELTRACE_GRAPH_COMPONENT_INTERNAL_H */ |