src.ctf.fs: remove unused parameter from ctf_fs_component_create
[babeltrace.git] / src / lib / graph / component.c
index 14653172c9f0b4c47a0047ada268417e14fd1922..7b592b5031808935d0e05d4f0342f35989b6a65d 100644 (file)
 #include "lib/func-status.h"
 
 static
-struct bt_component * (* const component_create_funcs[])(
-               const struct bt_component_class *) = {
+struct bt_component * (* const component_create_funcs[])(void) = {
        [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_create,
        [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_create,
        [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_create,
 };
 
-static
-void (*component_destroy_funcs[])(struct bt_component *) = {
-       [BT_COMPONENT_CLASS_TYPE_SOURCE] = bt_component_source_destroy,
-       [BT_COMPONENT_CLASS_TYPE_SINK] = bt_component_sink_destroy,
-       [BT_COMPONENT_CLASS_TYPE_FILTER] = bt_component_filter_destroy,
-};
-
 static
 void finalize_component(struct bt_component *comp)
 {
@@ -133,7 +125,7 @@ void destroy_component(struct bt_object *obj)
 
        for (i = component->destroy_listeners->len - 1; i >= 0; i--) {
                struct bt_component_destroy_listener *listener =
-                       &g_array_index(component->destroy_listeners,
+                       &bt_g_array_index(component->destroy_listeners,
                                struct bt_component_destroy_listener, i);
 
                listener->func(component, listener->data);
@@ -148,11 +140,6 @@ void destroy_component(struct bt_object *obj)
                finalize_component(component);
        }
 
-       if (component->destroy) {
-               BT_LOGD_STR("Destroying type-specific data.");
-               component->destroy(component);
-       }
-
        if (component->input_ports) {
                BT_LOGD_STR("Destroying input ports.");
                g_ptr_array_free(component->input_ports, TRUE);
@@ -188,18 +175,46 @@ enum bt_component_class_type bt_component_get_class_type(
        return component->class->type;
 }
 
+static
+bool port_name_is_unique(GPtrArray *ports, const char *name)
+{
+       guint i;
+       bool unique;
+
+       for (i = 0; i < ports->len; i++) {
+               struct bt_port *port = g_ptr_array_index(ports, i);
+
+               if (strcmp(port->name->str, name) == 0) {
+                       unique = false;
+                       goto end;
+               }
+       }
+
+       unique = true;
+
+end:
+       return unique;
+}
+
 static
 enum bt_self_component_add_port_status add_port(
                struct bt_component *component, GPtrArray *ports,
                enum bt_port_type port_type, const char *name, void *user_data,
-               struct bt_port **port, const char *api_func)
+               struct bt_port **port, const char *api_func, bool input)
 {
        struct bt_port *new_port = NULL;
        struct bt_graph *graph = NULL;
        enum bt_self_component_add_port_status status;
 
-       BT_ASSERT(component);
-       BT_ASSERT(name);
+       BT_ASSERT_PRE_NO_ERROR_FROM_FUNC(api_func);
+       BT_ASSERT_PRE_COMP_NON_NULL_FROM_FUNC(api_func, component);
+       BT_ASSERT_PRE_NAME_NON_NULL_FROM_FUNC(api_func, name);
+       BT_ASSERT_PRE_FROM_FUNC(api_func,
+               input ? "input" : "output" "-port-name-is-unique",
+               port_name_is_unique(component->output_ports, name),
+               input ? "Input" : "Output"
+                       " port name is not unique: name=\"%s\", %![comp-]c",
+               name, component);
        BT_ASSERT_PRE_FROM_FUNC(api_func, "name-is-not-empty",
                strlen(name) > 0, "Name is empty");
        graph = bt_component_borrow_graph(component);
@@ -208,8 +223,6 @@ enum bt_self_component_add_port_status add_port(
                "Component's graph is already configured: "
                "%![comp-]+c, %![graph-]+g", component, graph);
 
-       // TODO: Validate that the name is not already used.
-
        BT_LIB_LOGI("Adding port to component: %![comp-]+c, "
                "port-type=%s, port-name=\"%s\"", component,
                bt_port_type_string(port_type), name);
@@ -291,7 +304,7 @@ int bt_component_create(struct bt_component_class *component_class,
        BT_LIB_LOGI("Creating empty component from component class: %![cc-]+C, "
                "comp-name=\"%s\", log-level=%s", component_class, name,
                bt_common_logging_level_string(log_level));
-       component = component_create_funcs[type](component_class);
+       component = component_create_funcs[type]();
        if (!component) {
                BT_LIB_LOGE_APPEND_CAUSE(
                        "Cannot create specific component object.");
@@ -302,7 +315,6 @@ int bt_component_create(struct bt_component_class *component_class,
        bt_object_init_shared_with_parent(&component->base, destroy_component);
        component->class = component_class;
        bt_object_get_ref_no_null_check(component->class);
-       component->destroy = component_destroy_funcs[type];
        component->name = g_string_new(name);
        if (!component->name) {
                BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate one GString.");
@@ -454,16 +466,9 @@ enum bt_self_component_add_port_status bt_component_add_input_port(
                struct bt_component *component, const char *name,
                void *user_data, struct bt_port **port, const char *api_func)
 {
-       BT_ASSERT_PRE_COMP_NON_NULL_FROM_FUNC(api_func, component);
-       BT_ASSERT_PRE_NAME_NON_NULL_FROM_FUNC(api_func, name);
-       BT_ASSERT_PRE_FROM_FUNC(api_func, "input-port-name-is-unique",
-               bt_component_port_name_is_unique(component->input_ports, name),
-               "Input port name is not unique: name=\"%s\", %![comp-]c",
-               name, component);
-
        /* add_port() logs details and checks preconditions */
        return add_port(component, component->input_ports,
-               BT_PORT_TYPE_INPUT, name, user_data, port, api_func);
+               BT_PORT_TYPE_INPUT, name, user_data, port, api_func, true);
 }
 
 enum bt_self_component_add_port_status bt_component_add_output_port(
@@ -471,36 +476,9 @@ enum bt_self_component_add_port_status bt_component_add_output_port(
                void *user_data, struct bt_port **port,
                const char *api_func)
 {
-       BT_ASSERT_PRE_COMP_NON_NULL_FROM_FUNC(api_func, component);
-       BT_ASSERT_PRE_NAME_NON_NULL_FROM_FUNC(api_func, name);
-       BT_ASSERT_PRE_FROM_FUNC(api_func, "output-port-name-is-unique",
-               bt_component_port_name_is_unique(component->output_ports, name),
-               "Output port name is not unique: name=\"%s\", %![comp-]c",
-               name, component);
-
        /* add_port() logs details and checks preconditions */
        return add_port(component, component->output_ports,
-               BT_PORT_TYPE_OUTPUT, name, user_data, port, api_func);
-}
-
-bool bt_component_port_name_is_unique(GPtrArray *ports, const char *name)
-{
-       guint i;
-       bool unique;
-
-       for (i = 0; i < ports->len; i++) {
-               struct bt_port *port = g_ptr_array_index(ports, i);
-
-               if (strcmp(port->name->str, name) == 0) {
-                       unique = false;
-                       goto end;
-               }
-       }
-
-       unique = true;
-
-end:
-       return unique;
+               BT_PORT_TYPE_OUTPUT, name, user_data, port, api_func, false);
 }
 
 enum bt_component_class_port_connected_method_status
@@ -618,7 +596,7 @@ void bt_component_remove_destroy_listener(struct bt_component *component,
 
        for (i = 0; i < component->destroy_listeners->len; i++) {
                struct bt_component_destroy_listener *listener =
-                       &g_array_index(component->destroy_listeners,
+                       &bt_g_array_index(component->destroy_listeners,
                                struct bt_component_destroy_listener, i);
 
                if (listener->func == func && listener->data == data) {
This page took 0.024598 seconds and 4 git commands to generate.