Merge "[Multimedia] Updated the doc-comments to fix the grammar errors."
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.WiFi / Tizen.Network.WiFi / WiFiNetwork.cs
index 7e94e37..d77be57 100755 (executable)
@@ -23,20 +23,21 @@ using Tizen.Network.Connection;
 namespace Tizen.Network.WiFi
 {
     /// <summary>
-    /// A class for managing the Wi-Fi information. It allows applications to manager network information.
-    /// This class is not intended to create instance directly from applications.
+    /// A class for managing the Wi-Fi network information.
     /// </summary>
-    public class WiFiNetwork : IDisposable
+    /// <since_tizen> 3 </since_tizen>
+    public class WiFiNetwork
     {
-        private IntPtr _apHandle = IntPtr.Zero;
+        private Interop.WiFi.SafeWiFiAPHandle _apHandle;
         private IAddressInformation _ipv4;
         private IAddressInformation _ipv6;
-        private bool disposed = false;
         private string _essid;
 
         /// <summary>
-        /// The Extended Service Set Identifier(ESSID).
+        /// The Extended Service Set Identifier (ESSID).
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>ESSID of the Wi-Fi.</value>
         public string Essid
         {
             get
@@ -44,7 +45,7 @@ namespace Tizen.Network.WiFi
                 if (string.IsNullOrEmpty(_essid))
                 {
                     IntPtr strPtr;
-                    int ret = Interop.WiFi.Ap.GetEssid(_apHandle, out strPtr);
+                    int ret = Interop.WiFi.AP.GetEssid(_apHandle, out strPtr);
                     if (ret != (int)WiFiError.None)
                     {
                         Log.Error(Globals.LogTag, "Failed to get essid, Error - " + (WiFiError)ret);
@@ -58,15 +59,18 @@ namespace Tizen.Network.WiFi
                 return _essid;
             }
         }
+
         /// <summary>
-        /// The Basic Service Set Identifier(BSSID).
+        /// The Basic Service Set Identifier (BSSID).
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>BSSID of the Wi-Fi.</value>
         public string Bssid
         {
             get
             {
                 IntPtr strPtr;
-                int ret = Interop.WiFi.Ap.GetBssid(_apHandle, out strPtr);
+                int ret = Interop.WiFi.AP.GetBssid(_apHandle, out strPtr);
                 if (ret != (int)WiFiError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to get bssid, Error - " + (WiFiError)ret);
@@ -75,35 +79,47 @@ namespace Tizen.Network.WiFi
                 return Marshal.PtrToStringAnsi(strPtr);
             }
         }
+
         /// <summary>
-        /// The address informaiton for Ipv4.
+        /// The address information for IPv4.
         /// </summary>
-        public IAddressInformation Ipv4Setting
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>IP address information for IPv4 type.</value>
+        public IAddressInformation IPv4Setting
         {
             get
             {
                 return _ipv4;
             }
         }
+
         /// <summary>
-        /// The address ainformation for Ipv6.
+        /// The address information for IPv6.
         /// </summary>
-        public IAddressInformation Ipv6Setting
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>IP address information for IPv6 type.</value>
+        public IAddressInformation IPv6Setting
         {
             get
             {
                 return _ipv6;
             }
         }
+
         /// <summary>
         /// The proxy address.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Represents the proxy address of the Wi-Fi.</value>
+        /// <exception cref="NotSupportedException">Thrown while setting this property when Wi-Fi is not supported.</exception>
+        /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
         public string ProxyAddress
         {
             get
             {
                 IntPtr strPtr;
-                int ret = Interop.WiFi.Ap.GetProxyAddress(_apHandle, (int)AddressFamily.Ipv4, out strPtr);
+                int ret = Interop.WiFi.AP.GetProxyAddress(_apHandle, (int)AddressFamily.IPv4, out strPtr);
                 if (ret != (int)WiFiError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to get proxy address, Error - " + (WiFiError)ret);
@@ -113,22 +129,29 @@ namespace Tizen.Network.WiFi
             }
             set
             {
-                int ret = Interop.WiFi.Ap.SetProxyAddress(_apHandle, (int)AddressFamily.Ipv4, value);
+                int ret = Interop.WiFi.AP.SetProxyAddress(_apHandle, (int)AddressFamily.IPv4, value);
                 if (ret != (int)WiFiError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to set proxy address, Error - " + (WiFiError)ret);
+                    WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
                 }
             }
         }
+
         /// <summary>
-        /// The proxy type(Ipv6).
+        /// The proxy type (IPv6).
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Represents the proxy type of the Wi-Fi.</value>
+        /// <exception cref="NotSupportedException">Thrown while setting this property when Wi-Fi is not supported.</exception>
+        /// <exception cref="ArgumentException">Thrown while setting this property due to an invalid parameter.</exception>
+        /// <exception cref="InvalidOperationException">Thrown while setting this value due to an invalid operation.</exception>
         public WiFiProxyType ProxyType
         {
             get
             {
                 int type;
-                int ret = Interop.WiFi.Ap.GetProxyType(_apHandle, out type);
+                int ret = Interop.WiFi.AP.GetProxyType(_apHandle, out type);
                 if (ret != (int)WiFiError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to get proxy type, Error - " + (WiFiError)ret);
@@ -137,22 +160,26 @@ namespace Tizen.Network.WiFi
             }
             set
             {
-                int ret = Interop.WiFi.Ap.SetProxyType(_apHandle, (int)value);
+                int ret = Interop.WiFi.AP.SetProxyType(_apHandle, (int)value);
                 if (ret != (int)WiFiError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to set proxy type, Error - " + (WiFiError)ret);
+                    WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
                 }
             }
         }
+
         /// <summary>
-        /// The frequency band(MHz).
+        /// The frequency band (MHz).
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Represents the frequency band value.</value>
         public int Frequency
         {
             get
             {
                 int freq;
-                int ret = Interop.WiFi.Ap.GetFrequency(_apHandle, out freq);
+                int ret = Interop.WiFi.AP.GetFrequency(_apHandle, out freq);
                 if (ret != (int)WiFiError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to get frequency, Error - " + (WiFiError)ret);
@@ -160,15 +187,18 @@ namespace Tizen.Network.WiFi
                 return freq;
             }
         }
+
         /// <summary>
-        /// The Received signal strength indication(RSSI).
+        /// The received signal strength indicator (RSSI).
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Represents RSSI of Wi-Fi (dbm).</value>
         public int Rssi
         {
             get
             {
                 int rssi;
-                int ret = Interop.WiFi.Ap.GetRssi(_apHandle, out rssi);
+                int ret = Interop.WiFi.AP.GetRssi(_apHandle, out rssi);
                 if (ret != (int)WiFiError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to get rssi, Error - " + (WiFiError)ret);
@@ -176,15 +206,39 @@ namespace Tizen.Network.WiFi
                 return rssi;
             }
         }
+
         /// <summary>
-        /// Rhe max speed (Mbps).
+        /// The Received signal strength indication(RSSI).
         /// </summary>
+        /// <since_tizen> 4 </since_tizen>
+        /// <value>Represents Rssi level of WiFi.</value>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <exception cref="NotSupportedException">Thrown while setting this property when WiFi is not supported.</exception>
+        public WiFiRssiLevel RssiLevel
+        {
+            get
+            {
+                int rssi;
+                int ret = Interop.WiFi.AP.GetRssiLevel(_apHandle, out rssi);
+                if (ret != (int)WiFiError.None)
+                {
+                    Log.Error(Globals.LogTag, "Failed to get rssi level, Error - " + (WiFiError)ret);
+                }
+                return (WiFiRssiLevel)rssi;
+            }
+        }
+
+        /// <summary>
+        /// The max speed (Mbps).
+        /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Represents the max speed value.</value>
         public int MaxSpeed
         {
             get
             {
                 int maxSpeed;
-                int ret = Interop.WiFi.Ap.GetMaxSpeed(_apHandle, out maxSpeed);
+                int ret = Interop.WiFi.AP.GetMaxSpeed(_apHandle, out maxSpeed);
                 if (ret != (int)WiFiError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to get max speed, Error - " + (WiFiError)ret);
@@ -192,15 +246,18 @@ namespace Tizen.Network.WiFi
                 return maxSpeed;
             }
         }
+
         /// <summary>
-        /// A property to check whether the access point is favorite or not.
+        /// A property to check whether the access point is favorite or not.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Boolean value to check if the access point is a favorite or not.</value>
         public bool IsFavorite
         {
             get
             {
                 bool isFavorite;
-                int ret = Interop.WiFi.Ap.IsFavorite(_apHandle, out isFavorite);
+                int ret = Interop.WiFi.AP.IsFavorite(_apHandle, out isFavorite);
                 if (ret != (int)WiFiError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to get favorite, Error - " + (WiFiError)ret);
@@ -208,16 +265,19 @@ namespace Tizen.Network.WiFi
                 return isFavorite;
             }
         }
+
         /// <summary>
-        /// A property to check whether the access point is passpoint or not.
+        /// A property to check whether the access point is passpoint or not.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Boolean value to check if the access point is a passpoint or not.</value>
         public bool IsPasspoint
         {
             get
             {
                 bool isPasspoint;
                 Log.Debug(Globals.LogTag, "Handle: " + _apHandle);
-                int ret = Interop.WiFi.Ap.IsPasspoint(_apHandle, out isPasspoint);
+                int ret = Interop.WiFi.AP.IsPasspoint(_apHandle, out isPasspoint);
                 if (ret != (int)WiFiError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to get isPassport, Error - " + (WiFiError)ret);
@@ -225,15 +285,18 @@ namespace Tizen.Network.WiFi
                 return isPasspoint;
             }
         }
+
         /// <summary>
         /// The connection state.
         /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <value>Represents the connection state of the Wi-Fi.</value>
         public WiFiConnectionState ConnectionState
         {
             get
             {
                 int state;
-                int ret = Interop.WiFi.Ap.GetConnectionState(_apHandle, out state);
+                int ret = Interop.WiFi.AP.GetConnectionState(_apHandle, out state);
                 if (ret != (int)WiFiError.None)
                 {
                     Log.Error(Globals.LogTag, "Failed to get connection state, Error - " + (WiFiError)ret);
@@ -242,45 +305,56 @@ namespace Tizen.Network.WiFi
             }
         }
 
-        internal WiFiNetwork(IntPtr apHandle)
+        /// <summary>
+        /// Gets all IPv6 addresses of the access point.
+        /// </summary>
+        /// <since_tizen> 3 </since_tizen>
+        /// <returns>A list of IPv6 addresses of the access point.</returns>
+        /// <feature>http://tizen.org/feature/network.wifi</feature>
+        /// <exception cref="NotSupportedException">Thrown when the Wi-Fi is not supported.</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>
+        public IEnumerable<System.Net.IPAddress> GetAllIPv6Addresses()
         {
-            _apHandle = apHandle;
-            _ipv4 = new WiFiAddressInformation(apHandle, AddressFamily.Ipv4);
-            _ipv6 = new WiFiAddressInformation(apHandle, AddressFamily.Ipv6);
+            Log.Debug(Globals.LogTag, "GetAllIPv6Addresses");
+            List<System.Net.IPAddress> ipList = new List<System.Net.IPAddress>();
+            Interop.WiFi.HandleCallback callback = (IntPtr ipv6Address, IntPtr userData) =>
+            {
+                if (ipv6Address != IntPtr.Zero)
+                {
+                    string ipv6 = Marshal.PtrToStringAnsi(ipv6Address);
+                    if (ipv6.Length == 0)
+                        ipList.Add(System.Net.IPAddress.Parse("::"));
+                    else
+                        ipList.Add(System.Net.IPAddress.Parse(ipv6));
+                    return true;
+                }
+                return false;
+            };
 
-            IntPtr strPtr;
-            int ret = Interop.WiFi.Ap.GetEssid(_apHandle, out strPtr);
+            int ret = Interop.WiFi.AP.GetAllIPv6Addresses(_apHandle, callback, IntPtr.Zero);
             if (ret != (int)WiFiError.None)
             {
-                Log.Error(Globals.LogTag, "Failed to get essid, Error - " + (WiFiError)ret);
+                Log.Error(Globals.LogTag, "Failed to get all IPv6 addresses, Error - " + (WiFiError)ret);
+                WiFiErrorFactory.ThrowWiFiException(ret, _apHandle.DangerousGetHandle());
             }
-            _essid = Marshal.PtrToStringAnsi(strPtr);
-        }
-
-        ~WiFiNetwork()
-        {
-            Dispose(false);
-        }
 
-        public void Dispose()
-        {
-            Dispose(true);
-            GC.SuppressFinalize(this);
+            return ipList;
         }
 
-        private void Dispose(bool disposing)
+        internal WiFiNetwork(Interop.WiFi.SafeWiFiAPHandle apHandle)
         {
-            if (disposed)
-                return;
+            _apHandle = apHandle;
+            _ipv4 = new WiFiAddressInformation(apHandle, AddressFamily.IPv4);
+            _ipv6 = new WiFiAddressInformation(apHandle, AddressFamily.IPv6);
 
-            if (disposing)
+            IntPtr strPtr;
+            int ret = Interop.WiFi.AP.GetEssid(_apHandle, out strPtr);
+            if (ret != (int)WiFiError.None)
             {
-                _ipv4.Dispose();
-                _ipv6.Dispose();
+                Log.Error(Globals.LogTag, "Failed to get essid, Error - " + (WiFiError)ret);
             }
-            _apHandle = IntPtr.Zero;
-            disposed = true;
+            _essid = Marshal.PtrToStringAnsi(strPtr);
         }
-
     } //WiFiNetworkInformation
 }