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