lib: fully configure graph (add components, connect ports), then run
[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
0d72b8c3
PP
248int bt_component_class_source_set_init_method(
249 struct bt_component_class_source *comp_cls,
250 bt_component_class_source_init_method method)
d3e4dcd8 251{
d94d92ac
PP
252 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
253 BT_ASSERT_PRE_NON_NULL(method, "Method");
254 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
255 comp_cls->methods.init = method;
256 BT_LIB_LOGV("Set source component class's initialization method: "
257 "%!+C", comp_cls);
d0cf29ee 258 return BT_COMPONENT_CLASS_STATUS_OK;
d3e4dcd8
PP
259}
260
0d72b8c3
PP
261int bt_component_class_filter_set_init_method(
262 struct bt_component_class_filter *comp_cls,
263 bt_component_class_filter_init_method method)
efa96d5d 264{
d94d92ac
PP
265 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
266 BT_ASSERT_PRE_NON_NULL(method, "Method");
267 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
268 comp_cls->methods.init = method;
269 BT_LIB_LOGV("Set filter component class's initialization method: "
270 "%!+C", comp_cls);
d0cf29ee 271 return BT_COMPONENT_CLASS_STATUS_OK;
efa96d5d
PP
272}
273
0d72b8c3
PP
274int bt_component_class_sink_set_init_method(
275 struct bt_component_class_sink *comp_cls,
276 bt_component_class_sink_init_method method)
2d41b99e 277{
d94d92ac
PP
278 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
279 BT_ASSERT_PRE_NON_NULL(method, "Method");
280 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
281 comp_cls->methods.init = method;
282 BT_LIB_LOGV("Set sink component class's initialization method: "
283 "%!+C", comp_cls);
d0cf29ee 284 return BT_COMPONENT_CLASS_STATUS_OK;
72b913fb
PP
285}
286
0d72b8c3
PP
287int bt_component_class_source_set_finalize_method(
288 struct bt_component_class_source *comp_cls,
289 bt_component_class_source_finalize_method method)
0d8b4d8e 290{
d94d92ac
PP
291 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
292 BT_ASSERT_PRE_NON_NULL(method, "Method");
293 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
294 comp_cls->methods.finalize = method;
295 BT_LIB_LOGV("Set source component class's finalization method: "
296 "%!+C", comp_cls);
d0cf29ee 297 return BT_COMPONENT_CLASS_STATUS_OK;
0d8b4d8e
PP
298}
299
0d72b8c3
PP
300int bt_component_class_filter_set_finalize_method(
301 struct bt_component_class_filter *comp_cls,
302 bt_component_class_filter_finalize_method method)
72b913fb 303{
d94d92ac
PP
304 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
305 BT_ASSERT_PRE_NON_NULL(method, "Method");
306 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
307 comp_cls->methods.finalize = method;
308 BT_LIB_LOGV("Set filter component class's finalization method: "
309 "%!+C", comp_cls);
d0cf29ee 310 return BT_COMPONENT_CLASS_STATUS_OK;
2d41b99e
JG
311}
312
0d72b8c3
PP
313int bt_component_class_sink_set_finalize_method(
314 struct bt_component_class_sink *comp_cls,
315 bt_component_class_sink_finalize_method method)
d3e4dcd8 316{
d94d92ac
PP
317 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
318 BT_ASSERT_PRE_NON_NULL(method, "Method");
319 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
320 comp_cls->methods.finalize = method;
321 BT_LIB_LOGV("Set sink component class's finalization method: "
322 "%!+C", comp_cls);
d0cf29ee 323 return BT_COMPONENT_CLASS_STATUS_OK;
d3e4dcd8
PP
324}
325
0d72b8c3
PP
326int bt_component_class_source_set_query_method(
327 struct bt_component_class_source *comp_cls,
328 bt_component_class_source_query_method method)
d3eb6e8f 329{
d94d92ac
PP
330 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
331 BT_ASSERT_PRE_NON_NULL(method, "Method");
332 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
333 comp_cls->methods.query = method;
334 BT_LIB_LOGV("Set source component class's query method: "
335 "%!+C", comp_cls);
d0cf29ee 336 return BT_COMPONENT_CLASS_STATUS_OK;
d3eb6e8f
PP
337}
338
0d72b8c3
PP
339int bt_component_class_filter_set_query_method(
340 struct bt_component_class_filter *comp_cls,
341 bt_component_class_filter_query_method method)
d3eb6e8f 342{
d94d92ac
PP
343 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
344 BT_ASSERT_PRE_NON_NULL(method, "Method");
345 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
346 comp_cls->methods.query = method;
347 BT_LIB_LOGV("Set filter component class's query method: "
348 "%!+C", comp_cls);
d0cf29ee 349 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 350}
a3aacb6f 351
0d72b8c3
PP
352int bt_component_class_sink_set_query_method(
353 struct bt_component_class_sink *comp_cls,
354 bt_component_class_sink_query_method method)
d94d92ac 355{
d94d92ac
PP
356 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
357 BT_ASSERT_PRE_NON_NULL(method, "Method");
358 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
359 comp_cls->methods.query = method;
360 BT_LIB_LOGV("Set sink component class's query method: "
361 "%!+C", comp_cls);
d0cf29ee 362 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 363}
d3eb6e8f 364
0d72b8c3
PP
365int bt_component_class_filter_set_accept_input_port_connection_method(
366 struct bt_component_class_filter *comp_cls,
367 bt_component_class_filter_accept_input_port_connection_method method)
d94d92ac 368{
d94d92ac
PP
369 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
370 BT_ASSERT_PRE_NON_NULL(method, "Method");
371 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
372 comp_cls->methods.accept_input_port_connection = method;
373 BT_LIB_LOGV("Set filter component class's \"accept input port connection\" method"
374 ": %!+C", comp_cls);
d0cf29ee 375 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 376}
d3eb6e8f 377
0d72b8c3
PP
378int bt_component_class_sink_set_accept_input_port_connection_method(
379 struct bt_component_class_sink *comp_cls,
380 bt_component_class_sink_accept_input_port_connection_method method)
d94d92ac 381{
d94d92ac
PP
382 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
383 BT_ASSERT_PRE_NON_NULL(method, "Method");
384 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
385 comp_cls->methods.accept_input_port_connection = method;
386 BT_LIB_LOGV("Set sink component class's \"accept input port connection\" method"
387 ": %!+C", comp_cls);
d0cf29ee 388 return BT_COMPONENT_CLASS_STATUS_OK;
d3eb6e8f
PP
389}
390
0d72b8c3
PP
391int bt_component_class_source_set_accept_output_port_connection_method(
392 struct bt_component_class_source *comp_cls,
393 bt_component_class_source_accept_output_port_connection_method method)
d3eb6e8f 394{
d94d92ac
PP
395 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
396 BT_ASSERT_PRE_NON_NULL(method, "Method");
397 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
398 comp_cls->methods.accept_output_port_connection = method;
399 BT_LIB_LOGV("Set source component class's \"accept output port connection\" method"
400 ": %!+C", comp_cls);
d0cf29ee 401 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 402}
d3eb6e8f 403
0d72b8c3
PP
404int bt_component_class_filter_set_accept_output_port_connection_method(
405 struct bt_component_class_filter *comp_cls,
406 bt_component_class_filter_accept_output_port_connection_method method)
d94d92ac 407{
d94d92ac
PP
408 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
409 BT_ASSERT_PRE_NON_NULL(method, "Method");
410 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
411 comp_cls->methods.accept_output_port_connection = method;
412 BT_LIB_LOGV("Set filter component class's \"accept output port connection\" method"
413 ": %!+C", comp_cls);
d0cf29ee 414 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 415}
a3aacb6f 416
0d72b8c3
PP
417int bt_component_class_filter_set_input_port_connected_method(
418 struct bt_component_class_filter *comp_cls,
419 bt_component_class_filter_input_port_connected_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.input_port_connected = method;
425 BT_LIB_LOGV("Set filter component class's \"input port connected\" method"
426 ": %!+C", comp_cls);
d0cf29ee 427 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 428}
a3aacb6f 429
0d72b8c3
PP
430int bt_component_class_sink_set_input_port_connected_method(
431 struct bt_component_class_sink *comp_cls,
432 bt_component_class_sink_input_port_connected_method method)
d94d92ac 433{
d94d92ac
PP
434 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
435 BT_ASSERT_PRE_NON_NULL(method, "Method");
436 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
437 comp_cls->methods.input_port_connected = method;
438 BT_LIB_LOGV("Set sink component class's \"input port connected\" method"
439 ": %!+C", comp_cls);
d0cf29ee 440 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 441}
a3aacb6f 442
0d72b8c3
PP
443int bt_component_class_source_set_output_port_connected_method(
444 struct bt_component_class_source *comp_cls,
445 bt_component_class_source_output_port_connected_method method)
d94d92ac 446{
d94d92ac
PP
447 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
448 BT_ASSERT_PRE_NON_NULL(method, "Method");
449 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
450 comp_cls->methods.output_port_connected = method;
451 BT_LIB_LOGV("Set source component class's \"output port connected\" method"
452 ": %!+C", comp_cls);
d0cf29ee 453 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 454}
d3eb6e8f 455
0d72b8c3
PP
456int bt_component_class_filter_set_output_port_connected_method(
457 struct bt_component_class_filter *comp_cls,
458 bt_component_class_filter_output_port_connected_method method)
d94d92ac 459{
d94d92ac
PP
460 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
461 BT_ASSERT_PRE_NON_NULL(method, "Method");
462 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
463 comp_cls->methods.output_port_connected = method;
464 BT_LIB_LOGV("Set filter component class's \"output port connected\" method"
465 ": %!+C", comp_cls);
d0cf29ee 466 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 467}
d3eb6e8f 468
d6e69534 469int bt_component_class_source_set_message_iterator_init_method(
0d72b8c3 470 struct bt_component_class_source *comp_cls,
d6e69534 471 bt_component_class_source_message_iterator_init_method method)
d94d92ac 472{
d94d92ac
PP
473 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
474 BT_ASSERT_PRE_NON_NULL(method, "Method");
475 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
d6e69534
PP
476 comp_cls->methods.msg_iter_init = method;
477 BT_LIB_LOGV("Set source component class's message iterator initialization method"
d94d92ac 478 ": %!+C", comp_cls);
d0cf29ee 479 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 480}
a3aacb6f 481
d6e69534 482int bt_component_class_filter_set_message_iterator_init_method(
0d72b8c3 483 struct bt_component_class_filter *comp_cls,
d6e69534 484 bt_component_class_filter_message_iterator_init_method method)
d94d92ac 485{
d94d92ac
PP
486 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
487 BT_ASSERT_PRE_NON_NULL(method, "Method");
488 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
d6e69534
PP
489 comp_cls->methods.msg_iter_init = method;
490 BT_LIB_LOGV("Set filter component class's message iterator initialization method"
d94d92ac 491 ": %!+C", comp_cls);
d0cf29ee 492 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 493}
d3eb6e8f 494
d6e69534 495int bt_component_class_source_set_message_iterator_finalize_method(
0d72b8c3 496 struct bt_component_class_source *comp_cls,
d6e69534 497 bt_component_class_source_message_iterator_finalize_method method)
d94d92ac 498{
d94d92ac
PP
499 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
500 BT_ASSERT_PRE_NON_NULL(method, "Method");
501 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
d6e69534
PP
502 comp_cls->methods.msg_iter_finalize = method;
503 BT_LIB_LOGV("Set source component class's message iterator finalization method"
d94d92ac 504 ": %!+C", comp_cls);
d0cf29ee 505 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 506}
d3eb6e8f 507
d6e69534 508int bt_component_class_filter_set_message_iterator_finalize_method(
0d72b8c3 509 struct bt_component_class_filter *comp_cls,
d6e69534 510 bt_component_class_filter_message_iterator_finalize_method method)
d94d92ac 511{
d94d92ac
PP
512 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
513 BT_ASSERT_PRE_NON_NULL(method, "Method");
514 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
d6e69534
PP
515 comp_cls->methods.msg_iter_finalize = method;
516 BT_LIB_LOGV("Set filter component class's message iterator finalization method"
d94d92ac 517 ": %!+C", comp_cls);
d0cf29ee 518 return BT_COMPONENT_CLASS_STATUS_OK;
d3eb6e8f
PP
519}
520
d0cf29ee 521bt_component_class_status bt_component_class_set_description(
0d72b8c3 522 struct bt_component_class *comp_cls,
d3e4dcd8
PP
523 const char *description)
524{
d94d92ac
PP
525 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
526 BT_ASSERT_PRE_NON_NULL(description, "Description");
527 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
528 g_string_assign(comp_cls->description, description);
529 BT_LIB_LOGV("Set component class's description: "
a3aacb6f 530 "addr=%p, name=\"%s\", type=%s",
d94d92ac
PP
531 comp_cls,
532 bt_component_class_get_name(comp_cls),
533 bt_component_class_type_string(comp_cls->type));
d0cf29ee 534 return BT_COMPONENT_CLASS_STATUS_OK;
fb2dcc52 535}
38b48196 536
d0cf29ee 537bt_component_class_status bt_component_class_set_help(
0d72b8c3 538 struct bt_component_class *comp_cls,
5536d9a6
PP
539 const char *help)
540{
d94d92ac
PP
541 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
542 BT_ASSERT_PRE_NON_NULL(help, "Help");
543 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
544 g_string_assign(comp_cls->help, help);
545 BT_LIB_LOGV("Set component class's help text: %!+C", comp_cls);
d0cf29ee 546 return BT_COMPONENT_CLASS_STATUS_OK;
5536d9a6
PP
547}
548
0d72b8c3 549const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
38b48196 550{
d94d92ac
PP
551 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
552 return comp_cls->name->str;
38b48196
JG
553}
554
d3e4dcd8 555enum bt_component_class_type bt_component_class_get_type(
0d72b8c3 556 const struct bt_component_class *comp_cls)
38b48196 557{
d94d92ac
PP
558 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
559 return comp_cls->type;
38b48196
JG
560}
561
33b34c43 562const char *bt_component_class_get_description(
0d72b8c3 563 const struct bt_component_class *comp_cls)
38b48196 564{
d94d92ac
PP
565 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
566 return comp_cls->description &&
567 comp_cls->description->str[0] != '\0' ?
568 comp_cls->description->str : NULL;
38b48196 569}
7c7c0433 570
5536d9a6 571const char *bt_component_class_get_help(
0d72b8c3 572 const struct bt_component_class *comp_cls)
5536d9a6 573{
d94d92ac
PP
574 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
575 return comp_cls->help &&
576 comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL;
5536d9a6
PP
577}
578
33b34c43 579BT_HIDDEN
d94d92ac
PP
580void bt_component_class_add_destroy_listener(
581 struct bt_component_class *comp_cls,
33b34c43 582 bt_component_class_destroy_listener_func func, void *data)
7c7c0433 583{
d3e4dcd8 584 struct bt_component_class_destroy_listener listener;
33b34c43 585
d94d92ac 586 BT_ASSERT(comp_cls);
f6ccaed9 587 BT_ASSERT(func);
33b34c43
PP
588 listener.func = func;
589 listener.data = data;
d94d92ac
PP
590 g_array_append_val(comp_cls->destroy_listeners, listener);
591 BT_LIB_LOGV("Added destroy listener to component class: "
592 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
7c7c0433 593}
d3e4dcd8 594
d94d92ac 595BT_HIDDEN
0d72b8c3 596void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
1e4d8103 597{
d94d92ac
PP
598 BT_ASSERT(comp_cls);
599 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
0d72b8c3 600 ((struct bt_component_class *) comp_cls)->frozen = true;
1e4d8103 601}
c5b9b441
PP
602
603void bt_component_class_get_ref(
604 const struct bt_component_class *component_class)
605{
606 bt_object_get_ref(component_class);
607}
608
609void bt_component_class_put_ref(
610 const struct bt_component_class *component_class)
611{
612 bt_object_put_ref(component_class);
613}
614
615void bt_component_class_source_get_ref(
616 const struct bt_component_class_source *component_class_source)
617{
618 bt_object_get_ref(component_class_source);
619}
620
621void bt_component_class_source_put_ref(
622 const struct bt_component_class_source *component_class_source)
623{
624 bt_object_put_ref(component_class_source);
625}
626
627void bt_component_class_filter_get_ref(
628 const struct bt_component_class_filter *component_class_filter)
629{
630 bt_object_get_ref(component_class_filter);
631}
632
633void bt_component_class_filter_put_ref(
634 const struct bt_component_class_filter *component_class_filter)
635{
636 bt_object_put_ref(component_class_filter);
637}
638
639void bt_component_class_sink_get_ref(
640 const struct bt_component_class_sink *component_class_sink)
641{
642 bt_object_get_ref(component_class_sink);
643}
644
645void bt_component_class_sink_put_ref(
646 const struct bt_component_class_sink *component_class_sink)
647{
648 bt_object_put_ref(component_class_sink);
649}
This page took 0.071841 seconds and 4 git commands to generate.