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