From 1a45e79b942373471dbfcda434f97ba95e5d7ceb Mon Sep 17 00:00:00 2001 From: Jiwan Kim Date: Wed, 7 Jun 2017 11:24:45 +0900 Subject: [PATCH] Change 'Connect' as asynchronous method - Call asynchronousely 'Connect' method - Add 'mesh_connected' signal for response. It would be notified when state reaches 'Ready' from connman. --- include/mesh-request.h | 1 + introspection/mesh.xml | 3 +++ src/mesh-gdbus.c | 41 ++++++++++++++++++++++++++++------------- src/mesh-request.c | 7 +++++++ 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/include/mesh-request.h b/include/mesh-request.h index 1cb8565..5afb019 100644 --- a/include/mesh-request.h +++ b/include/mesh-request.h @@ -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); diff --git a/introspection/mesh.xml b/introspection/mesh.xml index d0a65db..3ed8faf 100644 --- a/introspection/mesh.xml +++ b/introspection/mesh.xml @@ -111,6 +111,9 @@ + + + diff --git a/src/mesh-gdbus.c b/src/mesh-gdbus.c index d55f866..a128641 100644 --- a/src/mesh-gdbus.c +++ b/src/mesh-gdbus.c @@ -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) diff --git a/src/mesh-request.c b/src/mesh-request.c index c8719f5..cd7f1d0 100644 --- a/src/mesh-request.c +++ b/src/mesh-request.c @@ -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(); -- 2.7.4