cpp-common/bt2c/fmt.hpp: use `wise_enum::string_type` in `EnableIfIsWiseEnum` definition
[babeltrace.git] / src / lib / graph / component-class.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 */
7
8 #define BT_LOG_TAG "LIB/COMPONENT-CLASS"
9 #include "lib/logging.h"
10
11 #include "common/assert.h"
12 #include "common/common.h"
13 #include "lib/assert-cond.h"
14 #include "compat/compiler.h"
15 #include <babeltrace2/graph/component-class.h>
16 #include <babeltrace2/types.h>
17 #include <glib.h>
18
19 #include "component-class.h"
20 #include "lib/func-status.h"
21 #include "lib/graph/message-iterator-class.h"
22
23 #define BT_ASSERT_PRE_DEV_COMP_CLS_HOT(_cc) \
24 BT_ASSERT_PRE_DEV_HOT("component-class", \
25 ((const struct bt_component_class *) (_cc)), \
26 "Component class", ": %!+C", (_cc))
27
28 static
29 void destroy_component_class(struct bt_object *obj)
30 {
31 struct bt_component_class *class;
32 int i;
33
34 BT_ASSERT(obj);
35 class = container_of(obj, struct bt_component_class, base);
36
37 BT_LIB_LOGI("Destroying component class: %!+C", class);
38
39 /* Call destroy listeners in reverse registration order */
40 if (class->destroy_listeners) {
41 for (i = class->destroy_listeners->len - 1; i >= 0; i--) {
42 struct bt_component_class_destroy_listener *listener =
43 &bt_g_array_index(class->destroy_listeners,
44 struct bt_component_class_destroy_listener,
45 i);
46
47 BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p",
48 listener->func, listener->data);
49 listener->func(class, listener->data);
50 }
51 }
52
53 if (class->name) {
54 g_string_free(class->name, TRUE);
55 class->name = NULL;
56 }
57
58 if (class->description) {
59 g_string_free(class->description, TRUE);
60 class->description = NULL;
61 }
62
63 if (class->help) {
64 g_string_free(class->help, TRUE);
65 class->help = NULL;
66 }
67
68 if (class->plugin_name) {
69 g_string_free(class->plugin_name, TRUE);
70 class->plugin_name = NULL;
71 }
72
73 if (class->destroy_listeners) {
74 g_array_free(class->destroy_listeners, TRUE);
75 class->destroy_listeners = NULL;
76 }
77
78 if (bt_component_class_has_message_iterator_class(class)) {
79 struct bt_component_class_with_iterator_class *class_with_iter_class =
80 container_of(class, struct bt_component_class_with_iterator_class, parent);
81
82 BT_ASSERT(class_with_iter_class->msg_iter_cls);
83 bt_message_iterator_class_put_ref(class_with_iter_class->msg_iter_cls);
84 class_with_iter_class->msg_iter_cls = NULL;
85 }
86
87 g_free(class);
88 }
89
90 static
91 int bt_component_class_init(struct bt_component_class *class,
92 enum bt_component_class_type type, const char *name)
93 {
94 int ret = 0;
95
96 bt_object_init_shared(&class->base, destroy_component_class);
97 class->type = type;
98 class->name = g_string_new(name);
99 if (!class->name) {
100 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
101 goto error;
102 }
103
104 class->description = g_string_new(NULL);
105 if (!class->description) {
106 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
107 goto error;
108 }
109
110 class->help = g_string_new(NULL);
111 if (!class->help) {
112 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
113 goto error;
114 }
115
116 class->plugin_name = g_string_new(NULL);
117 if (!class->plugin_name) {
118 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
119 goto error;
120 }
121
122 class->destroy_listeners = g_array_new(FALSE, TRUE,
123 sizeof(struct bt_component_class_destroy_listener));
124 if (!class->destroy_listeners) {
125 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
126 goto error;
127 }
128
129 goto end;
130
131 error:
132 BT_OBJECT_PUT_REF_AND_RESET(class);
133 ret = -1;
134
135 end:
136 return ret;
137 }
138
139 static
140 int bt_component_class_with_iterator_class_init(
141 struct bt_component_class_with_iterator_class *class,
142 enum bt_component_class_type type, const char *name,
143 struct bt_message_iterator_class *message_iterator_class)
144 {
145 int ret;
146
147 ret = bt_component_class_init(&class->parent, type, name);
148 if (ret != 0) {
149 goto end;
150 }
151
152 class->msg_iter_cls = message_iterator_class;
153 bt_message_iterator_class_get_ref(class->msg_iter_cls);
154 bt_message_iterator_class_freeze(class->msg_iter_cls);
155
156 end:
157 return ret;
158 }
159
160 BT_EXPORT
161 struct bt_component_class_source *bt_component_class_source_create(
162 const char *name,
163 struct bt_message_iterator_class *message_iterator_class)
164 {
165 struct bt_component_class_source *source_class = NULL;
166 int ret;
167
168 BT_ASSERT_PRE_NO_ERROR();
169 BT_ASSERT_PRE_NAME_NON_NULL(name);
170 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
171 BT_LIB_LOGI("Creating source component class: "
172 "name=\"%s\", %![msg-iter-cls-]+I",
173 name, message_iterator_class);
174 source_class = g_new0(struct bt_component_class_source, 1);
175 if (!source_class) {
176 BT_LIB_LOGE_APPEND_CAUSE(
177 "Failed to allocate one source component class.");
178 goto end;
179 }
180
181 /* bt_component_class_init() logs errors */
182 ret = bt_component_class_with_iterator_class_init(&source_class->parent,
183 BT_COMPONENT_CLASS_TYPE_SOURCE, name, message_iterator_class);
184 if (ret) {
185 /*
186 * If bt_component_class_init() fails, the component
187 * class is put, therefore its memory is already
188 * freed.
189 */
190 source_class = NULL;
191 goto end;
192 }
193
194 BT_LIB_LOGI("Created source component class: %!+C", source_class);
195
196 end:
197 return (void *) source_class;
198 }
199
200 BT_EXPORT
201 struct bt_component_class_filter *bt_component_class_filter_create(
202 const char *name,
203 struct bt_message_iterator_class *message_iterator_class)
204 {
205 struct bt_component_class_filter *filter_class = NULL;
206 int ret;
207
208 BT_ASSERT_PRE_NO_ERROR();
209 BT_ASSERT_PRE_NAME_NON_NULL(name);
210 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
211 BT_LIB_LOGI("Creating filter component class: "
212 "name=\"%s\", %![msg-iter-cls-]+I",
213 name, message_iterator_class);
214 filter_class = g_new0(struct bt_component_class_filter, 1);
215 if (!filter_class) {
216 BT_LIB_LOGE_APPEND_CAUSE(
217 "Failed to allocate one filter component class.");
218 goto end;
219 }
220
221 /* bt_component_class_init() logs errors */
222 ret = bt_component_class_with_iterator_class_init(&filter_class->parent,
223 BT_COMPONENT_CLASS_TYPE_FILTER, name, message_iterator_class);
224 if (ret) {
225 /*
226 * If bt_component_class_init() fails, the component
227 * class is put, therefore its memory is already
228 * freed.
229 */
230 filter_class = NULL;
231 goto end;
232 }
233
234 BT_LIB_LOGI("Created filter component class: %!+C", filter_class);
235
236 end:
237 return (void *) filter_class;
238 }
239
240 BT_EXPORT
241 struct bt_component_class_sink *bt_component_class_sink_create(
242 const char *name, bt_component_class_sink_consume_method method)
243 {
244 struct bt_component_class_sink *sink_class = NULL;
245 int ret;
246
247 BT_ASSERT_PRE_NO_ERROR();
248 BT_ASSERT_PRE_NAME_NON_NULL(name);
249 BT_ASSERT_PRE_NON_NULL("consume-method", method, "Consume next method");
250 BT_LOGI("Creating sink component class: "
251 "name=\"%s\", consume-method-addr=%p",
252 name, method);
253 sink_class = g_new0(struct bt_component_class_sink, 1);
254 if (!sink_class) {
255 BT_LIB_LOGE_APPEND_CAUSE(
256 "Failed to allocate one sink component class.");
257 goto end;
258 }
259
260 /* bt_component_class_init() logs errors */
261 ret = bt_component_class_init(&sink_class->parent,
262 BT_COMPONENT_CLASS_TYPE_SINK, name);
263 if (ret) {
264 /*
265 * If bt_component_class_init() fails, the component
266 * class is put, therefore its memory is already
267 * freed.
268 */
269 sink_class = NULL;
270 goto end;
271 }
272
273 sink_class->methods.consume = method;
274 BT_LIB_LOGI("Created sink component class: %!+C", sink_class);
275
276 end:
277 return (void *) sink_class;
278 }
279
280 BT_EXPORT
281 enum bt_component_class_set_method_status
282 bt_component_class_source_set_get_supported_mip_versions_method(
283 struct bt_component_class_source *comp_cls,
284 bt_component_class_source_get_supported_mip_versions_method method)
285 {
286 BT_ASSERT_PRE_NO_ERROR();
287 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
288 BT_ASSERT_PRE_METHOD_NON_NULL(method);
289 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
290 comp_cls->methods.get_supported_mip_versions = method;
291 BT_LIB_LOGD("Set source component class's \"get supported MIP versions\" method: "
292 "%!+C", comp_cls);
293 return BT_FUNC_STATUS_OK;
294 }
295
296 BT_EXPORT
297 enum bt_component_class_set_method_status
298 bt_component_class_filter_set_get_supported_mip_versions_method(
299 struct bt_component_class_filter *comp_cls,
300 bt_component_class_filter_get_supported_mip_versions_method method)
301 {
302 BT_ASSERT_PRE_NO_ERROR();
303 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
304 BT_ASSERT_PRE_METHOD_NON_NULL(method);
305 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
306 comp_cls->methods.get_supported_mip_versions = method;
307 BT_LIB_LOGD("Set filter component class's \"get supported MIP versions\" method: "
308 "%!+C", comp_cls);
309 return BT_FUNC_STATUS_OK;
310 }
311
312 BT_EXPORT
313 enum bt_component_class_set_method_status
314 bt_component_class_sink_set_get_supported_mip_versions_method(
315 struct bt_component_class_sink *comp_cls,
316 bt_component_class_sink_get_supported_mip_versions_method method)
317 {
318 BT_ASSERT_PRE_NO_ERROR();
319 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
320 BT_ASSERT_PRE_METHOD_NON_NULL(method);
321 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
322 comp_cls->methods.get_supported_mip_versions = method;
323 BT_LIB_LOGD("Set sink component class's \"get supported MIP versions\" method: "
324 "%!+C", comp_cls);
325 return BT_FUNC_STATUS_OK;
326 }
327
328 BT_EXPORT
329 enum bt_component_class_set_method_status
330 bt_component_class_source_set_initialize_method(
331 struct bt_component_class_source *comp_cls,
332 bt_component_class_source_initialize_method method)
333 {
334 BT_ASSERT_PRE_NO_ERROR();
335 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
336 BT_ASSERT_PRE_METHOD_NON_NULL(method);
337 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
338 comp_cls->methods.init = method;
339 BT_LIB_LOGD("Set source component class's initialization method: "
340 "%!+C", comp_cls);
341 return BT_FUNC_STATUS_OK;
342 }
343
344 BT_EXPORT
345 enum bt_component_class_set_method_status
346 bt_component_class_filter_set_initialize_method(
347 struct bt_component_class_filter *comp_cls,
348 bt_component_class_filter_initialize_method method)
349 {
350 BT_ASSERT_PRE_NO_ERROR();
351 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
352 BT_ASSERT_PRE_METHOD_NON_NULL(method);
353 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
354 comp_cls->methods.init = method;
355 BT_LIB_LOGD("Set filter component class's initialization method: "
356 "%!+C", comp_cls);
357 return BT_FUNC_STATUS_OK;
358 }
359
360 BT_EXPORT
361 enum bt_component_class_set_method_status
362 bt_component_class_sink_set_initialize_method(
363 struct bt_component_class_sink *comp_cls,
364 bt_component_class_sink_initialize_method method)
365 {
366 BT_ASSERT_PRE_NO_ERROR();
367 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
368 BT_ASSERT_PRE_METHOD_NON_NULL(method);
369 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
370 comp_cls->methods.init = method;
371 BT_LIB_LOGD("Set sink component class's initialization method: "
372 "%!+C", comp_cls);
373 return BT_FUNC_STATUS_OK;
374 }
375
376 BT_EXPORT
377 enum bt_component_class_set_method_status
378 bt_component_class_source_set_finalize_method(
379 struct bt_component_class_source *comp_cls,
380 bt_component_class_source_finalize_method method)
381 {
382 BT_ASSERT_PRE_NO_ERROR();
383 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
384 BT_ASSERT_PRE_METHOD_NON_NULL(method);
385 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
386 comp_cls->methods.finalize = method;
387 BT_LIB_LOGD("Set source component class's finalization method: "
388 "%!+C", comp_cls);
389 return BT_FUNC_STATUS_OK;
390 }
391
392 BT_EXPORT
393 enum bt_component_class_set_method_status
394 bt_component_class_filter_set_finalize_method(
395 struct bt_component_class_filter *comp_cls,
396 bt_component_class_filter_finalize_method method)
397 {
398 BT_ASSERT_PRE_NO_ERROR();
399 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
400 BT_ASSERT_PRE_METHOD_NON_NULL(method);
401 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
402 comp_cls->methods.finalize = method;
403 BT_LIB_LOGD("Set filter component class's finalization method: "
404 "%!+C", comp_cls);
405 return BT_FUNC_STATUS_OK;
406 }
407
408 BT_EXPORT
409 enum bt_component_class_set_method_status
410 bt_component_class_sink_set_finalize_method(
411 struct bt_component_class_sink *comp_cls,
412 bt_component_class_sink_finalize_method method)
413 {
414 BT_ASSERT_PRE_NO_ERROR();
415 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
416 BT_ASSERT_PRE_METHOD_NON_NULL(method);
417 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
418 comp_cls->methods.finalize = method;
419 BT_LIB_LOGD("Set sink component class's finalization method: "
420 "%!+C", comp_cls);
421 return BT_FUNC_STATUS_OK;
422 }
423
424 BT_EXPORT
425 enum bt_component_class_set_method_status
426 bt_component_class_source_set_query_method(
427 struct bt_component_class_source *comp_cls,
428 bt_component_class_source_query_method method)
429 {
430 BT_ASSERT_PRE_NO_ERROR();
431 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
432 BT_ASSERT_PRE_METHOD_NON_NULL(method);
433 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
434 comp_cls->methods.query = method;
435 BT_LIB_LOGD("Set source component class's query method: "
436 "%!+C", comp_cls);
437 return BT_FUNC_STATUS_OK;
438 }
439
440 BT_EXPORT
441 enum bt_component_class_set_method_status
442 bt_component_class_filter_set_query_method(
443 struct bt_component_class_filter *comp_cls,
444 bt_component_class_filter_query_method method)
445 {
446 BT_ASSERT_PRE_NO_ERROR();
447 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
448 BT_ASSERT_PRE_METHOD_NON_NULL(method);
449 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
450 comp_cls->methods.query = method;
451 BT_LIB_LOGD("Set filter component class's query method: "
452 "%!+C", comp_cls);
453 return BT_FUNC_STATUS_OK;
454 }
455
456 BT_EXPORT
457 enum bt_component_class_set_method_status
458 bt_component_class_sink_set_query_method(
459 struct bt_component_class_sink *comp_cls,
460 bt_component_class_sink_query_method method)
461 {
462 BT_ASSERT_PRE_NO_ERROR();
463 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
464 BT_ASSERT_PRE_METHOD_NON_NULL(method);
465 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
466 comp_cls->methods.query = method;
467 BT_LIB_LOGD("Set sink component class's query method: "
468 "%!+C", comp_cls);
469 return BT_FUNC_STATUS_OK;
470 }
471
472 BT_EXPORT
473 enum bt_component_class_set_method_status
474 bt_component_class_filter_set_input_port_connected_method(
475 struct bt_component_class_filter *comp_cls,
476 bt_component_class_filter_input_port_connected_method method)
477 {
478 BT_ASSERT_PRE_NO_ERROR();
479 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
480 BT_ASSERT_PRE_METHOD_NON_NULL(method);
481 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
482 comp_cls->methods.input_port_connected = method;
483 BT_LIB_LOGD("Set filter component class's \"input port connected\" method"
484 ": %!+C", comp_cls);
485 return BT_FUNC_STATUS_OK;
486 }
487
488 BT_EXPORT
489 enum bt_component_class_set_method_status
490 bt_component_class_sink_set_input_port_connected_method(
491 struct bt_component_class_sink *comp_cls,
492 bt_component_class_sink_input_port_connected_method method)
493 {
494 BT_ASSERT_PRE_NO_ERROR();
495 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
496 BT_ASSERT_PRE_METHOD_NON_NULL(method);
497 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
498 comp_cls->methods.input_port_connected = method;
499 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
500 ": %!+C", comp_cls);
501 return BT_FUNC_STATUS_OK;
502 }
503
504 BT_EXPORT
505 enum bt_component_class_set_method_status
506 bt_component_class_source_set_output_port_connected_method(
507 struct bt_component_class_source *comp_cls,
508 bt_component_class_source_output_port_connected_method method)
509 {
510 BT_ASSERT_PRE_NO_ERROR();
511 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
512 BT_ASSERT_PRE_METHOD_NON_NULL(method);
513 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
514 comp_cls->methods.output_port_connected = method;
515 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
516 ": %!+C", comp_cls);
517 return BT_FUNC_STATUS_OK;
518 }
519
520 BT_EXPORT
521 enum bt_component_class_set_method_status
522 bt_component_class_filter_set_output_port_connected_method(
523 struct bt_component_class_filter *comp_cls,
524 bt_component_class_filter_output_port_connected_method method)
525 {
526 BT_ASSERT_PRE_NO_ERROR();
527 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
528 BT_ASSERT_PRE_METHOD_NON_NULL(method);
529 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
530 comp_cls->methods.output_port_connected = method;
531 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
532 ": %!+C", comp_cls);
533 return BT_FUNC_STATUS_OK;
534 }
535
536 BT_EXPORT
537 enum bt_component_class_set_method_status
538 bt_component_class_sink_set_graph_is_configured_method(
539 struct bt_component_class_sink *comp_cls,
540 bt_component_class_sink_graph_is_configured_method method)
541 {
542 BT_ASSERT_PRE_NO_ERROR();
543 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
544 BT_ASSERT_PRE_METHOD_NON_NULL(method);
545 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
546 comp_cls->methods.graph_is_configured = method;
547 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
548 ": %!+C", comp_cls);
549 return BT_FUNC_STATUS_OK;
550 }
551
552 BT_EXPORT
553 enum bt_component_class_set_description_status
554 bt_component_class_set_description(
555 struct bt_component_class *comp_cls,
556 const char *description)
557 {
558 BT_ASSERT_PRE_NO_ERROR();
559 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
560 BT_ASSERT_PRE_DESCR_NON_NULL(description);
561 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
562 g_string_assign(comp_cls->description, description);
563 BT_LIB_LOGD("Set component class's description: "
564 "addr=%p, name=\"%s\", type=%s",
565 comp_cls,
566 bt_component_class_get_name(comp_cls),
567 bt_common_component_class_type_string(comp_cls->type));
568 return BT_FUNC_STATUS_OK;
569 }
570
571 BT_EXPORT
572 enum bt_component_class_set_help_status bt_component_class_set_help(
573 struct bt_component_class *comp_cls,
574 const char *help)
575 {
576 BT_ASSERT_PRE_NO_ERROR();
577 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
578 BT_ASSERT_PRE_NON_NULL("help-text", help, "Help text");
579 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
580 g_string_assign(comp_cls->help, help);
581 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls);
582 return BT_FUNC_STATUS_OK;
583 }
584
585 BT_EXPORT
586 const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
587 {
588 BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls);
589 return comp_cls->name->str;
590 }
591
592 BT_EXPORT
593 enum bt_component_class_type bt_component_class_get_type(
594 const struct bt_component_class *comp_cls)
595 {
596 BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls);
597 return comp_cls->type;
598 }
599
600 BT_EXPORT
601 const char *bt_component_class_get_description(
602 const struct bt_component_class *comp_cls)
603 {
604 BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls);
605 return comp_cls->description &&
606 comp_cls->description->str[0] != '\0' ?
607 comp_cls->description->str : NULL;
608 }
609
610 BT_EXPORT
611 const char *bt_component_class_get_help(
612 const struct bt_component_class *comp_cls)
613 {
614 BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls);
615 return comp_cls->help &&
616 comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL;
617 }
618
619 void bt_component_class_add_destroy_listener(
620 struct bt_component_class *comp_cls,
621 bt_component_class_destroy_listener_func func, void *data)
622 {
623 struct bt_component_class_destroy_listener listener;
624
625 BT_ASSERT(comp_cls);
626 BT_ASSERT(func);
627 listener.func = func;
628 listener.data = data;
629 g_array_append_val(comp_cls->destroy_listeners, listener);
630 BT_LIB_LOGD("Added destroy listener to component class: "
631 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
632 }
633
634 void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
635 {
636 BT_ASSERT(comp_cls);
637 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
638 ((struct bt_component_class *) comp_cls)->frozen = true;
639 }
640
641 BT_EXPORT
642 void bt_component_class_get_ref(
643 const struct bt_component_class *component_class)
644 {
645 bt_object_get_ref(component_class);
646 }
647
648 BT_EXPORT
649 void bt_component_class_put_ref(
650 const struct bt_component_class *component_class)
651 {
652 bt_object_put_ref(component_class);
653 }
654
655 BT_EXPORT
656 void bt_component_class_source_get_ref(
657 const struct bt_component_class_source *component_class_source)
658 {
659 bt_object_get_ref(component_class_source);
660 }
661
662 BT_EXPORT
663 void bt_component_class_source_put_ref(
664 const struct bt_component_class_source *component_class_source)
665 {
666 bt_object_put_ref(component_class_source);
667 }
668
669 BT_EXPORT
670 void bt_component_class_filter_get_ref(
671 const struct bt_component_class_filter *component_class_filter)
672 {
673 bt_object_get_ref(component_class_filter);
674 }
675
676 BT_EXPORT
677 void bt_component_class_filter_put_ref(
678 const struct bt_component_class_filter *component_class_filter)
679 {
680 bt_object_put_ref(component_class_filter);
681 }
682
683 BT_EXPORT
684 void bt_component_class_sink_get_ref(
685 const struct bt_component_class_sink *component_class_sink)
686 {
687 bt_object_get_ref(component_class_sink);
688 }
689
690 BT_EXPORT
691 void bt_component_class_sink_put_ref(
692 const struct bt_component_class_sink *component_class_sink)
693 {
694 bt_object_put_ref(component_class_sink);
695 }
This page took 0.042939 seconds and 4 git commands to generate.