Logging: standardize logging tags
[babeltrace.git] / src / 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
350ad6c1 24#define BT_LOG_TAG "LIB/COMPONENT-CLASS"
578e048b 25#include "lib/lib-logging.h"
a3aacb6f 26
578e048b
MJ
27#include "common/assert.h"
28#include "lib/assert-pre.h"
29#include "compat/compiler.h"
3fadfbc0
MJ
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>
3fadfbc0 38#include <babeltrace2/types.h>
fb2dcc52
JG
39#include <glib.h>
40
578e048b
MJ
41#include "component-class.h"
42
d94d92ac 43#define BT_ASSERT_PRE_COMP_CLS_HOT(_cc) \
0d72b8c3 44 BT_ASSERT_PRE_HOT(((const struct bt_component_class *) (_cc)), \
d94d92ac
PP
45 "Component class", ": %!+C", (_cc))
46
fb2dcc52 47static
d94d92ac 48void destroy_component_class(struct bt_object *obj)
fb2dcc52
JG
49{
50 struct bt_component_class *class;
33b34c43 51 int i;
fb2dcc52 52
f6ccaed9 53 BT_ASSERT(obj);
b8a06801 54 class = container_of(obj, struct bt_component_class, base);
33b34c43 55
3f7d4d90 56 BT_LIB_LOGI("Destroying component class: %!+C", class);
a3aacb6f 57
33b34c43
PP
58 /* Call destroy listeners in reverse registration order */
59 for (i = class->destroy_listeners->len - 1; i >= 0; i--) {
d3e4dcd8 60 struct bt_component_class_destroy_listener *listener =
33b34c43 61 &g_array_index(class->destroy_listeners,
d3e4dcd8 62 struct bt_component_class_destroy_listener,
33b34c43
PP
63 i);
64
a3aacb6f
PP
65 BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p",
66 listener->func, listener->data);
33b34c43
PP
67 listener->func(class, listener->data);
68 }
69
fb2dcc52
JG
70 if (class->name) {
71 g_string_free(class->name, TRUE);
d94d92ac 72 class->name = NULL;
fb2dcc52 73 }
d94d92ac 74
7c7c0433
JG
75 if (class->description) {
76 g_string_free(class->description, TRUE);
d94d92ac 77 class->description = NULL;
7c7c0433 78 }
d94d92ac 79
5536d9a6
PP
80 if (class->help) {
81 g_string_free(class->help, TRUE);
d94d92ac 82 class->help = NULL;
5536d9a6 83 }
d94d92ac 84
33b34c43
PP
85 if (class->destroy_listeners) {
86 g_array_free(class->destroy_listeners, TRUE);
d94d92ac 87 class->destroy_listeners = NULL;
33b34c43 88 }
b8a06801 89
fb2dcc52
JG
90 g_free(class);
91}
92
d3e4dcd8
PP
93static
94int bt_component_class_init(struct bt_component_class *class,
95 enum bt_component_class_type type, const char *name)
fb2dcc52 96{
d3e4dcd8
PP
97 int ret = 0;
98
d94d92ac 99 bt_object_init_shared(&class->base, destroy_component_class);
d3e4dcd8
PP
100 class->type = type;
101 class->name = g_string_new(name);
102 if (!class->name) {
a3aacb6f 103 BT_LOGE_STR("Failed to allocate a GString.");
d3e4dcd8
PP
104 goto error;
105 }
106
107 class->description = g_string_new(NULL);
108 if (!class->description) {
a3aacb6f 109 BT_LOGE_STR("Failed to allocate a GString.");
d3e4dcd8
PP
110 goto error;
111 }
112
5536d9a6
PP
113 class->help = g_string_new(NULL);
114 if (!class->help) {
a3aacb6f 115 BT_LOGE_STR("Failed to allocate a GString.");
5536d9a6
PP
116 goto error;
117 }
118
d3e4dcd8
PP
119 class->destroy_listeners = g_array_new(FALSE, TRUE,
120 sizeof(struct bt_component_class_destroy_listener));
121 if (!class->destroy_listeners) {
a3aacb6f 122 BT_LOGE_STR("Failed to allocate a GArray.");
d3e4dcd8
PP
123 goto error;
124 }
125
126 goto end;
6ba0b073 127
d3e4dcd8 128error:
65300d60 129 BT_OBJECT_PUT_REF_AND_RESET(class);
d3e4dcd8
PP
130 ret = -1;
131
132end:
133 return ret;
134}
135
0d72b8c3 136struct bt_component_class_source *bt_component_class_source_create(
d94d92ac 137 const char *name,
d6e69534 138 bt_component_class_source_message_iterator_next_method method)
d3e4dcd8
PP
139{
140 struct bt_component_class_source *source_class = NULL;
141 int ret;
142
d94d92ac 143 BT_ASSERT_PRE_NON_NULL(name, "Name");
d6e69534 144 BT_ASSERT_PRE_NON_NULL(method, "Message iterator next method");
3f7d4d90 145 BT_LOGI("Creating source component class: "
d6e69534 146 "name=\"%s\", msg-iter-next-method-addr=%p",
90157d89 147 name, method);
d3e4dcd8
PP
148 source_class = g_new0(struct bt_component_class_source, 1);
149 if (!source_class) {
a3aacb6f 150 BT_LOGE_STR("Failed to allocate one source component class.");
fb2dcc52
JG
151 goto end;
152 }
153
a3aacb6f 154 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
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
d6e69534 167 source_class->methods.msg_iter_next = method;
3f7d4d90 168 BT_LIB_LOGI("Created source component class: %!+C", source_class);
d3e4dcd8
PP
169
170end:
d94d92ac 171 return (void *) source_class;
d3e4dcd8
PP
172}
173
0d72b8c3
PP
174struct bt_component_class_filter *bt_component_class_filter_create(
175 const char *name,
d6e69534 176 bt_component_class_filter_message_iterator_next_method method)
d3e4dcd8
PP
177{
178 struct bt_component_class_filter *filter_class = NULL;
179 int ret;
180
d94d92ac 181 BT_ASSERT_PRE_NON_NULL(name, "Name");
d6e69534 182 BT_ASSERT_PRE_NON_NULL(method, "Message iterator next method");
3f7d4d90 183 BT_LOGI("Creating filter component class: "
d6e69534 184 "name=\"%s\", msg-iter-next-method-addr=%p",
90157d89 185 name, method);
d3e4dcd8
PP
186 filter_class = g_new0(struct bt_component_class_filter, 1);
187 if (!filter_class) {
a3aacb6f 188 BT_LOGE_STR("Failed to allocate one filter component class.");
d3e4dcd8 189 goto end;
6ba0b073
PP
190 }
191
a3aacb6f 192 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
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;
33b34c43
PP
202 goto end;
203 }
d3e4dcd8 204
d6e69534 205 filter_class->methods.msg_iter_next = method;
3f7d4d90 206 BT_LIB_LOGI("Created filter component class: %!+C", filter_class);
d3e4dcd8 207
fb2dcc52 208end:
d94d92ac 209 return (void *) filter_class;
d3e4dcd8
PP
210}
211
0d72b8c3
PP
212struct bt_component_class_sink *bt_component_class_sink_create(
213 const char *name, bt_component_class_sink_consume_method method)
d3e4dcd8
PP
214{
215 struct bt_component_class_sink *sink_class = NULL;
216 int ret;
217
d94d92ac
PP
218 BT_ASSERT_PRE_NON_NULL(name, "Name");
219 BT_ASSERT_PRE_NON_NULL(method, "Consume next method");
3f7d4d90 220 BT_LOGI("Creating sink component class: "
a3aacb6f 221 "name=\"%s\", consume-method-addr=%p",
90157d89 222 name, method);
d3e4dcd8
PP
223 sink_class = g_new0(struct bt_component_class_sink, 1);
224 if (!sink_class) {
a3aacb6f 225 BT_LOGE_STR("Failed to allocate one sink component class.");
d3e4dcd8
PP
226 goto end;
227 }
228
a3aacb6f 229 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
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
90157d89 242 sink_class->methods.consume = method;
3f7d4d90 243 BT_LIB_LOGI("Created sink component class: %!+C", sink_class);
d3e4dcd8
PP
244
245end:
d94d92ac 246 return (void *) sink_class;
d3e4dcd8
PP
247}
248
5badd463 249enum bt_component_class_status
7474e7d3 250bt_component_class_source_set_init_method(
0d72b8c3
PP
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;
3f7d4d90 258 BT_LIB_LOGD("Set source component class's initialization method: "
d94d92ac 259 "%!+C", comp_cls);
d0cf29ee 260 return BT_COMPONENT_CLASS_STATUS_OK;
d3e4dcd8
PP
261}
262
5badd463 263enum bt_component_class_status
7474e7d3 264bt_component_class_filter_set_init_method(
0d72b8c3
PP
265 struct bt_component_class_filter *comp_cls,
266 bt_component_class_filter_init_method method)
efa96d5d 267{
d94d92ac
PP
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;
3f7d4d90 272 BT_LIB_LOGD("Set filter component class's initialization method: "
d94d92ac 273 "%!+C", comp_cls);
d0cf29ee 274 return BT_COMPONENT_CLASS_STATUS_OK;
efa96d5d
PP
275}
276
5badd463 277enum bt_component_class_status
7474e7d3 278bt_component_class_sink_set_init_method(
0d72b8c3
PP
279 struct bt_component_class_sink *comp_cls,
280 bt_component_class_sink_init_method method)
2d41b99e 281{
d94d92ac
PP
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;
3f7d4d90 286 BT_LIB_LOGD("Set sink component class's initialization method: "
d94d92ac 287 "%!+C", comp_cls);
d0cf29ee 288 return BT_COMPONENT_CLASS_STATUS_OK;
72b913fb
PP
289}
290
5badd463 291enum bt_component_class_status
7474e7d3 292bt_component_class_source_set_finalize_method(
0d72b8c3
PP
293 struct bt_component_class_source *comp_cls,
294 bt_component_class_source_finalize_method method)
0d8b4d8e 295{
d94d92ac
PP
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;
3f7d4d90 300 BT_LIB_LOGD("Set source component class's finalization method: "
d94d92ac 301 "%!+C", comp_cls);
d0cf29ee 302 return BT_COMPONENT_CLASS_STATUS_OK;
0d8b4d8e
PP
303}
304
5badd463 305enum bt_component_class_status
7474e7d3 306bt_component_class_filter_set_finalize_method(
0d72b8c3
PP
307 struct bt_component_class_filter *comp_cls,
308 bt_component_class_filter_finalize_method method)
72b913fb 309{
d94d92ac
PP
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;
3f7d4d90 314 BT_LIB_LOGD("Set filter component class's finalization method: "
d94d92ac 315 "%!+C", comp_cls);
d0cf29ee 316 return BT_COMPONENT_CLASS_STATUS_OK;
2d41b99e
JG
317}
318
5badd463 319enum bt_component_class_status
7474e7d3 320bt_component_class_sink_set_finalize_method(
0d72b8c3
PP
321 struct bt_component_class_sink *comp_cls,
322 bt_component_class_sink_finalize_method method)
d3e4dcd8 323{
d94d92ac
PP
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;
3f7d4d90 328 BT_LIB_LOGD("Set sink component class's finalization method: "
d94d92ac 329 "%!+C", comp_cls);
d0cf29ee 330 return BT_COMPONENT_CLASS_STATUS_OK;
d3e4dcd8
PP
331}
332
5badd463 333enum bt_component_class_status
7474e7d3 334bt_component_class_source_set_query_method(
0d72b8c3
PP
335 struct bt_component_class_source *comp_cls,
336 bt_component_class_source_query_method method)
d3eb6e8f 337{
d94d92ac
PP
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;
3f7d4d90 342 BT_LIB_LOGD("Set source component class's query method: "
d94d92ac 343 "%!+C", comp_cls);
d0cf29ee 344 return BT_COMPONENT_CLASS_STATUS_OK;
d3eb6e8f
PP
345}
346
5badd463 347enum bt_component_class_status
7474e7d3 348bt_component_class_filter_set_query_method(
0d72b8c3
PP
349 struct bt_component_class_filter *comp_cls,
350 bt_component_class_filter_query_method method)
d3eb6e8f 351{
d94d92ac
PP
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;
3f7d4d90 356 BT_LIB_LOGD("Set filter component class's query method: "
d94d92ac 357 "%!+C", comp_cls);
d0cf29ee 358 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 359}
a3aacb6f 360
5badd463 361enum bt_component_class_status
7474e7d3 362bt_component_class_sink_set_query_method(
0d72b8c3
PP
363 struct bt_component_class_sink *comp_cls,
364 bt_component_class_sink_query_method method)
d94d92ac 365{
d94d92ac
PP
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;
3f7d4d90 370 BT_LIB_LOGD("Set sink component class's query method: "
d94d92ac 371 "%!+C", comp_cls);
d0cf29ee 372 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 373}
d3eb6e8f 374
5badd463 375enum bt_component_class_status
7474e7d3 376bt_component_class_filter_set_accept_input_port_connection_method(
0d72b8c3
PP
377 struct bt_component_class_filter *comp_cls,
378 bt_component_class_filter_accept_input_port_connection_method method)
d94d92ac 379{
d94d92ac
PP
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;
3f7d4d90 384 BT_LIB_LOGD("Set filter component class's \"accept input port connection\" method"
d94d92ac 385 ": %!+C", comp_cls);
d0cf29ee 386 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 387}
d3eb6e8f 388
5badd463 389enum bt_component_class_status
7474e7d3 390bt_component_class_sink_set_accept_input_port_connection_method(
0d72b8c3
PP
391 struct bt_component_class_sink *comp_cls,
392 bt_component_class_sink_accept_input_port_connection_method method)
d94d92ac 393{
d94d92ac
PP
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;
3f7d4d90 398 BT_LIB_LOGD("Set sink component class's \"accept input port connection\" method"
d94d92ac 399 ": %!+C", comp_cls);
d0cf29ee 400 return BT_COMPONENT_CLASS_STATUS_OK;
d3eb6e8f
PP
401}
402
5badd463 403enum bt_component_class_status
7474e7d3 404bt_component_class_source_set_accept_output_port_connection_method(
0d72b8c3
PP
405 struct bt_component_class_source *comp_cls,
406 bt_component_class_source_accept_output_port_connection_method method)
d3eb6e8f 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;
3f7d4d90 412 BT_LIB_LOGD("Set source component class's \"accept output port connection\" method"
d94d92ac 413 ": %!+C", comp_cls);
d0cf29ee 414 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 415}
d3eb6e8f 416
5badd463 417enum bt_component_class_status
7474e7d3 418bt_component_class_filter_set_accept_output_port_connection_method(
0d72b8c3
PP
419 struct bt_component_class_filter *comp_cls,
420 bt_component_class_filter_accept_output_port_connection_method method)
d94d92ac 421{
d94d92ac
PP
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;
3f7d4d90 426 BT_LIB_LOGD("Set filter component class's \"accept output port connection\" method"
d94d92ac 427 ": %!+C", comp_cls);
d0cf29ee 428 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 429}
a3aacb6f 430
5badd463 431enum bt_component_class_status
7474e7d3 432bt_component_class_filter_set_input_port_connected_method(
0d72b8c3
PP
433 struct bt_component_class_filter *comp_cls,
434 bt_component_class_filter_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;
3f7d4d90 440 BT_LIB_LOGD("Set filter component class's \"input port connected\" method"
d94d92ac 441 ": %!+C", comp_cls);
d0cf29ee 442 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 443}
a3aacb6f 444
5badd463 445enum bt_component_class_status
7474e7d3 446bt_component_class_sink_set_input_port_connected_method(
0d72b8c3
PP
447 struct bt_component_class_sink *comp_cls,
448 bt_component_class_sink_input_port_connected_method method)
d94d92ac 449{
d94d92ac
PP
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;
3f7d4d90 454 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
d94d92ac 455 ": %!+C", comp_cls);
d0cf29ee 456 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 457}
a3aacb6f 458
5badd463 459enum bt_component_class_status
7474e7d3 460bt_component_class_source_set_output_port_connected_method(
0d72b8c3
PP
461 struct bt_component_class_source *comp_cls,
462 bt_component_class_source_output_port_connected_method method)
d94d92ac 463{
d94d92ac
PP
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;
3f7d4d90 468 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
d94d92ac 469 ": %!+C", comp_cls);
d0cf29ee 470 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 471}
d3eb6e8f 472
5badd463 473enum bt_component_class_status
7474e7d3 474bt_component_class_filter_set_output_port_connected_method(
0d72b8c3
PP
475 struct bt_component_class_filter *comp_cls,
476 bt_component_class_filter_output_port_connected_method method)
d94d92ac 477{
d94d92ac
PP
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;
3f7d4d90 482 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
d94d92ac 483 ": %!+C", comp_cls);
d0cf29ee 484 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 485}
d3eb6e8f 486
5badd463
PP
487enum bt_component_class_status
488bt_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;
3f7d4d90 496 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
5badd463
PP
497 ": %!+C", comp_cls);
498 return BT_COMPONENT_CLASS_STATUS_OK;
499}
500
d6e69534 501int bt_component_class_source_set_message_iterator_init_method(
0d72b8c3 502 struct bt_component_class_source *comp_cls,
d6e69534 503 bt_component_class_source_message_iterator_init_method method)
d94d92ac 504{
d94d92ac
PP
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);
d6e69534 508 comp_cls->methods.msg_iter_init = method;
3f7d4d90 509 BT_LIB_LOGD("Set source component class's message iterator initialization method"
d94d92ac 510 ": %!+C", comp_cls);
d0cf29ee 511 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 512}
a3aacb6f 513
5badd463 514enum bt_component_class_status
7474e7d3 515bt_component_class_filter_set_message_iterator_init_method(
0d72b8c3 516 struct bt_component_class_filter *comp_cls,
d6e69534 517 bt_component_class_filter_message_iterator_init_method method)
d94d92ac 518{
d94d92ac
PP
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);
d6e69534 522 comp_cls->methods.msg_iter_init = method;
3f7d4d90 523 BT_LIB_LOGD("Set filter component class's message iterator initialization method"
d94d92ac 524 ": %!+C", comp_cls);
d0cf29ee 525 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 526}
d3eb6e8f 527
5badd463 528enum bt_component_class_status
7474e7d3 529bt_component_class_source_set_message_iterator_finalize_method(
0d72b8c3 530 struct bt_component_class_source *comp_cls,
d6e69534 531 bt_component_class_source_message_iterator_finalize_method method)
d94d92ac 532{
d94d92ac
PP
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);
d6e69534 536 comp_cls->methods.msg_iter_finalize = method;
3f7d4d90 537 BT_LIB_LOGD("Set source component class's message iterator finalization method"
d94d92ac 538 ": %!+C", comp_cls);
d0cf29ee 539 return BT_COMPONENT_CLASS_STATUS_OK;
d94d92ac 540}
d3eb6e8f 541
5badd463 542enum bt_component_class_status
7474e7d3 543bt_component_class_filter_set_message_iterator_finalize_method(
0d72b8c3 544 struct bt_component_class_filter *comp_cls,
d6e69534 545 bt_component_class_filter_message_iterator_finalize_method method)
d94d92ac 546{
d94d92ac
PP
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);
d6e69534 550 comp_cls->methods.msg_iter_finalize = method;
3f7d4d90 551 BT_LIB_LOGD("Set filter component class's message iterator finalization method"
d94d92ac 552 ": %!+C", comp_cls);
d0cf29ee 553 return BT_COMPONENT_CLASS_STATUS_OK;
d3eb6e8f
PP
554}
555
7474e7d3
PP
556enum bt_component_class_status
557bt_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;
3f7d4d90 565 BT_LIB_LOGD("Set filter component class's message iterator \"seek nanoseconds from origin\" method"
7474e7d3
PP
566 ": %!+C", comp_cls);
567 return BT_COMPONENT_CLASS_STATUS_OK;
568}
569
570enum bt_component_class_status
571bt_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;
3f7d4d90 579 BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" method"
7474e7d3
PP
580 ": %!+C", comp_cls);
581 return BT_COMPONENT_CLASS_STATUS_OK;
582}
583
584enum bt_component_class_status
585bt_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;
3f7d4d90 593 BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" method"
7474e7d3
PP
594 ": %!+C", comp_cls);
595 return BT_COMPONENT_CLASS_STATUS_OK;
596}
597
598enum bt_component_class_status
599bt_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;
3f7d4d90 607 BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" method"
7474e7d3
PP
608 ": %!+C", comp_cls);
609 return BT_COMPONENT_CLASS_STATUS_OK;
610}
611
612enum bt_component_class_status
613bt_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;
3f7d4d90 621 BT_LIB_LOGD("Set filter component class's message iterator \"can seek beginning\" method"
7474e7d3
PP
622 ": %!+C", comp_cls);
623 return BT_COMPONENT_CLASS_STATUS_OK;
624}
625
626enum bt_component_class_status
627bt_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;
3f7d4d90 635 BT_LIB_LOGD("Set source component class's message iterator \"can seek beginning\" method"
7474e7d3
PP
636 ": %!+C", comp_cls);
637 return BT_COMPONENT_CLASS_STATUS_OK;
638}
639
640enum bt_component_class_status
641bt_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;
3f7d4d90 649 BT_LIB_LOGD("Set filter component class's message iterator \"can seek nanoseconds from origin\" method"
7474e7d3
PP
650 ": %!+C", comp_cls);
651 return BT_COMPONENT_CLASS_STATUS_OK;
652}
653
654enum bt_component_class_status
655bt_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;
3f7d4d90 663 BT_LIB_LOGD("Set source component class's message iterator \"can seek nanoseconds from origin\" method"
7474e7d3
PP
664 ": %!+C", comp_cls);
665 return BT_COMPONENT_CLASS_STATUS_OK;
666}
667
d0cf29ee 668bt_component_class_status bt_component_class_set_description(
0d72b8c3 669 struct bt_component_class *comp_cls,
d3e4dcd8
PP
670 const char *description)
671{
d94d92ac
PP
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);
3f7d4d90 676 BT_LIB_LOGD("Set component class's description: "
a3aacb6f 677 "addr=%p, name=\"%s\", type=%s",
d94d92ac
PP
678 comp_cls,
679 bt_component_class_get_name(comp_cls),
680 bt_component_class_type_string(comp_cls->type));
d0cf29ee 681 return BT_COMPONENT_CLASS_STATUS_OK;
fb2dcc52 682}
38b48196 683
d0cf29ee 684bt_component_class_status bt_component_class_set_help(
0d72b8c3 685 struct bt_component_class *comp_cls,
5536d9a6
PP
686 const char *help)
687{
d94d92ac
PP
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);
3f7d4d90 692 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls);
d0cf29ee 693 return BT_COMPONENT_CLASS_STATUS_OK;
5536d9a6
PP
694}
695
0d72b8c3 696const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
38b48196 697{
d94d92ac
PP
698 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
699 return comp_cls->name->str;
38b48196
JG
700}
701
d3e4dcd8 702enum bt_component_class_type bt_component_class_get_type(
0d72b8c3 703 const struct bt_component_class *comp_cls)
38b48196 704{
d94d92ac
PP
705 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
706 return comp_cls->type;
38b48196
JG
707}
708
33b34c43 709const char *bt_component_class_get_description(
0d72b8c3 710 const struct bt_component_class *comp_cls)
38b48196 711{
d94d92ac
PP
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;
38b48196 716}
7c7c0433 717
5536d9a6 718const char *bt_component_class_get_help(
0d72b8c3 719 const struct bt_component_class *comp_cls)
5536d9a6 720{
d94d92ac
PP
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;
5536d9a6
PP
724}
725
33b34c43 726BT_HIDDEN
d94d92ac
PP
727void bt_component_class_add_destroy_listener(
728 struct bt_component_class *comp_cls,
33b34c43 729 bt_component_class_destroy_listener_func func, void *data)
7c7c0433 730{
d3e4dcd8 731 struct bt_component_class_destroy_listener listener;
33b34c43 732
d94d92ac 733 BT_ASSERT(comp_cls);
f6ccaed9 734 BT_ASSERT(func);
33b34c43
PP
735 listener.func = func;
736 listener.data = data;
d94d92ac 737 g_array_append_val(comp_cls->destroy_listeners, listener);
3f7d4d90 738 BT_LIB_LOGD("Added destroy listener to component class: "
d94d92ac 739 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
7c7c0433 740}
d3e4dcd8 741
d94d92ac 742BT_HIDDEN
0d72b8c3 743void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
1e4d8103 744{
d94d92ac
PP
745 BT_ASSERT(comp_cls);
746 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
0d72b8c3 747 ((struct bt_component_class *) comp_cls)->frozen = true;
1e4d8103 748}
c5b9b441
PP
749
750void bt_component_class_get_ref(
751 const struct bt_component_class *component_class)
752{
753 bt_object_get_ref(component_class);
754}
755
756void bt_component_class_put_ref(
757 const struct bt_component_class *component_class)
758{
759 bt_object_put_ref(component_class);
760}
761
762void 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
768void 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
774void 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
780void 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
786void 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
792void 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.087131 seconds and 4 git commands to generate.