X-Git-Url: https://git.efficios.com/?a=blobdiff_plain;f=lib%2Fgraph%2Ffilter.c;h=67beb4cd7c367a883efc3ab924f3c27fd8bf48ac;hb=36712f1d9ad9269638e493ca36a50979fe4da989;hp=f7d2961800e4ed5867402b0d3efa0a30900ca495;hpb=544d0515ffa2d011247e4f1d7cad5770b8ec7033;p=babeltrace.git diff --git a/lib/graph/filter.c b/lib/graph/filter.c index f7d29618..67beb4cd 100644 --- a/lib/graph/filter.c +++ b/lib/graph/filter.c @@ -26,6 +26,9 @@ * SOFTWARE. */ +#define BT_LOG_TAG "COMP-FILTER" +#include + #include #include #include @@ -33,6 +36,7 @@ #include #include #include +#include BT_HIDDEN void bt_component_filter_destroy(struct bt_component *component) @@ -41,12 +45,13 @@ void bt_component_filter_destroy(struct bt_component *component) BT_HIDDEN struct bt_component *bt_component_filter_create( - struct bt_component_class *class, struct bt_value *params) + struct bt_component_class *class) { struct bt_component_filter *filter = NULL; filter = g_new0(struct bt_component_filter, 1); if (!filter) { + BT_LOGE_STR("Failed to allocate one filter component."); goto end; } @@ -54,206 +59,317 @@ end: return filter ? &filter->parent : NULL; } -BT_HIDDEN -enum bt_component_status bt_component_filter_validate( +int64_t bt_component_filter_get_input_port_count( struct bt_component *component) { - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + int64_t ret; if (!component) { - ret = BT_COMPONENT_STATUS_INVALID; - goto end; - } - - if (!component->class) { - ret = BT_COMPONENT_STATUS_INVALID; + BT_LOGW_STR("Invalid parameter: component is NULL."); + ret = (int64_t) -1; goto end; } if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - ret = BT_COMPONENT_STATUS_INVALID; + BT_LOGW("Invalid parameter: component's class is not a filter component class: " + "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", + component, bt_component_get_name(component), + bt_component_class_type_string(component->class->type)); + ret = (int64_t) -1; goto end; } - /* Enforce iterator limits. */ + ret = (int64_t) bt_component_get_input_port_count(component); + end: return ret; } -int64_t bt_component_filter_get_input_port_count( - struct bt_component *component, uint64_t *count) +struct bt_port *bt_component_filter_get_input_port_by_name( + struct bt_component *component, const char *name) { - int64_t ret; + struct bt_port *port = NULL; - if (!component || - component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - ret = -1; + if (!component) { + BT_LOGW_STR("Invalid parameter: component is NULL."); goto end; } - ret = bt_component_get_input_port_count(component); -end: - return ret; -} - -struct bt_port *bt_component_filter_get_input_port( - struct bt_component *component, const char *name) -{ - struct bt_port *port = NULL; + if (!name) { + BT_LOGW_STR("Invalid parameter: name is NULL."); + goto end; + } - if (!component || !name || - component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + BT_LOGW("Invalid parameter: component's class is not a filter component class: " + "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", + component, bt_component_get_name(component), + bt_component_class_type_string(component->class->type)); goto end; } - port = bt_component_get_input_port(component, name); + /* bt_component_get_input_port_by_name() logs details/errors */ + port = bt_component_get_input_port_by_name(component, name); + end: return port; } -struct bt_port *bt_component_filter_get_input_port_at_index( - struct bt_component *component, int index) +struct bt_port *bt_component_filter_get_input_port_by_index( + struct bt_component *component, uint64_t index) { struct bt_port *port = NULL; - if (!component || - component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + if (!component) { + BT_LOGW_STR("Invalid parameter: component is NULL."); + goto end; + } + + if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + BT_LOGW("Invalid parameter: component's class is not a filter component class: " + "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", + component, bt_component_get_name(component), + bt_component_class_type_string(component->class->type)); goto end; } - port = bt_component_get_input_port_at_index(component, index); + /* bt_component_get_input_port_by_index() logs details/errors */ + port = bt_component_get_input_port_by_index(component, index); + end: return port; } -struct bt_port *bt_component_filter_get_default_input_port( - struct bt_component *component) -{ - return bt_component_filter_get_input_port(component, - DEFAULT_INPUT_PORT_NAME); -} - int64_t bt_component_filter_get_output_port_count( - struct bt_component *component, uint64_t *count) + struct bt_component *component) { int64_t ret; - if (!component || !count || - component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { - ret = -1; + if (!component) { + BT_LOGW_STR("Invalid parameter: component is NULL."); + ret = (int64_t) -1; goto end; } + if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + BT_LOGW("Invalid parameter: component's class is not a filter component class: " + "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", + component, bt_component_get_name(component), + bt_component_class_type_string(component->class->type)); + ret = (int64_t) -1; + goto end; + } + + /* bt_component_get_output_port_count() logs details/errors */ ret = bt_component_get_output_port_count(component); + end: return ret; } -struct bt_port *bt_component_filter_get_output_port( +struct bt_port *bt_component_filter_get_output_port_by_name( struct bt_component *component, const char *name) { struct bt_port *port = NULL; - if (!component || !name || - component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + if (!component) { + BT_LOGW_STR("Invalid parameter: component is NULL."); + goto end; + } + + if (!name) { + BT_LOGW_STR("Invalid parameter: name is NULL."); + goto end; + } + + if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + BT_LOGW("Invalid parameter: component's class is not a filter component class: " + "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", + component, bt_component_get_name(component), + bt_component_class_type_string(component->class->type)); goto end; } - port = bt_component_get_output_port(component, name); + /* bt_component_get_output_port_by_name() logs details/errors */ + port = bt_component_get_output_port_by_name(component, name); + end: return port; } -struct bt_port *bt_component_filter_get_output_port_at_index( - struct bt_component *component, int index) +struct bt_port *bt_component_filter_get_output_port_by_index( + struct bt_component *component, uint64_t index) { struct bt_port *port = NULL; - if (!component || - component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + if (!component) { + BT_LOGW_STR("Invalid parameter: component is NULL."); + goto end; + } + + if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + BT_LOGW("Invalid parameter: component's class is not a filter component class: " + "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", + component, bt_component_get_name(component), + bt_component_class_type_string(component->class->type)); goto end; } - port = bt_component_get_output_port_at_index(component, index); + /* bt_component_get_output_port_by_index() logs details/errors */ + port = bt_component_get_output_port_by_index(component, index); + end: return port; } -struct bt_port *bt_component_filter_get_default_output_port( - struct bt_component *component) -{ - return bt_component_filter_get_output_port(component, - DEFAULT_OUTPUT_PORT_NAME); -} - struct bt_private_port * -bt_private_component_filter_get_input_private_port_at_index( - struct bt_private_component *private_component, int index) +bt_private_component_filter_get_input_private_port_by_index( + struct bt_private_component *private_component, uint64_t index) { + /* bt_component_filter_get_input_port_by_index() logs details/errors */ return bt_private_port_from_port( - bt_component_filter_get_input_port_at_index( + bt_component_filter_get_input_port_by_index( bt_component_from_private(private_component), index)); } struct bt_private_port * -bt_private_component_filter_get_default_input_private_port( - struct bt_private_component *private_component) +bt_private_component_filter_get_input_private_port_by_name( + struct bt_private_component *private_component, + const char *name) { + /* bt_component_filter_get_input_port_by_name() logs details/errors */ return bt_private_port_from_port( - bt_component_filter_get_default_input_port( - bt_component_from_private(private_component))); + bt_component_filter_get_input_port_by_name( + bt_component_from_private(private_component), name)); } -struct bt_private_port *bt_private_component_filter_add_input_private_port( +enum bt_component_status bt_private_component_filter_add_input_private_port( struct bt_private_component *private_component, - const char *name) + const char *name, void *user_data, + struct bt_private_port **user_priv_port) { + enum bt_component_status status = BT_COMPONENT_STATUS_OK; struct bt_port *port = NULL; struct bt_component *component = bt_component_from_private(private_component); + struct bt_graph *graph; + + if (!component) { + BT_LOGW_STR("Invalid parameter: component is NULL."); + status = BT_COMPONENT_STATUS_INVALID; + goto end; + } - if (!component || - component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + BT_LOGW("Invalid parameter: component's class is not a filter component class: " + "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", + component, bt_component_get_name(component), + bt_component_class_type_string(component->class->type)); + status = BT_COMPONENT_STATUS_INVALID; goto end; } - port = bt_component_add_input_port(component, name); + graph = bt_component_borrow_graph(component); + + if (graph && bt_graph_is_canceled(graph)) { + BT_LOGW("Cannot add input port to filter component: graph is canceled: " + "comp-addr=%p, comp-name=\"%s\", graph-addr=%p", + component, bt_component_get_name(component), + bt_component_borrow_graph(component)); + status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED; + goto end; + } + + /* bt_component_add_input_port() logs details/errors */ + port = bt_component_add_input_port(component, name, user_data); + if (!port) { + status = BT_COMPONENT_STATUS_NOMEM; + goto end; + } + + if (user_priv_port) { + /* Move reference to user */ + *user_priv_port = bt_private_port_from_port(port); + port = NULL; + } + end: - return bt_private_port_from_port(port); + bt_put(port); + return status; } struct bt_private_port * -bt_private_component_filter_get_output_private_port_at_index( - struct bt_private_component *private_component, int index) +bt_private_component_filter_get_output_private_port_by_index( + struct bt_private_component *private_component, uint64_t index) { + /* bt_component_filter_get_output_port_by_index() logs details/errors */ return bt_private_port_from_port( - bt_component_filter_get_output_port_at_index( + bt_component_filter_get_output_port_by_index( bt_component_from_private(private_component), index)); } struct bt_private_port * -bt_private_component_filter_get_default_output_private_port( - struct bt_private_component *private_component) +bt_private_component_filter_get_output_private_port_by_name( + struct bt_private_component *private_component, + const char *name) { + /* bt_component_filter_get_output_port_by_name() logs details/errors */ return bt_private_port_from_port( - bt_component_filter_get_default_output_port( - bt_component_from_private(private_component))); + bt_component_filter_get_output_port_by_name( + bt_component_from_private(private_component), name)); } -struct bt_private_port *bt_private_component_filter_add_output_private_port( +enum bt_component_status bt_private_component_filter_add_output_private_port( struct bt_private_component *private_component, - const char *name) + const char *name, void *user_data, + struct bt_private_port **user_priv_port) { + enum bt_component_status status = BT_COMPONENT_STATUS_OK; struct bt_port *port = NULL; struct bt_component *component = bt_component_from_private(private_component); + struct bt_graph *graph; - if (!component || - component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + if (!component) { + BT_LOGW_STR("Invalid parameter: component is NULL."); + status = BT_COMPONENT_STATUS_INVALID; goto end; } - port = bt_component_add_output_port(component, name); + if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) { + BT_LOGW("Invalid parameter: component's class is not a filter component class: " + "comp-addr=%p, comp-name=\"%s\", comp-class-type=%s", + component, bt_component_get_name(component), + bt_component_class_type_string(component->class->type)); + status = BT_COMPONENT_STATUS_INVALID; + goto end; + } + + graph = bt_component_borrow_graph(component); + + if (graph && bt_graph_is_canceled(graph)) { + BT_LOGW("Cannot add output port to filter component: graph is canceled: " + "comp-addr=%p, comp-name=\"%s\", graph-addr=%p", + component, bt_component_get_name(component), + bt_component_borrow_graph(component)); + status = BT_COMPONENT_STATUS_GRAPH_IS_CANCELED; + goto end; + } + + /* bt_component_add_output_port() logs details/errors */ + port = bt_component_add_output_port(component, name, user_data); + if (!port) { + status = BT_COMPONENT_STATUS_NOMEM; + goto end; + } + + if (user_priv_port) { + /* Move reference to user */ + *user_priv_port = bt_private_port_from_port(port); + port = NULL; + } + end: - return bt_private_port_from_port(port); + bt_put(port); + return status; }