Handle error return code
authorJiwan Kim <ji-wan.kim@samsung.com>
Wed, 14 Jun 2017 10:12:28 +0000 (19:12 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 17 Jul 2017 02:35:37 +0000 (11:35 +0900)
- Change to return valid return code on repeated call.
  mesh_enable_mesh
  mesh_disable_mesh
- Change policy of return code
  mesh_cancel_scan
  mesh_disable_softap
- Add method
  mesh_is_joined

include/mesh-interface.h
introspection/mesh.xml
src/mesh-gdbus.c
src/mesh-interface.c
src/mesh-request.c
src/mesh-service-interface.c

index 288d947..3ef8899 100644 (file)
@@ -29,8 +29,10 @@ int mesh_interface_set(const char* interface, const char* ip_addr,
                mesh_set_interface_type_e type);
 //int mesh_interface_set_mac_addr(const char* interface, const char* mac_addr);
 int mesh_interface_initialize(mesh_interface_s *info);
+int mesh_interface_check(const char* interface);
 int mesh_interface_check_external_exists(
                const char* external_interface, bool *state);
+int mesh_interface_check_bridge_interface_exists(const char* bridge, const char* interface);
 char* mesh_interface_get_address(const char* if_name);
 
 #endif /* __MESH_INTERFACE_H__ */
index 8eec274..519d46f 100644 (file)
                <method name="disable_mesh">\r
                        <arg type="i" name="result" direction="out"/>\r
                </method>\r
+               <method name="is_joined">\r
+                       <arg type="b" name="state" direction="out"/>\r
+                       <arg type="i" name="result" direction="out"/>\r
+               </method>\r
                <method name="get_joined_mesh_network">\r
                        <arg type="s" name="mesh_id" direction="out"/>\r
                        <arg type="s" name="bssid" direction="out"/>\r
index 209e0ff..82b4af8 100644 (file)
@@ -420,6 +420,7 @@ int mesh_gdbus_create_mesh_interface(mesh_service *service)
 
 int mesh_gdbus_remove_mesh_interface(mesh_service *service)
 {
+       int ret = MESHD_ERROR_NONE;
        GVariant *variant = NULL;
        GError *error = NULL;
        GVariant *var_dict = NULL;
@@ -445,12 +446,16 @@ int mesh_gdbus_remove_mesh_interface(mesh_service *service)
        if (variant) {
                MESH_LOGD("Successfully requested. [MeshInterfaceRemove]");
        } else if (error) {
+               ret = MESHD_ERROR_IO_ERROR;
                MESH_LOGE("Failed DBus call [%s]", error->message);
+
+               /* Interface not exists (Not created yet) */
+               if (g_strrstr(error->message, "No such device"))
+                       ret = MESHD_ERROR_NONE;
                g_error_free(error);
-               return MESHD_ERROR_IO_ERROR;
        }
 
-       return MESHD_ERROR_NONE;
+       return ret;
 }
 
 int mesh_gdbus_mesh_scan(mesh_service *service)
@@ -509,6 +514,7 @@ int mesh_gdbus_mesh_specific_scan(mesh_service *service, gchar *mesh_id, gint ch
 
 int mesh_gdbus_mesh_cancel_scan(mesh_service *service)
 {
+       int ret = MESHD_ERROR_NONE;
        GVariant *variant = NULL;
        GError *error = NULL;
        GVariant *var_dict = NULL;
@@ -530,12 +536,17 @@ int mesh_gdbus_mesh_cancel_scan(mesh_service *service)
        if (variant) {
                MESH_LOGD("Successfully requested. [AbortScan]");
        } else if (error) {
+               ret = MESHD_ERROR_IO_ERROR;
                MESH_LOGE("Failed DBus call [%s]", error->message);
+
+               /* Scan is not in progress */
+               if (g_strrstr(error->message, "Already exists"))
+                       ret = MESHD_ERROR_NONE;
+               
                g_error_free(error);
-               return MESHD_ERROR_IO_ERROR;
        }
 
-       return MESHD_ERROR_NONE;
+       return ret;
 }
 
 static void _on_scan_result_destroy(gpointer data)
index 0a9f4b7..15ee3a3 100644 (file)
@@ -183,7 +183,6 @@ static char* _get_interface_not_exists_in_seq(const char* prefix)
 }
 #endif
 
-/* Returns interface name in sequence order which is exists */
 static bool _check_interface_exists(const char* if_name)
 {
        int ret;
@@ -204,6 +203,27 @@ static bool _check_interface_exists(const char* if_name)
        return false;
 }
 
+/* Check if interface is bridged */
+static bool _check_bridge_interface_exists(const char* bridge, const char* if_name)
+{
+       int ret;
+       char buf[32];
+       int i = 0;
+       const int IF_INDEX_MAX = 9;
+
+       for (i = 0; i <= IF_INDEX_MAX; i++) {
+               snprintf(buf, sizeof(buf), "/sys/class/net/%s/brif/%s", bridge, if_name);
+
+               ret = access(buf, F_OK);
+               if (ret >= 0) {
+                       /* This name is exists. */
+                       return true;
+               }
+       }
+
+       return false;
+}
+
 char* mesh_interface_get_address(const char* if_name)
 {
        FILE *pf;
@@ -340,3 +360,36 @@ int mesh_interface_check_external_exists(const char* external_interface, bool *s
 
        return MESHD_ERROR_NONE;
 }
+
+int mesh_interface_check(const char* interface)
+{
+       bool ex = FALSE;
+
+       if (NULL == interface || strlen(interface) == 0)
+               return MESHD_ERROR_INVALID_PARAMETER;
+
+       ex = _check_interface_exists(interface);
+       if (FALSE == ex) {
+               MESH_LOGE("Interface[%s] was not found.", interface);
+               return MESHD_ERROR_NO_DATA;
+       }
+
+       return MESHD_ERROR_NONE;
+}
+
+int mesh_interface_check_bridge_interface_exists(const char* bridge, const char* interface)
+{
+       bool ex = FALSE;
+
+       if (NULL == bridge || NULL == interface ||
+               strlen(bridge) == 0 || strlen(interface) == 0)
+               return MESHD_ERROR_INVALID_PARAMETER;
+
+       ex = _check_bridge_interface_exists(bridge, interface);
+       if (FALSE == ex) {
+               MESH_LOGE("Interface[%s] was not found.", interface);
+               return MESHD_ERROR_NO_DATA;
+       }
+
+       return MESHD_ERROR_NONE;
+}
index a15a264..0c08314 100644 (file)
@@ -145,6 +145,12 @@ int mesh_request_remove_bridge_interface(const char* bridge_interface,
 
        MESH_LOGD("Removing interface[%s] from bridge[%s]...", interface, bridge_interface);
 
+       ret = mesh_interface_check_bridge_interface_exists(bridge_interface, interface);
+       if (MESHD_ERROR_NONE != ret) {
+               MESH_LOGD("Interface is not exist in bridge");
+               return MESHD_ERROR_NONE;
+       }
+
        /* Remove external interface into bridge */
        ret = mesh_bridge_del_interface(bridge_interface, interface);
        if (MESHD_ERROR_NONE != ret) {
@@ -268,6 +274,8 @@ int mesh_request_unregister_event_handler()
 int mesh_request_enable_network(mesh_service *service)
 {
        int ret;
+       mesh_interface_s *info = NULL;
+
        if (NULL == service) {
                MESH_LOGE("Invalid parameter");
                return MESHD_ERROR_INVALID_PARAMETER;
@@ -275,6 +283,14 @@ int mesh_request_enable_network(mesh_service *service)
 
        MESH_LOGD("[IPC] Enable mesh network");
 
+       /* Check if mesh interface exists */
+       info = service->interface_info;
+       ret = mesh_interface_check(info->mesh_interface);
+       if (MESHD_ERROR_NONE == ret) {
+               /* Interface already exists */
+               return MESHD_ERROR_NONE;
+       }
+
        ret = mesh_gdbus_create_mesh_interface(service);
        if (MESHD_ERROR_NONE != ret) {
                MESH_LOGE("Failed to create mesh network");
@@ -296,7 +312,7 @@ int mesh_request_disable_network(mesh_service *service)
 
        ret = mesh_gdbus_remove_mesh_interface(service);
        if (MESHD_ERROR_NONE != ret) {
-               MESH_LOGE("Failed to create mesh network");
+               MESH_LOGE("Failed to disable mesh network");
                return ret;
        }
 
index a37fca0..c6c6544 100644 (file)
@@ -406,6 +406,25 @@ static gboolean _meshd_dbus_handle_disable_mesh(NetMesh *object,
        return TRUE;
 }
 
+static gboolean _meshd_dbus_handle_is_joined(NetMesh *object,
+               GDBusMethodInvocation *invocation,
+               gpointer user_data)
+{
+       int ret = MESHD_ERROR_NONE;
+       gboolean state = FALSE;
+       mesh_service *service = (mesh_service *)user_data;
+
+       ret = mesh_request_get_joined_network(service);
+       if (MESHD_ERROR_NONE == ret) {
+               if (service->joined_network)
+                       state = TRUE;
+       }
+
+       net_mesh_complete_is_joined(object, invocation, state, ret);
+
+       return TRUE;
+}
+
 static gboolean _meshd_dbus_handle_get_joined_mesh_network(NetMesh *object,
                GDBusMethodInvocation *invocation,
                gpointer user_data)
@@ -937,6 +956,8 @@ static void _meshd_dbus_on_bus_acquired(GDBusConnection *conn, const gchar *name
                        G_CALLBACK(_meshd_dbus_handle_enable_mesh), service);
        g_signal_connect(meshd_dbus_object, "handle-disable-mesh",
                        G_CALLBACK(_meshd_dbus_handle_disable_mesh), service);
+       g_signal_connect(meshd_dbus_object, "handle-is-joined",
+                       G_CALLBACK(_meshd_dbus_handle_is_joined), service);
        g_signal_connect(meshd_dbus_object, "handle-get-joined-mesh-network",
                        G_CALLBACK(_meshd_dbus_handle_get_joined_mesh_network), service);
        g_signal_connect(meshd_dbus_object, "handle-get-connected-peers",