lib: split real FC/field into single and double prec FC/field
[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
d94d92ac 155 BT_ASSERT_PRE_NON_NULL(name, "Name");
d6e69534 156 BT_ASSERT_PRE_NON_NULL(method, "Message iterator next method");
3f7d4d90 157 BT_LOGI("Creating source component class: "
d6e69534 158 "name=\"%s\", msg-iter-next-method-addr=%p",
90157d89 159 name, method);
d3e4dcd8
PP
160 source_class = g_new0(struct bt_component_class_source, 1);
161 if (!source_class) {
870631a2
PP
162 BT_LIB_LOGE_APPEND_CAUSE(
163 "Failed to allocate one source component class.");
fb2dcc52
JG
164 goto end;
165 }
166
a3aacb6f 167 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
168 ret = bt_component_class_init(&source_class->parent,
169 BT_COMPONENT_CLASS_TYPE_SOURCE, name);
170 if (ret) {
171 /*
172 * If bt_component_class_init() fails, the component
173 * class is put, therefore its memory is already
174 * freed.
175 */
176 source_class = NULL;
177 goto end;
178 }
179
d6e69534 180 source_class->methods.msg_iter_next = method;
3f7d4d90 181 BT_LIB_LOGI("Created source component class: %!+C", source_class);
d3e4dcd8
PP
182
183end:
d94d92ac 184 return (void *) source_class;
d3e4dcd8
PP
185}
186
0d72b8c3
PP
187struct bt_component_class_filter *bt_component_class_filter_create(
188 const char *name,
d6e69534 189 bt_component_class_filter_message_iterator_next_method method)
d3e4dcd8
PP
190{
191 struct bt_component_class_filter *filter_class = NULL;
192 int ret;
193
d94d92ac 194 BT_ASSERT_PRE_NON_NULL(name, "Name");
d6e69534 195 BT_ASSERT_PRE_NON_NULL(method, "Message iterator next method");
3f7d4d90 196 BT_LOGI("Creating filter component class: "
d6e69534 197 "name=\"%s\", msg-iter-next-method-addr=%p",
90157d89 198 name, method);
d3e4dcd8
PP
199 filter_class = g_new0(struct bt_component_class_filter, 1);
200 if (!filter_class) {
870631a2
PP
201 BT_LIB_LOGE_APPEND_CAUSE(
202 "Failed to allocate one filter component class.");
d3e4dcd8 203 goto end;
6ba0b073
PP
204 }
205
a3aacb6f 206 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
207 ret = bt_component_class_init(&filter_class->parent,
208 BT_COMPONENT_CLASS_TYPE_FILTER, name);
209 if (ret) {
210 /*
211 * If bt_component_class_init() fails, the component
212 * class is put, therefore its memory is already
213 * freed.
214 */
215 filter_class = NULL;
33b34c43
PP
216 goto end;
217 }
d3e4dcd8 218
d6e69534 219 filter_class->methods.msg_iter_next = method;
3f7d4d90 220 BT_LIB_LOGI("Created filter component class: %!+C", filter_class);
d3e4dcd8 221
fb2dcc52 222end:
d94d92ac 223 return (void *) filter_class;
d3e4dcd8
PP
224}
225
0d72b8c3
PP
226struct bt_component_class_sink *bt_component_class_sink_create(
227 const char *name, bt_component_class_sink_consume_method method)
d3e4dcd8
PP
228{
229 struct bt_component_class_sink *sink_class = NULL;
230 int ret;
231
d94d92ac
PP
232 BT_ASSERT_PRE_NON_NULL(name, "Name");
233 BT_ASSERT_PRE_NON_NULL(method, "Consume next method");
3f7d4d90 234 BT_LOGI("Creating sink component class: "
a3aacb6f 235 "name=\"%s\", consume-method-addr=%p",
90157d89 236 name, method);
d3e4dcd8
PP
237 sink_class = g_new0(struct bt_component_class_sink, 1);
238 if (!sink_class) {
870631a2
PP
239 BT_LIB_LOGE_APPEND_CAUSE(
240 "Failed to allocate one sink component class.");
d3e4dcd8
PP
241 goto end;
242 }
243
a3aacb6f 244 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
245 ret = bt_component_class_init(&sink_class->parent,
246 BT_COMPONENT_CLASS_TYPE_SINK, name);
247 if (ret) {
248 /*
249 * If bt_component_class_init() fails, the component
250 * class is put, therefore its memory is already
251 * freed.
252 */
253 sink_class = NULL;
254 goto end;
255 }
256
90157d89 257 sink_class->methods.consume = method;
3f7d4d90 258 BT_LIB_LOGI("Created sink component class: %!+C", sink_class);
d3e4dcd8
PP
259
260end:
d94d92ac 261 return (void *) sink_class;
d3e4dcd8
PP
262}
263
2b55df78
PP
264enum bt_component_class_set_method_status
265bt_component_class_source_set_get_supported_mip_versions_method(
266 struct bt_component_class_source *comp_cls,
267 bt_component_class_source_get_supported_mip_versions_method method)
268{
269 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
270 BT_ASSERT_PRE_NON_NULL(method, "Method");
271 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
272 comp_cls->methods.get_supported_mip_versions = method;
273 BT_LIB_LOGD("Set source component class's \"get supported MIP versions\" method: "
274 "%!+C", comp_cls);
275 return BT_FUNC_STATUS_OK;
276}
277
278enum bt_component_class_set_method_status
279bt_component_class_filter_set_get_supported_mip_versions_method(
280 struct bt_component_class_filter *comp_cls,
281 bt_component_class_filter_get_supported_mip_versions_method method)
282{
283 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
284 BT_ASSERT_PRE_NON_NULL(method, "Method");
285 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
286 comp_cls->methods.get_supported_mip_versions = method;
287 BT_LIB_LOGD("Set filter component class's \"get supported MIP versions\" method: "
288 "%!+C", comp_cls);
289 return BT_FUNC_STATUS_OK;
290}
291
292enum bt_component_class_set_method_status
293bt_component_class_sink_set_get_supported_mip_versions_method(
294 struct bt_component_class_sink *comp_cls,
295 bt_component_class_sink_get_supported_mip_versions_method method)
296{
297 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
298 BT_ASSERT_PRE_NON_NULL(method, "Method");
299 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
300 comp_cls->methods.get_supported_mip_versions = method;
301 BT_LIB_LOGD("Set sink component class's \"get supported MIP versions\" method: "
302 "%!+C", comp_cls);
303 return BT_FUNC_STATUS_OK;
304}
305
d24d5663 306enum bt_component_class_set_method_status
7474e7d3 307bt_component_class_source_set_init_method(
0d72b8c3
PP
308 struct bt_component_class_source *comp_cls,
309 bt_component_class_source_init_method method)
d3e4dcd8 310{
d94d92ac
PP
311 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
312 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 313 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 314 comp_cls->methods.init = method;
3f7d4d90 315 BT_LIB_LOGD("Set source component class's initialization method: "
d94d92ac 316 "%!+C", comp_cls);
d24d5663 317 return BT_FUNC_STATUS_OK;
d3e4dcd8
PP
318}
319
d24d5663 320enum bt_component_class_set_method_status
7474e7d3 321bt_component_class_filter_set_init_method(
0d72b8c3
PP
322 struct bt_component_class_filter *comp_cls,
323 bt_component_class_filter_init_method method)
efa96d5d 324{
d94d92ac
PP
325 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
326 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 327 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 328 comp_cls->methods.init = method;
3f7d4d90 329 BT_LIB_LOGD("Set filter component class's initialization method: "
d94d92ac 330 "%!+C", comp_cls);
d24d5663 331 return BT_FUNC_STATUS_OK;
efa96d5d
PP
332}
333
d24d5663 334enum bt_component_class_set_method_status
7474e7d3 335bt_component_class_sink_set_init_method(
0d72b8c3
PP
336 struct bt_component_class_sink *comp_cls,
337 bt_component_class_sink_init_method method)
2d41b99e 338{
d94d92ac
PP
339 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
340 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 341 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 342 comp_cls->methods.init = method;
3f7d4d90 343 BT_LIB_LOGD("Set sink component class's initialization method: "
d94d92ac 344 "%!+C", comp_cls);
d24d5663 345 return BT_FUNC_STATUS_OK;
72b913fb
PP
346}
347
d24d5663 348enum bt_component_class_set_method_status
7474e7d3 349bt_component_class_source_set_finalize_method(
0d72b8c3
PP
350 struct bt_component_class_source *comp_cls,
351 bt_component_class_source_finalize_method method)
0d8b4d8e 352{
d94d92ac
PP
353 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
354 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 355 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 356 comp_cls->methods.finalize = method;
3f7d4d90 357 BT_LIB_LOGD("Set source component class's finalization method: "
d94d92ac 358 "%!+C", comp_cls);
d24d5663 359 return BT_FUNC_STATUS_OK;
0d8b4d8e
PP
360}
361
d24d5663 362enum bt_component_class_set_method_status
7474e7d3 363bt_component_class_filter_set_finalize_method(
0d72b8c3
PP
364 struct bt_component_class_filter *comp_cls,
365 bt_component_class_filter_finalize_method method)
72b913fb 366{
d94d92ac
PP
367 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
368 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 369 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 370 comp_cls->methods.finalize = method;
3f7d4d90 371 BT_LIB_LOGD("Set filter component class's finalization method: "
d94d92ac 372 "%!+C", comp_cls);
d24d5663 373 return BT_FUNC_STATUS_OK;
2d41b99e
JG
374}
375
d24d5663 376enum bt_component_class_set_method_status
7474e7d3 377bt_component_class_sink_set_finalize_method(
0d72b8c3
PP
378 struct bt_component_class_sink *comp_cls,
379 bt_component_class_sink_finalize_method method)
d3e4dcd8 380{
d94d92ac
PP
381 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
382 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 383 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 384 comp_cls->methods.finalize = method;
3f7d4d90 385 BT_LIB_LOGD("Set sink component class's finalization method: "
d94d92ac 386 "%!+C", comp_cls);
d24d5663 387 return BT_FUNC_STATUS_OK;
d3e4dcd8
PP
388}
389
d24d5663 390enum bt_component_class_set_method_status
7474e7d3 391bt_component_class_source_set_query_method(
0d72b8c3
PP
392 struct bt_component_class_source *comp_cls,
393 bt_component_class_source_query_method method)
d3eb6e8f 394{
d94d92ac
PP
395 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
396 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 397 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 398 comp_cls->methods.query = method;
3f7d4d90 399 BT_LIB_LOGD("Set source component class's query method: "
d94d92ac 400 "%!+C", comp_cls);
d24d5663 401 return BT_FUNC_STATUS_OK;
d3eb6e8f
PP
402}
403
d24d5663 404enum bt_component_class_set_method_status
7474e7d3 405bt_component_class_filter_set_query_method(
0d72b8c3
PP
406 struct bt_component_class_filter *comp_cls,
407 bt_component_class_filter_query_method method)
d3eb6e8f 408{
d94d92ac
PP
409 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
410 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 411 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 412 comp_cls->methods.query = method;
3f7d4d90 413 BT_LIB_LOGD("Set filter component class's query method: "
d94d92ac 414 "%!+C", comp_cls);
d24d5663 415 return BT_FUNC_STATUS_OK;
d94d92ac 416}
a3aacb6f 417
d24d5663 418enum bt_component_class_set_method_status
7474e7d3 419bt_component_class_sink_set_query_method(
0d72b8c3
PP
420 struct bt_component_class_sink *comp_cls,
421 bt_component_class_sink_query_method method)
d94d92ac 422{
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 sink component class's query method: "
d94d92ac 428 "%!+C", comp_cls);
d24d5663 429 return BT_FUNC_STATUS_OK;
d94d92ac 430}
d3eb6e8f 431
d24d5663 432enum bt_component_class_set_method_status
7474e7d3 433bt_component_class_filter_set_input_port_connected_method(
0d72b8c3
PP
434 struct bt_component_class_filter *comp_cls,
435 bt_component_class_filter_input_port_connected_method method)
d94d92ac 436{
d94d92ac
PP
437 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
438 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 439 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 440 comp_cls->methods.input_port_connected = method;
3f7d4d90 441 BT_LIB_LOGD("Set filter component class's \"input port connected\" method"
d94d92ac 442 ": %!+C", comp_cls);
d24d5663 443 return BT_FUNC_STATUS_OK;
d94d92ac 444}
a3aacb6f 445
d24d5663 446enum bt_component_class_set_method_status
7474e7d3 447bt_component_class_sink_set_input_port_connected_method(
0d72b8c3
PP
448 struct bt_component_class_sink *comp_cls,
449 bt_component_class_sink_input_port_connected_method method)
d94d92ac 450{
d94d92ac
PP
451 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
452 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 453 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 454 comp_cls->methods.input_port_connected = method;
3f7d4d90 455 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
d94d92ac 456 ": %!+C", comp_cls);
d24d5663 457 return BT_FUNC_STATUS_OK;
d94d92ac 458}
a3aacb6f 459
d24d5663 460enum bt_component_class_set_method_status
7474e7d3 461bt_component_class_source_set_output_port_connected_method(
0d72b8c3
PP
462 struct bt_component_class_source *comp_cls,
463 bt_component_class_source_output_port_connected_method method)
d94d92ac 464{
d94d92ac
PP
465 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
466 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 467 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 468 comp_cls->methods.output_port_connected = method;
3f7d4d90 469 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
d94d92ac 470 ": %!+C", comp_cls);
d24d5663 471 return BT_FUNC_STATUS_OK;
d94d92ac 472}
d3eb6e8f 473
d24d5663 474enum bt_component_class_set_method_status
7474e7d3 475bt_component_class_filter_set_output_port_connected_method(
0d72b8c3
PP
476 struct bt_component_class_filter *comp_cls,
477 bt_component_class_filter_output_port_connected_method method)
d94d92ac 478{
d94d92ac
PP
479 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
480 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 481 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 482 comp_cls->methods.output_port_connected = method;
3f7d4d90 483 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
d94d92ac 484 ": %!+C", comp_cls);
d24d5663 485 return BT_FUNC_STATUS_OK;
d94d92ac 486}
d3eb6e8f 487
d24d5663 488enum bt_component_class_set_method_status
5badd463
PP
489bt_component_class_sink_set_graph_is_configured_method(
490 struct bt_component_class_sink *comp_cls,
491 bt_component_class_sink_graph_is_configured_method method)
492{
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);
5badd463 496 comp_cls->methods.graph_is_configured = method;
3f7d4d90 497 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
5badd463 498 ": %!+C", comp_cls);
d24d5663 499 return BT_FUNC_STATUS_OK;
5badd463
PP
500}
501
d24d5663
PP
502enum bt_component_class_set_method_status
503bt_component_class_source_set_message_iterator_init_method(
0d72b8c3 504 struct bt_component_class_source *comp_cls,
d6e69534 505 bt_component_class_source_message_iterator_init_method method)
d94d92ac 506{
d94d92ac
PP
507 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
508 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 509 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d6e69534 510 comp_cls->methods.msg_iter_init = method;
3f7d4d90 511 BT_LIB_LOGD("Set source component class's message iterator initialization method"
d94d92ac 512 ": %!+C", comp_cls);
d24d5663 513 return BT_FUNC_STATUS_OK;
d94d92ac 514}
a3aacb6f 515
d24d5663 516enum bt_component_class_set_method_status
7474e7d3 517bt_component_class_filter_set_message_iterator_init_method(
0d72b8c3 518 struct bt_component_class_filter *comp_cls,
d6e69534 519 bt_component_class_filter_message_iterator_init_method method)
d94d92ac 520{
d94d92ac
PP
521 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
522 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 523 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d6e69534 524 comp_cls->methods.msg_iter_init = method;
3f7d4d90 525 BT_LIB_LOGD("Set filter component class's message iterator initialization method"
d94d92ac 526 ": %!+C", comp_cls);
d24d5663 527 return BT_FUNC_STATUS_OK;
d94d92ac 528}
d3eb6e8f 529
d24d5663 530enum bt_component_class_set_method_status
7474e7d3 531bt_component_class_source_set_message_iterator_finalize_method(
0d72b8c3 532 struct bt_component_class_source *comp_cls,
d6e69534 533 bt_component_class_source_message_iterator_finalize_method method)
d94d92ac 534{
d94d92ac
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);
d6e69534 538 comp_cls->methods.msg_iter_finalize = method;
3f7d4d90 539 BT_LIB_LOGD("Set source component class's message iterator finalization method"
d94d92ac 540 ": %!+C", comp_cls);
d24d5663 541 return BT_FUNC_STATUS_OK;
d94d92ac 542}
d3eb6e8f 543
d24d5663 544enum bt_component_class_set_method_status
7474e7d3 545bt_component_class_filter_set_message_iterator_finalize_method(
0d72b8c3 546 struct bt_component_class_filter *comp_cls,
d6e69534 547 bt_component_class_filter_message_iterator_finalize_method method)
d94d92ac 548{
d94d92ac
PP
549 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
550 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 551 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d6e69534 552 comp_cls->methods.msg_iter_finalize = method;
3f7d4d90 553 BT_LIB_LOGD("Set filter component class's message iterator finalization method"
d94d92ac 554 ": %!+C", comp_cls);
d24d5663 555 return BT_FUNC_STATUS_OK;
d3eb6e8f
PP
556}
557
d24d5663 558enum bt_component_class_set_method_status
7474e7d3
PP
559bt_component_class_filter_set_message_iterator_seek_ns_from_origin_method(
560 struct bt_component_class_filter *comp_cls,
561 bt_component_class_filter_message_iterator_seek_ns_from_origin_method method)
562{
563 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
564 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 565 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7474e7d3 566 comp_cls->methods.msg_iter_seek_ns_from_origin = method;
3f7d4d90 567 BT_LIB_LOGD("Set filter component class's message iterator \"seek nanoseconds from origin\" method"
7474e7d3 568 ": %!+C", comp_cls);
d24d5663 569 return BT_FUNC_STATUS_OK;
7474e7d3
PP
570}
571
d24d5663 572enum bt_component_class_set_method_status
7474e7d3
PP
573bt_component_class_source_set_message_iterator_seek_ns_from_origin_method(
574 struct bt_component_class_source *comp_cls,
575 bt_component_class_source_message_iterator_seek_ns_from_origin_method method)
576{
577 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
578 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 579 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7474e7d3 580 comp_cls->methods.msg_iter_seek_ns_from_origin = method;
3f7d4d90 581 BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" method"
7474e7d3 582 ": %!+C", comp_cls);
d24d5663 583 return BT_FUNC_STATUS_OK;
7474e7d3
PP
584}
585
d24d5663 586enum bt_component_class_set_method_status
7474e7d3
PP
587bt_component_class_filter_set_message_iterator_seek_beginning_method(
588 struct bt_component_class_filter *comp_cls,
589 bt_component_class_filter_message_iterator_seek_beginning_method method)
590{
591 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
592 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 593 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7474e7d3 594 comp_cls->methods.msg_iter_seek_beginning = method;
3f7d4d90 595 BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" method"
7474e7d3 596 ": %!+C", comp_cls);
d24d5663 597 return BT_FUNC_STATUS_OK;
7474e7d3
PP
598}
599
d24d5663 600enum bt_component_class_set_method_status
7474e7d3
PP
601bt_component_class_source_set_message_iterator_seek_beginning_method(
602 struct bt_component_class_source *comp_cls,
603 bt_component_class_source_message_iterator_seek_beginning_method method)
604{
605 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
606 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 607 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7474e7d3 608 comp_cls->methods.msg_iter_seek_beginning = method;
3f7d4d90 609 BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" method"
7474e7d3 610 ": %!+C", comp_cls);
d24d5663 611 return BT_FUNC_STATUS_OK;
7474e7d3
PP
612}
613
d24d5663 614enum bt_component_class_set_method_status
7474e7d3
PP
615bt_component_class_filter_set_message_iterator_can_seek_beginning_method(
616 struct bt_component_class_filter *comp_cls,
617 bt_component_class_filter_message_iterator_can_seek_beginning_method method)
618{
619 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
620 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 621 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7474e7d3 622 comp_cls->methods.msg_iter_can_seek_beginning = method;
3f7d4d90 623 BT_LIB_LOGD("Set filter component class's message iterator \"can seek beginning\" method"
7474e7d3 624 ": %!+C", comp_cls);
d24d5663 625 return BT_FUNC_STATUS_OK;
7474e7d3
PP
626}
627
d24d5663 628enum bt_component_class_set_method_status
7474e7d3
PP
629bt_component_class_source_set_message_iterator_can_seek_beginning_method(
630 struct bt_component_class_source *comp_cls,
631 bt_component_class_source_message_iterator_can_seek_beginning_method method)
632{
633 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
634 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 635 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7474e7d3 636 comp_cls->methods.msg_iter_can_seek_beginning = method;
3f7d4d90 637 BT_LIB_LOGD("Set source component class's message iterator \"can seek beginning\" method"
7474e7d3 638 ": %!+C", comp_cls);
d24d5663 639 return BT_FUNC_STATUS_OK;
7474e7d3
PP
640}
641
d24d5663 642enum bt_component_class_set_method_status
7474e7d3
PP
643bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method(
644 struct bt_component_class_filter *comp_cls,
645 bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method method)
646{
647 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
648 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 649 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7474e7d3 650 comp_cls->methods.msg_iter_can_seek_ns_from_origin = method;
3f7d4d90 651 BT_LIB_LOGD("Set filter component class's message iterator \"can seek nanoseconds from origin\" method"
7474e7d3 652 ": %!+C", comp_cls);
d24d5663 653 return BT_FUNC_STATUS_OK;
7474e7d3
PP
654}
655
d24d5663 656enum bt_component_class_set_method_status
7474e7d3
PP
657bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method(
658 struct bt_component_class_source *comp_cls,
659 bt_component_class_source_message_iterator_can_seek_ns_from_origin_method method)
660{
661 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
662 BT_ASSERT_PRE_NON_NULL(method, "Method");
bdb288b3 663 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7474e7d3 664 comp_cls->methods.msg_iter_can_seek_ns_from_origin = method;
3f7d4d90 665 BT_LIB_LOGD("Set source component class's message iterator \"can seek nanoseconds from origin\" method"
7474e7d3 666 ": %!+C", comp_cls);
d24d5663 667 return BT_FUNC_STATUS_OK;
7474e7d3
PP
668}
669
d24d5663
PP
670enum bt_component_class_set_description_status
671bt_component_class_set_description(
0d72b8c3 672 struct bt_component_class *comp_cls,
d3e4dcd8
PP
673 const char *description)
674{
d94d92ac
PP
675 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
676 BT_ASSERT_PRE_NON_NULL(description, "Description");
bdb288b3 677 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 678 g_string_assign(comp_cls->description, description);
3f7d4d90 679 BT_LIB_LOGD("Set component class's description: "
a3aacb6f 680 "addr=%p, name=\"%s\", type=%s",
d94d92ac
PP
681 comp_cls,
682 bt_component_class_get_name(comp_cls),
683 bt_component_class_type_string(comp_cls->type));
d24d5663 684 return BT_FUNC_STATUS_OK;
fb2dcc52 685}
38b48196 686
d24d5663 687enum bt_component_class_set_help_status bt_component_class_set_help(
0d72b8c3 688 struct bt_component_class *comp_cls,
5536d9a6
PP
689 const char *help)
690{
d94d92ac
PP
691 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
692 BT_ASSERT_PRE_NON_NULL(help, "Help");
bdb288b3 693 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
d94d92ac 694 g_string_assign(comp_cls->help, help);
3f7d4d90 695 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls);
d24d5663 696 return BT_FUNC_STATUS_OK;
5536d9a6
PP
697}
698
0d72b8c3 699const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
38b48196 700{
bdb288b3 701 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
d94d92ac 702 return comp_cls->name->str;
38b48196
JG
703}
704
d3e4dcd8 705enum bt_component_class_type bt_component_class_get_type(
0d72b8c3 706 const struct bt_component_class *comp_cls)
38b48196 707{
bdb288b3 708 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
d94d92ac 709 return comp_cls->type;
38b48196
JG
710}
711
33b34c43 712const char *bt_component_class_get_description(
0d72b8c3 713 const struct bt_component_class *comp_cls)
38b48196 714{
bdb288b3 715 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
d94d92ac
PP
716 return comp_cls->description &&
717 comp_cls->description->str[0] != '\0' ?
718 comp_cls->description->str : NULL;
38b48196 719}
7c7c0433 720
5536d9a6 721const char *bt_component_class_get_help(
0d72b8c3 722 const struct bt_component_class *comp_cls)
5536d9a6 723{
bdb288b3 724 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
d94d92ac
PP
725 return comp_cls->help &&
726 comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL;
5536d9a6
PP
727}
728
33b34c43 729BT_HIDDEN
d94d92ac
PP
730void bt_component_class_add_destroy_listener(
731 struct bt_component_class *comp_cls,
33b34c43 732 bt_component_class_destroy_listener_func func, void *data)
7c7c0433 733{
d3e4dcd8 734 struct bt_component_class_destroy_listener listener;
33b34c43 735
d94d92ac 736 BT_ASSERT(comp_cls);
f6ccaed9 737 BT_ASSERT(func);
33b34c43
PP
738 listener.func = func;
739 listener.data = data;
d94d92ac 740 g_array_append_val(comp_cls->destroy_listeners, listener);
3f7d4d90 741 BT_LIB_LOGD("Added destroy listener to component class: "
d94d92ac 742 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
7c7c0433 743}
d3e4dcd8 744
d94d92ac 745BT_HIDDEN
0d72b8c3 746void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
1e4d8103 747{
d94d92ac
PP
748 BT_ASSERT(comp_cls);
749 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
0d72b8c3 750 ((struct bt_component_class *) comp_cls)->frozen = true;
1e4d8103 751}
c5b9b441
PP
752
753void bt_component_class_get_ref(
754 const struct bt_component_class *component_class)
755{
756 bt_object_get_ref(component_class);
757}
758
759void bt_component_class_put_ref(
760 const struct bt_component_class *component_class)
761{
762 bt_object_put_ref(component_class);
763}
764
765void bt_component_class_source_get_ref(
766 const struct bt_component_class_source *component_class_source)
767{
768 bt_object_get_ref(component_class_source);
769}
770
771void bt_component_class_source_put_ref(
772 const struct bt_component_class_source *component_class_source)
773{
774 bt_object_put_ref(component_class_source);
775}
776
777void bt_component_class_filter_get_ref(
778 const struct bt_component_class_filter *component_class_filter)
779{
780 bt_object_get_ref(component_class_filter);
781}
782
783void bt_component_class_filter_put_ref(
784 const struct bt_component_class_filter *component_class_filter)
785{
786 bt_object_put_ref(component_class_filter);
787}
788
789void bt_component_class_sink_get_ref(
790 const struct bt_component_class_sink *component_class_sink)
791{
792 bt_object_get_ref(component_class_sink);
793}
794
795void bt_component_class_sink_put_ref(
796 const struct bt_component_class_sink *component_class_sink)
797{
798 bt_object_put_ref(component_class_sink);
799}
This page took 0.102468 seconds and 4 git commands to generate.