Document libbabeltrace2's C API
[babeltrace.git] / src / lib / graph / component-class.c
1 /*
2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
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:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
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
21 * SOFTWARE.
22 */
23
24 #define BT_LOG_TAG "LIB/COMPONENT-CLASS"
25 #include "lib/logging.h"
26
27 #include "common/assert.h"
28 #include "lib/assert-pre.h"
29 #include "compat/compiler.h"
30 #include <babeltrace2/graph/component-class.h>
31 #include <babeltrace2/types.h>
32 #include <glib.h>
33
34 #include "component-class.h"
35 #include "lib/func-status.h"
36 #include "lib/graph/message-iterator-class.h"
37
38 #define BT_ASSERT_PRE_DEV_COMP_CLS_HOT(_cc) \
39 BT_ASSERT_PRE_DEV_HOT(((const struct bt_component_class *) (_cc)), \
40 "Component class", ": %!+C", (_cc))
41
42 static
43 void destroy_component_class(struct bt_object *obj)
44 {
45 struct bt_component_class *class;
46 int i;
47
48 BT_ASSERT(obj);
49 class = container_of(obj, struct bt_component_class, base);
50
51 BT_LIB_LOGI("Destroying component class: %!+C", class);
52
53 /* Call destroy listeners in reverse registration order */
54 for (i = class->destroy_listeners->len - 1; i >= 0; i--) {
55 struct bt_component_class_destroy_listener *listener =
56 &g_array_index(class->destroy_listeners,
57 struct bt_component_class_destroy_listener,
58 i);
59
60 BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p",
61 listener->func, listener->data);
62 listener->func(class, listener->data);
63 }
64
65 if (class->name) {
66 g_string_free(class->name, TRUE);
67 class->name = NULL;
68 }
69
70 if (class->description) {
71 g_string_free(class->description, TRUE);
72 class->description = NULL;
73 }
74
75 if (class->help) {
76 g_string_free(class->help, TRUE);
77 class->help = NULL;
78 }
79
80 if (class->plugin_name) {
81 g_string_free(class->plugin_name, TRUE);
82 class->plugin_name = NULL;
83 }
84
85 if (class->destroy_listeners) {
86 g_array_free(class->destroy_listeners, TRUE);
87 class->destroy_listeners = NULL;
88 }
89
90 if (bt_component_class_has_message_iterator_class(class)) {
91 struct bt_component_class_with_iterator_class *class_with_iter_class =
92 container_of(class, struct bt_component_class_with_iterator_class, parent);
93
94 BT_ASSERT(class_with_iter_class->msg_iter_cls);
95 bt_message_iterator_class_put_ref(class_with_iter_class->msg_iter_cls);
96 class_with_iter_class->msg_iter_cls = NULL;
97 }
98
99 g_free(class);
100 }
101
102 static
103 int bt_component_class_init(struct bt_component_class *class,
104 enum bt_component_class_type type, const char *name)
105 {
106 int ret = 0;
107
108 bt_object_init_shared(&class->base, destroy_component_class);
109 class->type = type;
110 class->name = g_string_new(name);
111 if (!class->name) {
112 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
113 goto error;
114 }
115
116 class->description = g_string_new(NULL);
117 if (!class->description) {
118 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
119 goto error;
120 }
121
122 class->help = g_string_new(NULL);
123 if (!class->help) {
124 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
125 goto error;
126 }
127
128 class->plugin_name = g_string_new(NULL);
129 if (!class->plugin_name) {
130 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
131 goto error;
132 }
133
134 class->destroy_listeners = g_array_new(FALSE, TRUE,
135 sizeof(struct bt_component_class_destroy_listener));
136 if (!class->destroy_listeners) {
137 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
138 goto error;
139 }
140
141 goto end;
142
143 error:
144 BT_OBJECT_PUT_REF_AND_RESET(class);
145 ret = -1;
146
147 end:
148 return ret;
149 }
150
151 static
152 int bt_component_class_with_iterator_class_init(
153 struct bt_component_class_with_iterator_class *class,
154 enum bt_component_class_type type, const char *name,
155 struct bt_message_iterator_class *message_iterator_class)
156 {
157 int ret;
158
159 ret = bt_component_class_init(&class->parent, type, name);
160 if (ret != 0) {
161 goto end;
162 }
163
164 class->msg_iter_cls = message_iterator_class;
165 bt_message_iterator_class_get_ref(class->msg_iter_cls);
166 bt_message_iterator_class_freeze(class->msg_iter_cls);
167
168 end:
169 return ret;
170 }
171
172 struct bt_component_class_source *bt_component_class_source_create(
173 const char *name,
174 struct bt_message_iterator_class *message_iterator_class)
175 {
176 struct bt_component_class_source *source_class = NULL;
177 int ret;
178
179 BT_ASSERT_PRE_NO_ERROR();
180 BT_ASSERT_PRE_NON_NULL(name, "Name");
181 BT_ASSERT_PRE_NON_NULL(message_iterator_class, "Message iterator class");
182 BT_LIB_LOGI("Creating source component class: "
183 "name=\"%s\", %![msg-iter-cls-]+I",
184 name, message_iterator_class);
185 source_class = g_new0(struct bt_component_class_source, 1);
186 if (!source_class) {
187 BT_LIB_LOGE_APPEND_CAUSE(
188 "Failed to allocate one source component class.");
189 goto end;
190 }
191
192 /* bt_component_class_init() logs errors */
193 ret = bt_component_class_with_iterator_class_init(&source_class->parent,
194 BT_COMPONENT_CLASS_TYPE_SOURCE, name, message_iterator_class);
195 if (ret) {
196 /*
197 * If bt_component_class_init() fails, the component
198 * class is put, therefore its memory is already
199 * freed.
200 */
201 source_class = NULL;
202 goto end;
203 }
204
205 BT_LIB_LOGI("Created source component class: %!+C", source_class);
206
207 end:
208 return (void *) source_class;
209 }
210
211 struct bt_component_class_filter *bt_component_class_filter_create(
212 const char *name,
213 struct bt_message_iterator_class *message_iterator_class)
214 {
215 struct bt_component_class_filter *filter_class = NULL;
216 int ret;
217
218 BT_ASSERT_PRE_NO_ERROR();
219 BT_ASSERT_PRE_NON_NULL(name, "Name");
220 BT_ASSERT_PRE_NON_NULL(message_iterator_class, "Message iterator class");
221 BT_LIB_LOGI("Creating filter component class: "
222 "name=\"%s\", %![msg-iter-cls-]+I",
223 name, message_iterator_class);
224 filter_class = g_new0(struct bt_component_class_filter, 1);
225 if (!filter_class) {
226 BT_LIB_LOGE_APPEND_CAUSE(
227 "Failed to allocate one filter component class.");
228 goto end;
229 }
230
231 /* bt_component_class_init() logs errors */
232 ret = bt_component_class_with_iterator_class_init(&filter_class->parent,
233 BT_COMPONENT_CLASS_TYPE_FILTER, name, message_iterator_class);
234 if (ret) {
235 /*
236 * If bt_component_class_init() fails, the component
237 * class is put, therefore its memory is already
238 * freed.
239 */
240 filter_class = NULL;
241 goto end;
242 }
243
244 BT_LIB_LOGI("Created filter component class: %!+C", filter_class);
245
246 end:
247 return (void *) filter_class;
248 }
249
250 struct bt_component_class_sink *bt_component_class_sink_create(
251 const char *name, bt_component_class_sink_consume_method method)
252 {
253 struct bt_component_class_sink *sink_class = NULL;
254 int ret;
255
256 BT_ASSERT_PRE_NO_ERROR();
257 BT_ASSERT_PRE_NON_NULL(name, "Name");
258 BT_ASSERT_PRE_NON_NULL(method, "Consume next method");
259 BT_LOGI("Creating sink component class: "
260 "name=\"%s\", consume-method-addr=%p",
261 name, method);
262 sink_class = g_new0(struct bt_component_class_sink, 1);
263 if (!sink_class) {
264 BT_LIB_LOGE_APPEND_CAUSE(
265 "Failed to allocate one sink component class.");
266 goto end;
267 }
268
269 /* bt_component_class_init() logs errors */
270 ret = bt_component_class_init(&sink_class->parent,
271 BT_COMPONENT_CLASS_TYPE_SINK, name);
272 if (ret) {
273 /*
274 * If bt_component_class_init() fails, the component
275 * class is put, therefore its memory is already
276 * freed.
277 */
278 sink_class = NULL;
279 goto end;
280 }
281
282 sink_class->methods.consume = method;
283 BT_LIB_LOGI("Created sink component class: %!+C", sink_class);
284
285 end:
286 return (void *) sink_class;
287 }
288
289 enum bt_component_class_set_method_status
290 bt_component_class_source_set_get_supported_mip_versions_method(
291 struct bt_component_class_source *comp_cls,
292 bt_component_class_source_get_supported_mip_versions_method method)
293 {
294 BT_ASSERT_PRE_NO_ERROR();
295 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
296 BT_ASSERT_PRE_NON_NULL(method, "Method");
297 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
298 comp_cls->methods.get_supported_mip_versions = method;
299 BT_LIB_LOGD("Set source component class's \"get supported MIP versions\" method: "
300 "%!+C", comp_cls);
301 return BT_FUNC_STATUS_OK;
302 }
303
304 enum bt_component_class_set_method_status
305 bt_component_class_filter_set_get_supported_mip_versions_method(
306 struct bt_component_class_filter *comp_cls,
307 bt_component_class_filter_get_supported_mip_versions_method method)
308 {
309 BT_ASSERT_PRE_NO_ERROR();
310 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
311 BT_ASSERT_PRE_NON_NULL(method, "Method");
312 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
313 comp_cls->methods.get_supported_mip_versions = method;
314 BT_LIB_LOGD("Set filter component class's \"get supported MIP versions\" method: "
315 "%!+C", comp_cls);
316 return BT_FUNC_STATUS_OK;
317 }
318
319 enum bt_component_class_set_method_status
320 bt_component_class_sink_set_get_supported_mip_versions_method(
321 struct bt_component_class_sink *comp_cls,
322 bt_component_class_sink_get_supported_mip_versions_method method)
323 {
324 BT_ASSERT_PRE_NO_ERROR();
325 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
326 BT_ASSERT_PRE_NON_NULL(method, "Method");
327 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
328 comp_cls->methods.get_supported_mip_versions = method;
329 BT_LIB_LOGD("Set sink component class's \"get supported MIP versions\" method: "
330 "%!+C", comp_cls);
331 return BT_FUNC_STATUS_OK;
332 }
333
334 enum bt_component_class_set_method_status
335 bt_component_class_source_set_initialize_method(
336 struct bt_component_class_source *comp_cls,
337 bt_component_class_source_initialize_method method)
338 {
339 BT_ASSERT_PRE_NO_ERROR();
340 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
341 BT_ASSERT_PRE_NON_NULL(method, "Method");
342 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
343 comp_cls->methods.init = method;
344 BT_LIB_LOGD("Set source component class's initialization method: "
345 "%!+C", comp_cls);
346 return BT_FUNC_STATUS_OK;
347 }
348
349 enum bt_component_class_set_method_status
350 bt_component_class_filter_set_initialize_method(
351 struct bt_component_class_filter *comp_cls,
352 bt_component_class_filter_initialize_method method)
353 {
354 BT_ASSERT_PRE_NO_ERROR();
355 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
356 BT_ASSERT_PRE_NON_NULL(method, "Method");
357 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
358 comp_cls->methods.init = method;
359 BT_LIB_LOGD("Set filter component class's initialization method: "
360 "%!+C", comp_cls);
361 return BT_FUNC_STATUS_OK;
362 }
363
364 enum bt_component_class_set_method_status
365 bt_component_class_sink_set_initialize_method(
366 struct bt_component_class_sink *comp_cls,
367 bt_component_class_sink_initialize_method method)
368 {
369 BT_ASSERT_PRE_NO_ERROR();
370 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
371 BT_ASSERT_PRE_NON_NULL(method, "Method");
372 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
373 comp_cls->methods.init = method;
374 BT_LIB_LOGD("Set sink component class's initialization method: "
375 "%!+C", comp_cls);
376 return BT_FUNC_STATUS_OK;
377 }
378
379 enum bt_component_class_set_method_status
380 bt_component_class_source_set_finalize_method(
381 struct bt_component_class_source *comp_cls,
382 bt_component_class_source_finalize_method method)
383 {
384 BT_ASSERT_PRE_NO_ERROR();
385 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
386 BT_ASSERT_PRE_NON_NULL(method, "Method");
387 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
388 comp_cls->methods.finalize = method;
389 BT_LIB_LOGD("Set source component class's finalization method: "
390 "%!+C", comp_cls);
391 return BT_FUNC_STATUS_OK;
392 }
393
394 enum bt_component_class_set_method_status
395 bt_component_class_filter_set_finalize_method(
396 struct bt_component_class_filter *comp_cls,
397 bt_component_class_filter_finalize_method method)
398 {
399 BT_ASSERT_PRE_NO_ERROR();
400 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
401 BT_ASSERT_PRE_NON_NULL(method, "Method");
402 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
403 comp_cls->methods.finalize = method;
404 BT_LIB_LOGD("Set filter component class's finalization method: "
405 "%!+C", comp_cls);
406 return BT_FUNC_STATUS_OK;
407 }
408
409 enum bt_component_class_set_method_status
410 bt_component_class_sink_set_finalize_method(
411 struct bt_component_class_sink *comp_cls,
412 bt_component_class_sink_finalize_method method)
413 {
414 BT_ASSERT_PRE_NO_ERROR();
415 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
416 BT_ASSERT_PRE_NON_NULL(method, "Method");
417 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
418 comp_cls->methods.finalize = method;
419 BT_LIB_LOGD("Set sink component class's finalization method: "
420 "%!+C", comp_cls);
421 return BT_FUNC_STATUS_OK;
422 }
423
424 enum bt_component_class_set_method_status
425 bt_component_class_source_set_query_method(
426 struct bt_component_class_source *comp_cls,
427 bt_component_class_source_query_method method)
428 {
429 BT_ASSERT_PRE_NO_ERROR();
430 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
431 BT_ASSERT_PRE_NON_NULL(method, "Method");
432 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
433 comp_cls->methods.query = method;
434 BT_LIB_LOGD("Set source component class's query method: "
435 "%!+C", comp_cls);
436 return BT_FUNC_STATUS_OK;
437 }
438
439 enum bt_component_class_set_method_status
440 bt_component_class_filter_set_query_method(
441 struct bt_component_class_filter *comp_cls,
442 bt_component_class_filter_query_method method)
443 {
444 BT_ASSERT_PRE_NO_ERROR();
445 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
446 BT_ASSERT_PRE_NON_NULL(method, "Method");
447 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
448 comp_cls->methods.query = method;
449 BT_LIB_LOGD("Set filter component class's query method: "
450 "%!+C", comp_cls);
451 return BT_FUNC_STATUS_OK;
452 }
453
454 enum bt_component_class_set_method_status
455 bt_component_class_sink_set_query_method(
456 struct bt_component_class_sink *comp_cls,
457 bt_component_class_sink_query_method method)
458 {
459 BT_ASSERT_PRE_NO_ERROR();
460 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
461 BT_ASSERT_PRE_NON_NULL(method, "Method");
462 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
463 comp_cls->methods.query = method;
464 BT_LIB_LOGD("Set sink component class's query method: "
465 "%!+C", comp_cls);
466 return BT_FUNC_STATUS_OK;
467 }
468
469 enum bt_component_class_set_method_status
470 bt_component_class_filter_set_input_port_connected_method(
471 struct bt_component_class_filter *comp_cls,
472 bt_component_class_filter_input_port_connected_method method)
473 {
474 BT_ASSERT_PRE_NO_ERROR();
475 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
476 BT_ASSERT_PRE_NON_NULL(method, "Method");
477 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
478 comp_cls->methods.input_port_connected = method;
479 BT_LIB_LOGD("Set filter component class's \"input port connected\" method"
480 ": %!+C", comp_cls);
481 return BT_FUNC_STATUS_OK;
482 }
483
484 enum bt_component_class_set_method_status
485 bt_component_class_sink_set_input_port_connected_method(
486 struct bt_component_class_sink *comp_cls,
487 bt_component_class_sink_input_port_connected_method method)
488 {
489 BT_ASSERT_PRE_NO_ERROR();
490 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
491 BT_ASSERT_PRE_NON_NULL(method, "Method");
492 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
493 comp_cls->methods.input_port_connected = method;
494 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
495 ": %!+C", comp_cls);
496 return BT_FUNC_STATUS_OK;
497 }
498
499 enum bt_component_class_set_method_status
500 bt_component_class_source_set_output_port_connected_method(
501 struct bt_component_class_source *comp_cls,
502 bt_component_class_source_output_port_connected_method method)
503 {
504 BT_ASSERT_PRE_NO_ERROR();
505 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
506 BT_ASSERT_PRE_NON_NULL(method, "Method");
507 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
508 comp_cls->methods.output_port_connected = method;
509 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
510 ": %!+C", comp_cls);
511 return BT_FUNC_STATUS_OK;
512 }
513
514 enum bt_component_class_set_method_status
515 bt_component_class_filter_set_output_port_connected_method(
516 struct bt_component_class_filter *comp_cls,
517 bt_component_class_filter_output_port_connected_method method)
518 {
519 BT_ASSERT_PRE_NO_ERROR();
520 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
521 BT_ASSERT_PRE_NON_NULL(method, "Method");
522 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
523 comp_cls->methods.output_port_connected = method;
524 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
525 ": %!+C", comp_cls);
526 return BT_FUNC_STATUS_OK;
527 }
528
529 enum bt_component_class_set_method_status
530 bt_component_class_sink_set_graph_is_configured_method(
531 struct bt_component_class_sink *comp_cls,
532 bt_component_class_sink_graph_is_configured_method method)
533 {
534 BT_ASSERT_PRE_NO_ERROR();
535 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
536 BT_ASSERT_PRE_NON_NULL(method, "Method");
537 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
538 comp_cls->methods.graph_is_configured = method;
539 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
540 ": %!+C", comp_cls);
541 return BT_FUNC_STATUS_OK;
542 }
543
544 enum bt_component_class_set_description_status
545 bt_component_class_set_description(
546 struct bt_component_class *comp_cls,
547 const char *description)
548 {
549 BT_ASSERT_PRE_NO_ERROR();
550 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
551 BT_ASSERT_PRE_NON_NULL(description, "Description");
552 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
553 g_string_assign(comp_cls->description, description);
554 BT_LIB_LOGD("Set component class's description: "
555 "addr=%p, name=\"%s\", type=%s",
556 comp_cls,
557 bt_component_class_get_name(comp_cls),
558 bt_component_class_type_string(comp_cls->type));
559 return BT_FUNC_STATUS_OK;
560 }
561
562 enum bt_component_class_set_help_status bt_component_class_set_help(
563 struct bt_component_class *comp_cls,
564 const char *help)
565 {
566 BT_ASSERT_PRE_NO_ERROR();
567 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
568 BT_ASSERT_PRE_NON_NULL(help, "Help");
569 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
570 g_string_assign(comp_cls->help, help);
571 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls);
572 return BT_FUNC_STATUS_OK;
573 }
574
575 const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
576 {
577 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
578 return comp_cls->name->str;
579 }
580
581 enum bt_component_class_type bt_component_class_get_type(
582 const struct bt_component_class *comp_cls)
583 {
584 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
585 return comp_cls->type;
586 }
587
588 const char *bt_component_class_get_description(
589 const struct bt_component_class *comp_cls)
590 {
591 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
592 return comp_cls->description &&
593 comp_cls->description->str[0] != '\0' ?
594 comp_cls->description->str : NULL;
595 }
596
597 const char *bt_component_class_get_help(
598 const struct bt_component_class *comp_cls)
599 {
600 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
601 return comp_cls->help &&
602 comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL;
603 }
604
605 BT_HIDDEN
606 void bt_component_class_add_destroy_listener(
607 struct bt_component_class *comp_cls,
608 bt_component_class_destroy_listener_func func, void *data)
609 {
610 struct bt_component_class_destroy_listener listener;
611
612 BT_ASSERT(comp_cls);
613 BT_ASSERT(func);
614 listener.func = func;
615 listener.data = data;
616 g_array_append_val(comp_cls->destroy_listeners, listener);
617 BT_LIB_LOGD("Added destroy listener to component class: "
618 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
619 }
620
621 BT_HIDDEN
622 void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
623 {
624 BT_ASSERT(comp_cls);
625 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
626 ((struct bt_component_class *) comp_cls)->frozen = true;
627 }
628
629 void bt_component_class_get_ref(
630 const struct bt_component_class *component_class)
631 {
632 bt_object_get_ref(component_class);
633 }
634
635 void bt_component_class_put_ref(
636 const struct bt_component_class *component_class)
637 {
638 bt_object_put_ref(component_class);
639 }
640
641 void bt_component_class_source_get_ref(
642 const struct bt_component_class_source *component_class_source)
643 {
644 bt_object_get_ref(component_class_source);
645 }
646
647 void bt_component_class_source_put_ref(
648 const struct bt_component_class_source *component_class_source)
649 {
650 bt_object_put_ref(component_class_source);
651 }
652
653 void bt_component_class_filter_get_ref(
654 const struct bt_component_class_filter *component_class_filter)
655 {
656 bt_object_get_ref(component_class_filter);
657 }
658
659 void bt_component_class_filter_put_ref(
660 const struct bt_component_class_filter *component_class_filter)
661 {
662 bt_object_put_ref(component_class_filter);
663 }
664
665 void bt_component_class_sink_get_ref(
666 const struct bt_component_class_sink *component_class_sink)
667 {
668 bt_object_get_ref(component_class_sink);
669 }
670
671 void bt_component_class_sink_put_ref(
672 const struct bt_component_class_sink *component_class_sink)
673 {
674 bt_object_put_ref(component_class_sink);
675 }
This page took 0.04313 seconds and 4 git commands to generate.