[Connection] Prevent a delegate for EthernetCableStateChanged event from being collec... 64/159764/2
authorchleun.moon <chleun.moon@samsung.com>
Mon, 13 Nov 2017 04:44:10 +0000 (13:44 +0900)
committerchleun.moon <chleun.moon@samsung.com>
Mon, 13 Nov 2017 04:46:43 +0000 (13:46 +0900)
Change-Id: Ife2bc746a8447d5835519f14c40084af8d919128
Signed-off-by: Cheoleun Moon <chleun.moon@samsung.com>
src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs

index 56f6290..ea7157f 100755 (executable)
@@ -96,6 +96,7 @@ namespace Tizen.Network.Connection
         private Interop.Connection.ConnectionAddressChangedCallback _connectionAddressChangedCallback;
         private Interop.Connection.ConnectionTypeChangedCallback _connectionTypeChangedCallback;
         private Interop.Connection.ConnectionAddressChangedCallback _proxyAddressChangedCallback;
+        private Interop.Connection.EthernetCableStateChangedCallback _ethernetCableStateChangedCallback;
 
         internal static ConnectionInternalManager Instance
         {
@@ -224,10 +225,20 @@ namespace Tizen.Network.Connection
 
         private void EthernetCableStateChangedStart()
         {
-            int ret = Interop.Connection.SetEthernetCableStateChagedCallback(GetHandle(), EthernetCableStateChangedCallback, IntPtr.Zero);
+            _ethernetCableStateChangedCallback = (EthernetCableState state, IntPtr user_data) =>
+            {
+                if (_EthernetCableStateChanged != null)
+                {
+                    _EthernetCableStateChanged(null, new EthernetCableStateEventArgs(state));
+                }
+            };
+            int ret = Interop.Connection.SetEthernetCableStateChagedCallback(GetHandle(),
+                    _ethernetCableStateChangedCallback, IntPtr.Zero);
             if ((ConnectionError)ret != ConnectionError.None)
             {
-                Log.Error(Globals.LogTag, "It failed to register ethernet cable state changed callback, " + (ConnectionError)ret);
+                Log.Error(Globals.LogTag,
+                        "It failed to register ethernet cable state changed callback, " +
+                        (ConnectionError)ret);
                 ConnectionErrorFactory.ThrowConnectionException(ret);
             }
         }
@@ -237,19 +248,13 @@ namespace Tizen.Network.Connection
             int ret = Interop.Connection.UnsetEthernetCableStateChagedCallback(GetHandle());
             if ((ConnectionError)ret != ConnectionError.None)
             {
-                Log.Error(Globals.LogTag, "It failed to unregister ethernet cable state changed callback, " + (ConnectionError)ret);
+                Log.Error(Globals.LogTag,
+                        "It failed to unregister ethernet cable state changed callback, " + 
+                        (ConnectionError)ret);
                 ConnectionErrorFactory.ThrowConnectionException(ret);
             }
         }
 
-        private void EthernetCableStateChangedCallback(EthernetCableState state, IntPtr user_data)
-        {
-            if (_EthernetCableStateChanged != null)
-            {
-                _EthernetCableStateChanged(null, new EthernetCableStateEventArgs(state));
-            }
-        }
-
         internal event EventHandler<AddressEventArgs> IPAddressChanged
         {
             add