2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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
24 #define BT_LOG_TAG "LIB/COMPONENT-CLASS"
25 #include "lib/logging.h"
27 #include "common/assert.h"
28 #include "lib/assert-pre.h"
29 #include "compat/compiler.h"
30 #include <babeltrace2/graph/component-class.h>
31 #include <babeltrace2/graph/component-class-const.h>
32 #include <babeltrace2/graph/component-class-source.h>
33 #include <babeltrace2/graph/component-class-source-const.h>
34 #include <babeltrace2/graph/component-class-filter.h>
35 #include <babeltrace2/graph/component-class-filter-const.h>
36 #include <babeltrace2/graph/component-class-sink.h>
37 #include <babeltrace2/graph/component-class-sink-const.h>
38 #include <babeltrace2/types.h>
41 #include "component-class.h"
42 #include "lib/func-status.h"
44 #define BT_ASSERT_PRE_COMP_CLS_HOT(_cc) \
45 BT_ASSERT_PRE_HOT(((const struct bt_component_class *) (_cc)), \
46 "Component class", ": %!+C", (_cc))
49 void destroy_component_class(struct bt_object
*obj
)
51 struct bt_component_class
*class;
55 class = container_of(obj
, struct bt_component_class
, base
);
57 BT_LIB_LOGI("Destroying component class: %!+C", class);
59 /* Call destroy listeners in reverse registration order */
60 for (i
= class->destroy_listeners
->len
- 1; i
>= 0; i
--) {
61 struct bt_component_class_destroy_listener
*listener
=
62 &g_array_index(class->destroy_listeners
,
63 struct bt_component_class_destroy_listener
,
66 BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p",
67 listener
->func
, listener
->data
);
68 listener
->func(class, listener
->data
);
72 g_string_free(class->name
, TRUE
);
76 if (class->description
) {
77 g_string_free(class->description
, TRUE
);
78 class->description
= NULL
;
82 g_string_free(class->help
, TRUE
);
86 if (class->plugin_name
) {
87 g_string_free(class->plugin_name
, TRUE
);
88 class->plugin_name
= NULL
;
91 if (class->destroy_listeners
) {
92 g_array_free(class->destroy_listeners
, TRUE
);
93 class->destroy_listeners
= NULL
;
100 int bt_component_class_init(struct bt_component_class
*class,
101 enum bt_component_class_type type
, const char *name
)
105 bt_object_init_shared(&class->base
, destroy_component_class
);
107 class->name
= g_string_new(name
);
109 BT_LOGE_STR("Failed to allocate a GString.");
113 class->description
= g_string_new(NULL
);
114 if (!class->description
) {
115 BT_LOGE_STR("Failed to allocate a GString.");
119 class->help
= g_string_new(NULL
);
121 BT_LOGE_STR("Failed to allocate a GString.");
125 class->plugin_name
= g_string_new(NULL
);
126 if (!class->plugin_name
) {
127 BT_LOGE_STR("Failed to allocate a GString.");
131 class->destroy_listeners
= g_array_new(FALSE
, TRUE
,
132 sizeof(struct bt_component_class_destroy_listener
));
133 if (!class->destroy_listeners
) {
134 BT_LOGE_STR("Failed to allocate a GArray.");
141 BT_OBJECT_PUT_REF_AND_RESET(class);
148 struct bt_component_class_source
*bt_component_class_source_create(
150 bt_component_class_source_message_iterator_next_method method
)
152 struct bt_component_class_source
*source_class
= NULL
;
155 BT_ASSERT_PRE_NON_NULL(name
, "Name");
156 BT_ASSERT_PRE_NON_NULL(method
, "Message iterator next method");
157 BT_LOGI("Creating source component class: "
158 "name=\"%s\", msg-iter-next-method-addr=%p",
160 source_class
= g_new0(struct bt_component_class_source
, 1);
162 BT_LOGE_STR("Failed to allocate one source component class.");
166 /* bt_component_class_init() logs errors */
167 ret
= bt_component_class_init(&source_class
->parent
,
168 BT_COMPONENT_CLASS_TYPE_SOURCE
, name
);
171 * If bt_component_class_init() fails, the component
172 * class is put, therefore its memory is already
179 source_class
->methods
.msg_iter_next
= method
;
180 BT_LIB_LOGI("Created source component class: %!+C", source_class
);
183 return (void *) source_class
;
186 struct bt_component_class_filter
*bt_component_class_filter_create(
188 bt_component_class_filter_message_iterator_next_method method
)
190 struct bt_component_class_filter
*filter_class
= NULL
;
193 BT_ASSERT_PRE_NON_NULL(name
, "Name");
194 BT_ASSERT_PRE_NON_NULL(method
, "Message iterator next method");
195 BT_LOGI("Creating filter component class: "
196 "name=\"%s\", msg-iter-next-method-addr=%p",
198 filter_class
= g_new0(struct bt_component_class_filter
, 1);
200 BT_LOGE_STR("Failed to allocate one filter component class.");
204 /* bt_component_class_init() logs errors */
205 ret
= bt_component_class_init(&filter_class
->parent
,
206 BT_COMPONENT_CLASS_TYPE_FILTER
, name
);
209 * If bt_component_class_init() fails, the component
210 * class is put, therefore its memory is already
217 filter_class
->methods
.msg_iter_next
= method
;
218 BT_LIB_LOGI("Created filter component class: %!+C", filter_class
);
221 return (void *) filter_class
;
224 struct bt_component_class_sink
*bt_component_class_sink_create(
225 const char *name
, bt_component_class_sink_consume_method method
)
227 struct bt_component_class_sink
*sink_class
= NULL
;
230 BT_ASSERT_PRE_NON_NULL(name
, "Name");
231 BT_ASSERT_PRE_NON_NULL(method
, "Consume next method");
232 BT_LOGI("Creating sink component class: "
233 "name=\"%s\", consume-method-addr=%p",
235 sink_class
= g_new0(struct bt_component_class_sink
, 1);
237 BT_LOGE_STR("Failed to allocate one sink component class.");
241 /* bt_component_class_init() logs errors */
242 ret
= bt_component_class_init(&sink_class
->parent
,
243 BT_COMPONENT_CLASS_TYPE_SINK
, name
);
246 * If bt_component_class_init() fails, the component
247 * class is put, therefore its memory is already
254 sink_class
->methods
.consume
= method
;
255 BT_LIB_LOGI("Created sink component class: %!+C", sink_class
);
258 return (void *) sink_class
;
261 enum bt_component_class_set_method_status
262 bt_component_class_source_set_init_method(
263 struct bt_component_class_source
*comp_cls
,
264 bt_component_class_source_init_method method
)
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_LOGD("Set source component class's initialization method: "
272 return BT_FUNC_STATUS_OK
;
275 enum bt_component_class_set_method_status
276 bt_component_class_filter_set_init_method(
277 struct bt_component_class_filter
*comp_cls
,
278 bt_component_class_filter_init_method method
)
280 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
281 BT_ASSERT_PRE_NON_NULL(method
, "Method");
282 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
283 comp_cls
->methods
.init
= method
;
284 BT_LIB_LOGD("Set filter component class's initialization method: "
286 return BT_FUNC_STATUS_OK
;
289 enum bt_component_class_set_method_status
290 bt_component_class_sink_set_init_method(
291 struct bt_component_class_sink
*comp_cls
,
292 bt_component_class_sink_init_method method
)
294 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
295 BT_ASSERT_PRE_NON_NULL(method
, "Method");
296 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
297 comp_cls
->methods
.init
= method
;
298 BT_LIB_LOGD("Set sink component class's initialization method: "
300 return BT_FUNC_STATUS_OK
;
303 enum bt_component_class_set_method_status
304 bt_component_class_source_set_finalize_method(
305 struct bt_component_class_source
*comp_cls
,
306 bt_component_class_source_finalize_method method
)
308 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
309 BT_ASSERT_PRE_NON_NULL(method
, "Method");
310 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
311 comp_cls
->methods
.finalize
= method
;
312 BT_LIB_LOGD("Set source component class's finalization method: "
314 return BT_FUNC_STATUS_OK
;
317 enum bt_component_class_set_method_status
318 bt_component_class_filter_set_finalize_method(
319 struct bt_component_class_filter
*comp_cls
,
320 bt_component_class_filter_finalize_method method
)
322 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
323 BT_ASSERT_PRE_NON_NULL(method
, "Method");
324 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
325 comp_cls
->methods
.finalize
= method
;
326 BT_LIB_LOGD("Set filter component class's finalization method: "
328 return BT_FUNC_STATUS_OK
;
331 enum bt_component_class_set_method_status
332 bt_component_class_sink_set_finalize_method(
333 struct bt_component_class_sink
*comp_cls
,
334 bt_component_class_sink_finalize_method method
)
336 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
337 BT_ASSERT_PRE_NON_NULL(method
, "Method");
338 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
339 comp_cls
->methods
.finalize
= method
;
340 BT_LIB_LOGD("Set sink component class's finalization method: "
342 return BT_FUNC_STATUS_OK
;
345 enum bt_component_class_set_method_status
346 bt_component_class_source_set_query_method(
347 struct bt_component_class_source
*comp_cls
,
348 bt_component_class_source_query_method method
)
350 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
351 BT_ASSERT_PRE_NON_NULL(method
, "Method");
352 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
353 comp_cls
->methods
.query
= method
;
354 BT_LIB_LOGD("Set source component class's query method: "
356 return BT_FUNC_STATUS_OK
;
359 enum bt_component_class_set_method_status
360 bt_component_class_filter_set_query_method(
361 struct bt_component_class_filter
*comp_cls
,
362 bt_component_class_filter_query_method method
)
364 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
365 BT_ASSERT_PRE_NON_NULL(method
, "Method");
366 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
367 comp_cls
->methods
.query
= method
;
368 BT_LIB_LOGD("Set filter component class's query method: "
370 return BT_FUNC_STATUS_OK
;
373 enum bt_component_class_set_method_status
374 bt_component_class_sink_set_query_method(
375 struct bt_component_class_sink
*comp_cls
,
376 bt_component_class_sink_query_method method
)
378 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
379 BT_ASSERT_PRE_NON_NULL(method
, "Method");
380 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
381 comp_cls
->methods
.query
= method
;
382 BT_LIB_LOGD("Set sink component class's query method: "
384 return BT_FUNC_STATUS_OK
;
387 enum bt_component_class_set_method_status
388 bt_component_class_filter_set_input_port_connected_method(
389 struct bt_component_class_filter
*comp_cls
,
390 bt_component_class_filter_input_port_connected_method method
)
392 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
393 BT_ASSERT_PRE_NON_NULL(method
, "Method");
394 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
395 comp_cls
->methods
.input_port_connected
= method
;
396 BT_LIB_LOGD("Set filter component class's \"input port connected\" method"
398 return BT_FUNC_STATUS_OK
;
401 enum bt_component_class_set_method_status
402 bt_component_class_sink_set_input_port_connected_method(
403 struct bt_component_class_sink
*comp_cls
,
404 bt_component_class_sink_input_port_connected_method method
)
406 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
407 BT_ASSERT_PRE_NON_NULL(method
, "Method");
408 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
409 comp_cls
->methods
.input_port_connected
= method
;
410 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
412 return BT_FUNC_STATUS_OK
;
415 enum bt_component_class_set_method_status
416 bt_component_class_source_set_output_port_connected_method(
417 struct bt_component_class_source
*comp_cls
,
418 bt_component_class_source_output_port_connected_method method
)
420 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
421 BT_ASSERT_PRE_NON_NULL(method
, "Method");
422 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
423 comp_cls
->methods
.output_port_connected
= method
;
424 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
426 return BT_FUNC_STATUS_OK
;
429 enum bt_component_class_set_method_status
430 bt_component_class_filter_set_output_port_connected_method(
431 struct bt_component_class_filter
*comp_cls
,
432 bt_component_class_filter_output_port_connected_method method
)
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
.output_port_connected
= method
;
438 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
440 return BT_FUNC_STATUS_OK
;
443 enum bt_component_class_set_method_status
444 bt_component_class_sink_set_graph_is_configured_method(
445 struct bt_component_class_sink
*comp_cls
,
446 bt_component_class_sink_graph_is_configured_method method
)
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
.graph_is_configured
= method
;
452 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
454 return BT_FUNC_STATUS_OK
;
457 enum bt_component_class_set_method_status
458 bt_component_class_source_set_message_iterator_init_method(
459 struct bt_component_class_source
*comp_cls
,
460 bt_component_class_source_message_iterator_init_method method
)
462 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
463 BT_ASSERT_PRE_NON_NULL(method
, "Method");
464 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
465 comp_cls
->methods
.msg_iter_init
= method
;
466 BT_LIB_LOGD("Set source component class's message iterator initialization method"
468 return BT_FUNC_STATUS_OK
;
471 enum bt_component_class_set_method_status
472 bt_component_class_filter_set_message_iterator_init_method(
473 struct bt_component_class_filter
*comp_cls
,
474 bt_component_class_filter_message_iterator_init_method method
)
476 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
477 BT_ASSERT_PRE_NON_NULL(method
, "Method");
478 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
479 comp_cls
->methods
.msg_iter_init
= method
;
480 BT_LIB_LOGD("Set filter component class's message iterator initialization method"
482 return BT_FUNC_STATUS_OK
;
485 enum bt_component_class_set_method_status
486 bt_component_class_source_set_message_iterator_finalize_method(
487 struct bt_component_class_source
*comp_cls
,
488 bt_component_class_source_message_iterator_finalize_method method
)
490 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
491 BT_ASSERT_PRE_NON_NULL(method
, "Method");
492 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
493 comp_cls
->methods
.msg_iter_finalize
= method
;
494 BT_LIB_LOGD("Set source component class's message iterator finalization method"
496 return BT_FUNC_STATUS_OK
;
499 enum bt_component_class_set_method_status
500 bt_component_class_filter_set_message_iterator_finalize_method(
501 struct bt_component_class_filter
*comp_cls
,
502 bt_component_class_filter_message_iterator_finalize_method method
)
504 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
505 BT_ASSERT_PRE_NON_NULL(method
, "Method");
506 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
507 comp_cls
->methods
.msg_iter_finalize
= method
;
508 BT_LIB_LOGD("Set filter component class's message iterator finalization method"
510 return BT_FUNC_STATUS_OK
;
513 enum bt_component_class_set_method_status
514 bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method(
515 struct bt_component_class_filter
*comp_cls
,
516 bt_component_class_filter_message_iterator_seek_ns_from_origin_method method
)
518 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
519 BT_ASSERT_PRE_NON_NULL(method
, "Method");
520 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
521 comp_cls
->methods
.msg_iter_seek_ns_from_origin
= method
;
522 BT_LIB_LOGD("Set filter component class's message iterator \"seek nanoseconds from origin\" method"
524 return BT_FUNC_STATUS_OK
;
527 enum bt_component_class_set_method_status
528 bt_component_class_source_set_message_iterator_seek_ns_from_origin_method(
529 struct bt_component_class_source
*comp_cls
,
530 bt_component_class_source_message_iterator_seek_ns_from_origin_method method
)
532 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
533 BT_ASSERT_PRE_NON_NULL(method
, "Method");
534 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
535 comp_cls
->methods
.msg_iter_seek_ns_from_origin
= method
;
536 BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" method"
538 return BT_FUNC_STATUS_OK
;
541 enum bt_component_class_set_method_status
542 bt_component_class_filter_set_message_iterator_seek_beginning_method(
543 struct bt_component_class_filter
*comp_cls
,
544 bt_component_class_filter_message_iterator_seek_beginning_method method
)
546 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
547 BT_ASSERT_PRE_NON_NULL(method
, "Method");
548 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
549 comp_cls
->methods
.msg_iter_seek_beginning
= method
;
550 BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" method"
552 return BT_FUNC_STATUS_OK
;
555 enum bt_component_class_set_method_status
556 bt_component_class_source_set_message_iterator_seek_beginning_method(
557 struct bt_component_class_source
*comp_cls
,
558 bt_component_class_source_message_iterator_seek_beginning_method method
)
560 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
561 BT_ASSERT_PRE_NON_NULL(method
, "Method");
562 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
563 comp_cls
->methods
.msg_iter_seek_beginning
= method
;
564 BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" method"
566 return BT_FUNC_STATUS_OK
;
569 enum bt_component_class_set_method_status
570 bt_component_class_filter_set_message_iterator_can_seek_beginning_method(
571 struct bt_component_class_filter
*comp_cls
,
572 bt_component_class_filter_message_iterator_can_seek_beginning_method method
)
574 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
575 BT_ASSERT_PRE_NON_NULL(method
, "Method");
576 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
577 comp_cls
->methods
.msg_iter_can_seek_beginning
= method
;
578 BT_LIB_LOGD("Set filter component class's message iterator \"can seek beginning\" method"
580 return BT_FUNC_STATUS_OK
;
583 enum bt_component_class_set_method_status
584 bt_component_class_source_set_message_iterator_can_seek_beginning_method(
585 struct bt_component_class_source
*comp_cls
,
586 bt_component_class_source_message_iterator_can_seek_beginning_method method
)
588 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
589 BT_ASSERT_PRE_NON_NULL(method
, "Method");
590 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
591 comp_cls
->methods
.msg_iter_can_seek_beginning
= method
;
592 BT_LIB_LOGD("Set source component class's message iterator \"can seek beginning\" method"
594 return BT_FUNC_STATUS_OK
;
597 enum bt_component_class_set_method_status
598 bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method(
599 struct bt_component_class_filter
*comp_cls
,
600 bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method method
)
602 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
603 BT_ASSERT_PRE_NON_NULL(method
, "Method");
604 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
605 comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
= method
;
606 BT_LIB_LOGD("Set filter component class's message iterator \"can seek nanoseconds from origin\" method"
608 return BT_FUNC_STATUS_OK
;
611 enum bt_component_class_set_method_status
612 bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method(
613 struct bt_component_class_source
*comp_cls
,
614 bt_component_class_source_message_iterator_can_seek_ns_from_origin_method method
)
616 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
617 BT_ASSERT_PRE_NON_NULL(method
, "Method");
618 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
619 comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
= method
;
620 BT_LIB_LOGD("Set source component class's message iterator \"can seek nanoseconds from origin\" method"
622 return BT_FUNC_STATUS_OK
;
625 enum bt_component_class_set_description_status
626 bt_component_class_set_description(
627 struct bt_component_class
*comp_cls
,
628 const char *description
)
630 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
631 BT_ASSERT_PRE_NON_NULL(description
, "Description");
632 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
633 g_string_assign(comp_cls
->description
, description
);
634 BT_LIB_LOGD("Set component class's description: "
635 "addr=%p, name=\"%s\", type=%s",
637 bt_component_class_get_name(comp_cls
),
638 bt_component_class_type_string(comp_cls
->type
));
639 return BT_FUNC_STATUS_OK
;
642 enum bt_component_class_set_help_status
bt_component_class_set_help(
643 struct bt_component_class
*comp_cls
,
646 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
647 BT_ASSERT_PRE_NON_NULL(help
, "Help");
648 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
649 g_string_assign(comp_cls
->help
, help
);
650 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls
);
651 return BT_FUNC_STATUS_OK
;
654 const char *bt_component_class_get_name(const struct bt_component_class
*comp_cls
)
656 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
657 return comp_cls
->name
->str
;
660 enum bt_component_class_type
bt_component_class_get_type(
661 const struct bt_component_class
*comp_cls
)
663 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
664 return comp_cls
->type
;
667 const char *bt_component_class_get_description(
668 const struct bt_component_class
*comp_cls
)
670 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
671 return comp_cls
->description
&&
672 comp_cls
->description
->str
[0] != '\0' ?
673 comp_cls
->description
->str
: NULL
;
676 const char *bt_component_class_get_help(
677 const struct bt_component_class
*comp_cls
)
679 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
680 return comp_cls
->help
&&
681 comp_cls
->help
->str
[0] != '\0' ? comp_cls
->help
->str
: NULL
;
685 void bt_component_class_add_destroy_listener(
686 struct bt_component_class
*comp_cls
,
687 bt_component_class_destroy_listener_func func
, void *data
)
689 struct bt_component_class_destroy_listener listener
;
693 listener
.func
= func
;
694 listener
.data
= data
;
695 g_array_append_val(comp_cls
->destroy_listeners
, listener
);
696 BT_LIB_LOGD("Added destroy listener to component class: "
697 "%![cc-]+C, listener-func-addr=%p", comp_cls
, func
);
701 void _bt_component_class_freeze(const struct bt_component_class
*comp_cls
)
704 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls
);
705 ((struct bt_component_class
*) comp_cls
)->frozen
= true;
708 void bt_component_class_get_ref(
709 const struct bt_component_class
*component_class
)
711 bt_object_get_ref(component_class
);
714 void bt_component_class_put_ref(
715 const struct bt_component_class
*component_class
)
717 bt_object_put_ref(component_class
);
720 void bt_component_class_source_get_ref(
721 const struct bt_component_class_source
*component_class_source
)
723 bt_object_get_ref(component_class_source
);
726 void bt_component_class_source_put_ref(
727 const struct bt_component_class_source
*component_class_source
)
729 bt_object_put_ref(component_class_source
);
732 void bt_component_class_filter_get_ref(
733 const struct bt_component_class_filter
*component_class_filter
)
735 bt_object_get_ref(component_class_filter
);
738 void bt_component_class_filter_put_ref(
739 const struct bt_component_class_filter
*component_class_filter
)
741 bt_object_put_ref(component_class_filter
);
744 void bt_component_class_sink_get_ref(
745 const struct bt_component_class_sink
*component_class_sink
)
747 bt_object_get_ref(component_class_sink
);
750 void bt_component_class_sink_put_ref(
751 const struct bt_component_class_sink
*component_class_sink
)
753 bt_object_put_ref(component_class_sink
);