Document libbabeltrace2's C API
[babeltrace.git] / src / lib / graph / component-class.c
CommitLineData
fb2dcc52 1/*
e2f7325d 2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3310b217 3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
fb2dcc52 4 *
fb2dcc52
JG
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 */
23
350ad6c1 24#define BT_LOG_TAG "LIB/COMPONENT-CLASS"
c2d9d9cf 25#include "lib/logging.h"
a3aacb6f 26
578e048b
MJ
27#include "common/assert.h"
28#include "lib/assert-pre.h"
29#include "compat/compiler.h"
3fadfbc0 30#include <babeltrace2/graph/component-class.h>
3fadfbc0 31#include <babeltrace2/types.h>
fb2dcc52
JG
32#include <glib.h>
33
578e048b 34#include "component-class.h"
d24d5663 35#include "lib/func-status.h"
a3f0c7db 36#include "lib/graph/message-iterator-class.h"
578e048b 37
bdb288b3
PP
38#define BT_ASSERT_PRE_DEV_COMP_CLS_HOT(_cc) \
39 BT_ASSERT_PRE_DEV_HOT(((const struct bt_component_class *) (_cc)), \
d94d92ac
PP
40 "Component class", ": %!+C", (_cc))
41
fb2dcc52 42static
d94d92ac 43void destroy_component_class(struct bt_object *obj)
fb2dcc52
JG
44{
45 struct bt_component_class *class;
33b34c43 46 int i;
fb2dcc52 47
f6ccaed9 48 BT_ASSERT(obj);
b8a06801 49 class = container_of(obj, struct bt_component_class, base);
33b34c43 50
3f7d4d90 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);
d94d92ac 67 class->name = NULL;
fb2dcc52 68 }
d94d92ac 69
7c7c0433
JG
70 if (class->description) {
71 g_string_free(class->description, TRUE);
d94d92ac 72 class->description = NULL;
7c7c0433 73 }
d94d92ac 74
5536d9a6
PP
75 if (class->help) {
76 g_string_free(class->help, TRUE);
d94d92ac 77 class->help = NULL;
5536d9a6 78 }
d94d92ac 79
2ce06c9e
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);
d94d92ac 87 class->destroy_listeners = NULL;
33b34c43 88 }
b8a06801 89
41a3efcd
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;
a3f0c7db
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
d94d92ac 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) {
870631a2 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) {
870631a2 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) {
870631a2 124 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
5536d9a6
PP
125 goto error;
126 }
127
2ce06c9e
PP
128 class->plugin_name = g_string_new(NULL);
129 if (!class->plugin_name) {
870631a2 130 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
2ce06c9e
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) {
870631a2 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:
65300d60 144 BT_OBJECT_PUT_REF_AND_RESET(class);
d3e4dcd8
PP
145 ret = -1;
146
147end:
148 return ret;
149}
150
41a3efcd
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
0d72b8c3 172struct bt_component_class_source *bt_component_class_source_create(
d94d92ac 173 const char *name,
a3f0c7db 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
17f3083a 179 BT_ASSERT_PRE_NO_ERROR();
d94d92ac 180 BT_ASSERT_PRE_NON_NULL(name, "Name");
a3f0c7db
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) {
870631a2
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 */
41a3efcd
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
3f7d4d90 205 BT_LIB_LOGI("Created source component class: %!+C", source_class);
d3e4dcd8
PP
206
207end:
d94d92ac 208 return (void *) source_class;
d3e4dcd8
PP
209}
210
0d72b8c3
PP
211struct bt_component_class_filter *bt_component_class_filter_create(
212 const char *name,
a3f0c7db 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
17f3083a 218 BT_ASSERT_PRE_NO_ERROR();
d94d92ac 219 BT_ASSERT_PRE_NON_NULL(name, "Name");
a3f0c7db
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) {
870631a2
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 */
41a3efcd
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
3f7d4d90 244 BT_LIB_LOGI("Created filter component class: %!+C", filter_class);
d3e4dcd8 245
fb2dcc52 246end:
d94d92ac 247 return (void *) filter_class;
d3e4dcd8
PP
248}
249
0d72b8c3
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
17f3083a 256 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
257 BT_ASSERT_PRE_NON_NULL(name, "Name");
258 BT_ASSERT_PRE_NON_NULL(method, "Consume next method");
3f7d4d90 259 BT_LOGI("Creating sink component class: "
a3aacb6f 260 "name=\"%s\", consume-method-addr=%p",
90157d89 261 name, method);
d3e4dcd8
PP
262 sink_class = g_new0(struct bt_component_class_sink, 1);
263 if (!sink_class) {
870631a2
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
90157d89 282 sink_class->methods.consume = method;
3f7d4d90 283 BT_LIB_LOGI("Created sink component class: %!+C", sink_class);
d3e4dcd8
PP
284
285end:
d94d92ac 286 return (void *) sink_class;
d3e4dcd8
PP
287}
288
2b55df78
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{
17f3083a 294 BT_ASSERT_PRE_NO_ERROR();
2b55df78
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{
17f3083a 309 BT_ASSERT_PRE_NO_ERROR();
2b55df78
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{
17f3083a 324 BT_ASSERT_PRE_NO_ERROR();
2b55df78
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
d24d5663 334enum bt_component_class_set_method_status
21a9f056 335bt_component_class_source_set_initialize_method(
0d72b8c3 336 struct bt_component_class_source *comp_cls,
21a9f056 337 bt_component_class_source_initialize_method method)
d3e4dcd8 338{
17f3083a 339 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
340 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
341 BT_ASSERT_PRE_NON_NULL(method, "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 source component class's initialization method: "
d94d92ac 345 "%!+C", comp_cls);
d24d5663 346 return BT_FUNC_STATUS_OK;
d3e4dcd8
PP
347}
348
d24d5663 349enum bt_component_class_set_method_status
21a9f056 350bt_component_class_filter_set_initialize_method(
0d72b8c3 351 struct bt_component_class_filter *comp_cls,
21a9f056 352 bt_component_class_filter_initialize_method method)
efa96d5d 353{
17f3083a 354 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
355 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
356 BT_ASSERT_PRE_NON_NULL(method, "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 filter component class's initialization method: "
d94d92ac 360 "%!+C", comp_cls);
d24d5663 361 return BT_FUNC_STATUS_OK;
efa96d5d
PP
362}
363
d24d5663 364enum bt_component_class_set_method_status
21a9f056 365bt_component_class_sink_set_initialize_method(
0d72b8c3 366 struct bt_component_class_sink *comp_cls,
21a9f056 367 bt_component_class_sink_initialize_method method)
2d41b99e 368{
17f3083a 369 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
370 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
371 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 372 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 373 comp_cls->methods.init = method;
3f7d4d90 374 BT_LIB_LOGD("Set sink component class's initialization method: "
d94d92ac 375 "%!+C", comp_cls);
d24d5663 376 return BT_FUNC_STATUS_OK;
72b913fb
PP
377}
378
d24d5663 379enum bt_component_class_set_method_status
7474e7d3 380bt_component_class_source_set_finalize_method(
0d72b8c3
PP
381 struct bt_component_class_source *comp_cls,
382 bt_component_class_source_finalize_method method)
0d8b4d8e 383{
17f3083a 384 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
385 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
386 BT_ASSERT_PRE_NON_NULL(method, "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 source component class's finalization method: "
d94d92ac 390 "%!+C", comp_cls);
d24d5663 391 return BT_FUNC_STATUS_OK;
0d8b4d8e
PP
392}
393
d24d5663 394enum bt_component_class_set_method_status
7474e7d3 395bt_component_class_filter_set_finalize_method(
0d72b8c3
PP
396 struct bt_component_class_filter *comp_cls,
397 bt_component_class_filter_finalize_method method)
72b913fb 398{
17f3083a 399 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
400 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
401 BT_ASSERT_PRE_NON_NULL(method, "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 filter component class's finalization method: "
d94d92ac 405 "%!+C", comp_cls);
d24d5663 406 return BT_FUNC_STATUS_OK;
2d41b99e
JG
407}
408
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();
d94d92ac
PP
415 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
416 BT_ASSERT_PRE_NON_NULL(method, "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
d24d5663 424enum bt_component_class_set_method_status
7474e7d3 425bt_component_class_source_set_query_method(
0d72b8c3
PP
426 struct bt_component_class_source *comp_cls,
427 bt_component_class_source_query_method method)
d3eb6e8f 428{
17f3083a 429 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
430 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
431 BT_ASSERT_PRE_NON_NULL(method, "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 source component class's query method: "
d94d92ac 435 "%!+C", comp_cls);
d24d5663 436 return BT_FUNC_STATUS_OK;
d3eb6e8f
PP
437}
438
d24d5663 439enum bt_component_class_set_method_status
7474e7d3 440bt_component_class_filter_set_query_method(
0d72b8c3
PP
441 struct bt_component_class_filter *comp_cls,
442 bt_component_class_filter_query_method method)
d3eb6e8f 443{
17f3083a 444 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
445 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
446 BT_ASSERT_PRE_NON_NULL(method, "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 filter component class's query method: "
d94d92ac 450 "%!+C", comp_cls);
d24d5663 451 return BT_FUNC_STATUS_OK;
d94d92ac 452}
a3aacb6f 453
d24d5663 454enum bt_component_class_set_method_status
7474e7d3 455bt_component_class_sink_set_query_method(
0d72b8c3
PP
456 struct bt_component_class_sink *comp_cls,
457 bt_component_class_sink_query_method method)
d94d92ac 458{
17f3083a 459 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
460 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
461 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 462 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 463 comp_cls->methods.query = method;
3f7d4d90 464 BT_LIB_LOGD("Set sink component class's query method: "
d94d92ac 465 "%!+C", comp_cls);
d24d5663 466 return BT_FUNC_STATUS_OK;
d94d92ac 467}
d3eb6e8f 468
d24d5663 469enum bt_component_class_set_method_status
7474e7d3 470bt_component_class_filter_set_input_port_connected_method(
0d72b8c3
PP
471 struct bt_component_class_filter *comp_cls,
472 bt_component_class_filter_input_port_connected_method method)
d94d92ac 473{
17f3083a 474 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
475 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
476 BT_ASSERT_PRE_NON_NULL(method, "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 filter 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_sink_set_input_port_connected_method(
0d72b8c3
PP
486 struct bt_component_class_sink *comp_cls,
487 bt_component_class_sink_input_port_connected_method method)
d94d92ac 488{
17f3083a 489 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
490 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
491 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 492 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 493 comp_cls->methods.input_port_connected = method;
3f7d4d90 494 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
d94d92ac 495 ": %!+C", comp_cls);
d24d5663 496 return BT_FUNC_STATUS_OK;
d94d92ac 497}
a3aacb6f 498
d24d5663 499enum bt_component_class_set_method_status
7474e7d3 500bt_component_class_source_set_output_port_connected_method(
0d72b8c3
PP
501 struct bt_component_class_source *comp_cls,
502 bt_component_class_source_output_port_connected_method method)
d94d92ac 503{
17f3083a 504 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
505 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
506 BT_ASSERT_PRE_NON_NULL(method, "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 source 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
7474e7d3 515bt_component_class_filter_set_output_port_connected_method(
0d72b8c3
PP
516 struct bt_component_class_filter *comp_cls,
517 bt_component_class_filter_output_port_connected_method method)
d94d92ac 518{
17f3083a 519 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
520 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
521 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 522 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 523 comp_cls->methods.output_port_connected = method;
3f7d4d90 524 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
d94d92ac 525 ": %!+C", comp_cls);
d24d5663 526 return BT_FUNC_STATUS_OK;
d94d92ac 527}
d3eb6e8f 528
d24d5663 529enum bt_component_class_set_method_status
5badd463
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{
17f3083a 534 BT_ASSERT_PRE_NO_ERROR();
5badd463
PP
535 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
536 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 537 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
5badd463 538 comp_cls->methods.graph_is_configured = method;
3f7d4d90 539 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
5badd463 540 ": %!+C", comp_cls);
d24d5663 541 return BT_FUNC_STATUS_OK;
5badd463
PP
542}
543
d24d5663
PP
544enum bt_component_class_set_description_status
545bt_component_class_set_description(
0d72b8c3 546 struct bt_component_class *comp_cls,
d3e4dcd8
PP
547 const char *description)
548{
17f3083a 549 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
550 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
551 BT_ASSERT_PRE_NON_NULL(description, "Description");
bdb288b3 552 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 553 g_string_assign(comp_cls->description, description);
3f7d4d90 554 BT_LIB_LOGD("Set component class's description: "
a3aacb6f 555 "addr=%p, name=\"%s\", type=%s",
d94d92ac
PP
556 comp_cls,
557 bt_component_class_get_name(comp_cls),
558 bt_component_class_type_string(comp_cls->type));
d24d5663 559 return BT_FUNC_STATUS_OK;
fb2dcc52 560}
38b48196 561
d24d5663 562enum bt_component_class_set_help_status bt_component_class_set_help(
0d72b8c3 563 struct bt_component_class *comp_cls,
5536d9a6
PP
564 const char *help)
565{
17f3083a 566 BT_ASSERT_PRE_NO_ERROR();
d94d92ac
PP
567 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
568 BT_ASSERT_PRE_NON_NULL(help, "Help");
bdb288b3 569 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 570 g_string_assign(comp_cls->help, help);
3f7d4d90 571 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls);
d24d5663 572 return BT_FUNC_STATUS_OK;
5536d9a6
PP
573}
574
0d72b8c3 575const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
38b48196 576{
bdb288b3 577 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
d94d92ac 578 return comp_cls->name->str;
38b48196
JG
579}
580
d3e4dcd8 581enum bt_component_class_type bt_component_class_get_type(
0d72b8c3 582 const struct bt_component_class *comp_cls)
38b48196 583{
bdb288b3 584 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
d94d92ac 585 return comp_cls->type;
38b48196
JG
586}
587
33b34c43 588const char *bt_component_class_get_description(
0d72b8c3 589 const struct bt_component_class *comp_cls)
38b48196 590{
bdb288b3 591 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
d94d92ac
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(
0d72b8c3 598 const struct bt_component_class *comp_cls)
5536d9a6 599{
bdb288b3 600 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
d94d92ac
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
d94d92ac
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
d94d92ac 612 BT_ASSERT(comp_cls);
f6ccaed9 613 BT_ASSERT(func);
33b34c43
PP
614 listener.func = func;
615 listener.data = data;
d94d92ac 616 g_array_append_val(comp_cls->destroy_listeners, listener);
3f7d4d90 617 BT_LIB_LOGD("Added destroy listener to component class: "
d94d92ac 618 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
7c7c0433 619}
d3e4dcd8 620
d94d92ac 621BT_HIDDEN
0d72b8c3 622void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
1e4d8103 623{
d94d92ac
PP
624 BT_ASSERT(comp_cls);
625 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
0d72b8c3 626 ((struct bt_component_class *) comp_cls)->frozen = true;
1e4d8103 627}
c5b9b441
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.103829 seconds and 4 git commands to generate.