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