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 "COMP-CLASS"
25 #include <babeltrace/lib-logging-internal.h>
27 #include <babeltrace/assert-internal.h>
28 #include <babeltrace/assert-pre-internal.h>
29 #include <babeltrace/compiler-internal.h>
30 #include <babeltrace/graph/component-class.h>
31 #include <babeltrace/graph/component-class-const.h>
32 #include <babeltrace/graph/component-class-source.h>
33 #include <babeltrace/graph/component-class-source-const.h>
34 #include <babeltrace/graph/component-class-filter.h>
35 #include <babeltrace/graph/component-class-filter-const.h>
36 #include <babeltrace/graph/component-class-sink.h>
37 #include <babeltrace/graph/component-class-sink-const.h>
38 #include <babeltrace/graph/component-class-internal.h>
39 #include <babeltrace/types.h>
42 #define BT_ASSERT_PRE_COMP_CLS_HOT(_cc) \
43 BT_ASSERT_PRE_HOT(((const struct bt_component_class *) (_cc)), \
44 "Component class", ": %!+C", (_cc))
47 void destroy_component_class(struct bt_object
*obj
)
49 struct bt_component_class
*class;
53 class = container_of(obj
, struct bt_component_class
, base
);
55 BT_LIB_LOGD("Destroying component class: %!+C", class);
57 /* Call destroy listeners in reverse registration order */
58 for (i
= class->destroy_listeners
->len
- 1; i
>= 0; i
--) {
59 struct bt_component_class_destroy_listener
*listener
=
60 &g_array_index(class->destroy_listeners
,
61 struct bt_component_class_destroy_listener
,
64 BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p",
65 listener
->func
, listener
->data
);
66 listener
->func(class, listener
->data
);
70 g_string_free(class->name
, TRUE
);
74 if (class->description
) {
75 g_string_free(class->description
, TRUE
);
76 class->description
= NULL
;
80 g_string_free(class->help
, TRUE
);
84 if (class->destroy_listeners
) {
85 g_array_free(class->destroy_listeners
, TRUE
);
86 class->destroy_listeners
= NULL
;
93 int bt_component_class_init(struct bt_component_class
*class,
94 enum bt_component_class_type type
, const char *name
)
98 bt_object_init_shared(&class->base
, destroy_component_class
);
100 class->name
= g_string_new(name
);
102 BT_LOGE_STR("Failed to allocate a GString.");
106 class->description
= g_string_new(NULL
);
107 if (!class->description
) {
108 BT_LOGE_STR("Failed to allocate a GString.");
112 class->help
= g_string_new(NULL
);
114 BT_LOGE_STR("Failed to allocate a GString.");
118 class->destroy_listeners
= g_array_new(FALSE
, TRUE
,
119 sizeof(struct bt_component_class_destroy_listener
));
120 if (!class->destroy_listeners
) {
121 BT_LOGE_STR("Failed to allocate a GArray.");
128 BT_OBJECT_PUT_REF_AND_RESET(class);
135 struct bt_component_class_source
*bt_component_class_source_create(
137 bt_component_class_source_message_iterator_next_method method
)
139 struct bt_component_class_source
*source_class
= NULL
;
142 BT_ASSERT_PRE_NON_NULL(name
, "Name");
143 BT_ASSERT_PRE_NON_NULL(method
, "Message iterator next method");
144 BT_LOGD("Creating source component class: "
145 "name=\"%s\", msg-iter-next-method-addr=%p",
147 source_class
= g_new0(struct bt_component_class_source
, 1);
149 BT_LOGE_STR("Failed to allocate one source component class.");
153 /* bt_component_class_init() logs errors */
154 ret
= bt_component_class_init(&source_class
->parent
,
155 BT_COMPONENT_CLASS_TYPE_SOURCE
, name
);
158 * If bt_component_class_init() fails, the component
159 * class is put, therefore its memory is already
166 source_class
->methods
.msg_iter_next
= method
;
167 BT_LIB_LOGD("Created source component class: %!+C", source_class
);
170 return (void *) source_class
;
173 struct bt_component_class_filter
*bt_component_class_filter_create(
175 bt_component_class_filter_message_iterator_next_method method
)
177 struct bt_component_class_filter
*filter_class
= NULL
;
180 BT_ASSERT_PRE_NON_NULL(name
, "Name");
181 BT_ASSERT_PRE_NON_NULL(method
, "Message iterator next method");
182 BT_LOGD("Creating filter component class: "
183 "name=\"%s\", msg-iter-next-method-addr=%p",
185 filter_class
= g_new0(struct bt_component_class_filter
, 1);
187 BT_LOGE_STR("Failed to allocate one filter component class.");
191 /* bt_component_class_init() logs errors */
192 ret
= bt_component_class_init(&filter_class
->parent
,
193 BT_COMPONENT_CLASS_TYPE_FILTER
, name
);
196 * If bt_component_class_init() fails, the component
197 * class is put, therefore its memory is already
204 filter_class
->methods
.msg_iter_next
= method
;
205 BT_LIB_LOGD("Created filter component class: %!+C", filter_class
);
208 return (void *) filter_class
;
211 struct bt_component_class_sink
*bt_component_class_sink_create(
212 const char *name
, bt_component_class_sink_consume_method method
)
214 struct bt_component_class_sink
*sink_class
= NULL
;
217 BT_ASSERT_PRE_NON_NULL(name
, "Name");
218 BT_ASSERT_PRE_NON_NULL(method
, "Consume next method");
219 BT_LOGD("Creating sink component class: "
220 "name=\"%s\", consume-method-addr=%p",
222 sink_class
= g_new0(struct bt_component_class_sink
, 1);
224 BT_LOGE_STR("Failed to allocate one sink component class.");
228 /* bt_component_class_init() logs errors */
229 ret
= bt_component_class_init(&sink_class
->parent
,
230 BT_COMPONENT_CLASS_TYPE_SINK
, name
);
233 * If bt_component_class_init() fails, the component
234 * class is put, therefore its memory is already
241 sink_class
->methods
.consume
= method
;
242 BT_LIB_LOGD("Created sink component class: %!+C", sink_class
);
245 return (void *) sink_class
;
248 enum bt_component_class_status
249 bt_component_class_source_set_init_method(
250 struct bt_component_class_source
*comp_cls
,
251 bt_component_class_source_init_method method
)
253 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
254 BT_ASSERT_PRE_NON_NULL(method
, "Method");
255 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
256 comp_cls
->methods
.init
= method
;
257 BT_LIB_LOGV("Set source component class's initialization method: "
259 return BT_COMPONENT_CLASS_STATUS_OK
;
262 enum bt_component_class_status
263 bt_component_class_filter_set_init_method(
264 struct bt_component_class_filter
*comp_cls
,
265 bt_component_class_filter_init_method method
)
267 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
268 BT_ASSERT_PRE_NON_NULL(method
, "Method");
269 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
270 comp_cls
->methods
.init
= method
;
271 BT_LIB_LOGV("Set filter component class's initialization method: "
273 return BT_COMPONENT_CLASS_STATUS_OK
;
276 enum bt_component_class_status
277 bt_component_class_sink_set_init_method(
278 struct bt_component_class_sink
*comp_cls
,
279 bt_component_class_sink_init_method method
)
281 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
282 BT_ASSERT_PRE_NON_NULL(method
, "Method");
283 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
284 comp_cls
->methods
.init
= method
;
285 BT_LIB_LOGV("Set sink component class's initialization method: "
287 return BT_COMPONENT_CLASS_STATUS_OK
;
290 enum bt_component_class_status
291 bt_component_class_source_set_finalize_method(
292 struct bt_component_class_source
*comp_cls
,
293 bt_component_class_source_finalize_method method
)
295 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
296 BT_ASSERT_PRE_NON_NULL(method
, "Method");
297 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
298 comp_cls
->methods
.finalize
= method
;
299 BT_LIB_LOGV("Set source component class's finalization method: "
301 return BT_COMPONENT_CLASS_STATUS_OK
;
304 enum bt_component_class_status
305 bt_component_class_filter_set_finalize_method(
306 struct bt_component_class_filter
*comp_cls
,
307 bt_component_class_filter_finalize_method method
)
309 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
310 BT_ASSERT_PRE_NON_NULL(method
, "Method");
311 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
312 comp_cls
->methods
.finalize
= method
;
313 BT_LIB_LOGV("Set filter component class's finalization method: "
315 return BT_COMPONENT_CLASS_STATUS_OK
;
318 enum bt_component_class_status
319 bt_component_class_sink_set_finalize_method(
320 struct bt_component_class_sink
*comp_cls
,
321 bt_component_class_sink_finalize_method method
)
323 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
324 BT_ASSERT_PRE_NON_NULL(method
, "Method");
325 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
326 comp_cls
->methods
.finalize
= method
;
327 BT_LIB_LOGV("Set sink component class's finalization method: "
329 return BT_COMPONENT_CLASS_STATUS_OK
;
332 enum bt_component_class_status
333 bt_component_class_source_set_query_method(
334 struct bt_component_class_source
*comp_cls
,
335 bt_component_class_source_query_method method
)
337 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
338 BT_ASSERT_PRE_NON_NULL(method
, "Method");
339 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
340 comp_cls
->methods
.query
= method
;
341 BT_LIB_LOGV("Set source component class's query method: "
343 return BT_COMPONENT_CLASS_STATUS_OK
;
346 enum bt_component_class_status
347 bt_component_class_filter_set_query_method(
348 struct bt_component_class_filter
*comp_cls
,
349 bt_component_class_filter_query_method method
)
351 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
352 BT_ASSERT_PRE_NON_NULL(method
, "Method");
353 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
354 comp_cls
->methods
.query
= method
;
355 BT_LIB_LOGV("Set filter component class's query method: "
357 return BT_COMPONENT_CLASS_STATUS_OK
;
360 enum bt_component_class_status
361 bt_component_class_sink_set_query_method(
362 struct bt_component_class_sink
*comp_cls
,
363 bt_component_class_sink_query_method method
)
365 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
366 BT_ASSERT_PRE_NON_NULL(method
, "Method");
367 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
368 comp_cls
->methods
.query
= method
;
369 BT_LIB_LOGV("Set sink component class's query method: "
371 return BT_COMPONENT_CLASS_STATUS_OK
;
374 enum bt_component_class_status
375 bt_component_class_filter_set_accept_input_port_connection_method(
376 struct bt_component_class_filter
*comp_cls
,
377 bt_component_class_filter_accept_input_port_connection_method method
)
379 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
380 BT_ASSERT_PRE_NON_NULL(method
, "Method");
381 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
382 comp_cls
->methods
.accept_input_port_connection
= method
;
383 BT_LIB_LOGV("Set filter component class's \"accept input port connection\" method"
385 return BT_COMPONENT_CLASS_STATUS_OK
;
388 enum bt_component_class_status
389 bt_component_class_sink_set_accept_input_port_connection_method(
390 struct bt_component_class_sink
*comp_cls
,
391 bt_component_class_sink_accept_input_port_connection_method method
)
393 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
394 BT_ASSERT_PRE_NON_NULL(method
, "Method");
395 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
396 comp_cls
->methods
.accept_input_port_connection
= method
;
397 BT_LIB_LOGV("Set sink component class's \"accept input port connection\" method"
399 return BT_COMPONENT_CLASS_STATUS_OK
;
402 enum bt_component_class_status
403 bt_component_class_source_set_accept_output_port_connection_method(
404 struct bt_component_class_source
*comp_cls
,
405 bt_component_class_source_accept_output_port_connection_method method
)
407 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
408 BT_ASSERT_PRE_NON_NULL(method
, "Method");
409 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
410 comp_cls
->methods
.accept_output_port_connection
= method
;
411 BT_LIB_LOGV("Set source component class's \"accept output port connection\" method"
413 return BT_COMPONENT_CLASS_STATUS_OK
;
416 enum bt_component_class_status
417 bt_component_class_filter_set_accept_output_port_connection_method(
418 struct bt_component_class_filter
*comp_cls
,
419 bt_component_class_filter_accept_output_port_connection_method method
)
421 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
422 BT_ASSERT_PRE_NON_NULL(method
, "Method");
423 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
424 comp_cls
->methods
.accept_output_port_connection
= method
;
425 BT_LIB_LOGV("Set filter component class's \"accept output port connection\" method"
427 return BT_COMPONENT_CLASS_STATUS_OK
;
430 enum bt_component_class_status
431 bt_component_class_filter_set_input_port_connected_method(
432 struct bt_component_class_filter
*comp_cls
,
433 bt_component_class_filter_input_port_connected_method method
)
435 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
436 BT_ASSERT_PRE_NON_NULL(method
, "Method");
437 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
438 comp_cls
->methods
.input_port_connected
= method
;
439 BT_LIB_LOGV("Set filter component class's \"input port connected\" method"
441 return BT_COMPONENT_CLASS_STATUS_OK
;
444 enum bt_component_class_status
445 bt_component_class_sink_set_input_port_connected_method(
446 struct bt_component_class_sink
*comp_cls
,
447 bt_component_class_sink_input_port_connected_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
.input_port_connected
= method
;
453 BT_LIB_LOGV("Set sink component class's \"input port connected\" method"
455 return BT_COMPONENT_CLASS_STATUS_OK
;
458 enum bt_component_class_status
459 bt_component_class_source_set_output_port_connected_method(
460 struct bt_component_class_source
*comp_cls
,
461 bt_component_class_source_output_port_connected_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
.output_port_connected
= method
;
467 BT_LIB_LOGV("Set source component class's \"output port connected\" method"
469 return BT_COMPONENT_CLASS_STATUS_OK
;
472 enum bt_component_class_status
473 bt_component_class_filter_set_output_port_connected_method(
474 struct bt_component_class_filter
*comp_cls
,
475 bt_component_class_filter_output_port_connected_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
.output_port_connected
= method
;
481 BT_LIB_LOGV("Set filter component class's \"output port connected\" method"
483 return BT_COMPONENT_CLASS_STATUS_OK
;
486 enum bt_component_class_status
487 bt_component_class_sink_set_graph_is_configured_method(
488 struct bt_component_class_sink
*comp_cls
,
489 bt_component_class_sink_graph_is_configured_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
.graph_is_configured
= method
;
495 BT_LIB_LOGV("Set sink component class's \"graph is configured\" method"
497 return BT_COMPONENT_CLASS_STATUS_OK
;
500 int bt_component_class_source_set_message_iterator_init_method(
501 struct bt_component_class_source
*comp_cls
,
502 bt_component_class_source_message_iterator_init_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_init
= method
;
508 BT_LIB_LOGV("Set source component class's message iterator initialization method"
510 return BT_COMPONENT_CLASS_STATUS_OK
;
513 enum bt_component_class_status
514 bt_component_class_filter_set_message_iterator_init_method(
515 struct bt_component_class_filter
*comp_cls
,
516 bt_component_class_filter_message_iterator_init_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_init
= method
;
522 BT_LIB_LOGV("Set filter component class's message iterator initialization method"
524 return BT_COMPONENT_CLASS_STATUS_OK
;
527 enum bt_component_class_status
528 bt_component_class_source_set_message_iterator_finalize_method(
529 struct bt_component_class_source
*comp_cls
,
530 bt_component_class_source_message_iterator_finalize_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_finalize
= method
;
536 BT_LIB_LOGV("Set source component class's message iterator finalization method"
538 return BT_COMPONENT_CLASS_STATUS_OK
;
541 enum bt_component_class_status
542 bt_component_class_filter_set_message_iterator_finalize_method(
543 struct bt_component_class_filter
*comp_cls
,
544 bt_component_class_filter_message_iterator_finalize_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_finalize
= method
;
550 BT_LIB_LOGV("Set filter component class's message iterator finalization method"
552 return BT_COMPONENT_CLASS_STATUS_OK
;
555 enum bt_component_class_status
556 bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method(
557 struct bt_component_class_filter
*comp_cls
,
558 bt_component_class_filter_message_iterator_seek_ns_from_origin_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_ns_from_origin
= method
;
564 BT_LIB_LOGV("Set filter component class's message iterator \"seek nanoseconds from origin\" method"
566 return BT_COMPONENT_CLASS_STATUS_OK
;
569 enum bt_component_class_status
570 bt_component_class_source_set_message_iterator_seek_ns_from_origin_method(
571 struct bt_component_class_source
*comp_cls
,
572 bt_component_class_source_message_iterator_seek_ns_from_origin_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_seek_ns_from_origin
= method
;
578 BT_LIB_LOGV("Set source component class's message iterator \"seek nanoseconds from origin\" method"
580 return BT_COMPONENT_CLASS_STATUS_OK
;
583 enum bt_component_class_status
584 bt_component_class_filter_set_message_iterator_seek_beginning_method(
585 struct bt_component_class_filter
*comp_cls
,
586 bt_component_class_filter_message_iterator_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_seek_beginning
= method
;
592 BT_LIB_LOGV("Set filter component class's message iterator \"seek beginning\" method"
594 return BT_COMPONENT_CLASS_STATUS_OK
;
597 enum bt_component_class_status
598 bt_component_class_source_set_message_iterator_seek_beginning_method(
599 struct bt_component_class_source
*comp_cls
,
600 bt_component_class_source_message_iterator_seek_beginning_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_seek_beginning
= method
;
606 BT_LIB_LOGV("Set source component class's message iterator \"seek beginning\" method"
608 return BT_COMPONENT_CLASS_STATUS_OK
;
611 enum bt_component_class_status
612 bt_component_class_filter_set_message_iterator_can_seek_beginning_method(
613 struct bt_component_class_filter
*comp_cls
,
614 bt_component_class_filter_message_iterator_can_seek_beginning_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_beginning
= method
;
620 BT_LIB_LOGV("Set filter component class's message iterator \"can seek beginning\" method"
622 return BT_COMPONENT_CLASS_STATUS_OK
;
625 enum bt_component_class_status
626 bt_component_class_source_set_message_iterator_can_seek_beginning_method(
627 struct bt_component_class_source
*comp_cls
,
628 bt_component_class_source_message_iterator_can_seek_beginning_method method
)
630 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
631 BT_ASSERT_PRE_NON_NULL(method
, "Method");
632 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
633 comp_cls
->methods
.msg_iter_can_seek_beginning
= method
;
634 BT_LIB_LOGV("Set source component class's message iterator \"can seek beginning\" method"
636 return BT_COMPONENT_CLASS_STATUS_OK
;
639 enum bt_component_class_status
640 bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method(
641 struct bt_component_class_filter
*comp_cls
,
642 bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method method
)
644 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
645 BT_ASSERT_PRE_NON_NULL(method
, "Method");
646 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
647 comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
= method
;
648 BT_LIB_LOGV("Set filter component class's message iterator \"can seek nanoseconds from origin\" method"
650 return BT_COMPONENT_CLASS_STATUS_OK
;
653 enum bt_component_class_status
654 bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method(
655 struct bt_component_class_source
*comp_cls
,
656 bt_component_class_source_message_iterator_can_seek_ns_from_origin_method method
)
658 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
659 BT_ASSERT_PRE_NON_NULL(method
, "Method");
660 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
661 comp_cls
->methods
.msg_iter_can_seek_ns_from_origin
= method
;
662 BT_LIB_LOGV("Set source component class's message iterator \"can seek nanoseconds from origin\" method"
664 return BT_COMPONENT_CLASS_STATUS_OK
;
667 bt_component_class_status
bt_component_class_set_description(
668 struct bt_component_class
*comp_cls
,
669 const char *description
)
671 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
672 BT_ASSERT_PRE_NON_NULL(description
, "Description");
673 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
674 g_string_assign(comp_cls
->description
, description
);
675 BT_LIB_LOGV("Set component class's description: "
676 "addr=%p, name=\"%s\", type=%s",
678 bt_component_class_get_name(comp_cls
),
679 bt_component_class_type_string(comp_cls
->type
));
680 return BT_COMPONENT_CLASS_STATUS_OK
;
683 bt_component_class_status
bt_component_class_set_help(
684 struct bt_component_class
*comp_cls
,
687 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
688 BT_ASSERT_PRE_NON_NULL(help
, "Help");
689 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls
);
690 g_string_assign(comp_cls
->help
, help
);
691 BT_LIB_LOGV("Set component class's help text: %!+C", comp_cls
);
692 return BT_COMPONENT_CLASS_STATUS_OK
;
695 const char *bt_component_class_get_name(const struct bt_component_class
*comp_cls
)
697 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
698 return comp_cls
->name
->str
;
701 enum bt_component_class_type
bt_component_class_get_type(
702 const struct bt_component_class
*comp_cls
)
704 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
705 return comp_cls
->type
;
708 const char *bt_component_class_get_description(
709 const struct bt_component_class
*comp_cls
)
711 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
712 return comp_cls
->description
&&
713 comp_cls
->description
->str
[0] != '\0' ?
714 comp_cls
->description
->str
: NULL
;
717 const char *bt_component_class_get_help(
718 const struct bt_component_class
*comp_cls
)
720 BT_ASSERT_PRE_NON_NULL(comp_cls
, "Component class");
721 return comp_cls
->help
&&
722 comp_cls
->help
->str
[0] != '\0' ? comp_cls
->help
->str
: NULL
;
726 void bt_component_class_add_destroy_listener(
727 struct bt_component_class
*comp_cls
,
728 bt_component_class_destroy_listener_func func
, void *data
)
730 struct bt_component_class_destroy_listener listener
;
734 listener
.func
= func
;
735 listener
.data
= data
;
736 g_array_append_val(comp_cls
->destroy_listeners
, listener
);
737 BT_LIB_LOGV("Added destroy listener to component class: "
738 "%![cc-]+C, listener-func-addr=%p", comp_cls
, func
);
742 void _bt_component_class_freeze(const struct bt_component_class
*comp_cls
)
745 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls
);
746 ((struct bt_component_class
*) comp_cls
)->frozen
= true;
749 void bt_component_class_get_ref(
750 const struct bt_component_class
*component_class
)
752 bt_object_get_ref(component_class
);
755 void bt_component_class_put_ref(
756 const struct bt_component_class
*component_class
)
758 bt_object_put_ref(component_class
);
761 void bt_component_class_source_get_ref(
762 const struct bt_component_class_source
*component_class_source
)
764 bt_object_get_ref(component_class_source
);
767 void bt_component_class_source_put_ref(
768 const struct bt_component_class_source
*component_class_source
)
770 bt_object_put_ref(component_class_source
);
773 void bt_component_class_filter_get_ref(
774 const struct bt_component_class_filter
*component_class_filter
)
776 bt_object_get_ref(component_class_filter
);
779 void bt_component_class_filter_put_ref(
780 const struct bt_component_class_filter
*component_class_filter
)
782 bt_object_put_ref(component_class_filter
);
785 void bt_component_class_sink_get_ref(
786 const struct bt_component_class_sink
*component_class_sink
)
788 bt_object_get_ref(component_class_sink
);
791 void bt_component_class_sink_put_ref(
792 const struct bt_component_class_sink
*component_class_sink
)
794 bt_object_put_ref(component_class_sink
);