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