Add query executor
[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 notification_iterator_next_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 (!notification_iterator_next_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, notification_iterator_next_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 = notification_iterator_next_method;
162 BT_LOGD("Created source component class: "
163 "name=\"%s\", notif-iter-next-method-addr=%p, addr=%p",
164 name, notification_iterator_next_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 notification_iterator_next_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 (!notification_iterator_next_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, notification_iterator_next_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 = notification_iterator_next_method;
209 BT_LOGD("Created filter component class: "
210 "name=\"%s\", notif-iter-next-method-addr=%p, addr=%p",
211 name, notification_iterator_next_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 consume_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 (!consume_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, consume_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 = consume_method;
256 BT_LOGD("Created sink component class: "
257 "name=\"%s\", consume-method-addr=%p, addr=%p",
258 name, consume_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 init_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 (!init_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 = 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 init_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 query_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 (!query_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 = 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 query_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 finalize_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 (!finalize_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 = 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 finalize_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 notification_iterator_init_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 (!notification_iterator_init_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 = notification_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 notification_iterator_init_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 notification_iterator_finalize_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 (!notification_iterator_finalize_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 notification_iterator_finalize_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 notification_iterator_finalize_method);
604
605 end:
606 return ret;
607 }
608
609 int bt_component_class_source_set_notification_iterator_seek_time_method(
610 struct bt_component_class *component_class,
611 bt_component_class_notification_iterator_seek_time_method notification_iterator_seek_time_method)
612 {
613 struct bt_component_class_source *source_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 (!notification_iterator_seek_time_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_SOURCE) {
629 BT_LOGW("Invalid parameter: component class is not a source 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 source_class = container_of(component_class,
649 struct bt_component_class_source, parent);
650 source_class->methods.iterator.seek_time =
651 notification_iterator_seek_time_method;
652 BT_LOGV("Set source component class's notification iterator seek time method: "
653 "addr=%p, name=\"%s\", method-addr=%p",
654 component_class,
655 bt_component_class_get_name(component_class),
656 notification_iterator_seek_time_method);
657
658 end:
659 return ret;
660 }
661
662 int bt_component_class_filter_set_notification_iterator_init_method(
663 struct bt_component_class *component_class,
664 bt_component_class_notification_iterator_init_method notification_iterator_init_method)
665 {
666 struct bt_component_class_filter *filter_class;
667 int ret = 0;
668
669 if (!component_class) {
670 BT_LOGW_STR("Invalid parameter: component class is NULL.");
671 ret = -1;
672 goto end;
673 }
674
675 if (!notification_iterator_init_method) {
676 BT_LOGW_STR("Invalid parameter: method is NULL.");
677 ret = -1;
678 goto end;
679 }
680
681 if (component_class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
682 BT_LOGW("Invalid parameter: component class is not a filter component class: "
683 "addr=%p, name=\"%s\", type=%s",
684 component_class,
685 bt_component_class_get_name(component_class),
686 bt_component_class_type_string(component_class->type));
687 ret = -1;
688 goto end;
689 }
690
691 if (component_class->frozen) {
692 BT_LOGW("Invalid parameter: component class is frozen: "
693 "addr=%p, name=\"%s\", type=%s",
694 component_class,
695 bt_component_class_get_name(component_class),
696 bt_component_class_type_string(component_class->type));
697 ret = -1;
698 goto end;
699 }
700
701 filter_class = container_of(component_class,
702 struct bt_component_class_filter, parent);
703 filter_class->methods.iterator.init = notification_iterator_init_method;
704 BT_LOGV("Set filter component class's notification iterator initialization method: "
705 "addr=%p, name=\"%s\", method-addr=%p",
706 component_class,
707 bt_component_class_get_name(component_class),
708 notification_iterator_init_method);
709
710 end:
711 return ret;
712 }
713
714 int bt_component_class_filter_set_notification_iterator_finalize_method(
715 struct bt_component_class *component_class,
716 bt_component_class_notification_iterator_finalize_method notification_iterator_finalize_method)
717 {
718 struct bt_component_class_filter *filter_class;
719 int ret = 0;
720
721 if (!component_class) {
722 BT_LOGW_STR("Invalid parameter: component class is NULL.");
723 ret = -1;
724 goto end;
725 }
726
727 if (!notification_iterator_finalize_method) {
728 BT_LOGW_STR("Invalid parameter: method is NULL.");
729 ret = -1;
730 goto end;
731 }
732
733 if (component_class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
734 BT_LOGW("Invalid parameter: component class is not a filter component class: "
735 "addr=%p, name=\"%s\", type=%s",
736 component_class,
737 bt_component_class_get_name(component_class),
738 bt_component_class_type_string(component_class->type));
739 ret = -1;
740 goto end;
741 }
742
743 if (component_class->frozen) {
744 BT_LOGW("Invalid parameter: component class is frozen: "
745 "addr=%p, name=\"%s\", type=%s",
746 component_class,
747 bt_component_class_get_name(component_class),
748 bt_component_class_type_string(component_class->type));
749 ret = -1;
750 goto end;
751 }
752
753 filter_class = container_of(component_class,
754 struct bt_component_class_filter, parent);
755 filter_class->methods.iterator.finalize =
756 notification_iterator_finalize_method;
757 BT_LOGV("Set filter component class's notification iterator finalization method: "
758 "addr=%p, name=\"%s\", method-addr=%p",
759 component_class,
760 bt_component_class_get_name(component_class),
761 notification_iterator_finalize_method);
762
763 end:
764 return ret;
765 }
766
767 int bt_component_class_filter_set_notification_iterator_seek_time_method(
768 struct bt_component_class *component_class,
769 bt_component_class_notification_iterator_seek_time_method notification_iterator_seek_time_method)
770 {
771 struct bt_component_class_filter *filter_class;
772 int ret = 0;
773
774 if (!component_class) {
775 BT_LOGW_STR("Invalid parameter: component class is NULL.");
776 ret = -1;
777 goto end;
778 }
779
780 if (!notification_iterator_seek_time_method) {
781 BT_LOGW_STR("Invalid parameter: method is NULL.");
782 ret = -1;
783 goto end;
784 }
785
786 if (component_class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
787 BT_LOGW("Invalid parameter: component class is not a filter component class: "
788 "addr=%p, name=\"%s\", type=%s",
789 component_class,
790 bt_component_class_get_name(component_class),
791 bt_component_class_type_string(component_class->type));
792 ret = -1;
793 goto end;
794 }
795
796 if (component_class->frozen) {
797 BT_LOGW("Invalid parameter: component class is frozen: "
798 "addr=%p, name=\"%s\", type=%s",
799 component_class,
800 bt_component_class_get_name(component_class),
801 bt_component_class_type_string(component_class->type));
802 ret = -1;
803 goto end;
804 }
805
806 filter_class = container_of(component_class,
807 struct bt_component_class_filter, parent);
808 filter_class->methods.iterator.seek_time =
809 notification_iterator_seek_time_method;
810 BT_LOGV("Set filter component class's notification iterator seek time method: "
811 "addr=%p, name=\"%s\", method-addr=%p",
812 component_class,
813 bt_component_class_get_name(component_class),
814 notification_iterator_seek_time_method);
815
816 end:
817 return ret;
818 }
819
820 int bt_component_class_set_description(
821 struct bt_component_class *component_class,
822 const char *description)
823 {
824 int ret = 0;
825
826 if (!component_class) {
827 BT_LOGW_STR("Invalid parameter: component class is NULL.");
828 ret = -1;
829 goto end;
830 }
831
832 if (!description) {
833 BT_LOGW_STR("Invalid parameter: description is NULL.");
834 ret = -1;
835 goto end;
836 }
837
838 if (component_class->frozen) {
839 BT_LOGW("Invalid parameter: component class is frozen: "
840 "addr=%p, name=\"%s\", type=%s",
841 component_class,
842 bt_component_class_get_name(component_class),
843 bt_component_class_type_string(component_class->type));
844 ret = -1;
845 goto end;
846 }
847
848 g_string_assign(component_class->description, description);
849 BT_LOGV("Set component class's description: "
850 "addr=%p, name=\"%s\", type=%s",
851 component_class,
852 bt_component_class_get_name(component_class),
853 bt_component_class_type_string(component_class->type));
854
855 end:
856 return ret;
857 }
858
859 int bt_component_class_set_help(
860 struct bt_component_class *component_class,
861 const char *help)
862 {
863 int ret = 0;
864
865 if (!component_class) {
866 BT_LOGW_STR("Invalid parameter: component class is NULL.");
867 ret = -1;
868 goto end;
869 }
870
871 if (!help) {
872 BT_LOGW_STR("Invalid parameter: help is NULL.");
873 ret = -1;
874 goto end;
875 }
876
877 if (component_class->frozen) {
878 BT_LOGW("Invalid parameter: component class is frozen: "
879 "addr=%p, name=\"%s\", type=%s",
880 component_class,
881 bt_component_class_get_name(component_class),
882 bt_component_class_type_string(component_class->type));
883 ret = -1;
884 goto end;
885 }
886
887 g_string_assign(component_class->help, help);
888 BT_LOGV("Set component class's help text: "
889 "addr=%p, name=\"%s\", type=%s",
890 component_class,
891 bt_component_class_get_name(component_class),
892 bt_component_class_type_string(component_class->type));
893
894 end:
895 return ret;
896 }
897
898 const char *bt_component_class_get_name(
899 struct bt_component_class *component_class)
900 {
901 return component_class ? component_class->name->str : NULL;
902 }
903
904 enum bt_component_class_type bt_component_class_get_type(
905 struct bt_component_class *component_class)
906 {
907 return component_class ? component_class->type :
908 BT_COMPONENT_CLASS_TYPE_UNKNOWN;
909 }
910
911 const char *bt_component_class_get_description(
912 struct bt_component_class *component_class)
913 {
914 return component_class && component_class->description &&
915 component_class->description->str[0] != '\0' ?
916 component_class->description->str : NULL;
917 }
918
919 const char *bt_component_class_get_help(
920 struct bt_component_class *component_class)
921 {
922 return component_class && component_class->help &&
923 component_class->help->str[0] != '\0' ?
924 component_class->help->str : NULL;
925 }
926
927 BT_HIDDEN
928 void bt_component_class_add_destroy_listener(struct bt_component_class *class,
929 bt_component_class_destroy_listener_func func, void *data)
930 {
931 struct bt_component_class_destroy_listener listener;
932
933 assert(class);
934 assert(func);
935 listener.func = func;
936 listener.data = data;
937 g_array_append_val(class->destroy_listeners, listener);
938 BT_LOGV("Component class has no registered query method: "
939 "comp-class-addr=%p, comp-class-name=\"%s\", comp-class-type=%s"
940 "func-addr=%p, data-addr=%p",
941 class,
942 bt_component_class_get_name(class),
943 bt_component_class_type_string(class->type),
944 func, data);
945 }
946
947 int bt_component_class_freeze(
948 struct bt_component_class *component_class)
949 {
950 int ret = 0;
951
952 if (!component_class) {
953 BT_LOGW_STR("Invalid parameter: component class is NULL.");
954 ret = -1;
955 goto end;
956 }
957
958 if (component_class->frozen) {
959 goto end;
960 }
961
962 BT_LOGD("Freezing component class: "
963 "addr=%p, name=\"%s\", type=%s",
964 component_class,
965 bt_component_class_get_name(component_class),
966 bt_component_class_type_string(component_class->type));
967 component_class->frozen = BT_TRUE;
968
969 end:
970 return ret;
971 }
This page took 0.079761 seconds and 4 git commands to generate.