Fix: lib: add NULL check for destroy_listeners in destroy_component_class
[babeltrace.git] / src / ctf-writer / visitor.c
CommitLineData
16ca5ff0 1/*
0235b0db 2 * SPDX-License-Identifier: MIT
16ca5ff0
PP
3 *
4 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
0235b0db 6 * Babeltrace CTF writer - Visitor
16ca5ff0
PP
7 */
8
217cf9d3 9#include <babeltrace2-ctf-writer/object.h>
16ca5ff0 10
91d81473 11#include "common/macros.h"
578e048b
MJ
12
13#include "visitor.h"
14
16ca5ff0
PP
15BT_HIDDEN
16int bt_ctf_visitor_helper(struct bt_ctf_visitor_object *root,
17 bt_ctf_child_count_accessor child_counter,
18 bt_ctf_child_accessor child_accessor,
19 bt_ctf_child_visitor child_visitor,
20 bt_ctf_visitor visitor,
21 void *data)
22{
23 int ret, child_count, i;
24
25 ret = visitor(root, data);
26 if (ret) {
27 goto end;
28 }
29
30 child_count = child_counter(root->object);
31 if (child_count < 0) {
32 ret = child_count;
33 goto end;
34 }
35
36 for (i = 0; i < child_count; i++) {
37 void *child;
38
39 child = child_accessor(root->object, i);
40 if (!child) {
41 ret = -1;
42 goto end;
43 }
44 ret = child_visitor(child, visitor, data);
e1e02a22 45 BT_CTF_OBJECT_PUT_REF_AND_RESET(child);
16ca5ff0
PP
46 if (ret) {
47 goto end;
48 }
49 }
50end:
51 return ret;
52}
53
54enum bt_ctf_visitor_object_type bt_ctf_visitor_object_get_type(
55 struct bt_ctf_visitor_object *object)
56{
57 enum bt_ctf_visitor_object_type ret = BT_CTF_VISITOR_OBJECT_TYPE_UNKNOWN;
58
59 if (!object) {
60 goto end;
61 }
62
63 ret = object->type;
64end:
65 return ret;
66}
67
68void *bt_ctf_visitor_object_get_object(struct bt_ctf_visitor_object *object)
69{
70 void *ret = NULL;
71
72 if (!object) {
73 goto end;
74 }
75
76 ret = object->object;
77end:
78 return ret;
79}
This page took 0.06126 seconds and 4 git commands to generate.