Split notification iterator API into base and specialized functions
[babeltrace.git] / lib / graph / component-class.c
1 /*
2 * component-class.c
3 *
4 * Babeltrace Plugin Component Class
5 *
6 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 *
8 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 * SOFTWARE.
27 */
28
29 #define BT_LOG_TAG "COMP-CLASS"
30 #include <babeltrace/lib-logging-internal.h>
31
32 #include <babeltrace/compiler-internal.h>
33 #include <babeltrace/graph/component-class-internal.h>
34 #include <babeltrace/ref.h>
35 #include <babeltrace/types.h>
36 #include <glib.h>
37
38 static
39 void bt_component_class_destroy(struct bt_object *obj)
40 {
41 struct bt_component_class *class;
42 int i;
43
44 assert(obj);
45 class = container_of(obj, struct bt_component_class, base);
46
47 BT_LOGD("Destroying component class: "
48 "addr=%p, name=\"%s\", type=%s",
49 class, bt_component_class_get_name(class),
50 bt_component_class_type_string(class->type));
51
52 /* Call destroy listeners in reverse registration order */
53 for (i = class->destroy_listeners->len - 1; i >= 0; i--) {
54 struct bt_component_class_destroy_listener *listener =
55 &g_array_index(class->destroy_listeners,
56 struct bt_component_class_destroy_listener,
57 i);
58
59 BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p",
60 listener->func, listener->data);
61 listener->func(class, listener->data);
62 }
63
64 if (class->name) {
65 g_string_free(class->name, TRUE);
66 }
67 if (class->description) {
68 g_string_free(class->description, TRUE);
69 }
70 if (class->help) {
71 g_string_free(class->help, TRUE);
72 }
73 if (class->destroy_listeners) {
74 g_array_free(class->destroy_listeners, TRUE);
75 }
76
77 g_free(class);
78 }
79
80 static
81 int bt_component_class_init(struct bt_component_class *class,
82 enum bt_component_class_type type, const char *name)
83 {
84 int ret = 0;
85
86 bt_object_init(class, bt_component_class_destroy);
87 class->type = type;
88 class->name = g_string_new(name);
89 if (!class->name) {
90 BT_LOGE_STR("Failed to allocate a GString.");
91 goto error;
92 }
93
94 class->description = g_string_new(NULL);
95 if (!class->description) {
96 BT_LOGE_STR("Failed to allocate a GString.");
97 goto error;
98 }
99
100 class->help = g_string_new(NULL);
101 if (!class->help) {
102 BT_LOGE_STR("Failed to allocate a GString.");
103 goto error;
104 }
105
106 class->destroy_listeners = g_array_new(FALSE, TRUE,
107 sizeof(struct bt_component_class_destroy_listener));
108 if (!class->destroy_listeners) {
109 BT_LOGE_STR("Failed to allocate a GArray.");
110 goto error;
111 }
112
113 goto end;
114
115 error:
116 BT_PUT(class);
117 ret = -1;
118
119 end:
120 return ret;
121 }
122
123 struct bt_component_class *bt_component_class_source_create(const char *name,
124 bt_component_class_notification_iterator_next_method method)
125 {
126 struct bt_component_class_source *source_class = NULL;
127 int ret;
128
129 if (!name) {
130 BT_LOGW_STR("Invalid parameter: name is NULL.");
131 goto end;
132 }
133
134 if (!method) {
135 BT_LOGW_STR("Invalid parameter: method is NULL.");
136 goto end;
137 }
138
139 BT_LOGD("Creating source component class: "
140 "name=\"%s\", notif-iter-next-method-addr=%p",
141 name, method);
142 source_class = g_new0(struct bt_component_class_source, 1);
143 if (!source_class) {
144 BT_LOGE_STR("Failed to allocate one source component class.");
145 goto end;
146 }
147
148 /* bt_component_class_init() logs errors */
149 ret = bt_component_class_init(&source_class->parent,
150 BT_COMPONENT_CLASS_TYPE_SOURCE, name);
151 if (ret) {
152 /*
153 * If bt_component_class_init() fails, the component
154 * class is put, therefore its memory is already
155 * freed.
156 */
157 source_class = NULL;
158 goto end;
159 }
160
161 source_class->methods.iterator.next = method;
162 BT_LOGD("Created source component class: "
163 "name=\"%s\", notif-iter-next-method-addr=%p, addr=%p",
164 name, method, &source_class->parent);
165
166 end:
167 return &source_class->parent;
168 }
169
170 struct bt_component_class *bt_component_class_filter_create(const char *name,
171 bt_component_class_notification_iterator_next_method method)
172 {
173 struct bt_component_class_filter *filter_class = NULL;
174 int ret;
175
176 if (!name) {
177 BT_LOGW_STR("Invalid parameter: name is NULL.");
178 goto end;
179 }
180
181 if (!method) {
182 BT_LOGW_STR("Invalid parameter: method is NULL.");
183 goto end;
184 }
185
186 BT_LOGD("Creating filter component class: "
187 "name=\"%s\", notif-iter-next-method-addr=%p",
188 name, method);
189 filter_class = g_new0(struct bt_component_class_filter, 1);
190 if (!filter_class) {
191 BT_LOGE_STR("Failed to allocate one filter component class.");
192 goto end;
193 }
194
195 /* bt_component_class_init() logs errors */
196 ret = bt_component_class_init(&filter_class->parent,
197 BT_COMPONENT_CLASS_TYPE_FILTER, name);
198 if (ret) {
199 /*
200 * If bt_component_class_init() fails, the component
201 * class is put, therefore its memory is already
202 * freed.
203 */
204 filter_class = NULL;
205 goto end;
206 }
207
208 filter_class->methods.iterator.next = method;
209 BT_LOGD("Created filter component class: "
210 "name=\"%s\", notif-iter-next-method-addr=%p, addr=%p",
211 name, method, &filter_class->parent);
212
213 end:
214 return &filter_class->parent;
215 }
216
217 struct bt_component_class *bt_component_class_sink_create(const char *name,
218 bt_component_class_sink_consume_method method)
219 {
220 struct bt_component_class_sink *sink_class = NULL;
221 int ret;
222
223 if (!name) {
224 BT_LOGW_STR("Invalid parameter: name is NULL.");
225 goto end;
226 }
227
228 if (!method) {
229 BT_LOGW_STR("Invalid parameter: method is NULL.");
230 goto end;
231 }
232
233 BT_LOGD("Creating sink component class: "
234 "name=\"%s\", consume-method-addr=%p",
235 name, method);
236 sink_class = g_new0(struct bt_component_class_sink, 1);
237 if (!sink_class) {
238 BT_LOGE_STR("Failed to allocate one sink component class.");
239 goto end;
240 }
241
242 /* bt_component_class_init() logs errors */
243 ret = bt_component_class_init(&sink_class->parent,
244 BT_COMPONENT_CLASS_TYPE_SINK, name);
245 if (ret) {
246 /*
247 * If bt_component_class_init() fails, the component
248 * class is put, therefore its memory is already
249 * freed.
250 */
251 sink_class = NULL;
252 goto end;
253 }
254
255 sink_class->methods.consume = method;
256 BT_LOGD("Created sink component class: "
257 "name=\"%s\", consume-method-addr=%p, addr=%p",
258 name, method, &sink_class->parent);
259
260 end:
261 return &sink_class->parent;
262 }
263
264 int bt_component_class_set_init_method(
265 struct bt_component_class *component_class,
266 bt_component_class_init_method method)
267 {
268 int ret = 0;
269
270 if (!component_class) {
271 BT_LOGW_STR("Invalid parameter: component class is NULL.");
272 ret = -1;
273 goto end;
274 }
275
276 if (!method) {
277 BT_LOGW_STR("Invalid parameter: method is NULL.");
278 ret = -1;
279 goto end;
280 }
281
282 if (component_class->frozen) {
283 BT_LOGW("Invalid parameter: component class is frozen: "
284 "addr=%p, name=\"%s\", type=%s",
285 component_class,
286 bt_component_class_get_name(component_class),
287 bt_component_class_type_string(component_class->type));
288 ret = -1;
289 goto end;
290 }
291
292 component_class->methods.init = method;
293 BT_LOGV("Set component class's initialization method: "
294 "addr=%p, name=\"%s\", type=%s, method-addr=%p",
295 component_class,
296 bt_component_class_get_name(component_class),
297 bt_component_class_type_string(component_class->type),
298 method);
299
300 end:
301 return ret;
302 }
303
304 int bt_component_class_set_query_method(
305 struct bt_component_class *component_class,
306 bt_component_class_query_method method)
307 {
308 int ret = 0;
309
310 if (!component_class) {
311 BT_LOGW_STR("Invalid parameter: component class is NULL.");
312 ret = -1;
313 goto end;
314 }
315
316 if (!method) {
317 BT_LOGW_STR("Invalid parameter: method is NULL.");
318 ret = -1;
319 goto end;
320 }
321
322 if (component_class->frozen) {
323 BT_LOGW("Invalid parameter: component class is frozen: "
324 "addr=%p, name=\"%s\", type=%s",
325 component_class,
326 bt_component_class_get_name(component_class),
327 bt_component_class_type_string(component_class->type));
328 ret = -1;
329 goto end;
330 }
331
332 component_class->methods.query = method;
333 BT_LOGV("Set component class's query method: "
334 "addr=%p, name=\"%s\", type=%s, method-addr=%p",
335 component_class,
336 bt_component_class_get_name(component_class),
337 bt_component_class_type_string(component_class->type),
338 method);
339
340 end:
341 return ret;
342 }
343
344 int bt_component_class_set_accept_port_connection_method(
345 struct bt_component_class *component_class,
346 bt_component_class_accept_port_connection_method method)
347 {
348 int ret = 0;
349
350 if (!component_class) {
351 BT_LOGW_STR("Invalid parameter: component class is NULL.");
352 ret = -1;
353 goto end;
354 }
355
356 if (!method) {
357 BT_LOGW_STR("Invalid parameter: method is NULL.");
358 ret = -1;
359 goto end;
360 }
361
362 if (component_class->frozen) {
363 BT_LOGW("Invalid parameter: component class is frozen: "
364 "addr=%p, name=\"%s\", type=%s",
365 component_class,
366 bt_component_class_get_name(component_class),
367 bt_component_class_type_string(component_class->type));
368 ret = -1;
369 goto end;
370 }
371
372 component_class->methods.accept_port_connection = method;
373 BT_LOGV("Set component class's \"accept port connection\" method: "
374 "addr=%p, name=\"%s\", type=%s, method-addr=%p",
375 component_class,
376 bt_component_class_get_name(component_class),
377 bt_component_class_type_string(component_class->type),
378 method);
379
380 end:
381 return ret;
382 }
383
384 int bt_component_class_set_port_connected_method(
385 struct bt_component_class *component_class,
386 bt_component_class_port_connected_method method)
387 {
388 int ret = 0;
389
390 if (!component_class) {
391 BT_LOGW_STR("Invalid parameter: component class is NULL.");
392 ret = -1;
393 goto end;
394 }
395
396 if (!method) {
397 BT_LOGW_STR("Invalid parameter: method is NULL.");
398 ret = -1;
399 goto end;
400 }
401
402 if (component_class->frozen) {
403 BT_LOGW("Invalid parameter: component class is frozen: "
404 "addr=%p, name=\"%s\", type=%s",
405 component_class,
406 bt_component_class_get_name(component_class),
407 bt_component_class_type_string(component_class->type));
408 ret = -1;
409 goto end;
410 }
411
412 component_class->methods.port_connected = method;
413 BT_LOGV("Set component class's \"port connected\" method: "
414 "addr=%p, name=\"%s\", type=%s, method-addr=%p",
415 component_class,
416 bt_component_class_get_name(component_class),
417 bt_component_class_type_string(component_class->type),
418 method);
419
420 end:
421 return ret;
422 }
423
424 int bt_component_class_set_port_disconnected_method(
425 struct bt_component_class *component_class,
426 bt_component_class_port_disconnected_method method)
427 {
428 int ret = 0;
429
430 if (!component_class) {
431 BT_LOGW_STR("Invalid parameter: component class is NULL.");
432 ret = -1;
433 goto end;
434 }
435
436 if (!method) {
437 BT_LOGW_STR("Invalid parameter: method is NULL.");
438 ret = -1;
439 goto end;
440 }
441
442 if (component_class->frozen) {
443 BT_LOGW("Invalid parameter: component class is frozen: "
444 "addr=%p, name=\"%s\", type=%s",
445 component_class,
446 bt_component_class_get_name(component_class),
447 bt_component_class_type_string(component_class->type));
448 ret = -1;
449 goto end;
450 }
451
452 component_class->methods.port_disconnected = method;
453 BT_LOGV("Set component class's \"port disconnected\" method: "
454 "addr=%p, name=\"%s\", type=%s, method-addr=%p",
455 component_class,
456 bt_component_class_get_name(component_class),
457 bt_component_class_type_string(component_class->type),
458 method);
459
460 end:
461 return ret;
462 }
463
464 int bt_component_class_set_finalize_method(
465 struct bt_component_class *component_class,
466 bt_component_class_finalize_method method)
467 {
468 int ret = 0;
469
470 if (!component_class) {
471 BT_LOGW_STR("Invalid parameter: component class is NULL.");
472 ret = -1;
473 goto end;
474 }
475
476 if (!method) {
477 BT_LOGW_STR("Invalid parameter: method is NULL.");
478 ret = -1;
479 goto end;
480 }
481
482 if (component_class->frozen) {
483 BT_LOGW("Invalid parameter: component class is frozen: "
484 "addr=%p, name=\"%s\", type=%s",
485 component_class,
486 bt_component_class_get_name(component_class),
487 bt_component_class_type_string(component_class->type));
488 ret = -1;
489 goto end;
490 }
491
492 component_class->methods.finalize = method;
493 BT_LOGV("Set component class's finalization method: "
494 "addr=%p, name=\"%s\", type=%s, method-addr=%p",
495 component_class,
496 bt_component_class_get_name(component_class),
497 bt_component_class_type_string(component_class->type),
498 method);
499
500 end:
501 return ret;
502 }
503
504 int bt_component_class_source_set_notification_iterator_init_method(
505 struct bt_component_class *component_class,
506 bt_component_class_notification_iterator_init_method method)
507 {
508 struct bt_component_class_source *source_class;
509 int ret = 0;
510
511 if (!component_class) {
512 BT_LOGW_STR("Invalid parameter: component class is NULL.");
513 ret = -1;
514 goto end;
515 }
516
517 if (!method) {
518 BT_LOGW_STR("Invalid parameter: method is NULL.");
519 ret = -1;
520 goto end;
521 }
522
523 if (component_class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
524 BT_LOGW("Invalid parameter: component class is not a source component class: "
525 "addr=%p, name=\"%s\", type=%s",
526 component_class,
527 bt_component_class_get_name(component_class),
528 bt_component_class_type_string(component_class->type));
529 ret = -1;
530 goto end;
531 }
532
533 if (component_class->frozen) {
534 BT_LOGW("Invalid parameter: component class is frozen: "
535 "addr=%p, name=\"%s\", type=%s",
536 component_class,
537 bt_component_class_get_name(component_class),
538 bt_component_class_type_string(component_class->type));
539 ret = -1;
540 goto end;
541 }
542
543 source_class = container_of(component_class,
544 struct bt_component_class_source, parent);
545 source_class->methods.iterator.init = method;
546 BT_LOGV("Set filter component class's notification iterator initialization method: "
547 "addr=%p, name=\"%s\", method-addr=%p",
548 component_class,
549 bt_component_class_get_name(component_class),
550 method);
551
552 end:
553 return ret;
554 }
555
556 int bt_component_class_source_set_notification_iterator_finalize_method(
557 struct bt_component_class *component_class,
558 bt_component_class_notification_iterator_finalize_method method)
559 {
560 struct bt_component_class_source *source_class;
561 int ret = 0;
562
563 if (!component_class) {
564 BT_LOGW_STR("Invalid parameter: component class is NULL.");
565 ret = -1;
566 goto end;
567 }
568
569 if (!method) {
570 BT_LOGW_STR("Invalid parameter: method is NULL.");
571 ret = -1;
572 goto end;
573 }
574
575 if (component_class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
576 BT_LOGW("Invalid parameter: component class is not a source component class: "
577 "addr=%p, name=\"%s\", type=%s",
578 component_class,
579 bt_component_class_get_name(component_class),
580 bt_component_class_type_string(component_class->type));
581 ret = -1;
582 goto end;
583 }
584
585 if (component_class->frozen) {
586 BT_LOGW("Invalid parameter: component class is frozen: "
587 "addr=%p, name=\"%s\", type=%s",
588 component_class,
589 bt_component_class_get_name(component_class),
590 bt_component_class_type_string(component_class->type));
591 ret = -1;
592 goto end;
593 }
594
595 source_class = container_of(component_class,
596 struct bt_component_class_source, parent);
597 source_class->methods.iterator.finalize =
598 method;
599 BT_LOGV("Set filter component class's notification iterator finalization method: "
600 "addr=%p, name=\"%s\", method-addr=%p",
601 component_class,
602 bt_component_class_get_name(component_class),
603 method);
604
605 end:
606 return ret;
607 }
608
609 int bt_component_class_filter_set_notification_iterator_init_method(
610 struct bt_component_class *component_class,
611 bt_component_class_notification_iterator_init_method method)
612 {
613 struct bt_component_class_filter *filter_class;
614 int ret = 0;
615
616 if (!component_class) {
617 BT_LOGW_STR("Invalid parameter: component class is NULL.");
618 ret = -1;
619 goto end;
620 }
621
622 if (!method) {
623 BT_LOGW_STR("Invalid parameter: method is NULL.");
624 ret = -1;
625 goto end;
626 }
627
628 if (component_class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
629 BT_LOGW("Invalid parameter: component class is not a filter component class: "
630 "addr=%p, name=\"%s\", type=%s",
631 component_class,
632 bt_component_class_get_name(component_class),
633 bt_component_class_type_string(component_class->type));
634 ret = -1;
635 goto end;
636 }
637
638 if (component_class->frozen) {
639 BT_LOGW("Invalid parameter: component class is frozen: "
640 "addr=%p, name=\"%s\", type=%s",
641 component_class,
642 bt_component_class_get_name(component_class),
643 bt_component_class_type_string(component_class->type));
644 ret = -1;
645 goto end;
646 }
647
648 filter_class = container_of(component_class,
649 struct bt_component_class_filter, parent);
650 filter_class->methods.iterator.init = method;
651 BT_LOGV("Set filter component class's notification iterator initialization method: "
652 "addr=%p, name=\"%s\", method-addr=%p",
653 component_class,
654 bt_component_class_get_name(component_class),
655 method);
656
657 end:
658 return ret;
659 }
660
661 int bt_component_class_filter_set_notification_iterator_finalize_method(
662 struct bt_component_class *component_class,
663 bt_component_class_notification_iterator_finalize_method method)
664 {
665 struct bt_component_class_filter *filter_class;
666 int ret = 0;
667
668 if (!component_class) {
669 BT_LOGW_STR("Invalid parameter: component class is NULL.");
670 ret = -1;
671 goto end;
672 }
673
674 if (!method) {
675 BT_LOGW_STR("Invalid parameter: method is NULL.");
676 ret = -1;
677 goto end;
678 }
679
680 if (component_class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
681 BT_LOGW("Invalid parameter: component class is not a filter component class: "
682 "addr=%p, name=\"%s\", type=%s",
683 component_class,
684 bt_component_class_get_name(component_class),
685 bt_component_class_type_string(component_class->type));
686 ret = -1;
687 goto end;
688 }
689
690 if (component_class->frozen) {
691 BT_LOGW("Invalid parameter: component class is frozen: "
692 "addr=%p, name=\"%s\", type=%s",
693 component_class,
694 bt_component_class_get_name(component_class),
695 bt_component_class_type_string(component_class->type));
696 ret = -1;
697 goto end;
698 }
699
700 filter_class = container_of(component_class,
701 struct bt_component_class_filter, parent);
702 filter_class->methods.iterator.finalize =
703 method;
704 BT_LOGV("Set filter component class's notification iterator finalization method: "
705 "addr=%p, name=\"%s\", method-addr=%p",
706 component_class,
707 bt_component_class_get_name(component_class),
708 method);
709
710 end:
711 return ret;
712 }
713
714 int bt_component_class_set_description(
715 struct bt_component_class *component_class,
716 const char *description)
717 {
718 int ret = 0;
719
720 if (!component_class) {
721 BT_LOGW_STR("Invalid parameter: component class is NULL.");
722 ret = -1;
723 goto end;
724 }
725
726 if (!description) {
727 BT_LOGW_STR("Invalid parameter: description is NULL.");
728 ret = -1;
729 goto end;
730 }
731
732 if (component_class->frozen) {
733 BT_LOGW("Invalid parameter: component class is frozen: "
734 "addr=%p, name=\"%s\", type=%s",
735 component_class,
736 bt_component_class_get_name(component_class),
737 bt_component_class_type_string(component_class->type));
738 ret = -1;
739 goto end;
740 }
741
742 g_string_assign(component_class->description, description);
743 BT_LOGV("Set component class's description: "
744 "addr=%p, name=\"%s\", type=%s",
745 component_class,
746 bt_component_class_get_name(component_class),
747 bt_component_class_type_string(component_class->type));
748
749 end:
750 return ret;
751 }
752
753 int bt_component_class_set_help(
754 struct bt_component_class *component_class,
755 const char *help)
756 {
757 int ret = 0;
758
759 if (!component_class) {
760 BT_LOGW_STR("Invalid parameter: component class is NULL.");
761 ret = -1;
762 goto end;
763 }
764
765 if (!help) {
766 BT_LOGW_STR("Invalid parameter: help is NULL.");
767 ret = -1;
768 goto end;
769 }
770
771 if (component_class->frozen) {
772 BT_LOGW("Invalid parameter: component class is frozen: "
773 "addr=%p, name=\"%s\", type=%s",
774 component_class,
775 bt_component_class_get_name(component_class),
776 bt_component_class_type_string(component_class->type));
777 ret = -1;
778 goto end;
779 }
780
781 g_string_assign(component_class->help, help);
782 BT_LOGV("Set component class's help text: "
783 "addr=%p, name=\"%s\", type=%s",
784 component_class,
785 bt_component_class_get_name(component_class),
786 bt_component_class_type_string(component_class->type));
787
788 end:
789 return ret;
790 }
791
792 const char *bt_component_class_get_name(
793 struct bt_component_class *component_class)
794 {
795 return component_class ? component_class->name->str : NULL;
796 }
797
798 enum bt_component_class_type bt_component_class_get_type(
799 struct bt_component_class *component_class)
800 {
801 return component_class ? component_class->type :
802 BT_COMPONENT_CLASS_TYPE_UNKNOWN;
803 }
804
805 const char *bt_component_class_get_description(
806 struct bt_component_class *component_class)
807 {
808 return component_class && component_class->description &&
809 component_class->description->str[0] != '\0' ?
810 component_class->description->str : NULL;
811 }
812
813 const char *bt_component_class_get_help(
814 struct bt_component_class *component_class)
815 {
816 return component_class && component_class->help &&
817 component_class->help->str[0] != '\0' ?
818 component_class->help->str : NULL;
819 }
820
821 BT_HIDDEN
822 void bt_component_class_add_destroy_listener(struct bt_component_class *class,
823 bt_component_class_destroy_listener_func func, void *data)
824 {
825 struct bt_component_class_destroy_listener listener;
826
827 assert(class);
828 assert(func);
829 listener.func = func;
830 listener.data = data;
831 g_array_append_val(class->destroy_listeners, listener);
832 BT_LOGV("Component class has no registered query method: "
833 "comp-class-addr=%p, comp-class-name=\"%s\", comp-class-type=%s"
834 "func-addr=%p, data-addr=%p",
835 class,
836 bt_component_class_get_name(class),
837 bt_component_class_type_string(class->type),
838 func, data);
839 }
840
841 int bt_component_class_freeze(
842 struct bt_component_class *component_class)
843 {
844 int ret = 0;
845
846 if (!component_class) {
847 BT_LOGW_STR("Invalid parameter: component class is NULL.");
848 ret = -1;
849 goto end;
850 }
851
852 if (component_class->frozen) {
853 goto end;
854 }
855
856 BT_LOGD("Freezing component class: "
857 "addr=%p, name=\"%s\", type=%s",
858 component_class,
859 bt_component_class_get_name(component_class),
860 bt_component_class_type_string(component_class->type));
861 component_class->frozen = BT_TRUE;
862
863 end:
864 return ret;
865 }
This page took 0.075075 seconds and 4 git commands to generate.