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