[Connection][WiFi] Assign zero to the handle only when Interop.Destroy() 03/177303/2
authorchleun.moon <chleun.moon@samsung.com>
Fri, 27 Apr 2018 03:03:47 +0000 (12:03 +0900)
committerchleun.moon <chleun.moon@samsung.com>
Mon, 30 Apr 2018 00:32:17 +0000 (09:32 +0900)
Change-Id: Ib486d7cfd972ad777901088a2955e0ff58a7533c
Signed-off-by: Cheoleun Moon <chleun.moon@samsung.com>
src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfileManager.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs

index 5ab232c4ec578e00e5a9a5b9c15f071add0024a0..7d0fb7ad807a9d6940b5bb943fe6ead8302422c1 100755 (executable)
@@ -62,7 +62,14 @@ namespace Tizen.Network.Connection
                 {
                     if (_ProfileStateChanged == null)
                     {
-                        ProfileStateChangedStart();
+                        try
+                        {
+                            ProfileStateChangedStart();
+                        } catch (Exception e)
+                        {
+                            Log.Error(Globals.LogTag, "Exception on adding ProfileStateChanged\n" + e.ToString());
+                            return;
+                        }
                     }
                     _ProfileStateChanged += value;
                 }, null);
@@ -75,7 +82,14 @@ namespace Tizen.Network.Connection
                     _ProfileStateChanged -= value;
                     if (_ProfileStateChanged == null)
                     {
-                        ProfileStateChangedStop();
+                        try
+                        {
+                            ProfileStateChangedStop();
+                        }
+                        catch (Exception e)
+                        {
+                            Log.Error(Globals.LogTag, "Exception on removing ProfileStateChanged\n" + e.ToString());
+                        }
                     }
                 }, null);
             }
@@ -85,7 +99,6 @@ namespace Tizen.Network.Connection
         {
             _profileChangedCallback = (ProfileState state, IntPtr userData) =>
             {
-                Log.Info(Globals.LogTag, "***** MOON ProfileStateChanged occur");
                 if (_ProfileStateChanged != null)
                 {
                     _ProfileStateChanged(null, new ProfileStateEventArgs(state));
@@ -97,6 +110,7 @@ namespace Tizen.Network.Connection
             if ((ConnectionError)ret != ConnectionError.None)
             {
                 Log.Error(Globals.LogTag, "It failed to register callback for changing profile state, " + (ConnectionError)ret);
+                ConnectionErrorFactory.ThrowConnectionException(ret);
             }
         }
 
@@ -107,6 +121,7 @@ namespace Tizen.Network.Connection
             if ((ConnectionError)ret != ConnectionError.None)
             {
                 Log.Error(Globals.LogTag, "It failed to unregister callback for changing profile state, " + (ConnectionError)ret);
+                ConnectionErrorFactory.ThrowConnectionException(ret);
             }
         }
 
@@ -137,7 +152,6 @@ namespace Tizen.Network.Connection
 
         private void Dispose(bool disposing)
         {
-            Log.Debug(Globals.LogTag, ">>> ConnectionProfile Dispose with " + disposing);
             if (disposed)
                 return;
 
@@ -157,8 +171,11 @@ namespace Tizen.Network.Connection
 
         private void Destroy()
         {
-            Interop.ConnectionProfile.Destroy(ProfileHandle);
-            ProfileHandle = IntPtr.Zero;
+            int ret = Interop.ConnectionProfile.Destroy(ProfileHandle);
+            if ((ConnectionError)ret == ConnectionError.None)
+            {
+                ProfileHandle = IntPtr.Zero;
+            }
         }
 
         internal void CheckDisposed()
index e205c4875a2acdb207993aee34f16b2fc012603d..a0d1ae61086d94b48a5b16fec87b3cc800884212 100755 (executable)
@@ -80,6 +80,9 @@ namespace Tizen.Network.Connection
         /// <since_tizen> 3 </since_tizen>
         /// <param name="profile">The connection profile object.</param>
         /// <returns>A task indicates whether the ConnectProfileAsync method is done successfully or not.</returns>
+        /// <remarks>
+        /// This method must be called from MainThread.
+        /// </remarks>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <privilege>http://tizen.org/privilege/network.set</privilege>
         /// <feature>http://tizen.org/feature/network.telephony</feature>
@@ -104,6 +107,9 @@ namespace Tizen.Network.Connection
         /// <since_tizen> 3 </since_tizen>
         /// <param name="profile">The connection profile object.</param>
         /// <returns>A task indicates whether the DisconnectProfileAsync method is done successfully or not.</returns>
+        /// <remarks>
+        /// This method must be called from MainThread.
+        /// </remarks>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <privilege>http://tizen.org/privilege/network.set</privilege>
         /// <feature>http://tizen.org/feature/network.telephony</feature>
@@ -220,6 +226,9 @@ namespace Tizen.Network.Connection
         /// <param name="type">The cellular service type.</param>
         /// <param name="profile">The connection profile object.</param>
         /// <returns>A task indicates whether the SetDefaultCellularProfile method is done successfully or not.</returns>
+        /// <remarks>
+        /// This method must be called from MainThread.
+        /// </remarks>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
         /// <feature>http://tizen.org/feature/network.telephony</feature>
index cc72ad6806b83ce5a08bfd95a32426f8a01b5a9f..919ae1db29a44f3cb5297ed75059af5c5cc1d4aa 100755 (executable)
@@ -135,8 +135,12 @@ namespace Tizen.Network.WiFi
             if (_disposed)
                 return;
 
-            Interop.WiFi.AP.Destroy(_apHandle);
-            _apHandle = IntPtr.Zero;
+            Log.Info(Globals.LogTag, "WiFiAP Handle HashCode: " + _apHandle.GetHashCode());
+            int ret = Interop.WiFi.AP.Destroy(_apHandle);
+            if (ret == (int)WiFiError.None)
+            {
+                _apHandle = IntPtr.Zero;
+            }
             _disposed = true;
         }
 
@@ -203,6 +207,9 @@ namespace Tizen.Network.WiFi
         /// </summary>
         /// <since_tizen> 3 </since_tizen>
         /// <returns> A task indicating whether the connect method is done or not.</returns>
+        /// <remarks>
+        /// This method must be called from MainThread.
+        /// </remarks>
         /// <feature>http://tizen.org/feature/network.wifi</feature>
         /// <privilege>http://tizen.org/privilege/network.set</privilege>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
@@ -214,7 +221,7 @@ namespace Tizen.Network.WiFi
         /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
         public Task ConnectAsync()
         {
-            Log.Info(Globals.LogTag, "ConnectAsync");
+            Log.Info(Globals.LogTag, "ConnectAsync HashCode: " + _apHandle.GetHashCode());
             if (_disposed)
             {
                 throw new ObjectDisposedException("Invalid AP instance (Object may have been disposed or released)");
@@ -271,6 +278,9 @@ namespace Tizen.Network.WiFi
         /// <since_tizen> 3 </since_tizen>
         /// <param name="info">A WpsInfo instance which is type of WpsPbcInfo or WpsPinInfo.</param>
         /// <returns>A task indicating whether the ConnectWps method is done or not.</returns>
+        /// <remarks>
+        /// This method must be called from MainThread.
+        /// </remarks>
         /// <feature>http://tizen.org/feature/network.wifi</feature>
         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
@@ -363,7 +373,8 @@ namespace Tizen.Network.WiFi
         /// <param name="info">A WpsInfo instance which is of type WpsPbcInfo or WpsPinInfo.</param>
         /// <returns>A task which contains Connected access point information.</returns>
         /// <remarks>
-        /// If WpsPinInfo is used, its object has to be constructed with a pin which must be 4 or 8 characters long.
+        /// If WpsPinInfo is used, its object has to be constructed with a pin which must be 4 or 8 characters long. \n
+        /// This method must be called from MainThread.
         /// </remarks>
         /// <feature>http://tizen.org/feature/network.wifi</feature>
         /// <privilege>http://tizen.org/privilege/network.set</privilege>