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