| 1 | /* |
| 2 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
| 3 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | * of this software and associated documentation files (the "Software"), to deal |
| 7 | * in the Software without restriction, including without limitation the rights |
| 8 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | * copies of the Software, and to permit persons to whom the Software is |
| 10 | * furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included in |
| 13 | * all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | * SOFTWARE. |
| 22 | */ |
| 23 | |
| 24 | #define BT_LOG_TAG "LIB/COMPONENT-CLASS" |
| 25 | #include "lib/logging.h" |
| 26 | |
| 27 | #include "common/assert.h" |
| 28 | #include "lib/assert-pre.h" |
| 29 | #include "compat/compiler.h" |
| 30 | #include <babeltrace2/graph/component-class.h> |
| 31 | #include <babeltrace2/graph/component-class-const.h> |
| 32 | #include <babeltrace2/graph/component-class-source.h> |
| 33 | #include <babeltrace2/graph/component-class-source-const.h> |
| 34 | #include <babeltrace2/graph/component-class-filter.h> |
| 35 | #include <babeltrace2/graph/component-class-filter-const.h> |
| 36 | #include <babeltrace2/graph/component-class-sink.h> |
| 37 | #include <babeltrace2/graph/component-class-sink-const.h> |
| 38 | #include <babeltrace2/types.h> |
| 39 | #include <glib.h> |
| 40 | |
| 41 | #include "component-class.h" |
| 42 | #include "lib/func-status.h" |
| 43 | #include "lib/graph/message-iterator-class.h" |
| 44 | |
| 45 | #define BT_ASSERT_PRE_DEV_COMP_CLS_HOT(_cc) \ |
| 46 | BT_ASSERT_PRE_DEV_HOT(((const struct bt_component_class *) (_cc)), \ |
| 47 | "Component class", ": %!+C", (_cc)) |
| 48 | |
| 49 | static |
| 50 | void destroy_component_class(struct bt_object *obj) |
| 51 | { |
| 52 | struct bt_component_class *class; |
| 53 | int i; |
| 54 | |
| 55 | BT_ASSERT(obj); |
| 56 | class = container_of(obj, struct bt_component_class, base); |
| 57 | |
| 58 | BT_LIB_LOGI("Destroying component class: %!+C", class); |
| 59 | |
| 60 | /* Call destroy listeners in reverse registration order */ |
| 61 | for (i = class->destroy_listeners->len - 1; i >= 0; i--) { |
| 62 | struct bt_component_class_destroy_listener *listener = |
| 63 | &g_array_index(class->destroy_listeners, |
| 64 | struct bt_component_class_destroy_listener, |
| 65 | i); |
| 66 | |
| 67 | BT_LOGD("Calling destroy listener: func-addr=%p, data-addr=%p", |
| 68 | listener->func, listener->data); |
| 69 | listener->func(class, listener->data); |
| 70 | } |
| 71 | |
| 72 | if (class->name) { |
| 73 | g_string_free(class->name, TRUE); |
| 74 | class->name = NULL; |
| 75 | } |
| 76 | |
| 77 | if (class->description) { |
| 78 | g_string_free(class->description, TRUE); |
| 79 | class->description = NULL; |
| 80 | } |
| 81 | |
| 82 | if (class->help) { |
| 83 | g_string_free(class->help, TRUE); |
| 84 | class->help = NULL; |
| 85 | } |
| 86 | |
| 87 | if (class->plugin_name) { |
| 88 | g_string_free(class->plugin_name, TRUE); |
| 89 | class->plugin_name = NULL; |
| 90 | } |
| 91 | |
| 92 | if (class->destroy_listeners) { |
| 93 | g_array_free(class->destroy_listeners, TRUE); |
| 94 | class->destroy_listeners = NULL; |
| 95 | } |
| 96 | |
| 97 | if (class->type == BT_COMPONENT_CLASS_TYPE_SOURCE) { |
| 98 | struct bt_component_class_source *class_src |
| 99 | = container_of(class, struct bt_component_class_source, |
| 100 | parent); |
| 101 | |
| 102 | BT_ASSERT(class_src->msg_iter_cls); |
| 103 | bt_message_iterator_class_put_ref(class_src->msg_iter_cls); |
| 104 | class_src->msg_iter_cls = NULL; |
| 105 | } else if (class->type == BT_COMPONENT_CLASS_TYPE_FILTER) { |
| 106 | struct bt_component_class_filter *class_flt |
| 107 | = container_of(class, struct bt_component_class_filter, |
| 108 | parent); |
| 109 | |
| 110 | BT_ASSERT(class_flt->msg_iter_cls); |
| 111 | bt_message_iterator_class_put_ref(class_flt->msg_iter_cls); |
| 112 | class_flt->msg_iter_cls = NULL; |
| 113 | } |
| 114 | |
| 115 | g_free(class); |
| 116 | } |
| 117 | |
| 118 | static |
| 119 | int bt_component_class_init(struct bt_component_class *class, |
| 120 | enum bt_component_class_type type, const char *name) |
| 121 | { |
| 122 | int ret = 0; |
| 123 | |
| 124 | bt_object_init_shared(&class->base, destroy_component_class); |
| 125 | class->type = type; |
| 126 | class->name = g_string_new(name); |
| 127 | if (!class->name) { |
| 128 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
| 129 | goto error; |
| 130 | } |
| 131 | |
| 132 | class->description = g_string_new(NULL); |
| 133 | if (!class->description) { |
| 134 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
| 135 | goto error; |
| 136 | } |
| 137 | |
| 138 | class->help = g_string_new(NULL); |
| 139 | if (!class->help) { |
| 140 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
| 141 | goto error; |
| 142 | } |
| 143 | |
| 144 | class->plugin_name = g_string_new(NULL); |
| 145 | if (!class->plugin_name) { |
| 146 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); |
| 147 | goto error; |
| 148 | } |
| 149 | |
| 150 | class->destroy_listeners = g_array_new(FALSE, TRUE, |
| 151 | sizeof(struct bt_component_class_destroy_listener)); |
| 152 | if (!class->destroy_listeners) { |
| 153 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GArray."); |
| 154 | goto error; |
| 155 | } |
| 156 | |
| 157 | goto end; |
| 158 | |
| 159 | error: |
| 160 | BT_OBJECT_PUT_REF_AND_RESET(class); |
| 161 | ret = -1; |
| 162 | |
| 163 | end: |
| 164 | return ret; |
| 165 | } |
| 166 | |
| 167 | struct bt_component_class_source *bt_component_class_source_create( |
| 168 | const char *name, |
| 169 | struct bt_message_iterator_class *message_iterator_class) |
| 170 | { |
| 171 | struct bt_component_class_source *source_class = NULL; |
| 172 | int ret; |
| 173 | |
| 174 | BT_ASSERT_PRE_NO_ERROR(); |
| 175 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
| 176 | BT_ASSERT_PRE_NON_NULL(message_iterator_class, "Message iterator class"); |
| 177 | BT_LIB_LOGI("Creating source component class: " |
| 178 | "name=\"%s\", %![msg-iter-cls-]+I", |
| 179 | name, message_iterator_class); |
| 180 | source_class = g_new0(struct bt_component_class_source, 1); |
| 181 | if (!source_class) { |
| 182 | BT_LIB_LOGE_APPEND_CAUSE( |
| 183 | "Failed to allocate one source component class."); |
| 184 | goto end; |
| 185 | } |
| 186 | |
| 187 | /* bt_component_class_init() logs errors */ |
| 188 | ret = bt_component_class_init(&source_class->parent, |
| 189 | BT_COMPONENT_CLASS_TYPE_SOURCE, name); |
| 190 | if (ret) { |
| 191 | /* |
| 192 | * If bt_component_class_init() fails, the component |
| 193 | * class is put, therefore its memory is already |
| 194 | * freed. |
| 195 | */ |
| 196 | source_class = NULL; |
| 197 | goto end; |
| 198 | } |
| 199 | |
| 200 | source_class->msg_iter_cls = message_iterator_class; |
| 201 | bt_message_iterator_class_get_ref(source_class->msg_iter_cls); |
| 202 | bt_message_iterator_class_freeze(source_class->msg_iter_cls); |
| 203 | |
| 204 | BT_LIB_LOGI("Created source component class: %!+C", source_class); |
| 205 | |
| 206 | end: |
| 207 | return (void *) source_class; |
| 208 | } |
| 209 | |
| 210 | struct bt_component_class_filter *bt_component_class_filter_create( |
| 211 | const char *name, |
| 212 | struct bt_message_iterator_class *message_iterator_class) |
| 213 | { |
| 214 | struct bt_component_class_filter *filter_class = NULL; |
| 215 | int ret; |
| 216 | |
| 217 | BT_ASSERT_PRE_NO_ERROR(); |
| 218 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
| 219 | BT_ASSERT_PRE_NON_NULL(message_iterator_class, "Message iterator class"); |
| 220 | BT_LIB_LOGI("Creating filter component class: " |
| 221 | "name=\"%s\", %![msg-iter-cls-]+I", |
| 222 | name, message_iterator_class); |
| 223 | filter_class = g_new0(struct bt_component_class_filter, 1); |
| 224 | if (!filter_class) { |
| 225 | BT_LIB_LOGE_APPEND_CAUSE( |
| 226 | "Failed to allocate one filter component class."); |
| 227 | goto end; |
| 228 | } |
| 229 | |
| 230 | /* bt_component_class_init() logs errors */ |
| 231 | ret = bt_component_class_init(&filter_class->parent, |
| 232 | BT_COMPONENT_CLASS_TYPE_FILTER, name); |
| 233 | if (ret) { |
| 234 | /* |
| 235 | * If bt_component_class_init() fails, the component |
| 236 | * class is put, therefore its memory is already |
| 237 | * freed. |
| 238 | */ |
| 239 | filter_class = NULL; |
| 240 | goto end; |
| 241 | } |
| 242 | |
| 243 | filter_class->msg_iter_cls = message_iterator_class; |
| 244 | bt_message_iterator_class_get_ref(filter_class->msg_iter_cls); |
| 245 | bt_message_iterator_class_freeze(filter_class->msg_iter_cls); |
| 246 | |
| 247 | BT_LIB_LOGI("Created filter component class: %!+C", filter_class); |
| 248 | |
| 249 | end: |
| 250 | return (void *) filter_class; |
| 251 | } |
| 252 | |
| 253 | struct bt_component_class_sink *bt_component_class_sink_create( |
| 254 | const char *name, bt_component_class_sink_consume_method method) |
| 255 | { |
| 256 | struct bt_component_class_sink *sink_class = NULL; |
| 257 | int ret; |
| 258 | |
| 259 | BT_ASSERT_PRE_NO_ERROR(); |
| 260 | BT_ASSERT_PRE_NON_NULL(name, "Name"); |
| 261 | BT_ASSERT_PRE_NON_NULL(method, "Consume next method"); |
| 262 | BT_LOGI("Creating sink component class: " |
| 263 | "name=\"%s\", consume-method-addr=%p", |
| 264 | name, method); |
| 265 | sink_class = g_new0(struct bt_component_class_sink, 1); |
| 266 | if (!sink_class) { |
| 267 | BT_LIB_LOGE_APPEND_CAUSE( |
| 268 | "Failed to allocate one sink component class."); |
| 269 | goto end; |
| 270 | } |
| 271 | |
| 272 | /* bt_component_class_init() logs errors */ |
| 273 | ret = bt_component_class_init(&sink_class->parent, |
| 274 | BT_COMPONENT_CLASS_TYPE_SINK, name); |
| 275 | if (ret) { |
| 276 | /* |
| 277 | * If bt_component_class_init() fails, the component |
| 278 | * class is put, therefore its memory is already |
| 279 | * freed. |
| 280 | */ |
| 281 | sink_class = NULL; |
| 282 | goto end; |
| 283 | } |
| 284 | |
| 285 | sink_class->methods.consume = method; |
| 286 | BT_LIB_LOGI("Created sink component class: %!+C", sink_class); |
| 287 | |
| 288 | end: |
| 289 | return (void *) sink_class; |
| 290 | } |
| 291 | |
| 292 | enum bt_component_class_set_method_status |
| 293 | bt_component_class_source_set_get_supported_mip_versions_method( |
| 294 | struct bt_component_class_source *comp_cls, |
| 295 | bt_component_class_source_get_supported_mip_versions_method method) |
| 296 | { |
| 297 | BT_ASSERT_PRE_NO_ERROR(); |
| 298 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 299 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 300 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 301 | comp_cls->methods.get_supported_mip_versions = method; |
| 302 | BT_LIB_LOGD("Set source component class's \"get supported MIP versions\" method: " |
| 303 | "%!+C", comp_cls); |
| 304 | return BT_FUNC_STATUS_OK; |
| 305 | } |
| 306 | |
| 307 | enum bt_component_class_set_method_status |
| 308 | bt_component_class_filter_set_get_supported_mip_versions_method( |
| 309 | struct bt_component_class_filter *comp_cls, |
| 310 | bt_component_class_filter_get_supported_mip_versions_method method) |
| 311 | { |
| 312 | BT_ASSERT_PRE_NO_ERROR(); |
| 313 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 314 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 315 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 316 | comp_cls->methods.get_supported_mip_versions = method; |
| 317 | BT_LIB_LOGD("Set filter component class's \"get supported MIP versions\" method: " |
| 318 | "%!+C", comp_cls); |
| 319 | return BT_FUNC_STATUS_OK; |
| 320 | } |
| 321 | |
| 322 | enum bt_component_class_set_method_status |
| 323 | bt_component_class_sink_set_get_supported_mip_versions_method( |
| 324 | struct bt_component_class_sink *comp_cls, |
| 325 | bt_component_class_sink_get_supported_mip_versions_method method) |
| 326 | { |
| 327 | BT_ASSERT_PRE_NO_ERROR(); |
| 328 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 329 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 330 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 331 | comp_cls->methods.get_supported_mip_versions = method; |
| 332 | BT_LIB_LOGD("Set sink component class's \"get supported MIP versions\" method: " |
| 333 | "%!+C", comp_cls); |
| 334 | return BT_FUNC_STATUS_OK; |
| 335 | } |
| 336 | |
| 337 | enum bt_component_class_set_method_status |
| 338 | bt_component_class_source_set_initialize_method( |
| 339 | struct bt_component_class_source *comp_cls, |
| 340 | bt_component_class_source_initialize_method method) |
| 341 | { |
| 342 | BT_ASSERT_PRE_NO_ERROR(); |
| 343 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 344 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 345 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 346 | comp_cls->methods.init = method; |
| 347 | BT_LIB_LOGD("Set source component class's initialization method: " |
| 348 | "%!+C", comp_cls); |
| 349 | return BT_FUNC_STATUS_OK; |
| 350 | } |
| 351 | |
| 352 | enum bt_component_class_set_method_status |
| 353 | bt_component_class_filter_set_initialize_method( |
| 354 | struct bt_component_class_filter *comp_cls, |
| 355 | bt_component_class_filter_initialize_method method) |
| 356 | { |
| 357 | BT_ASSERT_PRE_NO_ERROR(); |
| 358 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 359 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 360 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 361 | comp_cls->methods.init = method; |
| 362 | BT_LIB_LOGD("Set filter component class's initialization method: " |
| 363 | "%!+C", comp_cls); |
| 364 | return BT_FUNC_STATUS_OK; |
| 365 | } |
| 366 | |
| 367 | enum bt_component_class_set_method_status |
| 368 | bt_component_class_sink_set_initialize_method( |
| 369 | struct bt_component_class_sink *comp_cls, |
| 370 | bt_component_class_sink_initialize_method method) |
| 371 | { |
| 372 | BT_ASSERT_PRE_NO_ERROR(); |
| 373 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 374 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 375 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 376 | comp_cls->methods.init = method; |
| 377 | BT_LIB_LOGD("Set sink component class's initialization method: " |
| 378 | "%!+C", comp_cls); |
| 379 | return BT_FUNC_STATUS_OK; |
| 380 | } |
| 381 | |
| 382 | enum bt_component_class_set_method_status |
| 383 | bt_component_class_source_set_finalize_method( |
| 384 | struct bt_component_class_source *comp_cls, |
| 385 | bt_component_class_source_finalize_method method) |
| 386 | { |
| 387 | BT_ASSERT_PRE_NO_ERROR(); |
| 388 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 389 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 390 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 391 | comp_cls->methods.finalize = method; |
| 392 | BT_LIB_LOGD("Set source component class's finalization method: " |
| 393 | "%!+C", comp_cls); |
| 394 | return BT_FUNC_STATUS_OK; |
| 395 | } |
| 396 | |
| 397 | enum bt_component_class_set_method_status |
| 398 | bt_component_class_filter_set_finalize_method( |
| 399 | struct bt_component_class_filter *comp_cls, |
| 400 | bt_component_class_filter_finalize_method method) |
| 401 | { |
| 402 | BT_ASSERT_PRE_NO_ERROR(); |
| 403 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 404 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 405 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 406 | comp_cls->methods.finalize = method; |
| 407 | BT_LIB_LOGD("Set filter component class's finalization method: " |
| 408 | "%!+C", comp_cls); |
| 409 | return BT_FUNC_STATUS_OK; |
| 410 | } |
| 411 | |
| 412 | enum bt_component_class_set_method_status |
| 413 | bt_component_class_sink_set_finalize_method( |
| 414 | struct bt_component_class_sink *comp_cls, |
| 415 | bt_component_class_sink_finalize_method method) |
| 416 | { |
| 417 | BT_ASSERT_PRE_NO_ERROR(); |
| 418 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 419 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 420 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 421 | comp_cls->methods.finalize = method; |
| 422 | BT_LIB_LOGD("Set sink component class's finalization method: " |
| 423 | "%!+C", comp_cls); |
| 424 | return BT_FUNC_STATUS_OK; |
| 425 | } |
| 426 | |
| 427 | enum bt_component_class_set_method_status |
| 428 | bt_component_class_source_set_query_method( |
| 429 | struct bt_component_class_source *comp_cls, |
| 430 | bt_component_class_source_query_method method) |
| 431 | { |
| 432 | BT_ASSERT_PRE_NO_ERROR(); |
| 433 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 434 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 435 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 436 | comp_cls->methods.query = method; |
| 437 | BT_LIB_LOGD("Set source component class's query method: " |
| 438 | "%!+C", comp_cls); |
| 439 | return BT_FUNC_STATUS_OK; |
| 440 | } |
| 441 | |
| 442 | enum bt_component_class_set_method_status |
| 443 | bt_component_class_filter_set_query_method( |
| 444 | struct bt_component_class_filter *comp_cls, |
| 445 | bt_component_class_filter_query_method method) |
| 446 | { |
| 447 | BT_ASSERT_PRE_NO_ERROR(); |
| 448 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 449 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 450 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 451 | comp_cls->methods.query = method; |
| 452 | BT_LIB_LOGD("Set filter component class's query method: " |
| 453 | "%!+C", comp_cls); |
| 454 | return BT_FUNC_STATUS_OK; |
| 455 | } |
| 456 | |
| 457 | enum bt_component_class_set_method_status |
| 458 | bt_component_class_sink_set_query_method( |
| 459 | struct bt_component_class_sink *comp_cls, |
| 460 | bt_component_class_sink_query_method method) |
| 461 | { |
| 462 | BT_ASSERT_PRE_NO_ERROR(); |
| 463 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 464 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 465 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 466 | comp_cls->methods.query = method; |
| 467 | BT_LIB_LOGD("Set sink component class's query method: " |
| 468 | "%!+C", comp_cls); |
| 469 | return BT_FUNC_STATUS_OK; |
| 470 | } |
| 471 | |
| 472 | enum bt_component_class_set_method_status |
| 473 | bt_component_class_filter_set_input_port_connected_method( |
| 474 | struct bt_component_class_filter *comp_cls, |
| 475 | bt_component_class_filter_input_port_connected_method method) |
| 476 | { |
| 477 | BT_ASSERT_PRE_NO_ERROR(); |
| 478 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 479 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 480 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 481 | comp_cls->methods.input_port_connected = method; |
| 482 | BT_LIB_LOGD("Set filter component class's \"input port connected\" method" |
| 483 | ": %!+C", comp_cls); |
| 484 | return BT_FUNC_STATUS_OK; |
| 485 | } |
| 486 | |
| 487 | enum bt_component_class_set_method_status |
| 488 | bt_component_class_sink_set_input_port_connected_method( |
| 489 | struct bt_component_class_sink *comp_cls, |
| 490 | bt_component_class_sink_input_port_connected_method method) |
| 491 | { |
| 492 | BT_ASSERT_PRE_NO_ERROR(); |
| 493 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 494 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 495 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 496 | comp_cls->methods.input_port_connected = method; |
| 497 | BT_LIB_LOGD("Set sink component class's \"input port connected\" method" |
| 498 | ": %!+C", comp_cls); |
| 499 | return BT_FUNC_STATUS_OK; |
| 500 | } |
| 501 | |
| 502 | enum bt_component_class_set_method_status |
| 503 | bt_component_class_source_set_output_port_connected_method( |
| 504 | struct bt_component_class_source *comp_cls, |
| 505 | bt_component_class_source_output_port_connected_method method) |
| 506 | { |
| 507 | BT_ASSERT_PRE_NO_ERROR(); |
| 508 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 509 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 510 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 511 | comp_cls->methods.output_port_connected = method; |
| 512 | BT_LIB_LOGD("Set source component class's \"output port connected\" method" |
| 513 | ": %!+C", comp_cls); |
| 514 | return BT_FUNC_STATUS_OK; |
| 515 | } |
| 516 | |
| 517 | enum bt_component_class_set_method_status |
| 518 | bt_component_class_filter_set_output_port_connected_method( |
| 519 | struct bt_component_class_filter *comp_cls, |
| 520 | bt_component_class_filter_output_port_connected_method method) |
| 521 | { |
| 522 | BT_ASSERT_PRE_NO_ERROR(); |
| 523 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 524 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 525 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 526 | comp_cls->methods.output_port_connected = method; |
| 527 | BT_LIB_LOGD("Set filter component class's \"output port connected\" method" |
| 528 | ": %!+C", comp_cls); |
| 529 | return BT_FUNC_STATUS_OK; |
| 530 | } |
| 531 | |
| 532 | enum bt_component_class_set_method_status |
| 533 | bt_component_class_sink_set_graph_is_configured_method( |
| 534 | struct bt_component_class_sink *comp_cls, |
| 535 | bt_component_class_sink_graph_is_configured_method method) |
| 536 | { |
| 537 | BT_ASSERT_PRE_NO_ERROR(); |
| 538 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 539 | BT_ASSERT_PRE_NON_NULL(method, "Method"); |
| 540 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 541 | comp_cls->methods.graph_is_configured = method; |
| 542 | BT_LIB_LOGD("Set sink component class's \"graph is configured\" method" |
| 543 | ": %!+C", comp_cls); |
| 544 | return BT_FUNC_STATUS_OK; |
| 545 | } |
| 546 | |
| 547 | enum bt_component_class_set_description_status |
| 548 | bt_component_class_set_description( |
| 549 | struct bt_component_class *comp_cls, |
| 550 | const char *description) |
| 551 | { |
| 552 | BT_ASSERT_PRE_NO_ERROR(); |
| 553 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 554 | BT_ASSERT_PRE_NON_NULL(description, "Description"); |
| 555 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 556 | g_string_assign(comp_cls->description, description); |
| 557 | BT_LIB_LOGD("Set component class's description: " |
| 558 | "addr=%p, name=\"%s\", type=%s", |
| 559 | comp_cls, |
| 560 | bt_component_class_get_name(comp_cls), |
| 561 | bt_component_class_type_string(comp_cls->type)); |
| 562 | return BT_FUNC_STATUS_OK; |
| 563 | } |
| 564 | |
| 565 | enum bt_component_class_set_help_status bt_component_class_set_help( |
| 566 | struct bt_component_class *comp_cls, |
| 567 | const char *help) |
| 568 | { |
| 569 | BT_ASSERT_PRE_NO_ERROR(); |
| 570 | BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); |
| 571 | BT_ASSERT_PRE_NON_NULL(help, "Help"); |
| 572 | BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); |
| 573 | g_string_assign(comp_cls->help, help); |
| 574 | BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls); |
| 575 | return BT_FUNC_STATUS_OK; |
| 576 | } |
| 577 | |
| 578 | const char *bt_component_class_get_name(const struct bt_component_class *comp_cls) |
| 579 | { |
| 580 | BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class"); |
| 581 | return comp_cls->name->str; |
| 582 | } |
| 583 | |
| 584 | enum bt_component_class_type bt_component_class_get_type( |
| 585 | const struct bt_component_class *comp_cls) |
| 586 | { |
| 587 | BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class"); |
| 588 | return comp_cls->type; |
| 589 | } |
| 590 | |
| 591 | const char *bt_component_class_get_description( |
| 592 | const struct bt_component_class *comp_cls) |
| 593 | { |
| 594 | BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class"); |
| 595 | return comp_cls->description && |
| 596 | comp_cls->description->str[0] != '\0' ? |
| 597 | comp_cls->description->str : NULL; |
| 598 | } |
| 599 | |
| 600 | const char *bt_component_class_get_help( |
| 601 | const struct bt_component_class *comp_cls) |
| 602 | { |
| 603 | BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class"); |
| 604 | return comp_cls->help && |
| 605 | comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL; |
| 606 | } |
| 607 | |
| 608 | BT_HIDDEN |
| 609 | void bt_component_class_add_destroy_listener( |
| 610 | struct bt_component_class *comp_cls, |
| 611 | bt_component_class_destroy_listener_func func, void *data) |
| 612 | { |
| 613 | struct bt_component_class_destroy_listener listener; |
| 614 | |
| 615 | BT_ASSERT(comp_cls); |
| 616 | BT_ASSERT(func); |
| 617 | listener.func = func; |
| 618 | listener.data = data; |
| 619 | g_array_append_val(comp_cls->destroy_listeners, listener); |
| 620 | BT_LIB_LOGD("Added destroy listener to component class: " |
| 621 | "%![cc-]+C, listener-func-addr=%p", comp_cls, func); |
| 622 | } |
| 623 | |
| 624 | BT_HIDDEN |
| 625 | void _bt_component_class_freeze(const struct bt_component_class *comp_cls) |
| 626 | { |
| 627 | BT_ASSERT(comp_cls); |
| 628 | BT_LIB_LOGD("Freezing component class: %!+C", comp_cls); |
| 629 | ((struct bt_component_class *) comp_cls)->frozen = true; |
| 630 | } |
| 631 | |
| 632 | void bt_component_class_get_ref( |
| 633 | const struct bt_component_class *component_class) |
| 634 | { |
| 635 | bt_object_get_ref(component_class); |
| 636 | } |
| 637 | |
| 638 | void bt_component_class_put_ref( |
| 639 | const struct bt_component_class *component_class) |
| 640 | { |
| 641 | bt_object_put_ref(component_class); |
| 642 | } |
| 643 | |
| 644 | void bt_component_class_source_get_ref( |
| 645 | const struct bt_component_class_source *component_class_source) |
| 646 | { |
| 647 | bt_object_get_ref(component_class_source); |
| 648 | } |
| 649 | |
| 650 | void bt_component_class_source_put_ref( |
| 651 | const struct bt_component_class_source *component_class_source) |
| 652 | { |
| 653 | bt_object_put_ref(component_class_source); |
| 654 | } |
| 655 | |
| 656 | void bt_component_class_filter_get_ref( |
| 657 | const struct bt_component_class_filter *component_class_filter) |
| 658 | { |
| 659 | bt_object_get_ref(component_class_filter); |
| 660 | } |
| 661 | |
| 662 | void bt_component_class_filter_put_ref( |
| 663 | const struct bt_component_class_filter *component_class_filter) |
| 664 | { |
| 665 | bt_object_put_ref(component_class_filter); |
| 666 | } |
| 667 | |
| 668 | void bt_component_class_sink_get_ref( |
| 669 | const struct bt_component_class_sink *component_class_sink) |
| 670 | { |
| 671 | bt_object_get_ref(component_class_sink); |
| 672 | } |
| 673 | |
| 674 | void bt_component_class_sink_put_ref( |
| 675 | const struct bt_component_class_sink *component_class_sink) |
| 676 | { |
| 677 | bt_object_put_ref(component_class_sink); |
| 678 | } |