X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=lib%2Fgraph%2Fcomponent.c;h=6494f64883128ccb3ce0d81c5e1ac7ab305ed3bc;hb=68b66a256a54d32992dfefeaad11eea88b7df234;hp=53c9cd6defa4a12d9cac248e78ac4073e49b200e;hpb=5badd463e184894a3bfd5b8db257efc6f92c6374;p=babeltrace.git diff --git a/lib/graph/component.c b/lib/graph/component.c index 53c9cd6d..6494f648 100644 --- a/lib/graph/component.c +++ b/lib/graph/component.c @@ -22,29 +22,29 @@ */ #define BT_LOG_TAG "COMP" -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include @@ -190,12 +190,14 @@ enum bt_component_class_type bt_component_get_class_type( } static -struct bt_port *add_port( +enum bt_self_component_status add_port( struct bt_component *component, GPtrArray *ports, - enum bt_port_type port_type, const char *name, void *user_data) + enum bt_port_type port_type, const char *name, void *user_data, + struct bt_port **port) { struct bt_port *new_port = NULL; struct bt_graph *graph = NULL; + enum bt_self_component_status status; BT_ASSERT_PRE_NON_NULL(component, "Component"); BT_ASSERT_PRE_NON_NULL(name, "Name"); @@ -218,7 +220,8 @@ struct bt_port *add_port( new_port = bt_port_create(component, port_type, name, user_data); if (!new_port) { BT_LOGE_STR("Cannot create port object."); - goto end; + status = BT_SELF_COMPONENT_STATUS_NOMEM; + goto error; } /* @@ -232,18 +235,34 @@ struct bt_port *add_port( /* * Notify the graph's creator that a new port was added. */ - bt_object_get_ref(bt_component_borrow_graph(component)); graph = bt_component_borrow_graph(component); if (graph) { - bt_graph_notify_port_added(graph, new_port); - BT_OBJECT_PUT_REF_AND_RESET(graph); + enum bt_graph_listener_status listener_status; + + listener_status = bt_graph_notify_port_added(graph, new_port); + if (listener_status != BT_GRAPH_LISTENER_STATUS_OK) { + bt_graph_make_faulty(graph); + status = listener_status; + goto error; + } } BT_LIB_LOGD("Created and added port to component: " "%![comp-]+c, %![port-]+p", component, new_port); + *port = new_port; + status = BT_SELF_COMPONENT_STATUS_OK; + + goto end; +error: + /* + * We need to release the reference that we would otherwise have + * returned to the caller. + */ + BT_PORT_PUT_REF_AND_RESET(new_port); + end: - return new_port; + return status; } BT_HIDDEN @@ -331,7 +350,7 @@ const char *bt_component_get_name(const struct bt_component *component) return component->name->str; } -struct bt_component_class *bt_component_borrow_class( +const struct bt_component_class *bt_component_borrow_class_const( const struct bt_component *component) { BT_ASSERT_PRE_NON_NULL(component, "Component"); @@ -436,25 +455,23 @@ struct bt_port_output *bt_component_borrow_output_port_by_index( } BT_HIDDEN -struct bt_port_input *bt_component_add_input_port( +enum bt_self_component_status bt_component_add_input_port( struct bt_component *component, const char *name, - void *user_data) + void *user_data, struct bt_port **port) { /* add_port() logs details */ - return (void *) - add_port(component, component->input_ports, - BT_PORT_TYPE_INPUT, name, user_data); + return add_port(component, component->input_ports, + BT_PORT_TYPE_INPUT, name, user_data, port); } BT_HIDDEN -struct bt_port_output *bt_component_add_output_port( +enum bt_self_component_status bt_component_add_output_port( struct bt_component *component, const char *name, - void *user_data) + void *user_data, struct bt_port **port) { /* add_port() logs details */ - return (void *) - add_port(component, component->output_ports, - BT_PORT_TYPE_OUTPUT, name, user_data); + return add_port(component, component->output_ports, + BT_PORT_TYPE_OUTPUT, name, user_data, port); } BT_HIDDEN