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_DEV_COMP_CLS_HOT(_cc) \
45 BT_ASSERT_PRE_DEV_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_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
113 class->description
= g_string_new(NULL
);
114 if (!class->description
) {
115 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
119 class->help
= g_string_new(NULL
);
121 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
125 class->plugin_name
= g_string_new(NULL
);
126 if (!class->plugin_name
) {
127 BT_LIB_LOGE_APPEND_CAUSE("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_LIB_LOGE_APPEND_CAUSE("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_NO_ERROR();
156 BT_ASSERT_PRE_NON_NULL(name
, "Name");
157 BT_ASSERT_PRE_NON_NULL(method
, "Message iterator next method");
158 BT_LOGI("Creating source component class: "
159 "name=\"%s\", msg-iter-next-method-addr=%p",
161 source_class
= g_new0(struct bt_component_class_source
, 1);
163 BT_LIB_LOGE_APPEND_CAUSE(
164 "Failed to allocate one source component class.");
168 /* bt_component_class_init() logs errors */
169 ret
= bt_component_class_init(&source_class
->parent
,
170 BT_COMPONENT_CLASS_TYPE_SOURCE
, name
);
173 * If bt_component_class_init() fails, the component
174 * class is put, therefore its memory is already
181 source_class
->methods
.msg_iter_next
= method
;
182 BT_LIB_LOGI("Created source component class: %!+C", source_class
);
185 return (void *) source_class
;
188 struct bt_component_class_filter
*bt_component_class_filter_create(
190 bt_component_class_filter_message_iterator_next_method method
)
192 struct bt_component_class_filter
*filter_class
= NULL
;
195 BT_ASSERT_PRE_NO_ERROR();
196 BT_ASSERT_PRE_NON_NULL(name
, "Name");
197 BT_ASSERT_PRE_NON_NULL(method
, "Message iterator next method");
198 BT_LOGI("Creating filter component class: "
199 "name=\"%s\", msg-iter-next-method-addr=%p",
201 filter_class
= g_new0(struct bt_component_class_filter
, 1);
203 BT_LIB_LOGE_APPEND_CAUSE(
204 "Failed to allocate one filter component class.");
208 /* bt_component_class_init() logs errors */
209 ret
= bt_component_class_init(&filter_class
->parent
,
210 BT_COMPONENT_CLASS_TYPE_FILTER
, name
);
213 * If bt_component_class_init() fails, the component
214 * class is put, therefore its memory is already
221 filter_class
->methods
.msg_iter_next
= method
;
222 BT_LIB_LOGI("Created filter component class: %!+C", filter_class
);
225 return (void *) filter_class
;
228 struct bt_component_class_sink
*bt_component_class_sink_create(
229 const char *name
, bt_component_class_sink_consume_method method
)
231 struct bt_component_class_sink
*sink_class
= NULL
;
234 BT_ASSERT_PRE_NO_ERROR();
235 BT_ASSERT_PRE_NON_NULL(name
, "Name");
236 BT_ASSERT_PRE_NON_NULL(method
, "Consume next method");
237 BT_LOGI("Creating sink component class: "
238 "name=\"%s\", consume-method-addr=%p",
240 sink_class
= g_new0(struct bt_component_class_sink
, 1);
242 BT_LIB_LOGE_APPEND_CAUSE(
243 "Failed to allocate one sink component class.");
247 /* bt_component_class_init() logs errors */
248 ret
= bt_component_class_init(&sink_class
->parent
,
249 BT_COMPONENT_CLASS_TYPE_SINK
, name
);
252 * If bt_component_class_init() fails, the component
253 * class is put, therefore its memory is already
260 sink_class
->methods
.consume
= method
;
261 BT_LIB_LOGI("Created sink component class: %!+C", sink_class
);
264 return (void *) sink_class
;
267 enum bt_component_class_set_method_status
268 bt_component_class_source_set_get_supported_mip_versions_method(
269 struct bt_component_class_source
*comp_cls
,
270 bt_component_class_source_get_supported_mip_versions_method method
)
272 BT_ASSERT_PRE_NO_ERROR();
273 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
274 BT_ASSERT_PRE_NON_NULL(method
, "Method");
275 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
276 comp_cls
->methods
.get_supported_mip_versions
= method
;
277 BT_LIB_LOGD("Set source component class's \"get supported MIP versions\" method: "
279 return BT_FUNC_STATUS_OK
;
282 enum bt_component_class_set_method_status
283 bt_component_class_filter_set_get_supported_mip_versions_method(
284 struct bt_component_class_filter
*comp_cls
,
285 bt_component_class_filter_get_supported_mip_versions_method method
)
287 BT_ASSERT_PRE_NO_ERROR();
288 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
289 BT_ASSERT_PRE_NON_NULL(method
, "Method");
290 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
291 comp_cls
->methods
.get_supported_mip_versions
= method
;
292 BT_LIB_LOGD("Set filter component class's \"get supported MIP versions\" method: "
294 return BT_FUNC_STATUS_OK
;
297 enum bt_component_class_set_method_status
298 bt_component_class_sink_set_get_supported_mip_versions_method(
299 struct bt_component_class_sink
*comp_cls
,
300 bt_component_class_sink_get_supported_mip_versions_method method
)
302 BT_ASSERT_PRE_NO_ERROR();
303 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
304 BT_ASSERT_PRE_NON_NULL(method
, "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 sink component class's \"get supported MIP versions\" method: "
309 return BT_FUNC_STATUS_OK
;
312 enum bt_component_class_set_method_status
313 bt_component_class_source_set_initialize_method(
314 struct bt_component_class_source
*comp_cls
,
315 bt_component_class_source_initialize_method method
)
317 BT_ASSERT_PRE_NO_ERROR();
318 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
319 BT_ASSERT_PRE_NON_NULL(method
, "Method");
320 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
321 comp_cls
->methods
.init
= method
;
322 BT_LIB_LOGD("Set source component class's initialization method: "
324 return BT_FUNC_STATUS_OK
;
327 enum bt_component_class_set_method_status
328 bt_component_class_filter_set_initialize_method(
329 struct bt_component_class_filter
*comp_cls
,
330 bt_component_class_filter_initialize_method method
)
332 BT_ASSERT_PRE_NO_ERROR();
333 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
334 BT_ASSERT_PRE_NON_NULL(method
, "Method");
335 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
336 comp_cls
->methods
.init
= method
;
337 BT_LIB_LOGD("Set filter component class's initialization method: "
339 return BT_FUNC_STATUS_OK
;
342 enum bt_component_class_set_method_status
343 bt_component_class_sink_set_initialize_method(
344 struct bt_component_class_sink
*comp_cls
,
345 bt_component_class_sink_initialize_method method
)
347 BT_ASSERT_PRE_NO_ERROR();
348 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
349 BT_ASSERT_PRE_NON_NULL(method
, "Method");
350 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
351 comp_cls
->methods
.init
= method
;
352 BT_LIB_LOGD("Set sink component class's initialization method: "
354 return BT_FUNC_STATUS_OK
;
357 enum bt_component_class_set_method_status
358 bt_component_class_source_set_finalize_method(
359 struct bt_component_class_source
*comp_cls
,
360 bt_component_class_source_finalize_method method
)
362 BT_ASSERT_PRE_NO_ERROR();
363 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
364 BT_ASSERT_PRE_NON_NULL(method
, "Method");
365 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
366 comp_cls
->methods
.finalize
= method
;
367 BT_LIB_LOGD("Set source component class's finalization method: "
369 return BT_FUNC_STATUS_OK
;
372 enum bt_component_class_set_method_status
373 bt_component_class_filter_set_finalize_method(
374 struct bt_component_class_filter
*comp_cls
,
375 bt_component_class_filter_finalize_method method
)
377 BT_ASSERT_PRE_NO_ERROR();
378 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
379 BT_ASSERT_PRE_NON_NULL(method
, "Method");
380 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
381 comp_cls
->methods
.finalize
= method
;
382 BT_LIB_LOGD("Set filter component class's finalization method: "
384 return BT_FUNC_STATUS_OK
;
387 enum bt_component_class_set_method_status
388 bt_component_class_sink_set_finalize_method(
389 struct bt_component_class_sink
*comp_cls
,
390 bt_component_class_sink_finalize_method method
)
392 BT_ASSERT_PRE_NO_ERROR();
393 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
394 BT_ASSERT_PRE_NON_NULL(method
, "Method");
395 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
396 comp_cls
->methods
.finalize
= method
;
397 BT_LIB_LOGD("Set sink component class's finalization method: "
399 return BT_FUNC_STATUS_OK
;
402 enum bt_component_class_set_method_status
403 bt_component_class_source_set_query_method(
404 struct bt_component_class_source
*comp_cls
,
405 bt_component_class_source_query_method method
)
407 BT_ASSERT_PRE_NO_ERROR();
408 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
409 BT_ASSERT_PRE_NON_NULL(method
, "Method");
410 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
411 comp_cls
->methods
.query
= method
;
412 BT_LIB_LOGD("Set source component class's query method: "
414 return BT_FUNC_STATUS_OK
;
417 enum bt_component_class_set_method_status
418 bt_component_class_filter_set_query_method(
419 struct bt_component_class_filter
*comp_cls
,
420 bt_component_class_filter_query_method method
)
422 BT_ASSERT_PRE_NO_ERROR();
423 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
424 BT_ASSERT_PRE_NON_NULL(method
, "Method");
425 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
426 comp_cls
->methods
.query
= method
;
427 BT_LIB_LOGD("Set filter component class's query method: "
429 return BT_FUNC_STATUS_OK
;
432 enum bt_component_class_set_method_status
433 bt_component_class_sink_set_query_method(
434 struct bt_component_class_sink
*comp_cls
,
435 bt_component_class_sink_query_method method
)
437 BT_ASSERT_PRE_NO_ERROR();
438 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
439 BT_ASSERT_PRE_NON_NULL(method
, "Method");
440 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
441 comp_cls
->methods
.query
= method
;
442 BT_LIB_LOGD("Set sink component class's query method: "
444 return BT_FUNC_STATUS_OK
;
447 enum bt_component_class_set_method_status
448 bt_component_class_filter_set_input_port_connected_method(
449 struct bt_component_class_filter
*comp_cls
,
450 bt_component_class_filter_input_port_connected_method method
)
452 BT_ASSERT_PRE_NO_ERROR();
453 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
454 BT_ASSERT_PRE_NON_NULL(method
, "Method");
455 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
456 comp_cls
->methods
.input_port_connected
= method
;
457 BT_LIB_LOGD("Set filter component class's \"input port connected\" method"
459 return BT_FUNC_STATUS_OK
;
462 enum bt_component_class_set_method_status
463 bt_component_class_sink_set_input_port_connected_method(
464 struct bt_component_class_sink
*comp_cls
,
465 bt_component_class_sink_input_port_connected_method method
)
467 BT_ASSERT_PRE_NO_ERROR();
468 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
469 BT_ASSERT_PRE_NON_NULL(method
, "Method");
470 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
471 comp_cls
->methods
.input_port_connected
= method
;
472 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
474 return BT_FUNC_STATUS_OK
;
477 enum bt_component_class_set_method_status
478 bt_component_class_source_set_output_port_connected_method(
479 struct bt_component_class_source
*comp_cls
,
480 bt_component_class_source_output_port_connected_method method
)
482 BT_ASSERT_PRE_NO_ERROR();
483 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
484 BT_ASSERT_PRE_NON_NULL(method
, "Method");
485 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
486 comp_cls
->methods
.output_port_connected
= method
;
487 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
489 return BT_FUNC_STATUS_OK
;
492 enum bt_component_class_set_method_status
493 bt_component_class_filter_set_output_port_connected_method(
494 struct bt_component_class_filter
*comp_cls
,
495 bt_component_class_filter_output_port_connected_method method
)
497 BT_ASSERT_PRE_NO_ERROR();
498 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
499 BT_ASSERT_PRE_NON_NULL(method
, "Method");
500 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
501 comp_cls
->methods
.output_port_connected
= method
;
502 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
504 return BT_FUNC_STATUS_OK
;
507 enum bt_component_class_set_method_status
508 bt_component_class_sink_set_graph_is_configured_method(
509 struct bt_component_class_sink
*comp_cls
,
510 bt_component_class_sink_graph_is_configured_method method
)
512 BT_ASSERT_PRE_NO_ERROR();
513 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
514 BT_ASSERT_PRE_NON_NULL(method
, "Method");
515 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
516 comp_cls
->methods
.graph_is_configured
= method
;
517 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
519 return BT_FUNC_STATUS_OK
;
522 enum bt_component_class_set_method_status
523 bt_component_class_source_set_message_iterator_initialize_method(
524 struct bt_component_class_source
*comp_cls
,
525 bt_component_class_source_message_iterator_initialize_method method
)
527 BT_ASSERT_PRE_NO_ERROR();
528 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
529 BT_ASSERT_PRE_NON_NULL(method
, "Method");
530 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
531 comp_cls
->methods
.msg_iter_initialize
= method
;
532 BT_LIB_LOGD("Set source component class's message iterator initialization method"
534 return BT_FUNC_STATUS_OK
;
537 enum bt_component_class_set_method_status
538 bt_component_class_filter_set_message_iterator_initialize_method(
539 struct bt_component_class_filter
*comp_cls
,
540 bt_component_class_filter_message_iterator_initialize_method method
)
542 BT_ASSERT_PRE_NO_ERROR();
543 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
544 BT_ASSERT_PRE_NON_NULL(method
, "Method");
545 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
546 comp_cls
->methods
.msg_iter_initialize
= method
;
547 BT_LIB_LOGD("Set filter component class's message iterator initialization method"
549 return BT_FUNC_STATUS_OK
;
552 enum bt_component_class_set_method_status
553 bt_component_class_source_set_message_iterator_finalize_method(
554 struct bt_component_class_source
*comp_cls
,
555 bt_component_class_source_message_iterator_finalize_method method
)
557 BT_ASSERT_PRE_NO_ERROR();
558 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
559 BT_ASSERT_PRE_NON_NULL(method
, "Method");
560 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
561 comp_cls
->methods
.msg_iter_finalize
= method
;
562 BT_LIB_LOGD("Set source component class's message iterator finalization method"
564 return BT_FUNC_STATUS_OK
;
567 enum bt_component_class_set_method_status
568 bt_component_class_filter_set_message_iterator_finalize_method(
569 struct bt_component_class_filter
*comp_cls
,
570 bt_component_class_filter_message_iterator_finalize_method method
)
572 BT_ASSERT_PRE_NO_ERROR();
573 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
574 BT_ASSERT_PRE_NON_NULL(method
, "Method");
575 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
576 comp_cls
->methods
.msg_iter_finalize
= method
;
577 BT_LIB_LOGD("Set filter component class's message iterator finalization method"
579 return BT_FUNC_STATUS_OK
;
582 enum bt_component_class_set_method_status
583 bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods(
584 struct bt_component_class_filter
*comp_cls
,
585 bt_component_class_filter_message_iterator_seek_ns_from_origin_method seek_method
,
586 bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method can_seek_method
)
588 BT_ASSERT_PRE_NO_ERROR();
589 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
590 BT_ASSERT_PRE_NON_NULL(seek_method
, "Seek method");
591 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
592 comp_cls
->methods
.msg_iter_seek_ns_from_origin
= seek_method
;
593 comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
= can_seek_method
;
594 BT_LIB_LOGD("Set filter component class's message iterator \"seek nanoseconds from origin\" method"
596 return BT_FUNC_STATUS_OK
;
599 enum bt_component_class_set_method_status
600 bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods(
601 struct bt_component_class_source
*comp_cls
,
602 bt_component_class_source_message_iterator_seek_ns_from_origin_method seek_method
,
603 bt_component_class_source_message_iterator_can_seek_ns_from_origin_method can_seek_method
)
605 BT_ASSERT_PRE_NO_ERROR();
606 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
607 BT_ASSERT_PRE_NON_NULL(seek_method
, "Seek method");
608 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
609 comp_cls
->methods
.msg_iter_seek_ns_from_origin
= seek_method
;
610 comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
= can_seek_method
;
611 BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" methods"
613 return BT_FUNC_STATUS_OK
;
616 enum bt_component_class_set_method_status
617 bt_component_class_filter_set_message_iterator_seek_beginning_methods(
618 struct bt_component_class_filter
*comp_cls
,
619 bt_component_class_filter_message_iterator_seek_beginning_method seek_method
,
620 bt_component_class_filter_message_iterator_can_seek_beginning_method can_seek_method
)
622 BT_ASSERT_PRE_NO_ERROR();
623 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
624 BT_ASSERT_PRE_NON_NULL(seek_method
, "Seek method");
625 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
626 comp_cls
->methods
.msg_iter_seek_beginning
= seek_method
;
627 comp_cls
->methods
.msg_iter_can_seek_beginning
= can_seek_method
;
628 BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" methods"
630 return BT_FUNC_STATUS_OK
;
633 enum bt_component_class_set_method_status
634 bt_component_class_source_set_message_iterator_seek_beginning_methods(
635 struct bt_component_class_source
*comp_cls
,
636 bt_component_class_source_message_iterator_seek_beginning_method seek_method
,
637 bt_component_class_source_message_iterator_can_seek_beginning_method can_seek_method
)
639 BT_ASSERT_PRE_NO_ERROR();
640 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
641 BT_ASSERT_PRE_NON_NULL(seek_method
, "Seek method");
642 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
643 comp_cls
->methods
.msg_iter_seek_beginning
= seek_method
;
644 comp_cls
->methods
.msg_iter_can_seek_beginning
= can_seek_method
;
645 BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" methods"
647 return BT_FUNC_STATUS_OK
;
650 enum bt_component_class_set_description_status
651 bt_component_class_set_description(
652 struct bt_component_class
*comp_cls
,
653 const char *description
)
655 BT_ASSERT_PRE_NO_ERROR();
656 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
657 BT_ASSERT_PRE_NON_NULL(description
, "Description");
658 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
659 g_string_assign(comp_cls
->description
, description
);
660 BT_LIB_LOGD("Set component class's description: "
661 "addr=%p, name=\"%s\", type=%s",
663 bt_component_class_get_name(comp_cls
),
664 bt_component_class_type_string(comp_cls
->type
));
665 return BT_FUNC_STATUS_OK
;
668 enum bt_component_class_set_help_status
bt_component_class_set_help(
669 struct bt_component_class
*comp_cls
,
672 BT_ASSERT_PRE_NO_ERROR();
673 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
674 BT_ASSERT_PRE_NON_NULL(help
, "Help");
675 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls
);
676 g_string_assign(comp_cls
->help
, help
);
677 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls
);
678 return BT_FUNC_STATUS_OK
;
681 const char *bt_component_class_get_name(const struct bt_component_class
*comp_cls
)
683 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls
, "Component class");
684 return comp_cls
->name
->str
;
687 enum bt_component_class_type
bt_component_class_get_type(
688 const struct bt_component_class
*comp_cls
)
690 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls
, "Component class");
691 return comp_cls
->type
;
694 const char *bt_component_class_get_description(
695 const struct bt_component_class
*comp_cls
)
697 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls
, "Component class");
698 return comp_cls
->description
&&
699 comp_cls
->description
->str
[0] != '\0' ?
700 comp_cls
->description
->str
: NULL
;
703 const char *bt_component_class_get_help(
704 const struct bt_component_class
*comp_cls
)
706 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls
, "Component class");
707 return comp_cls
->help
&&
708 comp_cls
->help
->str
[0] != '\0' ? comp_cls
->help
->str
: NULL
;
712 void bt_component_class_add_destroy_listener(
713 struct bt_component_class
*comp_cls
,
714 bt_component_class_destroy_listener_func func
, void *data
)
716 struct bt_component_class_destroy_listener listener
;
720 listener
.func
= func
;
721 listener
.data
= data
;
722 g_array_append_val(comp_cls
->destroy_listeners
, listener
);
723 BT_LIB_LOGD("Added destroy listener to component class: "
724 "%![cc-]+C, listener-func-addr=%p", comp_cls
, func
);
728 void _bt_component_class_freeze(const struct bt_component_class
*comp_cls
)
731 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls
);
732 ((struct bt_component_class
*) comp_cls
)->frozen
= true;
735 void bt_component_class_get_ref(
736 const struct bt_component_class
*component_class
)
738 bt_object_get_ref(component_class
);
741 void bt_component_class_put_ref(
742 const struct bt_component_class
*component_class
)
744 bt_object_put_ref(component_class
);
747 void bt_component_class_source_get_ref(
748 const struct bt_component_class_source
*component_class_source
)
750 bt_object_get_ref(component_class_source
);
753 void bt_component_class_source_put_ref(
754 const struct bt_component_class_source
*component_class_source
)
756 bt_object_put_ref(component_class_source
);
759 void bt_component_class_filter_get_ref(
760 const struct bt_component_class_filter
*component_class_filter
)
762 bt_object_get_ref(component_class_filter
);
765 void bt_component_class_filter_put_ref(
766 const struct bt_component_class_filter
*component_class_filter
)
768 bt_object_put_ref(component_class_filter
);
771 void bt_component_class_sink_get_ref(
772 const struct bt_component_class_sink
*component_class_sink
)
774 bt_object_get_ref(component_class_sink
);
777 void bt_component_class_sink_put_ref(
778 const struct bt_component_class_sink
*component_class_sink
)
780 bt_object_put_ref(component_class_sink
);