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