Change 'Connect' as asynchronous method
authorJiwan Kim <ji-wan.kim@samsung.com>
Wed, 7 Jun 2017 02:24:45 +0000 (11:24 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 17 Jul 2017 02:35:36 +0000 (11:35 +0900)
- Call asynchronousely 'Connect' method
- Add 'mesh_connected' signal for response.
  It would be notified when state reaches 'Ready' from connman.

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

index 1cb8565..5afb019 100644 (file)
@@ -97,6 +97,7 @@ int mesh_request_unregister_event_handler();
 void mesh_notify_scan_done();
 void mesh_notify_joined_network();
 void mesh_notify_left_network();
+void mesh_notify_mesh_connected(int result);
 void mesh_notify_station_joined(const char* bssid);
 void mesh_notify_station_left(const char* bssid);
 
index d0a65db..3ed8faf 100644 (file)
                </signal>\r
                <signal name="left_network">\r
                </signal>\r
+               <signal name="mesh_connected">\r
+                       <arg type="i" name="result" direction="out"/>\r
+               </signal>\r
                <signal name="sta_joined">\r
                        <arg type="s" name="bssid" direction="out"/>\r
                </signal>\r
index d55f866..a128641 100644 (file)
@@ -815,23 +815,17 @@ int mesh_ipc_create_network(mesh_service *service, gchar *mesh_id, gint channel,
        return MESHD_ERROR_NONE;
 }
 
-int mesh_ipc_connect_network(mesh_service *service, mesh_scan_result_s *info)
+static void on_response_connect_network(GObject *source_object,
+       GAsyncResult *res, gpointer user_data)
 {
        int ret = MESHD_ERROR_NONE;
-       GVariant *variant = NULL;
        GError *error = NULL;
+       GVariant *variant = NULL;
 
-       meshd_check_null_ret_error("service", service, MESHD_ERROR_INVALID_PARAMETER);
-       meshd_check_null_ret_error("info", info, MESHD_ERROR_INVALID_PARAMETER);
+       NOTUSED(user_data);
 
-       variant = g_dbus_connection_call_sync(service->connection,
-                       CONNMAN_SERVER_NAME,
-                       info->object_path,
-                       CONNMAN_INTERFACE_MESH,
-                       "Connect",
-                       NULL, NULL,
-                       G_DBUS_CALL_FLAGS_NONE,
-                       -1, NULL, &error);
+       variant = g_dbus_connection_call_finish(
+                       G_DBUS_CONNECTION(source_object), res, &error);
        if (variant) {
                MESH_LOGD("Successfully requested. [Connect]");
        } else if (error) {
@@ -840,13 +834,34 @@ int mesh_ipc_connect_network(mesh_service *service, mesh_scan_result_s *info)
 
                if (g_strrstr(error->message, "Already exists"))
                        ret = MESHD_ERROR_ALREADY_REGISTERED;
+               else if (g_strrstr(error->message, "In progress"))
+                       ret = MESHD_ERROR_IN_PROGRESS;
                else
                        ret = MESHD_ERROR_IO_ERROR;
 
                g_error_free(error);
        }
 
-       return ret;
+       mesh_notify_mesh_connected(ret);
+}
+
+int mesh_ipc_connect_network(mesh_service *service, mesh_scan_result_s *info)
+{
+       meshd_check_null_ret_error("service", service, MESHD_ERROR_INVALID_PARAMETER);
+       meshd_check_null_ret_error("info", info, MESHD_ERROR_INVALID_PARAMETER);
+
+       g_dbus_connection_call(service->connection,
+                       CONNMAN_SERVER_NAME,
+                       info->object_path,
+                       CONNMAN_INTERFACE_MESH,
+                       "Connect",
+                       NULL, NULL,
+                       G_DBUS_CALL_FLAGS_NONE,
+                       MESH_DBUS_PROXY_TIMEOUT * 2, /* Waits for long time */
+                       NULL,
+                       on_response_connect_network, service);
+
+       return MESHD_ERROR_NONE;
 }
 
 int mesh_ipc_disconnect_network(mesh_service *service, mesh_scan_result_s *info)
index c8719f5..cd7f1d0 100644 (file)
@@ -986,6 +986,13 @@ void mesh_notify_left_network()
        net_mesh_emit_left_network(object);
 }
 
+void mesh_notify_mesh_connected(int result)
+{
+       NetMesh *object = meshd_dbus_get_object();
+
+       net_mesh_emit_mesh_connected(object, result);
+}
+
 void mesh_notify_station_joined(const char* bssid)
 {
        NetMesh *object = meshd_dbus_get_object();