Logging: standardize logging tags
[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/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_accept_input_port_connection_method(
377 struct bt_component_class_filter *comp_cls,
378 bt_component_class_filter_accept_input_port_connection_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.accept_input_port_connection = method;
384 BT_LIB_LOGD("Set filter component class's \"accept input port connection\" 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_accept_input_port_connection_method(
391 struct bt_component_class_sink *comp_cls,
392 bt_component_class_sink_accept_input_port_connection_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.accept_input_port_connection = method;
398 BT_LIB_LOGD("Set sink component class's \"accept input port connection\" 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_accept_output_port_connection_method(
405 struct bt_component_class_source *comp_cls,
406 bt_component_class_source_accept_output_port_connection_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.accept_output_port_connection = method;
412 BT_LIB_LOGD("Set source component class's \"accept output port connection\" 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_accept_output_port_connection_method(
419 struct bt_component_class_filter *comp_cls,
420 bt_component_class_filter_accept_output_port_connection_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.accept_output_port_connection = method;
426 BT_LIB_LOGD("Set filter component class's \"accept output port connection\" method"
427 ": %!+C", comp_cls);
428 return BT_COMPONENT_CLASS_STATUS_OK;
429 }
430
431 enum bt_component_class_status
432 bt_component_class_filter_set_input_port_connected_method(
433 struct bt_component_class_filter *comp_cls,
434 bt_component_class_filter_input_port_connected_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.input_port_connected = method;
440 BT_LIB_LOGD("Set filter component class's \"input port connected\" method"
441 ": %!+C", comp_cls);
442 return BT_COMPONENT_CLASS_STATUS_OK;
443 }
444
445 enum bt_component_class_status
446 bt_component_class_sink_set_input_port_connected_method(
447 struct bt_component_class_sink *comp_cls,
448 bt_component_class_sink_input_port_connected_method method)
449 {
450 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
451 BT_ASSERT_PRE_NON_NULL(method, "Method");
452 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
453 comp_cls->methods.input_port_connected = method;
454 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
455 ": %!+C", comp_cls);
456 return BT_COMPONENT_CLASS_STATUS_OK;
457 }
458
459 enum bt_component_class_status
460 bt_component_class_source_set_output_port_connected_method(
461 struct bt_component_class_source *comp_cls,
462 bt_component_class_source_output_port_connected_method method)
463 {
464 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
465 BT_ASSERT_PRE_NON_NULL(method, "Method");
466 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
467 comp_cls->methods.output_port_connected = method;
468 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
469 ": %!+C", comp_cls);
470 return BT_COMPONENT_CLASS_STATUS_OK;
471 }
472
473 enum bt_component_class_status
474 bt_component_class_filter_set_output_port_connected_method(
475 struct bt_component_class_filter *comp_cls,
476 bt_component_class_filter_output_port_connected_method method)
477 {
478 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
479 BT_ASSERT_PRE_NON_NULL(method, "Method");
480 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
481 comp_cls->methods.output_port_connected = method;
482 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
483 ": %!+C", comp_cls);
484 return BT_COMPONENT_CLASS_STATUS_OK;
485 }
486
487 enum bt_component_class_status
488 bt_component_class_sink_set_graph_is_configured_method(
489 struct bt_component_class_sink *comp_cls,
490 bt_component_class_sink_graph_is_configured_method method)
491 {
492 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
493 BT_ASSERT_PRE_NON_NULL(method, "Method");
494 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
495 comp_cls->methods.graph_is_configured = method;
496 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
497 ": %!+C", comp_cls);
498 return BT_COMPONENT_CLASS_STATUS_OK;
499 }
500
501 int bt_component_class_source_set_message_iterator_init_method(
502 struct bt_component_class_source *comp_cls,
503 bt_component_class_source_message_iterator_init_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_init = method;
509 BT_LIB_LOGD("Set source component class's message iterator initialization method"
510 ": %!+C", comp_cls);
511 return BT_COMPONENT_CLASS_STATUS_OK;
512 }
513
514 enum bt_component_class_status
515 bt_component_class_filter_set_message_iterator_init_method(
516 struct bt_component_class_filter *comp_cls,
517 bt_component_class_filter_message_iterator_init_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_init = method;
523 BT_LIB_LOGD("Set filter component class's message iterator initialization method"
524 ": %!+C", comp_cls);
525 return BT_COMPONENT_CLASS_STATUS_OK;
526 }
527
528 enum bt_component_class_status
529 bt_component_class_source_set_message_iterator_finalize_method(
530 struct bt_component_class_source *comp_cls,
531 bt_component_class_source_message_iterator_finalize_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_finalize = method;
537 BT_LIB_LOGD("Set source component class's message iterator finalization method"
538 ": %!+C", comp_cls);
539 return BT_COMPONENT_CLASS_STATUS_OK;
540 }
541
542 enum bt_component_class_status
543 bt_component_class_filter_set_message_iterator_finalize_method(
544 struct bt_component_class_filter *comp_cls,
545 bt_component_class_filter_message_iterator_finalize_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_finalize = method;
551 BT_LIB_LOGD("Set filter component class's message iterator finalization 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_seek_ns_from_origin_method(
558 struct bt_component_class_filter *comp_cls,
559 bt_component_class_filter_message_iterator_seek_ns_from_origin_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_seek_ns_from_origin = method;
565 BT_LIB_LOGD("Set filter component class's message iterator \"seek nanoseconds from origin\" 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_seek_ns_from_origin_method(
572 struct bt_component_class_source *comp_cls,
573 bt_component_class_source_message_iterator_seek_ns_from_origin_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_seek_ns_from_origin = method;
579 BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" 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_seek_beginning_method(
586 struct bt_component_class_filter *comp_cls,
587 bt_component_class_filter_message_iterator_seek_beginning_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_seek_beginning = method;
593 BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" 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_seek_beginning_method(
600 struct bt_component_class_source *comp_cls,
601 bt_component_class_source_message_iterator_seek_beginning_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_seek_beginning = method;
607 BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" method"
608 ": %!+C", comp_cls);
609 return BT_COMPONENT_CLASS_STATUS_OK;
610 }
611
612 enum bt_component_class_status
613 bt_component_class_filter_set_message_iterator_can_seek_beginning_method(
614 struct bt_component_class_filter *comp_cls,
615 bt_component_class_filter_message_iterator_can_seek_beginning_method method)
616 {
617 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
618 BT_ASSERT_PRE_NON_NULL(method, "Method");
619 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
620 comp_cls->methods.msg_iter_can_seek_beginning = method;
621 BT_LIB_LOGD("Set filter component class's message iterator \"can seek beginning\" method"
622 ": %!+C", comp_cls);
623 return BT_COMPONENT_CLASS_STATUS_OK;
624 }
625
626 enum bt_component_class_status
627 bt_component_class_source_set_message_iterator_can_seek_beginning_method(
628 struct bt_component_class_source *comp_cls,
629 bt_component_class_source_message_iterator_can_seek_beginning_method method)
630 {
631 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
632 BT_ASSERT_PRE_NON_NULL(method, "Method");
633 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
634 comp_cls->methods.msg_iter_can_seek_beginning = method;
635 BT_LIB_LOGD("Set source component class's message iterator \"can seek beginning\" method"
636 ": %!+C", comp_cls);
637 return BT_COMPONENT_CLASS_STATUS_OK;
638 }
639
640 enum bt_component_class_status
641 bt_component_class_filter_set_message_iterator_can_seek_ns_from_origin_method(
642 struct bt_component_class_filter *comp_cls,
643 bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method method)
644 {
645 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
646 BT_ASSERT_PRE_NON_NULL(method, "Method");
647 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
648 comp_cls->methods.msg_iter_can_seek_ns_from_origin = method;
649 BT_LIB_LOGD("Set filter component class's message iterator \"can seek nanoseconds from origin\" method"
650 ": %!+C", comp_cls);
651 return BT_COMPONENT_CLASS_STATUS_OK;
652 }
653
654 enum bt_component_class_status
655 bt_component_class_source_set_message_iterator_can_seek_ns_from_origin_method(
656 struct bt_component_class_source *comp_cls,
657 bt_component_class_source_message_iterator_can_seek_ns_from_origin_method method)
658 {
659 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
660 BT_ASSERT_PRE_NON_NULL(method, "Method");
661 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
662 comp_cls->methods.msg_iter_can_seek_ns_from_origin = method;
663 BT_LIB_LOGD("Set source component class's message iterator \"can seek nanoseconds from origin\" method"
664 ": %!+C", comp_cls);
665 return BT_COMPONENT_CLASS_STATUS_OK;
666 }
667
668 bt_component_class_status bt_component_class_set_description(
669 struct bt_component_class *comp_cls,
670 const char *description)
671 {
672 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
673 BT_ASSERT_PRE_NON_NULL(description, "Description");
674 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
675 g_string_assign(comp_cls->description, description);
676 BT_LIB_LOGD("Set component class's description: "
677 "addr=%p, name=\"%s\", type=%s",
678 comp_cls,
679 bt_component_class_get_name(comp_cls),
680 bt_component_class_type_string(comp_cls->type));
681 return BT_COMPONENT_CLASS_STATUS_OK;
682 }
683
684 bt_component_class_status bt_component_class_set_help(
685 struct bt_component_class *comp_cls,
686 const char *help)
687 {
688 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
689 BT_ASSERT_PRE_NON_NULL(help, "Help");
690 BT_ASSERT_PRE_COMP_CLS_HOT(comp_cls);
691 g_string_assign(comp_cls->help, help);
692 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls);
693 return BT_COMPONENT_CLASS_STATUS_OK;
694 }
695
696 const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
697 {
698 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
699 return comp_cls->name->str;
700 }
701
702 enum bt_component_class_type bt_component_class_get_type(
703 const struct bt_component_class *comp_cls)
704 {
705 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
706 return comp_cls->type;
707 }
708
709 const char *bt_component_class_get_description(
710 const struct bt_component_class *comp_cls)
711 {
712 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
713 return comp_cls->description &&
714 comp_cls->description->str[0] != '\0' ?
715 comp_cls->description->str : NULL;
716 }
717
718 const char *bt_component_class_get_help(
719 const struct bt_component_class *comp_cls)
720 {
721 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
722 return comp_cls->help &&
723 comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL;
724 }
725
726 BT_HIDDEN
727 void bt_component_class_add_destroy_listener(
728 struct bt_component_class *comp_cls,
729 bt_component_class_destroy_listener_func func, void *data)
730 {
731 struct bt_component_class_destroy_listener listener;
732
733 BT_ASSERT(comp_cls);
734 BT_ASSERT(func);
735 listener.func = func;
736 listener.data = data;
737 g_array_append_val(comp_cls->destroy_listeners, listener);
738 BT_LIB_LOGD("Added destroy listener to component class: "
739 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
740 }
741
742 BT_HIDDEN
743 void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
744 {
745 BT_ASSERT(comp_cls);
746 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
747 ((struct bt_component_class *) comp_cls)->frozen = true;
748 }
749
750 void bt_component_class_get_ref(
751 const struct bt_component_class *component_class)
752 {
753 bt_object_get_ref(component_class);
754 }
755
756 void bt_component_class_put_ref(
757 const struct bt_component_class *component_class)
758 {
759 bt_object_put_ref(component_class);
760 }
761
762 void bt_component_class_source_get_ref(
763 const struct bt_component_class_source *component_class_source)
764 {
765 bt_object_get_ref(component_class_source);
766 }
767
768 void bt_component_class_source_put_ref(
769 const struct bt_component_class_source *component_class_source)
770 {
771 bt_object_put_ref(component_class_source);
772 }
773
774 void bt_component_class_filter_get_ref(
775 const struct bt_component_class_filter *component_class_filter)
776 {
777 bt_object_get_ref(component_class_filter);
778 }
779
780 void bt_component_class_filter_put_ref(
781 const struct bt_component_class_filter *component_class_filter)
782 {
783 bt_object_put_ref(component_class_filter);
784 }
785
786 void bt_component_class_sink_get_ref(
787 const struct bt_component_class_sink *component_class_sink)
788 {
789 bt_object_get_ref(component_class_sink);
790 }
791
792 void bt_component_class_sink_put_ref(
793 const struct bt_component_class_sink *component_class_sink)
794 {
795 bt_object_put_ref(component_class_sink);
796 }
This page took 0.045801 seconds and 4 git commands to generate.