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