Fix: lib: add NULL check for destroy_listeners in destroy_component_class
[babeltrace.git] / src / lib / graph / component-class.c
CommitLineData
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 27static
d94d92ac 28void 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
89static
90int 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 130error:
65300d60 131 BT_OBJECT_PUT_REF_AND_RESET(class);
d3e4dcd8
PP
132 ret = -1;
133
134end:
135 return ret;
136}
137
41a3efcd
SM
138static
139int 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
155end:
156 return ret;
157}
158
0d72b8c3 159struct bt_component_class_source *bt_component_class_source_create(
d94d92ac 160 const char *name,
a3f0c7db 161 struct bt_message_iterator_class *message_iterator_class)
d3e4dcd8
PP
162{
163 struct bt_component_class_source *source_class = NULL;
164 int ret;
165
17f3083a 166 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
167 BT_ASSERT_PRE_NAME_NON_NULL(name);
168 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
a3f0c7db
SM
169 BT_LIB_LOGI("Creating source component class: "
170 "name=\"%s\", %![msg-iter-cls-]+I",
171 name, message_iterator_class);
d3e4dcd8
PP
172 source_class = g_new0(struct bt_component_class_source, 1);
173 if (!source_class) {
870631a2
PP
174 BT_LIB_LOGE_APPEND_CAUSE(
175 "Failed to allocate one source component class.");
fb2dcc52
JG
176 goto end;
177 }
178
a3aacb6f 179 /* bt_component_class_init() logs errors */
41a3efcd
SM
180 ret = bt_component_class_with_iterator_class_init(&source_class->parent,
181 BT_COMPONENT_CLASS_TYPE_SOURCE, name, message_iterator_class);
d3e4dcd8
PP
182 if (ret) {
183 /*
184 * If bt_component_class_init() fails, the component
185 * class is put, therefore its memory is already
186 * freed.
187 */
188 source_class = NULL;
189 goto end;
190 }
191
3f7d4d90 192 BT_LIB_LOGI("Created source component class: %!+C", source_class);
d3e4dcd8
PP
193
194end:
d94d92ac 195 return (void *) source_class;
d3e4dcd8
PP
196}
197
0d72b8c3
PP
198struct bt_component_class_filter *bt_component_class_filter_create(
199 const char *name,
a3f0c7db 200 struct bt_message_iterator_class *message_iterator_class)
d3e4dcd8
PP
201{
202 struct bt_component_class_filter *filter_class = NULL;
203 int ret;
204
17f3083a 205 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
206 BT_ASSERT_PRE_NAME_NON_NULL(name);
207 BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class);
a3f0c7db
SM
208 BT_LIB_LOGI("Creating filter component class: "
209 "name=\"%s\", %![msg-iter-cls-]+I",
210 name, message_iterator_class);
d3e4dcd8
PP
211 filter_class = g_new0(struct bt_component_class_filter, 1);
212 if (!filter_class) {
870631a2
PP
213 BT_LIB_LOGE_APPEND_CAUSE(
214 "Failed to allocate one filter component class.");
d3e4dcd8 215 goto end;
6ba0b073
PP
216 }
217
a3aacb6f 218 /* bt_component_class_init() logs errors */
41a3efcd
SM
219 ret = bt_component_class_with_iterator_class_init(&filter_class->parent,
220 BT_COMPONENT_CLASS_TYPE_FILTER, name, message_iterator_class);
d3e4dcd8
PP
221 if (ret) {
222 /*
223 * If bt_component_class_init() fails, the component
224 * class is put, therefore its memory is already
225 * freed.
226 */
227 filter_class = NULL;
33b34c43
PP
228 goto end;
229 }
d3e4dcd8 230
3f7d4d90 231 BT_LIB_LOGI("Created filter component class: %!+C", filter_class);
d3e4dcd8 232
fb2dcc52 233end:
d94d92ac 234 return (void *) filter_class;
d3e4dcd8
PP
235}
236
0d72b8c3
PP
237struct bt_component_class_sink *bt_component_class_sink_create(
238 const char *name, bt_component_class_sink_consume_method method)
d3e4dcd8
PP
239{
240 struct bt_component_class_sink *sink_class = NULL;
241 int ret;
242
17f3083a 243 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b 244 BT_ASSERT_PRE_NAME_NON_NULL(name);
1778c2a4 245 BT_ASSERT_PRE_NON_NULL("consume-method", method, "Consume next method");
3f7d4d90 246 BT_LOGI("Creating sink component class: "
a3aacb6f 247 "name=\"%s\", consume-method-addr=%p",
90157d89 248 name, method);
d3e4dcd8
PP
249 sink_class = g_new0(struct bt_component_class_sink, 1);
250 if (!sink_class) {
870631a2
PP
251 BT_LIB_LOGE_APPEND_CAUSE(
252 "Failed to allocate one sink component class.");
d3e4dcd8
PP
253 goto end;
254 }
255
a3aacb6f 256 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
257 ret = bt_component_class_init(&sink_class->parent,
258 BT_COMPONENT_CLASS_TYPE_SINK, name);
259 if (ret) {
260 /*
261 * If bt_component_class_init() fails, the component
262 * class is put, therefore its memory is already
263 * freed.
264 */
265 sink_class = NULL;
266 goto end;
267 }
268
90157d89 269 sink_class->methods.consume = method;
3f7d4d90 270 BT_LIB_LOGI("Created sink component class: %!+C", sink_class);
d3e4dcd8
PP
271
272end:
d94d92ac 273 return (void *) sink_class;
d3e4dcd8
PP
274}
275
2b55df78
PP
276enum bt_component_class_set_method_status
277bt_component_class_source_set_get_supported_mip_versions_method(
278 struct bt_component_class_source *comp_cls,
279 bt_component_class_source_get_supported_mip_versions_method method)
280{
17f3083a 281 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
282 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
283 BT_ASSERT_PRE_METHOD_NON_NULL(method);
2b55df78
PP
284 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
285 comp_cls->methods.get_supported_mip_versions = method;
286 BT_LIB_LOGD("Set source component class's \"get supported MIP versions\" method: "
287 "%!+C", comp_cls);
288 return BT_FUNC_STATUS_OK;
289}
290
291enum bt_component_class_set_method_status
292bt_component_class_filter_set_get_supported_mip_versions_method(
293 struct bt_component_class_filter *comp_cls,
294 bt_component_class_filter_get_supported_mip_versions_method method)
295{
17f3083a 296 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
297 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
298 BT_ASSERT_PRE_METHOD_NON_NULL(method);
2b55df78
PP
299 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
300 comp_cls->methods.get_supported_mip_versions = method;
301 BT_LIB_LOGD("Set filter component class's \"get supported MIP versions\" method: "
302 "%!+C", comp_cls);
303 return BT_FUNC_STATUS_OK;
304}
305
306enum bt_component_class_set_method_status
307bt_component_class_sink_set_get_supported_mip_versions_method(
308 struct bt_component_class_sink *comp_cls,
309 bt_component_class_sink_get_supported_mip_versions_method method)
310{
17f3083a 311 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
312 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
313 BT_ASSERT_PRE_METHOD_NON_NULL(method);
2b55df78
PP
314 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
315 comp_cls->methods.get_supported_mip_versions = method;
316 BT_LIB_LOGD("Set sink component class's \"get supported MIP versions\" method: "
317 "%!+C", comp_cls);
318 return BT_FUNC_STATUS_OK;
319}
320
d24d5663 321enum bt_component_class_set_method_status
21a9f056 322bt_component_class_source_set_initialize_method(
0d72b8c3 323 struct bt_component_class_source *comp_cls,
21a9f056 324 bt_component_class_source_initialize_method method)
d3e4dcd8 325{
17f3083a 326 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
327 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
328 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 329 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 330 comp_cls->methods.init = method;
3f7d4d90 331 BT_LIB_LOGD("Set source component class's initialization method: "
d94d92ac 332 "%!+C", comp_cls);
d24d5663 333 return BT_FUNC_STATUS_OK;
d3e4dcd8
PP
334}
335
d24d5663 336enum bt_component_class_set_method_status
21a9f056 337bt_component_class_filter_set_initialize_method(
0d72b8c3 338 struct bt_component_class_filter *comp_cls,
21a9f056 339 bt_component_class_filter_initialize_method method)
efa96d5d 340{
17f3083a 341 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
342 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
343 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 344 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 345 comp_cls->methods.init = method;
3f7d4d90 346 BT_LIB_LOGD("Set filter component class's initialization method: "
d94d92ac 347 "%!+C", comp_cls);
d24d5663 348 return BT_FUNC_STATUS_OK;
efa96d5d
PP
349}
350
d24d5663 351enum bt_component_class_set_method_status
21a9f056 352bt_component_class_sink_set_initialize_method(
0d72b8c3 353 struct bt_component_class_sink *comp_cls,
21a9f056 354 bt_component_class_sink_initialize_method method)
2d41b99e 355{
17f3083a 356 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
357 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
358 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 359 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 360 comp_cls->methods.init = method;
3f7d4d90 361 BT_LIB_LOGD("Set sink component class's initialization method: "
d94d92ac 362 "%!+C", comp_cls);
d24d5663 363 return BT_FUNC_STATUS_OK;
72b913fb
PP
364}
365
d24d5663 366enum bt_component_class_set_method_status
7474e7d3 367bt_component_class_source_set_finalize_method(
0d72b8c3
PP
368 struct bt_component_class_source *comp_cls,
369 bt_component_class_source_finalize_method method)
0d8b4d8e 370{
17f3083a 371 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
372 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
373 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 374 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 375 comp_cls->methods.finalize = method;
3f7d4d90 376 BT_LIB_LOGD("Set source component class's finalization method: "
d94d92ac 377 "%!+C", comp_cls);
d24d5663 378 return BT_FUNC_STATUS_OK;
0d8b4d8e
PP
379}
380
d24d5663 381enum bt_component_class_set_method_status
7474e7d3 382bt_component_class_filter_set_finalize_method(
0d72b8c3
PP
383 struct bt_component_class_filter *comp_cls,
384 bt_component_class_filter_finalize_method method)
72b913fb 385{
17f3083a 386 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
387 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
388 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 389 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 390 comp_cls->methods.finalize = method;
3f7d4d90 391 BT_LIB_LOGD("Set filter component class's finalization method: "
d94d92ac 392 "%!+C", comp_cls);
d24d5663 393 return BT_FUNC_STATUS_OK;
2d41b99e
JG
394}
395
d24d5663 396enum bt_component_class_set_method_status
7474e7d3 397bt_component_class_sink_set_finalize_method(
0d72b8c3
PP
398 struct bt_component_class_sink *comp_cls,
399 bt_component_class_sink_finalize_method method)
d3e4dcd8 400{
17f3083a 401 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
402 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
403 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 404 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 405 comp_cls->methods.finalize = method;
3f7d4d90 406 BT_LIB_LOGD("Set sink component class's finalization method: "
d94d92ac 407 "%!+C", comp_cls);
d24d5663 408 return BT_FUNC_STATUS_OK;
d3e4dcd8
PP
409}
410
d24d5663 411enum bt_component_class_set_method_status
7474e7d3 412bt_component_class_source_set_query_method(
0d72b8c3
PP
413 struct bt_component_class_source *comp_cls,
414 bt_component_class_source_query_method method)
d3eb6e8f 415{
17f3083a 416 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
417 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
418 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 419 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 420 comp_cls->methods.query = method;
3f7d4d90 421 BT_LIB_LOGD("Set source component class's query method: "
d94d92ac 422 "%!+C", comp_cls);
d24d5663 423 return BT_FUNC_STATUS_OK;
d3eb6e8f
PP
424}
425
d24d5663 426enum bt_component_class_set_method_status
7474e7d3 427bt_component_class_filter_set_query_method(
0d72b8c3
PP
428 struct bt_component_class_filter *comp_cls,
429 bt_component_class_filter_query_method method)
d3eb6e8f 430{
17f3083a 431 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
432 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
433 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 434 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 435 comp_cls->methods.query = method;
3f7d4d90 436 BT_LIB_LOGD("Set filter component class's query method: "
d94d92ac 437 "%!+C", comp_cls);
d24d5663 438 return BT_FUNC_STATUS_OK;
d94d92ac 439}
a3aacb6f 440
d24d5663 441enum bt_component_class_set_method_status
7474e7d3 442bt_component_class_sink_set_query_method(
0d72b8c3
PP
443 struct bt_component_class_sink *comp_cls,
444 bt_component_class_sink_query_method method)
d94d92ac 445{
17f3083a 446 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
447 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
448 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 449 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 450 comp_cls->methods.query = method;
3f7d4d90 451 BT_LIB_LOGD("Set sink component class's query method: "
d94d92ac 452 "%!+C", comp_cls);
d24d5663 453 return BT_FUNC_STATUS_OK;
d94d92ac 454}
d3eb6e8f 455
d24d5663 456enum bt_component_class_set_method_status
7474e7d3 457bt_component_class_filter_set_input_port_connected_method(
0d72b8c3
PP
458 struct bt_component_class_filter *comp_cls,
459 bt_component_class_filter_input_port_connected_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.input_port_connected = method;
3f7d4d90 466 BT_LIB_LOGD("Set filter component class's \"input port connected\" method"
d94d92ac 467 ": %!+C", comp_cls);
d24d5663 468 return BT_FUNC_STATUS_OK;
d94d92ac 469}
a3aacb6f 470
d24d5663 471enum bt_component_class_set_method_status
7474e7d3 472bt_component_class_sink_set_input_port_connected_method(
0d72b8c3
PP
473 struct bt_component_class_sink *comp_cls,
474 bt_component_class_sink_input_port_connected_method method)
d94d92ac 475{
17f3083a 476 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
477 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
478 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 479 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 480 comp_cls->methods.input_port_connected = method;
3f7d4d90 481 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
d94d92ac 482 ": %!+C", comp_cls);
d24d5663 483 return BT_FUNC_STATUS_OK;
d94d92ac 484}
a3aacb6f 485
d24d5663 486enum bt_component_class_set_method_status
7474e7d3 487bt_component_class_source_set_output_port_connected_method(
0d72b8c3
PP
488 struct bt_component_class_source *comp_cls,
489 bt_component_class_source_output_port_connected_method method)
d94d92ac 490{
17f3083a 491 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
492 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
493 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 494 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 495 comp_cls->methods.output_port_connected = method;
3f7d4d90 496 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
d94d92ac 497 ": %!+C", comp_cls);
d24d5663 498 return BT_FUNC_STATUS_OK;
d94d92ac 499}
d3eb6e8f 500
d24d5663 501enum bt_component_class_set_method_status
7474e7d3 502bt_component_class_filter_set_output_port_connected_method(
0d72b8c3
PP
503 struct bt_component_class_filter *comp_cls,
504 bt_component_class_filter_output_port_connected_method method)
d94d92ac 505{
17f3083a 506 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
507 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
508 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 509 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 510 comp_cls->methods.output_port_connected = method;
3f7d4d90 511 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
d94d92ac 512 ": %!+C", comp_cls);
d24d5663 513 return BT_FUNC_STATUS_OK;
d94d92ac 514}
d3eb6e8f 515
d24d5663 516enum bt_component_class_set_method_status
5badd463
PP
517bt_component_class_sink_set_graph_is_configured_method(
518 struct bt_component_class_sink *comp_cls,
519 bt_component_class_sink_graph_is_configured_method method)
520{
17f3083a 521 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
522 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
523 BT_ASSERT_PRE_METHOD_NON_NULL(method);
bdb288b3 524 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
5badd463 525 comp_cls->methods.graph_is_configured = method;
3f7d4d90 526 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
5badd463 527 ": %!+C", comp_cls);
d24d5663 528 return BT_FUNC_STATUS_OK;
5badd463
PP
529}
530
d24d5663
PP
531enum bt_component_class_set_description_status
532bt_component_class_set_description(
0d72b8c3 533 struct bt_component_class *comp_cls,
d3e4dcd8
PP
534 const char *description)
535{
17f3083a 536 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b
PP
537 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
538 BT_ASSERT_PRE_DESCR_NON_NULL(description);
bdb288b3 539 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 540 g_string_assign(comp_cls->description, description);
3f7d4d90 541 BT_LIB_LOGD("Set component class's description: "
a3aacb6f 542 "addr=%p, name=\"%s\", type=%s",
d94d92ac
PP
543 comp_cls,
544 bt_component_class_get_name(comp_cls),
6375b942 545 bt_common_component_class_type_string(comp_cls->type));
d24d5663 546 return BT_FUNC_STATUS_OK;
fb2dcc52 547}
38b48196 548
d24d5663 549enum bt_component_class_set_help_status bt_component_class_set_help(
0d72b8c3 550 struct bt_component_class *comp_cls,
5536d9a6
PP
551 const char *help)
552{
17f3083a 553 BT_ASSERT_PRE_NO_ERROR();
d5b13b9b 554 BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls);
1778c2a4 555 BT_ASSERT_PRE_NON_NULL("help-text", help, "Help text");
bdb288b3 556 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 557 g_string_assign(comp_cls->help, help);
3f7d4d90 558 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls);
d24d5663 559 return BT_FUNC_STATUS_OK;
5536d9a6
PP
560}
561
0d72b8c3 562const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
38b48196 563{
d5b13b9b 564 BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls);
d94d92ac 565 return comp_cls->name->str;
38b48196
JG
566}
567
d3e4dcd8 568enum bt_component_class_type bt_component_class_get_type(
0d72b8c3 569 const struct bt_component_class *comp_cls)
38b48196 570{
d5b13b9b 571 BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls);
d94d92ac 572 return comp_cls->type;
38b48196
JG
573}
574
33b34c43 575const char *bt_component_class_get_description(
0d72b8c3 576 const struct bt_component_class *comp_cls)
38b48196 577{
d5b13b9b 578 BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls);
d94d92ac
PP
579 return comp_cls->description &&
580 comp_cls->description->str[0] != '\0' ?
581 comp_cls->description->str : NULL;
38b48196 582}
7c7c0433 583
5536d9a6 584const char *bt_component_class_get_help(
0d72b8c3 585 const struct bt_component_class *comp_cls)
5536d9a6 586{
d5b13b9b 587 BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls);
d94d92ac
PP
588 return comp_cls->help &&
589 comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL;
5536d9a6
PP
590}
591
33b34c43 592BT_HIDDEN
d94d92ac
PP
593void bt_component_class_add_destroy_listener(
594 struct bt_component_class *comp_cls,
33b34c43 595 bt_component_class_destroy_listener_func func, void *data)
7c7c0433 596{
d3e4dcd8 597 struct bt_component_class_destroy_listener listener;
33b34c43 598
d94d92ac 599 BT_ASSERT(comp_cls);
f6ccaed9 600 BT_ASSERT(func);
33b34c43
PP
601 listener.func = func;
602 listener.data = data;
d94d92ac 603 g_array_append_val(comp_cls->destroy_listeners, listener);
3f7d4d90 604 BT_LIB_LOGD("Added destroy listener to component class: "
d94d92ac 605 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
7c7c0433 606}
d3e4dcd8 607
d94d92ac 608BT_HIDDEN
0d72b8c3 609void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
1e4d8103 610{
d94d92ac
PP
611 BT_ASSERT(comp_cls);
612 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
0d72b8c3 613 ((struct bt_component_class *) comp_cls)->frozen = true;
1e4d8103 614}
c5b9b441
PP
615
616void bt_component_class_get_ref(
617 const struct bt_component_class *component_class)
618{
619 bt_object_get_ref(component_class);
620}
621
622void bt_component_class_put_ref(
623 const struct bt_component_class *component_class)
624{
625 bt_object_put_ref(component_class);
626}
627
628void bt_component_class_source_get_ref(
629 const struct bt_component_class_source *component_class_source)
630{
631 bt_object_get_ref(component_class_source);
632}
633
634void bt_component_class_source_put_ref(
635 const struct bt_component_class_source *component_class_source)
636{
637 bt_object_put_ref(component_class_source);
638}
639
640void bt_component_class_filter_get_ref(
641 const struct bt_component_class_filter *component_class_filter)
642{
643 bt_object_get_ref(component_class_filter);
644}
645
646void bt_component_class_filter_put_ref(
647 const struct bt_component_class_filter *component_class_filter)
648{
649 bt_object_put_ref(component_class_filter);
650}
651
652void bt_component_class_sink_get_ref(
653 const struct bt_component_class_sink *component_class_sink)
654{
655 bt_object_get_ref(component_class_sink);
656}
657
658void bt_component_class_sink_put_ref(
659 const struct bt_component_class_sink *component_class_sink)
660{
661 bt_object_put_ref(component_class_sink);
662}
This page took 0.12463 seconds and 4 git commands to generate.