From 3bfc4924fe7c8f5846b9aee4443cc974fb82e7c5 Mon Sep 17 00:00:00 2001 From: saerome kim Date: Tue, 22 Aug 2017 19:15:01 +0900 Subject: [PATCH] Added new CAPI to check if mesh is started Change-Id: I8396e619bbc854e89b0598d0ed298b70957a26b1 Signed-off-by: Saurav Babu --- include/wifi-mesh.h | 21 +++++++++++++++++++++ include/wifi-mesh_dbus.h | 1 + src/wifi-mesh-dbus.c | 40 ++++++++++++++++++++++++++++++++++++++++ src/wifi-mesh.c | 16 ++++++++++++++++ test/wifi-mesh-network.c | 14 ++++++++++++++ 5 files changed, 92 insertions(+) diff --git a/include/wifi-mesh.h b/include/wifi-mesh.h index 07d1799..fbfea15 100644 --- a/include/wifi-mesh.h +++ b/include/wifi-mesh.h @@ -803,6 +803,27 @@ int wifi_mesh_start(wifi_mesh_h handle); int wifi_mesh_stop(wifi_mesh_h handle); /** + * @brief Get the Wi-Fi mesh enable state. + * @details Check if mesh is enabled in current device. + * + * @since_tizen 4.0 + * + * @param[in] handle The Wi-Fi mesh handle + * @param[out] is_started The state of mesh. + * + * + * @return 0 on success, otherwise a negative error value. + * @retval #WIFI_MESH_ERROR_NONE Successful + * @retval #WIFI_MESH_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WIFI_MESH_ERROR_IO_ERROR Unexpected d-bus error + * + * @see wifi_mesh_start() + * @see wifi_mesh_stop() + * + */ +int wifi_mesh_is_started(wifi_mesh_h handle, bool *is_started); + +/** * @brief Get the Wi-Fi mesh connection state. * @details Check if current device is joined Wi-Fi mesh network. * diff --git a/include/wifi-mesh_dbus.h b/include/wifi-mesh_dbus.h index 1e5e225..16dc20d 100644 --- a/include/wifi-mesh_dbus.h +++ b/include/wifi-mesh_dbus.h @@ -51,6 +51,7 @@ int _wifi_mesh_foreach_connected_peers(wifi_mesh_h handle, wifi_mesh_connected_peer_cb cb, void *user_data); int _wifi_mesh_enable_mesh(wifi_mesh_h handle); int _wifi_mesh_disable_mesh(wifi_mesh_h handle); +int _wifi_mesh_is_started(wifi_mesh_h handle, bool* is_started); int _wifi_mesh_is_joined(wifi_mesh_h handle, bool* is_joined); int _mesh_get_joined_mesh_network(wifi_mesh_h handle, wifi_mesh_network_h* _network); int _wifi_mesh_set_gate(wifi_mesh_h handle, bool gate_announce, int hwmp_root_mode, bool stp); diff --git a/src/wifi-mesh-dbus.c b/src/wifi-mesh-dbus.c index fcf74d9..aa7711f 100644 --- a/src/wifi-mesh-dbus.c +++ b/src/wifi-mesh-dbus.c @@ -1000,6 +1000,46 @@ int _wifi_mesh_disable_mesh(wifi_mesh_h handle) return result; } +int _wifi_mesh_is_started(wifi_mesh_h handle, bool* is_started) +{ + GVariant *variant = NULL; + GError *error = NULL; + gboolean state; + struct mesh_handle *h = handle; + + if (NULL == h) { + /* LCOV_EXCL_START */ + LOGE("Invaild parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + if (NULL == h->dbus_connection || NULL == _gproxy_mesh_service) { + /* LCOV_EXCL_START */ + LOGE("I/O error"); + return WIFI_MESH_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ + } + + variant = g_dbus_proxy_call_sync(_gproxy_mesh_service, "is_mesh_enabled", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, + NULL, &error); + if (variant) { + g_variant_get(variant, "(b)", &state); + *is_started = ((state) ? true : false); + } else if (error) { + /* LCOV_EXCL_START */ + LOGE("Failed DBus call [%s]", error->message); + g_error_free(error); + return WIFI_MESH_ERROR_IO_ERROR; + /* LCOV_EXCL_STOP */ + } + + return WIFI_MESH_ERROR_NONE; +} + /* TODO: Parameter verification required */ int _wifi_mesh_is_joined(wifi_mesh_h handle, bool* is_joined) { diff --git a/src/wifi-mesh.c b/src/wifi-mesh.c index 70ec7a8..b5de9fd 100644 --- a/src/wifi-mesh.c +++ b/src/wifi-mesh.c @@ -571,6 +571,22 @@ EXPORT_API int wifi_mesh_stop(wifi_mesh_h handle) return rv; } +EXPORT_API int wifi_mesh_is_started(wifi_mesh_h handle, bool *is_started) +{ + int rv = 0; + CHECK_FEATURE_SUPPORTED(MESH_FEATURE); + + if (NULL == handle || is_started == NULL) { + /* LCOV_EXCL_START */ + LOGE("Invalid parameter"); + return WIFI_MESH_ERROR_INVALID_PARAMETER; + /* LCOV_EXCL_STOP */ + } + + rv = _wifi_mesh_is_started(handle, is_started); + return rv; +} + EXPORT_API int wifi_mesh_is_joined(wifi_mesh_h handle, bool* is_joined) { int rv = 0; diff --git a/test/wifi-mesh-network.c b/test/wifi-mesh-network.c index e5945a9..0d6b153 100644 --- a/test/wifi-mesh-network.c +++ b/test/wifi-mesh-network.c @@ -410,6 +410,20 @@ static int run_wifi_mesh_cancel_scan(MManager *mm, struct menu_data *menu) static int run_wifi_mesh_enable(MManager *mm, struct menu_data *menu) { int ret; + bool is_started; + + ret = wifi_mesh_is_started(mesh, &is_started); + if (WIFI_MESH_ERROR_NONE != ret) { + msgr("Failed to check mesh started: [%s(0x%X)]", + wifi_mesh_error_to_string(ret), ret); + return RET_FAILURE; + } + + if (is_started == true) { + msg("Mesh is already enabled"); + return RET_SUCCESS; + } + msg("Enable Mesh"); ret = wifi_mesh_start(mesh); -- 2.7.4