Move to kernel style SPDX license identifiers
[babeltrace.git] / src / lib / graph / component.h
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 */
7
8 #ifndef BABELTRACE_GRAPH_COMPONENT_INTERNAL_H
9 #define BABELTRACE_GRAPH_COMPONENT_INTERNAL_H
10
11 #include "common/macros.h"
12 #include <babeltrace2/graph/component.h>
13 #include <babeltrace2/graph/component-class.h>
14 #include "lib/object.h"
15 #include <babeltrace2/types.h>
16 #include <babeltrace2/logging.h>
17 #include "common/assert.h"
18 #include <glib.h>
19 #include <stdbool.h>
20 #include <stdio.h>
21
22 #include "component-class.h"
23 #include "port.h"
24
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
33 struct bt_graph;
34
35 struct bt_component {
36 struct bt_object base;
37 struct bt_component_class *class;
38 GString *name;
39 bt_logging_level log_level;
40
41 /*
42 * Internal destroy function specific to a source, filter, or
43 * sink component object.
44 */
45 void (*destroy)(struct bt_component *);
46
47 /* User-defined data */
48 void *user_data;
49
50 /* Input and output ports (weak references) */
51 GPtrArray *input_ports;
52 GPtrArray *output_ports;
53
54 /* Array of struct bt_component_destroy_listener */
55 GArray *destroy_listeners;
56
57 bool initialized;
58 };
59
60 static inline
61 struct bt_graph *bt_component_borrow_graph(struct bt_component *comp)
62 {
63 BT_ASSERT_DBG(comp);
64 return (void *) bt_object_borrow_parent(&comp->base);
65 }
66
67 BT_HIDDEN
68 int bt_component_create(struct bt_component_class *component_class,
69 const char *name, bt_logging_level log_level,
70 struct bt_component **component);
71
72 BT_HIDDEN
73 enum bt_component_class_port_connected_method_status
74 bt_component_port_connected(
75 struct bt_component *comp,
76 struct bt_port *self_port, struct bt_port *other_port);
77
78 BT_HIDDEN
79 void bt_component_set_graph(struct bt_component *component,
80 struct bt_graph *graph);
81
82 BT_HIDDEN
83 uint64_t bt_component_get_input_port_count(const struct bt_component *comp);
84
85 BT_HIDDEN
86 uint64_t bt_component_get_output_port_count(const struct bt_component *comp);
87
88 BT_HIDDEN
89 struct bt_port_input *bt_component_borrow_input_port_by_index(
90 struct bt_component *comp, uint64_t index);
91
92 BT_HIDDEN
93 struct bt_port_output *bt_component_borrow_output_port_by_index(
94 struct bt_component *comp, uint64_t index);
95
96 BT_HIDDEN
97 struct bt_port_input *bt_component_borrow_input_port_by_name(
98 struct bt_component *comp, const char *name);
99
100 BT_HIDDEN
101 struct bt_port_output *bt_component_borrow_output_port_by_name(
102 struct bt_component *comp, const char *name);
103
104 BT_HIDDEN
105 enum bt_self_component_add_port_status bt_component_add_input_port(
106 struct bt_component *component, const char *name,
107 void *user_data, struct bt_port **port);
108
109 BT_HIDDEN
110 enum bt_self_component_add_port_status bt_component_add_output_port(
111 struct bt_component *component, const char *name,
112 void *user_data, struct bt_port **port);
113
114 BT_HIDDEN
115 void bt_component_remove_port(struct bt_component *component,
116 struct bt_port *port);
117
118 BT_HIDDEN
119 void bt_component_add_destroy_listener(struct bt_component *component,
120 bt_component_destroy_listener_func func, void *data);
121
122 BT_HIDDEN
123 void bt_component_remove_destroy_listener(struct bt_component *component,
124 bt_component_destroy_listener_func func, void *data);
125
126 #endif /* BABELTRACE_GRAPH_COMPONENT_INTERNAL_H */
This page took 0.031033 seconds and 4 git commands to generate.