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