lib: add pre condition asserts to check current thread has no error
[babeltrace.git] / src / lib / graph / component-class.c
CommitLineData
fb2dcc52 1/*
f2b0325d 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
b03487ab 24#define BT_LOG_TAG "LIB/COMPONENT-CLASS"
1633ef46 25#include "lib/logging.h"
a3aacb6f 26
57952005
MJ
27#include "common/assert.h"
28#include "lib/assert-pre.h"
29#include "compat/compiler.h"
71c5da58
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>
71c5da58 38#include <babeltrace2/types.h>
fb2dcc52
JG
39#include <glib.h>
40
57952005 41#include "component-class.h"
fb25b9e3 42#include "lib/func-status.h"
57952005 43
fa6cfec3
PP
44#define BT_ASSERT_PRE_DEV_COMP_CLS_HOT(_cc) \
45 BT_ASSERT_PRE_DEV_HOT(((const struct bt_component_class *) (_cc)), \
834e9996
PP
46 "Component class", ": %!+C", (_cc))
47
fb2dcc52 48static
834e9996 49void destroy_component_class(struct bt_object *obj)
fb2dcc52
JG
50{
51 struct bt_component_class *class;
33b34c43 52 int i;
fb2dcc52 53
8b45963b 54 BT_ASSERT(obj);
b8a06801 55 class = container_of(obj, struct bt_component_class, base);
33b34c43 56
a684a357 57 BT_LIB_LOGI("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);
834e9996 73 class->name = NULL;
fb2dcc52 74 }
834e9996 75
7c7c0433
JG
76 if (class->description) {
77 g_string_free(class->description, TRUE);
834e9996 78 class->description = NULL;
7c7c0433 79 }
834e9996 80
5536d9a6
PP
81 if (class->help) {
82 g_string_free(class->help, TRUE);
834e9996 83 class->help = NULL;
5536d9a6 84 }
834e9996 85
0c99efa4
PP
86 if (class->plugin_name) {
87 g_string_free(class->plugin_name, TRUE);
88 class->plugin_name = NULL;
89 }
90
33b34c43
PP
91 if (class->destroy_listeners) {
92 g_array_free(class->destroy_listeners, TRUE);
834e9996 93 class->destroy_listeners = NULL;
33b34c43 94 }
b8a06801 95
fb2dcc52
JG
96 g_free(class);
97}
98
d3e4dcd8
PP
99static
100int bt_component_class_init(struct bt_component_class *class,
101 enum bt_component_class_type type, const char *name)
fb2dcc52 102{
d3e4dcd8
PP
103 int ret = 0;
104
834e9996 105 bt_object_init_shared(&class->base, destroy_component_class);
d3e4dcd8
PP
106 class->type = type;
107 class->name = g_string_new(name);
108 if (!class->name) {
a8f90e5d 109 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
d3e4dcd8
PP
110 goto error;
111 }
112
113 class->description = g_string_new(NULL);
114 if (!class->description) {
a8f90e5d 115 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
d3e4dcd8
PP
116 goto error;
117 }
118
5536d9a6
PP
119 class->help = g_string_new(NULL);
120 if (!class->help) {
a8f90e5d 121 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
5536d9a6
PP
122 goto error;
123 }
124
0c99efa4
PP
125 class->plugin_name = g_string_new(NULL);
126 if (!class->plugin_name) {
a8f90e5d 127 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
0c99efa4
PP
128 goto error;
129 }
130
d3e4dcd8
PP
131 class->destroy_listeners = g_array_new(FALSE, TRUE,
132 sizeof(struct bt_component_class_destroy_listener));
133 if (!class->destroy_listeners) {
a8f90e5d 134 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray.");
d3e4dcd8
PP
135 goto error;
136 }
137
138 goto end;
6ba0b073 139
d3e4dcd8 140error:
8138bfe1 141 BT_OBJECT_PUT_REF_AND_RESET(class);
d3e4dcd8
PP
142 ret = -1;
143
144end:
145 return ret;
146}
147
7b53201c 148struct bt_component_class_source *bt_component_class_source_create(
834e9996 149 const char *name,
b09a5592 150 bt_component_class_source_message_iterator_next_method method)
d3e4dcd8
PP
151{
152 struct bt_component_class_source *source_class = NULL;
153 int ret;
154
7c7324d3 155 BT_ASSERT_PRE_NO_ERROR();
834e9996 156 BT_ASSERT_PRE_NON_NULL(name, "Name");
b09a5592 157 BT_ASSERT_PRE_NON_NULL(method, "Message iterator next method");
a684a357 158 BT_LOGI("Creating source component class: "
b09a5592 159 "name=\"%s\", msg-iter-next-method-addr=%p",
fe7265b5 160 name, method);
d3e4dcd8
PP
161 source_class = g_new0(struct bt_component_class_source, 1);
162 if (!source_class) {
a8f90e5d
PP
163 BT_LIB_LOGE_APPEND_CAUSE(
164 "Failed to allocate one source component class.");
fb2dcc52
JG
165 goto end;
166 }
167
a3aacb6f 168 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
169 ret = bt_component_class_init(&source_class->parent,
170 BT_COMPONENT_CLASS_TYPE_SOURCE, name);
171 if (ret) {
172 /*
173 * If bt_component_class_init() fails, the component
174 * class is put, therefore its memory is already
175 * freed.
176 */
177 source_class = NULL;
178 goto end;
179 }
180
b09a5592 181 source_class->methods.msg_iter_next = method;
a684a357 182 BT_LIB_LOGI("Created source component class: %!+C", source_class);
d3e4dcd8
PP
183
184end:
834e9996 185 return (void *) source_class;
d3e4dcd8
PP
186}
187
7b53201c
PP
188struct bt_component_class_filter *bt_component_class_filter_create(
189 const char *name,
b09a5592 190 bt_component_class_filter_message_iterator_next_method method)
d3e4dcd8
PP
191{
192 struct bt_component_class_filter *filter_class = NULL;
193 int ret;
194
7c7324d3 195 BT_ASSERT_PRE_NO_ERROR();
834e9996 196 BT_ASSERT_PRE_NON_NULL(name, "Name");
b09a5592 197 BT_ASSERT_PRE_NON_NULL(method, "Message iterator next method");
a684a357 198 BT_LOGI("Creating filter component class: "
b09a5592 199 "name=\"%s\", msg-iter-next-method-addr=%p",
fe7265b5 200 name, method);
d3e4dcd8
PP
201 filter_class = g_new0(struct bt_component_class_filter, 1);
202 if (!filter_class) {
a8f90e5d
PP
203 BT_LIB_LOGE_APPEND_CAUSE(
204 "Failed to allocate one filter component class.");
d3e4dcd8 205 goto end;
6ba0b073
PP
206 }
207
a3aacb6f 208 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
209 ret = bt_component_class_init(&filter_class->parent,
210 BT_COMPONENT_CLASS_TYPE_FILTER, name);
211 if (ret) {
212 /*
213 * If bt_component_class_init() fails, the component
214 * class is put, therefore its memory is already
215 * freed.
216 */
217 filter_class = NULL;
33b34c43
PP
218 goto end;
219 }
d3e4dcd8 220
b09a5592 221 filter_class->methods.msg_iter_next = method;
a684a357 222 BT_LIB_LOGI("Created filter component class: %!+C", filter_class);
d3e4dcd8 223
fb2dcc52 224end:
834e9996 225 return (void *) filter_class;
d3e4dcd8
PP
226}
227
7b53201c
PP
228struct bt_component_class_sink *bt_component_class_sink_create(
229 const char *name, bt_component_class_sink_consume_method method)
d3e4dcd8
PP
230{
231 struct bt_component_class_sink *sink_class = NULL;
232 int ret;
233
7c7324d3 234 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
235 BT_ASSERT_PRE_NON_NULL(name, "Name");
236 BT_ASSERT_PRE_NON_NULL(method, "Consume next method");
a684a357 237 BT_LOGI("Creating sink component class: "
a3aacb6f 238 "name=\"%s\", consume-method-addr=%p",
fe7265b5 239 name, method);
d3e4dcd8
PP
240 sink_class = g_new0(struct bt_component_class_sink, 1);
241 if (!sink_class) {
a8f90e5d
PP
242 BT_LIB_LOGE_APPEND_CAUSE(
243 "Failed to allocate one sink component class.");
d3e4dcd8
PP
244 goto end;
245 }
246
a3aacb6f 247 /* bt_component_class_init() logs errors */
d3e4dcd8
PP
248 ret = bt_component_class_init(&sink_class->parent,
249 BT_COMPONENT_CLASS_TYPE_SINK, name);
250 if (ret) {
251 /*
252 * If bt_component_class_init() fails, the component
253 * class is put, therefore its memory is already
254 * freed.
255 */
256 sink_class = NULL;
257 goto end;
258 }
259
fe7265b5 260 sink_class->methods.consume = method;
a684a357 261 BT_LIB_LOGI("Created sink component class: %!+C", sink_class);
d3e4dcd8
PP
262
263end:
834e9996 264 return (void *) sink_class;
d3e4dcd8
PP
265}
266
be788861
PP
267enum bt_component_class_set_method_status
268bt_component_class_source_set_get_supported_mip_versions_method(
269 struct bt_component_class_source *comp_cls,
270 bt_component_class_source_get_supported_mip_versions_method method)
271{
7c7324d3 272 BT_ASSERT_PRE_NO_ERROR();
be788861
PP
273 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
274 BT_ASSERT_PRE_NON_NULL(method, "Method");
275 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
276 comp_cls->methods.get_supported_mip_versions = method;
277 BT_LIB_LOGD("Set source component class's \"get supported MIP versions\" method: "
278 "%!+C", comp_cls);
279 return BT_FUNC_STATUS_OK;
280}
281
282enum bt_component_class_set_method_status
283bt_component_class_filter_set_get_supported_mip_versions_method(
284 struct bt_component_class_filter *comp_cls,
285 bt_component_class_filter_get_supported_mip_versions_method method)
286{
7c7324d3 287 BT_ASSERT_PRE_NO_ERROR();
be788861
PP
288 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
289 BT_ASSERT_PRE_NON_NULL(method, "Method");
290 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
291 comp_cls->methods.get_supported_mip_versions = method;
292 BT_LIB_LOGD("Set filter component class's \"get supported MIP versions\" method: "
293 "%!+C", comp_cls);
294 return BT_FUNC_STATUS_OK;
295}
296
297enum bt_component_class_set_method_status
298bt_component_class_sink_set_get_supported_mip_versions_method(
299 struct bt_component_class_sink *comp_cls,
300 bt_component_class_sink_get_supported_mip_versions_method method)
301{
7c7324d3 302 BT_ASSERT_PRE_NO_ERROR();
be788861
PP
303 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
304 BT_ASSERT_PRE_NON_NULL(method, "Method");
305 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
306 comp_cls->methods.get_supported_mip_versions = method;
307 BT_LIB_LOGD("Set sink component class's \"get supported MIP versions\" method: "
308 "%!+C", comp_cls);
309 return BT_FUNC_STATUS_OK;
310}
311
fb25b9e3 312enum bt_component_class_set_method_status
4175c1d5 313bt_component_class_source_set_initialize_method(
7b53201c 314 struct bt_component_class_source *comp_cls,
4175c1d5 315 bt_component_class_source_initialize_method method)
d3e4dcd8 316{
7c7324d3 317 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
318 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
319 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 320 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 321 comp_cls->methods.init = method;
a684a357 322 BT_LIB_LOGD("Set source component class's initialization method: "
834e9996 323 "%!+C", comp_cls);
fb25b9e3 324 return BT_FUNC_STATUS_OK;
d3e4dcd8
PP
325}
326
fb25b9e3 327enum bt_component_class_set_method_status
4175c1d5 328bt_component_class_filter_set_initialize_method(
7b53201c 329 struct bt_component_class_filter *comp_cls,
4175c1d5 330 bt_component_class_filter_initialize_method method)
efa96d5d 331{
7c7324d3 332 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
333 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
334 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 335 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 336 comp_cls->methods.init = method;
a684a357 337 BT_LIB_LOGD("Set filter component class's initialization method: "
834e9996 338 "%!+C", comp_cls);
fb25b9e3 339 return BT_FUNC_STATUS_OK;
efa96d5d
PP
340}
341
fb25b9e3 342enum bt_component_class_set_method_status
4175c1d5 343bt_component_class_sink_set_initialize_method(
7b53201c 344 struct bt_component_class_sink *comp_cls,
4175c1d5 345 bt_component_class_sink_initialize_method method)
2d41b99e 346{
7c7324d3 347 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
348 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
349 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 350 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 351 comp_cls->methods.init = method;
a684a357 352 BT_LIB_LOGD("Set sink component class's initialization method: "
834e9996 353 "%!+C", comp_cls);
fb25b9e3 354 return BT_FUNC_STATUS_OK;
72b913fb
PP
355}
356
fb25b9e3 357enum bt_component_class_set_method_status
15a52f66 358bt_component_class_source_set_finalize_method(
7b53201c
PP
359 struct bt_component_class_source *comp_cls,
360 bt_component_class_source_finalize_method method)
0d8b4d8e 361{
7c7324d3 362 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
363 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
364 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 365 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 366 comp_cls->methods.finalize = method;
a684a357 367 BT_LIB_LOGD("Set source component class's finalization method: "
834e9996 368 "%!+C", comp_cls);
fb25b9e3 369 return BT_FUNC_STATUS_OK;
0d8b4d8e
PP
370}
371
fb25b9e3 372enum bt_component_class_set_method_status
15a52f66 373bt_component_class_filter_set_finalize_method(
7b53201c
PP
374 struct bt_component_class_filter *comp_cls,
375 bt_component_class_filter_finalize_method method)
72b913fb 376{
7c7324d3 377 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
378 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
379 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 380 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 381 comp_cls->methods.finalize = method;
a684a357 382 BT_LIB_LOGD("Set filter component class's finalization method: "
834e9996 383 "%!+C", comp_cls);
fb25b9e3 384 return BT_FUNC_STATUS_OK;
2d41b99e
JG
385}
386
fb25b9e3 387enum bt_component_class_set_method_status
15a52f66 388bt_component_class_sink_set_finalize_method(
7b53201c
PP
389 struct bt_component_class_sink *comp_cls,
390 bt_component_class_sink_finalize_method method)
d3e4dcd8 391{
7c7324d3 392 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
393 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
394 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 395 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 396 comp_cls->methods.finalize = method;
a684a357 397 BT_LIB_LOGD("Set sink component class's finalization method: "
834e9996 398 "%!+C", comp_cls);
fb25b9e3 399 return BT_FUNC_STATUS_OK;
d3e4dcd8
PP
400}
401
fb25b9e3 402enum bt_component_class_set_method_status
15a52f66 403bt_component_class_source_set_query_method(
7b53201c
PP
404 struct bt_component_class_source *comp_cls,
405 bt_component_class_source_query_method method)
d3eb6e8f 406{
7c7324d3 407 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
408 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
409 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 410 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 411 comp_cls->methods.query = method;
a684a357 412 BT_LIB_LOGD("Set source component class's query method: "
834e9996 413 "%!+C", comp_cls);
fb25b9e3 414 return BT_FUNC_STATUS_OK;
d3eb6e8f
PP
415}
416
fb25b9e3 417enum bt_component_class_set_method_status
15a52f66 418bt_component_class_filter_set_query_method(
7b53201c
PP
419 struct bt_component_class_filter *comp_cls,
420 bt_component_class_filter_query_method method)
d3eb6e8f 421{
7c7324d3 422 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
423 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
424 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 425 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 426 comp_cls->methods.query = method;
a684a357 427 BT_LIB_LOGD("Set filter component class's query method: "
834e9996 428 "%!+C", comp_cls);
fb25b9e3 429 return BT_FUNC_STATUS_OK;
834e9996 430}
a3aacb6f 431
fb25b9e3 432enum bt_component_class_set_method_status
15a52f66 433bt_component_class_sink_set_query_method(
7b53201c
PP
434 struct bt_component_class_sink *comp_cls,
435 bt_component_class_sink_query_method method)
834e9996 436{
7c7324d3 437 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
438 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
439 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 440 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 441 comp_cls->methods.query = method;
a684a357 442 BT_LIB_LOGD("Set sink component class's query method: "
834e9996 443 "%!+C", comp_cls);
fb25b9e3 444 return BT_FUNC_STATUS_OK;
834e9996 445}
d3eb6e8f 446
fb25b9e3 447enum bt_component_class_set_method_status
15a52f66 448bt_component_class_filter_set_input_port_connected_method(
7b53201c
PP
449 struct bt_component_class_filter *comp_cls,
450 bt_component_class_filter_input_port_connected_method method)
834e9996 451{
7c7324d3 452 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
453 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
454 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 455 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 456 comp_cls->methods.input_port_connected = method;
a684a357 457 BT_LIB_LOGD("Set filter component class's \"input port connected\" method"
834e9996 458 ": %!+C", comp_cls);
fb25b9e3 459 return BT_FUNC_STATUS_OK;
834e9996 460}
a3aacb6f 461
fb25b9e3 462enum bt_component_class_set_method_status
15a52f66 463bt_component_class_sink_set_input_port_connected_method(
7b53201c
PP
464 struct bt_component_class_sink *comp_cls,
465 bt_component_class_sink_input_port_connected_method method)
834e9996 466{
7c7324d3 467 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
468 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
469 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 470 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 471 comp_cls->methods.input_port_connected = method;
a684a357 472 BT_LIB_LOGD("Set sink component class's \"input port connected\" method"
834e9996 473 ": %!+C", comp_cls);
fb25b9e3 474 return BT_FUNC_STATUS_OK;
834e9996 475}
a3aacb6f 476
fb25b9e3 477enum bt_component_class_set_method_status
15a52f66 478bt_component_class_source_set_output_port_connected_method(
7b53201c
PP
479 struct bt_component_class_source *comp_cls,
480 bt_component_class_source_output_port_connected_method method)
834e9996 481{
7c7324d3 482 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
483 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
484 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 485 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 486 comp_cls->methods.output_port_connected = method;
a684a357 487 BT_LIB_LOGD("Set source component class's \"output port connected\" method"
834e9996 488 ": %!+C", comp_cls);
fb25b9e3 489 return BT_FUNC_STATUS_OK;
834e9996 490}
d3eb6e8f 491
fb25b9e3 492enum bt_component_class_set_method_status
15a52f66 493bt_component_class_filter_set_output_port_connected_method(
7b53201c
PP
494 struct bt_component_class_filter *comp_cls,
495 bt_component_class_filter_output_port_connected_method method)
834e9996 496{
7c7324d3 497 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
498 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
499 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 500 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 501 comp_cls->methods.output_port_connected = method;
a684a357 502 BT_LIB_LOGD("Set filter component class's \"output port connected\" method"
834e9996 503 ": %!+C", comp_cls);
fb25b9e3 504 return BT_FUNC_STATUS_OK;
834e9996 505}
d3eb6e8f 506
fb25b9e3 507enum bt_component_class_set_method_status
1043fdea
PP
508bt_component_class_sink_set_graph_is_configured_method(
509 struct bt_component_class_sink *comp_cls,
510 bt_component_class_sink_graph_is_configured_method method)
511{
7c7324d3 512 BT_ASSERT_PRE_NO_ERROR();
1043fdea
PP
513 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
514 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 515 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
1043fdea 516 comp_cls->methods.graph_is_configured = method;
a684a357 517 BT_LIB_LOGD("Set sink component class's \"graph is configured\" method"
1043fdea 518 ": %!+C", comp_cls);
fb25b9e3 519 return BT_FUNC_STATUS_OK;
1043fdea
PP
520}
521
fb25b9e3 522enum bt_component_class_set_method_status
4175c1d5 523bt_component_class_source_set_message_iterator_initialize_method(
7b53201c 524 struct bt_component_class_source *comp_cls,
4175c1d5 525 bt_component_class_source_message_iterator_initialize_method method)
834e9996 526{
7c7324d3 527 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
528 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
529 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 530 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
4175c1d5 531 comp_cls->methods.msg_iter_initialize = method;
a684a357 532 BT_LIB_LOGD("Set source component class's message iterator initialization method"
834e9996 533 ": %!+C", comp_cls);
fb25b9e3 534 return BT_FUNC_STATUS_OK;
834e9996 535}
a3aacb6f 536
fb25b9e3 537enum bt_component_class_set_method_status
4175c1d5 538bt_component_class_filter_set_message_iterator_initialize_method(
7b53201c 539 struct bt_component_class_filter *comp_cls,
4175c1d5 540 bt_component_class_filter_message_iterator_initialize_method method)
834e9996 541{
7c7324d3 542 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
543 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
544 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 545 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
4175c1d5 546 comp_cls->methods.msg_iter_initialize = method;
a684a357 547 BT_LIB_LOGD("Set filter component class's message iterator initialization method"
834e9996 548 ": %!+C", comp_cls);
fb25b9e3 549 return BT_FUNC_STATUS_OK;
834e9996 550}
d3eb6e8f 551
fb25b9e3 552enum bt_component_class_set_method_status
15a52f66 553bt_component_class_source_set_message_iterator_finalize_method(
7b53201c 554 struct bt_component_class_source *comp_cls,
b09a5592 555 bt_component_class_source_message_iterator_finalize_method method)
834e9996 556{
7c7324d3 557 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
558 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
559 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 560 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
b09a5592 561 comp_cls->methods.msg_iter_finalize = method;
a684a357 562 BT_LIB_LOGD("Set source component class's message iterator finalization method"
834e9996 563 ": %!+C", comp_cls);
fb25b9e3 564 return BT_FUNC_STATUS_OK;
834e9996 565}
d3eb6e8f 566
fb25b9e3 567enum bt_component_class_set_method_status
15a52f66 568bt_component_class_filter_set_message_iterator_finalize_method(
7b53201c 569 struct bt_component_class_filter *comp_cls,
b09a5592 570 bt_component_class_filter_message_iterator_finalize_method method)
834e9996 571{
7c7324d3 572 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
573 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
574 BT_ASSERT_PRE_NON_NULL(method, "Method");
fa6cfec3 575 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
b09a5592 576 comp_cls->methods.msg_iter_finalize = method;
a684a357 577 BT_LIB_LOGD("Set filter component class's message iterator finalization method"
834e9996 578 ": %!+C", comp_cls);
fb25b9e3 579 return BT_FUNC_STATUS_OK;
d3eb6e8f
PP
580}
581
fb25b9e3 582enum bt_component_class_set_method_status
7f8e969d 583bt_component_class_filter_set_message_iterator_seek_ns_from_origin_methods(
15a52f66 584 struct bt_component_class_filter *comp_cls,
7f8e969d
SM
585 bt_component_class_filter_message_iterator_seek_ns_from_origin_method seek_method,
586 bt_component_class_filter_message_iterator_can_seek_ns_from_origin_method can_seek_method)
15a52f66 587{
7c7324d3 588 BT_ASSERT_PRE_NO_ERROR();
15a52f66 589 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
7f8e969d 590 BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method");
fa6cfec3 591 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7f8e969d
SM
592 comp_cls->methods.msg_iter_seek_ns_from_origin = seek_method;
593 comp_cls->methods.msg_iter_can_seek_ns_from_origin = can_seek_method;
a684a357 594 BT_LIB_LOGD("Set filter component class's message iterator \"seek nanoseconds from origin\" method"
15a52f66 595 ": %!+C", comp_cls);
fb25b9e3 596 return BT_FUNC_STATUS_OK;
15a52f66
PP
597}
598
fb25b9e3 599enum bt_component_class_set_method_status
7f8e969d 600bt_component_class_source_set_message_iterator_seek_ns_from_origin_methods(
15a52f66 601 struct bt_component_class_source *comp_cls,
7f8e969d
SM
602 bt_component_class_source_message_iterator_seek_ns_from_origin_method seek_method,
603 bt_component_class_source_message_iterator_can_seek_ns_from_origin_method can_seek_method)
15a52f66 604{
7c7324d3 605 BT_ASSERT_PRE_NO_ERROR();
15a52f66 606 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
7f8e969d 607 BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method");
fa6cfec3 608 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7f8e969d
SM
609 comp_cls->methods.msg_iter_seek_ns_from_origin = seek_method;
610 comp_cls->methods.msg_iter_can_seek_ns_from_origin = can_seek_method;
611 BT_LIB_LOGD("Set source component class's message iterator \"seek nanoseconds from origin\" methods"
15a52f66 612 ": %!+C", comp_cls);
fb25b9e3 613 return BT_FUNC_STATUS_OK;
15a52f66
PP
614}
615
fb25b9e3 616enum bt_component_class_set_method_status
7f8e969d 617bt_component_class_filter_set_message_iterator_seek_beginning_methods(
15a52f66 618 struct bt_component_class_filter *comp_cls,
7f8e969d
SM
619 bt_component_class_filter_message_iterator_seek_beginning_method seek_method,
620 bt_component_class_filter_message_iterator_can_seek_beginning_method can_seek_method)
15a52f66 621{
7c7324d3 622 BT_ASSERT_PRE_NO_ERROR();
15a52f66 623 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
7f8e969d 624 BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method");
fa6cfec3 625 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7f8e969d
SM
626 comp_cls->methods.msg_iter_seek_beginning = seek_method;
627 comp_cls->methods.msg_iter_can_seek_beginning = can_seek_method;
628 BT_LIB_LOGD("Set filter component class's message iterator \"seek beginning\" methods"
15a52f66 629 ": %!+C", comp_cls);
fb25b9e3 630 return BT_FUNC_STATUS_OK;
15a52f66
PP
631}
632
fb25b9e3 633enum bt_component_class_set_method_status
7f8e969d 634bt_component_class_source_set_message_iterator_seek_beginning_methods(
15a52f66 635 struct bt_component_class_source *comp_cls,
7f8e969d
SM
636 bt_component_class_source_message_iterator_seek_beginning_method seek_method,
637 bt_component_class_source_message_iterator_can_seek_beginning_method can_seek_method)
15a52f66 638{
7c7324d3 639 BT_ASSERT_PRE_NO_ERROR();
15a52f66 640 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
7f8e969d 641 BT_ASSERT_PRE_NON_NULL(seek_method, "Seek method");
fa6cfec3 642 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
7f8e969d
SM
643 comp_cls->methods.msg_iter_seek_beginning = seek_method;
644 comp_cls->methods.msg_iter_can_seek_beginning = can_seek_method;
645 BT_LIB_LOGD("Set source component class's message iterator \"seek beginning\" methods"
15a52f66 646 ": %!+C", comp_cls);
fb25b9e3 647 return BT_FUNC_STATUS_OK;
15a52f66
PP
648}
649
fb25b9e3
PP
650enum bt_component_class_set_description_status
651bt_component_class_set_description(
7b53201c 652 struct bt_component_class *comp_cls,
d3e4dcd8
PP
653 const char *description)
654{
7c7324d3 655 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
656 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
657 BT_ASSERT_PRE_NON_NULL(description, "Description");
fa6cfec3 658 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 659 g_string_assign(comp_cls->description, description);
a684a357 660 BT_LIB_LOGD("Set component class's description: "
a3aacb6f 661 "addr=%p, name=\"%s\", type=%s",
834e9996
PP
662 comp_cls,
663 bt_component_class_get_name(comp_cls),
664 bt_component_class_type_string(comp_cls->type));
fb25b9e3 665 return BT_FUNC_STATUS_OK;
fb2dcc52 666}
38b48196 667
fb25b9e3 668enum bt_component_class_set_help_status bt_component_class_set_help(
7b53201c 669 struct bt_component_class *comp_cls,
5536d9a6
PP
670 const char *help)
671{
7c7324d3 672 BT_ASSERT_PRE_NO_ERROR();
834e9996
PP
673 BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class");
674 BT_ASSERT_PRE_NON_NULL(help, "Help");
fa6cfec3 675 BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls);
834e9996 676 g_string_assign(comp_cls->help, help);
a684a357 677 BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls);
fb25b9e3 678 return BT_FUNC_STATUS_OK;
5536d9a6
PP
679}
680
7b53201c 681const char *bt_component_class_get_name(const struct bt_component_class *comp_cls)
38b48196 682{
fa6cfec3 683 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
834e9996 684 return comp_cls->name->str;
38b48196
JG
685}
686
d3e4dcd8 687enum bt_component_class_type bt_component_class_get_type(
7b53201c 688 const struct bt_component_class *comp_cls)
38b48196 689{
fa6cfec3 690 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
834e9996 691 return comp_cls->type;
38b48196
JG
692}
693
33b34c43 694const char *bt_component_class_get_description(
7b53201c 695 const struct bt_component_class *comp_cls)
38b48196 696{
fa6cfec3 697 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
834e9996
PP
698 return comp_cls->description &&
699 comp_cls->description->str[0] != '\0' ?
700 comp_cls->description->str : NULL;
38b48196 701}
7c7c0433 702
5536d9a6 703const char *bt_component_class_get_help(
7b53201c 704 const struct bt_component_class *comp_cls)
5536d9a6 705{
fa6cfec3 706 BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class");
834e9996
PP
707 return comp_cls->help &&
708 comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL;
5536d9a6
PP
709}
710
33b34c43 711BT_HIDDEN
834e9996
PP
712void bt_component_class_add_destroy_listener(
713 struct bt_component_class *comp_cls,
33b34c43 714 bt_component_class_destroy_listener_func func, void *data)
7c7c0433 715{
d3e4dcd8 716 struct bt_component_class_destroy_listener listener;
33b34c43 717
834e9996 718 BT_ASSERT(comp_cls);
8b45963b 719 BT_ASSERT(func);
33b34c43
PP
720 listener.func = func;
721 listener.data = data;
834e9996 722 g_array_append_val(comp_cls->destroy_listeners, listener);
a684a357 723 BT_LIB_LOGD("Added destroy listener to component class: "
834e9996 724 "%![cc-]+C, listener-func-addr=%p", comp_cls, func);
7c7c0433 725}
d3e4dcd8 726
834e9996 727BT_HIDDEN
7b53201c 728void _bt_component_class_freeze(const struct bt_component_class *comp_cls)
1e4d8103 729{
834e9996
PP
730 BT_ASSERT(comp_cls);
731 BT_LIB_LOGD("Freezing component class: %!+C", comp_cls);
7b53201c 732 ((struct bt_component_class *) comp_cls)->frozen = true;
1e4d8103 733}
8c6884d9
PP
734
735void bt_component_class_get_ref(
736 const struct bt_component_class *component_class)
737{
738 bt_object_get_ref(component_class);
739}
740
741void bt_component_class_put_ref(
742 const struct bt_component_class *component_class)
743{
744 bt_object_put_ref(component_class);
745}
746
747void bt_component_class_source_get_ref(
748 const struct bt_component_class_source *component_class_source)
749{
750 bt_object_get_ref(component_class_source);
751}
752
753void bt_component_class_source_put_ref(
754 const struct bt_component_class_source *component_class_source)
755{
756 bt_object_put_ref(component_class_source);
757}
758
759void bt_component_class_filter_get_ref(
760 const struct bt_component_class_filter *component_class_filter)
761{
762 bt_object_get_ref(component_class_filter);
763}
764
765void bt_component_class_filter_put_ref(
766 const struct bt_component_class_filter *component_class_filter)
767{
768 bt_object_put_ref(component_class_filter);
769}
770
771void bt_component_class_sink_get_ref(
772 const struct bt_component_class_sink *component_class_sink)
773{
774 bt_object_get_ref(component_class_sink);
775}
776
777void bt_component_class_sink_put_ref(
778 const struct bt_component_class_sink *component_class_sink)
779{
780 bt_object_put_ref(component_class_sink);
781}
This page took 0.125064 seconds and 4 git commands to generate.