lib: make it mandatory to have seek_X if can_seek_X is defined
[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_DEV_COMP_CLS_HOT(_cc) \
45 BT_ASSERT_PRE_DEV_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_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
110 goto error;
111 }
112
113 class->description = g_string_new(NULL);
114 if (!class->description) {
115 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
116 goto error;
117 }
118
119 class->help = g_string_new(NULL);
120 if (!class->help) {
121 BT_LIB_LOGE_APPEND_CAUSE("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_LIB_LOGE_APPEND_CAUSE("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_LIB_LOGE_APPEND_CAUSE("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_LIB_LOGE_APPEND_CAUSE(
163 "Failed to allocate one source component class.");
164 goto end;
165 }
166
167 /* bt_component_class_init() logs errors */
168 ret = bt_component_class_init(&source_class->parent,
169 BT_COMPONENT_CLASS_TYPE_SOURCE, name);
170 if (ret) {
171 /*
172 * If bt_component_class_init() fails, the component
173 * class is put, therefore its memory is already
174 * freed.
175 */
176 source_class = NULL;
177 goto end;
178 }
179
180 source_class->methods.msg_iter_next = method;
181 BT_LIB_LOGI("Created source component class: %!+C", source_class);
182
183 end:
184 return (void *) source_class;
185 }
186
187 struct bt_component_class_filter *bt_component_class_filter_create(
188 const char *name,
189 bt_component_class_filter_message_iterator_next_method method)
190 {
191 struct bt_component_class_filter *filter_class = NULL;
192 int ret;
193
194 BT_ASSERT_PRE_NON_NULL(name, "Name");
195 BT_ASSERT_PRE_NON_NULL(method, "Message iterator next method");
196 BT_LOGI("Creating filter component class: "
197 "name=\"%s\", msg-iter-next-method-addr=%p",
198 name, method);
199 filter_class = g_new0(struct bt_component_class_filter, 1);
200 if (!filter_class) {
201 BT_LIB_LOGE_APPEND_CAUSE(
202 "Failed to allocate one filter component class.");
203 goto end;
204 }
205
206 /* bt_component_class_init() logs errors */
207 ret = bt_component_class_init(&filter_class->parent,
208 BT_COMPONENT_CLASS_TYPE_FILTER, name);
209 if (ret) {
210 /*
211 * If bt_component_class_init() fails, the component
212 * class is put, therefore its memory is already
213 * freed.
214 */
215 filter_class = NULL;
216 goto end;
217 }
218
219 filter_class->methods.msg_iter_next = method;
220 BT_LIB_LOGI("Created filter component class: %!+C", filter_class);
221
222 end:
223 return (void *) filter_class;
224 }
225
226 struct bt_component_class_sink *bt_component_class_sink_create(
227 const char *name, bt_component_class_sink_consume_method method)
228 {
229 struct bt_component_class_sink *sink_class = NULL;
230 int ret;
231
232 BT_ASSERT_PRE_NON_NULL(name, "Name");
233 BT_ASSERT_PRE_NON_NULL(method, "Consume next method");
234 BT_LOGI("Creating sink component class: "
235 "name=\"%s\", consume-method-addr=%p",
236 name, method);
237 sink_class = g_new0(struct bt_component_class_sink, 1);
238 if (!sink_class) {
239 BT_LIB_LOGE_APPEND_CAUSE(
240 "Failed to allocate one sink component class.");
241 goto end;
242 }
243
244 /* bt_component_class_init() logs errors */
245 ret = bt_component_class_init(&sink_class->parent,
246 BT_COMPONENT_CLASS_TYPE_SINK, name);
247 if (ret) {
248 /*
249 * If bt_component_class_init() fails, the component
250 * class is put, therefore its memory is already
251 * freed.
252 */
253 sink_class = NULL;
254 goto end;
255 }
256
257 sink_class->methods.consume = method;
258 BT_LIB_LOGI("Created sink component class: %!+C", sink_class);
259
260 end:
261 return (void *) sink_class;
262 }
263
264 enum bt_component_class_set_method_status
265 bt_component_class_source_set_get_supported_mip_versions_method(
266 struct bt_component_class_source *comp_cls,
267 bt_component_class_source_get_supported_mip_versions_method method)
268 {
269 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
270 BT_ASSERT_PRE_NON_NULL(method, "Method");
271 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
272 comp_cls->methods.get_supported_mip_versions = method;
273 BT_LIB_LOGD("Set source component class's \"get supported MIP versions\" method: "
274 "%!+C", comp_cls);
275 return BT_FUNC_STATUS_OK;
276 }
277
278 enum bt_component_class_set_method_status
279 bt_component_class_filter_set_get_supported_mip_versions_method(
280 struct bt_component_class_filter *comp_cls,
281 bt_component_class_filter_get_supported_mip_versions_method method)
282 {
283 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
284 BT_ASSERT_PRE_NON_NULL(method, "Method");
285 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
286 comp_cls->methods.get_supported_mip_versions = method;
287 BT_LIB_LOGD("Set filter component class's \"get supported MIP versions\" method: "
288 "%!+C", comp_cls);
289 return BT_FUNC_STATUS_OK;
290 }
291
292 enum bt_component_class_set_method_status
293 bt_component_class_sink_set_get_supported_mip_versions_method(
294 struct bt_component_class_sink *comp_cls,
295 bt_component_class_sink_get_supported_mip_versions_method method)
296 {
297 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
298 BT_ASSERT_PRE_NON_NULL(method, "Method");
299 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
300 comp_cls->methods.get_supported_mip_versions = method;
301 BT_LIB_LOGD("Set sink component class's \"get supported MIP versions\" method: "
302 "%!+C", comp_cls);
303 return BT_FUNC_STATUS_OK;
304 }
305
306 enum bt_component_class_set_method_status
307 bt_component_class_source_set_initialize_method(
308 struct bt_component_class_source *comp_cls,
309 bt_component_class_source_initialize_method method)
310 {
311 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
312 BT_ASSERT_PRE_NON_NULL(method, "Method");
313 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
314 comp_cls->methods.init = method;
315 BT_LIB_LOGD("Set source component class's initialization method: "
316 "%!+C", comp_cls);
317 return BT_FUNC_STATUS_OK;
318 }
319
320 enum bt_component_class_set_method_status
321 bt_component_class_filter_set_initialize_method(
322 struct bt_component_class_filter *comp_cls,
323 bt_component_class_filter_initialize_method method)
324 {
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.init = method;
329 BT_LIB_LOGD("Set filter component class's initialization 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_sink_set_initialize_method(
336 struct bt_component_class_sink *comp_cls,
337 bt_component_class_sink_initialize_method method)
338 {
339 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
340 BT_ASSERT_PRE_NON_NULL(method, "Method");
341 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
342 comp_cls->methods.init = method;
343 BT_LIB_LOGD("Set sink component class's initialization method: "
344 "%!+C", comp_cls);
345 return BT_FUNC_STATUS_OK;
346 }
347
348 enum bt_component_class_set_method_status
349 bt_component_class_source_set_finalize_method(
350 struct bt_component_class_source *comp_cls,
351 bt_component_class_source_finalize_method method)
352 {
353 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
354 BT_ASSERT_PRE_NON_NULL(method, "Method");
355 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
356 comp_cls->methods.finalize = method;
357 BT_LIB_LOGD("Set source component class's finalization method: "
358 "%!+C", comp_cls);
359 return BT_FUNC_STATUS_OK;
360 }
361
362 enum bt_component_class_set_method_status
363 bt_component_class_filter_set_finalize_method(
364 struct bt_component_class_filter *comp_cls,
365 bt_component_class_filter_finalize_method method)
366 {
367 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
368 BT_ASSERT_PRE_NON_NULL(method, "Method");
369 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
370 comp_cls->methods.finalize = method;
371 BT_LIB_LOGD("Set filter component class's finalization method: "
372 "%!+C", comp_cls);
373 return BT_FUNC_STATUS_OK;
374 }
375
376 enum bt_component_class_set_method_status
377 bt_component_class_sink_set_finalize_method(
378 struct bt_component_class_sink *comp_cls,
379 bt_component_class_sink_finalize_method method)
380 {
381 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
382 BT_ASSERT_PRE_NON_NULL(method, "Method");
383 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
384 comp_cls->methods.finalize = method;
385 BT_LIB_LOGD("Set sink component class's finalization method: "
386 "%!+C", comp_cls);
387 return BT_FUNC_STATUS_OK;
388 }
389
390 enum bt_component_class_set_method_status
391 bt_component_class_source_set_query_method(
392 struct bt_component_class_source *comp_cls,
393 bt_component_class_source_query_method method)
394 {
395 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
396 BT_ASSERT_PRE_NON_NULL(method, "Method");
397 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
398 comp_cls->methods.query = method;
399 BT_LIB_LOGD("Set source component class's query method: "
400 "%!+C", comp_cls);
401 return BT_FUNC_STATUS_OK;
402 }
403
404 enum bt_component_class_set_method_status
405 bt_component_class_filter_set_query_method(
406 struct bt_component_class_filter *comp_cls,
407 bt_component_class_filter_query_method method)
408 {
409 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
410 BT_ASSERT_PRE_NON_NULL(method, "Method");
411 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
412 comp_cls->methods.query = method;
413 BT_LIB_LOGD("Set filter component class's query method: "
414 "%!+C", comp_cls);
415 return BT_FUNC_STATUS_OK;
416 }
417
418 enum bt_component_class_set_method_status
419 bt_component_class_sink_set_query_method(
420 struct bt_component_class_sink *comp_cls,
421 bt_component_class_sink_query_method method)
422 {
423 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
424 BT_ASSERT_PRE_NON_NULL(method, "Method");
425 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
426 comp_cls->methods.query = method;
427 BT_LIB_LOGD("Set sink component class's query method: "
428 "%!+C", comp_cls);
429 return BT_FUNC_STATUS_OK;
430 }
431
432 enum bt_component_class_set_method_status
433 bt_component_class_filter_set_input_port_connected_method(
434 struct bt_component_class_filter *comp_cls,
435 bt_component_class_filter_input_port_connected_method method)
436 {
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.input_port_connected = method;
441 BT_LIB_LOGD("Set filter component class's \"input port connected\" 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_sink_set_input_port_connected_method(
448 struct bt_component_class_sink *comp_cls,
449 bt_component_class_sink_input_port_connected_method method)
450 {
451 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
452 BT_ASSERT_PRE_NON_NULL(method, "Method");
453 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
454 comp_cls->methods.input_port_connected = method;
455 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
456 ": %!+C", comp_cls);
457 return BT_FUNC_STATUS_OK;
458 }
459
460 enum bt_component_class_set_method_status
461 bt_component_class_source_set_output_port_connected_method(
462 struct bt_component_class_source *comp_cls,
463 bt_component_class_source_output_port_connected_method method)
464 {
465 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
466 BT_ASSERT_PRE_NON_NULL(method, "Method");
467 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
468 comp_cls->methods.output_port_connected = method;
469 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
470 ": %!+C", comp_cls);
471 return BT_FUNC_STATUS_OK;
472 }
473
474 enum bt_component_class_set_method_status
475 bt_component_class_filter_set_output_port_connected_method(
476 struct bt_component_class_filter *comp_cls,
477 bt_component_class_filter_output_port_connected_method method)
478 {
479 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
480 BT_ASSERT_PRE_NON_NULL(method, "Method");
481 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
482 comp_cls->methods.output_port_connected = method;
483 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
484 ": %!+C", comp_cls);
485 return BT_FUNC_STATUS_OK;
486 }
487
488 enum bt_component_class_set_method_status
489 bt_component_class_sink_set_graph_is_configured_method(
490 struct bt_component_class_sink *comp_cls,
491 bt_component_class_sink_graph_is_configured_method method)
492 {
493 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
494 BT_ASSERT_PRE_NON_NULL(method, "Method");
495 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
496 comp_cls->methods.graph_is_configured = method;
497 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
498 ": %!+C", comp_cls);
499 return BT_FUNC_STATUS_OK;
500 }
501
502 enum bt_component_class_set_method_status
503 bt_component_class_source_set_message_iterator_initialize_method(
504 struct bt_component_class_source *comp_cls,
505 bt_component_class_source_message_iterator_initialize_method method)
506 {
507 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
508 BT_ASSERT_PRE_NON_NULL(method, "Method");
509 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
510 comp_cls->methods.msg_iter_initialize = method;
511 BT_LIB_LOGD("Set source component class's message iterator initialization method"
512 ": %!+C", comp_cls);
513 return BT_FUNC_STATUS_OK;
514 }
515
516 enum bt_component_class_set_method_status
517 bt_component_class_filter_set_message_iterator_initialize_method(
518 struct bt_component_class_filter *comp_cls,
519 bt_component_class_filter_message_iterator_initialize_method method)
520 {
521 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
522 BT_ASSERT_PRE_NON_NULL(method, "Method");
523 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
524 comp_cls->methods.msg_iter_initialize = method;
525 BT_LIB_LOGD("Set filter component class's message iterator initialization method"
526 ": %!+C", comp_cls);
527 return BT_FUNC_STATUS_OK;
528 }
529
530 enum bt_component_class_set_method_status
531 bt_component_class_source_set_message_iterator_finalize_method(
532 struct bt_component_class_source *comp_cls,
533 bt_component_class_source_message_iterator_finalize_method method)
534 {
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.msg_iter_finalize = method;
539 BT_LIB_LOGD("Set source component class's message iterator finalization method"
540 ": %!+C", comp_cls);
541 return BT_FUNC_STATUS_OK;
542 }
543
544 enum bt_component_class_set_method_status
545 bt_component_class_filter_set_message_iterator_finalize_method(
546 struct bt_component_class_filter *comp_cls,
547 bt_component_class_filter_message_iterator_finalize_method method)
548 {
549 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
550 BT_ASSERT_PRE_NON_NULL(method, "Method");
551 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
552 comp_cls->methods.msg_iter_finalize = method;
553 BT_LIB_LOGD("Set filter component class's message iterator finalization method"
554 ": %!+C", comp_cls);
555 return BT_FUNC_STATUS_OK;
556 }
557
558 enum bt_component_class_set_method_status
559 bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods(
560 struct bt_component_class_filter *comp_cls,
561 bt_component_class_filter_message_iterator_seek_ns_from_origin_method seek_method,
562 bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method can_seek_method)
563 {
564 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
565 BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method");
566 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
567 comp_cls->methods.msg_iter_seek_ns_from_origin = seek_method;
568 comp_cls->methods.msg_iter_can_seek_ns_from_origin = can_seek_method;
569 BT_LIB_LOGD("Set filter component class's message iterator \"seek nanoseconds from origin\" method"
570 ": %!+C", comp_cls);
571 return BT_FUNC_STATUS_OK;
572 }
573
574 enum bt_component_class_set_method_status
575 bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods(
576 struct bt_component_class_source *comp_cls,
577 bt_component_class_source_message_iterator_seek_ns_from_origin_method seek_method,
578 bt_component_class_source_message_iterator_can_seek_ns_from_origin_method can_seek_method)
579 {
580 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
581 BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method");
582 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
583 comp_cls->methods.msg_iter_seek_ns_from_origin = seek_method;
584 comp_cls->methods.msg_iter_can_seek_ns_from_origin = can_seek_method;
585 BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" methods"
586 ": %!+C", comp_cls);
587 return BT_FUNC_STATUS_OK;
588 }
589
590 enum bt_component_class_set_method_status
591 bt_component_class_filter_set_message_iterator_seek_beginning_methods(
592 struct bt_component_class_filter *comp_cls,
593 bt_component_class_filter_message_iterator_seek_beginning_method seek_method,
594 bt_component_class_filter_message_iterator_can_seek_beginning_method can_seek_method)
595 {
596 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
597 BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method");
598 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
599 comp_cls->methods.msg_iter_seek_beginning = seek_method;
600 comp_cls->methods.msg_iter_can_seek_beginning = can_seek_method;
601 BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" methods"
602 ": %!+C", comp_cls);
603 return BT_FUNC_STATUS_OK;
604 }
605
606 enum bt_component_class_set_method_status
607 bt_component_class_source_set_message_iterator_seek_beginning_methods(
608 struct bt_component_class_source *comp_cls,
609 bt_component_class_source_message_iterator_seek_beginning_method seek_method,
610 bt_component_class_source_message_iterator_can_seek_beginning_method can_seek_method)
611 {
612 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
613 BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method");
614 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
615 comp_cls->methods.msg_iter_seek_beginning = seek_method;
616 comp_cls->methods.msg_iter_can_seek_beginning = can_seek_method;
617 BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" methods"
618 ": %!+C", comp_cls);
619 return BT_FUNC_STATUS_OK;
620 }
621
622 enum bt_component_class_set_description_status
623 bt_component_class_set_description(
624 struct bt_component_class *comp_cls,
625 const char *description)
626 {
627 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
628 BT_ASSERT_PRE_NON_NULL(description, "Description");
629 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
630 g_string_assign(comp_cls->description, description);
631 BT_LIB_LOGD("Set component class's description: "
632 "addr=%p, name=\"%s\", type=%s",
633 comp_cls,
634 bt_component_class_get_name(comp_cls),
635 bt_component_class_type_string(comp_cls->type));
636 return BT_FUNC_STATUS_OK;
637 }
638
639 enum bt_component_class_set_help_status bt_component_class_set_help(
640 struct bt_component_class *comp_cls,
641 const char *help)
642 {
643 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
644 BT_ASSERT_PRE_NON_NULL(help, "Help");
645 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
646 g_string_assign(comp_cls->help, help);
647 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls);
648 return BT_FUNC_STATUS_OK;
649 }
650
651 const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
652 {
653 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
654 return comp_cls->name->str;
655 }
656
657 enum bt_component_class_type bt_component_class_get_type(
658 const struct bt_component_class *comp_cls)
659 {
660 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
661 return comp_cls->type;
662 }
663
664 const char *bt_component_class_get_description(
665 const struct bt_component_class *comp_cls)
666 {
667 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
668 return comp_cls->description &&
669 comp_cls->description->str[0] != '\0' ?
670 comp_cls->description->str : NULL;
671 }
672
673 const char *bt_component_class_get_help(
674 const struct bt_component_class *comp_cls)
675 {
676 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
677 return comp_cls->help &&
678 comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL;
679 }
680
681 BT_HIDDEN
682 void bt_component_class_add_destroy_listener(
683 struct bt_component_class *comp_cls,
684 bt_component_class_destroy_listener_func func, void *data)
685 {
686 struct bt_component_class_destroy_listener listener;
687
688 BT_ASSERT(comp_cls);
689 BT_ASSERT(func);
690 listener.func = func;
691 listener.data = data;
692 g_array_append_val(comp_cls->destroy_listeners, listener);
693 BT_LIB_LOGD("Added destroy listener to component class: "
694 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
695 }
696
697 BT_HIDDEN
698 void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
699 {
700 BT_ASSERT(comp_cls);
701 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
702 ((struct bt_component_class *) comp_cls)->frozen = true;
703 }
704
705 void bt_component_class_get_ref(
706 const struct bt_component_class *component_class)
707 {
708 bt_object_get_ref(component_class);
709 }
710
711 void bt_component_class_put_ref(
712 const struct bt_component_class *component_class)
713 {
714 bt_object_put_ref(component_class);
715 }
716
717 void bt_component_class_source_get_ref(
718 const struct bt_component_class_source *component_class_source)
719 {
720 bt_object_get_ref(component_class_source);
721 }
722
723 void bt_component_class_source_put_ref(
724 const struct bt_component_class_source *component_class_source)
725 {
726 bt_object_put_ref(component_class_source);
727 }
728
729 void bt_component_class_filter_get_ref(
730 const struct bt_component_class_filter *component_class_filter)
731 {
732 bt_object_get_ref(component_class_filter);
733 }
734
735 void bt_component_class_filter_put_ref(
736 const struct bt_component_class_filter *component_class_filter)
737 {
738 bt_object_put_ref(component_class_filter);
739 }
740
741 void bt_component_class_sink_get_ref(
742 const struct bt_component_class_sink *component_class_sink)
743 {
744 bt_object_get_ref(component_class_sink);
745 }
746
747 void bt_component_class_sink_put_ref(
748 const struct bt_component_class_sink *component_class_sink)
749 {
750 bt_object_put_ref(component_class_sink);
751 }
This page took 0.043949 seconds and 4 git commands to generate.