lib: rename plural file names to singular
[babeltrace.git] / lib / graph / component-class.c
... / ...
CommitLineData
1/*
2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 *
4 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
25#define BT_LOG_TAG "COMP-CLASS"
26#include <babeltrace/lib-logging-internal.h>
27
28#include <babeltrace/compiler-internal.h>
29#include <babeltrace/graph/component-class.h>
30#include <babeltrace/graph/component-class-const.h>
31#include <babeltrace/graph/component-class-source.h>
32#include <babeltrace/graph/component-class-source-const.h>
33#include <babeltrace/graph/component-class-filter.h>
34#include <babeltrace/graph/component-class-filter-const.h>
35#include <babeltrace/graph/component-class-sink.h>
36#include <babeltrace/graph/component-class-sink-const.h>
37#include <babeltrace/graph/component-class-internal.h>
38#include <babeltrace/object.h>
39#include <babeltrace/types.h>
40#include <babeltrace/assert-internal.h>
41#include <babeltrace/assert-pre-internal.h>
42#include <glib.h>
43
44#define BT_ASSERT_PRE_COMP_CLS_HOT(_cc) \
45 BT_ASSERT_PRE_HOT(((const struct bt_component_class *) (_cc)), \
46 "Component class", ": %!+C", (_cc))
47
48static
49void destroy_component_class(struct bt_object *obj)
50{
51 struct bt_component_class *class;
52 int i;
53
54 BT_ASSERT(obj);
55 class = container_of(obj, struct bt_component_class, base);
56
57 BT_LIB_LOGD("Destroying component class: %!+C", class);
58
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,
64 i);
65
66 BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p",
67 listener->func, listener->data);
68 listener->func(class, listener->data);
69 }
70
71 if (class->name) {
72 g_string_free(class->name, TRUE);
73 class->name = NULL;
74 }
75
76 if (class->description) {
77 g_string_free(class->description, TRUE);
78 class->description = NULL;
79 }
80
81 if (class->help) {
82 g_string_free(class->help, TRUE);
83 class->help = NULL;
84 }
85
86 if (class->destroy_listeners) {
87 g_array_free(class->destroy_listeners, TRUE);
88 class->destroy_listeners = NULL;
89 }
90
91 g_free(class);
92}
93
94static
95int bt_component_class_init(struct bt_component_class *class,
96 enum bt_component_class_type type, const char *name)
97{
98 int ret = 0;
99
100 bt_object_init_shared(&class->base, destroy_component_class);
101 class->type = type;
102 class->name = g_string_new(name);
103 if (!class->name) {
104 BT_LOGE_STR("Failed to allocate a GString.");
105 goto error;
106 }
107
108 class->description = g_string_new(NULL);
109 if (!class->description) {
110 BT_LOGE_STR("Failed to allocate a GString.");
111 goto error;
112 }
113
114 class->help = g_string_new(NULL);
115 if (!class->help) {
116 BT_LOGE_STR("Failed to allocate a GString.");
117 goto error;
118 }
119
120 class->destroy_listeners = g_array_new(FALSE, TRUE,
121 sizeof(struct bt_component_class_destroy_listener));
122 if (!class->destroy_listeners) {
123 BT_LOGE_STR("Failed to allocate a GArray.");
124 goto error;
125 }
126
127 goto end;
128
129error:
130 BT_OBJECT_PUT_REF_AND_RESET(class);
131 ret = -1;
132
133end:
134 return ret;
135}
136
137struct bt_component_class_source *bt_component_class_source_create(
138 const char *name,
139 bt_component_class_source_notification_iterator_next_method method)
140{
141 struct bt_component_class_source *source_class = NULL;
142 int ret;
143
144 BT_ASSERT_PRE_NON_NULL(name, "Name");
145 BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method");
146 BT_LOGD("Creating source component class: "
147 "name=\"%s\", notif-iter-next-method-addr=%p",
148 name, method);
149 source_class = g_new0(struct bt_component_class_source, 1);
150 if (!source_class) {
151 BT_LOGE_STR("Failed to allocate one source component class.");
152 goto end;
153 }
154
155 /* bt_component_class_init() logs errors */
156 ret = bt_component_class_init(&source_class->parent,
157 BT_COMPONENT_CLASS_TYPE_SOURCE, name);
158 if (ret) {
159 /*
160 * If bt_component_class_init() fails, the component
161 * class is put, therefore its memory is already
162 * freed.
163 */
164 source_class = NULL;
165 goto end;
166 }
167
168 source_class->methods.notif_iter_next = method;
169 BT_LIB_LOGD("Created source component class: %!+C", source_class);
170
171end:
172 return (void *) source_class;
173}
174
175struct bt_component_class_filter *bt_component_class_filter_create(
176 const char *name,
177 bt_component_class_filter_notification_iterator_next_method method)
178{
179 struct bt_component_class_filter *filter_class = NULL;
180 int ret;
181
182 BT_ASSERT_PRE_NON_NULL(name, "Name");
183 BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method");
184 BT_LOGD("Creating filter component class: "
185 "name=\"%s\", notif-iter-next-method-addr=%p",
186 name, method);
187 filter_class = g_new0(struct bt_component_class_filter, 1);
188 if (!filter_class) {
189 BT_LOGE_STR("Failed to allocate one filter component class.");
190 goto end;
191 }
192
193 /* bt_component_class_init() logs errors */
194 ret = bt_component_class_init(&filter_class->parent,
195 BT_COMPONENT_CLASS_TYPE_FILTER, name);
196 if (ret) {
197 /*
198 * If bt_component_class_init() fails, the component
199 * class is put, therefore its memory is already
200 * freed.
201 */
202 filter_class = NULL;
203 goto end;
204 }
205
206 filter_class->methods.notif_iter_next = method;
207 BT_LIB_LOGD("Created filter component class: %!+C", filter_class);
208
209end:
210 return (void *) filter_class;
211}
212
213struct bt_component_class_sink *bt_component_class_sink_create(
214 const char *name, bt_component_class_sink_consume_method method)
215{
216 struct bt_component_class_sink *sink_class = NULL;
217 int ret;
218
219 BT_ASSERT_PRE_NON_NULL(name, "Name");
220 BT_ASSERT_PRE_NON_NULL(method, "Consume next method");
221 BT_LOGD("Creating sink component class: "
222 "name=\"%s\", consume-method-addr=%p",
223 name, method);
224 sink_class = g_new0(struct bt_component_class_sink, 1);
225 if (!sink_class) {
226 BT_LOGE_STR("Failed to allocate one sink component class.");
227 goto end;
228 }
229
230 /* bt_component_class_init() logs errors */
231 ret = bt_component_class_init(&sink_class->parent,
232 BT_COMPONENT_CLASS_TYPE_SINK, name);
233 if (ret) {
234 /*
235 * If bt_component_class_init() fails, the component
236 * class is put, therefore its memory is already
237 * freed.
238 */
239 sink_class = NULL;
240 goto end;
241 }
242
243 sink_class->methods.consume = method;
244 BT_LIB_LOGD("Created sink component class: %!+C", sink_class);
245
246end:
247 return (void *) sink_class;
248}
249
250int bt_component_class_source_set_init_method(
251 struct bt_component_class_source *comp_cls,
252 bt_component_class_source_init_method method)
253{
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_LOGV("Set source component class's initialization method: "
259 "%!+C", comp_cls);
260 return 0;
261}
262
263int bt_component_class_filter_set_init_method(
264 struct bt_component_class_filter *comp_cls,
265 bt_component_class_filter_init_method method)
266{
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: "
272 "%!+C", comp_cls);
273 return 0;
274}
275
276int bt_component_class_sink_set_init_method(
277 struct bt_component_class_sink *comp_cls,
278 bt_component_class_sink_init_method method)
279{
280 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
281 BT_ASSERT_PRE_NON_NULL(method, "Method");
282 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
283 comp_cls->methods.init = method;
284 BT_LIB_LOGV("Set sink component class's initialization method: "
285 "%!+C", comp_cls);
286 return 0;
287}
288
289int bt_component_class_source_set_finalize_method(
290 struct bt_component_class_source *comp_cls,
291 bt_component_class_source_finalize_method method)
292{
293 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
294 BT_ASSERT_PRE_NON_NULL(method, "Method");
295 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
296 comp_cls->methods.finalize = method;
297 BT_LIB_LOGV("Set source component class's finalization method: "
298 "%!+C", comp_cls);
299 return 0;
300}
301
302int bt_component_class_filter_set_finalize_method(
303 struct bt_component_class_filter *comp_cls,
304 bt_component_class_filter_finalize_method method)
305{
306 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
307 BT_ASSERT_PRE_NON_NULL(method, "Method");
308 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
309 comp_cls->methods.finalize = method;
310 BT_LIB_LOGV("Set filter component class's finalization method: "
311 "%!+C", comp_cls);
312 return 0;
313}
314
315int bt_component_class_sink_set_finalize_method(
316 struct bt_component_class_sink *comp_cls,
317 bt_component_class_sink_finalize_method method)
318{
319 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
320 BT_ASSERT_PRE_NON_NULL(method, "Method");
321 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
322 comp_cls->methods.finalize = method;
323 BT_LIB_LOGV("Set sink component class's finalization method: "
324 "%!+C", comp_cls);
325 return 0;
326}
327
328int bt_component_class_source_set_query_method(
329 struct bt_component_class_source *comp_cls,
330 bt_component_class_source_query_method method)
331{
332 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
333 BT_ASSERT_PRE_NON_NULL(method, "Method");
334 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
335 comp_cls->methods.query = method;
336 BT_LIB_LOGV("Set source component class's query method: "
337 "%!+C", comp_cls);
338 return 0;
339}
340
341int bt_component_class_filter_set_query_method(
342 struct bt_component_class_filter *comp_cls,
343 bt_component_class_filter_query_method method)
344{
345 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
346 BT_ASSERT_PRE_NON_NULL(method, "Method");
347 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
348 comp_cls->methods.query = method;
349 BT_LIB_LOGV("Set filter component class's query method: "
350 "%!+C", comp_cls);
351 return 0;
352}
353
354int bt_component_class_sink_set_query_method(
355 struct bt_component_class_sink *comp_cls,
356 bt_component_class_sink_query_method method)
357{
358 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
359 BT_ASSERT_PRE_NON_NULL(method, "Method");
360 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
361 comp_cls->methods.query = method;
362 BT_LIB_LOGV("Set sink component class's query method: "
363 "%!+C", comp_cls);
364 return 0;
365}
366
367int bt_component_class_filter_set_accept_input_port_connection_method(
368 struct bt_component_class_filter *comp_cls,
369 bt_component_class_filter_accept_input_port_connection_method method)
370{
371 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
372 BT_ASSERT_PRE_NON_NULL(method, "Method");
373 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
374 comp_cls->methods.accept_input_port_connection = method;
375 BT_LIB_LOGV("Set filter component class's \"accept input port connection\" method"
376 ": %!+C", comp_cls);
377 return 0;
378}
379
380int bt_component_class_sink_set_accept_input_port_connection_method(
381 struct bt_component_class_sink *comp_cls,
382 bt_component_class_sink_accept_input_port_connection_method method)
383{
384 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
385 BT_ASSERT_PRE_NON_NULL(method, "Method");
386 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
387 comp_cls->methods.accept_input_port_connection = method;
388 BT_LIB_LOGV("Set sink component class's \"accept input port connection\" method"
389 ": %!+C", comp_cls);
390 return 0;
391}
392
393int bt_component_class_source_set_accept_output_port_connection_method(
394 struct bt_component_class_source *comp_cls,
395 bt_component_class_source_accept_output_port_connection_method method)
396{
397 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
398 BT_ASSERT_PRE_NON_NULL(method, "Method");
399 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
400 comp_cls->methods.accept_output_port_connection = method;
401 BT_LIB_LOGV("Set source component class's \"accept output port connection\" method"
402 ": %!+C", comp_cls);
403 return 0;
404}
405
406int bt_component_class_filter_set_accept_output_port_connection_method(
407 struct bt_component_class_filter *comp_cls,
408 bt_component_class_filter_accept_output_port_connection_method method)
409{
410 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
411 BT_ASSERT_PRE_NON_NULL(method, "Method");
412 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
413 comp_cls->methods.accept_output_port_connection = method;
414 BT_LIB_LOGV("Set filter component class's \"accept output port connection\" method"
415 ": %!+C", comp_cls);
416 return 0;
417}
418
419int bt_component_class_filter_set_input_port_connected_method(
420 struct bt_component_class_filter *comp_cls,
421 bt_component_class_filter_input_port_connected_method method)
422{
423 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
424 BT_ASSERT_PRE_NON_NULL(method, "Method");
425 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
426 comp_cls->methods.input_port_connected = method;
427 BT_LIB_LOGV("Set filter component class's \"input port connected\" method"
428 ": %!+C", comp_cls);
429 return 0;
430}
431
432int bt_component_class_sink_set_input_port_connected_method(
433 struct bt_component_class_sink *comp_cls,
434 bt_component_class_sink_input_port_connected_method method)
435{
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_LOGV("Set sink component class's \"input port connected\" method"
441 ": %!+C", comp_cls);
442 return 0;
443}
444
445int bt_component_class_source_set_output_port_connected_method(
446 struct bt_component_class_source *comp_cls,
447 bt_component_class_source_output_port_connected_method method)
448{
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.output_port_connected = method;
453 BT_LIB_LOGV("Set source component class's \"output port connected\" method"
454 ": %!+C", comp_cls);
455 return 0;
456}
457
458int bt_component_class_filter_set_output_port_connected_method(
459 struct bt_component_class_filter *comp_cls,
460 bt_component_class_filter_output_port_connected_method method)
461{
462 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
463 BT_ASSERT_PRE_NON_NULL(method, "Method");
464 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
465 comp_cls->methods.output_port_connected = method;
466 BT_LIB_LOGV("Set filter component class's \"output port connected\" method"
467 ": %!+C", comp_cls);
468 return 0;
469}
470
471int bt_component_class_filter_set_input_port_disconnected_method(
472 struct bt_component_class_filter *comp_cls,
473 bt_component_class_filter_input_port_disconnected_method method)
474{
475 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
476 BT_ASSERT_PRE_NON_NULL(method, "Method");
477 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
478 comp_cls->methods.input_port_disconnected = method;
479 BT_LIB_LOGV("Set filter component class's \"input port disconnected\" method"
480 ": %!+C", comp_cls);
481 return 0;
482}
483
484int bt_component_class_sink_set_input_port_disconnected_method(
485 struct bt_component_class_sink *comp_cls,
486 bt_component_class_sink_input_port_disconnected_method method)
487{
488 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
489 BT_ASSERT_PRE_NON_NULL(method, "Method");
490 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
491 comp_cls->methods.input_port_disconnected = method;
492 BT_LIB_LOGV("Set sink component class's \"input port disconnected\" method"
493 ": %!+C", comp_cls);
494 return 0;
495}
496
497int bt_component_class_source_set_output_port_disconnected_method(
498 struct bt_component_class_source *comp_cls,
499 bt_component_class_source_output_port_disconnected_method method)
500{
501 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
502 BT_ASSERT_PRE_NON_NULL(method, "Method");
503 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
504 comp_cls->methods.output_port_disconnected = method;
505 BT_LIB_LOGV("Set source component class's \"output port disconnected\" method"
506 ": %!+C", comp_cls);
507 return 0;
508}
509
510int bt_component_class_filter_set_output_port_disconnected_method(
511 struct bt_component_class_filter *comp_cls,
512 bt_component_class_filter_output_port_disconnected_method method)
513{
514 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
515 BT_ASSERT_PRE_NON_NULL(method, "Method");
516 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
517 comp_cls->methods.output_port_disconnected = method;
518 BT_LIB_LOGV("Set filter component class's \"output port disconnected\" method"
519 ": %!+C", comp_cls);
520 return 0;
521}
522
523int bt_component_class_source_set_notification_iterator_init_method(
524 struct bt_component_class_source *comp_cls,
525 bt_component_class_source_notification_iterator_init_method method)
526{
527 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
528 BT_ASSERT_PRE_NON_NULL(method, "Method");
529 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
530 comp_cls->methods.notif_iter_init = method;
531 BT_LIB_LOGV("Set source component class's notification iterator initialization method"
532 ": %!+C", comp_cls);
533 return 0;
534}
535
536int bt_component_class_filter_set_notification_iterator_init_method(
537 struct bt_component_class_filter *comp_cls,
538 bt_component_class_filter_notification_iterator_init_method method)
539{
540 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
541 BT_ASSERT_PRE_NON_NULL(method, "Method");
542 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
543 comp_cls->methods.notif_iter_init = method;
544 BT_LIB_LOGV("Set filter component class's notification iterator initialization method"
545 ": %!+C", comp_cls);
546 return 0;
547}
548
549int bt_component_class_source_set_notification_iterator_finalize_method(
550 struct bt_component_class_source *comp_cls,
551 bt_component_class_source_notification_iterator_finalize_method method)
552{
553 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
554 BT_ASSERT_PRE_NON_NULL(method, "Method");
555 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
556 comp_cls->methods.notif_iter_finalize = method;
557 BT_LIB_LOGV("Set source component class's notification iterator finalization method"
558 ": %!+C", comp_cls);
559 return 0;
560}
561
562int bt_component_class_filter_set_notification_iterator_finalize_method(
563 struct bt_component_class_filter *comp_cls,
564 bt_component_class_filter_notification_iterator_finalize_method method)
565{
566 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
567 BT_ASSERT_PRE_NON_NULL(method, "Method");
568 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
569 comp_cls->methods.notif_iter_finalize = method;
570 BT_LIB_LOGV("Set filter component class's notification iterator finalization method"
571 ": %!+C", comp_cls);
572 return 0;
573}
574
575int bt_component_class_set_description(
576 struct bt_component_class *comp_cls,
577 const char *description)
578{
579 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
580 BT_ASSERT_PRE_NON_NULL(description, "Description");
581 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
582 g_string_assign(comp_cls->description, description);
583 BT_LIB_LOGV("Set component class's description: "
584 "addr=%p, name=\"%s\", type=%s",
585 comp_cls,
586 bt_component_class_get_name(comp_cls),
587 bt_component_class_type_string(comp_cls->type));
588 return 0;
589}
590
591int bt_component_class_set_help(
592 struct bt_component_class *comp_cls,
593 const char *help)
594{
595 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
596 BT_ASSERT_PRE_NON_NULL(help, "Help");
597 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
598 g_string_assign(comp_cls->help, help);
599 BT_LIB_LOGV("Set component class's help text: %!+C", comp_cls);
600 return 0;
601}
602
603const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
604{
605 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
606 return comp_cls->name->str;
607}
608
609enum bt_component_class_type bt_component_class_get_type(
610 const struct bt_component_class *comp_cls)
611{
612 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
613 return comp_cls->type;
614}
615
616const char *bt_component_class_get_description(
617 const struct bt_component_class *comp_cls)
618{
619 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
620 return comp_cls->description &&
621 comp_cls->description->str[0] != '\0' ?
622 comp_cls->description->str : NULL;
623}
624
625const char *bt_component_class_get_help(
626 const struct bt_component_class *comp_cls)
627{
628 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
629 return comp_cls->help &&
630 comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL;
631}
632
633BT_HIDDEN
634void bt_component_class_add_destroy_listener(
635 struct bt_component_class *comp_cls,
636 bt_component_class_destroy_listener_func func, void *data)
637{
638 struct bt_component_class_destroy_listener listener;
639
640 BT_ASSERT(comp_cls);
641 BT_ASSERT(func);
642 listener.func = func;
643 listener.data = data;
644 g_array_append_val(comp_cls->destroy_listeners, listener);
645 BT_LIB_LOGV("Added destroy listener to component class: "
646 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
647}
648
649BT_HIDDEN
650void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
651{
652 BT_ASSERT(comp_cls);
653 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
654 ((struct bt_component_class *) comp_cls)->frozen = true;
655}
This page took 0.024831 seconds and 4 git commands to generate.