Visibility hidden by default
[babeltrace.git] / src / lib / error.c
CommitLineData
553c4bab 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
553c4bab 3 *
0235b0db 4 * Copyright (c) 2019 Philippe Proulx <pproulx@efficios.com>
553c4bab
PP
5 */
6
7#define BT_LOG_TAG "LIB/ERROR"
8#include "lib/logging.h"
9
10#include <stdlib.h>
11#include <stdint.h>
4fa90f32 12#include <babeltrace2/babeltrace.h>
553c4bab
PP
13
14#include "error.h"
15#include "graph/message/iterator.h"
16#include "graph/component.h"
17#include "graph/component-class.h"
18#include "common/assert.h"
d98421f2 19#include "lib/assert-cond.h"
553c4bab
PP
20#include "lib/func-status.h"
21
1778c2a4
PP
22#define BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(_cause, _exp_type_name, _exp_type) \
23 BT_ASSERT_PRE("error-cause-has-" _exp_type_name "-actor", \
24 ((const struct bt_error_cause *) (_cause))->actor_type == _exp_type, \
553c4bab
PP
25 "Unexpected error cause's actor type: type=%s, exp-type=%s", \
26 bt_error_cause_actor_type_string(((const struct bt_error_cause *) (_cause))->actor_type), \
27 bt_error_cause_actor_type_string(_exp_type))
28
29static
30void fini_component_class_id(
31 struct bt_error_cause_component_class_id *comp_class_id)
32{
33 BT_ASSERT(comp_class_id);
34
35 if (comp_class_id->name) {
36 g_string_free(comp_class_id->name, TRUE);
37 comp_class_id->name = NULL;
38 }
39
40 if (comp_class_id->plugin_name) {
41 g_string_free(comp_class_id->plugin_name, TRUE);
42 comp_class_id->plugin_name = NULL;
43 }
44}
45
46static
47void fini_error_cause(struct bt_error_cause *cause)
48{
49 BT_ASSERT(cause);
50 BT_LIB_LOGD("Finalizing error cause: %!+r", cause);
51
52 if (cause->module_name) {
53 g_string_free(cause->module_name, TRUE);
54 cause->module_name = NULL;
55 }
56
57 if (cause->file_name) {
58 g_string_free(cause->file_name, TRUE);
59 cause->file_name = NULL;
60 }
61
62 if (cause->message) {
63 g_string_free(cause->message, TRUE);
64 cause->message = NULL;
65 }
66}
67
68static
69void destroy_error_cause(struct bt_error_cause *cause)
70{
71 if (!cause) {
72 goto end;
73 }
74
75 BT_LIB_LOGD("Destroying error cause: %!+r", cause);
76
77 switch (cause->actor_type) {
78 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT:
79 {
80 struct bt_error_cause_component_actor *spec_cause =
81 (void *) cause;
82
83 if (spec_cause->comp_name) {
84 g_string_free(spec_cause->comp_name, TRUE);
85 spec_cause->comp_name = NULL;
86 }
87
88 fini_component_class_id(&spec_cause->comp_class_id);
89 break;
90 }
91 case BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS:
92 {
93 struct bt_error_cause_component_class_actor *spec_cause =
94 (void *) cause;
95
96 fini_component_class_id(&spec_cause->comp_class_id);
97 break;
98 }
99 case BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR:
100 {
101 struct bt_error_cause_message_iterator_actor *spec_cause =
102 (void *) cause;
103
104 if (spec_cause->comp_name) {
105 g_string_free(spec_cause->comp_name, TRUE);
106 spec_cause->comp_name = NULL;
107 }
108
109 if (spec_cause->output_port_name) {
110 g_string_free(spec_cause->output_port_name, TRUE);
111 spec_cause->output_port_name = NULL;
112 }
113
114 fini_component_class_id(&spec_cause->comp_class_id);
115 break;
116 }
117 default:
118 break;
119 }
120
121 fini_error_cause(cause);
122 g_free(cause);
123
124end:
125 return;
126}
127
128static
129int init_error_cause(struct bt_error_cause *cause,
130 enum bt_error_cause_actor_type actor_type)
131{
132 int ret = 0;
133
134 BT_ASSERT(cause);
135 BT_LIB_LOGD("Initializing error cause: %!+r", cause);
136 cause->actor_type = actor_type;
137 cause->module_name = g_string_new(NULL);
138 if (!cause->module_name) {
139 BT_LOGE_STR("Failed to allocate one GString.");
140 ret = -1;
141 goto end;
142 }
143
144 cause->message = g_string_new(NULL);
145 if (!cause->message) {
146 BT_LOGE_STR("Failed to allocate one GString.");
147 ret = -1;
148 goto end;
149 }
150
151 cause->file_name = g_string_new(NULL);
152 if (!cause->file_name) {
153 BT_LOGE_STR("Failed to allocate one GString.");
154 ret = -1;
155 goto end;
156 }
157
553c4bab
PP
158end:
159 return ret;
160}
161
162static
163int init_component_class_id(
164 struct bt_error_cause_component_class_id *comp_class_id,
165 struct bt_component_class *comp_cls)
166{
167 int ret = 0;
168
169 BT_ASSERT(comp_class_id);
170 comp_class_id->type = comp_cls->type;
171 comp_class_id->name = g_string_new(comp_cls->name->str);
172 if (!comp_class_id->name) {
173 BT_LOGE_STR("Failed to allocate one GString.");
174 ret = -1;
175 goto end;
176 }
177
178 comp_class_id->plugin_name = g_string_new(comp_cls->plugin_name->str);
179 if (!comp_class_id->plugin_name) {
180 BT_LOGE_STR("Failed to allocate one GString.");
181 ret = -1;
182 goto end;
183 }
184
185end:
186 return ret;
187}
188
189static
190void set_error_cause_props(struct bt_error_cause *cause,
191 const char *file_name, uint64_t line_no)
192{
193 BT_ASSERT(cause);
194 g_string_assign(cause->file_name, file_name);
195 cause->line_no = line_no;
196}
197
198static
199struct bt_error_cause *create_error_cause(const char *module_name,
200 const char *file_name, uint64_t line_no)
201{
202 struct bt_error_cause *cause = g_new0(struct bt_error_cause, 1);
203 int ret;
204
205 BT_LOGD_STR("Creating error cause (unknown actor).");
206
207 if (!cause) {
208 BT_LOGE_STR("Failed to allocate one error cause.");
209 goto error;
210 }
211
212 ret = init_error_cause(cause, BT_ERROR_CAUSE_ACTOR_TYPE_UNKNOWN);
213 if (ret) {
214 goto error;
215 }
216
217 g_string_assign(cause->module_name, module_name);
218 set_error_cause_props(cause, file_name, line_no);
219 BT_LIB_LOGD("Created error cause: %!+r", cause);
220 goto end;
221
222error:
223 destroy_error_cause(cause);
224 cause = NULL;
225
226end:
227 return cause;
228}
229
230static
231void append_component_class_id_str(GString *str,
232 struct bt_error_cause_component_class_id *comp_class_id)
233{
234 const char *type_str = NULL;
235
236 switch (comp_class_id->type) {
237 case BT_COMPONENT_CLASS_TYPE_SOURCE:
238 type_str = "src";
239 break;
240 case BT_COMPONENT_CLASS_TYPE_FILTER:
241 type_str = "flt";
242 break;
243 case BT_COMPONENT_CLASS_TYPE_SINK:
244 type_str = "sink";
245 break;
246 default:
498e7994 247 bt_common_abort();
553c4bab
PP
248 }
249
250 if (comp_class_id->plugin_name->len > 0) {
251 g_string_append_printf(str, "%s.%s.%s",
252 type_str, comp_class_id->plugin_name->str,
253 comp_class_id->name->str);
254 } else {
255 g_string_append_printf(str, "%s.%s",
256 type_str, comp_class_id->name->str);
257 }
258}
259
260static
261struct bt_error_cause_component_actor *create_error_cause_component_actor(
262 struct bt_component *comp, const char *file_name,
263 uint64_t line_no)
264{
265 struct bt_error_cause_component_actor *cause =
266 g_new0(struct bt_error_cause_component_actor, 1);
267 int ret;
268
269 BT_LOGD_STR("Creating error cause object (component actor).");
270
271 if (!cause) {
272 goto error;
273 }
274
275 ret = init_error_cause(&cause->base,
276 BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT);
277 if (ret) {
278 goto error;
279 }
280
281 set_error_cause_props(&cause->base, file_name, line_no);
282 cause->comp_name = g_string_new(comp->name->str);
283 if (!cause->comp_name) {
284 BT_LOGE_STR("Failed to allocate one GString.");
285 goto error;
286 }
287
288 ret = init_component_class_id(&cause->comp_class_id, comp->class);
289 if (ret) {
290 goto error;
291 }
292
293 g_string_append_printf(cause->base.module_name, "%s: ",
294 comp->name->str);
295 append_component_class_id_str(cause->base.module_name,
296 &cause->comp_class_id);
297 BT_LIB_LOGD("Created error cause object: %!+r", cause);
298 goto end;
299
300error:
6ef39fe9
SM
301 if (cause) {
302 destroy_error_cause(&cause->base);
303 cause = NULL;
304 }
553c4bab
PP
305
306end:
307 return cause;
308}
309
310static
311struct bt_error_cause_component_class_actor *
312create_error_cause_component_class_actor(struct bt_component_class *comp_cls,
313 const char *file_name, uint64_t line_no)
314{
315 struct bt_error_cause_component_class_actor *cause =
316 g_new0(struct bt_error_cause_component_class_actor, 1);
317 int ret;
318
319 BT_LOGD_STR("Creating error cause object (component class actor).");
320
321 if (!cause) {
322 BT_LOGE_STR("Failed to allocate one error cause object.");
323 goto error;
324 }
325
326 ret = init_error_cause(&cause->base,
327 BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS);
328 if (ret) {
329 goto error;
330 }
331
332 set_error_cause_props(&cause->base, file_name, line_no);
333 ret = init_component_class_id(&cause->comp_class_id, comp_cls);
334 if (ret) {
335 goto error;
336 }
337
338 append_component_class_id_str(cause->base.module_name,
339 &cause->comp_class_id);
340 BT_LIB_LOGD("Created error cause object: %!+r", cause);
341 goto end;
342
343error:
6ef39fe9
SM
344 if (cause) {
345 destroy_error_cause(&cause->base);
346 cause = NULL;
347 }
553c4bab
PP
348
349end:
350 return cause;
351}
352
7c7301d5 353static
553c4bab
PP
354struct bt_error_cause_message_iterator_actor *
355create_error_cause_message_iterator_actor(struct bt_message_iterator *iter,
356 const char *file_name, uint64_t line_no)
357{
358 struct bt_error_cause_message_iterator_actor *cause;
9a2c8b8e 359 struct bt_message_iterator *input_port_iter;
553c4bab
PP
360 int ret;
361
362 BT_LOGD_STR("Creating error cause object (message iterator actor).");
363
364 /*
365 * This can only be created from within a graph, from a user
366 * message iterator, which is a self component port input
367 * message iterator.
368 */
553c4bab
PP
369 input_port_iter = (void *) iter;
370 cause = g_new0(struct bt_error_cause_message_iterator_actor, 1);
371 if (!cause) {
372 BT_LOGE_STR("Failed to allocate one error cause object.");
373 goto error;
374 }
375
376 ret = init_error_cause(&cause->base,
377 BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR);
378 if (ret) {
379 goto error;
380 }
381
382 set_error_cause_props(&cause->base, file_name, line_no);
383 cause->comp_name = g_string_new(
384 input_port_iter->upstream_component->name->str);
385 if (!cause->comp_name) {
386 BT_LOGE_STR("Failed to allocate one GString.");
387 goto error;
388 }
389
390 cause->output_port_name = g_string_new(
391 input_port_iter->upstream_port->name->str);
392 if (!cause->output_port_name) {
393 BT_LOGE_STR("Failed to allocate one GString.");
394 goto error;
395 }
396
397 ret = init_component_class_id(&cause->comp_class_id,
398 input_port_iter->upstream_component->class);
399 if (ret) {
400 goto error;
401 }
402
403 g_string_append_printf(cause->base.module_name, "%s (%s): ",
404 input_port_iter->upstream_component->name->str,
405 input_port_iter->upstream_port->name->str);
406 append_component_class_id_str(cause->base.module_name,
407 &cause->comp_class_id);
408 BT_LIB_LOGD("Created error cause object: %!+r", cause);
409 goto end;
410
411error:
6ef39fe9
SM
412 if (cause) {
413 destroy_error_cause(&cause->base);
414 cause = NULL;
415 }
553c4bab
PP
416
417end:
418 return cause;
419}
420
553c4bab
PP
421struct bt_error *bt_error_create(void)
422{
423 struct bt_error *error;
424
425 BT_LOGD_STR("Creating error object.");
426 error = g_new0(struct bt_error, 1);
427 if (!error) {
428 BT_LOGE_STR("Failed to allocate one error object.");
429 goto error;
430 }
431
432 error->causes = g_ptr_array_new_with_free_func(
433 (GDestroyNotify) destroy_error_cause);
434 if (!error->causes) {
435 BT_LOGE_STR("Failed to allocate one GPtrArray.");
436 goto error;
437 }
438
439 BT_LOGD("Created error object: addr=%p", error);
440 goto end;
441
442error:
443 bt_error_destroy(error);
444 error = NULL;
445
446end:
447 return error;
448}
449
553c4bab
PP
450void bt_error_destroy(struct bt_error *error)
451{
452 if (!error) {
453 goto end;
454 }
455
456 if (error->causes) {
457 g_ptr_array_free(error->causes, TRUE);
458 error->causes = NULL;
459 }
460
461 g_free(error);
462
463end:
464 return;
465}
466
553c4bab
PP
467int bt_error_append_cause_from_unknown(struct bt_error *error,
468 const char *module_name, const char *file_name,
469 uint64_t line_no, const char *msg_fmt, va_list args)
470{
471 struct bt_error_cause *cause = NULL;
472 int status = BT_FUNC_STATUS_OK;
473
c77d03eb
PP
474 BT_ASSERT(error);
475 BT_ASSERT(module_name);
476 BT_ASSERT(file_name);
477 BT_ASSERT(msg_fmt);
553c4bab
PP
478 BT_LOGD("Appending error cause from unknown actor: "
479 "module-name=\"%s\", func-name=\"%s\", line-no=%" PRIu64,
480 module_name, file_name, line_no);
481 cause = create_error_cause(module_name, file_name, line_no);
482 if (!cause) {
483 /* create_error_cause() logs errors */
484 status = BT_FUNC_STATUS_MEMORY_ERROR;
485 goto end;
486 }
487
488 g_string_append_vprintf(cause->message, msg_fmt, args);
489 g_ptr_array_add(error->causes, cause);
490 BT_LIB_LOGD("Appended error cause: %!+r", cause);
491 cause = NULL;
492
493end:
553c4bab
PP
494 return status;
495}
496
553c4bab
PP
497int bt_error_append_cause_from_component(
498 struct bt_error *error, bt_self_component *self_comp,
499 const char *file_name, uint64_t line_no,
500 const char *msg_fmt, va_list args)
501{
502 struct bt_error_cause_component_actor *cause = NULL;
503 int status = BT_FUNC_STATUS_OK;
504
c77d03eb
PP
505 BT_ASSERT(error);
506 BT_ASSERT(self_comp);
507 BT_ASSERT(file_name);
508 BT_ASSERT(msg_fmt);
553c4bab
PP
509 BT_LIB_LOGD("Appending error cause from component actor: %![comp-]+c",
510 self_comp);
511 cause = create_error_cause_component_actor((void *) self_comp,
512 file_name, line_no);
513 if (!cause) {
514 /* create_error_cause_component_actor() logs errors */
515 status = BT_FUNC_STATUS_MEMORY_ERROR;
516 goto end;
517 }
518
519 g_string_append_vprintf(cause->base.message, msg_fmt, args);
520 g_ptr_array_add(error->causes, cause);
521 BT_LIB_LOGD("Appended error cause: %!+r", cause);
522 cause = NULL;
523
524end:
553c4bab
PP
525 return status;
526}
527
553c4bab
PP
528int bt_error_append_cause_from_component_class(
529 struct bt_error *error,
530 bt_self_component_class *self_comp_class,
531 const char *file_name, uint64_t line_no,
532 const char *msg_fmt, va_list args)
533{
534 struct bt_error_cause_component_class_actor *cause = NULL;
535 int status = BT_FUNC_STATUS_OK;
536
c77d03eb
PP
537 BT_ASSERT(error);
538 BT_ASSERT(self_comp_class);
539 BT_ASSERT(file_name);
540 BT_ASSERT(msg_fmt);
553c4bab
PP
541 BT_LIB_LOGD("Appending error cause from component class actor: "
542 "%![comp-cls-]+C", self_comp_class);
543 cause = create_error_cause_component_class_actor(
544 (void *) self_comp_class, file_name, line_no);
545 if (!cause) {
546 /* create_error_cause_component_class_actor() logs errors */
547 status = BT_FUNC_STATUS_MEMORY_ERROR;
548 goto end;
549 }
550
551 g_string_append_vprintf(cause->base.message, msg_fmt, args);
552 g_ptr_array_add(error->causes, cause);
553 BT_LIB_LOGD("Appended error cause: %!+r", cause);
554 cause = NULL;
555
556end:
553c4bab
PP
557 return status;
558}
559
553c4bab
PP
560int bt_error_append_cause_from_message_iterator(
561 struct bt_error *error, bt_self_message_iterator *self_iter,
562 const char *file_name, uint64_t line_no,
563 const char *msg_fmt, va_list args)
564{
565 struct bt_error_cause_message_iterator_actor *cause = NULL;
566 int status = BT_FUNC_STATUS_OK;
567
c77d03eb
PP
568 BT_ASSERT(error);
569 BT_ASSERT(self_iter);
570 BT_ASSERT(file_name);
571 BT_ASSERT(msg_fmt);
553c4bab
PP
572 BT_LIB_LOGD("Appending error cause from message iterator actor: "
573 "%![comp-]+i", self_iter);
574 cause = create_error_cause_message_iterator_actor(
575 (void *) self_iter, file_name, line_no);
576 if (!cause) {
577 /* create_error_cause_message_iterator_actor() logs errors */
578 status = BT_FUNC_STATUS_MEMORY_ERROR;
579 goto end;
580 }
581
582 g_string_append_vprintf(cause->base.message, msg_fmt, args);
583 g_ptr_array_add(error->causes, cause);
584 BT_LIB_LOGD("Appended error cause: %!+r", cause);
585 cause = NULL;
586
587end:
553c4bab
PP
588 return status;
589}
590
591static
592uint64_t error_cause_count(const bt_error *error)
593{
594 return error->causes ? error->causes->len : 0;
595}
596
1353b066 597BT_EXPORT
553c4bab
PP
598uint64_t bt_error_get_cause_count(const bt_error *error)
599{
d5b13b9b 600 BT_ASSERT_PRE_ERROR_NON_NULL(error);
553c4bab
PP
601 return error_cause_count(error);
602}
603
1353b066 604BT_EXPORT
553c4bab
PP
605void bt_error_release(const struct bt_error *error)
606{
d5b13b9b 607 BT_ASSERT_PRE_ERROR_NON_NULL(error);
553c4bab
PP
608 bt_error_destroy((void *) error);
609}
610
1353b066 611BT_EXPORT
553c4bab
PP
612const struct bt_error_cause *bt_error_borrow_cause_by_index(
613 const bt_error *error, uint64_t index)
614{
d5b13b9b 615 BT_ASSERT_PRE_ERROR_NON_NULL(error);
553c4bab
PP
616 BT_ASSERT_PRE_VALID_INDEX(index, error_cause_count(error));
617 return error->causes->pdata[index];
618}
619
1353b066 620BT_EXPORT
553c4bab
PP
621enum bt_error_cause_actor_type bt_error_cause_get_actor_type(
622 const struct bt_error_cause *cause)
623{
d5b13b9b 624 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
553c4bab
PP
625 return cause->actor_type;
626}
627
1353b066 628BT_EXPORT
553c4bab
PP
629const char *bt_error_cause_get_message(const struct bt_error_cause *cause)
630{
d5b13b9b 631 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
553c4bab
PP
632 return cause->message->str;
633}
634
1353b066 635BT_EXPORT
553c4bab
PP
636const char *bt_error_cause_get_module_name(const struct bt_error_cause *cause)
637{
d5b13b9b 638 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
553c4bab
PP
639 return cause->module_name->str;
640}
641
1353b066 642BT_EXPORT
553c4bab
PP
643const char *bt_error_cause_get_file_name(const struct bt_error_cause *cause)
644{
d5b13b9b 645 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
553c4bab
PP
646 return cause->file_name->str;
647}
648
1353b066 649BT_EXPORT
553c4bab
PP
650uint64_t bt_error_cause_get_line_number(const bt_error_cause *cause)
651{
d5b13b9b 652 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
553c4bab
PP
653 return cause->line_no;
654}
655
1353b066 656BT_EXPORT
553c4bab
PP
657const char *bt_error_cause_component_actor_get_component_name(
658 const struct bt_error_cause *cause)
659{
660 const struct bt_error_cause_component_actor *spec_cause =
661 (const void *) cause;
662
d5b13b9b 663 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 664 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component",
553c4bab
PP
665 BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT);
666 return spec_cause->comp_name->str;
667}
668
1353b066 669BT_EXPORT
553c4bab
PP
670bt_component_class_type bt_error_cause_component_actor_get_component_class_type(
671 const struct bt_error_cause *cause)
672{
673 const struct bt_error_cause_component_actor *spec_cause =
674 (const void *) cause;
675
d5b13b9b 676 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 677 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component",
553c4bab
PP
678 BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT);
679 return spec_cause->comp_class_id.type;
680}
681
1353b066 682BT_EXPORT
553c4bab
PP
683const char *bt_error_cause_component_actor_get_component_class_name(
684 const struct bt_error_cause *cause)
685{
686 const struct bt_error_cause_component_actor *spec_cause =
687 (const void *) cause;
688
d5b13b9b 689 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 690 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component",
553c4bab
PP
691 BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT);
692 return spec_cause->comp_class_id.name->str;
693}
694
1353b066 695BT_EXPORT
553c4bab
PP
696const char *bt_error_cause_component_actor_get_plugin_name(
697 const struct bt_error_cause *cause)
698{
699 const struct bt_error_cause_component_actor *spec_cause =
700 (const void *) cause;
701
d5b13b9b 702 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 703 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component",
553c4bab
PP
704 BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT);
705 return spec_cause->comp_class_id.plugin_name->len > 0 ?
706 spec_cause->comp_class_id.plugin_name->str : NULL;
707}
708
1353b066 709BT_EXPORT
553c4bab
PP
710bt_component_class_type
711bt_error_cause_component_class_actor_get_component_class_type(
712 const struct bt_error_cause *cause)
713{
714 const struct bt_error_cause_component_class_actor *spec_cause =
715 (const void *) cause;
716
d5b13b9b 717 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 718 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component-class",
553c4bab
PP
719 BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS);
720 return spec_cause->comp_class_id.type;
721}
722
1353b066 723BT_EXPORT
553c4bab
PP
724const char *bt_error_cause_component_class_actor_get_component_class_name(
725 const struct bt_error_cause *cause)
726{
727 const struct bt_error_cause_component_class_actor *spec_cause =
728 (const void *) cause;
729
d5b13b9b 730 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 731 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component-class",
553c4bab
PP
732 BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS);
733 return spec_cause->comp_class_id.name->str;
734}
735
1353b066 736BT_EXPORT
553c4bab
PP
737const char *bt_error_cause_component_class_actor_get_plugin_name(
738 const struct bt_error_cause *cause)
739{
740 const struct bt_error_cause_component_class_actor *spec_cause =
741 (const void *) cause;
742
d5b13b9b 743 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 744 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component-class",
553c4bab
PP
745 BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS);
746 return spec_cause->comp_class_id.plugin_name->len > 0 ?
747 spec_cause->comp_class_id.plugin_name->str : NULL;
748}
749
1353b066 750BT_EXPORT
553c4bab
PP
751const char *bt_error_cause_message_iterator_actor_get_component_name(
752 const struct bt_error_cause *cause)
753{
754 const struct bt_error_cause_message_iterator_actor *spec_cause =
755 (const void *) cause;
756
d5b13b9b 757 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 758 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator",
553c4bab
PP
759 BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR);
760 return spec_cause->comp_name->str;
761}
762
1353b066 763BT_EXPORT
553c4bab
PP
764const char *
765bt_error_cause_message_iterator_actor_get_component_output_port_name(
766 const struct bt_error_cause *cause)
767{
768 const struct bt_error_cause_message_iterator_actor *spec_cause =
769 (const void *) cause;
770
d5b13b9b 771 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 772 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator",
553c4bab
PP
773 BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR);
774 return spec_cause->output_port_name->str;
775}
776
1353b066 777BT_EXPORT
553c4bab
PP
778bt_component_class_type
779bt_error_cause_message_iterator_actor_get_component_class_type(
780 const struct bt_error_cause *cause)
781{
782 const struct bt_error_cause_message_iterator_actor *spec_cause =
783 (const void *) cause;
784
d5b13b9b 785 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 786 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator",
553c4bab
PP
787 BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR);
788 return spec_cause->comp_class_id.type;
789}
790
1353b066 791BT_EXPORT
553c4bab
PP
792const char *bt_error_cause_message_iterator_actor_get_component_class_name(
793 const struct bt_error_cause *cause)
794{
795 const struct bt_error_cause_message_iterator_actor *spec_cause =
796 (const void *) cause;
797
d5b13b9b 798 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 799 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator",
553c4bab
PP
800 BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR);
801 return spec_cause->comp_class_id.name->str;
802}
803
1353b066 804BT_EXPORT
553c4bab
PP
805const char *bt_error_cause_message_iterator_actor_get_plugin_name(
806 const struct bt_error_cause *cause)
807{
808 const struct bt_error_cause_message_iterator_actor *spec_cause =
809 (const void *) cause;
810
d5b13b9b 811 BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause);
1778c2a4 812 BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator",
553c4bab
PP
813 BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR);
814 return spec_cause->comp_class_id.plugin_name->len > 0 ?
815 spec_cause->comp_class_id.plugin_name->str : NULL;
816}
This page took 0.086322 seconds and 4 git commands to generate.