Commit | Line | Data |
---|---|---|
d94d92ac | 1 | /* |
e2f7325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
d94d92ac PP |
3 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
4 | * | |
d94d92ac PP |
5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
6 | * of this software and associated documentation files (the "Software"), to deal | |
7 | * in the Software without restriction, including without limitation the rights | |
8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
9 | * copies of the Software, and to permit persons to whom the Software is | |
10 | * furnished to do so, subject to the following conditions: | |
11 | * | |
12 | * The above copyright notice and this permission notice shall be included in | |
13 | * all copies or substantial portions of the Software. | |
14 | * | |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
21 | * SOFTWARE. | |
22 | */ | |
23 | ||
350ad6c1 | 24 | #define BT_LOG_TAG "LIB/COMPONENT-FILTER" |
c2d9d9cf | 25 | #include "lib/logging.h" |
d94d92ac | 26 | |
578e048b MJ |
27 | #include "common/assert.h" |
28 | #include "lib/assert-pre.h" | |
29 | #include "compat/compiler.h" | |
3fadfbc0 MJ |
30 | #include <babeltrace2/value.h> |
31 | #include <babeltrace2/graph/self-component-filter.h> | |
32 | #include <babeltrace2/graph/component-filter-const.h> | |
3fadfbc0 | 33 | #include <babeltrace2/graph/graph.h> |
d94d92ac | 34 | |
578e048b MJ |
35 | #include "component-filter.h" |
36 | #include "component.h" | |
37 | #include "component-class.h" | |
d24d5663 | 38 | #include "lib/func-status.h" |
578e048b | 39 | |
d94d92ac PP |
40 | BT_HIDDEN |
41 | void bt_component_filter_destroy(struct bt_component *component) | |
42 | { | |
43 | } | |
44 | ||
45 | BT_HIDDEN | |
46 | struct bt_component *bt_component_filter_create( | |
0d72b8c3 | 47 | const struct bt_component_class *class) |
d94d92ac PP |
48 | { |
49 | struct bt_component_filter *filter = NULL; | |
50 | ||
51 | filter = g_new0(struct bt_component_filter, 1); | |
52 | if (!filter) { | |
870631a2 PP |
53 | BT_LIB_LOGE_APPEND_CAUSE( |
54 | "Failed to allocate one filter component."); | |
d94d92ac PP |
55 | goto end; |
56 | } | |
57 | ||
58 | end: | |
59 | return (void *) filter; | |
60 | } | |
61 | ||
752d0e47 SM |
62 | const bt_component_class_filter * |
63 | bt_component_filter_borrow_class_const( | |
64 | const bt_component_filter *component) | |
65 | { | |
66 | struct bt_component_class *cls; | |
67 | ||
bdb288b3 | 68 | BT_ASSERT_PRE_DEV_NON_NULL(component, "Component"); |
752d0e47 SM |
69 | |
70 | cls = component->parent.class; | |
71 | ||
72 | BT_ASSERT(cls); | |
73 | BT_ASSERT(cls->type == BT_COMPONENT_CLASS_TYPE_FILTER); | |
74 | ||
75 | return (bt_component_class_filter *) cls; | |
76 | } | |
77 | ||
d94d92ac | 78 | uint64_t bt_component_filter_get_output_port_count( |
0d72b8c3 | 79 | const struct bt_component_filter *comp) |
d94d92ac PP |
80 | { |
81 | return bt_component_get_output_port_count((void *) comp); | |
82 | } | |
83 | ||
0d72b8c3 PP |
84 | const struct bt_port_output * |
85 | bt_component_filter_borrow_output_port_by_name_const( | |
86 | const struct bt_component_filter *comp, const char *name) | |
d94d92ac PP |
87 | { |
88 | return bt_component_borrow_output_port_by_name( | |
89 | (void *) comp, name); | |
90 | } | |
91 | ||
92 | struct bt_self_component_port_output * | |
93 | bt_self_component_filter_borrow_output_port_by_name( | |
94 | struct bt_self_component_filter *comp, const char *name) | |
95 | { | |
96 | return (void *) bt_component_borrow_output_port_by_name( | |
97 | (void *) comp, name); | |
98 | } | |
99 | ||
0d72b8c3 PP |
100 | const struct bt_port_output * |
101 | bt_component_filter_borrow_output_port_by_index_const( | |
102 | const struct bt_component_filter *comp, uint64_t index) | |
d94d92ac PP |
103 | { |
104 | return bt_component_borrow_output_port_by_index( | |
105 | (void *) comp, index); | |
106 | } | |
107 | ||
108 | struct bt_self_component_port_output * | |
109 | bt_self_component_filter_borrow_output_port_by_index( | |
110 | struct bt_self_component_filter *comp, uint64_t index) | |
111 | { | |
112 | return (void *) bt_component_borrow_output_port_by_index( | |
113 | (void *) comp, index); | |
114 | } | |
115 | ||
d24d5663 | 116 | enum bt_self_component_add_port_status bt_self_component_filter_add_output_port( |
d94d92ac PP |
117 | struct bt_self_component_filter *self_comp, |
118 | const char *name, void *user_data, | |
119 | struct bt_self_component_port_output **self_port) | |
120 | { | |
121 | struct bt_component *comp = (void *) self_comp; | |
d24d5663 | 122 | enum bt_self_component_add_port_status status; |
d94d92ac PP |
123 | struct bt_port *port = NULL; |
124 | ||
125 | /* bt_component_add_output_port() logs details and errors */ | |
8cc56726 | 126 | status = bt_component_add_output_port(comp, name, user_data, &port); |
d24d5663 | 127 | if (status != BT_FUNC_STATUS_OK) { |
d94d92ac PP |
128 | goto end; |
129 | } | |
130 | ||
131 | if (self_port) { | |
132 | /* Move reference to user */ | |
133 | *self_port = (void *) port; | |
134 | port = NULL; | |
135 | } | |
136 | ||
137 | end: | |
138 | bt_object_put_ref(port); | |
139 | return status; | |
140 | } | |
141 | ||
142 | uint64_t bt_component_filter_get_input_port_count( | |
0d72b8c3 | 143 | const struct bt_component_filter *component) |
d94d92ac PP |
144 | { |
145 | /* bt_component_get_input_port_count() logs details/errors */ | |
146 | return bt_component_get_input_port_count((void *) component); | |
147 | } | |
148 | ||
0d72b8c3 PP |
149 | const struct bt_port_input *bt_component_filter_borrow_input_port_by_name_const( |
150 | const struct bt_component_filter *component, const char *name) | |
d94d92ac PP |
151 | { |
152 | /* bt_component_borrow_input_port_by_name() logs details/errors */ | |
153 | return bt_component_borrow_input_port_by_name( | |
154 | (void *) component, name); | |
155 | } | |
156 | ||
157 | struct bt_self_component_port_input * | |
158 | bt_self_component_filter_borrow_input_port_by_name( | |
159 | struct bt_self_component_filter *component, const char *name) | |
160 | { | |
161 | /* bt_component_borrow_input_port_by_name() logs details/errors */ | |
162 | return (void *) bt_component_borrow_input_port_by_name( | |
163 | (void *) component, name); | |
164 | } | |
165 | ||
0d72b8c3 PP |
166 | const struct bt_port_input * |
167 | bt_component_filter_borrow_input_port_by_index_const( | |
168 | const struct bt_component_filter *component, uint64_t index) | |
d94d92ac PP |
169 | { |
170 | /* bt_component_borrow_input_port_by_index() logs details/errors */ | |
171 | return bt_component_borrow_input_port_by_index( | |
172 | (void *) component, index); | |
173 | } | |
174 | ||
175 | struct bt_self_component_port_input * | |
176 | bt_self_component_filter_borrow_input_port_by_index( | |
177 | struct bt_self_component_filter *component, uint64_t index) | |
178 | { | |
179 | /* bt_component_borrow_input_port_by_index() logs details/errors */ | |
180 | return (void *) bt_component_borrow_input_port_by_index( | |
181 | (void *) component, index); | |
182 | } | |
183 | ||
d24d5663 | 184 | enum bt_self_component_add_port_status bt_self_component_filter_add_input_port( |
d94d92ac PP |
185 | struct bt_self_component_filter *self_comp, |
186 | const char *name, void *user_data, | |
187 | struct bt_self_component_port_input **self_port) | |
188 | { | |
d24d5663 | 189 | enum bt_self_component_add_port_status status; |
d94d92ac PP |
190 | struct bt_port *port = NULL; |
191 | struct bt_component *comp = (void *) self_comp; | |
192 | ||
193 | /* bt_component_add_input_port() logs details/errors */ | |
8cc56726 | 194 | status = bt_component_add_input_port(comp, name, user_data, &port); |
d24d5663 | 195 | if (status != BT_FUNC_STATUS_OK) { |
d94d92ac PP |
196 | goto end; |
197 | } | |
198 | ||
199 | if (self_port) { | |
200 | /* Move reference to user */ | |
201 | *self_port = (void *) port; | |
202 | port = NULL; | |
203 | } | |
204 | ||
205 | end: | |
206 | bt_object_put_ref(port); | |
207 | return status; | |
208 | } | |
c5b9b441 PP |
209 | |
210 | void bt_component_filter_get_ref( | |
211 | const struct bt_component_filter *component_filter) | |
212 | { | |
213 | bt_object_get_ref(component_filter); | |
214 | } | |
215 | ||
216 | void bt_component_filter_put_ref( | |
217 | const struct bt_component_filter *component_filter) | |
218 | { | |
219 | bt_object_put_ref(component_filter); | |
220 | } |