Return component port counts by parameter
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 23 Feb 2017 14:36:05 +0000 (09:36 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:38 +0000 (12:57 -0400)
The rest of the API separates the return of success/error from
the return of the item count. This change makes the component
API consistent with the style used elsewhere.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/component/component-filter.h
include/babeltrace/component/component-sink.h
include/babeltrace/component/component-source.h
lib/component/filter.c
lib/component/graph.c
lib/component/sink.c
lib/component/source.c

index 08dde198c0326f85e108e39b90a361a3284226f7..cda188eb2f874c444ef005b001c1701d9f54fb8d 100644 (file)
@@ -38,8 +38,8 @@ struct bt_port;
 struct bt_component;
 struct bt_notification_iterator;
 
-extern int bt_component_filter_get_input_port_count(
-               struct bt_component *component);
+extern enum bt_component_status bt_component_filter_get_input_port_count(
+               struct bt_component *component, uint64_t *count);
 extern struct bt_port *bt_component_filter_get_input_port(
                struct bt_component *component, const char *name);
 extern struct bt_port *bt_component_filter_get_input_port_at_index(
@@ -47,8 +47,8 @@ extern struct bt_port *bt_component_filter_get_input_port_at_index(
 extern struct bt_port *bt_component_filter_get_default_input_port(
                struct bt_component *component);
 
-extern int bt_component_filter_get_output_port_count(
-               struct bt_component *component);
+extern enum bt_component_status bt_component_filter_get_output_port_count(
+               struct bt_component *component, uint64_t *count);
 extern struct bt_port *bt_component_filter_get_output_port(
                struct bt_component *component, const char *name);
 extern struct bt_port *bt_component_filter_get_output_port_at_index(
index ff79c09edd3ca0f14f9191462378ea33ef6ef2fd..d9072c3b2bde6427ccc63766a439764050e8e440 100644 (file)
@@ -36,8 +36,8 @@ extern "C" {
 struct bt_component;
 struct bt_notification;
 
-extern int bt_component_sink_get_input_port_count(
-               struct bt_component *component);
+extern enum bt_component_status bt_component_sink_get_input_port_count(
+               struct bt_component *component, uint64_t *count);
 extern struct bt_port *bt_component_sink_get_input_port(
                struct bt_component *component, const char *name);
 extern struct bt_port *bt_component_sink_get_input_port_at_index(
index 7bea78da22837a379fd0dbc879226509aa08dce6..628786c3db533680479071e88510d02db1616ab0 100644 (file)
@@ -37,9 +37,8 @@ extern "C" {
 struct bt_component;
 struct bt_notification_iterator;
 
-/* FIXME should return a bt_component_status, same applies for filter and sink. Use uint64_t. */
-extern int bt_component_source_get_output_port_count(
-               struct bt_component *component);
+extern enum bt_component_status bt_component_source_get_output_port_count(
+               struct bt_component *component, uint64_t *count);
 extern struct bt_port *bt_component_source_get_output_port(
                struct bt_component *component, const char *name);
 extern struct bt_port *bt_component_source_get_output_port_at_index(
index da59cc21d82081f81ad69c82d7aed02445f36bb7..8abd5a6d38c2b1be421fdd0547ec9faf83266315 100644 (file)
@@ -127,25 +127,26 @@ end:
        return ret;
 }
 
-int bt_component_filter_get_input_port_count(struct bt_component *component)
+enum bt_component_status bt_component_filter_get_input_port_count(
+               struct bt_component *component, uint64_t *count)
 {
-       int ret;
+       enum bt_component_status status = BT_COMPONENT_STATUS_OK;
        struct bt_component_filter *filter;
 
-       if (!component) {
-               ret = -1;
+       if (!component || !count) {
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
        if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
-               ret = -1;
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
        filter = container_of(component, struct bt_component_filter, parent);
-       ret = filter->input_ports->len;
+       *count = (uint64_t) filter->input_ports->len;
 end:
-       return ret;
+       return status;
 }
 
 struct bt_port *bt_component_filter_get_input_port(
@@ -227,25 +228,26 @@ end:
        return status;
 }
 
-int bt_component_filter_get_output_port_count(struct bt_component *component)
+enum bt_component_status bt_component_filter_get_output_port_count(
+               struct bt_component *component, uint64_t *count)
 {
-       int ret;
+       enum bt_component_status status = BT_COMPONENT_STATUS_OK;
        struct bt_component_filter *filter;
 
-       if (!component) {
-               ret = -1;
+       if (!component || !count) {
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
        if (component->class->type != BT_COMPONENT_CLASS_TYPE_FILTER) {
-               ret = -1;
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
        filter = container_of(component, struct bt_component_filter, parent);
-       ret = filter->output_ports->len;
+       *count = (uint64_t) filter->output_ports->len;
 end:
-       return ret;
+       return status;
 }
 
 struct bt_port *bt_component_filter_get_output_port(
index 4d6c2802352c8ba11224522d6e0531d3baa70097..d0ce1dfbcb79ab6ee5028cb8fee6112faa714fba 100644 (file)
@@ -189,44 +189,44 @@ error:
 }
 
 static
-int get_component_port_counts(struct bt_component *component, int *input_count,
-               int *output_count)
+enum bt_component_status get_component_port_counts(
+               struct bt_component *component, uint64_t *input_count,
+               uint64_t *output_count)
 {
-       int ret = -1;
+       enum bt_component_status ret;
 
        switch (bt_component_get_class_type(component)) {
        case BT_COMPONENT_CLASS_TYPE_SOURCE:
-               ret = bt_component_source_get_output_port_count(component);
-               if (ret < 0) {
+               ret = bt_component_source_get_output_port_count(component,
+                               output_count);
+               if (ret != BT_COMPONENT_STATUS_OK) {
                        goto end;
                }
-               *output_count = ret;
                break;
        case BT_COMPONENT_CLASS_TYPE_FILTER:
-               ret = bt_component_filter_get_output_port_count(component);
-               if (ret < 0) {
+               ret = bt_component_filter_get_output_port_count(component,
+                               output_count);
+               if (ret != BT_COMPONENT_STATUS_OK) {
                        goto end;
                }
-               *output_count = ret;
-               break;
-               ret = bt_component_filter_get_input_port_count(component);
-               if (ret < 0) {
+               ret = bt_component_filter_get_input_port_count(component,
+                               input_count);
+               if (ret != BT_COMPONENT_STATUS_OK) {
                        goto end;
                }
-               *input_count = ret;
                break;
        case BT_COMPONENT_CLASS_TYPE_SINK:
-               ret = bt_component_sink_get_input_port_count(component);
-               if (ret < 0) {
+               ret = bt_component_sink_get_input_port_count(component,
+                               input_count);
+               if (ret != BT_COMPONENT_STATUS_OK) {
                        goto end;
                }
-               *input_count = ret;
                break;
        default:
                assert(false);
                break;
        }
-       ret = 0;
+       ret = BT_COMPONENT_STATUS_OK;
 end:
        return ret;
 }
@@ -275,10 +275,10 @@ enum bt_graph_status bt_graph_add_component_as_sibling(struct bt_graph *graph,
                struct bt_component *origin,
                struct bt_component *new_component)
 {
-       int origin_input_port_count = 0;
-       int origin_output_port_count = 0;
-       int new_input_port_count = 0;
-       int new_output_port_count = 0;
+       uint64_t origin_input_port_count = 0;
+       uint64_t origin_output_port_count = 0;
+       uint64_t new_input_port_count = 0;
+       uint64_t new_output_port_count = 0;
        enum bt_graph_status status = BT_GRAPH_STATUS_OK;
        struct bt_graph *origin_graph = NULL;
        struct bt_graph *new_graph = NULL;
@@ -314,12 +314,12 @@ enum bt_graph_status bt_graph_add_component_as_sibling(struct bt_graph *graph,
        }
 
        if (get_component_port_counts(origin, &origin_input_port_count,
-                       &origin_output_port_count)) {
+                       &origin_output_port_count) != BT_COMPONENT_STATUS_OK) {
                status = BT_GRAPH_STATUS_INVALID;
                goto end;
        }
        if (get_component_port_counts(new_component, &new_input_port_count,
-                       &new_output_port_count)) {
+                       &new_output_port_count) != BT_COMPONENT_STATUS_OK) {
                status = BT_GRAPH_STATUS_INVALID;
                goto end;
        }
index e6c890c650547e29104bdab084410e46c762e8b2..e516d325a1a3d83e8822b27f9c85bbf0edea2c81 100644 (file)
@@ -163,25 +163,26 @@ end:
 }
 */
 
-int bt_component_sink_get_input_port_count(struct bt_component *component)
+enum bt_component_status bt_component_sink_get_input_port_count(
+               struct bt_component *component, uint64_t *count)
 {
-       int ret;
+       enum bt_component_status status = BT_COMPONENT_STATUS_OK;
        struct bt_component_sink *sink;
 
-       if (!component) {
-               ret = -1;
+       if (!component || !count) {
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
        if (component->class->type != BT_COMPONENT_CLASS_TYPE_SINK) {
-               ret = -1;
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
        sink = container_of(component, struct bt_component_sink, parent);
-       ret = sink->input_ports->len;
+       *count = (uint64_t) sink->input_ports->len;
 end:
-       return ret;
+       return status;
 }
 
 struct bt_port *bt_component_sink_get_input_port(
index e0c717b3d9390450147d9453a55c9a15bfaa424b..8b5de6b6178161f28e946e99f0d1e5aaf5ec1c5f 100644 (file)
@@ -116,25 +116,26 @@ struct bt_notification_iterator *bt_component_source_create_notification_iterato
        return bt_component_create_iterator(component, init_method_data);
 }
 
-int bt_component_source_get_output_port_count(struct bt_component *component)
+enum bt_component_status bt_component_source_get_output_port_count(
+               struct bt_component *component, uint64_t *count)
 {
-       int ret;
+       enum bt_component_status status = BT_COMPONENT_STATUS_OK;
        struct bt_component_source *source;
 
-       if (!component) {
-               ret = -1;
+       if (!component || !count) {
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
        if (component->class->type != BT_COMPONENT_CLASS_TYPE_SOURCE) {
-               ret = -1;
+               status = BT_COMPONENT_STATUS_INVALID;
                goto end;
        }
 
        source = container_of(component, struct bt_component_source, parent);
-       ret = source->output_ports->len;
+       *count = (uint64_t) source->output_ports->len;
 end:
-       return ret;
+       return status;
 }
 
 struct bt_port *bt_component_source_get_output_port(
This page took 0.031276 seconds and 4 git commands to generate.