Commit | Line | Data |
---|---|---|
fb2dcc52 | 1 | /* |
f2b0325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
3310b217 | 3 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
fb2dcc52 | 4 | * |
fb2dcc52 JG |
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | * of this software and associated documentation files (the "Software"), to deal | |
7 | * in the Software without restriction, including without limitation the rights | |
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | * copies of the Software, and to permit persons to whom the Software is | |
10 | * furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included in | |
13 | * all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
21 | * SOFTWARE. | |
22 | */ | |
23 | ||
a3aacb6f PP |
24 | #define BT_LOG_TAG "COMP-CLASS" |
25 | #include <babeltrace/lib-logging-internal.h> | |
26 | ||
8c6884d9 PP |
27 | #include <babeltrace/assert-internal.h> |
28 | #include <babeltrace/assert-pre-internal.h> | |
3d9990ac | 29 | #include <babeltrace/compiler-internal.h> |
7b53201c PP |
30 | #include <babeltrace/graph/component-class.h> |
31 | #include <babeltrace/graph/component-class-const.h> | |
32 | #include <babeltrace/graph/component-class-source.h> | |
33 | #include <babeltrace/graph/component-class-source-const.h> | |
34 | #include <babeltrace/graph/component-class-filter.h> | |
35 | #include <babeltrace/graph/component-class-filter-const.h> | |
36 | #include <babeltrace/graph/component-class-sink.h> | |
37 | #include <babeltrace/graph/component-class-sink-const.h> | |
b2e0c907 | 38 | #include <babeltrace/graph/component-class-internal.h> |
c55a9f58 | 39 | #include <babeltrace/types.h> |
fb2dcc52 JG |
40 | #include <glib.h> |
41 | ||
834e9996 | 42 | #define BT_ASSERT_PRE_COMP_CLS_HOT(_cc) \ |
7b53201c | 43 | BT_ASSERT_PRE_HOT(((const struct bt_component_class *) (_cc)), \ |
834e9996 PP |
44 | "Component class", ": %!+C", (_cc)) |
45 | ||
fb2dcc52 | 46 | static |
834e9996 | 47 | void destroy_component_class(struct bt_object *obj) |
fb2dcc52 JG |
48 | { |
49 | struct bt_component_class *class; | |
33b34c43 | 50 | int i; |
fb2dcc52 | 51 | |
8b45963b | 52 | BT_ASSERT(obj); |
b8a06801 | 53 | class = container_of(obj, struct bt_component_class, base); |
33b34c43 | 54 | |
834e9996 | 55 | BT_LIB_LOGD("Destroying component class: %!+C", class); |
a3aacb6f | 56 | |
33b34c43 PP |
57 | /* Call destroy listeners in reverse registration order */ |
58 | for (i = class->destroy_listeners->len - 1; i >= 0; i--) { | |
d3e4dcd8 | 59 | struct bt_component_class_destroy_listener *listener = |
33b34c43 | 60 | &g_array_index(class->destroy_listeners, |
d3e4dcd8 | 61 | struct bt_component_class_destroy_listener, |
33b34c43 PP |
62 | i); |
63 | ||
a3aacb6f PP |
64 | BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p", |
65 | listener->func, listener->data); | |
33b34c43 PP |
66 | listener->func(class, listener->data); |
67 | } | |
68 | ||
fb2dcc52 JG |
69 | if (class->name) { |
70 | g_string_free(class->name, TRUE); | |
834e9996 | 71 | class->name = NULL; |
fb2dcc52 | 72 | } |
834e9996 | 73 | |
7c7c0433 JG |
74 | if (class->description) { |
75 | g_string_free(class->description, TRUE); | |
834e9996 | 76 | class->description = NULL; |
7c7c0433 | 77 | } |
834e9996 | 78 | |
5536d9a6 PP |
79 | if (class->help) { |
80 | g_string_free(class->help, TRUE); | |
834e9996 | 81 | class->help = NULL; |
5536d9a6 | 82 | } |
834e9996 | 83 | |
33b34c43 PP |
84 | if (class->destroy_listeners) { |
85 | g_array_free(class->destroy_listeners, TRUE); | |
834e9996 | 86 | class->destroy_listeners = NULL; |
33b34c43 | 87 | } |
b8a06801 | 88 | |
fb2dcc52 JG |
89 | g_free(class); |
90 | } | |
91 | ||
d3e4dcd8 PP |
92 | static |
93 | int bt_component_class_init(struct bt_component_class *class, | |
94 | enum bt_component_class_type type, const char *name) | |
fb2dcc52 | 95 | { |
d3e4dcd8 PP |
96 | int ret = 0; |
97 | ||
834e9996 | 98 | bt_object_init_shared(&class->base, destroy_component_class); |
d3e4dcd8 PP |
99 | class->type = type; |
100 | class->name = g_string_new(name); | |
101 | if (!class->name) { | |
a3aacb6f | 102 | BT_LOGE_STR("Failed to allocate a GString."); |
d3e4dcd8 PP |
103 | goto error; |
104 | } | |
105 | ||
106 | class->description = g_string_new(NULL); | |
107 | if (!class->description) { | |
a3aacb6f | 108 | BT_LOGE_STR("Failed to allocate a GString."); |
d3e4dcd8 PP |
109 | goto error; |
110 | } | |
111 | ||
5536d9a6 PP |
112 | class->help = g_string_new(NULL); |
113 | if (!class->help) { | |
a3aacb6f | 114 | BT_LOGE_STR("Failed to allocate a GString."); |
5536d9a6 PP |
115 | goto error; |
116 | } | |
117 | ||
d3e4dcd8 PP |
118 | class->destroy_listeners = g_array_new(FALSE, TRUE, |
119 | sizeof(struct bt_component_class_destroy_listener)); | |
120 | if (!class->destroy_listeners) { | |
a3aacb6f | 121 | BT_LOGE_STR("Failed to allocate a GArray."); |
d3e4dcd8 PP |
122 | goto error; |
123 | } | |
124 | ||
125 | goto end; | |
6ba0b073 | 126 | |
d3e4dcd8 | 127 | error: |
8138bfe1 | 128 | BT_OBJECT_PUT_REF_AND_RESET(class); |
d3e4dcd8 PP |
129 | ret = -1; |
130 | ||
131 | end: | |
132 | return ret; | |
133 | } | |
134 | ||
7b53201c | 135 | struct bt_component_class_source *bt_component_class_source_create( |
834e9996 | 136 | const char *name, |
7b53201c | 137 | bt_component_class_source_notification_iterator_next_method method) |
d3e4dcd8 PP |
138 | { |
139 | struct bt_component_class_source *source_class = NULL; | |
140 | int ret; | |
141 | ||
834e9996 PP |
142 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
143 | BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method"); | |
a3aacb6f PP |
144 | BT_LOGD("Creating source component class: " |
145 | "name=\"%s\", notif-iter-next-method-addr=%p", | |
fe7265b5 | 146 | name, method); |
d3e4dcd8 PP |
147 | source_class = g_new0(struct bt_component_class_source, 1); |
148 | if (!source_class) { | |
a3aacb6f | 149 | BT_LOGE_STR("Failed to allocate one source component class."); |
fb2dcc52 JG |
150 | goto end; |
151 | } | |
152 | ||
a3aacb6f | 153 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
154 | ret = bt_component_class_init(&source_class->parent, |
155 | BT_COMPONENT_CLASS_TYPE_SOURCE, name); | |
156 | if (ret) { | |
157 | /* | |
158 | * If bt_component_class_init() fails, the component | |
159 | * class is put, therefore its memory is already | |
160 | * freed. | |
161 | */ | |
162 | source_class = NULL; | |
163 | goto end; | |
164 | } | |
165 | ||
834e9996 PP |
166 | source_class->methods.notif_iter_next = method; |
167 | BT_LIB_LOGD("Created source component class: %!+C", source_class); | |
d3e4dcd8 PP |
168 | |
169 | end: | |
834e9996 | 170 | return (void *) source_class; |
d3e4dcd8 PP |
171 | } |
172 | ||
7b53201c PP |
173 | struct bt_component_class_filter *bt_component_class_filter_create( |
174 | const char *name, | |
175 | bt_component_class_filter_notification_iterator_next_method method) | |
d3e4dcd8 PP |
176 | { |
177 | struct bt_component_class_filter *filter_class = NULL; | |
178 | int ret; | |
179 | ||
834e9996 PP |
180 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
181 | BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method"); | |
a3aacb6f PP |
182 | BT_LOGD("Creating filter component class: " |
183 | "name=\"%s\", notif-iter-next-method-addr=%p", | |
fe7265b5 | 184 | name, method); |
d3e4dcd8 PP |
185 | filter_class = g_new0(struct bt_component_class_filter, 1); |
186 | if (!filter_class) { | |
a3aacb6f | 187 | BT_LOGE_STR("Failed to allocate one filter component class."); |
d3e4dcd8 | 188 | goto end; |
6ba0b073 PP |
189 | } |
190 | ||
a3aacb6f | 191 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
192 | ret = bt_component_class_init(&filter_class->parent, |
193 | BT_COMPONENT_CLASS_TYPE_FILTER, name); | |
194 | if (ret) { | |
195 | /* | |
196 | * If bt_component_class_init() fails, the component | |
197 | * class is put, therefore its memory is already | |
198 | * freed. | |
199 | */ | |
200 | filter_class = NULL; | |
33b34c43 PP |
201 | goto end; |
202 | } | |
d3e4dcd8 | 203 | |
834e9996 PP |
204 | filter_class->methods.notif_iter_next = method; |
205 | BT_LIB_LOGD("Created filter component class: %!+C", filter_class); | |
d3e4dcd8 | 206 | |
fb2dcc52 | 207 | end: |
834e9996 | 208 | return (void *) filter_class; |
d3e4dcd8 PP |
209 | } |
210 | ||
7b53201c PP |
211 | struct bt_component_class_sink *bt_component_class_sink_create( |
212 | const char *name, bt_component_class_sink_consume_method method) | |
d3e4dcd8 PP |
213 | { |
214 | struct bt_component_class_sink *sink_class = NULL; | |
215 | int ret; | |
216 | ||
834e9996 PP |
217 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
218 | BT_ASSERT_PRE_NON_NULL(method, "Consume next method"); | |
a3aacb6f PP |
219 | BT_LOGD("Creating sink component class: " |
220 | "name=\"%s\", consume-method-addr=%p", | |
fe7265b5 | 221 | name, method); |
d3e4dcd8 PP |
222 | sink_class = g_new0(struct bt_component_class_sink, 1); |
223 | if (!sink_class) { | |
a3aacb6f | 224 | BT_LOGE_STR("Failed to allocate one sink component class."); |
d3e4dcd8 PP |
225 | goto end; |
226 | } | |
227 | ||
a3aacb6f | 228 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
229 | ret = bt_component_class_init(&sink_class->parent, |
230 | BT_COMPONENT_CLASS_TYPE_SINK, name); | |
231 | if (ret) { | |
232 | /* | |
233 | * If bt_component_class_init() fails, the component | |
234 | * class is put, therefore its memory is already | |
235 | * freed. | |
236 | */ | |
237 | sink_class = NULL; | |
238 | goto end; | |
239 | } | |
240 | ||
fe7265b5 | 241 | sink_class->methods.consume = method; |
834e9996 | 242 | BT_LIB_LOGD("Created sink component class: %!+C", sink_class); |
d3e4dcd8 PP |
243 | |
244 | end: | |
834e9996 | 245 | return (void *) sink_class; |
d3e4dcd8 PP |
246 | } |
247 | ||
7b53201c PP |
248 | int bt_component_class_source_set_init_method( |
249 | struct bt_component_class_source *comp_cls, | |
250 | bt_component_class_source_init_method method) | |
d3e4dcd8 | 251 | { |
834e9996 PP |
252 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
253 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
254 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
255 | comp_cls->methods.init = method; | |
256 | BT_LIB_LOGV("Set source component class's initialization method: " | |
257 | "%!+C", comp_cls); | |
258 | return 0; | |
d3e4dcd8 PP |
259 | } |
260 | ||
7b53201c PP |
261 | int bt_component_class_filter_set_init_method( |
262 | struct bt_component_class_filter *comp_cls, | |
263 | bt_component_class_filter_init_method method) | |
efa96d5d | 264 | { |
834e9996 PP |
265 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
266 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
267 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
268 | comp_cls->methods.init = method; | |
269 | BT_LIB_LOGV("Set filter component class's initialization method: " | |
270 | "%!+C", comp_cls); | |
271 | return 0; | |
efa96d5d PP |
272 | } |
273 | ||
7b53201c PP |
274 | int bt_component_class_sink_set_init_method( |
275 | struct bt_component_class_sink *comp_cls, | |
276 | bt_component_class_sink_init_method method) | |
2d41b99e | 277 | { |
834e9996 PP |
278 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
279 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
280 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
281 | comp_cls->methods.init = method; | |
282 | BT_LIB_LOGV("Set sink component class's initialization method: " | |
283 | "%!+C", comp_cls); | |
284 | return 0; | |
72b913fb PP |
285 | } |
286 | ||
7b53201c PP |
287 | int bt_component_class_source_set_finalize_method( |
288 | struct bt_component_class_source *comp_cls, | |
289 | bt_component_class_source_finalize_method method) | |
0d8b4d8e | 290 | { |
834e9996 PP |
291 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
292 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
293 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
294 | comp_cls->methods.finalize = method; | |
295 | BT_LIB_LOGV("Set source component class's finalization method: " | |
296 | "%!+C", comp_cls); | |
297 | return 0; | |
0d8b4d8e PP |
298 | } |
299 | ||
7b53201c PP |
300 | int bt_component_class_filter_set_finalize_method( |
301 | struct bt_component_class_filter *comp_cls, | |
302 | bt_component_class_filter_finalize_method method) | |
72b913fb | 303 | { |
834e9996 PP |
304 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
305 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
306 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
307 | comp_cls->methods.finalize = method; | |
308 | BT_LIB_LOGV("Set filter component class's finalization method: " | |
309 | "%!+C", comp_cls); | |
310 | return 0; | |
2d41b99e JG |
311 | } |
312 | ||
7b53201c PP |
313 | int bt_component_class_sink_set_finalize_method( |
314 | struct bt_component_class_sink *comp_cls, | |
315 | bt_component_class_sink_finalize_method method) | |
d3e4dcd8 | 316 | { |
834e9996 PP |
317 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
318 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
319 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
320 | comp_cls->methods.finalize = method; | |
321 | BT_LIB_LOGV("Set sink component class's finalization method: " | |
322 | "%!+C", comp_cls); | |
323 | return 0; | |
d3e4dcd8 PP |
324 | } |
325 | ||
7b53201c PP |
326 | int bt_component_class_source_set_query_method( |
327 | struct bt_component_class_source *comp_cls, | |
328 | bt_component_class_source_query_method method) | |
d3eb6e8f | 329 | { |
834e9996 PP |
330 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
331 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
332 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
333 | comp_cls->methods.query = method; | |
334 | BT_LIB_LOGV("Set source component class's query method: " | |
335 | "%!+C", comp_cls); | |
336 | return 0; | |
d3eb6e8f PP |
337 | } |
338 | ||
7b53201c PP |
339 | int bt_component_class_filter_set_query_method( |
340 | struct bt_component_class_filter *comp_cls, | |
341 | bt_component_class_filter_query_method method) | |
d3eb6e8f | 342 | { |
834e9996 PP |
343 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
344 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
345 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
346 | comp_cls->methods.query = method; | |
347 | BT_LIB_LOGV("Set filter component class's query method: " | |
348 | "%!+C", comp_cls); | |
349 | return 0; | |
350 | } | |
a3aacb6f | 351 | |
7b53201c PP |
352 | int bt_component_class_sink_set_query_method( |
353 | struct bt_component_class_sink *comp_cls, | |
354 | bt_component_class_sink_query_method method) | |
834e9996 | 355 | { |
834e9996 PP |
356 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
357 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
358 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
359 | comp_cls->methods.query = method; | |
360 | BT_LIB_LOGV("Set sink component class's query method: " | |
361 | "%!+C", comp_cls); | |
362 | return 0; | |
363 | } | |
d3eb6e8f | 364 | |
7b53201c PP |
365 | int bt_component_class_filter_set_accept_input_port_connection_method( |
366 | struct bt_component_class_filter *comp_cls, | |
367 | bt_component_class_filter_accept_input_port_connection_method method) | |
834e9996 | 368 | { |
834e9996 PP |
369 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
370 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
371 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
372 | comp_cls->methods.accept_input_port_connection = method; | |
373 | BT_LIB_LOGV("Set filter component class's \"accept input port connection\" method" | |
374 | ": %!+C", comp_cls); | |
375 | return 0; | |
376 | } | |
d3eb6e8f | 377 | |
7b53201c PP |
378 | int bt_component_class_sink_set_accept_input_port_connection_method( |
379 | struct bt_component_class_sink *comp_cls, | |
380 | bt_component_class_sink_accept_input_port_connection_method method) | |
834e9996 | 381 | { |
834e9996 PP |
382 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
383 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
384 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
385 | comp_cls->methods.accept_input_port_connection = method; | |
386 | BT_LIB_LOGV("Set sink component class's \"accept input port connection\" method" | |
387 | ": %!+C", comp_cls); | |
388 | return 0; | |
d3eb6e8f PP |
389 | } |
390 | ||
7b53201c PP |
391 | int bt_component_class_source_set_accept_output_port_connection_method( |
392 | struct bt_component_class_source *comp_cls, | |
393 | bt_component_class_source_accept_output_port_connection_method method) | |
d3eb6e8f | 394 | { |
834e9996 PP |
395 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
396 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
397 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
398 | comp_cls->methods.accept_output_port_connection = method; | |
399 | BT_LIB_LOGV("Set source component class's \"accept output port connection\" method" | |
400 | ": %!+C", comp_cls); | |
401 | return 0; | |
402 | } | |
d3eb6e8f | 403 | |
7b53201c PP |
404 | int bt_component_class_filter_set_accept_output_port_connection_method( |
405 | struct bt_component_class_filter *comp_cls, | |
406 | bt_component_class_filter_accept_output_port_connection_method method) | |
834e9996 | 407 | { |
834e9996 PP |
408 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
409 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
410 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
411 | comp_cls->methods.accept_output_port_connection = method; | |
412 | BT_LIB_LOGV("Set filter component class's \"accept output port connection\" method" | |
413 | ": %!+C", comp_cls); | |
414 | return 0; | |
415 | } | |
a3aacb6f | 416 | |
7b53201c PP |
417 | int bt_component_class_filter_set_input_port_connected_method( |
418 | struct bt_component_class_filter *comp_cls, | |
419 | bt_component_class_filter_input_port_connected_method method) | |
834e9996 | 420 | { |
834e9996 PP |
421 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
422 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
423 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
424 | comp_cls->methods.input_port_connected = method; | |
425 | BT_LIB_LOGV("Set filter component class's \"input port connected\" method" | |
426 | ": %!+C", comp_cls); | |
427 | return 0; | |
428 | } | |
a3aacb6f | 429 | |
7b53201c PP |
430 | int bt_component_class_sink_set_input_port_connected_method( |
431 | struct bt_component_class_sink *comp_cls, | |
432 | bt_component_class_sink_input_port_connected_method method) | |
834e9996 | 433 | { |
834e9996 PP |
434 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
435 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
436 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
437 | comp_cls->methods.input_port_connected = method; | |
438 | BT_LIB_LOGV("Set sink component class's \"input port connected\" method" | |
439 | ": %!+C", comp_cls); | |
440 | return 0; | |
441 | } | |
a3aacb6f | 442 | |
7b53201c PP |
443 | int bt_component_class_source_set_output_port_connected_method( |
444 | struct bt_component_class_source *comp_cls, | |
445 | bt_component_class_source_output_port_connected_method method) | |
834e9996 | 446 | { |
834e9996 PP |
447 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
448 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
449 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
450 | comp_cls->methods.output_port_connected = method; | |
451 | BT_LIB_LOGV("Set source component class's \"output port connected\" method" | |
452 | ": %!+C", comp_cls); | |
453 | return 0; | |
454 | } | |
d3eb6e8f | 455 | |
7b53201c PP |
456 | int bt_component_class_filter_set_output_port_connected_method( |
457 | struct bt_component_class_filter *comp_cls, | |
458 | bt_component_class_filter_output_port_connected_method method) | |
834e9996 | 459 | { |
834e9996 PP |
460 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
461 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
462 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
463 | comp_cls->methods.output_port_connected = method; | |
464 | BT_LIB_LOGV("Set filter component class's \"output port connected\" method" | |
465 | ": %!+C", comp_cls); | |
466 | return 0; | |
467 | } | |
d3eb6e8f | 468 | |
7b53201c PP |
469 | int bt_component_class_filter_set_input_port_disconnected_method( |
470 | struct bt_component_class_filter *comp_cls, | |
471 | bt_component_class_filter_input_port_disconnected_method method) | |
834e9996 | 472 | { |
834e9996 PP |
473 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
474 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
475 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
476 | comp_cls->methods.input_port_disconnected = method; | |
477 | BT_LIB_LOGV("Set filter component class's \"input port disconnected\" method" | |
478 | ": %!+C", comp_cls); | |
479 | return 0; | |
d3eb6e8f PP |
480 | } |
481 | ||
7b53201c PP |
482 | int bt_component_class_sink_set_input_port_disconnected_method( |
483 | struct bt_component_class_sink *comp_cls, | |
484 | bt_component_class_sink_input_port_disconnected_method method) | |
d3eb6e8f | 485 | { |
834e9996 PP |
486 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
487 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
488 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
489 | comp_cls->methods.input_port_disconnected = method; | |
490 | BT_LIB_LOGV("Set sink component class's \"input port disconnected\" method" | |
491 | ": %!+C", comp_cls); | |
492 | return 0; | |
493 | } | |
d3eb6e8f | 494 | |
7b53201c PP |
495 | int bt_component_class_source_set_output_port_disconnected_method( |
496 | struct bt_component_class_source *comp_cls, | |
497 | bt_component_class_source_output_port_disconnected_method method) | |
834e9996 | 498 | { |
834e9996 PP |
499 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
500 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
501 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
502 | comp_cls->methods.output_port_disconnected = method; | |
503 | BT_LIB_LOGV("Set source component class's \"output port disconnected\" method" | |
504 | ": %!+C", comp_cls); | |
505 | return 0; | |
506 | } | |
a3aacb6f | 507 | |
7b53201c PP |
508 | int bt_component_class_filter_set_output_port_disconnected_method( |
509 | struct bt_component_class_filter *comp_cls, | |
510 | bt_component_class_filter_output_port_disconnected_method method) | |
834e9996 | 511 | { |
834e9996 PP |
512 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
513 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
514 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
515 | comp_cls->methods.output_port_disconnected = method; | |
516 | BT_LIB_LOGV("Set filter component class's \"output port disconnected\" method" | |
517 | ": %!+C", comp_cls); | |
518 | return 0; | |
519 | } | |
a3aacb6f | 520 | |
7b53201c PP |
521 | int bt_component_class_source_set_notification_iterator_init_method( |
522 | struct bt_component_class_source *comp_cls, | |
523 | bt_component_class_source_notification_iterator_init_method method) | |
834e9996 | 524 | { |
834e9996 PP |
525 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
526 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
527 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
528 | comp_cls->methods.notif_iter_init = method; | |
529 | BT_LIB_LOGV("Set source component class's notification iterator initialization method" | |
530 | ": %!+C", comp_cls); | |
531 | return 0; | |
532 | } | |
a3aacb6f | 533 | |
7b53201c PP |
534 | int bt_component_class_filter_set_notification_iterator_init_method( |
535 | struct bt_component_class_filter *comp_cls, | |
536 | bt_component_class_filter_notification_iterator_init_method method) | |
834e9996 | 537 | { |
834e9996 PP |
538 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
539 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
540 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
541 | comp_cls->methods.notif_iter_init = method; | |
542 | BT_LIB_LOGV("Set filter component class's notification iterator initialization method" | |
543 | ": %!+C", comp_cls); | |
544 | return 0; | |
545 | } | |
d3eb6e8f | 546 | |
7b53201c PP |
547 | int bt_component_class_source_set_notification_iterator_finalize_method( |
548 | struct bt_component_class_source *comp_cls, | |
549 | bt_component_class_source_notification_iterator_finalize_method method) | |
834e9996 | 550 | { |
834e9996 PP |
551 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
552 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
553 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
554 | comp_cls->methods.notif_iter_finalize = method; | |
555 | BT_LIB_LOGV("Set source component class's notification iterator finalization method" | |
556 | ": %!+C", comp_cls); | |
557 | return 0; | |
558 | } | |
d3eb6e8f | 559 | |
7b53201c PP |
560 | int bt_component_class_filter_set_notification_iterator_finalize_method( |
561 | struct bt_component_class_filter *comp_cls, | |
562 | bt_component_class_filter_notification_iterator_finalize_method method) | |
834e9996 | 563 | { |
834e9996 PP |
564 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
565 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
566 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
567 | comp_cls->methods.notif_iter_finalize = method; | |
568 | BT_LIB_LOGV("Set filter component class's notification iterator finalization method" | |
569 | ": %!+C", comp_cls); | |
570 | return 0; | |
d3eb6e8f PP |
571 | } |
572 | ||
7b53201c PP |
573 | int bt_component_class_set_description( |
574 | struct bt_component_class *comp_cls, | |
d3e4dcd8 PP |
575 | const char *description) |
576 | { | |
834e9996 PP |
577 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
578 | BT_ASSERT_PRE_NON_NULL(description, "Description"); | |
579 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
580 | g_string_assign(comp_cls->description, description); | |
581 | BT_LIB_LOGV("Set component class's description: " | |
a3aacb6f | 582 | "addr=%p, name=\"%s\", type=%s", |
834e9996 PP |
583 | comp_cls, |
584 | bt_component_class_get_name(comp_cls), | |
585 | bt_component_class_type_string(comp_cls->type)); | |
586 | return 0; | |
fb2dcc52 | 587 | } |
38b48196 | 588 | |
7b53201c PP |
589 | int bt_component_class_set_help( |
590 | struct bt_component_class *comp_cls, | |
5536d9a6 PP |
591 | const char *help) |
592 | { | |
834e9996 PP |
593 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
594 | BT_ASSERT_PRE_NON_NULL(help, "Help"); | |
595 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
596 | g_string_assign(comp_cls->help, help); | |
597 | BT_LIB_LOGV("Set component class's help text: %!+C", comp_cls); | |
598 | return 0; | |
5536d9a6 PP |
599 | } |
600 | ||
7b53201c | 601 | const char *bt_component_class_get_name(const struct bt_component_class *comp_cls) |
38b48196 | 602 | { |
834e9996 PP |
603 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
604 | return comp_cls->name->str; | |
38b48196 JG |
605 | } |
606 | ||
d3e4dcd8 | 607 | enum bt_component_class_type bt_component_class_get_type( |
7b53201c | 608 | const struct bt_component_class *comp_cls) |
38b48196 | 609 | { |
834e9996 PP |
610 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
611 | return comp_cls->type; | |
38b48196 JG |
612 | } |
613 | ||
33b34c43 | 614 | const char *bt_component_class_get_description( |
7b53201c | 615 | const struct bt_component_class *comp_cls) |
38b48196 | 616 | { |
834e9996 PP |
617 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
618 | return comp_cls->description && | |
619 | comp_cls->description->str[0] != '\0' ? | |
620 | comp_cls->description->str : NULL; | |
38b48196 | 621 | } |
7c7c0433 | 622 | |
5536d9a6 | 623 | const char *bt_component_class_get_help( |
7b53201c | 624 | const struct bt_component_class *comp_cls) |
5536d9a6 | 625 | { |
834e9996 PP |
626 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
627 | return comp_cls->help && | |
628 | comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL; | |
5536d9a6 PP |
629 | } |
630 | ||
33b34c43 | 631 | BT_HIDDEN |
834e9996 PP |
632 | void bt_component_class_add_destroy_listener( |
633 | struct bt_component_class *comp_cls, | |
33b34c43 | 634 | bt_component_class_destroy_listener_func func, void *data) |
7c7c0433 | 635 | { |
d3e4dcd8 | 636 | struct bt_component_class_destroy_listener listener; |
33b34c43 | 637 | |
834e9996 | 638 | BT_ASSERT(comp_cls); |
8b45963b | 639 | BT_ASSERT(func); |
33b34c43 PP |
640 | listener.func = func; |
641 | listener.data = data; | |
834e9996 PP |
642 | g_array_append_val(comp_cls->destroy_listeners, listener); |
643 | BT_LIB_LOGV("Added destroy listener to component class: " | |
644 | "%![cc-]+C, listener-func-addr=%p", comp_cls, func); | |
7c7c0433 | 645 | } |
d3e4dcd8 | 646 | |
834e9996 | 647 | BT_HIDDEN |
7b53201c | 648 | void _bt_component_class_freeze(const struct bt_component_class *comp_cls) |
1e4d8103 | 649 | { |
834e9996 PP |
650 | BT_ASSERT(comp_cls); |
651 | BT_LIB_LOGD("Freezing component class: %!+C", comp_cls); | |
7b53201c | 652 | ((struct bt_component_class *) comp_cls)->frozen = true; |
1e4d8103 | 653 | } |
8c6884d9 PP |
654 | |
655 | void bt_component_class_get_ref( | |
656 | const struct bt_component_class *component_class) | |
657 | { | |
658 | bt_object_get_ref(component_class); | |
659 | } | |
660 | ||
661 | void bt_component_class_put_ref( | |
662 | const struct bt_component_class *component_class) | |
663 | { | |
664 | bt_object_put_ref(component_class); | |
665 | } | |
666 | ||
667 | void bt_component_class_source_get_ref( | |
668 | const struct bt_component_class_source *component_class_source) | |
669 | { | |
670 | bt_object_get_ref(component_class_source); | |
671 | } | |
672 | ||
673 | void bt_component_class_source_put_ref( | |
674 | const struct bt_component_class_source *component_class_source) | |
675 | { | |
676 | bt_object_put_ref(component_class_source); | |
677 | } | |
678 | ||
679 | void bt_component_class_filter_get_ref( | |
680 | const struct bt_component_class_filter *component_class_filter) | |
681 | { | |
682 | bt_object_get_ref(component_class_filter); | |
683 | } | |
684 | ||
685 | void bt_component_class_filter_put_ref( | |
686 | const struct bt_component_class_filter *component_class_filter) | |
687 | { | |
688 | bt_object_put_ref(component_class_filter); | |
689 | } | |
690 | ||
691 | void bt_component_class_sink_get_ref( | |
692 | const struct bt_component_class_sink *component_class_sink) | |
693 | { | |
694 | bt_object_get_ref(component_class_sink); | |
695 | } | |
696 | ||
697 | void bt_component_class_sink_put_ref( | |
698 | const struct bt_component_class_sink *component_class_sink) | |
699 | { | |
700 | bt_object_put_ref(component_class_sink); | |
701 | } |