lib: use `enum bt_port_status` where possible
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Mon, 17 Jul 2017 00:51:02 +0000 (20:51 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 10 Aug 2017 19:57:33 +0000 (15:57 -0400)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/graph/port.h
include/babeltrace/graph/private-port.h
lib/graph/port.c

index ebe33e556499696fead64aa5b964daedb7d52e87..d08e27478ba9578bf71b2ba8a42402a7b569b185 100644 (file)
@@ -53,7 +53,7 @@ extern const char *bt_port_get_name(struct bt_port *port);
 extern enum bt_port_type bt_port_get_type(struct bt_port *port);
 extern struct bt_connection *bt_port_get_connection(struct bt_port *port);
 extern struct bt_component *bt_port_get_component(struct bt_port *port);
-extern int bt_port_disconnect(struct bt_port *port);
+extern enum bt_port_status bt_port_disconnect(struct bt_port *port);
 extern bt_bool bt_port_is_connected(struct bt_port *port);
 
 static inline
index 8148f0a4a877867530d30ff25e40c1f750352ddd..e228594cdf936ad179f84a4ae8d5d19791c8de75 100644 (file)
@@ -37,7 +37,7 @@ extern struct bt_private_connection *bt_private_port_get_private_connection(
                struct bt_private_port *private_port);
 extern struct bt_private_component *bt_private_port_get_private_component(
                struct bt_private_port *private_port);
-extern int bt_private_port_remove_from_component(
+extern enum bt_port_status bt_private_port_remove_from_component(
                struct bt_private_port *private_port);
 extern void *bt_private_port_get_user_data(
                struct bt_private_port *private_port);
index 944e1cd4d859b4e08c711e1d5347a4c029fb5e31..60f88a33b943be80b15fbca2e001256d3aaafedf 100644 (file)
@@ -169,36 +169,48 @@ void bt_port_set_connection(struct bt_port *port,
                port, bt_port_get_name(port), connection);
 }
 
-int bt_private_port_remove_from_component(
+enum bt_port_status bt_private_port_remove_from_component(
                struct bt_private_port *private_port)
 {
-       int ret = 0;
+       enum bt_port_status status = BT_PORT_STATUS_OK;
        struct bt_port *port = bt_port_from_private(private_port);
        struct bt_component *comp = NULL;
+       enum bt_component_status comp_status;
 
        if (!port) {
                BT_LOGW_STR("Invalid parameter: private port is NULL.");
-               ret = -1;
+               status = BT_PORT_STATUS_INVALID;
                goto end;
        }
 
        comp = (void *) bt_object_get_parent(port);
+       if (!comp) {
+               BT_LOGV("Port already removed from its component: "
+                       "port-addr=%p, port-name=\"%s\", ",
+                       port, bt_port_get_name(port));
+               goto end;
+       }
 
        /* bt_component_remove_port() logs details */
-       ret = bt_component_remove_port(comp, port);
+       comp_status = bt_component_remove_port(comp, port);
+       assert(comp_status != BT_COMPONENT_STATUS_INVALID);
+       if (comp_status < 0) {
+               status = BT_PORT_STATUS_ERROR;
+               goto end;
+       }
 
 end:
        bt_put(comp);
-       return ret;
+       return status;
 }
 
-int bt_port_disconnect(struct bt_port *port)
+enum bt_port_status bt_port_disconnect(struct bt_port *port)
 {
-       int ret = 0;
+       enum bt_port_status status = BT_PORT_STATUS_OK;
 
        if (!port) {
                BT_LOGW_STR("Invalid parameter: port is NULL.");
-               ret = -1;
+               status = BT_PORT_STATUS_INVALID;
                goto end;
        }
 
@@ -210,7 +222,7 @@ int bt_port_disconnect(struct bt_port *port)
        }
 
 end:
-       return ret;
+       return status;
 }
 
 bt_bool bt_port_is_connected(struct bt_port *port)
This page took 0.027904 seconds and 4 git commands to generate.