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