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