common: move bt_component_class_type_string here, use it more
[babeltrace.git] / src / lib / graph / component-class.c
index 1c1497db4c6e24981aa28ad40e690b139bc98825..c3a47291ca0ec86d739e7169d0654015bc36a9fc 100644 (file)
@@ -1,40 +1,17 @@
 /*
+ * SPDX-License-Identifier: MIT
+ *
  * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
  * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * 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 <babeltrace2/graph/component-class.h>
-#include <babeltrace2/graph/component-class-const.h>
-#include <babeltrace2/graph/component-class-source.h>
-#include <babeltrace2/graph/component-class-source-const.h>
-#include <babeltrace2/graph/component-class-filter.h>
-#include <babeltrace2/graph/component-class-filter-const.h>
-#include <babeltrace2/graph/component-class-sink.h>
-#include <babeltrace2/graph/component-class-sink-const.h>
 #include <babeltrace2/types.h>
 #include <glib.h>
 
@@ -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
@@ -184,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);
@@ -223,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);
@@ -261,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);
@@ -299,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: "
@@ -314,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: "
@@ -329,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: "
@@ -344,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: "
@@ -359,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: "
@@ -374,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: "
@@ -389,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: "
@@ -404,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: "
@@ -419,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: "
@@ -434,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: "
@@ -449,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: "
@@ -464,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: "
@@ -479,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"
@@ -494,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"
@@ -509,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"
@@ -524,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"
@@ -539,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"
@@ -554,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;
 }
 
@@ -571,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);
@@ -581,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;
@@ -604,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;
 }
This page took 0.029299 seconds and 4 git commands to generate.