Commit | Line | Data |
---|---|---|
d94d92ac | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
e2f7325d | 4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
d94d92ac | 5 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
d94d92ac PP |
6 | */ |
7 | ||
350ad6c1 | 8 | #define BT_LOG_TAG "LIB/COMPONENT-FILTER" |
c2d9d9cf | 9 | #include "lib/logging.h" |
d94d92ac | 10 | |
578e048b MJ |
11 | #include "common/assert.h" |
12 | #include "lib/assert-pre.h" | |
13 | #include "compat/compiler.h" | |
3fadfbc0 | 14 | #include <babeltrace2/value.h> |
43c59509 PP |
15 | #include <babeltrace2/graph/self-component.h> |
16 | #include <babeltrace2/graph/component.h> | |
3fadfbc0 | 17 | #include <babeltrace2/graph/graph.h> |
d94d92ac | 18 | |
578e048b MJ |
19 | #include "component-filter.h" |
20 | #include "component.h" | |
21 | #include "component-class.h" | |
d24d5663 | 22 | #include "lib/func-status.h" |
578e048b | 23 | |
d94d92ac PP |
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( | |
0d72b8c3 | 31 | const struct bt_component_class *class) |
d94d92ac PP |
32 | { |
33 | struct bt_component_filter *filter = NULL; | |
34 | ||
17f3083a SM |
35 | BT_ASSERT_PRE_NO_ERROR(); |
36 | ||
d94d92ac PP |
37 | filter = g_new0(struct bt_component_filter, 1); |
38 | if (!filter) { | |
870631a2 PP |
39 | BT_LIB_LOGE_APPEND_CAUSE( |
40 | "Failed to allocate one filter component."); | |
d94d92ac PP |
41 | goto end; |
42 | } | |
43 | ||
44 | end: | |
45 | return (void *) filter; | |
46 | } | |
47 | ||
752d0e47 SM |
48 | const bt_component_class_filter * |
49 | bt_component_filter_borrow_class_const( | |
50 | const bt_component_filter *component) | |
51 | { | |
52 | struct bt_component_class *cls; | |
53 | ||
bdb288b3 | 54 | BT_ASSERT_PRE_DEV_NON_NULL(component, "Component"); |
752d0e47 SM |
55 | |
56 | cls = component->parent.class; | |
57 | ||
98b15851 PP |
58 | BT_ASSERT_DBG(cls); |
59 | BT_ASSERT_DBG(cls->type == BT_COMPONENT_CLASS_TYPE_FILTER); | |
752d0e47 SM |
60 | |
61 | return (bt_component_class_filter *) cls; | |
62 | } | |
63 | ||
d94d92ac | 64 | uint64_t bt_component_filter_get_output_port_count( |
0d72b8c3 | 65 | const struct bt_component_filter *comp) |
d94d92ac PP |
66 | { |
67 | return bt_component_get_output_port_count((void *) comp); | |
68 | } | |
69 | ||
0d72b8c3 PP |
70 | const struct bt_port_output * |
71 | bt_component_filter_borrow_output_port_by_name_const( | |
72 | const struct bt_component_filter *comp, const char *name) | |
d94d92ac PP |
73 | { |
74 | return bt_component_borrow_output_port_by_name( | |
75 | (void *) comp, name); | |
76 | } | |
77 | ||
78 | struct bt_self_component_port_output * | |
79 | bt_self_component_filter_borrow_output_port_by_name( | |
80 | struct bt_self_component_filter *comp, const char *name) | |
81 | { | |
82 | return (void *) bt_component_borrow_output_port_by_name( | |
83 | (void *) comp, name); | |
84 | } | |
85 | ||
0d72b8c3 PP |
86 | const struct bt_port_output * |
87 | bt_component_filter_borrow_output_port_by_index_const( | |
88 | const struct bt_component_filter *comp, uint64_t index) | |
d94d92ac PP |
89 | { |
90 | return bt_component_borrow_output_port_by_index( | |
91 | (void *) comp, index); | |
92 | } | |
93 | ||
94 | struct bt_self_component_port_output * | |
95 | bt_self_component_filter_borrow_output_port_by_index( | |
96 | struct bt_self_component_filter *comp, uint64_t index) | |
97 | { | |
98 | return (void *) bt_component_borrow_output_port_by_index( | |
99 | (void *) comp, index); | |
100 | } | |
101 | ||
d24d5663 | 102 | enum bt_self_component_add_port_status bt_self_component_filter_add_output_port( |
d94d92ac PP |
103 | struct bt_self_component_filter *self_comp, |
104 | const char *name, void *user_data, | |
105 | struct bt_self_component_port_output **self_port) | |
106 | { | |
107 | struct bt_component *comp = (void *) self_comp; | |
d24d5663 | 108 | enum bt_self_component_add_port_status status; |
d94d92ac PP |
109 | struct bt_port *port = NULL; |
110 | ||
17f3083a SM |
111 | BT_ASSERT_PRE_NO_ERROR(); |
112 | ||
d94d92ac | 113 | /* bt_component_add_output_port() logs details and errors */ |
8cc56726 | 114 | status = bt_component_add_output_port(comp, name, user_data, &port); |
d24d5663 | 115 | if (status != BT_FUNC_STATUS_OK) { |
d94d92ac PP |
116 | goto end; |
117 | } | |
118 | ||
119 | if (self_port) { | |
120 | /* Move reference to user */ | |
121 | *self_port = (void *) port; | |
d94d92ac PP |
122 | } |
123 | ||
124 | end: | |
125 | bt_object_put_ref(port); | |
126 | return status; | |
127 | } | |
128 | ||
129 | uint64_t bt_component_filter_get_input_port_count( | |
0d72b8c3 | 130 | const struct bt_component_filter *component) |
d94d92ac PP |
131 | { |
132 | /* bt_component_get_input_port_count() logs details/errors */ | |
133 | return bt_component_get_input_port_count((void *) component); | |
134 | } | |
135 | ||
0d72b8c3 PP |
136 | const struct bt_port_input *bt_component_filter_borrow_input_port_by_name_const( |
137 | const struct bt_component_filter *component, const char *name) | |
d94d92ac PP |
138 | { |
139 | /* bt_component_borrow_input_port_by_name() logs details/errors */ | |
140 | return bt_component_borrow_input_port_by_name( | |
141 | (void *) component, name); | |
142 | } | |
143 | ||
144 | struct bt_self_component_port_input * | |
145 | bt_self_component_filter_borrow_input_port_by_name( | |
146 | struct bt_self_component_filter *component, const char *name) | |
147 | { | |
148 | /* bt_component_borrow_input_port_by_name() logs details/errors */ | |
149 | return (void *) bt_component_borrow_input_port_by_name( | |
150 | (void *) component, name); | |
151 | } | |
152 | ||
0d72b8c3 PP |
153 | const struct bt_port_input * |
154 | bt_component_filter_borrow_input_port_by_index_const( | |
155 | const struct bt_component_filter *component, uint64_t index) | |
d94d92ac PP |
156 | { |
157 | /* bt_component_borrow_input_port_by_index() logs details/errors */ | |
158 | return bt_component_borrow_input_port_by_index( | |
159 | (void *) component, index); | |
160 | } | |
161 | ||
162 | struct bt_self_component_port_input * | |
163 | bt_self_component_filter_borrow_input_port_by_index( | |
164 | struct bt_self_component_filter *component, uint64_t index) | |
165 | { | |
166 | /* bt_component_borrow_input_port_by_index() logs details/errors */ | |
167 | return (void *) bt_component_borrow_input_port_by_index( | |
168 | (void *) component, index); | |
169 | } | |
170 | ||
d24d5663 | 171 | enum bt_self_component_add_port_status bt_self_component_filter_add_input_port( |
d94d92ac PP |
172 | struct bt_self_component_filter *self_comp, |
173 | const char *name, void *user_data, | |
174 | struct bt_self_component_port_input **self_port) | |
175 | { | |
d24d5663 | 176 | enum bt_self_component_add_port_status status; |
d94d92ac PP |
177 | struct bt_port *port = NULL; |
178 | struct bt_component *comp = (void *) self_comp; | |
179 | ||
17f3083a SM |
180 | BT_ASSERT_PRE_NO_ERROR(); |
181 | ||
d94d92ac | 182 | /* bt_component_add_input_port() logs details/errors */ |
8cc56726 | 183 | status = bt_component_add_input_port(comp, name, user_data, &port); |
d24d5663 | 184 | if (status != BT_FUNC_STATUS_OK) { |
d94d92ac PP |
185 | goto end; |
186 | } | |
187 | ||
188 | if (self_port) { | |
189 | /* Move reference to user */ | |
190 | *self_port = (void *) port; | |
d94d92ac PP |
191 | } |
192 | ||
193 | end: | |
194 | bt_object_put_ref(port); | |
195 | return status; | |
196 | } | |
c5b9b441 PP |
197 | |
198 | void bt_component_filter_get_ref( | |
199 | const struct bt_component_filter *component_filter) | |
200 | { | |
201 | bt_object_get_ref(component_filter); | |
202 | } | |
203 | ||
204 | void bt_component_filter_put_ref( | |
205 | const struct bt_component_filter *component_filter) | |
206 | { | |
207 | bt_object_put_ref(component_filter); | |
208 | } |