Commit | Line | Data |
---|---|---|
fb2dcc52 | 1 | /* |
f2b0325d | 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
3310b217 | 3 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
fb2dcc52 | 4 | * |
fb2dcc52 JG |
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 | ||
b03487ab | 24 | #define BT_LOG_TAG "LIB/COMPONENT-CLASS" |
1633ef46 | 25 | #include "lib/logging.h" |
a3aacb6f | 26 | |
57952005 MJ |
27 | #include "common/assert.h" |
28 | #include "lib/assert-pre.h" | |
29 | #include "compat/compiler.h" | |
71c5da58 MJ |
30 | #include <babeltrace2/graph/component-class.h> |
31 | #include <babeltrace2/graph/component-class-const.h> | |
32 | #include <babeltrace2/graph/component-class-source.h> | |
33 | #include <babeltrace2/graph/component-class-source-const.h> | |
34 | #include <babeltrace2/graph/component-class-filter.h> | |
35 | #include <babeltrace2/graph/component-class-filter-const.h> | |
36 | #include <babeltrace2/graph/component-class-sink.h> | |
37 | #include <babeltrace2/graph/component-class-sink-const.h> | |
71c5da58 | 38 | #include <babeltrace2/types.h> |
fb2dcc52 JG |
39 | #include <glib.h> |
40 | ||
57952005 | 41 | #include "component-class.h" |
fb25b9e3 | 42 | #include "lib/func-status.h" |
57952005 | 43 | |
834e9996 | 44 | #define BT_ASSERT_PRE_COMP_CLS_HOT(_cc) \ |
7b53201c | 45 | BT_ASSERT_PRE_HOT(((const struct bt_component_class *) (_cc)), \ |
834e9996 PP |
46 | "Component class", ": %!+C", (_cc)) |
47 | ||
fb2dcc52 | 48 | static |
834e9996 | 49 | void destroy_component_class(struct bt_object *obj) |
fb2dcc52 JG |
50 | { |
51 | struct bt_component_class *class; | |
33b34c43 | 52 | int i; |
fb2dcc52 | 53 | |
8b45963b | 54 | BT_ASSERT(obj); |
b8a06801 | 55 | class = container_of(obj, struct bt_component_class, base); |
33b34c43 | 56 | |
a684a357 | 57 | BT_LIB_LOGI("Destroying component class: %!+C", class); |
a3aacb6f | 58 | |
33b34c43 PP |
59 | /* Call destroy listeners in reverse registration order */ |
60 | for (i = class->destroy_listeners->len - 1; i >= 0; i--) { | |
d3e4dcd8 | 61 | struct bt_component_class_destroy_listener *listener = |
33b34c43 | 62 | &g_array_index(class->destroy_listeners, |
d3e4dcd8 | 63 | struct bt_component_class_destroy_listener, |
33b34c43 PP |
64 | i); |
65 | ||
a3aacb6f PP |
66 | BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p", |
67 | listener->func, listener->data); | |
33b34c43 PP |
68 | listener->func(class, listener->data); |
69 | } | |
70 | ||
fb2dcc52 JG |
71 | if (class->name) { |
72 | g_string_free(class->name, TRUE); | |
834e9996 | 73 | class->name = NULL; |
fb2dcc52 | 74 | } |
834e9996 | 75 | |
7c7c0433 JG |
76 | if (class->description) { |
77 | g_string_free(class->description, TRUE); | |
834e9996 | 78 | class->description = NULL; |
7c7c0433 | 79 | } |
834e9996 | 80 | |
5536d9a6 PP |
81 | if (class->help) { |
82 | g_string_free(class->help, TRUE); | |
834e9996 | 83 | class->help = NULL; |
5536d9a6 | 84 | } |
834e9996 | 85 | |
33b34c43 PP |
86 | if (class->destroy_listeners) { |
87 | g_array_free(class->destroy_listeners, TRUE); | |
834e9996 | 88 | class->destroy_listeners = NULL; |
33b34c43 | 89 | } |
b8a06801 | 90 | |
fb2dcc52 JG |
91 | g_free(class); |
92 | } | |
93 | ||
d3e4dcd8 PP |
94 | static |
95 | int bt_component_class_init(struct bt_component_class *class, | |
96 | enum bt_component_class_type type, const char *name) | |
fb2dcc52 | 97 | { |
d3e4dcd8 PP |
98 | int ret = 0; |
99 | ||
834e9996 | 100 | bt_object_init_shared(&class->base, destroy_component_class); |
d3e4dcd8 PP |
101 | class->type = type; |
102 | class->name = g_string_new(name); | |
103 | if (!class->name) { | |
a3aacb6f | 104 | BT_LOGE_STR("Failed to allocate a GString."); |
d3e4dcd8 PP |
105 | goto error; |
106 | } | |
107 | ||
108 | class->description = g_string_new(NULL); | |
109 | if (!class->description) { | |
a3aacb6f | 110 | BT_LOGE_STR("Failed to allocate a GString."); |
d3e4dcd8 PP |
111 | goto error; |
112 | } | |
113 | ||
5536d9a6 PP |
114 | class->help = g_string_new(NULL); |
115 | if (!class->help) { | |
a3aacb6f | 116 | BT_LOGE_STR("Failed to allocate a GString."); |
5536d9a6 PP |
117 | goto error; |
118 | } | |
119 | ||
d3e4dcd8 PP |
120 | class->destroy_listeners = g_array_new(FALSE, TRUE, |
121 | sizeof(struct bt_component_class_destroy_listener)); | |
122 | if (!class->destroy_listeners) { | |
a3aacb6f | 123 | BT_LOGE_STR("Failed to allocate a GArray."); |
d3e4dcd8 PP |
124 | goto error; |
125 | } | |
126 | ||
127 | goto end; | |
6ba0b073 | 128 | |
d3e4dcd8 | 129 | error: |
8138bfe1 | 130 | BT_OBJECT_PUT_REF_AND_RESET(class); |
d3e4dcd8 PP |
131 | ret = -1; |
132 | ||
133 | end: | |
134 | return ret; | |
135 | } | |
136 | ||
7b53201c | 137 | struct bt_component_class_source *bt_component_class_source_create( |
834e9996 | 138 | const char *name, |
b09a5592 | 139 | bt_component_class_source_message_iterator_next_method method) |
d3e4dcd8 PP |
140 | { |
141 | struct bt_component_class_source *source_class = NULL; | |
142 | int ret; | |
143 | ||
834e9996 | 144 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
b09a5592 | 145 | BT_ASSERT_PRE_NON_NULL(method, "Message iterator next method"); |
a684a357 | 146 | BT_LOGI("Creating source component class: " |
b09a5592 | 147 | "name=\"%s\", msg-iter-next-method-addr=%p", |
fe7265b5 | 148 | name, method); |
d3e4dcd8 PP |
149 | source_class = g_new0(struct bt_component_class_source, 1); |
150 | if (!source_class) { | |
a3aacb6f | 151 | BT_LOGE_STR("Failed to allocate one source component class."); |
fb2dcc52 JG |
152 | goto end; |
153 | } | |
154 | ||
a3aacb6f | 155 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
156 | ret = bt_component_class_init(&source_class->parent, |
157 | BT_COMPONENT_CLASS_TYPE_SOURCE, name); | |
158 | if (ret) { | |
159 | /* | |
160 | * If bt_component_class_init() fails, the component | |
161 | * class is put, therefore its memory is already | |
162 | * freed. | |
163 | */ | |
164 | source_class = NULL; | |
165 | goto end; | |
166 | } | |
167 | ||
b09a5592 | 168 | source_class->methods.msg_iter_next = method; |
a684a357 | 169 | BT_LIB_LOGI("Created source component class: %!+C", source_class); |
d3e4dcd8 PP |
170 | |
171 | end: | |
834e9996 | 172 | return (void *) source_class; |
d3e4dcd8 PP |
173 | } |
174 | ||
7b53201c PP |
175 | struct bt_component_class_filter *bt_component_class_filter_create( |
176 | const char *name, | |
b09a5592 | 177 | bt_component_class_filter_message_iterator_next_method method) |
d3e4dcd8 PP |
178 | { |
179 | struct bt_component_class_filter *filter_class = NULL; | |
180 | int ret; | |
181 | ||
834e9996 | 182 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
b09a5592 | 183 | BT_ASSERT_PRE_NON_NULL(method, "Message iterator next method"); |
a684a357 | 184 | BT_LOGI("Creating filter component class: " |
b09a5592 | 185 | "name=\"%s\", msg-iter-next-method-addr=%p", |
fe7265b5 | 186 | name, method); |
d3e4dcd8 PP |
187 | filter_class = g_new0(struct bt_component_class_filter, 1); |
188 | if (!filter_class) { | |
a3aacb6f | 189 | BT_LOGE_STR("Failed to allocate one filter component class."); |
d3e4dcd8 | 190 | goto end; |
6ba0b073 PP |
191 | } |
192 | ||
a3aacb6f | 193 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
194 | ret = bt_component_class_init(&filter_class->parent, |
195 | BT_COMPONENT_CLASS_TYPE_FILTER, name); | |
196 | if (ret) { | |
197 | /* | |
198 | * If bt_component_class_init() fails, the component | |
199 | * class is put, therefore its memory is already | |
200 | * freed. | |
201 | */ | |
202 | filter_class = NULL; | |
33b34c43 PP |
203 | goto end; |
204 | } | |
d3e4dcd8 | 205 | |
b09a5592 | 206 | filter_class->methods.msg_iter_next = method; |
a684a357 | 207 | BT_LIB_LOGI("Created filter component class: %!+C", filter_class); |
d3e4dcd8 | 208 | |
fb2dcc52 | 209 | end: |
834e9996 | 210 | return (void *) filter_class; |
d3e4dcd8 PP |
211 | } |
212 | ||
7b53201c PP |
213 | struct bt_component_class_sink *bt_component_class_sink_create( |
214 | const char *name, bt_component_class_sink_consume_method method) | |
d3e4dcd8 PP |
215 | { |
216 | struct bt_component_class_sink *sink_class = NULL; | |
217 | int ret; | |
218 | ||
834e9996 PP |
219 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
220 | BT_ASSERT_PRE_NON_NULL(method, "Consume next method"); | |
a684a357 | 221 | BT_LOGI("Creating sink component class: " |
a3aacb6f | 222 | "name=\"%s\", consume-method-addr=%p", |
fe7265b5 | 223 | name, method); |
d3e4dcd8 PP |
224 | sink_class = g_new0(struct bt_component_class_sink, 1); |
225 | if (!sink_class) { | |
a3aacb6f | 226 | BT_LOGE_STR("Failed to allocate one sink component class."); |
d3e4dcd8 PP |
227 | goto end; |
228 | } | |
229 | ||
a3aacb6f | 230 | /* bt_component_class_init() logs errors */ |
d3e4dcd8 PP |
231 | ret = bt_component_class_init(&sink_class->parent, |
232 | BT_COMPONENT_CLASS_TYPE_SINK, name); | |
233 | if (ret) { | |
234 | /* | |
235 | * If bt_component_class_init() fails, the component | |
236 | * class is put, therefore its memory is already | |
237 | * freed. | |
238 | */ | |
239 | sink_class = NULL; | |
240 | goto end; | |
241 | } | |
242 | ||
fe7265b5 | 243 | sink_class->methods.consume = method; |
a684a357 | 244 | BT_LIB_LOGI("Created sink component class: %!+C", sink_class); |
d3e4dcd8 PP |
245 | |
246 | end: | |
834e9996 | 247 | return (void *) sink_class; |
d3e4dcd8 PP |
248 | } |
249 | ||
fb25b9e3 | 250 | enum bt_component_class_set_method_status |
15a52f66 | 251 | bt_component_class_source_set_init_method( |
7b53201c PP |
252 | struct bt_component_class_source *comp_cls, |
253 | bt_component_class_source_init_method method) | |
d3e4dcd8 | 254 | { |
834e9996 PP |
255 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
256 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
257 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
258 | comp_cls->methods.init = method; | |
a684a357 | 259 | BT_LIB_LOGD("Set source component class's initialization method: " |
834e9996 | 260 | "%!+C", comp_cls); |
fb25b9e3 | 261 | return BT_FUNC_STATUS_OK; |
d3e4dcd8 PP |
262 | } |
263 | ||
fb25b9e3 | 264 | enum bt_component_class_set_method_status |
15a52f66 | 265 | bt_component_class_filter_set_init_method( |
7b53201c PP |
266 | struct bt_component_class_filter *comp_cls, |
267 | bt_component_class_filter_init_method method) | |
efa96d5d | 268 | { |
834e9996 PP |
269 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
270 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
271 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
272 | comp_cls->methods.init = method; | |
a684a357 | 273 | BT_LIB_LOGD("Set filter component class's initialization method: " |
834e9996 | 274 | "%!+C", comp_cls); |
fb25b9e3 | 275 | return BT_FUNC_STATUS_OK; |
efa96d5d PP |
276 | } |
277 | ||
fb25b9e3 | 278 | enum bt_component_class_set_method_status |
15a52f66 | 279 | bt_component_class_sink_set_init_method( |
7b53201c PP |
280 | struct bt_component_class_sink *comp_cls, |
281 | bt_component_class_sink_init_method method) | |
2d41b99e | 282 | { |
834e9996 PP |
283 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
284 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
285 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
286 | comp_cls->methods.init = method; | |
a684a357 | 287 | BT_LIB_LOGD("Set sink component class's initialization method: " |
834e9996 | 288 | "%!+C", comp_cls); |
fb25b9e3 | 289 | return BT_FUNC_STATUS_OK; |
72b913fb PP |
290 | } |
291 | ||
fb25b9e3 | 292 | enum bt_component_class_set_method_status |
15a52f66 | 293 | bt_component_class_source_set_finalize_method( |
7b53201c PP |
294 | struct bt_component_class_source *comp_cls, |
295 | bt_component_class_source_finalize_method method) | |
0d8b4d8e | 296 | { |
834e9996 PP |
297 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
298 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
299 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
300 | comp_cls->methods.finalize = method; | |
a684a357 | 301 | BT_LIB_LOGD("Set source component class's finalization method: " |
834e9996 | 302 | "%!+C", comp_cls); |
fb25b9e3 | 303 | return BT_FUNC_STATUS_OK; |
0d8b4d8e PP |
304 | } |
305 | ||
fb25b9e3 | 306 | enum bt_component_class_set_method_status |
15a52f66 | 307 | bt_component_class_filter_set_finalize_method( |
7b53201c PP |
308 | struct bt_component_class_filter *comp_cls, |
309 | bt_component_class_filter_finalize_method method) | |
72b913fb | 310 | { |
834e9996 PP |
311 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
312 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
313 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
314 | comp_cls->methods.finalize = method; | |
a684a357 | 315 | BT_LIB_LOGD("Set filter component class's finalization method: " |
834e9996 | 316 | "%!+C", comp_cls); |
fb25b9e3 | 317 | return BT_FUNC_STATUS_OK; |
2d41b99e JG |
318 | } |
319 | ||
fb25b9e3 | 320 | enum bt_component_class_set_method_status |
15a52f66 | 321 | bt_component_class_sink_set_finalize_method( |
7b53201c PP |
322 | struct bt_component_class_sink *comp_cls, |
323 | bt_component_class_sink_finalize_method method) | |
d3e4dcd8 | 324 | { |
834e9996 PP |
325 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
326 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
327 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
328 | comp_cls->methods.finalize = method; | |
a684a357 | 329 | BT_LIB_LOGD("Set sink component class's finalization method: " |
834e9996 | 330 | "%!+C", comp_cls); |
fb25b9e3 | 331 | return BT_FUNC_STATUS_OK; |
d3e4dcd8 PP |
332 | } |
333 | ||
fb25b9e3 | 334 | enum bt_component_class_set_method_status |
15a52f66 | 335 | bt_component_class_source_set_query_method( |
7b53201c PP |
336 | struct bt_component_class_source *comp_cls, |
337 | bt_component_class_source_query_method method) | |
d3eb6e8f | 338 | { |
834e9996 PP |
339 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
340 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
341 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
342 | comp_cls->methods.query = method; | |
a684a357 | 343 | BT_LIB_LOGD("Set source component class's query method: " |
834e9996 | 344 | "%!+C", comp_cls); |
fb25b9e3 | 345 | return BT_FUNC_STATUS_OK; |
d3eb6e8f PP |
346 | } |
347 | ||
fb25b9e3 | 348 | enum bt_component_class_set_method_status |
15a52f66 | 349 | bt_component_class_filter_set_query_method( |
7b53201c PP |
350 | struct bt_component_class_filter *comp_cls, |
351 | bt_component_class_filter_query_method method) | |
d3eb6e8f | 352 | { |
834e9996 PP |
353 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
354 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
355 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
356 | comp_cls->methods.query = method; | |
a684a357 | 357 | BT_LIB_LOGD("Set filter component class's query method: " |
834e9996 | 358 | "%!+C", comp_cls); |
fb25b9e3 | 359 | return BT_FUNC_STATUS_OK; |
834e9996 | 360 | } |
a3aacb6f | 361 | |
fb25b9e3 | 362 | enum bt_component_class_set_method_status |
15a52f66 | 363 | bt_component_class_sink_set_query_method( |
7b53201c PP |
364 | struct bt_component_class_sink *comp_cls, |
365 | bt_component_class_sink_query_method method) | |
834e9996 | 366 | { |
834e9996 PP |
367 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
368 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
369 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
370 | comp_cls->methods.query = method; | |
a684a357 | 371 | BT_LIB_LOGD("Set sink component class's query method: " |
834e9996 | 372 | "%!+C", comp_cls); |
fb25b9e3 | 373 | return BT_FUNC_STATUS_OK; |
834e9996 | 374 | } |
d3eb6e8f | 375 | |
fb25b9e3 | 376 | enum bt_component_class_set_method_status |
15a52f66 | 377 | bt_component_class_filter_set_input_port_connected_method( |
7b53201c PP |
378 | struct bt_component_class_filter *comp_cls, |
379 | bt_component_class_filter_input_port_connected_method method) | |
834e9996 | 380 | { |
834e9996 PP |
381 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
382 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
383 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
384 | comp_cls->methods.input_port_connected = method; | |
a684a357 | 385 | BT_LIB_LOGD("Set filter component class's \"input port connected\" method" |
834e9996 | 386 | ": %!+C", comp_cls); |
fb25b9e3 | 387 | return BT_FUNC_STATUS_OK; |
834e9996 | 388 | } |
a3aacb6f | 389 | |
fb25b9e3 | 390 | enum bt_component_class_set_method_status |
15a52f66 | 391 | bt_component_class_sink_set_input_port_connected_method( |
7b53201c PP |
392 | struct bt_component_class_sink *comp_cls, |
393 | bt_component_class_sink_input_port_connected_method method) | |
834e9996 | 394 | { |
834e9996 PP |
395 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
396 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
397 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
398 | comp_cls->methods.input_port_connected = method; | |
a684a357 | 399 | BT_LIB_LOGD("Set sink component class's \"input port connected\" method" |
834e9996 | 400 | ": %!+C", comp_cls); |
fb25b9e3 | 401 | return BT_FUNC_STATUS_OK; |
834e9996 | 402 | } |
a3aacb6f | 403 | |
fb25b9e3 | 404 | enum bt_component_class_set_method_status |
15a52f66 | 405 | bt_component_class_source_set_output_port_connected_method( |
7b53201c PP |
406 | struct bt_component_class_source *comp_cls, |
407 | bt_component_class_source_output_port_connected_method method) | |
834e9996 | 408 | { |
834e9996 PP |
409 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
410 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
411 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
412 | comp_cls->methods.output_port_connected = method; | |
a684a357 | 413 | BT_LIB_LOGD("Set source component class's \"output port connected\" method" |
834e9996 | 414 | ": %!+C", comp_cls); |
fb25b9e3 | 415 | return BT_FUNC_STATUS_OK; |
834e9996 | 416 | } |
d3eb6e8f | 417 | |
fb25b9e3 | 418 | enum bt_component_class_set_method_status |
15a52f66 | 419 | bt_component_class_filter_set_output_port_connected_method( |
7b53201c PP |
420 | struct bt_component_class_filter *comp_cls, |
421 | bt_component_class_filter_output_port_connected_method method) | |
834e9996 | 422 | { |
834e9996 PP |
423 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
424 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
425 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
426 | comp_cls->methods.output_port_connected = method; | |
a684a357 | 427 | BT_LIB_LOGD("Set filter component class's \"output port connected\" method" |
834e9996 | 428 | ": %!+C", comp_cls); |
fb25b9e3 | 429 | return BT_FUNC_STATUS_OK; |
834e9996 | 430 | } |
d3eb6e8f | 431 | |
fb25b9e3 | 432 | enum bt_component_class_set_method_status |
1043fdea PP |
433 | bt_component_class_sink_set_graph_is_configured_method( |
434 | struct bt_component_class_sink *comp_cls, | |
435 | bt_component_class_sink_graph_is_configured_method method) | |
436 | { | |
437 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); | |
438 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
439 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
440 | comp_cls->methods.graph_is_configured = method; | |
a684a357 | 441 | BT_LIB_LOGD("Set sink component class's \"graph is configured\" method" |
1043fdea | 442 | ": %!+C", comp_cls); |
fb25b9e3 | 443 | return BT_FUNC_STATUS_OK; |
1043fdea PP |
444 | } |
445 | ||
fb25b9e3 PP |
446 | enum bt_component_class_set_method_status |
447 | bt_component_class_source_set_message_iterator_init_method( | |
7b53201c | 448 | struct bt_component_class_source *comp_cls, |
b09a5592 | 449 | bt_component_class_source_message_iterator_init_method method) |
834e9996 | 450 | { |
834e9996 PP |
451 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
452 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
453 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
b09a5592 | 454 | comp_cls->methods.msg_iter_init = method; |
a684a357 | 455 | BT_LIB_LOGD("Set source component class's message iterator initialization method" |
834e9996 | 456 | ": %!+C", comp_cls); |
fb25b9e3 | 457 | return BT_FUNC_STATUS_OK; |
834e9996 | 458 | } |
a3aacb6f | 459 | |
fb25b9e3 | 460 | enum bt_component_class_set_method_status |
15a52f66 | 461 | bt_component_class_filter_set_message_iterator_init_method( |
7b53201c | 462 | struct bt_component_class_filter *comp_cls, |
b09a5592 | 463 | bt_component_class_filter_message_iterator_init_method method) |
834e9996 | 464 | { |
834e9996 PP |
465 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
466 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
467 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
b09a5592 | 468 | comp_cls->methods.msg_iter_init = method; |
a684a357 | 469 | BT_LIB_LOGD("Set filter component class's message iterator initialization method" |
834e9996 | 470 | ": %!+C", comp_cls); |
fb25b9e3 | 471 | return BT_FUNC_STATUS_OK; |
834e9996 | 472 | } |
d3eb6e8f | 473 | |
fb25b9e3 | 474 | enum bt_component_class_set_method_status |
15a52f66 | 475 | bt_component_class_source_set_message_iterator_finalize_method( |
7b53201c | 476 | struct bt_component_class_source *comp_cls, |
b09a5592 | 477 | bt_component_class_source_message_iterator_finalize_method method) |
834e9996 | 478 | { |
834e9996 PP |
479 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
480 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
481 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
b09a5592 | 482 | comp_cls->methods.msg_iter_finalize = method; |
a684a357 | 483 | BT_LIB_LOGD("Set source component class's message iterator finalization method" |
834e9996 | 484 | ": %!+C", comp_cls); |
fb25b9e3 | 485 | return BT_FUNC_STATUS_OK; |
834e9996 | 486 | } |
d3eb6e8f | 487 | |
fb25b9e3 | 488 | enum bt_component_class_set_method_status |
15a52f66 | 489 | bt_component_class_filter_set_message_iterator_finalize_method( |
7b53201c | 490 | struct bt_component_class_filter *comp_cls, |
b09a5592 | 491 | bt_component_class_filter_message_iterator_finalize_method method) |
834e9996 | 492 | { |
834e9996 PP |
493 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
494 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
495 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
b09a5592 | 496 | comp_cls->methods.msg_iter_finalize = method; |
a684a357 | 497 | BT_LIB_LOGD("Set filter component class's message iterator finalization method" |
834e9996 | 498 | ": %!+C", comp_cls); |
fb25b9e3 | 499 | return BT_FUNC_STATUS_OK; |
d3eb6e8f PP |
500 | } |
501 | ||
fb25b9e3 | 502 | enum bt_component_class_set_method_status |
15a52f66 PP |
503 | bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method( |
504 | struct bt_component_class_filter *comp_cls, | |
505 | bt_component_class_filter_message_iterator_seek_ns_from_origin_method method) | |
506 | { | |
507 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); | |
508 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
509 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
510 | comp_cls->methods.msg_iter_seek_ns_from_origin = method; | |
a684a357 | 511 | BT_LIB_LOGD("Set filter component class's message iterator \"seek nanoseconds from origin\" method" |
15a52f66 | 512 | ": %!+C", comp_cls); |
fb25b9e3 | 513 | return BT_FUNC_STATUS_OK; |
15a52f66 PP |
514 | } |
515 | ||
fb25b9e3 | 516 | enum bt_component_class_set_method_status |
15a52f66 PP |
517 | bt_component_class_source_set_message_iterator_seek_ns_from_origin_method( |
518 | struct bt_component_class_source *comp_cls, | |
519 | bt_component_class_source_message_iterator_seek_ns_from_origin_method method) | |
520 | { | |
521 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); | |
522 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
523 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
524 | comp_cls->methods.msg_iter_seek_ns_from_origin = method; | |
a684a357 | 525 | BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" method" |
15a52f66 | 526 | ": %!+C", comp_cls); |
fb25b9e3 | 527 | return BT_FUNC_STATUS_OK; |
15a52f66 PP |
528 | } |
529 | ||
fb25b9e3 | 530 | enum bt_component_class_set_method_status |
15a52f66 PP |
531 | bt_component_class_filter_set_message_iterator_seek_beginning_method( |
532 | struct bt_component_class_filter *comp_cls, | |
533 | bt_component_class_filter_message_iterator_seek_beginning_method method) | |
534 | { | |
535 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); | |
536 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
537 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
538 | comp_cls->methods.msg_iter_seek_beginning = method; | |
a684a357 | 539 | BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" method" |
15a52f66 | 540 | ": %!+C", comp_cls); |
fb25b9e3 | 541 | return BT_FUNC_STATUS_OK; |
15a52f66 PP |
542 | } |
543 | ||
fb25b9e3 | 544 | enum bt_component_class_set_method_status |
15a52f66 PP |
545 | bt_component_class_source_set_message_iterator_seek_beginning_method( |
546 | struct bt_component_class_source *comp_cls, | |
547 | bt_component_class_source_message_iterator_seek_beginning_method method) | |
548 | { | |
549 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); | |
550 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
551 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
552 | comp_cls->methods.msg_iter_seek_beginning = method; | |
a684a357 | 553 | BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" method" |
15a52f66 | 554 | ": %!+C", comp_cls); |
fb25b9e3 | 555 | return BT_FUNC_STATUS_OK; |
15a52f66 PP |
556 | } |
557 | ||
fb25b9e3 | 558 | enum bt_component_class_set_method_status |
15a52f66 PP |
559 | bt_component_class_filter_set_message_iterator_can_seek_beginning_method( |
560 | struct bt_component_class_filter *comp_cls, | |
561 | bt_component_class_filter_message_iterator_can_seek_beginning_method method) | |
562 | { | |
563 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); | |
564 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
565 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
566 | comp_cls->methods.msg_iter_can_seek_beginning = method; | |
a684a357 | 567 | BT_LIB_LOGD("Set filter component class's message iterator \"can seek beginning\" method" |
15a52f66 | 568 | ": %!+C", comp_cls); |
fb25b9e3 | 569 | return BT_FUNC_STATUS_OK; |
15a52f66 PP |
570 | } |
571 | ||
fb25b9e3 | 572 | enum bt_component_class_set_method_status |
15a52f66 PP |
573 | bt_component_class_source_set_message_iterator_can_seek_beginning_method( |
574 | struct bt_component_class_source *comp_cls, | |
575 | bt_component_class_source_message_iterator_can_seek_beginning_method method) | |
576 | { | |
577 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); | |
578 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
579 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
580 | comp_cls->methods.msg_iter_can_seek_beginning = method; | |
a684a357 | 581 | BT_LIB_LOGD("Set source component class's message iterator \"can seek beginning\" method" |
15a52f66 | 582 | ": %!+C", comp_cls); |
fb25b9e3 | 583 | return BT_FUNC_STATUS_OK; |
15a52f66 PP |
584 | } |
585 | ||
fb25b9e3 | 586 | enum bt_component_class_set_method_status |
15a52f66 PP |
587 | bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method( |
588 | struct bt_component_class_filter *comp_cls, | |
589 | bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method method) | |
590 | { | |
591 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); | |
592 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
593 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
594 | comp_cls->methods.msg_iter_can_seek_ns_from_origin = method; | |
a684a357 | 595 | BT_LIB_LOGD("Set filter component class's message iterator \"can seek nanoseconds from origin\" method" |
15a52f66 | 596 | ": %!+C", comp_cls); |
fb25b9e3 | 597 | return BT_FUNC_STATUS_OK; |
15a52f66 PP |
598 | } |
599 | ||
fb25b9e3 | 600 | enum bt_component_class_set_method_status |
15a52f66 PP |
601 | bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method( |
602 | struct bt_component_class_source *comp_cls, | |
603 | bt_component_class_source_message_iterator_can_seek_ns_from_origin_method method) | |
604 | { | |
605 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); | |
606 | BT_ASSERT_PRE_NON_NULL(method, "Method"); | |
607 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
608 | comp_cls->methods.msg_iter_can_seek_ns_from_origin = method; | |
a684a357 | 609 | BT_LIB_LOGD("Set source component class's message iterator \"can seek nanoseconds from origin\" method" |
15a52f66 | 610 | ": %!+C", comp_cls); |
fb25b9e3 | 611 | return BT_FUNC_STATUS_OK; |
15a52f66 PP |
612 | } |
613 | ||
fb25b9e3 PP |
614 | enum bt_component_class_set_description_status |
615 | bt_component_class_set_description( | |
7b53201c | 616 | struct bt_component_class *comp_cls, |
d3e4dcd8 PP |
617 | const char *description) |
618 | { | |
834e9996 PP |
619 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
620 | BT_ASSERT_PRE_NON_NULL(description, "Description"); | |
621 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
622 | g_string_assign(comp_cls->description, description); | |
a684a357 | 623 | BT_LIB_LOGD("Set component class's description: " |
a3aacb6f | 624 | "addr=%p, name=\"%s\", type=%s", |
834e9996 PP |
625 | comp_cls, |
626 | bt_component_class_get_name(comp_cls), | |
627 | bt_component_class_type_string(comp_cls->type)); | |
fb25b9e3 | 628 | return BT_FUNC_STATUS_OK; |
fb2dcc52 | 629 | } |
38b48196 | 630 | |
fb25b9e3 | 631 | enum bt_component_class_set_help_status bt_component_class_set_help( |
7b53201c | 632 | struct bt_component_class *comp_cls, |
5536d9a6 PP |
633 | const char *help) |
634 | { | |
834e9996 PP |
635 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
636 | BT_ASSERT_PRE_NON_NULL(help, "Help"); | |
637 | BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls); | |
638 | g_string_assign(comp_cls->help, help); | |
a684a357 | 639 | BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls); |
fb25b9e3 | 640 | return BT_FUNC_STATUS_OK; |
5536d9a6 PP |
641 | } |
642 | ||
7b53201c | 643 | const char *bt_component_class_get_name(const struct bt_component_class *comp_cls) |
38b48196 | 644 | { |
834e9996 PP |
645 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
646 | return comp_cls->name->str; | |
38b48196 JG |
647 | } |
648 | ||
d3e4dcd8 | 649 | enum bt_component_class_type bt_component_class_get_type( |
7b53201c | 650 | const struct bt_component_class *comp_cls) |
38b48196 | 651 | { |
834e9996 PP |
652 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
653 | return comp_cls->type; | |
38b48196 JG |
654 | } |
655 | ||
33b34c43 | 656 | const char *bt_component_class_get_description( |
7b53201c | 657 | const struct bt_component_class *comp_cls) |
38b48196 | 658 | { |
834e9996 PP |
659 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
660 | return comp_cls->description && | |
661 | comp_cls->description->str[0] != '\0' ? | |
662 | comp_cls->description->str : NULL; | |
38b48196 | 663 | } |
7c7c0433 | 664 | |
5536d9a6 | 665 | const char *bt_component_class_get_help( |
7b53201c | 666 | const struct bt_component_class *comp_cls) |
5536d9a6 | 667 | { |
834e9996 PP |
668 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
669 | return comp_cls->help && | |
670 | comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL; | |
5536d9a6 PP |
671 | } |
672 | ||
33b34c43 | 673 | BT_HIDDEN |
834e9996 PP |
674 | void bt_component_class_add_destroy_listener( |
675 | struct bt_component_class *comp_cls, | |
33b34c43 | 676 | bt_component_class_destroy_listener_func func, void *data) |
7c7c0433 | 677 | { |
d3e4dcd8 | 678 | struct bt_component_class_destroy_listener listener; |
33b34c43 | 679 | |
834e9996 | 680 | BT_ASSERT(comp_cls); |
8b45963b | 681 | BT_ASSERT(func); |
33b34c43 PP |
682 | listener.func = func; |
683 | listener.data = data; | |
834e9996 | 684 | g_array_append_val(comp_cls->destroy_listeners, listener); |
a684a357 | 685 | BT_LIB_LOGD("Added destroy listener to component class: " |
834e9996 | 686 | "%![cc-]+C, listener-func-addr=%p", comp_cls, func); |
7c7c0433 | 687 | } |
d3e4dcd8 | 688 | |
834e9996 | 689 | BT_HIDDEN |
7b53201c | 690 | void _bt_component_class_freeze(const struct bt_component_class *comp_cls) |
1e4d8103 | 691 | { |
834e9996 PP |
692 | BT_ASSERT(comp_cls); |
693 | BT_LIB_LOGD("Freezing component class: %!+C", comp_cls); | |
7b53201c | 694 | ((struct bt_component_class *) comp_cls)->frozen = true; |
1e4d8103 | 695 | } |
8c6884d9 PP |
696 | |
697 | void bt_component_class_get_ref( | |
698 | const struct bt_component_class *component_class) | |
699 | { | |
700 | bt_object_get_ref(component_class); | |
701 | } | |
702 | ||
703 | void bt_component_class_put_ref( | |
704 | const struct bt_component_class *component_class) | |
705 | { | |
706 | bt_object_put_ref(component_class); | |
707 | } | |
708 | ||
709 | void bt_component_class_source_get_ref( | |
710 | const struct bt_component_class_source *component_class_source) | |
711 | { | |
712 | bt_object_get_ref(component_class_source); | |
713 | } | |
714 | ||
715 | void bt_component_class_source_put_ref( | |
716 | const struct bt_component_class_source *component_class_source) | |
717 | { | |
718 | bt_object_put_ref(component_class_source); | |
719 | } | |
720 | ||
721 | void bt_component_class_filter_get_ref( | |
722 | const struct bt_component_class_filter *component_class_filter) | |
723 | { | |
724 | bt_object_get_ref(component_class_filter); | |
725 | } | |
726 | ||
727 | void bt_component_class_filter_put_ref( | |
728 | const struct bt_component_class_filter *component_class_filter) | |
729 | { | |
730 | bt_object_put_ref(component_class_filter); | |
731 | } | |
732 | ||
733 | void bt_component_class_sink_get_ref( | |
734 | const struct bt_component_class_sink *component_class_sink) | |
735 | { | |
736 | bt_object_get_ref(component_class_sink); | |
737 | } | |
738 | ||
739 | void bt_component_class_sink_put_ref( | |
740 | const struct bt_component_class_sink *component_class_sink) | |
741 | { | |
742 | bt_object_put_ref(component_class_sink); | |
743 | } |