[Connection][WiFi] Assign zero to Handle only when Interop.Destroy() (#235)
authorchleun-moon <32117100+chleun-moon@users.noreply.github.com>
Fri, 27 Apr 2018 00:54:15 +0000 (09:54 +0900)
committertaesubkim <35015408+taesubkim@users.noreply.github.com>
Fri, 27 Apr 2018 00:54:15 +0000 (09:54 +0900)
* [Connection][WiFi] Assign zero to Handle only when Interop.Destroy() returns Error.None

* [Connection] Do not add events in case of error

src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs
src/Tizen.Network.WiFi/Tizen.Network.WiFi/WiFiAP.cs

index 5ab232c..16b3aeb 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,12 @@ 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 d05ae57..e034626 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;
         }
 
@@ -217,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)");