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/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_accept_input_port_connection_method(
377 struct bt_component_class_filter
*comp_cls
,
378 bt_component_class_filter_accept_input_port_connection_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
.accept_input_port_connection
= method
;
384 BT_LIB_LOGD("Set filter component class's \"accept input port connection\" method"
386 return BT_COMPONENT_CLASS_STATUS_OK
;
389 enum bt_component_class_status
390 bt_component_class_sink_set_accept_input_port_connection_method(
391 struct bt_component_class_sink
*comp_cls
,
392 bt_component_class_sink_accept_input_port_connection_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
.accept_input_port_connection
= method
;
398 BT_LIB_LOGD("Set sink component class's \"accept input port connection\" method"
400 return BT_COMPONENT_CLASS_STATUS_OK
;
403 enum bt_component_class_status
404 bt_component_class_source_set_accept_output_port_connection_method(
405 struct bt_component_class_source
*comp_cls
,
406 bt_component_class_source_accept_output_port_connection_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
.accept_output_port_connection
= method
;
412 BT_LIB_LOGD("Set source component class's \"accept output port connection\" method"
414 return BT_COMPONENT_CLASS_STATUS_OK
;
417 enum bt_component_class_status
418 bt_component_class_filter_set_accept_output_port_connection_method(
419 struct bt_component_class_filter
*comp_cls
,
420 bt_component_class_filter_accept_output_port_connection_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
.accept_output_port_connection
= method
;
426 BT_LIB_LOGD("Set filter component class's \"accept output port connection\" method"
428 return BT_COMPONENT_CLASS_STATUS_OK
;
431 enum bt_component_class_status
432 bt_component_class_filter_set_input_port_connected_method(
433 struct bt_component_class_filter
*comp_cls
,
434 bt_component_class_filter_input_port_connected_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
.input_port_connected
= method
;
440 BT_LIB_LOGD("Set filter component class's \"input port connected\" method"
442 return BT_COMPONENT_CLASS_STATUS_OK
;
445 enum bt_component_class_status
446 bt_component_class_sink_set_input_port_connected_method(
447 struct bt_component_class_sink
*comp_cls
,
448 bt_component_class_sink_input_port_connected_method method
)
450 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
451 BT_ASSERT_PRE_NON_NULL(method
, "Method");
452 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
453 comp_cls
->methods
.input_port_connected
= method
;
454 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
456 return BT_COMPONENT_CLASS_STATUS_OK
;
459 enum bt_component_class_status
460 bt_component_class_source_set_output_port_connected_method(
461 struct bt_component_class_source
*comp_cls
,
462 bt_component_class_source_output_port_connected_method method
)
464 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
465 BT_ASSERT_PRE_NON_NULL(method
, "Method");
466 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
467 comp_cls
->methods
.output_port_connected
= method
;
468 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
470 return BT_COMPONENT_CLASS_STATUS_OK
;
473 enum bt_component_class_status
474 bt_component_class_filter_set_output_port_connected_method(
475 struct bt_component_class_filter
*comp_cls
,
476 bt_component_class_filter_output_port_connected_method method
)
478 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
479 BT_ASSERT_PRE_NON_NULL(method
, "Method");
480 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
481 comp_cls
->methods
.output_port_connected
= method
;
482 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
484 return BT_COMPONENT_CLASS_STATUS_OK
;
487 enum bt_component_class_status
488 bt_component_class_sink_set_graph_is_configured_method(
489 struct bt_component_class_sink
*comp_cls
,
490 bt_component_class_sink_graph_is_configured_method method
)
492 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
493 BT_ASSERT_PRE_NON_NULL(method
, "Method");
494 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
495 comp_cls
->methods
.graph_is_configured
= method
;
496 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
498 return BT_COMPONENT_CLASS_STATUS_OK
;
501 int bt_component_class_source_set_message_iterator_init_method(
502 struct bt_component_class_source
*comp_cls
,
503 bt_component_class_source_message_iterator_init_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_init
= method
;
509 BT_LIB_LOGD("Set source component class's message iterator initialization method"
511 return BT_COMPONENT_CLASS_STATUS_OK
;
514 enum bt_component_class_status
515 bt_component_class_filter_set_message_iterator_init_method(
516 struct bt_component_class_filter
*comp_cls
,
517 bt_component_class_filter_message_iterator_init_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_init
= method
;
523 BT_LIB_LOGD("Set filter component class's message iterator initialization method"
525 return BT_COMPONENT_CLASS_STATUS_OK
;
528 enum bt_component_class_status
529 bt_component_class_source_set_message_iterator_finalize_method(
530 struct bt_component_class_source
*comp_cls
,
531 bt_component_class_source_message_iterator_finalize_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_finalize
= method
;
537 BT_LIB_LOGD("Set source component class's message iterator finalization method"
539 return BT_COMPONENT_CLASS_STATUS_OK
;
542 enum bt_component_class_status
543 bt_component_class_filter_set_message_iterator_finalize_method(
544 struct bt_component_class_filter
*comp_cls
,
545 bt_component_class_filter_message_iterator_finalize_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_finalize
= method
;
551 BT_LIB_LOGD("Set filter component class's message iterator finalization method"
553 return BT_COMPONENT_CLASS_STATUS_OK
;
556 enum bt_component_class_status
557 bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method(
558 struct bt_component_class_filter
*comp_cls
,
559 bt_component_class_filter_message_iterator_seek_ns_from_origin_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_seek_ns_from_origin
= method
;
565 BT_LIB_LOGD("Set filter component class's message iterator \"seek nanoseconds from origin\" method"
567 return BT_COMPONENT_CLASS_STATUS_OK
;
570 enum bt_component_class_status
571 bt_component_class_source_set_message_iterator_seek_ns_from_origin_method(
572 struct bt_component_class_source
*comp_cls
,
573 bt_component_class_source_message_iterator_seek_ns_from_origin_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_seek_ns_from_origin
= method
;
579 BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" method"
581 return BT_COMPONENT_CLASS_STATUS_OK
;
584 enum bt_component_class_status
585 bt_component_class_filter_set_message_iterator_seek_beginning_method(
586 struct bt_component_class_filter
*comp_cls
,
587 bt_component_class_filter_message_iterator_seek_beginning_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_seek_beginning
= method
;
593 BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" method"
595 return BT_COMPONENT_CLASS_STATUS_OK
;
598 enum bt_component_class_status
599 bt_component_class_source_set_message_iterator_seek_beginning_method(
600 struct bt_component_class_source
*comp_cls
,
601 bt_component_class_source_message_iterator_seek_beginning_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_seek_beginning
= method
;
607 BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" method"
609 return BT_COMPONENT_CLASS_STATUS_OK
;
612 enum bt_component_class_status
613 bt_component_class_filter_set_message_iterator_can_seek_beginning_method(
614 struct bt_component_class_filter
*comp_cls
,
615 bt_component_class_filter_message_iterator_can_seek_beginning_method method
)
617 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
618 BT_ASSERT_PRE_NON_NULL(method
, "Method");
619 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
620 comp_cls
->methods
.msg_iter_can_seek_beginning
= method
;
621 BT_LIB_LOGD("Set filter component class's message iterator \"can seek beginning\" method"
623 return BT_COMPONENT_CLASS_STATUS_OK
;
626 enum bt_component_class_status
627 bt_component_class_source_set_message_iterator_can_seek_beginning_method(
628 struct bt_component_class_source
*comp_cls
,
629 bt_component_class_source_message_iterator_can_seek_beginning_method method
)
631 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
632 BT_ASSERT_PRE_NON_NULL(method
, "Method");
633 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
634 comp_cls
->methods
.msg_iter_can_seek_beginning
= method
;
635 BT_LIB_LOGD("Set source component class's message iterator \"can seek beginning\" method"
637 return BT_COMPONENT_CLASS_STATUS_OK
;
640 enum bt_component_class_status
641 bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method(
642 struct bt_component_class_filter
*comp_cls
,
643 bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method method
)
645 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
646 BT_ASSERT_PRE_NON_NULL(method
, "Method");
647 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
648 comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
= method
;
649 BT_LIB_LOGD("Set filter component class's message iterator \"can seek nanoseconds from origin\" method"
651 return BT_COMPONENT_CLASS_STATUS_OK
;
654 enum bt_component_class_status
655 bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method(
656 struct bt_component_class_source
*comp_cls
,
657 bt_component_class_source_message_iterator_can_seek_ns_from_origin_method method
)
659 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
660 BT_ASSERT_PRE_NON_NULL(method
, "Method");
661 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
662 comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
= method
;
663 BT_LIB_LOGD("Set source component class's message iterator \"can seek nanoseconds from origin\" method"
665 return BT_COMPONENT_CLASS_STATUS_OK
;
668 bt_component_class_status
bt_component_class_set_description(
669 struct bt_component_class
*comp_cls
,
670 const char *description
)
672 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
673 BT_ASSERT_PRE_NON_NULL(description
, "Description");
674 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
675 g_string_assign(comp_cls
->description
, description
);
676 BT_LIB_LOGD("Set component class's description: "
677 "addr=%p, name=\"%s\", type=%s",
679 bt_component_class_get_name(comp_cls
),
680 bt_component_class_type_string(comp_cls
->type
));
681 return BT_COMPONENT_CLASS_STATUS_OK
;
684 bt_component_class_status
bt_component_class_set_help(
685 struct bt_component_class
*comp_cls
,
688 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
689 BT_ASSERT_PRE_NON_NULL(help
, "Help");
690 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
691 g_string_assign(comp_cls
->help
, help
);
692 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls
);
693 return BT_COMPONENT_CLASS_STATUS_OK
;
696 const char *bt_component_class_get_name(const struct bt_component_class
*comp_cls
)
698 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
699 return comp_cls
->name
->str
;
702 enum bt_component_class_type
bt_component_class_get_type(
703 const struct bt_component_class
*comp_cls
)
705 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
706 return comp_cls
->type
;
709 const char *bt_component_class_get_description(
710 const struct bt_component_class
*comp_cls
)
712 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
713 return comp_cls
->description
&&
714 comp_cls
->description
->str
[0] != '\0' ?
715 comp_cls
->description
->str
: NULL
;
718 const char *bt_component_class_get_help(
719 const struct bt_component_class
*comp_cls
)
721 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
722 return comp_cls
->help
&&
723 comp_cls
->help
->str
[0] != '\0' ? comp_cls
->help
->str
: NULL
;
727 void bt_component_class_add_destroy_listener(
728 struct bt_component_class
*comp_cls
,
729 bt_component_class_destroy_listener_func func
, void *data
)
731 struct bt_component_class_destroy_listener listener
;
735 listener
.func
= func
;
736 listener
.data
= data
;
737 g_array_append_val(comp_cls
->destroy_listeners
, listener
);
738 BT_LIB_LOGD("Added destroy listener to component class: "
739 "%![cc-]+C, listener-func-addr=%p", comp_cls
, func
);
743 void _bt_component_class_freeze(const struct bt_component_class
*comp_cls
)
746 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls
);
747 ((struct bt_component_class
*) comp_cls
)->frozen
= true;
750 void bt_component_class_get_ref(
751 const struct bt_component_class
*component_class
)
753 bt_object_get_ref(component_class
);
756 void bt_component_class_put_ref(
757 const struct bt_component_class
*component_class
)
759 bt_object_put_ref(component_class
);
762 void bt_component_class_source_get_ref(
763 const struct bt_component_class_source
*component_class_source
)
765 bt_object_get_ref(component_class_source
);
768 void bt_component_class_source_put_ref(
769 const struct bt_component_class_source
*component_class_source
)
771 bt_object_put_ref(component_class_source
);
774 void bt_component_class_filter_get_ref(
775 const struct bt_component_class_filter
*component_class_filter
)
777 bt_object_get_ref(component_class_filter
);
780 void bt_component_class_filter_put_ref(
781 const struct bt_component_class_filter
*component_class_filter
)
783 bt_object_put_ref(component_class_filter
);
786 void bt_component_class_sink_get_ref(
787 const struct bt_component_class_sink
*component_class_sink
)
789 bt_object_get_ref(component_class_sink
);
792 void bt_component_class_sink_put_ref(
793 const struct bt_component_class_sink
*component_class_sink
)
795 bt_object_put_ref(component_class_sink
);