[WiFi][Connection] Apply CAPIs for thread handling (#134)
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.WiFi / Tizen.Network.WiFi / WiFiManager.cs
index 5767956..96d613c 100755 (executable)
 
 using System;
 using System.Collections.Generic;
+using System.Runtime.InteropServices;
 using System.Threading.Tasks;
+using System.ComponentModel;
 
 namespace Tizen.Network.WiFi
 {
     /// <summary>
-    /// A manager class which allows applications to connect to a Wireless Local Area Network (WLAN) and to transfer data over the network.<br>
+    /// A class for managing the WiFiManager handle.
+    /// </summary>
+    /// <since_tizen> 3 </since_tizen>
+    [EditorBrowsable(EditorBrowsableState.Never)]
+    public sealed class SafeWiFiManagerHandle : SafeHandle
+    {
+        private int tid;
+
+        internal SafeWiFiManagerHandle() : base(IntPtr.Zero, true)
+        {
+        }
+
+        /// <summary>
+        /// Checks the validity of the handle.
+        /// </summary>
+        /// <value>Represents the validity of the handle.</value>
+        /// <since_tizen> 3 </since_tizen>
+        public override bool IsInvalid
+        {
+            get
+            {
+                return this.handle == IntPtr.Zero;
+            }
+        }
+
+        /// <summary>
+        /// Release the handle
+        /// </summary>
+        protected override bool ReleaseHandle()
+        {
+            Interop.WiFi.Deinitialize(tid, this.handle);
+            this.SetHandle(IntPtr.Zero);
+            return true;
+        }
+
+        internal int TID
+        {
+            set
+            {
+                tid = value;
+                Log.Info(Globals.LogTag, "New Handle for Thread " + tid);
+            }
+        }
+    }
+
+    /// <summary>
+    /// A manager class which allows applications to connect to a Wireless Local Area Network (WLAN) and transfer data over the network.
     /// The Wi-Fi Manager enables your application to activate and deactivate a local Wi-Fi device, and to connect to a WLAN network in the infrastructure mode.
     /// </summary>
+    /// <since_tizen> 3 </since_tizen>
     static public class WiFiManager
     {
         /// <summary>
         /// The local MAC address.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Represents the MAC address of the Wi-Fi.</value>
+        /// <privilege>http://tizen.org/privilege/network.get</privilege>
         static public string MacAddress
         {
             get
@@ -40,6 +92,9 @@ namespace Tizen.Network.WiFi
         /// <summary>
         /// The name of the network interface.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Interface name of the Wi-Fi.</value>
+        /// <privilege>http://tizen.org/privilege/network.get</privilege>
         static public string InterfaceName
         {
             get
@@ -51,6 +106,9 @@ namespace Tizen.Network.WiFi
         /// <summary>
         /// The network connection state.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Represents the connection state of the Wi-Fi.</value>
+        /// <privilege>http://tizen.org/privilege/network.get</privilege>
         static public WiFiConnectionState ConnectionState
         {
             get
@@ -60,8 +118,11 @@ namespace Tizen.Network.WiFi
         }
 
         /// <summary>
-        /// A property to Check whether Wi-Fi is activated.
+        /// A property to check whether Wi-Fi is activated.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Boolean value to check whether Wi-Fi is activated or not.</value>
+        /// <privilege>http://tizen.org/privilege/network.get</privilege>
         static public bool IsActive
         {
             get
@@ -73,6 +134,9 @@ namespace Tizen.Network.WiFi
         /// <summary>
         /// DeviceStateChanged is raised when the device state is changed.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/network.get</privilege>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
         static public event EventHandler<DeviceStateChangedEventArgs> DeviceStateChanged
         {
             add
@@ -88,6 +152,9 @@ namespace Tizen.Network.WiFi
         /// <summary>
         /// ConnectionStateChanged is raised when the connection state is changed.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/network.get</privilege>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
         static public event EventHandler<ConnectionStateChangedEventArgs> ConnectionStateChanged
         {
             add
@@ -101,8 +168,11 @@ namespace Tizen.Network.WiFi
         }
 
         /// <summary>
-        /// RssiLevelChanged is raised when the RSSI of connected Wi-Fi is changed.
+        /// RssiLevelChanged is raised when the RSSI of the connected Wi-Fi is changed.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/network.get</privilege>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
         static public event EventHandler<RssiLevelChangedEventArgs> RssiLevelChanged
         {
             add
@@ -117,8 +187,11 @@ namespace Tizen.Network.WiFi
 
         /// <summary>
         /// BackgroundScanFinished is raised when the background scan is finished.
-        /// The background scan starts automatically when wifi is activated. The callback will be invoked periodically.
+        /// The background scan starts automatically when Wi-Fi is activated. The callback will be invoked periodically.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <privilege>http://tizen.org/privilege/network.get</privilege>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
         static public event EventHandler BackgroundScanFinished
         {
             add
@@ -132,36 +205,84 @@ namespace Tizen.Network.WiFi
         }
 
         /// <summary>
+        /// Gets the Wi-Fi safe handle.
+        /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <returns>The instance of the SafeWiFiManagerHandle.</returns>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <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 the permission is denied.</exception>
+        /// <exception cref="OutOfMemoryException">Thrown when the system is out of memory.</exception>
+        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static SafeWiFiManagerHandle GetWiFiHandle()
+        {
+            return WiFiManagerImpl.Instance.GetSafeHandle();
+        }
+
+        /// <summary>
         /// Gets the result of the scan.
         /// </summary>
-        /// <returns> A list of WiFiAP objects.</returns>
+        /// <since_tizen> 3 </since_tizen>
+        /// <returns>A list of the WiFiAP objects.</returns>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <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 the permission is denied.</exception>
+        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public IEnumerable<WiFiAP> GetFoundAPs()
         {
             return WiFiManagerImpl.Instance.GetFoundAPs();
         }
 
         /// <summary>
-        /// Gets the result of specific AP scan.
+        /// Gets the result of ScanSpecificAPAsync(string essid) API.
         /// </summary>
-        /// <returns> A list contains the WiFiAP objects.</returns>
+        /// <since_tizen> 3 </since_tizen>
+        /// <returns>A list containing the WiFiAP objects.</returns>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <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 the permission is denied.</exception>
+        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public IEnumerable<WiFiAP> GetFoundSpecificAPs()
         {
             return WiFiManagerImpl.Instance.GetFoundSpecificAPs();
         }
 
         /// <summary>
-        /// Gets the list of wifi configurations.
+        /// Gets the list of Wi-Fi configurations.
         /// </summary>
-        /// <returns>A list contains the WiFiConfiguration objects.</returns>
+        /// <since_tizen> 3 </since_tizen>
+        /// <returns>A list containing the WiFiConfiguration objects.</returns>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <privilege>http://tizen.org/privilege/network.profile</privilege>
+        /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
+        /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
+        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public IEnumerable<WiFiConfiguration> GetWiFiConfigurations()
         {
             return WiFiManagerImpl.Instance.GetWiFiConfigurations();
         }
 
         /// <summary>
-        /// Saves Wi-Fi configuration of access point.
+        /// Saves the Wi-Fi configuration of the access point.
         /// </summary>
-        /// <param name="configuration">The configuration to be stored</param>
+        /// <since_tizen> 3 </since_tizen>
+        /// <param name="configuration">The configuration to be stored.</param>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <privilege>http://tizen.org/privilege/network.profile</privilege>
+        /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</exception>
+        /// <exception cref="UnauthorizedAccessException">Thrown when the permission is denied.</exception>
+        /// <exception cref="ArgumentNullException">Thrown when WiFiConfiguration is passed as null.</exception>
+        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public void SaveWiFiConfiguration(WiFiConfiguration configuration)
         {
             WiFiManagerImpl.Instance.SaveWiFiNetworkConfiguration(configuration);
@@ -170,53 +291,101 @@ namespace Tizen.Network.WiFi
         /// <summary>
         /// Gets the object of the connected WiFiAP.
         /// </summary>
-        /// <returns> The connected wifi access point(AP) information.</returns>
+        /// <since_tizen> 3 </since_tizen>
+        /// <returns>The connected Wi-Fi access point (AP) information.</returns>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <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 the permission is denied.</exception>
+        /// <exception cref="OutOfMemoryException">Thrown when system is out of memory.</exception>
+        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public WiFiAP GetConnectedAP()
         {
             return WiFiManagerImpl.Instance.GetConnectedAP();
         }
 
         /// <summary>
-        /// Activates Wi-Fi asynchronously.
+        /// Activates the Wi-Fi asynchronously.
         /// </summary>
-        /// <returns> A task indicating whether the Activate method is done or not.</returns>
+        /// <since_tizen> 3 </since_tizen>
+        /// <returns> A task indicating whether the activate method is done or not.</returns>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <privilege>http://tizen.org/privilege/network.set</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 the permission is denied.</exception>
+        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public Task ActivateAsync()
         {
             return WiFiManagerImpl.Instance.ActivateAsync();
         }
 
         /// <summary>
-        /// Activates Wi-Fi asynchronously and displays Wi-Fi picker (popup) when Wi-Fi is not automatically connected.
+        /// Activates the Wi-Fi asynchronously and displays the Wi-Fi picker (popup) when the Wi-Fi is not automatically connected.
         /// </summary>
-        /// <returns> A task indicating whether the ActivateWithPicker method is done or not.</returns>
+        /// <since_tizen> 3 </since_tizen>
+        /// <returns>A task indicating whether the ActivateWithPicker method is done or not.</returns>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <privilege>http://tizen.org/privilege/network.set</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 the permission is denied.</exception>
+        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public Task ActivateWithPickerAsync()
         {
             return WiFiManagerImpl.Instance.ActivateWithWiFiPickerTestedAsync();
         }
 
         /// <summary>
-        /// Deactivates Wi-Fi asynchronously.
+        /// Deactivates the Wi-Fi asynchronously.
         /// </summary>
-        /// <returns> A task indicating whether the Deactivate method is done or not.</returns>
+        /// <since_tizen> 3 </since_tizen>
+        /// <returns>A task indicating whether the deactivate method is done or not.</returns>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <privilege>http://tizen.org/privilege/network.set</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 the permission is denied.</exception>
+        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public Task DeactivateAsync()
         {
             return WiFiManagerImpl.Instance.DeactivateAsync();
         }
 
         /// <summary>
-        /// Starts scan asynchronously.
+        /// Starts the scan asynchronously.
         /// </summary>
-        /// <returns> A task indicating whether the Scan method is done or not.</returns>
+        /// <since_tizen> 3 </since_tizen>
+        /// <returns>A task indicating whether the scan method is done or not.</returns>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <privilege>http://tizen.org/privilege/network.set</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 the permission is denied.</exception>
+        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public Task ScanAsync()
         {
             return WiFiManagerImpl.Instance.ScanAsync();
         }
 
         /// <summary>
-        /// Starts specific access point scan, asynchronously.
+        /// Starts a specific access point scan asynchronously.
         /// </summary>
-        /// <returns> A task indicating whether the ScanSpecificAP method is done or not.</returns>
-        /// <param name="essid">The essid of hidden ap</param>
+        /// <since_tizen> 3 </since_tizen>
+        /// <returns>A task indicating whether the ScanSpecificAP method is done or not.</returns>
+        /// <param name="essid">The ESSID of the hidden AP.</param>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <privilege>http://tizen.org/privilege/network.set</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 the permission is denied.</exception>
+        /// <exception cref="ArgumentException">Thrown when the method failed due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         static public Task ScanSpecificAPAsync(string essid)
         {
             return WiFiManagerImpl.Instance.ScanSpecificAPAsync(essid);