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