32a12924737f7af43569dafecdaf0cc2c8dfa5e7
[babeltrace.git] / lib / graph / component-filter.c
1 /*
2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 *
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
24 #define BT_LOG_TAG "COMP-FILTER"
25 #include <babeltrace/lib-logging-internal.h>
26
27 #include <babeltrace/assert-internal.h>
28 #include <babeltrace/assert-pre-internal.h>
29 #include <babeltrace/compiler-internal.h>
30 #include <babeltrace/value.h>
31 #include <babeltrace/graph/self-component-filter.h>
32 #include <babeltrace/graph/component-filter-const.h>
33 #include <babeltrace/graph/component-filter-internal.h>
34 #include <babeltrace/graph/component-internal.h>
35 #include <babeltrace/graph/component-class-internal.h>
36 #include <babeltrace/graph/graph.h>
37
38 BT_HIDDEN
39 void bt_component_filter_destroy(struct bt_component *component)
40 {
41 }
42
43 BT_HIDDEN
44 struct bt_component *bt_component_filter_create(
45 const struct bt_component_class *class)
46 {
47 struct bt_component_filter *filter = NULL;
48
49 filter = g_new0(struct bt_component_filter, 1);
50 if (!filter) {
51 BT_LOGE_STR("Failed to allocate one filter component.");
52 goto end;
53 }
54
55 end:
56 return (void *) filter;
57 }
58
59 uint64_t bt_component_filter_get_output_port_count(
60 const struct bt_component_filter *comp)
61 {
62 return bt_component_get_output_port_count((void *) comp);
63 }
64
65 const struct bt_port_output *
66 bt_component_filter_borrow_output_port_by_name_const(
67 const struct bt_component_filter *comp, const char *name)
68 {
69 return bt_component_borrow_output_port_by_name(
70 (void *) comp, name);
71 }
72
73 struct bt_self_component_port_output *
74 bt_self_component_filter_borrow_output_port_by_name(
75 struct bt_self_component_filter *comp, const char *name)
76 {
77 return (void *) bt_component_borrow_output_port_by_name(
78 (void *) comp, name);
79 }
80
81 const struct bt_port_output *
82 bt_component_filter_borrow_output_port_by_index_const(
83 const struct bt_component_filter *comp, uint64_t index)
84 {
85 return bt_component_borrow_output_port_by_index(
86 (void *) comp, index);
87 }
88
89 struct bt_self_component_port_output *
90 bt_self_component_filter_borrow_output_port_by_index(
91 struct bt_self_component_filter *comp, uint64_t index)
92 {
93 return (void *) bt_component_borrow_output_port_by_index(
94 (void *) comp, index);
95 }
96
97 enum bt_self_component_status bt_self_component_filter_add_output_port(
98 struct bt_self_component_filter *self_comp,
99 const char *name, void *user_data,
100 struct bt_self_component_port_output **self_port)
101 {
102 struct bt_component *comp = (void *) self_comp;
103 int status = BT_SELF_COMPONENT_STATUS_OK;
104 struct bt_port *port = NULL;
105
106 /* bt_component_add_output_port() logs details and errors */
107 port = (void *) bt_component_add_output_port(comp, name, user_data);
108 if (!port) {
109 status = BT_SELF_COMPONENT_STATUS_NOMEM;
110 goto end;
111 }
112
113 if (self_port) {
114 /* Move reference to user */
115 *self_port = (void *) port;
116 port = NULL;
117 }
118
119 end:
120 bt_object_put_ref(port);
121 return status;
122 }
123
124 uint64_t bt_component_filter_get_input_port_count(
125 const struct bt_component_filter *component)
126 {
127 /* bt_component_get_input_port_count() logs details/errors */
128 return bt_component_get_input_port_count((void *) component);
129 }
130
131 const struct bt_port_input *bt_component_filter_borrow_input_port_by_name_const(
132 const struct bt_component_filter *component, const char *name)
133 {
134 /* bt_component_borrow_input_port_by_name() logs details/errors */
135 return bt_component_borrow_input_port_by_name(
136 (void *) component, name);
137 }
138
139 struct bt_self_component_port_input *
140 bt_self_component_filter_borrow_input_port_by_name(
141 struct bt_self_component_filter *component, const char *name)
142 {
143 /* bt_component_borrow_input_port_by_name() logs details/errors */
144 return (void *) bt_component_borrow_input_port_by_name(
145 (void *) component, name);
146 }
147
148 const struct bt_port_input *
149 bt_component_filter_borrow_input_port_by_index_const(
150 const struct bt_component_filter *component, uint64_t index)
151 {
152 /* bt_component_borrow_input_port_by_index() logs details/errors */
153 return bt_component_borrow_input_port_by_index(
154 (void *) component, index);
155 }
156
157 struct bt_self_component_port_input *
158 bt_self_component_filter_borrow_input_port_by_index(
159 struct bt_self_component_filter *component, uint64_t index)
160 {
161 /* bt_component_borrow_input_port_by_index() logs details/errors */
162 return (void *) bt_component_borrow_input_port_by_index(
163 (void *) component, index);
164 }
165
166 enum bt_self_component_status bt_self_component_filter_add_input_port(
167 struct bt_self_component_filter *self_comp,
168 const char *name, void *user_data,
169 struct bt_self_component_port_input **self_port)
170 {
171 int status = BT_SELF_COMPONENT_STATUS_OK;
172 struct bt_port *port = NULL;
173 struct bt_component *comp = (void *) self_comp;
174
175 /* bt_component_add_input_port() logs details/errors */
176 port = (void *) bt_component_add_input_port(comp, name, user_data);
177 if (!port) {
178 status = BT_SELF_COMPONENT_STATUS_NOMEM;
179 goto end;
180 }
181
182 if (self_port) {
183 /* Move reference to user */
184 *self_port = (void *) port;
185 port = NULL;
186 }
187
188 end:
189 bt_object_put_ref(port);
190 return status;
191 }
192
193 void bt_component_filter_get_ref(
194 const struct bt_component_filter *component_filter)
195 {
196 bt_object_get_ref(component_filter);
197 }
198
199 void bt_component_filter_put_ref(
200 const struct bt_component_filter *component_filter)
201 {
202 bt_object_put_ref(component_filter);
203 }
This page took 0.04223 seconds and 3 git commands to generate.