93546445d0dbdd45e9cd6a127cb8df90957d0801
[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 /* User-defined data */
42 void *user_data;
43
44 /* Input and output ports (weak references) */
45 GPtrArray *input_ports;
46 GPtrArray *output_ports;
47
48 /* Array of struct bt_component_destroy_listener */
49 GArray *destroy_listeners;
50
51 bool initialized;
52 };
53
54 static inline
55 struct bt_graph *bt_component_borrow_graph(struct bt_component *comp)
56 {
57 BT_ASSERT_DBG(comp);
58 return (void *) bt_object_borrow_parent(&comp->base);
59 }
60
61 int bt_component_create(struct bt_component_class *component_class,
62 const char *name, bt_logging_level log_level,
63 struct bt_component **component);
64
65 enum bt_component_class_port_connected_method_status
66 bt_component_port_connected(
67 struct bt_component *comp,
68 struct bt_port *self_port, struct bt_port *other_port);
69
70 void bt_component_set_graph(struct bt_component *component,
71 struct bt_graph *graph);
72
73 uint64_t bt_component_get_input_port_count(const struct bt_component *comp,
74 const char *api_func);
75
76 uint64_t bt_component_get_output_port_count(const struct bt_component *comp,
77 const char *api_func);
78
79 struct bt_port_input *bt_component_borrow_input_port_by_index(
80 struct bt_component *comp, uint64_t index,
81 const char *api_func);
82
83 struct bt_port_output *bt_component_borrow_output_port_by_index(
84 struct bt_component *comp, uint64_t index,
85 const char *api_func);
86
87 struct bt_port_input *bt_component_borrow_input_port_by_name(
88 struct bt_component *comp, const char *name,
89 const char *api_func);
90
91 struct bt_port_output *bt_component_borrow_output_port_by_name(
92 struct bt_component *comp, const char *name,
93 const char *api_func);
94
95 enum bt_self_component_add_port_status bt_component_add_input_port(
96 struct bt_component *component, const char *name,
97 void *user_data, struct bt_port **port,
98 const char *api_func);
99
100 enum bt_self_component_add_port_status bt_component_add_output_port(
101 struct bt_component *component, const char *name,
102 void *user_data, struct bt_port **port,
103 const char *api_func);
104
105 void bt_component_remove_port(struct bt_component *component,
106 struct bt_port *port);
107
108 void bt_component_add_destroy_listener(struct bt_component *component,
109 bt_component_destroy_listener_func func, void *data);
110
111 void bt_component_remove_destroy_listener(struct bt_component *component,
112 bt_component_destroy_listener_func func, void *data);
113
114 #endif /* BABELTRACE_GRAPH_COMPONENT_INTERNAL_H */
This page took 0.030156 seconds and 3 git commands to generate.