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