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