Commit | Line | Data |
---|---|---|
fb2dcc52 | 1 | /* |
e2f7325d | 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 | ||
3d9990ac | 27 | #include <babeltrace/compiler-internal.h> |
0d72b8c3 PP |
28 | #include <babeltrace/graph/component-class.h> |
29 | #include <babeltrace/graph/component-class-const.h> | |
30 | #include <babeltrace/graph/component-class-source.h> | |
31 | #include <babeltrace/graph/component-class-source-const.h> | |
32 | #include <babeltrace/graph/component-class-filter.h> | |
33 | #include <babeltrace/graph/component-class-filter-const.h> | |
34 | #include <babeltrace/graph/component-class-sink.h> | |
35 | #include <babeltrace/graph/component-class-sink-const.h> | |
b2e0c907 | 36 | #include <babeltrace/graph/component-class-internal.h> |
65300d60 | 37 | #include <babeltrace/object.h> |
c55a9f58 | 38 | #include <babeltrace/types.h> |
f6ccaed9 | 39 | #include <babeltrace/assert-internal.h> |
d94d92ac | 40 | #include <babeltrace/assert-pre-internal.h> |
fb2dcc52 JG |
41 | #include <glib.h> |
42 | ||
d94d92ac | 43 | #define BT_ASSERT_PRE_COMP_CLS_HOT(_cc) \ |
0d72b8c3 | 44 | BT_ASSERT_PRE_HOT(((const struct bt_component_class *) (_cc)), \ |
d94d92ac PP |
45 | "Component class", ": %!+C", (_cc)) |
46 | ||
fb2dcc52 | 47 | static |
d94d92ac | 48 | void destroy_component_class(struct bt_object *obj) |
fb2dcc52 JG |
49 | { |
50 | struct bt_component_class *class; | |
33b34c43 | 51 | int i; |
fb2dcc52 | 52 | |
f6ccaed9 | 53 | BT_ASSERT(obj); |
b8a06801 | 54 | class = container_of(obj, struct bt_component_class, base); |
33b34c43 | 55 | |
d94d92ac | 56 | BT_LIB_LOGD("Destroying component class: %!+C", class); |
a3aacb6f | 57 | |
33b34c43 PP |
58 | /* Call destroy listeners in reverse registration order */ |
59 | for (i = class->destroy_listeners->len - 1; i >= 0; i--) { | |
d3e4dcd8 | 60 | struct bt_component_class_destroy_listener *listener = |
33b34c43 | 61 | &g_array_index(class->destroy_listeners, |
d3e4dcd8 | 62 | struct bt_component_class_destroy_listener, |
33b34c43 PP |
63 | i); |
64 | ||
a3aacb6f PP |
65 | BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p", |
66 | listener->func, listener->data); | |
33b34c43 PP |
67 | listener->func(class, listener->data); |
68 | } | |
69 | ||
fb2dcc52 JG |
70 | if (class->name) { |
71 | g_string_free(class->name, TRUE); | |
d94d92ac | 72 | class->name = NULL; |
fb2dcc52 | 73 | } |
d94d92ac | 74 | |
7c7c0433 JG |
75 | if (class->description) { |
76 | g_string_free(class->description, TRUE); | |
d94d92ac | 77 | class->description = NULL; |
7c7c0433 | 78 | } |
d94d92ac | 79 | |
5536d9a6 PP |
80 | if (class->help) { |
81 | g_string_free(class->help, TRUE); | |
d94d92ac | 82 | class->help = NULL; |
5536d9a6 | 83 | } |
d94d92ac | 84 | |
33b34c43 PP |
85 | if (class->destroy_listeners) { |
86 | g_array_free(class->destroy_listeners, TRUE); | |
d94d92ac | 87 | class->destroy_listeners = NULL; |
33b34c43 | 88 | } |
b8a06801 | 89 | |
fb2dcc52 JG |
90 | g_free(class); |
91 | } | |
92 | ||
d3e4dcd8 PP |
93 | static |
94 | int bt_component_class_init(struct bt_component_class *class, | |
95 | enum bt_component_class_type type, const char *name) | |
fb2dcc52 | 96 | { |
d3e4dcd8 PP |
97 | int ret = 0; |
98 | ||
d94d92ac | 99 | bt_object_init_shared(&class->base, destroy_component_class); |
d3e4dcd8 PP |
100 | class->type = type; |
101 | class->name = g_string_new(name); | |
102 | if (!class->name) { | |
a3aacb6f | 103 | BT_LOGE_STR("Failed to allocate a GString."); |
d3e4dcd8 PP |
104 | goto error; |
105 | } | |
106 | ||
107 | class->description = g_string_new(NULL); | |
108 | if (!class->description) { | |
a3aacb6f | 109 | BT_LOGE_STR("Failed to allocate a GString."); |
d3e4dcd8 PP |
110 | goto error; |
111 | } | |
112 | ||
5536d9a6 PP |
113 | class->help = g_string_new(NULL); |
114 | if (!class->help) { | |
a3aacb6f | 115 | BT_LOGE_STR("Failed to allocate a GString."); |
5536d9a6 PP |
116 | goto error; |
117 | } | |
118 | ||
d3e4dcd8 PP |
119 | class->destroy_listeners = g_array_new(FALSE, TRUE, |
120 | sizeof(struct bt_component_class_destroy_listener)); | |
121 | if (!class->destroy_listeners) { | |
a3aacb6f | 122 | BT_LOGE_STR("Failed to allocate a GArray."); |
d3e4dcd8 PP |
123 | goto error; |
124 | } | |
125 | ||
126 | goto end; | |
6ba0b073 | 127 | |
d3e4dcd8 | 128 | error: |
65300d60 | 129 | BT_OBJECT_PUT_REF_AND_RESET(class); |
d3e4dcd8 PP |
130 | ret = -1; |
131 | ||
132 | end: | |
133 | return ret; | |
134 | } | |
135 | ||
0d72b8c3 | 136 | struct bt_component_class_source *bt_component_class_source_create( |
d94d92ac | 137 | const char *name, |
0d72b8c3 | 138 | bt_component_class_source_notification_iterator_next_method method) |
d3e4dcd8 PP |
139 | { |
140 | struct bt_component_class_source *source_class = NULL; | |
141 | int ret; | |
142 | ||
d94d92ac PP |
143 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
144 | BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method"); | |
a3aacb6f PP |
145 | BT_LOGD("Creating source component class: " |
146 | "name=\"%s\", notif-iter-next-method-addr=%p", | |
90157d89 | 147 | name, method); |
d3e4dcd8 PP |
148 | source_class = g_new0(struct bt_component_class_source, 1); |
149 | if (!source_class) { | |
a3aacb6f | 150 | BT_LOGE_STR("Failed to allocate one source component class."); |
fb2dcc52 JG |
151 | goto end; |
152 | } | |
153 | ||
a3aacb6f | 154 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
155 | ret = bt_component_class_init(&source_class->parent, |
156 | BT_COMPONENT_CLASS_TYPE_SOURCE, name); | |
157 | if (ret) { | |
158 | /* | |
159 | * If bt_component_class_init() fails, the component | |
160 | * class is put, therefore its memory is already | |
161 | * freed. | |
162 | */ | |
163 | source_class = NULL; | |
164 | goto end; | |
165 | } | |
166 | ||
d94d92ac PP |
167 | source_class->methods.notif_iter_next = method; |
168 | BT_LIB_LOGD("Created source component class: %!+C", source_class); | |
d3e4dcd8 PP |
169 | |
170 | end: | |
d94d92ac | 171 | return (void *) source_class; |
d3e4dcd8 PP |
172 | } |
173 | ||
0d72b8c3 PP |
174 | struct bt_component_class_filter *bt_component_class_filter_create( |
175 | const char *name, | |
176 | bt_component_class_filter_notification_iterator_next_method method) | |
d3e4dcd8 PP |
177 | { |
178 | struct bt_component_class_filter *filter_class = NULL; | |
179 | int ret; | |
180 | ||
d94d92ac PP |
181 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
182 | BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method"); | |
a3aacb6f PP |
183 | BT_LOGD("Creating filter component class: " |
184 | "name=\"%s\", notif-iter-next-method-addr=%p", | |
90157d89 | 185 | name, method); |
d3e4dcd8 PP |
186 | filter_class = g_new0(struct bt_component_class_filter, 1); |
187 | if (!filter_class) { | |
a3aacb6f | 188 | BT_LOGE_STR("Failed to allocate one filter component class."); |
d3e4dcd8 | 189 | goto end; |
6ba0b073 PP |
190 | } |
191 | ||
a3aacb6f | 192 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
193 | ret = bt_component_class_init(&filter_class->parent, |
194 | BT_COMPONENT_CLASS_TYPE_FILTER, name); | |
195 | if (ret) { | |
196 | /* | |
197 | * If bt_component_class_init() fails, the component | |
198 | * class is put, therefore its memory is already | |
199 | * freed. | |
200 | */ | |
201 | filter_class = NULL; | |
33b34c43 PP |
202 | goto end; |
203 | } | |
d3e4dcd8 | 204 | |
d94d92ac PP |
205 | filter_class->methods.notif_iter_next = method; |
206 | BT_LIB_LOGD("Created filter component class: %!+C", filter_class); | |
d3e4dcd8 | 207 | |
fb2dcc52 | 208 | end: |
d94d92ac | 209 | return (void *) filter_class; |
d3e4dcd8 PP |
210 | } |
211 | ||
0d72b8c3 PP |
212 | struct bt_component_class_sink *bt_component_class_sink_create( |
213 | const char *name, bt_component_class_sink_consume_method method) | |
d3e4dcd8 PP |
214 | { |
215 | struct bt_component_class_sink *sink_class = NULL; | |
216 | int ret; | |
217 | ||
d94d92ac PP |
218 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
219 | BT_ASSERT_PRE_NON_NULL(method, "Consume next method"); | |
a3aacb6f PP |
220 | BT_LOGD("Creating sink component class: " |
221 | "name=\"%s\", consume-method-addr=%p", | |
90157d89 | 222 | name, method); |
d3e4dcd8 PP |
223 | sink_class = g_new0(struct bt_component_class_sink, 1); |
224 | if (!sink_class) { | |
a3aacb6f | 225 | BT_LOGE_STR("Failed to allocate one sink component class."); |
d3e4dcd8 PP |
226 | goto end; |
227 | } | |
228 | ||
a3aacb6f | 229 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
230 | ret = bt_component_class_init(&sink_class->parent, |
231 | BT_COMPONENT_CLASS_TYPE_SINK, name); | |
232 | if (ret) { | |
233 | /* | |
234 | * If bt_component_class_init() fails, the component | |
235 | * class is put, therefore its memory is already | |
236 | * freed. | |
237 | */ | |
238 | sink_class = NULL; | |
239 | goto end; | |
240 | } | |
241 | ||
90157d89 | 242 | sink_class->methods.consume = method; |
d94d92ac | 243 | BT_LIB_LOGD("Created sink component class: %!+C", sink_class); |
d3e4dcd8 PP |
244 | |
245 | end: | |
d94d92ac | 246 | return (void *) sink_class; |
d3e4dcd8 PP |
247 | } |
248 | ||
0d72b8c3 PP |
249 | int bt_component_class_source_set_init_method( |
250 | struct bt_component_class_source *comp_cls, | |
251 | bt_component_class_source_init_method method) | |
d3e4dcd8 | 252 | { |
d94d92ac PP |
253 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
254 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
255 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
256 | comp_cls->methods.init = method; | |
257 | BT_LIB_LOGV("Set source component class's initialization method: " | |
258 | "%!+C", comp_cls); | |
259 | return 0; | |
d3e4dcd8 PP |
260 | } |
261 | ||
0d72b8c3 PP |
262 | int bt_component_class_filter_set_init_method( |
263 | struct bt_component_class_filter *comp_cls, | |
264 | bt_component_class_filter_init_method method) | |
efa96d5d | 265 | { |
d94d92ac PP |
266 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
267 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
268 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
269 | comp_cls->methods.init = method; | |
270 | BT_LIB_LOGV("Set filter component class's initialization method: " | |
271 | "%!+C", comp_cls); | |
272 | return 0; | |
efa96d5d PP |
273 | } |
274 | ||
0d72b8c3 PP |
275 | int bt_component_class_sink_set_init_method( |
276 | struct bt_component_class_sink *comp_cls, | |
277 | bt_component_class_sink_init_method method) | |
2d41b99e | 278 | { |
d94d92ac PP |
279 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
280 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
281 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
282 | comp_cls->methods.init = method; | |
283 | BT_LIB_LOGV("Set sink component class's initialization method: " | |
284 | "%!+C", comp_cls); | |
285 | return 0; | |
72b913fb PP |
286 | } |
287 | ||
0d72b8c3 PP |
288 | int bt_component_class_source_set_finalize_method( |
289 | struct bt_component_class_source *comp_cls, | |
290 | bt_component_class_source_finalize_method method) | |
0d8b4d8e | 291 | { |
d94d92ac PP |
292 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
293 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
294 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
295 | comp_cls->methods.finalize = method; | |
296 | BT_LIB_LOGV("Set source component class's finalization method: " | |
297 | "%!+C", comp_cls); | |
298 | return 0; | |
0d8b4d8e PP |
299 | } |
300 | ||
0d72b8c3 PP |
301 | int bt_component_class_filter_set_finalize_method( |
302 | struct bt_component_class_filter *comp_cls, | |
303 | bt_component_class_filter_finalize_method method) | |
72b913fb | 304 | { |
d94d92ac PP |
305 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
306 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
307 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
308 | comp_cls->methods.finalize = method; | |
309 | BT_LIB_LOGV("Set filter component class's finalization method: " | |
310 | "%!+C", comp_cls); | |
311 | return 0; | |
2d41b99e JG |
312 | } |
313 | ||
0d72b8c3 PP |
314 | int bt_component_class_sink_set_finalize_method( |
315 | struct bt_component_class_sink *comp_cls, | |
316 | bt_component_class_sink_finalize_method method) | |
d3e4dcd8 | 317 | { |
d94d92ac PP |
318 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
319 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
320 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
321 | comp_cls->methods.finalize = method; | |
322 | BT_LIB_LOGV("Set sink component class's finalization method: " | |
323 | "%!+C", comp_cls); | |
324 | return 0; | |
d3e4dcd8 PP |
325 | } |
326 | ||
0d72b8c3 PP |
327 | int bt_component_class_source_set_query_method( |
328 | struct bt_component_class_source *comp_cls, | |
329 | bt_component_class_source_query_method method) | |
d3eb6e8f | 330 | { |
d94d92ac PP |
331 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
332 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
333 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
334 | comp_cls->methods.query = method; | |
335 | BT_LIB_LOGV("Set source component class's query method: " | |
336 | "%!+C", comp_cls); | |
337 | return 0; | |
d3eb6e8f PP |
338 | } |
339 | ||
0d72b8c3 PP |
340 | int bt_component_class_filter_set_query_method( |
341 | struct bt_component_class_filter *comp_cls, | |
342 | bt_component_class_filter_query_method method) | |
d3eb6e8f | 343 | { |
d94d92ac PP |
344 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
345 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
346 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
347 | comp_cls->methods.query = method; | |
348 | BT_LIB_LOGV("Set filter component class's query method: " | |
349 | "%!+C", comp_cls); | |
350 | return 0; | |
351 | } | |
a3aacb6f | 352 | |
0d72b8c3 PP |
353 | int bt_component_class_sink_set_query_method( |
354 | struct bt_component_class_sink *comp_cls, | |
355 | bt_component_class_sink_query_method method) | |
d94d92ac | 356 | { |
d94d92ac PP |
357 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
358 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
359 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
360 | comp_cls->methods.query = method; | |
361 | BT_LIB_LOGV("Set sink component class's query method: " | |
362 | "%!+C", comp_cls); | |
363 | return 0; | |
364 | } | |
d3eb6e8f | 365 | |
0d72b8c3 PP |
366 | int bt_component_class_filter_set_accept_input_port_connection_method( |
367 | struct bt_component_class_filter *comp_cls, | |
368 | bt_component_class_filter_accept_input_port_connection_method method) | |
d94d92ac | 369 | { |
d94d92ac PP |
370 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
371 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
372 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
373 | comp_cls->methods.accept_input_port_connection = method; | |
374 | BT_LIB_LOGV("Set filter component class's \"accept input port connection\" method" | |
375 | ": %!+C", comp_cls); | |
376 | return 0; | |
377 | } | |
d3eb6e8f | 378 | |
0d72b8c3 PP |
379 | int bt_component_class_sink_set_accept_input_port_connection_method( |
380 | struct bt_component_class_sink *comp_cls, | |
381 | bt_component_class_sink_accept_input_port_connection_method method) | |
d94d92ac | 382 | { |
d94d92ac PP |
383 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
384 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
385 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
386 | comp_cls->methods.accept_input_port_connection = method; | |
387 | BT_LIB_LOGV("Set sink component class's \"accept input port connection\" method" | |
388 | ": %!+C", comp_cls); | |
389 | return 0; | |
d3eb6e8f PP |
390 | } |
391 | ||
0d72b8c3 PP |
392 | int bt_component_class_source_set_accept_output_port_connection_method( |
393 | struct bt_component_class_source *comp_cls, | |
394 | bt_component_class_source_accept_output_port_connection_method method) | |
d3eb6e8f | 395 | { |
d94d92ac PP |
396 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
397 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
398 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
399 | comp_cls->methods.accept_output_port_connection = method; | |
400 | BT_LIB_LOGV("Set source component class's \"accept output port connection\" method" | |
401 | ": %!+C", comp_cls); | |
402 | return 0; | |
403 | } | |
d3eb6e8f | 404 | |
0d72b8c3 PP |
405 | int bt_component_class_filter_set_accept_output_port_connection_method( |
406 | struct bt_component_class_filter *comp_cls, | |
407 | bt_component_class_filter_accept_output_port_connection_method method) | |
d94d92ac | 408 | { |
d94d92ac PP |
409 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
410 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
411 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
412 | comp_cls->methods.accept_output_port_connection = method; | |
413 | BT_LIB_LOGV("Set filter component class's \"accept output port connection\" method" | |
414 | ": %!+C", comp_cls); | |
415 | return 0; | |
416 | } | |
a3aacb6f | 417 | |
0d72b8c3 PP |
418 | int bt_component_class_filter_set_input_port_connected_method( |
419 | struct bt_component_class_filter *comp_cls, | |
420 | bt_component_class_filter_input_port_connected_method method) | |
d94d92ac | 421 | { |
d94d92ac PP |
422 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
423 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
424 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
425 | comp_cls->methods.input_port_connected = method; | |
426 | BT_LIB_LOGV("Set filter component class's \"input port connected\" method" | |
427 | ": %!+C", comp_cls); | |
428 | return 0; | |
429 | } | |
a3aacb6f | 430 | |
0d72b8c3 PP |
431 | int bt_component_class_sink_set_input_port_connected_method( |
432 | struct bt_component_class_sink *comp_cls, | |
433 | bt_component_class_sink_input_port_connected_method method) | |
d94d92ac | 434 | { |
d94d92ac PP |
435 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
436 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
437 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
438 | comp_cls->methods.input_port_connected = method; | |
439 | BT_LIB_LOGV("Set sink component class's \"input port connected\" method" | |
440 | ": %!+C", comp_cls); | |
441 | return 0; | |
442 | } | |
a3aacb6f | 443 | |
0d72b8c3 PP |
444 | int bt_component_class_source_set_output_port_connected_method( |
445 | struct bt_component_class_source *comp_cls, | |
446 | bt_component_class_source_output_port_connected_method method) | |
d94d92ac | 447 | { |
d94d92ac PP |
448 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
449 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
450 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
451 | comp_cls->methods.output_port_connected = method; | |
452 | BT_LIB_LOGV("Set source component class's \"output port connected\" method" | |
453 | ": %!+C", comp_cls); | |
454 | return 0; | |
455 | } | |
d3eb6e8f | 456 | |
0d72b8c3 PP |
457 | int bt_component_class_filter_set_output_port_connected_method( |
458 | struct bt_component_class_filter *comp_cls, | |
459 | bt_component_class_filter_output_port_connected_method method) | |
d94d92ac | 460 | { |
d94d92ac PP |
461 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
462 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
463 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
464 | comp_cls->methods.output_port_connected = method; | |
465 | BT_LIB_LOGV("Set filter component class's \"output port connected\" method" | |
466 | ": %!+C", comp_cls); | |
467 | return 0; | |
468 | } | |
d3eb6e8f | 469 | |
0d72b8c3 PP |
470 | int bt_component_class_filter_set_input_port_disconnected_method( |
471 | struct bt_component_class_filter *comp_cls, | |
472 | bt_component_class_filter_input_port_disconnected_method method) | |
d94d92ac | 473 | { |
d94d92ac PP |
474 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
475 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
476 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
477 | comp_cls->methods.input_port_disconnected = method; | |
478 | BT_LIB_LOGV("Set filter component class's \"input port disconnected\" method" | |
479 | ": %!+C", comp_cls); | |
480 | return 0; | |
d3eb6e8f PP |
481 | } |
482 | ||
0d72b8c3 PP |
483 | int bt_component_class_sink_set_input_port_disconnected_method( |
484 | struct bt_component_class_sink *comp_cls, | |
485 | bt_component_class_sink_input_port_disconnected_method method) | |
d3eb6e8f | 486 | { |
d94d92ac PP |
487 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
488 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
489 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
490 | comp_cls->methods.input_port_disconnected = method; | |
491 | BT_LIB_LOGV("Set sink component class's \"input port disconnected\" method" | |
492 | ": %!+C", comp_cls); | |
493 | return 0; | |
494 | } | |
d3eb6e8f | 495 | |
0d72b8c3 PP |
496 | int bt_component_class_source_set_output_port_disconnected_method( |
497 | struct bt_component_class_source *comp_cls, | |
498 | bt_component_class_source_output_port_disconnected_method method) | |
d94d92ac | 499 | { |
d94d92ac PP |
500 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
501 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
502 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
503 | comp_cls->methods.output_port_disconnected = method; | |
504 | BT_LIB_LOGV("Set source component class's \"output port disconnected\" method" | |
505 | ": %!+C", comp_cls); | |
506 | return 0; | |
507 | } | |
a3aacb6f | 508 | |
0d72b8c3 PP |
509 | int bt_component_class_filter_set_output_port_disconnected_method( |
510 | struct bt_component_class_filter *comp_cls, | |
511 | bt_component_class_filter_output_port_disconnected_method method) | |
d94d92ac | 512 | { |
d94d92ac PP |
513 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
514 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
515 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
516 | comp_cls->methods.output_port_disconnected = method; | |
517 | BT_LIB_LOGV("Set filter component class's \"output port disconnected\" method" | |
518 | ": %!+C", comp_cls); | |
519 | return 0; | |
520 | } | |
a3aacb6f | 521 | |
0d72b8c3 PP |
522 | int bt_component_class_source_set_notification_iterator_init_method( |
523 | struct bt_component_class_source *comp_cls, | |
524 | bt_component_class_source_notification_iterator_init_method method) | |
d94d92ac | 525 | { |
d94d92ac PP |
526 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
527 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
528 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
529 | comp_cls->methods.notif_iter_init = method; | |
530 | BT_LIB_LOGV("Set source component class's notification iterator initialization method" | |
531 | ": %!+C", comp_cls); | |
532 | return 0; | |
533 | } | |
a3aacb6f | 534 | |
0d72b8c3 PP |
535 | int bt_component_class_filter_set_notification_iterator_init_method( |
536 | struct bt_component_class_filter *comp_cls, | |
537 | bt_component_class_filter_notification_iterator_init_method method) | |
d94d92ac | 538 | { |
d94d92ac PP |
539 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
540 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
541 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
542 | comp_cls->methods.notif_iter_init = method; | |
543 | BT_LIB_LOGV("Set filter component class's notification iterator initialization method" | |
544 | ": %!+C", comp_cls); | |
545 | return 0; | |
546 | } | |
d3eb6e8f | 547 | |
0d72b8c3 PP |
548 | int bt_component_class_source_set_notification_iterator_finalize_method( |
549 | struct bt_component_class_source *comp_cls, | |
550 | bt_component_class_source_notification_iterator_finalize_method method) | |
d94d92ac | 551 | { |
d94d92ac PP |
552 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
553 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
554 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
555 | comp_cls->methods.notif_iter_finalize = method; | |
556 | BT_LIB_LOGV("Set source component class's notification iterator finalization method" | |
557 | ": %!+C", comp_cls); | |
558 | return 0; | |
559 | } | |
d3eb6e8f | 560 | |
0d72b8c3 PP |
561 | int bt_component_class_filter_set_notification_iterator_finalize_method( |
562 | struct bt_component_class_filter *comp_cls, | |
563 | bt_component_class_filter_notification_iterator_finalize_method method) | |
d94d92ac | 564 | { |
d94d92ac PP |
565 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
566 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
567 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
568 | comp_cls->methods.notif_iter_finalize = method; | |
569 | BT_LIB_LOGV("Set filter component class's notification iterator finalization method" | |
570 | ": %!+C", comp_cls); | |
571 | return 0; | |
d3eb6e8f PP |
572 | } |
573 | ||
0d72b8c3 PP |
574 | int bt_component_class_set_description( |
575 | struct bt_component_class *comp_cls, | |
d3e4dcd8 PP |
576 | const char *description) |
577 | { | |
d94d92ac PP |
578 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
579 | BT_ASSERT_PRE_NON_NULL(description, "Description"); | |
580 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
581 | g_string_assign(comp_cls->description, description); | |
582 | BT_LIB_LOGV("Set component class's description: " | |
a3aacb6f | 583 | "addr=%p, name=\"%s\", type=%s", |
d94d92ac PP |
584 | comp_cls, |
585 | bt_component_class_get_name(comp_cls), | |
586 | bt_component_class_type_string(comp_cls->type)); | |
587 | return 0; | |
fb2dcc52 | 588 | } |
38b48196 | 589 | |
0d72b8c3 PP |
590 | int bt_component_class_set_help( |
591 | struct bt_component_class *comp_cls, | |
5536d9a6 PP |
592 | const char *help) |
593 | { | |
d94d92ac PP |
594 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
595 | BT_ASSERT_PRE_NON_NULL(help, "Help"); | |
596 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
597 | g_string_assign(comp_cls->help, help); | |
598 | BT_LIB_LOGV("Set component class's help text: %!+C", comp_cls); | |
599 | return 0; | |
5536d9a6 PP |
600 | } |
601 | ||
0d72b8c3 | 602 | const char *bt_component_class_get_name(const struct bt_component_class *comp_cls) |
38b48196 | 603 | { |
d94d92ac PP |
604 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
605 | return comp_cls->name->str; | |
38b48196 JG |
606 | } |
607 | ||
d3e4dcd8 | 608 | enum bt_component_class_type bt_component_class_get_type( |
0d72b8c3 | 609 | const struct bt_component_class *comp_cls) |
38b48196 | 610 | { |
d94d92ac PP |
611 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
612 | return comp_cls->type; | |
38b48196 JG |
613 | } |
614 | ||
33b34c43 | 615 | const char *bt_component_class_get_description( |
0d72b8c3 | 616 | const struct bt_component_class *comp_cls) |
38b48196 | 617 | { |
d94d92ac PP |
618 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
619 | return comp_cls->description && | |
620 | comp_cls->description->str[0] != '\0' ? | |
621 | comp_cls->description->str : NULL; | |
38b48196 | 622 | } |
7c7c0433 | 623 | |
5536d9a6 | 624 | const char *bt_component_class_get_help( |
0d72b8c3 | 625 | const struct bt_component_class *comp_cls) |
5536d9a6 | 626 | { |
d94d92ac PP |
627 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
628 | return comp_cls->help && | |
629 | comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL; | |
5536d9a6 PP |
630 | } |
631 | ||
33b34c43 | 632 | BT_HIDDEN |
d94d92ac PP |
633 | void bt_component_class_add_destroy_listener( |
634 | struct bt_component_class *comp_cls, | |
33b34c43 | 635 | bt_component_class_destroy_listener_func func, void *data) |
7c7c0433 | 636 | { |
d3e4dcd8 | 637 | struct bt_component_class_destroy_listener listener; |
33b34c43 | 638 | |
d94d92ac | 639 | BT_ASSERT(comp_cls); |
f6ccaed9 | 640 | BT_ASSERT(func); |
33b34c43 PP |
641 | listener.func = func; |
642 | listener.data = data; | |
d94d92ac PP |
643 | g_array_append_val(comp_cls->destroy_listeners, listener); |
644 | BT_LIB_LOGV("Added destroy listener to component class: " | |
645 | "%![cc-]+C, listener-func-addr=%p", comp_cls, func); | |
7c7c0433 | 646 | } |
d3e4dcd8 | 647 | |
d94d92ac | 648 | BT_HIDDEN |
0d72b8c3 | 649 | void _bt_component_class_freeze(const struct bt_component_class *comp_cls) |
1e4d8103 | 650 | { |
d94d92ac PP |
651 | BT_ASSERT(comp_cls); |
652 | BT_LIB_LOGD("Freezing component class: %!+C", comp_cls); | |
0d72b8c3 | 653 | ((struct bt_component_class *) comp_cls)->frozen = true; |
1e4d8103 | 654 | } |