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"
43 #define BT_ASSERT_PRE_COMP_CLS_HOT(_cc) \
44 BT_ASSERT_PRE_HOT(((const struct bt_component_class *) (_cc)), \
45 "Component class", ": %!+C", (_cc))
48 void destroy_component_class(struct bt_object
*obj
)
50 struct bt_component_class
*class;
54 class = container_of(obj
, struct bt_component_class
, base
);
56 BT_LIB_LOGI("Destroying component class: %!+C", class);
58 /* Call destroy listeners in reverse registration order */
59 for (i
= class->destroy_listeners
->len
- 1; i
>= 0; i
--) {
60 struct bt_component_class_destroy_listener
*listener
=
61 &g_array_index(class->destroy_listeners
,
62 struct bt_component_class_destroy_listener
,
65 BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p",
66 listener
->func
, listener
->data
);
67 listener
->func(class, listener
->data
);
71 g_string_free(class->name
, TRUE
);
75 if (class->description
) {
76 g_string_free(class->description
, TRUE
);
77 class->description
= NULL
;
81 g_string_free(class->help
, TRUE
);
85 if (class->destroy_listeners
) {
86 g_array_free(class->destroy_listeners
, TRUE
);
87 class->destroy_listeners
= NULL
;
94 int bt_component_class_init(struct bt_component_class
*class,
95 enum bt_component_class_type type
, const char *name
)
99 bt_object_init_shared(&class->base
, destroy_component_class
);
101 class->name
= g_string_new(name
);
103 BT_LOGE_STR("Failed to allocate a GString.");
107 class->description
= g_string_new(NULL
);
108 if (!class->description
) {
109 BT_LOGE_STR("Failed to allocate a GString.");
113 class->help
= g_string_new(NULL
);
115 BT_LOGE_STR("Failed to allocate a GString.");
119 class->destroy_listeners
= g_array_new(FALSE
, TRUE
,
120 sizeof(struct bt_component_class_destroy_listener
));
121 if (!class->destroy_listeners
) {
122 BT_LOGE_STR("Failed to allocate a GArray.");
129 BT_OBJECT_PUT_REF_AND_RESET(class);
136 struct bt_component_class_source
*bt_component_class_source_create(
138 bt_component_class_source_message_iterator_next_method method
)
140 struct bt_component_class_source
*source_class
= NULL
;
143 BT_ASSERT_PRE_NON_NULL(name
, "Name");
144 BT_ASSERT_PRE_NON_NULL(method
, "Message iterator next method");
145 BT_LOGI("Creating source component class: "
146 "name=\"%s\", msg-iter-next-method-addr=%p",
148 source_class
= g_new0(struct bt_component_class_source
, 1);
150 BT_LOGE_STR("Failed to allocate one source component class.");
154 /* bt_component_class_init() logs errors */
155 ret
= bt_component_class_init(&source_class
->parent
,
156 BT_COMPONENT_CLASS_TYPE_SOURCE
, name
);
159 * If bt_component_class_init() fails, the component
160 * class is put, therefore its memory is already
167 source_class
->methods
.msg_iter_next
= method
;
168 BT_LIB_LOGI("Created source component class: %!+C", source_class
);
171 return (void *) source_class
;
174 struct bt_component_class_filter
*bt_component_class_filter_create(
176 bt_component_class_filter_message_iterator_next_method method
)
178 struct bt_component_class_filter
*filter_class
= NULL
;
181 BT_ASSERT_PRE_NON_NULL(name
, "Name");
182 BT_ASSERT_PRE_NON_NULL(method
, "Message iterator next method");
183 BT_LOGI("Creating filter component class: "
184 "name=\"%s\", msg-iter-next-method-addr=%p",
186 filter_class
= g_new0(struct bt_component_class_filter
, 1);
188 BT_LOGE_STR("Failed to allocate one filter component class.");
192 /* bt_component_class_init() logs errors */
193 ret
= bt_component_class_init(&filter_class
->parent
,
194 BT_COMPONENT_CLASS_TYPE_FILTER
, name
);
197 * If bt_component_class_init() fails, the component
198 * class is put, therefore its memory is already
205 filter_class
->methods
.msg_iter_next
= method
;
206 BT_LIB_LOGI("Created filter component class: %!+C", filter_class
);
209 return (void *) filter_class
;
212 struct bt_component_class_sink
*bt_component_class_sink_create(
213 const char *name
, bt_component_class_sink_consume_method method
)
215 struct bt_component_class_sink
*sink_class
= NULL
;
218 BT_ASSERT_PRE_NON_NULL(name
, "Name");
219 BT_ASSERT_PRE_NON_NULL(method
, "Consume next method");
220 BT_LOGI("Creating sink component class: "
221 "name=\"%s\", consume-method-addr=%p",
223 sink_class
= g_new0(struct bt_component_class_sink
, 1);
225 BT_LOGE_STR("Failed to allocate one sink component class.");
229 /* bt_component_class_init() logs errors */
230 ret
= bt_component_class_init(&sink_class
->parent
,
231 BT_COMPONENT_CLASS_TYPE_SINK
, name
);
234 * If bt_component_class_init() fails, the component
235 * class is put, therefore its memory is already
242 sink_class
->methods
.consume
= method
;
243 BT_LIB_LOGI("Created sink component class: %!+C", sink_class
);
246 return (void *) sink_class
;
249 enum bt_component_class_status
250 bt_component_class_source_set_init_method(
251 struct bt_component_class_source
*comp_cls
,
252 bt_component_class_source_init_method method
)
254 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
255 BT_ASSERT_PRE_NON_NULL(method
, "Method");
256 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
257 comp_cls
->methods
.init
= method
;
258 BT_LIB_LOGD("Set source component class's initialization method: "
260 return BT_COMPONENT_CLASS_STATUS_OK
;
263 enum bt_component_class_status
264 bt_component_class_filter_set_init_method(
265 struct bt_component_class_filter
*comp_cls
,
266 bt_component_class_filter_init_method method
)
268 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
269 BT_ASSERT_PRE_NON_NULL(method
, "Method");
270 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
271 comp_cls
->methods
.init
= method
;
272 BT_LIB_LOGD("Set filter component class's initialization method: "
274 return BT_COMPONENT_CLASS_STATUS_OK
;
277 enum bt_component_class_status
278 bt_component_class_sink_set_init_method(
279 struct bt_component_class_sink
*comp_cls
,
280 bt_component_class_sink_init_method method
)
282 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
283 BT_ASSERT_PRE_NON_NULL(method
, "Method");
284 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
285 comp_cls
->methods
.init
= method
;
286 BT_LIB_LOGD("Set sink component class's initialization method: "
288 return BT_COMPONENT_CLASS_STATUS_OK
;
291 enum bt_component_class_status
292 bt_component_class_source_set_finalize_method(
293 struct bt_component_class_source
*comp_cls
,
294 bt_component_class_source_finalize_method method
)
296 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
297 BT_ASSERT_PRE_NON_NULL(method
, "Method");
298 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
299 comp_cls
->methods
.finalize
= method
;
300 BT_LIB_LOGD("Set source component class's finalization method: "
302 return BT_COMPONENT_CLASS_STATUS_OK
;
305 enum bt_component_class_status
306 bt_component_class_filter_set_finalize_method(
307 struct bt_component_class_filter
*comp_cls
,
308 bt_component_class_filter_finalize_method method
)
310 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
311 BT_ASSERT_PRE_NON_NULL(method
, "Method");
312 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
313 comp_cls
->methods
.finalize
= method
;
314 BT_LIB_LOGD("Set filter component class's finalization method: "
316 return BT_COMPONENT_CLASS_STATUS_OK
;
319 enum bt_component_class_status
320 bt_component_class_sink_set_finalize_method(
321 struct bt_component_class_sink
*comp_cls
,
322 bt_component_class_sink_finalize_method method
)
324 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
325 BT_ASSERT_PRE_NON_NULL(method
, "Method");
326 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
327 comp_cls
->methods
.finalize
= method
;
328 BT_LIB_LOGD("Set sink component class's finalization method: "
330 return BT_COMPONENT_CLASS_STATUS_OK
;
333 enum bt_component_class_status
334 bt_component_class_source_set_query_method(
335 struct bt_component_class_source
*comp_cls
,
336 bt_component_class_source_query_method method
)
338 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
339 BT_ASSERT_PRE_NON_NULL(method
, "Method");
340 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
341 comp_cls
->methods
.query
= method
;
342 BT_LIB_LOGD("Set source component class's query method: "
344 return BT_COMPONENT_CLASS_STATUS_OK
;
347 enum bt_component_class_status
348 bt_component_class_filter_set_query_method(
349 struct bt_component_class_filter
*comp_cls
,
350 bt_component_class_filter_query_method method
)
352 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
353 BT_ASSERT_PRE_NON_NULL(method
, "Method");
354 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
355 comp_cls
->methods
.query
= method
;
356 BT_LIB_LOGD("Set filter component class's query method: "
358 return BT_COMPONENT_CLASS_STATUS_OK
;
361 enum bt_component_class_status
362 bt_component_class_sink_set_query_method(
363 struct bt_component_class_sink
*comp_cls
,
364 bt_component_class_sink_query_method method
)
366 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
367 BT_ASSERT_PRE_NON_NULL(method
, "Method");
368 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
369 comp_cls
->methods
.query
= method
;
370 BT_LIB_LOGD("Set sink component class's query method: "
372 return BT_COMPONENT_CLASS_STATUS_OK
;
375 enum bt_component_class_status
376 bt_component_class_filter_set_input_port_connected_method(
377 struct bt_component_class_filter
*comp_cls
,
378 bt_component_class_filter_input_port_connected_method method
)
380 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
381 BT_ASSERT_PRE_NON_NULL(method
, "Method");
382 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
383 comp_cls
->methods
.input_port_connected
= method
;
384 BT_LIB_LOGD("Set filter component class's \"input port connected\" method"
386 return BT_COMPONENT_CLASS_STATUS_OK
;
389 enum bt_component_class_status
390 bt_component_class_sink_set_input_port_connected_method(
391 struct bt_component_class_sink
*comp_cls
,
392 bt_component_class_sink_input_port_connected_method method
)
394 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
395 BT_ASSERT_PRE_NON_NULL(method
, "Method");
396 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
397 comp_cls
->methods
.input_port_connected
= method
;
398 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
400 return BT_COMPONENT_CLASS_STATUS_OK
;
403 enum bt_component_class_status
404 bt_component_class_source_set_output_port_connected_method(
405 struct bt_component_class_source
*comp_cls
,
406 bt_component_class_source_output_port_connected_method method
)
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
.output_port_connected
= method
;
412 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
414 return BT_COMPONENT_CLASS_STATUS_OK
;
417 enum bt_component_class_status
418 bt_component_class_filter_set_output_port_connected_method(
419 struct bt_component_class_filter
*comp_cls
,
420 bt_component_class_filter_output_port_connected_method method
)
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
.output_port_connected
= method
;
426 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
428 return BT_COMPONENT_CLASS_STATUS_OK
;
431 enum bt_component_class_status
432 bt_component_class_sink_set_graph_is_configured_method(
433 struct bt_component_class_sink
*comp_cls
,
434 bt_component_class_sink_graph_is_configured_method method
)
436 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
437 BT_ASSERT_PRE_NON_NULL(method
, "Method");
438 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
439 comp_cls
->methods
.graph_is_configured
= method
;
440 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
442 return BT_COMPONENT_CLASS_STATUS_OK
;
445 int bt_component_class_source_set_message_iterator_init_method(
446 struct bt_component_class_source
*comp_cls
,
447 bt_component_class_source_message_iterator_init_method method
)
449 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
450 BT_ASSERT_PRE_NON_NULL(method
, "Method");
451 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
452 comp_cls
->methods
.msg_iter_init
= method
;
453 BT_LIB_LOGD("Set source component class's message iterator initialization method"
455 return BT_COMPONENT_CLASS_STATUS_OK
;
458 enum bt_component_class_status
459 bt_component_class_filter_set_message_iterator_init_method(
460 struct bt_component_class_filter
*comp_cls
,
461 bt_component_class_filter_message_iterator_init_method method
)
463 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
464 BT_ASSERT_PRE_NON_NULL(method
, "Method");
465 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
466 comp_cls
->methods
.msg_iter_init
= method
;
467 BT_LIB_LOGD("Set filter component class's message iterator initialization method"
469 return BT_COMPONENT_CLASS_STATUS_OK
;
472 enum bt_component_class_status
473 bt_component_class_source_set_message_iterator_finalize_method(
474 struct bt_component_class_source
*comp_cls
,
475 bt_component_class_source_message_iterator_finalize_method method
)
477 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
478 BT_ASSERT_PRE_NON_NULL(method
, "Method");
479 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
480 comp_cls
->methods
.msg_iter_finalize
= method
;
481 BT_LIB_LOGD("Set source component class's message iterator finalization method"
483 return BT_COMPONENT_CLASS_STATUS_OK
;
486 enum bt_component_class_status
487 bt_component_class_filter_set_message_iterator_finalize_method(
488 struct bt_component_class_filter
*comp_cls
,
489 bt_component_class_filter_message_iterator_finalize_method method
)
491 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
492 BT_ASSERT_PRE_NON_NULL(method
, "Method");
493 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
494 comp_cls
->methods
.msg_iter_finalize
= method
;
495 BT_LIB_LOGD("Set filter component class's message iterator finalization method"
497 return BT_COMPONENT_CLASS_STATUS_OK
;
500 enum bt_component_class_status
501 bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method(
502 struct bt_component_class_filter
*comp_cls
,
503 bt_component_class_filter_message_iterator_seek_ns_from_origin_method method
)
505 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
506 BT_ASSERT_PRE_NON_NULL(method
, "Method");
507 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
508 comp_cls
->methods
.msg_iter_seek_ns_from_origin
= method
;
509 BT_LIB_LOGD("Set filter component class's message iterator \"seek nanoseconds from origin\" method"
511 return BT_COMPONENT_CLASS_STATUS_OK
;
514 enum bt_component_class_status
515 bt_component_class_source_set_message_iterator_seek_ns_from_origin_method(
516 struct bt_component_class_source
*comp_cls
,
517 bt_component_class_source_message_iterator_seek_ns_from_origin_method method
)
519 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
520 BT_ASSERT_PRE_NON_NULL(method
, "Method");
521 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
522 comp_cls
->methods
.msg_iter_seek_ns_from_origin
= method
;
523 BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" method"
525 return BT_COMPONENT_CLASS_STATUS_OK
;
528 enum bt_component_class_status
529 bt_component_class_filter_set_message_iterator_seek_beginning_method(
530 struct bt_component_class_filter
*comp_cls
,
531 bt_component_class_filter_message_iterator_seek_beginning_method method
)
533 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
534 BT_ASSERT_PRE_NON_NULL(method
, "Method");
535 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
536 comp_cls
->methods
.msg_iter_seek_beginning
= method
;
537 BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" method"
539 return BT_COMPONENT_CLASS_STATUS_OK
;
542 enum bt_component_class_status
543 bt_component_class_source_set_message_iterator_seek_beginning_method(
544 struct bt_component_class_source
*comp_cls
,
545 bt_component_class_source_message_iterator_seek_beginning_method method
)
547 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
548 BT_ASSERT_PRE_NON_NULL(method
, "Method");
549 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
550 comp_cls
->methods
.msg_iter_seek_beginning
= method
;
551 BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" method"
553 return BT_COMPONENT_CLASS_STATUS_OK
;
556 enum bt_component_class_status
557 bt_component_class_filter_set_message_iterator_can_seek_beginning_method(
558 struct bt_component_class_filter
*comp_cls
,
559 bt_component_class_filter_message_iterator_can_seek_beginning_method method
)
561 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
562 BT_ASSERT_PRE_NON_NULL(method
, "Method");
563 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
564 comp_cls
->methods
.msg_iter_can_seek_beginning
= method
;
565 BT_LIB_LOGD("Set filter component class's message iterator \"can seek beginning\" method"
567 return BT_COMPONENT_CLASS_STATUS_OK
;
570 enum bt_component_class_status
571 bt_component_class_source_set_message_iterator_can_seek_beginning_method(
572 struct bt_component_class_source
*comp_cls
,
573 bt_component_class_source_message_iterator_can_seek_beginning_method method
)
575 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
576 BT_ASSERT_PRE_NON_NULL(method
, "Method");
577 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
578 comp_cls
->methods
.msg_iter_can_seek_beginning
= method
;
579 BT_LIB_LOGD("Set source component class's message iterator \"can seek beginning\" method"
581 return BT_COMPONENT_CLASS_STATUS_OK
;
584 enum bt_component_class_status
585 bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method(
586 struct bt_component_class_filter
*comp_cls
,
587 bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method method
)
589 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
590 BT_ASSERT_PRE_NON_NULL(method
, "Method");
591 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
592 comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
= method
;
593 BT_LIB_LOGD("Set filter component class's message iterator \"can seek nanoseconds from origin\" method"
595 return BT_COMPONENT_CLASS_STATUS_OK
;
598 enum bt_component_class_status
599 bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method(
600 struct bt_component_class_source
*comp_cls
,
601 bt_component_class_source_message_iterator_can_seek_ns_from_origin_method method
)
603 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
604 BT_ASSERT_PRE_NON_NULL(method
, "Method");
605 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
606 comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
= method
;
607 BT_LIB_LOGD("Set source component class's message iterator \"can seek nanoseconds from origin\" method"
609 return BT_COMPONENT_CLASS_STATUS_OK
;
612 bt_component_class_status
bt_component_class_set_description(
613 struct bt_component_class
*comp_cls
,
614 const char *description
)
616 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
617 BT_ASSERT_PRE_NON_NULL(description
, "Description");
618 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
619 g_string_assign(comp_cls
->description
, description
);
620 BT_LIB_LOGD("Set component class's description: "
621 "addr=%p, name=\"%s\", type=%s",
623 bt_component_class_get_name(comp_cls
),
624 bt_component_class_type_string(comp_cls
->type
));
625 return BT_COMPONENT_CLASS_STATUS_OK
;
628 bt_component_class_status
bt_component_class_set_help(
629 struct bt_component_class
*comp_cls
,
632 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
633 BT_ASSERT_PRE_NON_NULL(help
, "Help");
634 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
635 g_string_assign(comp_cls
->help
, help
);
636 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls
);
637 return BT_COMPONENT_CLASS_STATUS_OK
;
640 const char *bt_component_class_get_name(const struct bt_component_class
*comp_cls
)
642 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
643 return comp_cls
->name
->str
;
646 enum bt_component_class_type
bt_component_class_get_type(
647 const struct bt_component_class
*comp_cls
)
649 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
650 return comp_cls
->type
;
653 const char *bt_component_class_get_description(
654 const struct bt_component_class
*comp_cls
)
656 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
657 return comp_cls
->description
&&
658 comp_cls
->description
->str
[0] != '\0' ?
659 comp_cls
->description
->str
: NULL
;
662 const char *bt_component_class_get_help(
663 const struct bt_component_class
*comp_cls
)
665 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
666 return comp_cls
->help
&&
667 comp_cls
->help
->str
[0] != '\0' ? comp_cls
->help
->str
: NULL
;
671 void bt_component_class_add_destroy_listener(
672 struct bt_component_class
*comp_cls
,
673 bt_component_class_destroy_listener_func func
, void *data
)
675 struct bt_component_class_destroy_listener listener
;
679 listener
.func
= func
;
680 listener
.data
= data
;
681 g_array_append_val(comp_cls
->destroy_listeners
, listener
);
682 BT_LIB_LOGD("Added destroy listener to component class: "
683 "%![cc-]+C, listener-func-addr=%p", comp_cls
, func
);
687 void _bt_component_class_freeze(const struct bt_component_class
*comp_cls
)
690 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls
);
691 ((struct bt_component_class
*) comp_cls
)->frozen
= true;
694 void bt_component_class_get_ref(
695 const struct bt_component_class
*component_class
)
697 bt_object_get_ref(component_class
);
700 void bt_component_class_put_ref(
701 const struct bt_component_class
*component_class
)
703 bt_object_put_ref(component_class
);
706 void bt_component_class_source_get_ref(
707 const struct bt_component_class_source
*component_class_source
)
709 bt_object_get_ref(component_class_source
);
712 void bt_component_class_source_put_ref(
713 const struct bt_component_class_source
*component_class_source
)
715 bt_object_put_ref(component_class_source
);
718 void bt_component_class_filter_get_ref(
719 const struct bt_component_class_filter
*component_class_filter
)
721 bt_object_get_ref(component_class_filter
);
724 void bt_component_class_filter_put_ref(
725 const struct bt_component_class_filter
*component_class_filter
)
727 bt_object_put_ref(component_class_filter
);
730 void bt_component_class_sink_get_ref(
731 const struct bt_component_class_sink
*component_class_sink
)
733 bt_object_get_ref(component_class_sink
);
736 void bt_component_class_sink_put_ref(
737 const struct bt_component_class_sink
*component_class_sink
)
739 bt_object_put_ref(component_class_sink
);