bt2: update value.py, make test_value pass
[babeltrace.git] / lib / graph / component-filter.c
CommitLineData
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
24#define BT_LOG_TAG "COMP-FILTER"
25#include <babeltrace/lib-logging-internal.h>
26
c5b9b441
PP
27#include <babeltrace/assert-internal.h>
28#include <babeltrace/assert-pre-internal.h>
d94d92ac 29#include <babeltrace/compiler-internal.h>
c6bd8523 30#include <babeltrace/value.h>
d94d92ac 31#include <babeltrace/graph/self-component-filter.h>
0d72b8c3 32#include <babeltrace/graph/component-filter-const.h>
d94d92ac
PP
33#include <babeltrace/graph/component-filter-internal.h>
34#include <babeltrace/graph/component-internal.h>
35#include <babeltrace/graph/component-class-internal.h>
d94d92ac 36#include <babeltrace/graph/graph.h>
d94d92ac
PP
37
38BT_HIDDEN
39void bt_component_filter_destroy(struct bt_component *component)
40{
41}
42
43BT_HIDDEN
44struct bt_component *bt_component_filter_create(
0d72b8c3 45 const struct bt_component_class *class)
d94d92ac
PP
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
55end:
56 return (void *) filter;
57}
58
59uint64_t bt_component_filter_get_output_port_count(
0d72b8c3 60 const struct bt_component_filter *comp)
d94d92ac
PP
61{
62 return bt_component_get_output_port_count((void *) comp);
63}
64
0d72b8c3
PP
65const struct bt_port_output *
66bt_component_filter_borrow_output_port_by_name_const(
67 const struct bt_component_filter *comp, const char *name)
d94d92ac
PP
68{
69 return bt_component_borrow_output_port_by_name(
70 (void *) comp, name);
71}
72
73struct bt_self_component_port_output *
74bt_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
0d72b8c3
PP
81const struct bt_port_output *
82bt_component_filter_borrow_output_port_by_index_const(
83 const struct bt_component_filter *comp, uint64_t index)
d94d92ac
PP
84{
85 return bt_component_borrow_output_port_by_index(
86 (void *) comp, index);
87}
88
89struct bt_self_component_port_output *
90bt_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
97enum 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
119end:
120 bt_object_put_ref(port);
121 return status;
122}
123
124uint64_t bt_component_filter_get_input_port_count(
0d72b8c3 125 const struct bt_component_filter *component)
d94d92ac
PP
126{
127 /* bt_component_get_input_port_count() logs details/errors */
128 return bt_component_get_input_port_count((void *) component);
129}
130
0d72b8c3
PP
131const struct bt_port_input *bt_component_filter_borrow_input_port_by_name_const(
132 const struct bt_component_filter *component, const char *name)
d94d92ac
PP
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
139struct bt_self_component_port_input *
140bt_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
0d72b8c3
PP
148const struct bt_port_input *
149bt_component_filter_borrow_input_port_by_index_const(
150 const struct bt_component_filter *component, uint64_t index)
d94d92ac
PP
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
157struct bt_self_component_port_input *
158bt_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
166enum 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
188end:
189 bt_object_put_ref(port);
190 return status;
191}
c5b9b441
PP
192
193void bt_component_filter_get_ref(
194 const struct bt_component_filter *component_filter)
195{
196 bt_object_get_ref(component_filter);
197}
198
199void 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.033134 seconds and 4 git commands to generate.