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