Fix Dispose to release native resources only when Dispose is explicitly called
authorchleun.moon <chleun.moon@samsung.com>
Thu, 19 Jan 2017 09:41:39 +0000 (18:41 +0900)
committerchleun.moon <chleun.moon@samsung.com>
Thu, 19 Jan 2017 09:42:15 +0000 (18:42 +0900)
Change-Id: Ib2c8e2a4e4786b09560ff47856462c2e8eb5bb2a
Signed-off-by: cheoleun <chleun.moon@samsung.com>
packaging/csapi-network-connection.spec
src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionError.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/RequestCellularProfile.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/RequestWiFiProfile.cs

index 6e9ef3e..42730fa 100644 (file)
@@ -1,6 +1,6 @@
 Name:       csapi-network-connection
 Summary:    Tizen Connection API for C#
-Version:    1.0.5
+Version:    1.0.6
 Release:    1
 Group:      Development/Libraries
 License:    Apache-2.0
index 97fdf95..79d5502 100644 (file)
@@ -27,6 +27,7 @@ namespace Tizen.Network.Connection
         static public void ThrowConnectionException(int errno)
         {
             ConnectionError error = (ConnectionError)errno;
+            Log.Debug(Globals.LogTag, "ThrowConnectionException " + error);
             if (error == ConnectionError.AddressFamilyNotSupported)
             {
                 throw new InvalidOperationException("Address Family Not Supported");
index 8f64a5c..29e10b7 100644 (file)
@@ -53,16 +53,23 @@ namespace Tizen.Network.Connection
 
         private void Dispose(bool disposing)
         {
+            Log.Debug(Globals.LogTag, ">>> HandleHolder Dispose with " + disposing);
+            Log.Debug(Globals.LogTag, ">>> Handle: " + Handle);
             if (disposed)
                 return;
 
             if (disposing)
             {
                 // Free managed objects.
-                Interop.Connection.Destroy(Handle);
+                Destroy();
             }
             disposed = true;
         }
+
+        private void Destroy()
+        {
+            Interop.Connection.Destroy(Handle);
+        }
     }
 
     internal class ConnectionInternalManager
@@ -88,6 +95,8 @@ namespace Tizen.Network.Connection
 
         private void Dispose(bool disposing)
         {
+            Log.Debug(Globals.LogTag, ">>> ConnectionInternalManager Dispose with disposing " + disposing + ", disposed " + disposed);
+            Log.Debug(Globals.LogTag, ">>> Handle: " + GetHandle());
             if (disposed)
                 return;
 
index 8575c24..21724ca 100644 (file)
@@ -59,12 +59,14 @@ namespace Tizen.Network.Connection
 
         private void Dispose(bool disposing)
         {
+            Log.Debug(Globals.LogTag, ">>> ConnectionManager Dispose with disposing " + disposing + ", disposed " + disposed);
             if (disposed)
                 return;
 
             if (disposing)
             {
                 // Free managed objects.
+                UnregisterEvents();
                 _internalManager.Dispose();
             }
             disposed = true;
@@ -284,6 +286,26 @@ namespace Tizen.Network.Connection
             }
         }
 
+        private void UnregisterEvents()
+        {
+            if (_ConnectionTypeChanged != null)
+            {
+                ConnectionTypeChangedStop();
+            }
+            if (_IPAddressChanged != null)
+            {
+                IpAddressChangedStop();
+            }
+            if (_EthernetCableStateChanged != null)
+            {
+                EthernetCableStateChangedStop();
+            }
+            if (_ProxyAddressChanged != null)
+            {
+                ProxyAddressChangedStop();
+            }
+        }
+
         /// <summary>
         /// Gets the IP address of the current connection.
         /// </summary>
index 6c7aa8c..f91affe 100644 (file)
@@ -107,18 +107,32 @@ namespace Tizen.Network.Connection
 
         private void Dispose(bool disposing)
         {
+            Log.Debug(Globals.LogTag, ">>> ConnectionProfile Dispose with " + disposing);
             if (disposed)
                 return;
 
             if (disposing)
             {
                 // Free managed objects.
-//                ProfileStateChangedStop();
-                Interop.ConnectionProfile.Destroy(ProfileHandle);
+                UnregisterEvents();
+                Destroy();
             }
             disposed = true;
         }
 
+        private void UnregisterEvents()
+        {
+            if (_ProfileStateChanged != null)
+            {
+                ProfileStateChangedStop();
+            }
+        }
+
+        private void Destroy()
+        {
+            Interop.ConnectionProfile.Destroy(ProfileHandle);
+        }
+
         /// <summary>
         /// Gets the profile ID.
         /// </summary>
index e4ffcce..3670e8b 100644 (file)
@@ -66,17 +66,23 @@ namespace Tizen.Network.Connection
 
         private void Dispose(bool disposing)
         {
+            Log.Debug(Globals.LogTag, ">>> RequestCellularProfile Dispose with " + disposing);
             if (disposed)
                 return;
 
             if (disposing)
             {
                 // Free managed objects.
+                Destroy();
             }
-            Interop.ConnectionProfile.Destroy(ProfileHandle);
             disposed = true;
         }
 
+        private void Destroy()
+        {
+            Interop.ConnectionProfile.Destroy(ProfileHandle);
+        }
+
         /// <summary>
         /// Gets the network type.
         /// </summary>
index 16af8e1..055d7c1 100644 (file)
@@ -61,17 +61,23 @@ namespace Tizen.Network.Connection
 
         private void Dispose(bool disposing)
         {
+            Log.Debug(Globals.LogTag, ">>> RequestWiFiProfile Dispose with " + disposing);
             if (disposed)
                 return;
 
             if (disposing)
             {
                 // Free managed objects.
+                Destroy();
             }
-            Interop.ConnectionProfile.Destroy(ProfileHandle);
             disposed = true;
         }
 
+        private void Destroy()
+        {
+            Interop.ConnectionProfile.Destroy(ProfileHandle);
+        }
+
         /// <summary>
         /// Gets the network type.
         /// </summary>