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: | |
6ef39fe9 SM |
303 | if (cause) { |
304 | destroy_error_cause(&cause->base); | |
305 | cause = NULL; | |
306 | } | |
553c4bab PP |
307 | |
308 | end: | |
309 | return cause; | |
310 | } | |
311 | ||
312 | static | |
313 | struct bt_error_cause_component_class_actor * | |
314 | create_error_cause_component_class_actor(struct bt_component_class *comp_cls, | |
315 | const char *file_name, uint64_t line_no) | |
316 | { | |
317 | struct bt_error_cause_component_class_actor *cause = | |
318 | g_new0(struct bt_error_cause_component_class_actor, 1); | |
319 | int ret; | |
320 | ||
321 | BT_LOGD_STR("Creating error cause object (component class actor)."); | |
322 | ||
323 | if (!cause) { | |
324 | BT_LOGE_STR("Failed to allocate one error cause object."); | |
325 | goto error; | |
326 | } | |
327 | ||
328 | ret = init_error_cause(&cause->base, | |
329 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS); | |
330 | if (ret) { | |
331 | goto error; | |
332 | } | |
333 | ||
334 | set_error_cause_props(&cause->base, file_name, line_no); | |
335 | ret = init_component_class_id(&cause->comp_class_id, comp_cls); | |
336 | if (ret) { | |
337 | goto error; | |
338 | } | |
339 | ||
340 | append_component_class_id_str(cause->base.module_name, | |
341 | &cause->comp_class_id); | |
342 | BT_LIB_LOGD("Created error cause object: %!+r", cause); | |
343 | goto end; | |
344 | ||
345 | error: | |
6ef39fe9 SM |
346 | if (cause) { |
347 | destroy_error_cause(&cause->base); | |
348 | cause = NULL; | |
349 | } | |
553c4bab PP |
350 | |
351 | end: | |
352 | return cause; | |
353 | } | |
354 | ||
7c7301d5 | 355 | static |
553c4bab PP |
356 | struct bt_error_cause_message_iterator_actor * |
357 | create_error_cause_message_iterator_actor(struct bt_message_iterator *iter, | |
358 | const char *file_name, uint64_t line_no) | |
359 | { | |
360 | struct bt_error_cause_message_iterator_actor *cause; | |
9a2c8b8e | 361 | struct bt_message_iterator *input_port_iter; |
553c4bab PP |
362 | int ret; |
363 | ||
364 | BT_LOGD_STR("Creating error cause object (message iterator actor)."); | |
365 | ||
366 | /* | |
367 | * This can only be created from within a graph, from a user | |
368 | * message iterator, which is a self component port input | |
369 | * message iterator. | |
370 | */ | |
553c4bab PP |
371 | input_port_iter = (void *) iter; |
372 | cause = g_new0(struct bt_error_cause_message_iterator_actor, 1); | |
373 | if (!cause) { | |
374 | BT_LOGE_STR("Failed to allocate one error cause object."); | |
375 | goto error; | |
376 | } | |
377 | ||
378 | ret = init_error_cause(&cause->base, | |
379 | BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR); | |
380 | if (ret) { | |
381 | goto error; | |
382 | } | |
383 | ||
384 | set_error_cause_props(&cause->base, file_name, line_no); | |
385 | cause->comp_name = g_string_new( | |
386 | input_port_iter->upstream_component->name->str); | |
387 | if (!cause->comp_name) { | |
388 | BT_LOGE_STR("Failed to allocate one GString."); | |
389 | goto error; | |
390 | } | |
391 | ||
392 | cause->output_port_name = g_string_new( | |
393 | input_port_iter->upstream_port->name->str); | |
394 | if (!cause->output_port_name) { | |
395 | BT_LOGE_STR("Failed to allocate one GString."); | |
396 | goto error; | |
397 | } | |
398 | ||
399 | ret = init_component_class_id(&cause->comp_class_id, | |
400 | input_port_iter->upstream_component->class); | |
401 | if (ret) { | |
402 | goto error; | |
403 | } | |
404 | ||
405 | g_string_append_printf(cause->base.module_name, "%s (%s): ", | |
406 | input_port_iter->upstream_component->name->str, | |
407 | input_port_iter->upstream_port->name->str); | |
408 | append_component_class_id_str(cause->base.module_name, | |
409 | &cause->comp_class_id); | |
410 | BT_LIB_LOGD("Created error cause object: %!+r", cause); | |
411 | goto end; | |
412 | ||
413 | error: | |
6ef39fe9 SM |
414 | if (cause) { |
415 | destroy_error_cause(&cause->base); | |
416 | cause = NULL; | |
417 | } | |
553c4bab PP |
418 | |
419 | end: | |
420 | return cause; | |
421 | } | |
422 | ||
423 | BT_HIDDEN | |
424 | struct bt_error *bt_error_create(void) | |
425 | { | |
426 | struct bt_error *error; | |
427 | ||
428 | BT_LOGD_STR("Creating error object."); | |
429 | error = g_new0(struct bt_error, 1); | |
430 | if (!error) { | |
431 | BT_LOGE_STR("Failed to allocate one error object."); | |
432 | goto error; | |
433 | } | |
434 | ||
435 | error->causes = g_ptr_array_new_with_free_func( | |
436 | (GDestroyNotify) destroy_error_cause); | |
437 | if (!error->causes) { | |
438 | BT_LOGE_STR("Failed to allocate one GPtrArray."); | |
439 | goto error; | |
440 | } | |
441 | ||
442 | BT_LOGD("Created error object: addr=%p", error); | |
443 | goto end; | |
444 | ||
445 | error: | |
446 | bt_error_destroy(error); | |
447 | error = NULL; | |
448 | ||
449 | end: | |
450 | return error; | |
451 | } | |
452 | ||
453 | BT_HIDDEN | |
454 | void bt_error_destroy(struct bt_error *error) | |
455 | { | |
456 | if (!error) { | |
457 | goto end; | |
458 | } | |
459 | ||
460 | if (error->causes) { | |
461 | g_ptr_array_free(error->causes, TRUE); | |
462 | error->causes = NULL; | |
463 | } | |
464 | ||
465 | g_free(error); | |
466 | ||
467 | end: | |
468 | return; | |
469 | } | |
470 | ||
471 | BT_HIDDEN | |
472 | int bt_error_append_cause_from_unknown(struct bt_error *error, | |
473 | const char *module_name, const char *file_name, | |
474 | uint64_t line_no, const char *msg_fmt, va_list args) | |
475 | { | |
476 | struct bt_error_cause *cause = NULL; | |
477 | int status = BT_FUNC_STATUS_OK; | |
478 | ||
c77d03eb PP |
479 | BT_ASSERT(error); |
480 | BT_ASSERT(module_name); | |
481 | BT_ASSERT(file_name); | |
482 | BT_ASSERT(msg_fmt); | |
553c4bab PP |
483 | BT_LOGD("Appending error cause from unknown actor: " |
484 | "module-name=\"%s\", func-name=\"%s\", line-no=%" PRIu64, | |
485 | module_name, file_name, line_no); | |
486 | cause = create_error_cause(module_name, file_name, line_no); | |
487 | if (!cause) { | |
488 | /* create_error_cause() logs errors */ | |
489 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
490 | goto end; | |
491 | } | |
492 | ||
493 | g_string_append_vprintf(cause->message, msg_fmt, args); | |
494 | g_ptr_array_add(error->causes, cause); | |
495 | BT_LIB_LOGD("Appended error cause: %!+r", cause); | |
496 | cause = NULL; | |
497 | ||
498 | end: | |
499 | destroy_error_cause(cause); | |
500 | return status; | |
501 | } | |
502 | ||
503 | BT_HIDDEN | |
504 | int bt_error_append_cause_from_component( | |
505 | struct bt_error *error, bt_self_component *self_comp, | |
506 | const char *file_name, uint64_t line_no, | |
507 | const char *msg_fmt, va_list args) | |
508 | { | |
509 | struct bt_error_cause_component_actor *cause = NULL; | |
510 | int status = BT_FUNC_STATUS_OK; | |
511 | ||
c77d03eb PP |
512 | BT_ASSERT(error); |
513 | BT_ASSERT(self_comp); | |
514 | BT_ASSERT(file_name); | |
515 | BT_ASSERT(msg_fmt); | |
553c4bab PP |
516 | BT_LIB_LOGD("Appending error cause from component actor: %![comp-]+c", |
517 | self_comp); | |
518 | cause = create_error_cause_component_actor((void *) self_comp, | |
519 | file_name, line_no); | |
520 | if (!cause) { | |
521 | /* create_error_cause_component_actor() logs errors */ | |
522 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
523 | goto end; | |
524 | } | |
525 | ||
526 | g_string_append_vprintf(cause->base.message, msg_fmt, args); | |
527 | g_ptr_array_add(error->causes, cause); | |
528 | BT_LIB_LOGD("Appended error cause: %!+r", cause); | |
529 | cause = NULL; | |
530 | ||
531 | end: | |
6ef39fe9 SM |
532 | if (cause) { |
533 | destroy_error_cause(&cause->base); | |
534 | } | |
535 | ||
553c4bab PP |
536 | return status; |
537 | } | |
538 | ||
539 | BT_HIDDEN | |
540 | int bt_error_append_cause_from_component_class( | |
541 | struct bt_error *error, | |
542 | bt_self_component_class *self_comp_class, | |
543 | const char *file_name, uint64_t line_no, | |
544 | const char *msg_fmt, va_list args) | |
545 | { | |
546 | struct bt_error_cause_component_class_actor *cause = NULL; | |
547 | int status = BT_FUNC_STATUS_OK; | |
548 | ||
c77d03eb PP |
549 | BT_ASSERT(error); |
550 | BT_ASSERT(self_comp_class); | |
551 | BT_ASSERT(file_name); | |
552 | BT_ASSERT(msg_fmt); | |
553c4bab PP |
553 | BT_LIB_LOGD("Appending error cause from component class actor: " |
554 | "%![comp-cls-]+C", self_comp_class); | |
555 | cause = create_error_cause_component_class_actor( | |
556 | (void *) self_comp_class, file_name, line_no); | |
557 | if (!cause) { | |
558 | /* create_error_cause_component_class_actor() logs errors */ | |
559 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
560 | goto end; | |
561 | } | |
562 | ||
563 | g_string_append_vprintf(cause->base.message, msg_fmt, args); | |
564 | g_ptr_array_add(error->causes, cause); | |
565 | BT_LIB_LOGD("Appended error cause: %!+r", cause); | |
566 | cause = NULL; | |
567 | ||
568 | end: | |
6ef39fe9 SM |
569 | if (cause) { |
570 | destroy_error_cause(&cause->base); | |
571 | } | |
572 | ||
553c4bab PP |
573 | return status; |
574 | } | |
575 | ||
576 | BT_HIDDEN | |
577 | int bt_error_append_cause_from_message_iterator( | |
578 | struct bt_error *error, bt_self_message_iterator *self_iter, | |
579 | const char *file_name, uint64_t line_no, | |
580 | const char *msg_fmt, va_list args) | |
581 | { | |
582 | struct bt_error_cause_message_iterator_actor *cause = NULL; | |
583 | int status = BT_FUNC_STATUS_OK; | |
584 | ||
c77d03eb PP |
585 | BT_ASSERT(error); |
586 | BT_ASSERT(self_iter); | |
587 | BT_ASSERT(file_name); | |
588 | BT_ASSERT(msg_fmt); | |
553c4bab PP |
589 | BT_LIB_LOGD("Appending error cause from message iterator actor: " |
590 | "%![comp-]+i", self_iter); | |
591 | cause = create_error_cause_message_iterator_actor( | |
592 | (void *) self_iter, file_name, line_no); | |
593 | if (!cause) { | |
594 | /* create_error_cause_message_iterator_actor() logs errors */ | |
595 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
596 | goto end; | |
597 | } | |
598 | ||
599 | g_string_append_vprintf(cause->base.message, msg_fmt, args); | |
600 | g_ptr_array_add(error->causes, cause); | |
601 | BT_LIB_LOGD("Appended error cause: %!+r", cause); | |
602 | cause = NULL; | |
603 | ||
604 | end: | |
6ef39fe9 SM |
605 | if (cause) { |
606 | destroy_error_cause(&cause->base); | |
607 | } | |
608 | ||
553c4bab PP |
609 | return status; |
610 | } | |
611 | ||
612 | static | |
613 | uint64_t error_cause_count(const bt_error *error) | |
614 | { | |
615 | return error->causes ? error->causes->len : 0; | |
616 | } | |
617 | ||
618 | uint64_t bt_error_get_cause_count(const bt_error *error) | |
619 | { | |
d5b13b9b | 620 | BT_ASSERT_PRE_ERROR_NON_NULL(error); |
553c4bab PP |
621 | return error_cause_count(error); |
622 | } | |
623 | ||
624 | void bt_error_release(const struct bt_error *error) | |
625 | { | |
d5b13b9b | 626 | BT_ASSERT_PRE_ERROR_NON_NULL(error); |
553c4bab PP |
627 | bt_error_destroy((void *) error); |
628 | } | |
629 | ||
630 | const struct bt_error_cause *bt_error_borrow_cause_by_index( | |
631 | const bt_error *error, uint64_t index) | |
632 | { | |
d5b13b9b | 633 | BT_ASSERT_PRE_ERROR_NON_NULL(error); |
553c4bab PP |
634 | BT_ASSERT_PRE_VALID_INDEX(index, error_cause_count(error)); |
635 | return error->causes->pdata[index]; | |
636 | } | |
637 | ||
638 | enum bt_error_cause_actor_type bt_error_cause_get_actor_type( | |
639 | const struct bt_error_cause *cause) | |
640 | { | |
d5b13b9b | 641 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
553c4bab PP |
642 | return cause->actor_type; |
643 | } | |
644 | ||
645 | const char *bt_error_cause_get_message(const struct bt_error_cause *cause) | |
646 | { | |
d5b13b9b | 647 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
553c4bab PP |
648 | return cause->message->str; |
649 | } | |
650 | ||
651 | const char *bt_error_cause_get_module_name(const struct bt_error_cause *cause) | |
652 | { | |
d5b13b9b | 653 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
553c4bab PP |
654 | return cause->module_name->str; |
655 | } | |
656 | ||
657 | const char *bt_error_cause_get_file_name(const struct bt_error_cause *cause) | |
658 | { | |
d5b13b9b | 659 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
553c4bab PP |
660 | return cause->file_name->str; |
661 | } | |
662 | ||
663 | uint64_t bt_error_cause_get_line_number(const bt_error_cause *cause) | |
664 | { | |
d5b13b9b | 665 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
553c4bab PP |
666 | return cause->line_no; |
667 | } | |
668 | ||
669 | const char *bt_error_cause_component_actor_get_component_name( | |
670 | const struct bt_error_cause *cause) | |
671 | { | |
672 | const struct bt_error_cause_component_actor *spec_cause = | |
673 | (const void *) cause; | |
674 | ||
d5b13b9b | 675 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 676 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component", |
553c4bab PP |
677 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT); |
678 | return spec_cause->comp_name->str; | |
679 | } | |
680 | ||
681 | bt_component_class_type bt_error_cause_component_actor_get_component_class_type( | |
682 | const struct bt_error_cause *cause) | |
683 | { | |
684 | const struct bt_error_cause_component_actor *spec_cause = | |
685 | (const void *) cause; | |
686 | ||
d5b13b9b | 687 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 688 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component", |
553c4bab PP |
689 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT); |
690 | return spec_cause->comp_class_id.type; | |
691 | } | |
692 | ||
693 | const char *bt_error_cause_component_actor_get_component_class_name( | |
694 | const struct bt_error_cause *cause) | |
695 | { | |
696 | const struct bt_error_cause_component_actor *spec_cause = | |
697 | (const void *) cause; | |
698 | ||
d5b13b9b | 699 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 700 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component", |
553c4bab PP |
701 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT); |
702 | return spec_cause->comp_class_id.name->str; | |
703 | } | |
704 | ||
705 | const char *bt_error_cause_component_actor_get_plugin_name( | |
706 | const struct bt_error_cause *cause) | |
707 | { | |
708 | const struct bt_error_cause_component_actor *spec_cause = | |
709 | (const void *) cause; | |
710 | ||
d5b13b9b | 711 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 712 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component", |
553c4bab PP |
713 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT); |
714 | return spec_cause->comp_class_id.plugin_name->len > 0 ? | |
715 | spec_cause->comp_class_id.plugin_name->str : NULL; | |
716 | } | |
717 | ||
718 | bt_component_class_type | |
719 | bt_error_cause_component_class_actor_get_component_class_type( | |
720 | const struct bt_error_cause *cause) | |
721 | { | |
722 | const struct bt_error_cause_component_class_actor *spec_cause = | |
723 | (const void *) cause; | |
724 | ||
d5b13b9b | 725 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 726 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component-class", |
553c4bab PP |
727 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS); |
728 | return spec_cause->comp_class_id.type; | |
729 | } | |
730 | ||
731 | const char *bt_error_cause_component_class_actor_get_component_class_name( | |
732 | const struct bt_error_cause *cause) | |
733 | { | |
734 | const struct bt_error_cause_component_class_actor *spec_cause = | |
735 | (const void *) cause; | |
736 | ||
d5b13b9b | 737 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 738 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component-class", |
553c4bab PP |
739 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS); |
740 | return spec_cause->comp_class_id.name->str; | |
741 | } | |
742 | ||
743 | const char *bt_error_cause_component_class_actor_get_plugin_name( | |
744 | const struct bt_error_cause *cause) | |
745 | { | |
746 | const struct bt_error_cause_component_class_actor *spec_cause = | |
747 | (const void *) cause; | |
748 | ||
d5b13b9b | 749 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 750 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "component-class", |
553c4bab PP |
751 | BT_ERROR_CAUSE_ACTOR_TYPE_COMPONENT_CLASS); |
752 | return spec_cause->comp_class_id.plugin_name->len > 0 ? | |
753 | spec_cause->comp_class_id.plugin_name->str : NULL; | |
754 | } | |
755 | ||
756 | const char *bt_error_cause_message_iterator_actor_get_component_name( | |
757 | const struct bt_error_cause *cause) | |
758 | { | |
759 | const struct bt_error_cause_message_iterator_actor *spec_cause = | |
760 | (const void *) cause; | |
761 | ||
d5b13b9b | 762 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 763 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator", |
553c4bab PP |
764 | BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR); |
765 | return spec_cause->comp_name->str; | |
766 | } | |
767 | ||
768 | const char * | |
769 | bt_error_cause_message_iterator_actor_get_component_output_port_name( | |
770 | const struct bt_error_cause *cause) | |
771 | { | |
772 | const struct bt_error_cause_message_iterator_actor *spec_cause = | |
773 | (const void *) cause; | |
774 | ||
d5b13b9b | 775 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 776 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator", |
553c4bab PP |
777 | BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR); |
778 | return spec_cause->output_port_name->str; | |
779 | } | |
780 | ||
781 | bt_component_class_type | |
782 | bt_error_cause_message_iterator_actor_get_component_class_type( | |
783 | const struct bt_error_cause *cause) | |
784 | { | |
785 | const struct bt_error_cause_message_iterator_actor *spec_cause = | |
786 | (const void *) cause; | |
787 | ||
d5b13b9b | 788 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 789 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator", |
553c4bab PP |
790 | BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR); |
791 | return spec_cause->comp_class_id.type; | |
792 | } | |
793 | ||
794 | const char *bt_error_cause_message_iterator_actor_get_component_class_name( | |
795 | const struct bt_error_cause *cause) | |
796 | { | |
797 | const struct bt_error_cause_message_iterator_actor *spec_cause = | |
798 | (const void *) cause; | |
799 | ||
d5b13b9b | 800 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 801 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator", |
553c4bab PP |
802 | BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR); |
803 | return spec_cause->comp_class_id.name->str; | |
804 | } | |
805 | ||
806 | const char *bt_error_cause_message_iterator_actor_get_plugin_name( | |
807 | const struct bt_error_cause *cause) | |
808 | { | |
809 | const struct bt_error_cause_message_iterator_actor *spec_cause = | |
810 | (const void *) cause; | |
811 | ||
d5b13b9b | 812 | BT_ASSERT_PRE_ERROR_CAUSE_NON_NULL(cause); |
1778c2a4 | 813 | BT_ASSERT_PRE_CAUSE_HAS_ACTOR_TYPE(cause, "message-iterator", |
553c4bab PP |
814 | BT_ERROR_CAUSE_ACTOR_TYPE_MESSAGE_ITERATOR); |
815 | return spec_cause->comp_class_id.plugin_name->len > 0 ? | |
816 | spec_cause->comp_class_id.plugin_name->str : NULL; | |
817 | } |