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