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