[TCSACR-160] Add ForgetAPAsync (#332)
authorchleun-moon <32117100+chleun-moon@users.noreply.github.com>
Tue, 17 Jul 2018 23:56:24 +0000 (08:56 +0900)
committertaesubkim <35015408+taesubkim@users.noreply.github.com>
Tue, 17 Jul 2018 23:56:24 +0000 (08:56 +0900)
src/Tizen.Network.WiFi/Interop/Interop.WiFi.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs

index c23461d8170a78a85dcbdff471c1a582e6243c08..448dce8d4d3651b6c2eb4958d3f6016cb8ff516b 100755 (executable)
@@ -86,6 +86,8 @@ internal static partial class Interop
         internal static extern int CancelWps(SafeWiFiManagerHandle wifi);
         [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_forget_ap")]
         internal static extern int RemoveAP(SafeWiFiManagerHandle wifi, IntPtr ap);
+        [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_forget_ap_async")]
+        internal static extern int ForgetAP(SafeWiFiManagerHandle wifi, IntPtr ap, VoidCallback callback, IntPtr userData);
         [DllImport(Libraries.WiFi, EntryPoint = "wifi_manager_update_ap")]
         internal static extern int UpdateAP(SafeWiFiManagerHandle wifi, IntPtr ap);
 
index 72ecd2b27f285a70ff9d74c94574a94558696f0e..b5be8a3b3d8b5ed48d13e38f4bd826f3dec1ee1a 100644 (file)
@@ -622,6 +622,79 @@ namespace Tizen.Network.WiFi
             }
         }
 
+        /// <summary>
+        /// Deletes the information of a stored access point and disconnects it when the AP is connected asyncronously.
+        /// If an AP is connected, then the connection information will be stored. This information is used when a connection to that AP is established automatically.
+        /// </summary>
+        /// <returns> A task indicating whether the disconnect method is done or not.</returns>
+        /// <remarks>
+        /// This method must be called from MainThread.
+        /// </remarks>
+        /// <since_tizen> 5 </since_tizen>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <privilege>http://tizen.org/privilege/network.profile</privilege>
+        /// <privilege>http://tizen.org/privilege/network.get</privilege>
+        /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when permission is denied.</exception>
+        /// <exception cref="ObjectDisposedException">Thrown when the object instance is disposed or released.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
+        public Task ForgetAPAsync()
+        {
+            Log.Debug(Globals.LogTag, "ForgetAPAsync");
+            if (_disposed)
+            {
+                throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)");
+            }
+            TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
+            IntPtr id;
+            lock (_callback_map)
+            {
+                id = (IntPtr)_requestId++;
+                _callback_map[id] = (error, key) =>
+                {
+                    Log.Info(Globals.LogTag, "ForgetAPAsync done");
+                    if (error != (int)WiFiError.None)
+                    {
+                        Log.Error(Globals.LogTag, "Error occurs during WiFi disconnecting, " + (WiFiError)error);
+                        task.SetException(new InvalidOperationException("Error occurs during WiFi disconnecting, " + (WiFiError)error));
+                    }
+                    else
+                    {
+                        task.SetResult(true);
+                    }
+                    lock (_callback_map)
+                    {
+                        _callback_map.Remove(key);
+                    }
+                };
+            }
+
+            context.Post((x) =>
+            {
+                Log.Info(Globals.LogTag, "Interop.WiFi.ForgetAP");
+                try
+                {
+                    int ret = Interop.WiFi.ForgetAP(WiFiManagerImpl.Instance.GetSafeHandle(), _apHandle, _callback_map[id], id);
+                    if (ret != (int)WiFiError.None)
+                    {
+                        Log.Error(Globals.LogTag, "Failed to forget wifi, Error - " + (WiFiError)ret);
+                        if (ret == (int)WiFiError.InvalidParameterError)
+                        {
+                            throw new InvalidOperationException("Invalid handle");
+                        }
+                        WiFiErrorFactory.ThrowWiFiException(ret, WiFiManagerImpl.Instance.GetSafeHandle().DangerousGetHandle(), _apHandle);
+                    }
+                }
+                catch (Exception e)
+                {
+                    Log.Error(Globals.LogTag, "Exception on ForgetAPAsync\n" + e.ToString());
+                    task.SetException(e);
+                }
+            }, null);
+
+            return task.Task;
+        }
+
         /// <summary>
         /// Update the information of a stored access point.
         /// When a AP information is changed, the change will not be applied until this method is called.