Added new CAPI to check if mesh is started 60/145460/1
authorsaerome kim <saerome.kim@samsung.com>
Tue, 22 Aug 2017 10:15:01 +0000 (19:15 +0900)
committersaerome kim <saerome.kim@samsung.com>
Tue, 22 Aug 2017 10:15:01 +0000 (19:15 +0900)
Change-Id: I8396e619bbc854e89b0598d0ed298b70957a26b1
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
include/wifi-mesh.h
include/wifi-mesh_dbus.h
src/wifi-mesh-dbus.c
src/wifi-mesh.c
test/wifi-mesh-network.c

index 07d1799..fbfea15 100644 (file)
@@ -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.
  *
index 1e5e225..16dc20d 100644 (file)
@@ -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);
index fcf74d9..aa7711f 100644 (file)
@@ -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)
 {
index 70ec7a8..b5de9fd 100644 (file)
@@ -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;
index e5945a9..0d6b153 100644 (file)
@@ -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);