lib: rename plural file names to singular
[babeltrace.git] / lib / graph / component-class.c
CommitLineData
fb2dcc52 1/*
3310b217 2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
fb2dcc52
JG
3 *
4 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24
a3aacb6f
PP
25#define BT_LOG_TAG "COMP-CLASS"
26#include <babeltrace/lib-logging-internal.h>
27
3d9990ac 28#include <babeltrace/compiler-internal.h>
0d72b8c3
PP
29#include <babeltrace/graph/component-class.h>
30#include <babeltrace/graph/component-class-const.h>
31#include <babeltrace/graph/component-class-source.h>
32#include <babeltrace/graph/component-class-source-const.h>
33#include <babeltrace/graph/component-class-filter.h>
34#include <babeltrace/graph/component-class-filter-const.h>
35#include <babeltrace/graph/component-class-sink.h>
36#include <babeltrace/graph/component-class-sink-const.h>
b2e0c907 37#include <babeltrace/graph/component-class-internal.h>
65300d60 38#include <babeltrace/object.h>
c55a9f58 39#include <babeltrace/types.h>
f6ccaed9 40#include <babeltrace/assert-internal.h>
d94d92ac 41#include <babeltrace/assert-pre-internal.h>
fb2dcc52
JG
42#include <glib.h>
43
d94d92ac 44#define BT_ASSERT_PRE_COMP_CLS_HOT(_cc) \
0d72b8c3 45 BT_ASSERT_PRE_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
d94d92ac 57 BT_LIB_LOGD("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
33b34c43
PP
86 if (class->destroy_listeners) {
87 g_array_free(class->destroy_listeners, TRUE);
d94d92ac 88 class->destroy_listeners = NULL;
33b34c43 89 }
b8a06801 90
fb2dcc52
JG
91 g_free(class);
92}
93
d3e4dcd8
PP
94static
95int bt_component_class_init(struct bt_component_class *class,
96 enum bt_component_class_type type, const char *name)
fb2dcc52 97{
d3e4dcd8
PP
98 int ret = 0;
99
d94d92ac 100 bt_object_init_shared(&class->base, destroy_component_class);
d3e4dcd8
PP
101 class->type = type;
102 class->name = g_string_new(name);
103 if (!class->name) {
a3aacb6f 104 BT_LOGE_STR("Failed to allocate a GString.");
d3e4dcd8
PP
105 goto error;
106 }
107
108 class->description = g_string_new(NULL);
109 if (!class->description) {
a3aacb6f 110 BT_LOGE_STR("Failed to allocate a GString.");
d3e4dcd8
PP
111 goto error;
112 }
113
5536d9a6
PP
114 class->help = g_string_new(NULL);
115 if (!class->help) {
a3aacb6f 116 BT_LOGE_STR("Failed to allocate a GString.");
5536d9a6
PP
117 goto error;
118 }
119
d3e4dcd8
PP
120 class->destroy_listeners = g_array_new(FALSE, TRUE,
121 sizeof(struct bt_component_class_destroy_listener));
122 if (!class->destroy_listeners) {
a3aacb6f 123 BT_LOGE_STR("Failed to allocate a GArray.");
d3e4dcd8
PP
124 goto error;
125 }
126
127 goto end;
6ba0b073 128
d3e4dcd8 129error:
65300d60 130 BT_OBJECT_PUT_REF_AND_RESET(class);
d3e4dcd8
PP
131 ret = -1;
132
133end:
134 return ret;
135}
136
0d72b8c3 137struct bt_component_class_source *bt_component_class_source_create(
d94d92ac 138 const char *name,
0d72b8c3 139 bt_component_class_source_notification_iterator_next_method method)
d3e4dcd8
PP
140{
141 struct bt_component_class_source *source_class = NULL;
142 int ret;
143
d94d92ac
PP
144 BT_ASSERT_PRE_NON_NULL(name, "Name");
145 BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method");
a3aacb6f
PP
146 BT_LOGD("Creating source component class: "
147 "name=\"%s\", notif-iter-next-method-addr=%p",
90157d89 148 name, method);
d3e4dcd8
PP
149 source_class = g_new0(struct bt_component_class_source, 1);
150 if (!source_class) {
a3aacb6f 151 BT_LOGE_STR("Failed to allocate one source component class.");
fb2dcc52
JG
152 goto end;
153 }
154
a3aacb6f 155 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
156 ret = bt_component_class_init(&source_class->parent,
157 BT_COMPONENT_CLASS_TYPE_SOURCE, name);
158 if (ret) {
159 /*
160 * If bt_component_class_init() fails, the component
161 * class is put, therefore its memory is already
162 * freed.
163 */
164 source_class = NULL;
165 goto end;
166 }
167
d94d92ac
PP
168 source_class->methods.notif_iter_next = method;
169 BT_LIB_LOGD("Created source component class: %!+C", source_class);
d3e4dcd8
PP
170
171end:
d94d92ac 172 return (void *) source_class;
d3e4dcd8
PP
173}
174
0d72b8c3
PP
175struct bt_component_class_filter *bt_component_class_filter_create(
176 const char *name,
177 bt_component_class_filter_notification_iterator_next_method method)
d3e4dcd8
PP
178{
179 struct bt_component_class_filter *filter_class = NULL;
180 int ret;
181
d94d92ac
PP
182 BT_ASSERT_PRE_NON_NULL(name, "Name");
183 BT_ASSERT_PRE_NON_NULL(method, "Notification iterator next method");
a3aacb6f
PP
184 BT_LOGD("Creating filter component class: "
185 "name=\"%s\", notif-iter-next-method-addr=%p",
90157d89 186 name, method);
d3e4dcd8
PP
187 filter_class = g_new0(struct bt_component_class_filter, 1);
188 if (!filter_class) {
a3aacb6f 189 BT_LOGE_STR("Failed to allocate one filter component class.");
d3e4dcd8 190 goto end;
6ba0b073
PP
191 }
192
a3aacb6f 193 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
194 ret = bt_component_class_init(&filter_class->parent,
195 BT_COMPONENT_CLASS_TYPE_FILTER, name);
196 if (ret) {
197 /*
198 * If bt_component_class_init() fails, the component
199 * class is put, therefore its memory is already
200 * freed.
201 */
202 filter_class = NULL;
33b34c43
PP
203 goto end;
204 }
d3e4dcd8 205
d94d92ac
PP
206 filter_class->methods.notif_iter_next = method;
207 BT_LIB_LOGD("Created filter component class: %!+C", filter_class);
d3e4dcd8 208
fb2dcc52 209end:
d94d92ac 210 return (void *) filter_class;
d3e4dcd8
PP
211}
212
0d72b8c3
PP
213struct bt_component_class_sink *bt_component_class_sink_create(
214 const char *name, bt_component_class_sink_consume_method method)
d3e4dcd8
PP
215{
216 struct bt_component_class_sink *sink_class = NULL;
217 int ret;
218
d94d92ac
PP
219 BT_ASSERT_PRE_NON_NULL(name, "Name");
220 BT_ASSERT_PRE_NON_NULL(method, "Consume next method");
a3aacb6f
PP
221 BT_LOGD("Creating sink component class: "
222 "name=\"%s\", consume-method-addr=%p",
90157d89 223 name, method);
d3e4dcd8
PP
224 sink_class = g_new0(struct bt_component_class_sink, 1);
225 if (!sink_class) {
a3aacb6f 226 BT_LOGE_STR("Failed to allocate one sink component class.");
d3e4dcd8
PP
227 goto end;
228 }
229
a3aacb6f 230 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
231 ret = bt_component_class_init(&sink_class->parent,
232 BT_COMPONENT_CLASS_TYPE_SINK, name);
233 if (ret) {
234 /*
235 * If bt_component_class_init() fails, the component
236 * class is put, therefore its memory is already
237 * freed.
238 */
239 sink_class = NULL;
240 goto end;
241 }
242
90157d89 243 sink_class->methods.consume = method;
d94d92ac 244 BT_LIB_LOGD("Created sink component class: %!+C", sink_class);
d3e4dcd8
PP
245
246end:
d94d92ac 247 return (void *) sink_class;
d3e4dcd8
PP
248}
249
0d72b8c3
PP
250int bt_component_class_source_set_init_method(
251 struct bt_component_class_source *comp_cls,
252 bt_component_class_source_init_method method)
d3e4dcd8 253{
d94d92ac
PP
254 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
255 BT_ASSERT_PRE_NON_NULL(method, "Method");
256 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
257 comp_cls->methods.init = method;
258 BT_LIB_LOGV("Set source component class's initialization method: "
259 "%!+C", comp_cls);
260 return 0;
d3e4dcd8
PP
261}
262
0d72b8c3
PP
263int bt_component_class_filter_set_init_method(
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);
273 return 0;
efa96d5d
PP
274}
275
0d72b8c3
PP
276int bt_component_class_sink_set_init_method(
277 struct bt_component_class_sink *comp_cls,
278 bt_component_class_sink_init_method method)
2d41b99e 279{
d94d92ac
PP
280 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
281 BT_ASSERT_PRE_NON_NULL(method, "Method");
282 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
283 comp_cls->methods.init = method;
284 BT_LIB_LOGV("Set sink component class's initialization method: "
285 "%!+C", comp_cls);
286 return 0;
72b913fb
PP
287}
288
0d72b8c3
PP
289int bt_component_class_source_set_finalize_method(
290 struct bt_component_class_source *comp_cls,
291 bt_component_class_source_finalize_method method)
0d8b4d8e 292{
d94d92ac
PP
293 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
294 BT_ASSERT_PRE_NON_NULL(method, "Method");
295 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
296 comp_cls->methods.finalize = method;
297 BT_LIB_LOGV("Set source component class's finalization method: "
298 "%!+C", comp_cls);
299 return 0;
0d8b4d8e
PP
300}
301
0d72b8c3
PP
302int bt_component_class_filter_set_finalize_method(
303 struct bt_component_class_filter *comp_cls,
304 bt_component_class_filter_finalize_method method)
72b913fb 305{
d94d92ac
PP
306 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
307 BT_ASSERT_PRE_NON_NULL(method, "Method");
308 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
309 comp_cls->methods.finalize = method;
310 BT_LIB_LOGV("Set filter component class's finalization method: "
311 "%!+C", comp_cls);
312 return 0;
2d41b99e
JG
313}
314
0d72b8c3
PP
315int bt_component_class_sink_set_finalize_method(
316 struct bt_component_class_sink *comp_cls,
317 bt_component_class_sink_finalize_method method)
d3e4dcd8 318{
d94d92ac
PP
319 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
320 BT_ASSERT_PRE_NON_NULL(method, "Method");
321 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
322 comp_cls->methods.finalize = method;
323 BT_LIB_LOGV("Set sink component class's finalization method: "
324 "%!+C", comp_cls);
325 return 0;
d3e4dcd8
PP
326}
327
0d72b8c3
PP
328int bt_component_class_source_set_query_method(
329 struct bt_component_class_source *comp_cls,
330 bt_component_class_source_query_method method)
d3eb6e8f 331{
d94d92ac
PP
332 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
333 BT_ASSERT_PRE_NON_NULL(method, "Method");
334 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
335 comp_cls->methods.query = method;
336 BT_LIB_LOGV("Set source component class's query method: "
337 "%!+C", comp_cls);
338 return 0;
d3eb6e8f
PP
339}
340
0d72b8c3
PP
341int bt_component_class_filter_set_query_method(
342 struct bt_component_class_filter *comp_cls,
343 bt_component_class_filter_query_method method)
d3eb6e8f 344{
d94d92ac
PP
345 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
346 BT_ASSERT_PRE_NON_NULL(method, "Method");
347 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
348 comp_cls->methods.query = method;
349 BT_LIB_LOGV("Set filter component class's query method: "
350 "%!+C", comp_cls);
351 return 0;
352}
a3aacb6f 353
0d72b8c3
PP
354int bt_component_class_sink_set_query_method(
355 struct bt_component_class_sink *comp_cls,
356 bt_component_class_sink_query_method method)
d94d92ac 357{
d94d92ac
PP
358 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
359 BT_ASSERT_PRE_NON_NULL(method, "Method");
360 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
361 comp_cls->methods.query = method;
362 BT_LIB_LOGV("Set sink component class's query method: "
363 "%!+C", comp_cls);
364 return 0;
365}
d3eb6e8f 366
0d72b8c3
PP
367int bt_component_class_filter_set_accept_input_port_connection_method(
368 struct bt_component_class_filter *comp_cls,
369 bt_component_class_filter_accept_input_port_connection_method method)
d94d92ac 370{
d94d92ac
PP
371 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
372 BT_ASSERT_PRE_NON_NULL(method, "Method");
373 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
374 comp_cls->methods.accept_input_port_connection = method;
375 BT_LIB_LOGV("Set filter component class's \"accept input port connection\" method"
376 ": %!+C", comp_cls);
377 return 0;
378}
d3eb6e8f 379
0d72b8c3
PP
380int bt_component_class_sink_set_accept_input_port_connection_method(
381 struct bt_component_class_sink *comp_cls,
382 bt_component_class_sink_accept_input_port_connection_method method)
d94d92ac 383{
d94d92ac
PP
384 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
385 BT_ASSERT_PRE_NON_NULL(method, "Method");
386 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
387 comp_cls->methods.accept_input_port_connection = method;
388 BT_LIB_LOGV("Set sink component class's \"accept input port connection\" method"
389 ": %!+C", comp_cls);
390 return 0;
d3eb6e8f
PP
391}
392
0d72b8c3
PP
393int bt_component_class_source_set_accept_output_port_connection_method(
394 struct bt_component_class_source *comp_cls,
395 bt_component_class_source_accept_output_port_connection_method method)
d3eb6e8f 396{
d94d92ac
PP
397 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
398 BT_ASSERT_PRE_NON_NULL(method, "Method");
399 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
400 comp_cls->methods.accept_output_port_connection = method;
401 BT_LIB_LOGV("Set source component class's \"accept output port connection\" method"
402 ": %!+C", comp_cls);
403 return 0;
404}
d3eb6e8f 405
0d72b8c3
PP
406int bt_component_class_filter_set_accept_output_port_connection_method(
407 struct bt_component_class_filter *comp_cls,
408 bt_component_class_filter_accept_output_port_connection_method method)
d94d92ac 409{
d94d92ac
PP
410 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
411 BT_ASSERT_PRE_NON_NULL(method, "Method");
412 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
413 comp_cls->methods.accept_output_port_connection = method;
414 BT_LIB_LOGV("Set filter component class's \"accept output port connection\" method"
415 ": %!+C", comp_cls);
416 return 0;
417}
a3aacb6f 418
0d72b8c3
PP
419int bt_component_class_filter_set_input_port_connected_method(
420 struct bt_component_class_filter *comp_cls,
421 bt_component_class_filter_input_port_connected_method method)
d94d92ac 422{
d94d92ac
PP
423 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
424 BT_ASSERT_PRE_NON_NULL(method, "Method");
425 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
426 comp_cls->methods.input_port_connected = method;
427 BT_LIB_LOGV("Set filter component class's \"input port connected\" method"
428 ": %!+C", comp_cls);
429 return 0;
430}
a3aacb6f 431
0d72b8c3
PP
432int bt_component_class_sink_set_input_port_connected_method(
433 struct bt_component_class_sink *comp_cls,
434 bt_component_class_sink_input_port_connected_method method)
d94d92ac 435{
d94d92ac
PP
436 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
437 BT_ASSERT_PRE_NON_NULL(method, "Method");
438 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
439 comp_cls->methods.input_port_connected = method;
440 BT_LIB_LOGV("Set sink component class's \"input port connected\" method"
441 ": %!+C", comp_cls);
442 return 0;
443}
a3aacb6f 444
0d72b8c3
PP
445int bt_component_class_source_set_output_port_connected_method(
446 struct bt_component_class_source *comp_cls,
447 bt_component_class_source_output_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.output_port_connected = method;
453 BT_LIB_LOGV("Set source component class's \"output port connected\" method"
454 ": %!+C", comp_cls);
455 return 0;
456}
d3eb6e8f 457
0d72b8c3
PP
458int bt_component_class_filter_set_output_port_connected_method(
459 struct bt_component_class_filter *comp_cls,
460 bt_component_class_filter_output_port_connected_method method)
d94d92ac 461{
d94d92ac
PP
462 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
463 BT_ASSERT_PRE_NON_NULL(method, "Method");
464 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
465 comp_cls->methods.output_port_connected = method;
466 BT_LIB_LOGV("Set filter component class's \"output port connected\" method"
467 ": %!+C", comp_cls);
468 return 0;
469}
d3eb6e8f 470
0d72b8c3
PP
471int bt_component_class_filter_set_input_port_disconnected_method(
472 struct bt_component_class_filter *comp_cls,
473 bt_component_class_filter_input_port_disconnected_method method)
d94d92ac 474{
d94d92ac
PP
475 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
476 BT_ASSERT_PRE_NON_NULL(method, "Method");
477 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
478 comp_cls->methods.input_port_disconnected = method;
479 BT_LIB_LOGV("Set filter component class's \"input port disconnected\" method"
480 ": %!+C", comp_cls);
481 return 0;
d3eb6e8f
PP
482}
483
0d72b8c3
PP
484int bt_component_class_sink_set_input_port_disconnected_method(
485 struct bt_component_class_sink *comp_cls,
486 bt_component_class_sink_input_port_disconnected_method method)
d3eb6e8f 487{
d94d92ac
PP
488 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
489 BT_ASSERT_PRE_NON_NULL(method, "Method");
490 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
491 comp_cls->methods.input_port_disconnected = method;
492 BT_LIB_LOGV("Set sink component class's \"input port disconnected\" method"
493 ": %!+C", comp_cls);
494 return 0;
495}
d3eb6e8f 496
0d72b8c3
PP
497int bt_component_class_source_set_output_port_disconnected_method(
498 struct bt_component_class_source *comp_cls,
499 bt_component_class_source_output_port_disconnected_method method)
d94d92ac 500{
d94d92ac
PP
501 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
502 BT_ASSERT_PRE_NON_NULL(method, "Method");
503 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
504 comp_cls->methods.output_port_disconnected = method;
505 BT_LIB_LOGV("Set source component class's \"output port disconnected\" method"
506 ": %!+C", comp_cls);
507 return 0;
508}
a3aacb6f 509
0d72b8c3
PP
510int bt_component_class_filter_set_output_port_disconnected_method(
511 struct bt_component_class_filter *comp_cls,
512 bt_component_class_filter_output_port_disconnected_method method)
d94d92ac 513{
d94d92ac
PP
514 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
515 BT_ASSERT_PRE_NON_NULL(method, "Method");
516 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
517 comp_cls->methods.output_port_disconnected = method;
518 BT_LIB_LOGV("Set filter component class's \"output port disconnected\" method"
519 ": %!+C", comp_cls);
520 return 0;
521}
a3aacb6f 522
0d72b8c3
PP
523int bt_component_class_source_set_notification_iterator_init_method(
524 struct bt_component_class_source *comp_cls,
525 bt_component_class_source_notification_iterator_init_method method)
d94d92ac 526{
d94d92ac
PP
527 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
528 BT_ASSERT_PRE_NON_NULL(method, "Method");
529 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
530 comp_cls->methods.notif_iter_init = method;
531 BT_LIB_LOGV("Set source component class's notification iterator initialization method"
532 ": %!+C", comp_cls);
533 return 0;
534}
a3aacb6f 535
0d72b8c3
PP
536int bt_component_class_filter_set_notification_iterator_init_method(
537 struct bt_component_class_filter *comp_cls,
538 bt_component_class_filter_notification_iterator_init_method method)
d94d92ac 539{
d94d92ac
PP
540 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
541 BT_ASSERT_PRE_NON_NULL(method, "Method");
542 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
543 comp_cls->methods.notif_iter_init = method;
544 BT_LIB_LOGV("Set filter component class's notification iterator initialization method"
545 ": %!+C", comp_cls);
546 return 0;
547}
d3eb6e8f 548
0d72b8c3
PP
549int bt_component_class_source_set_notification_iterator_finalize_method(
550 struct bt_component_class_source *comp_cls,
551 bt_component_class_source_notification_iterator_finalize_method method)
d94d92ac 552{
d94d92ac
PP
553 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
554 BT_ASSERT_PRE_NON_NULL(method, "Method");
555 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
556 comp_cls->methods.notif_iter_finalize = method;
557 BT_LIB_LOGV("Set source component class's notification iterator finalization method"
558 ": %!+C", comp_cls);
559 return 0;
560}
d3eb6e8f 561
0d72b8c3
PP
562int bt_component_class_filter_set_notification_iterator_finalize_method(
563 struct bt_component_class_filter *comp_cls,
564 bt_component_class_filter_notification_iterator_finalize_method method)
d94d92ac 565{
d94d92ac
PP
566 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
567 BT_ASSERT_PRE_NON_NULL(method, "Method");
568 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
569 comp_cls->methods.notif_iter_finalize = method;
570 BT_LIB_LOGV("Set filter component class's notification iterator finalization method"
571 ": %!+C", comp_cls);
572 return 0;
d3eb6e8f
PP
573}
574
0d72b8c3
PP
575int bt_component_class_set_description(
576 struct bt_component_class *comp_cls,
d3e4dcd8
PP
577 const char *description)
578{
d94d92ac
PP
579 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
580 BT_ASSERT_PRE_NON_NULL(description, "Description");
581 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
582 g_string_assign(comp_cls->description, description);
583 BT_LIB_LOGV("Set component class's description: "
a3aacb6f 584 "addr=%p, name=\"%s\", type=%s",
d94d92ac
PP
585 comp_cls,
586 bt_component_class_get_name(comp_cls),
587 bt_component_class_type_string(comp_cls->type));
588 return 0;
fb2dcc52 589}
38b48196 590
0d72b8c3
PP
591int bt_component_class_set_help(
592 struct bt_component_class *comp_cls,
5536d9a6
PP
593 const char *help)
594{
d94d92ac
PP
595 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
596 BT_ASSERT_PRE_NON_NULL(help, "Help");
597 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
598 g_string_assign(comp_cls->help, help);
599 BT_LIB_LOGV("Set component class's help text: %!+C", comp_cls);
600 return 0;
5536d9a6
PP
601}
602
0d72b8c3 603const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
38b48196 604{
d94d92ac
PP
605 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
606 return comp_cls->name->str;
38b48196
JG
607}
608
d3e4dcd8 609enum bt_component_class_type bt_component_class_get_type(
0d72b8c3 610 const struct bt_component_class *comp_cls)
38b48196 611{
d94d92ac
PP
612 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
613 return comp_cls->type;
38b48196
JG
614}
615
33b34c43 616const char *bt_component_class_get_description(
0d72b8c3 617 const struct bt_component_class *comp_cls)
38b48196 618{
d94d92ac
PP
619 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
620 return comp_cls->description &&
621 comp_cls->description->str[0] != '\0' ?
622 comp_cls->description->str : NULL;
38b48196 623}
7c7c0433 624
5536d9a6 625const char *bt_component_class_get_help(
0d72b8c3 626 const struct bt_component_class *comp_cls)
5536d9a6 627{
d94d92ac
PP
628 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
629 return comp_cls->help &&
630 comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL;
5536d9a6
PP
631}
632
33b34c43 633BT_HIDDEN
d94d92ac
PP
634void bt_component_class_add_destroy_listener(
635 struct bt_component_class *comp_cls,
33b34c43 636 bt_component_class_destroy_listener_func func, void *data)
7c7c0433 637{
d3e4dcd8 638 struct bt_component_class_destroy_listener listener;
33b34c43 639
d94d92ac 640 BT_ASSERT(comp_cls);
f6ccaed9 641 BT_ASSERT(func);
33b34c43
PP
642 listener.func = func;
643 listener.data = data;
d94d92ac
PP
644 g_array_append_val(comp_cls->destroy_listeners, listener);
645 BT_LIB_LOGV("Added destroy listener to component class: "
646 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
7c7c0433 647}
d3e4dcd8 648
d94d92ac 649BT_HIDDEN
0d72b8c3 650void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
1e4d8103 651{
d94d92ac
PP
652 BT_ASSERT(comp_cls);
653 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
0d72b8c3 654 ((struct bt_component_class *) comp_cls)->frozen = true;
1e4d8103 655}
This page took 0.070068 seconds and 4 git commands to generate.