lib: assign a unique ID to each pre/postcond. and report it on failure
[babeltrace.git] / src / lib / graph / component-filter.c
1 /*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
6 */
7
8 #define BT_LOG_TAG "LIB/COMPONENT-FILTER"
9 #include "lib/logging.h"
10
11 #include "common/assert.h"
12 #include "lib/assert-cond.h"
13 #include "compat/compiler.h"
14 #include <babeltrace2/value.h>
15 #include <babeltrace2/graph/self-component.h>
16 #include <babeltrace2/graph/component.h>
17 #include <babeltrace2/graph/graph.h>
18
19 #include "component-filter.h"
20 #include "component.h"
21 #include "component-class.h"
22 #include "lib/func-status.h"
23
24 BT_HIDDEN
25 void bt_component_filter_destroy(struct bt_component *component)
26 {
27 }
28
29 BT_HIDDEN
30 struct bt_component *bt_component_filter_create(
31 const struct bt_component_class *class)
32 {
33 struct bt_component_filter *filter = NULL;
34
35 filter = g_new0(struct bt_component_filter, 1);
36 if (!filter) {
37 BT_LIB_LOGE_APPEND_CAUSE(
38 "Failed to allocate one filter component.");
39 goto end;
40 }
41
42 end:
43 return (void *) filter;
44 }
45
46 const bt_component_class_filter *
47 bt_component_filter_borrow_class_const(
48 const bt_component_filter *component)
49 {
50 struct bt_component_class *cls;
51
52 BT_ASSERT_PRE_DEV_COMP_NON_NULL(component);
53
54 cls = component->parent.class;
55
56 BT_ASSERT_DBG(cls);
57 BT_ASSERT_DBG(cls->type == BT_COMPONENT_CLASS_TYPE_FILTER);
58
59 return (bt_component_class_filter *) cls;
60 }
61
62 uint64_t bt_component_filter_get_output_port_count(
63 const struct bt_component_filter *comp)
64 {
65 /* bt_component_get_output_port_count() checks preconditions */
66 return bt_component_get_output_port_count((void *) comp, __func__);
67 }
68
69 const struct bt_port_output *
70 bt_component_filter_borrow_output_port_by_name_const(
71 const struct bt_component_filter *comp, const char *name)
72 {
73 /*
74 * bt_component_borrow_output_port_by_name() logs details/errors
75 * and checks preconditions.
76 */
77 return bt_component_borrow_output_port_by_name(
78 (void *) comp, name, __func__);
79 }
80
81 struct bt_self_component_port_output *
82 bt_self_component_filter_borrow_output_port_by_name(
83 struct bt_self_component_filter *comp, const char *name)
84 {
85 /*
86 * bt_component_borrow_output_port_by_name() logs details/errors
87 * and checks preconditions.
88 */
89 return (void *) bt_component_borrow_output_port_by_name(
90 (void *) comp, name, __func__);
91 }
92
93 const struct bt_port_output *
94 bt_component_filter_borrow_output_port_by_index_const(
95 const struct bt_component_filter *comp, uint64_t index)
96 {
97 /*
98 * bt_component_borrow_output_port_by_index() logs
99 * details/errors and checks preconditions.
100 */
101 return bt_component_borrow_output_port_by_index(
102 (void *) comp, index, __func__);
103 }
104
105 struct bt_self_component_port_output *
106 bt_self_component_filter_borrow_output_port_by_index(
107 struct bt_self_component_filter *comp, uint64_t index)
108 {
109 /*
110 * bt_component_borrow_output_port_by_index() logs
111 * details/errors and checks preconditions.
112 */
113 return (void *) bt_component_borrow_output_port_by_index(
114 (void *) comp, index, __func__);
115 }
116
117 enum bt_self_component_add_port_status bt_self_component_filter_add_output_port(
118 struct bt_self_component_filter *self_comp,
119 const char *name, void *user_data,
120 struct bt_self_component_port_output **self_port)
121 {
122 struct bt_component *comp = (void *) self_comp;
123 enum bt_self_component_add_port_status status;
124 struct bt_port *port = NULL;
125
126 BT_ASSERT_PRE_NO_ERROR();
127
128 /*
129 * bt_component_add_output_port() logs details/errors and checks
130 * preconditions.
131 */
132 status = bt_component_add_output_port(comp, name, user_data, &port,
133 __func__);
134 if (status != BT_FUNC_STATUS_OK) {
135 goto end;
136 }
137
138 if (self_port) {
139 /* Move reference to user */
140 *self_port = (void *) port;
141 }
142
143 end:
144 bt_object_put_ref(port);
145 return status;
146 }
147
148 uint64_t bt_component_filter_get_input_port_count(
149 const struct bt_component_filter *component)
150 {
151 /* bt_component_get_input_port_count() checks preconditions */
152 return bt_component_get_input_port_count((void *) component, __func__);
153 }
154
155 const struct bt_port_input *bt_component_filter_borrow_input_port_by_name_const(
156 const struct bt_component_filter *component, const char *name)
157 {
158 /*
159 * bt_component_borrow_input_port_by_name() logs details/errors
160 * and checks preconditions.
161 */
162 return bt_component_borrow_input_port_by_name(
163 (void *) component, name, __func__);
164 }
165
166 struct bt_self_component_port_input *
167 bt_self_component_filter_borrow_input_port_by_name(
168 struct bt_self_component_filter *component, const char *name)
169 {
170 /*
171 * bt_component_borrow_input_port_by_name() logs details/errors
172 * and checks preconditions.
173 */
174 return (void *) bt_component_borrow_input_port_by_name(
175 (void *) component, name, __func__);
176 }
177
178 const struct bt_port_input *
179 bt_component_filter_borrow_input_port_by_index_const(
180 const struct bt_component_filter *component, uint64_t index)
181 {
182 /*
183 * bt_component_borrow_input_port_by_index() logs details/errors
184 * and checks preconditions.
185 */
186 return bt_component_borrow_input_port_by_index(
187 (void *) component, index, __func__);
188 }
189
190 struct bt_self_component_port_input *
191 bt_self_component_filter_borrow_input_port_by_index(
192 struct bt_self_component_filter *component, uint64_t index)
193 {
194 /*
195 * bt_component_borrow_input_port_by_index() logs details/errors
196 * and checks preconditions.
197 */
198 return (void *) bt_component_borrow_input_port_by_index(
199 (void *) component, index, __func__);
200 }
201
202 enum bt_self_component_add_port_status bt_self_component_filter_add_input_port(
203 struct bt_self_component_filter *self_comp,
204 const char *name, void *user_data,
205 struct bt_self_component_port_input **self_port)
206 {
207 enum bt_self_component_add_port_status status;
208 struct bt_port *port = NULL;
209 struct bt_component *comp = (void *) self_comp;
210
211 BT_ASSERT_PRE_NO_ERROR();
212
213 /*
214 * bt_component_add_input_port() logs details/errors and checks
215 * preconditions.
216 */
217 status = bt_component_add_input_port(comp, name, user_data, &port,
218 __func__);
219 if (status != BT_FUNC_STATUS_OK) {
220 goto end;
221 }
222
223 if (self_port) {
224 /* Move reference to user */
225 *self_port = (void *) port;
226 }
227
228 end:
229 bt_object_put_ref(port);
230 return status;
231 }
232
233 void bt_component_filter_get_ref(
234 const struct bt_component_filter *component_filter)
235 {
236 bt_object_get_ref(component_filter);
237 }
238
239 void bt_component_filter_put_ref(
240 const struct bt_component_filter *component_filter)
241 {
242 bt_object_put_ref(component_filter);
243 }
This page took 0.03387 seconds and 4 git commands to generate.