X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Fgraph%2Fcomponent-class.c;h=c3a47291ca0ec86d739e7169d0654015bc36a9fc;hb=6375b9429f8332f3eacc2ec795aa1924c73d9cc8;hp=ea90b5ce32ab8987be8064983aeefd6b747b5046;hpb=a3f0c7db90f4cfc81090a83a7442b7bc624d5789;p=babeltrace.git diff --git a/src/lib/graph/component-class.c b/src/lib/graph/component-class.c index ea90b5ce..c3a47291 100644 --- a/src/lib/graph/component-class.c +++ b/src/lib/graph/component-class.c @@ -1,40 +1,17 @@ /* + * SPDX-License-Identifier: MIT + * * Copyright 2017-2018 Philippe Proulx * Copyright 2016 Jérémie Galarneau - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. */ #define BT_LOG_TAG "LIB/COMPONENT-CLASS" #include "lib/logging.h" #include "common/assert.h" -#include "lib/assert-pre.h" +#include "lib/assert-cond.h" #include "compat/compiler.h" #include -#include -#include -#include -#include -#include -#include -#include #include #include @@ -42,8 +19,9 @@ #include "lib/func-status.h" #include "lib/graph/message-iterator-class.h" -#define BT_ASSERT_PRE_DEV_COMP_CLS_HOT(_cc) \ - BT_ASSERT_PRE_DEV_HOT(((const struct bt_component_class *) (_cc)), \ +#define BT_ASSERT_PRE_DEV_COMP_CLS_HOT(_cc) \ + BT_ASSERT_PRE_DEV_HOT("component-class", \ + ((const struct bt_component_class *) (_cc)), \ "Component class", ": %!+C", (_cc)) static @@ -94,22 +72,13 @@ void destroy_component_class(struct bt_object *obj) class->destroy_listeners = NULL; } - if (class->type == BT_COMPONENT_CLASS_TYPE_SOURCE) { - struct bt_component_class_source *class_src - = container_of(class, struct bt_component_class_source, - parent); - - BT_ASSERT(class_src->msg_iter_cls); - bt_message_iterator_class_put_ref(class_src->msg_iter_cls); - class_src->msg_iter_cls = NULL; - } else if (class->type == BT_COMPONENT_CLASS_TYPE_FILTER) { - struct bt_component_class_filter *class_flt - = container_of(class, struct bt_component_class_filter, - parent); - - BT_ASSERT(class_flt->msg_iter_cls); - bt_message_iterator_class_put_ref(class_flt->msg_iter_cls); - class_flt->msg_iter_cls = NULL; + if (bt_component_class_has_message_iterator_class(class)) { + struct bt_component_class_with_iterator_class *class_with_iter_class = + container_of(class, struct bt_component_class_with_iterator_class, parent); + + BT_ASSERT(class_with_iter_class->msg_iter_cls); + bt_message_iterator_class_put_ref(class_with_iter_class->msg_iter_cls); + class_with_iter_class->msg_iter_cls = NULL; } g_free(class); @@ -164,6 +133,27 @@ end: return ret; } +static +int bt_component_class_with_iterator_class_init( + struct bt_component_class_with_iterator_class *class, + enum bt_component_class_type type, const char *name, + struct bt_message_iterator_class *message_iterator_class) +{ + int ret; + + ret = bt_component_class_init(&class->parent, type, name); + if (ret != 0) { + goto end; + } + + class->msg_iter_cls = message_iterator_class; + bt_message_iterator_class_get_ref(class->msg_iter_cls); + bt_message_iterator_class_freeze(class->msg_iter_cls); + +end: + return ret; +} + struct bt_component_class_source *bt_component_class_source_create( const char *name, struct bt_message_iterator_class *message_iterator_class) @@ -172,8 +162,8 @@ struct bt_component_class_source *bt_component_class_source_create( int ret; BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(name, "Name"); - BT_ASSERT_PRE_NON_NULL(message_iterator_class, "Message iterator class"); + BT_ASSERT_PRE_NAME_NON_NULL(name); + BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class); BT_LIB_LOGI("Creating source component class: " "name=\"%s\", %![msg-iter-cls-]+I", name, message_iterator_class); @@ -185,8 +175,8 @@ struct bt_component_class_source *bt_component_class_source_create( } /* bt_component_class_init() logs errors */ - ret = bt_component_class_init(&source_class->parent, - BT_COMPONENT_CLASS_TYPE_SOURCE, name); + ret = bt_component_class_with_iterator_class_init(&source_class->parent, + BT_COMPONENT_CLASS_TYPE_SOURCE, name, message_iterator_class); if (ret) { /* * If bt_component_class_init() fails, the component @@ -197,10 +187,6 @@ struct bt_component_class_source *bt_component_class_source_create( goto end; } - source_class->msg_iter_cls = message_iterator_class; - bt_message_iterator_class_get_ref(source_class->msg_iter_cls); - bt_message_iterator_class_freeze(source_class->msg_iter_cls); - BT_LIB_LOGI("Created source component class: %!+C", source_class); end: @@ -215,8 +201,8 @@ struct bt_component_class_filter *bt_component_class_filter_create( int ret; BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(name, "Name"); - BT_ASSERT_PRE_NON_NULL(message_iterator_class, "Message iterator class"); + BT_ASSERT_PRE_NAME_NON_NULL(name); + BT_ASSERT_PRE_MSG_ITER_CLS_NON_NULL(message_iterator_class); BT_LIB_LOGI("Creating filter component class: " "name=\"%s\", %![msg-iter-cls-]+I", name, message_iterator_class); @@ -228,8 +214,8 @@ struct bt_component_class_filter *bt_component_class_filter_create( } /* bt_component_class_init() logs errors */ - ret = bt_component_class_init(&filter_class->parent, - BT_COMPONENT_CLASS_TYPE_FILTER, name); + ret = bt_component_class_with_iterator_class_init(&filter_class->parent, + BT_COMPONENT_CLASS_TYPE_FILTER, name, message_iterator_class); if (ret) { /* * If bt_component_class_init() fails, the component @@ -240,10 +226,6 @@ struct bt_component_class_filter *bt_component_class_filter_create( goto end; } - filter_class->msg_iter_cls = message_iterator_class; - bt_message_iterator_class_get_ref(filter_class->msg_iter_cls); - bt_message_iterator_class_freeze(filter_class->msg_iter_cls); - BT_LIB_LOGI("Created filter component class: %!+C", filter_class); end: @@ -257,8 +239,8 @@ struct bt_component_class_sink *bt_component_class_sink_create( int ret; BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(name, "Name"); - BT_ASSERT_PRE_NON_NULL(method, "Consume next method"); + BT_ASSERT_PRE_NAME_NON_NULL(name); + BT_ASSERT_PRE_NON_NULL("consume-method", method, "Consume next method"); BT_LOGI("Creating sink component class: " "name=\"%s\", consume-method-addr=%p", name, method); @@ -295,8 +277,8 @@ bt_component_class_source_set_get_supported_mip_versions_method( bt_component_class_source_get_supported_mip_versions_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.get_supported_mip_versions = method; BT_LIB_LOGD("Set source component class's \"get supported MIP versions\" method: " @@ -310,8 +292,8 @@ bt_component_class_filter_set_get_supported_mip_versions_method( bt_component_class_filter_get_supported_mip_versions_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.get_supported_mip_versions = method; BT_LIB_LOGD("Set filter component class's \"get supported MIP versions\" method: " @@ -325,8 +307,8 @@ bt_component_class_sink_set_get_supported_mip_versions_method( bt_component_class_sink_get_supported_mip_versions_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.get_supported_mip_versions = method; BT_LIB_LOGD("Set sink component class's \"get supported MIP versions\" method: " @@ -340,8 +322,8 @@ bt_component_class_source_set_initialize_method( bt_component_class_source_initialize_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.init = method; BT_LIB_LOGD("Set source component class's initialization method: " @@ -355,8 +337,8 @@ bt_component_class_filter_set_initialize_method( bt_component_class_filter_initialize_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.init = method; BT_LIB_LOGD("Set filter component class's initialization method: " @@ -370,8 +352,8 @@ bt_component_class_sink_set_initialize_method( bt_component_class_sink_initialize_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.init = method; BT_LIB_LOGD("Set sink component class's initialization method: " @@ -385,8 +367,8 @@ bt_component_class_source_set_finalize_method( bt_component_class_source_finalize_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.finalize = method; BT_LIB_LOGD("Set source component class's finalization method: " @@ -400,8 +382,8 @@ bt_component_class_filter_set_finalize_method( bt_component_class_filter_finalize_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.finalize = method; BT_LIB_LOGD("Set filter component class's finalization method: " @@ -415,8 +397,8 @@ bt_component_class_sink_set_finalize_method( bt_component_class_sink_finalize_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.finalize = method; BT_LIB_LOGD("Set sink component class's finalization method: " @@ -430,8 +412,8 @@ bt_component_class_source_set_query_method( bt_component_class_source_query_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.query = method; BT_LIB_LOGD("Set source component class's query method: " @@ -445,8 +427,8 @@ bt_component_class_filter_set_query_method( bt_component_class_filter_query_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.query = method; BT_LIB_LOGD("Set filter component class's query method: " @@ -460,8 +442,8 @@ bt_component_class_sink_set_query_method( bt_component_class_sink_query_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.query = method; BT_LIB_LOGD("Set sink component class's query method: " @@ -475,8 +457,8 @@ bt_component_class_filter_set_input_port_connected_method( bt_component_class_filter_input_port_connected_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.input_port_connected = method; BT_LIB_LOGD("Set filter component class's \"input port connected\" method" @@ -490,8 +472,8 @@ bt_component_class_sink_set_input_port_connected_method( bt_component_class_sink_input_port_connected_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.input_port_connected = method; BT_LIB_LOGD("Set sink component class's \"input port connected\" method" @@ -505,8 +487,8 @@ bt_component_class_source_set_output_port_connected_method( bt_component_class_source_output_port_connected_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.output_port_connected = method; BT_LIB_LOGD("Set source component class's \"output port connected\" method" @@ -520,8 +502,8 @@ bt_component_class_filter_set_output_port_connected_method( bt_component_class_filter_output_port_connected_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.output_port_connected = method; BT_LIB_LOGD("Set filter component class's \"output port connected\" method" @@ -535,8 +517,8 @@ bt_component_class_sink_set_graph_is_configured_method( bt_component_class_sink_graph_is_configured_method method) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(method, "Method"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_METHOD_NON_NULL(method); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); comp_cls->methods.graph_is_configured = method; BT_LIB_LOGD("Set sink component class's \"graph is configured\" method" @@ -550,15 +532,15 @@ bt_component_class_set_description( const char *description) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(description, "Description"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_DESCR_NON_NULL(description); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); g_string_assign(comp_cls->description, description); BT_LIB_LOGD("Set component class's description: " "addr=%p, name=\"%s\", type=%s", comp_cls, bt_component_class_get_name(comp_cls), - bt_component_class_type_string(comp_cls->type)); + bt_common_component_class_type_string(comp_cls->type)); return BT_FUNC_STATUS_OK; } @@ -567,8 +549,8 @@ enum bt_component_class_set_help_status bt_component_class_set_help( const char *help) { BT_ASSERT_PRE_NO_ERROR(); - BT_ASSERT_PRE_NON_NULL(comp_cls, "Component class"); - BT_ASSERT_PRE_NON_NULL(help, "Help"); + BT_ASSERT_PRE_COMP_CLS_NON_NULL(comp_cls); + BT_ASSERT_PRE_NON_NULL("help-text", help, "Help text"); BT_ASSERT_PRE_DEV_COMP_CLS_HOT(comp_cls); g_string_assign(comp_cls->help, help); BT_LIB_LOGD("Set component class's help text: %!+C", comp_cls); @@ -577,21 +559,21 @@ enum bt_component_class_set_help_status bt_component_class_set_help( const char *bt_component_class_get_name(const struct bt_component_class *comp_cls) { - BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls); return comp_cls->name->str; } enum bt_component_class_type bt_component_class_get_type( const struct bt_component_class *comp_cls) { - BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls); return comp_cls->type; } const char *bt_component_class_get_description( const struct bt_component_class *comp_cls) { - BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls); return comp_cls->description && comp_cls->description->str[0] != '\0' ? comp_cls->description->str : NULL; @@ -600,7 +582,7 @@ const char *bt_component_class_get_description( const char *bt_component_class_get_help( const struct bt_component_class *comp_cls) { - BT_ASSERT_PRE_DEV_NON_NULL(comp_cls, "Component class"); + BT_ASSERT_PRE_DEV_COMP_CLS_NON_NULL(comp_cls); return comp_cls->help && comp_cls->help->str[0] != '\0' ? comp_cls->help->str : NULL; }