Commit | Line | Data |
---|---|---|
d94d92ac | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
e2f7325d | 4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
d94d92ac | 5 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
d94d92ac PP |
6 | */ |
7 | ||
350ad6c1 | 8 | #define BT_LOG_TAG "LIB/COMPONENT-FILTER" |
c2d9d9cf | 9 | #include "lib/logging.h" |
d94d92ac | 10 | |
578e048b | 11 | #include "common/assert.h" |
d98421f2 | 12 | #include "lib/assert-cond.h" |
578e048b | 13 | #include "compat/compiler.h" |
3fadfbc0 | 14 | #include <babeltrace2/value.h> |
43c59509 PP |
15 | #include <babeltrace2/graph/self-component.h> |
16 | #include <babeltrace2/graph/component.h> | |
3fadfbc0 | 17 | #include <babeltrace2/graph/graph.h> |
d94d92ac | 18 | |
578e048b MJ |
19 | #include "component-filter.h" |
20 | #include "component.h" | |
21 | #include "component-class.h" | |
d24d5663 | 22 | #include "lib/func-status.h" |
578e048b | 23 | |
ecd7492f MJ |
24 | void bt_component_filter_destroy( |
25 | struct bt_component *component __attribute__((unused))) | |
d94d92ac PP |
26 | { |
27 | } | |
28 | ||
d94d92ac | 29 | struct bt_component *bt_component_filter_create( |
ecd7492f | 30 | const struct bt_component_class *class __attribute__((unused))) |
d94d92ac PP |
31 | { |
32 | struct bt_component_filter *filter = NULL; | |
33 | ||
34 | filter = g_new0(struct bt_component_filter, 1); | |
35 | if (!filter) { | |
870631a2 PP |
36 | BT_LIB_LOGE_APPEND_CAUSE( |
37 | "Failed to allocate one filter component."); | |
d94d92ac PP |
38 | goto end; |
39 | } | |
40 | ||
41 | end: | |
42 | return (void *) filter; | |
43 | } | |
44 | ||
1353b066 | 45 | BT_EXPORT |
752d0e47 SM |
46 | const bt_component_class_filter * |
47 | bt_component_filter_borrow_class_const( | |
48 | const bt_component_filter *component) | |
49 | { | |
50 | struct bt_component_class *cls; | |
51 | ||
d5b13b9b | 52 | BT_ASSERT_PRE_DEV_COMP_NON_NULL(component); |
752d0e47 SM |
53 | |
54 | cls = component->parent.class; | |
55 | ||
98b15851 PP |
56 | BT_ASSERT_DBG(cls); |
57 | BT_ASSERT_DBG(cls->type == BT_COMPONENT_CLASS_TYPE_FILTER); | |
752d0e47 SM |
58 | |
59 | return (bt_component_class_filter *) cls; | |
60 | } | |
61 | ||
1353b066 | 62 | BT_EXPORT |
d94d92ac | 63 | uint64_t bt_component_filter_get_output_port_count( |
0d72b8c3 | 64 | const struct bt_component_filter *comp) |
d94d92ac | 65 | { |
1778c2a4 PP |
66 | /* bt_component_get_output_port_count() checks preconditions */ |
67 | return bt_component_get_output_port_count((void *) comp, __func__); | |
d94d92ac PP |
68 | } |
69 | ||
1353b066 | 70 | BT_EXPORT |
0d72b8c3 PP |
71 | const struct bt_port_output * |
72 | bt_component_filter_borrow_output_port_by_name_const( | |
73 | const struct bt_component_filter *comp, const char *name) | |
d94d92ac | 74 | { |
1778c2a4 PP |
75 | /* |
76 | * bt_component_borrow_output_port_by_name() logs details/errors | |
77 | * and checks preconditions. | |
78 | */ | |
d94d92ac | 79 | return bt_component_borrow_output_port_by_name( |
1778c2a4 | 80 | (void *) comp, name, __func__); |
d94d92ac PP |
81 | } |
82 | ||
1353b066 | 83 | BT_EXPORT |
d94d92ac PP |
84 | struct bt_self_component_port_output * |
85 | bt_self_component_filter_borrow_output_port_by_name( | |
86 | struct bt_self_component_filter *comp, const char *name) | |
87 | { | |
1778c2a4 PP |
88 | /* |
89 | * bt_component_borrow_output_port_by_name() logs details/errors | |
90 | * and checks preconditions. | |
91 | */ | |
d94d92ac | 92 | return (void *) bt_component_borrow_output_port_by_name( |
1778c2a4 | 93 | (void *) comp, name, __func__); |
d94d92ac PP |
94 | } |
95 | ||
1353b066 | 96 | BT_EXPORT |
0d72b8c3 PP |
97 | const struct bt_port_output * |
98 | bt_component_filter_borrow_output_port_by_index_const( | |
99 | const struct bt_component_filter *comp, uint64_t index) | |
d94d92ac | 100 | { |
1778c2a4 PP |
101 | /* |
102 | * bt_component_borrow_output_port_by_index() logs | |
103 | * details/errors and checks preconditions. | |
104 | */ | |
d94d92ac | 105 | return bt_component_borrow_output_port_by_index( |
1778c2a4 | 106 | (void *) comp, index, __func__); |
d94d92ac PP |
107 | } |
108 | ||
1353b066 | 109 | BT_EXPORT |
d94d92ac PP |
110 | struct bt_self_component_port_output * |
111 | bt_self_component_filter_borrow_output_port_by_index( | |
112 | struct bt_self_component_filter *comp, uint64_t index) | |
113 | { | |
1778c2a4 PP |
114 | /* |
115 | * bt_component_borrow_output_port_by_index() logs | |
116 | * details/errors and checks preconditions. | |
117 | */ | |
d94d92ac | 118 | return (void *) bt_component_borrow_output_port_by_index( |
1778c2a4 | 119 | (void *) comp, index, __func__); |
d94d92ac PP |
120 | } |
121 | ||
1353b066 | 122 | BT_EXPORT |
d24d5663 | 123 | enum bt_self_component_add_port_status bt_self_component_filter_add_output_port( |
d94d92ac PP |
124 | struct bt_self_component_filter *self_comp, |
125 | const char *name, void *user_data, | |
126 | struct bt_self_component_port_output **self_port) | |
127 | { | |
128 | struct bt_component *comp = (void *) self_comp; | |
d24d5663 | 129 | enum bt_self_component_add_port_status status; |
d94d92ac PP |
130 | struct bt_port *port = NULL; |
131 | ||
1778c2a4 PP |
132 | /* |
133 | * bt_component_add_output_port() logs details/errors and checks | |
134 | * preconditions. | |
135 | */ | |
136 | status = bt_component_add_output_port(comp, name, user_data, &port, | |
137 | __func__); | |
d24d5663 | 138 | if (status != BT_FUNC_STATUS_OK) { |
d94d92ac PP |
139 | goto end; |
140 | } | |
141 | ||
142 | if (self_port) { | |
143 | /* Move reference to user */ | |
144 | *self_port = (void *) port; | |
d94d92ac PP |
145 | } |
146 | ||
147 | end: | |
148 | bt_object_put_ref(port); | |
149 | return status; | |
150 | } | |
151 | ||
1353b066 | 152 | BT_EXPORT |
d94d92ac | 153 | uint64_t bt_component_filter_get_input_port_count( |
0d72b8c3 | 154 | const struct bt_component_filter *component) |
d94d92ac | 155 | { |
1778c2a4 PP |
156 | /* bt_component_get_input_port_count() checks preconditions */ |
157 | return bt_component_get_input_port_count((void *) component, __func__); | |
d94d92ac PP |
158 | } |
159 | ||
1353b066 | 160 | BT_EXPORT |
0d72b8c3 PP |
161 | const struct bt_port_input *bt_component_filter_borrow_input_port_by_name_const( |
162 | const struct bt_component_filter *component, const char *name) | |
d94d92ac | 163 | { |
1778c2a4 PP |
164 | /* |
165 | * bt_component_borrow_input_port_by_name() logs details/errors | |
166 | * and checks preconditions. | |
167 | */ | |
d94d92ac | 168 | return bt_component_borrow_input_port_by_name( |
1778c2a4 | 169 | (void *) component, name, __func__); |
d94d92ac PP |
170 | } |
171 | ||
1353b066 | 172 | BT_EXPORT |
d94d92ac PP |
173 | struct bt_self_component_port_input * |
174 | bt_self_component_filter_borrow_input_port_by_name( | |
175 | struct bt_self_component_filter *component, const char *name) | |
176 | { | |
1778c2a4 PP |
177 | /* |
178 | * bt_component_borrow_input_port_by_name() logs details/errors | |
179 | * and checks preconditions. | |
180 | */ | |
d94d92ac | 181 | return (void *) bt_component_borrow_input_port_by_name( |
1778c2a4 | 182 | (void *) component, name, __func__); |
d94d92ac PP |
183 | } |
184 | ||
1353b066 | 185 | BT_EXPORT |
0d72b8c3 PP |
186 | const struct bt_port_input * |
187 | bt_component_filter_borrow_input_port_by_index_const( | |
188 | const struct bt_component_filter *component, uint64_t index) | |
d94d92ac | 189 | { |
1778c2a4 PP |
190 | /* |
191 | * bt_component_borrow_input_port_by_index() logs details/errors | |
192 | * and checks preconditions. | |
193 | */ | |
d94d92ac | 194 | return bt_component_borrow_input_port_by_index( |
1778c2a4 | 195 | (void *) component, index, __func__); |
d94d92ac PP |
196 | } |
197 | ||
1353b066 | 198 | BT_EXPORT |
d94d92ac PP |
199 | struct bt_self_component_port_input * |
200 | bt_self_component_filter_borrow_input_port_by_index( | |
201 | struct bt_self_component_filter *component, uint64_t index) | |
202 | { | |
1778c2a4 PP |
203 | /* |
204 | * bt_component_borrow_input_port_by_index() logs details/errors | |
205 | * and checks preconditions. | |
206 | */ | |
d94d92ac | 207 | return (void *) bt_component_borrow_input_port_by_index( |
1778c2a4 | 208 | (void *) component, index, __func__); |
d94d92ac PP |
209 | } |
210 | ||
1353b066 | 211 | BT_EXPORT |
d24d5663 | 212 | enum bt_self_component_add_port_status bt_self_component_filter_add_input_port( |
d94d92ac PP |
213 | struct bt_self_component_filter *self_comp, |
214 | const char *name, void *user_data, | |
215 | struct bt_self_component_port_input **self_port) | |
216 | { | |
d24d5663 | 217 | enum bt_self_component_add_port_status status; |
d94d92ac PP |
218 | struct bt_port *port = NULL; |
219 | struct bt_component *comp = (void *) self_comp; | |
220 | ||
1778c2a4 PP |
221 | /* |
222 | * bt_component_add_input_port() logs details/errors and checks | |
223 | * preconditions. | |
224 | */ | |
225 | status = bt_component_add_input_port(comp, name, user_data, &port, | |
226 | __func__); | |
d24d5663 | 227 | if (status != BT_FUNC_STATUS_OK) { |
d94d92ac PP |
228 | goto end; |
229 | } | |
230 | ||
231 | if (self_port) { | |
232 | /* Move reference to user */ | |
233 | *self_port = (void *) port; | |
d94d92ac PP |
234 | } |
235 | ||
236 | end: | |
237 | bt_object_put_ref(port); | |
238 | return status; | |
239 | } | |
c5b9b441 | 240 | |
1353b066 | 241 | BT_EXPORT |
c5b9b441 PP |
242 | void bt_component_filter_get_ref( |
243 | const struct bt_component_filter *component_filter) | |
244 | { | |
245 | bt_object_get_ref(component_filter); | |
246 | } | |
247 | ||
1353b066 | 248 | BT_EXPORT |
c5b9b441 PP |
249 | void bt_component_filter_put_ref( |
250 | const struct bt_component_filter *component_filter) | |
251 | { | |
252 | bt_object_put_ref(component_filter); | |
253 | } |