2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
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:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
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
24 #define BT_LOG_TAG "LIB/COMPONENT-FILTER"
25 #include "lib/logging.h"
27 #include "common/assert.h"
28 #include "lib/assert-pre.h"
29 #include "compat/compiler.h"
30 #include <babeltrace2/value.h>
31 #include <babeltrace2/graph/self-component-filter.h>
32 #include <babeltrace2/graph/component-filter-const.h>
33 #include <babeltrace2/graph/graph.h>
35 #include "component-filter.h"
36 #include "component.h"
37 #include "component-class.h"
40 void bt_component_filter_destroy(struct bt_component
*component
)
45 struct bt_component
*bt_component_filter_create(
46 const struct bt_component_class
*class)
48 struct bt_component_filter
*filter
= NULL
;
50 filter
= g_new0(struct bt_component_filter
, 1);
52 BT_LOGE_STR("Failed to allocate one filter component.");
57 return (void *) filter
;
60 const bt_component_class_filter
*
61 bt_component_filter_borrow_class_const(
62 const bt_component_filter
*component
)
64 struct bt_component_class
*cls
;
66 BT_ASSERT_PRE_NON_NULL(component
, "Component");
68 cls
= component
->parent
.class;
71 BT_ASSERT(cls
->type
== BT_COMPONENT_CLASS_TYPE_FILTER
);
73 return (bt_component_class_filter
*) cls
;
76 uint64_t bt_component_filter_get_output_port_count(
77 const struct bt_component_filter
*comp
)
79 return bt_component_get_output_port_count((void *) comp
);
82 const struct bt_port_output
*
83 bt_component_filter_borrow_output_port_by_name_const(
84 const struct bt_component_filter
*comp
, const char *name
)
86 return bt_component_borrow_output_port_by_name(
90 struct bt_self_component_port_output
*
91 bt_self_component_filter_borrow_output_port_by_name(
92 struct bt_self_component_filter
*comp
, const char *name
)
94 return (void *) bt_component_borrow_output_port_by_name(
98 const struct bt_port_output
*
99 bt_component_filter_borrow_output_port_by_index_const(
100 const struct bt_component_filter
*comp
, uint64_t index
)
102 return bt_component_borrow_output_port_by_index(
103 (void *) comp
, index
);
106 struct bt_self_component_port_output
*
107 bt_self_component_filter_borrow_output_port_by_index(
108 struct bt_self_component_filter
*comp
, uint64_t index
)
110 return (void *) bt_component_borrow_output_port_by_index(
111 (void *) comp
, index
);
114 enum bt_self_component_status
bt_self_component_filter_add_output_port(
115 struct bt_self_component_filter
*self_comp
,
116 const char *name
, void *user_data
,
117 struct bt_self_component_port_output
**self_port
)
119 struct bt_component
*comp
= (void *) self_comp
;
120 enum bt_self_component_status status
;
121 struct bt_port
*port
= NULL
;
123 /* bt_component_add_output_port() logs details and errors */
124 status
= bt_component_add_output_port(comp
, name
, user_data
, &port
);
125 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
130 /* Move reference to user */
131 *self_port
= (void *) port
;
136 bt_object_put_ref(port
);
140 uint64_t bt_component_filter_get_input_port_count(
141 const struct bt_component_filter
*component
)
143 /* bt_component_get_input_port_count() logs details/errors */
144 return bt_component_get_input_port_count((void *) component
);
147 const struct bt_port_input
*bt_component_filter_borrow_input_port_by_name_const(
148 const struct bt_component_filter
*component
, const char *name
)
150 /* bt_component_borrow_input_port_by_name() logs details/errors */
151 return bt_component_borrow_input_port_by_name(
152 (void *) component
, name
);
155 struct bt_self_component_port_input
*
156 bt_self_component_filter_borrow_input_port_by_name(
157 struct bt_self_component_filter
*component
, const char *name
)
159 /* bt_component_borrow_input_port_by_name() logs details/errors */
160 return (void *) bt_component_borrow_input_port_by_name(
161 (void *) component
, name
);
164 const struct bt_port_input
*
165 bt_component_filter_borrow_input_port_by_index_const(
166 const struct bt_component_filter
*component
, uint64_t index
)
168 /* bt_component_borrow_input_port_by_index() logs details/errors */
169 return bt_component_borrow_input_port_by_index(
170 (void *) component
, index
);
173 struct bt_self_component_port_input
*
174 bt_self_component_filter_borrow_input_port_by_index(
175 struct bt_self_component_filter
*component
, uint64_t index
)
177 /* bt_component_borrow_input_port_by_index() logs details/errors */
178 return (void *) bt_component_borrow_input_port_by_index(
179 (void *) component
, index
);
182 enum bt_self_component_status
bt_self_component_filter_add_input_port(
183 struct bt_self_component_filter
*self_comp
,
184 const char *name
, void *user_data
,
185 struct bt_self_component_port_input
**self_port
)
187 enum bt_self_component_status status
;
188 struct bt_port
*port
= NULL
;
189 struct bt_component
*comp
= (void *) self_comp
;
191 /* bt_component_add_input_port() logs details/errors */
192 status
= bt_component_add_input_port(comp
, name
, user_data
, &port
);
193 if (status
!= BT_SELF_COMPONENT_STATUS_OK
) {
198 /* Move reference to user */
199 *self_port
= (void *) port
;
204 bt_object_put_ref(port
);
208 void bt_component_filter_get_ref(
209 const struct bt_component_filter
*component_filter
)
211 bt_object_get_ref(component_filter
);
214 void bt_component_filter_put_ref(
215 const struct bt_component_filter
*component_filter
)
217 bt_object_put_ref(component_filter
);