lib: assign a unique ID to each pre/postcond. and report it on failure
[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 #define BT_ASSERT_PRE_OUTPUT_PORT_NAME_UNIQUE(comp, name) \
26 BT_ASSERT_PRE("output-port-is-unique", \
27 bt_component_port_name_is_unique(comp->output_ports, name), \
28 "Output port name is not unique: name=\"%s\", %![comp-]c", name, comp);
29
30 typedef void (*bt_component_destroy_listener_func)(
31 struct bt_component *class, void *data);
32
33 struct bt_component_destroy_listener {
34 bt_component_destroy_listener_func func;
35 void *data;
36 };
37
38 struct bt_graph;
39
40 struct bt_component {
41 struct bt_object base;
42 struct bt_component_class *class;
43 GString *name;
44 bt_logging_level log_level;
45
46 /*
47 * Internal destroy function specific to a source, filter, or
48 * sink component object.
49 */
50 void (*destroy)(struct bt_component *);
51
52 /* User-defined data */
53 void *user_data;
54
55 /* Input and output ports (weak references) */
56 GPtrArray *input_ports;
57 GPtrArray *output_ports;
58
59 /* Array of struct bt_component_destroy_listener */
60 GArray *destroy_listeners;
61
62 bool initialized;
63 };
64
65 static inline
66 struct bt_graph *bt_component_borrow_graph(struct bt_component *comp)
67 {
68 BT_ASSERT_DBG(comp);
69 return (void *) bt_object_borrow_parent(&comp->base);
70 }
71
72 BT_HIDDEN
73 int bt_component_create(struct bt_component_class *component_class,
74 const char *name, bt_logging_level log_level,
75 struct bt_component **component);
76
77 BT_HIDDEN
78 enum bt_component_class_port_connected_method_status
79 bt_component_port_connected(
80 struct bt_component *comp,
81 struct bt_port *self_port, struct bt_port *other_port);
82
83 BT_HIDDEN
84 void bt_component_set_graph(struct bt_component *component,
85 struct bt_graph *graph);
86
87 BT_HIDDEN
88 uint64_t bt_component_get_input_port_count(const struct bt_component *comp,
89 const char *api_func);
90
91 BT_HIDDEN
92 uint64_t bt_component_get_output_port_count(const struct bt_component *comp,
93 const char *api_func);
94
95 BT_HIDDEN
96 struct bt_port_input *bt_component_borrow_input_port_by_index(
97 struct bt_component *comp, uint64_t index,
98 const char *api_func);
99
100 BT_HIDDEN
101 struct bt_port_output *bt_component_borrow_output_port_by_index(
102 struct bt_component *comp, uint64_t index,
103 const char *api_func);
104
105 BT_HIDDEN
106 struct bt_port_input *bt_component_borrow_input_port_by_name(
107 struct bt_component *comp, const char *name,
108 const char *api_func);
109
110 BT_HIDDEN
111 struct bt_port_output *bt_component_borrow_output_port_by_name(
112 struct bt_component *comp, const char *name,
113 const char *api_func);
114
115 BT_HIDDEN
116 enum bt_self_component_add_port_status bt_component_add_input_port(
117 struct bt_component *component, const char *name,
118 void *user_data, struct bt_port **port,
119 const char *api_func);
120
121 BT_HIDDEN
122 enum bt_self_component_add_port_status bt_component_add_output_port(
123 struct bt_component *component, const char *name,
124 void *user_data, struct bt_port **port,
125 const char *api_func);
126
127 BT_HIDDEN
128 bool bt_component_port_name_is_unique(GPtrArray *ports, const char *name);
129
130 BT_HIDDEN
131 void bt_component_remove_port(struct bt_component *component,
132 struct bt_port *port);
133
134 BT_HIDDEN
135 void bt_component_add_destroy_listener(struct bt_component *component,
136 bt_component_destroy_listener_func func, void *data);
137
138 BT_HIDDEN
139 void bt_component_remove_destroy_listener(struct bt_component *component,
140 bt_component_destroy_listener_func func, void *data);
141
142 #endif /* BABELTRACE_GRAPH_COMPONENT_INTERNAL_H */
This page took 0.032731 seconds and 5 git commands to generate.