Commit | Line | Data |
---|---|---|
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 | ||
29 | static | |
30 | void 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 | ||
46 | static | |
47 | void 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 | ||
68 | static | |
69 | void 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 | ||
124 | end: | |
125 | return; | |
126 | } | |
127 | ||
128 | static | |
129 | int 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 | ||
158 | BT_LIB_LOGD("Initialized error cause: %!+r", cause); | |
159 | ||
160 | end: | |
161 | return ret; | |
162 | } | |
163 | ||
164 | static | |
165 | int init_component_class_id( | |
166 | struct bt_error_cause_component_class_id *comp_class_id, | |
167 | struct bt_component_class *comp_cls) | |
168 | { | |
169 | int ret = 0; | |
170 | ||
171 | BT_ASSERT(comp_class_id); | |
172 | comp_class_id->type = comp_cls->type; | |
173 | comp_class_id->name = g_string_new(comp_cls->name->str); | |
174 | if (!comp_class_id->name) { | |
175 | BT_LOGE_STR("Failed to allocate one GString."); | |
176 | ret = -1; | |
177 | goto end; | |
178 | } | |
179 | ||
180 | comp_class_id->plugin_name = g_string_new(comp_cls->plugin_name->str); | |
181 | if (!comp_class_id->plugin_name) { | |
182 | BT_LOGE_STR("Failed to allocate one GString."); | |
183 | ret = -1; | |
184 | goto end; | |
185 | } | |
186 | ||
187 | end: | |
188 | return ret; | |
189 | } | |
190 | ||
191 | static | |
192 | void set_error_cause_props(struct bt_error_cause *cause, | |
193 | const char *file_name, uint64_t line_no) | |
194 | { | |
195 | BT_ASSERT(cause); | |
196 | g_string_assign(cause->file_name, file_name); | |
197 | cause->line_no = line_no; | |
198 | } | |
199 | ||
200 | static | |
201 | struct bt_error_cause *create_error_cause(const char *module_name, | |
202 | const char *file_name, uint64_t line_no) | |
203 | { | |
204 | struct bt_error_cause *cause = g_new0(struct bt_error_cause, 1); | |
205 | int ret; | |
206 | ||
207 | BT_LOGD_STR("Creating error cause (unknown actor)."); | |
208 | ||
209 | if (!cause) { | |
210 | BT_LOGE_STR("Failed to allocate one error cause."); | |
211 | goto error; | |
212 | } | |
213 | ||
214 | ret = init_error_cause(cause, BT_ERROR_CAUSE_ACTOR_TYPE_UNKNOWN); | |
215 | if (ret) { | |
216 | goto error; | |
217 | } | |
218 | ||
219 | g_string_assign(cause->module_name, module_name); | |
220 | set_error_cause_props(cause, file_name, line_no); | |
221 | BT_LIB_LOGD("Created error cause: %!+r", cause); | |
222 | goto end; | |
223 | ||
224 | error: | |
225 | destroy_error_cause(cause); | |
226 | cause = NULL; | |
227 | ||
228 | end: | |
229 | return cause; | |
230 | } | |
231 | ||
232 | static | |
233 | void append_component_class_id_str(GString *str, | |
234 | struct bt_error_cause_component_class_id *comp_class_id) | |
235 | { | |
236 | const char *type_str = NULL; | |
237 | ||
238 | switch (comp_class_id->type) { | |
239 | case BT_COMPONENT_CLASS_TYPE_SOURCE: | |
240 | type_str = "src"; | |
241 | break; | |
242 | case BT_COMPONENT_CLASS_TYPE_FILTER: | |
243 | type_str = "flt"; | |
244 | break; | |
245 | case BT_COMPONENT_CLASS_TYPE_SINK: | |
246 | type_str = "sink"; | |
247 | break; | |
248 | default: | |
498e7994 | 249 | bt_common_abort(); |
553c4bab PP |
250 | } |
251 | ||
252 | if (comp_class_id->plugin_name->len > 0) { | |
253 | g_string_append_printf(str, "%s.%s.%s", | |
254 | type_str, comp_class_id->plugin_name->str, | |
255 | comp_class_id->name->str); | |
256 | } else { | |
257 | g_string_append_printf(str, "%s.%s", | |
258 | type_str, comp_class_id->name->str); | |
259 | } | |
260 | } | |
261 | ||
262 | static | |
263 | struct bt_error_cause_component_actor *create_error_cause_component_actor( | |
264 | struct bt_component *comp, const char *file_name, | |
265 | uint64_t line_no) | |
266 | { | |
267 | struct bt_error_cause_component_actor *cause = | |
268 | g_new0(struct bt_error_cause_component_actor, 1); | |
269 | int ret; | |
270 | ||
271 | BT_LOGD_STR("Creating error cause object (component actor)."); | |
272 | ||
273 | if (!cause) { | |
274 | goto error; | |
275 | } | |
276 | ||
277 | ret = init_error_cause(&cause->base, | |
278 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT); | |
279 | if (ret) { | |
280 | goto error; | |
281 | } | |
282 | ||
283 | set_error_cause_props(&cause->base, file_name, line_no); | |
284 | cause->comp_name = g_string_new(comp->name->str); | |
285 | if (!cause->comp_name) { | |
286 | BT_LOGE_STR("Failed to allocate one GString."); | |
287 | goto error; | |
288 | } | |
289 | ||
290 | ret = init_component_class_id(&cause->comp_class_id, comp->class); | |
291 | if (ret) { | |
292 | goto error; | |
293 | } | |
294 | ||
295 | g_string_append_printf(cause->base.module_name, "%s: ", | |
296 | comp->name->str); | |
297 | append_component_class_id_str(cause->base.module_name, | |
298 | &cause->comp_class_id); | |
299 | BT_LIB_LOGD("Created error cause object: %!+r", cause); | |
300 | goto end; | |
301 | ||
302 | error: | |
303 | destroy_error_cause(&cause->base); | |
304 | cause = NULL; | |
305 | ||
306 | end: | |
307 | return cause; | |
308 | } | |
309 | ||
310 | static | |
311 | struct bt_error_cause_component_class_actor * | |
312 | create_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 | ||
343 | error: | |
344 | destroy_error_cause(&cause->base); | |
345 | cause = NULL; | |
346 | ||
347 | end: | |
348 | return cause; | |
349 | } | |
350 | ||
7c7301d5 | 351 | static |
553c4bab PP |
352 | struct bt_error_cause_message_iterator_actor * |
353 | create_error_cause_message_iterator_actor(struct bt_message_iterator *iter, | |
354 | const char *file_name, uint64_t line_no) | |
355 | { | |
356 | struct bt_error_cause_message_iterator_actor *cause; | |
9a2c8b8e | 357 | struct bt_message_iterator *input_port_iter; |
553c4bab PP |
358 | int ret; |
359 | ||
360 | BT_LOGD_STR("Creating error cause object (message iterator actor)."); | |
361 | ||
362 | /* | |
363 | * This can only be created from within a graph, from a user | |
364 | * message iterator, which is a self component port input | |
365 | * message iterator. | |
366 | */ | |
553c4bab PP |
367 | input_port_iter = (void *) iter; |
368 | cause = g_new0(struct bt_error_cause_message_iterator_actor, 1); | |
369 | if (!cause) { | |
370 | BT_LOGE_STR("Failed to allocate one error cause object."); | |
371 | goto error; | |
372 | } | |
373 | ||
374 | ret = init_error_cause(&cause->base, | |
375 | BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR); | |
376 | if (ret) { | |
377 | goto error; | |
378 | } | |
379 | ||
380 | set_error_cause_props(&cause->base, file_name, line_no); | |
381 | cause->comp_name = g_string_new( | |
382 | input_port_iter->upstream_component->name->str); | |
383 | if (!cause->comp_name) { | |
384 | BT_LOGE_STR("Failed to allocate one GString."); | |
385 | goto error; | |
386 | } | |
387 | ||
388 | cause->output_port_name = g_string_new( | |
389 | input_port_iter->upstream_port->name->str); | |
390 | if (!cause->output_port_name) { | |
391 | BT_LOGE_STR("Failed to allocate one GString."); | |
392 | goto error; | |
393 | } | |
394 | ||
395 | ret = init_component_class_id(&cause->comp_class_id, | |
396 | input_port_iter->upstream_component->class); | |
397 | if (ret) { | |
398 | goto error; | |
399 | } | |
400 | ||
401 | g_string_append_printf(cause->base.module_name, "%s (%s): ", | |
402 | input_port_iter->upstream_component->name->str, | |
403 | input_port_iter->upstream_port->name->str); | |
404 | append_component_class_id_str(cause->base.module_name, | |
405 | &cause->comp_class_id); | |
406 | BT_LIB_LOGD("Created error cause object: %!+r", cause); | |
407 | goto end; | |
408 | ||
409 | error: | |
410 | destroy_error_cause(&cause->base); | |
411 | cause = NULL; | |
412 | ||
413 | end: | |
414 | return cause; | |
415 | } | |
416 | ||
417 | BT_HIDDEN | |
418 | struct bt_error *bt_error_create(void) | |
419 | { | |
420 | struct bt_error *error; | |
421 | ||
422 | BT_LOGD_STR("Creating error object."); | |
423 | error = g_new0(struct bt_error, 1); | |
424 | if (!error) { | |
425 | BT_LOGE_STR("Failed to allocate one error object."); | |
426 | goto error; | |
427 | } | |
428 | ||
429 | error->causes = g_ptr_array_new_with_free_func( | |
430 | (GDestroyNotify) destroy_error_cause); | |
431 | if (!error->causes) { | |
432 | BT_LOGE_STR("Failed to allocate one GPtrArray."); | |
433 | goto error; | |
434 | } | |
435 | ||
436 | BT_LOGD("Created error object: addr=%p", error); | |
437 | goto end; | |
438 | ||
439 | error: | |
440 | bt_error_destroy(error); | |
441 | error = NULL; | |
442 | ||
443 | end: | |
444 | return error; | |
445 | } | |
446 | ||
447 | BT_HIDDEN | |
448 | void bt_error_destroy(struct bt_error *error) | |
449 | { | |
450 | if (!error) { | |
451 | goto end; | |
452 | } | |
453 | ||
454 | if (error->causes) { | |
455 | g_ptr_array_free(error->causes, TRUE); | |
456 | error->causes = NULL; | |
457 | } | |
458 | ||
459 | g_free(error); | |
460 | ||
461 | end: | |
462 | return; | |
463 | } | |
464 | ||
465 | BT_HIDDEN | |
466 | int bt_error_append_cause_from_unknown(struct bt_error *error, | |
467 | const char *module_name, const char *file_name, | |
468 | uint64_t line_no, const char *msg_fmt, va_list args) | |
469 | { | |
470 | struct bt_error_cause *cause = NULL; | |
471 | int status = BT_FUNC_STATUS_OK; | |
472 | ||
c77d03eb PP |
473 | BT_ASSERT(error); |
474 | BT_ASSERT(module_name); | |
475 | BT_ASSERT(file_name); | |
476 | BT_ASSERT(msg_fmt); | |
553c4bab PP |
477 | BT_LOGD("Appending error cause from unknown actor: " |
478 | "module-name=\"%s\", func-name=\"%s\", line-no=%" PRIu64, | |
479 | module_name, file_name, line_no); | |
480 | cause = create_error_cause(module_name, file_name, line_no); | |
481 | if (!cause) { | |
482 | /* create_error_cause() logs errors */ | |
483 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
484 | goto end; | |
485 | } | |
486 | ||
487 | g_string_append_vprintf(cause->message, msg_fmt, args); | |
488 | g_ptr_array_add(error->causes, cause); | |
489 | BT_LIB_LOGD("Appended error cause: %!+r", cause); | |
490 | cause = NULL; | |
491 | ||
492 | end: | |
493 | destroy_error_cause(cause); | |
494 | return status; | |
495 | } | |
496 | ||
497 | BT_HIDDEN | |
498 | int bt_error_append_cause_from_component( | |
499 | struct bt_error *error, bt_self_component *self_comp, | |
500 | const char *file_name, uint64_t line_no, | |
501 | const char *msg_fmt, va_list args) | |
502 | { | |
503 | struct bt_error_cause_component_actor *cause = NULL; | |
504 | int status = BT_FUNC_STATUS_OK; | |
505 | ||
c77d03eb PP |
506 | BT_ASSERT(error); |
507 | BT_ASSERT(self_comp); | |
508 | BT_ASSERT(file_name); | |
509 | BT_ASSERT(msg_fmt); | |
553c4bab PP |
510 | BT_LIB_LOGD("Appending error cause from component actor: %![comp-]+c", |
511 | self_comp); | |
512 | cause = create_error_cause_component_actor((void *) self_comp, | |
513 | file_name, line_no); | |
514 | if (!cause) { | |
515 | /* create_error_cause_component_actor() logs errors */ | |
516 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
517 | goto end; | |
518 | } | |
519 | ||
520 | g_string_append_vprintf(cause->base.message, msg_fmt, args); | |
521 | g_ptr_array_add(error->causes, cause); | |
522 | BT_LIB_LOGD("Appended error cause: %!+r", cause); | |
523 | cause = NULL; | |
524 | ||
525 | end: | |
526 | destroy_error_cause(&cause->base); | |
527 | return status; | |
528 | } | |
529 | ||
530 | BT_HIDDEN | |
531 | int bt_error_append_cause_from_component_class( | |
532 | struct bt_error *error, | |
533 | bt_self_component_class *self_comp_class, | |
534 | const char *file_name, uint64_t line_no, | |
535 | const char *msg_fmt, va_list args) | |
536 | { | |
537 | struct bt_error_cause_component_class_actor *cause = NULL; | |
538 | int status = BT_FUNC_STATUS_OK; | |
539 | ||
c77d03eb PP |
540 | BT_ASSERT(error); |
541 | BT_ASSERT(self_comp_class); | |
542 | BT_ASSERT(file_name); | |
543 | BT_ASSERT(msg_fmt); | |
553c4bab PP |
544 | BT_LIB_LOGD("Appending error cause from component class actor: " |
545 | "%![comp-cls-]+C", self_comp_class); | |
546 | cause = create_error_cause_component_class_actor( | |
547 | (void *) self_comp_class, file_name, line_no); | |
548 | if (!cause) { | |
549 | /* create_error_cause_component_class_actor() logs errors */ | |
550 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
551 | goto end; | |
552 | } | |
553 | ||
554 | g_string_append_vprintf(cause->base.message, msg_fmt, args); | |
555 | g_ptr_array_add(error->causes, cause); | |
556 | BT_LIB_LOGD("Appended error cause: %!+r", cause); | |
557 | cause = NULL; | |
558 | ||
559 | end: | |
560 | destroy_error_cause(&cause->base); | |
561 | return status; | |
562 | } | |
563 | ||
564 | BT_HIDDEN | |
565 | int bt_error_append_cause_from_message_iterator( | |
566 | struct bt_error *error, bt_self_message_iterator *self_iter, | |
567 | const char *file_name, uint64_t line_no, | |
568 | const char *msg_fmt, va_list args) | |
569 | { | |
570 | struct bt_error_cause_message_iterator_actor *cause = NULL; | |
571 | int status = BT_FUNC_STATUS_OK; | |
572 | ||
c77d03eb PP |
573 | BT_ASSERT(error); |
574 | BT_ASSERT(self_iter); | |
575 | BT_ASSERT(file_name); | |
576 | BT_ASSERT(msg_fmt); | |
553c4bab PP |
577 | BT_LIB_LOGD("Appending error cause from message iterator actor: " |
578 | "%![comp-]+i", self_iter); | |
579 | cause = create_error_cause_message_iterator_actor( | |
580 | (void *) self_iter, file_name, line_no); | |
581 | if (!cause) { | |
582 | /* create_error_cause_message_iterator_actor() logs errors */ | |
583 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
584 | goto end; | |
585 | } | |
586 | ||
587 | g_string_append_vprintf(cause->base.message, msg_fmt, args); | |
588 | g_ptr_array_add(error->causes, cause); | |
589 | BT_LIB_LOGD("Appended error cause: %!+r", cause); | |
590 | cause = NULL; | |
591 | ||
592 | end: | |
593 | destroy_error_cause(&cause->base); | |
594 | return status; | |
595 | } | |
596 | ||
597 | static | |
598 | uint64_t error_cause_count(const bt_error *error) | |
599 | { | |
600 | return error->causes ? error->causes->len : 0; | |
601 | } | |
602 | ||
603 | uint64_t bt_error_get_cause_count(const bt_error *error) | |
604 | { | |
d5b13b9b | 605 | BT_ASSERT_PRE_ERROR_NON_NULL(error); |
553c4bab PP |
606 | return error_cause_count(error); |
607 | } | |
608 | ||
609 | void bt_error_release(const struct bt_error *error) | |
610 | { | |
d5b13b9b | 611 | BT_ASSERT_PRE_ERROR_NON_NULL(error); |
553c4bab PP |
612 | bt_error_destroy((void *) error); |
613 | } | |
614 | ||
615 | const struct bt_error_cause *bt_error_borrow_cause_by_index( | |
616 | const bt_error *error, uint64_t index) | |
617 | { | |
d5b13b9b | 618 | BT_ASSERT_PRE_ERROR_NON_NULL(error); |
553c4bab PP |
619 | BT_ASSERT_PRE_VALID_INDEX(index, error_cause_count(error)); |
620 | return error->causes->pdata[index]; | |
621 | } | |
622 | ||
623 | enum bt_error_cause_actor_type bt_error_cause_get_actor_type( | |
624 | const struct bt_error_cause *cause) | |
625 | { | |
d5b13b9b | 626 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
553c4bab PP |
627 | return cause->actor_type; |
628 | } | |
629 | ||
630 | const char *bt_error_cause_get_message(const struct bt_error_cause *cause) | |
631 | { | |
d5b13b9b | 632 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
553c4bab PP |
633 | return cause->message->str; |
634 | } | |
635 | ||
636 | const 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 | ||
642 | const char *bt_error_cause_get_file_name(const struct bt_error_cause *cause) | |
643 | { | |
d5b13b9b | 644 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
553c4bab PP |
645 | return cause->file_name->str; |
646 | } | |
647 | ||
648 | uint64_t bt_error_cause_get_line_number(const bt_error_cause *cause) | |
649 | { | |
d5b13b9b | 650 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
553c4bab PP |
651 | return cause->line_no; |
652 | } | |
653 | ||
654 | const char *bt_error_cause_component_actor_get_component_name( | |
655 | const struct bt_error_cause *cause) | |
656 | { | |
657 | const struct bt_error_cause_component_actor *spec_cause = | |
658 | (const void *) cause; | |
659 | ||
d5b13b9b | 660 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 661 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component", |
553c4bab PP |
662 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT); |
663 | return spec_cause->comp_name->str; | |
664 | } | |
665 | ||
666 | bt_component_class_type bt_error_cause_component_actor_get_component_class_type( | |
667 | const struct bt_error_cause *cause) | |
668 | { | |
669 | const struct bt_error_cause_component_actor *spec_cause = | |
670 | (const void *) cause; | |
671 | ||
d5b13b9b | 672 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 673 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component", |
553c4bab PP |
674 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT); |
675 | return spec_cause->comp_class_id.type; | |
676 | } | |
677 | ||
678 | const char *bt_error_cause_component_actor_get_component_class_name( | |
679 | const struct bt_error_cause *cause) | |
680 | { | |
681 | const struct bt_error_cause_component_actor *spec_cause = | |
682 | (const void *) cause; | |
683 | ||
d5b13b9b | 684 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 685 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component", |
553c4bab PP |
686 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT); |
687 | return spec_cause->comp_class_id.name->str; | |
688 | } | |
689 | ||
690 | const char *bt_error_cause_component_actor_get_plugin_name( | |
691 | const struct bt_error_cause *cause) | |
692 | { | |
693 | const struct bt_error_cause_component_actor *spec_cause = | |
694 | (const void *) cause; | |
695 | ||
d5b13b9b | 696 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 697 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component", |
553c4bab PP |
698 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT); |
699 | return spec_cause->comp_class_id.plugin_name->len > 0 ? | |
700 | spec_cause->comp_class_id.plugin_name->str : NULL; | |
701 | } | |
702 | ||
703 | bt_component_class_type | |
704 | bt_error_cause_component_class_actor_get_component_class_type( | |
705 | const struct bt_error_cause *cause) | |
706 | { | |
707 | const struct bt_error_cause_component_class_actor *spec_cause = | |
708 | (const void *) cause; | |
709 | ||
d5b13b9b | 710 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 711 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component-class", |
553c4bab PP |
712 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS); |
713 | return spec_cause->comp_class_id.type; | |
714 | } | |
715 | ||
716 | const char *bt_error_cause_component_class_actor_get_component_class_name( | |
717 | const struct bt_error_cause *cause) | |
718 | { | |
719 | const struct bt_error_cause_component_class_actor *spec_cause = | |
720 | (const void *) cause; | |
721 | ||
d5b13b9b | 722 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 723 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component-class", |
553c4bab PP |
724 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS); |
725 | return spec_cause->comp_class_id.name->str; | |
726 | } | |
727 | ||
728 | const char *bt_error_cause_component_class_actor_get_plugin_name( | |
729 | const struct bt_error_cause *cause) | |
730 | { | |
731 | const struct bt_error_cause_component_class_actor *spec_cause = | |
732 | (const void *) cause; | |
733 | ||
d5b13b9b | 734 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 735 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component-class", |
553c4bab PP |
736 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS); |
737 | return spec_cause->comp_class_id.plugin_name->len > 0 ? | |
738 | spec_cause->comp_class_id.plugin_name->str : NULL; | |
739 | } | |
740 | ||
741 | const char *bt_error_cause_message_iterator_actor_get_component_name( | |
742 | const struct bt_error_cause *cause) | |
743 | { | |
744 | const struct bt_error_cause_message_iterator_actor *spec_cause = | |
745 | (const void *) cause; | |
746 | ||
d5b13b9b | 747 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 748 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator", |
553c4bab PP |
749 | BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR); |
750 | return spec_cause->comp_name->str; | |
751 | } | |
752 | ||
753 | const char * | |
754 | bt_error_cause_message_iterator_actor_get_component_output_port_name( | |
755 | const struct bt_error_cause *cause) | |
756 | { | |
757 | const struct bt_error_cause_message_iterator_actor *spec_cause = | |
758 | (const void *) cause; | |
759 | ||
d5b13b9b | 760 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 761 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator", |
553c4bab PP |
762 | BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR); |
763 | return spec_cause->output_port_name->str; | |
764 | } | |
765 | ||
766 | bt_component_class_type | |
767 | bt_error_cause_message_iterator_actor_get_component_class_type( | |
768 | const struct bt_error_cause *cause) | |
769 | { | |
770 | const struct bt_error_cause_message_iterator_actor *spec_cause = | |
771 | (const void *) cause; | |
772 | ||
d5b13b9b | 773 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 774 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator", |
553c4bab PP |
775 | BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR); |
776 | return spec_cause->comp_class_id.type; | |
777 | } | |
778 | ||
779 | const char *bt_error_cause_message_iterator_actor_get_component_class_name( | |
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.name->str; | |
789 | } | |
790 | ||
791 | const char *bt_error_cause_message_iterator_actor_get_plugin_name( | |
792 | const struct bt_error_cause *cause) | |
793 | { | |
794 | const struct bt_error_cause_message_iterator_actor *spec_cause = | |
795 | (const void *) cause; | |
796 | ||
d5b13b9b | 797 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 798 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator", |
553c4bab PP |
799 | BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR); |
800 | return spec_cause->comp_class_id.plugin_name->len > 0 ? | |
801 | spec_cause->comp_class_id.plugin_name->str : NULL; | |
802 | } |