From: chleun.moon Date: Mon, 13 Nov 2017 04:44:10 +0000 (+0900) Subject: [Connection] Prevent a delegate for EthernetCableStateChanged event from being collec... X-Git-Tag: 4.0.1-preview1-00020~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=6c59b247dcbc3450413748c6d90fe8edb5afbafa;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [Connection] Prevent a delegate for EthernetCableStateChanged event from being collected by GC Change-Id: Ife2bc746a8447d5835519f14c40084af8d919128 Signed-off-by: Cheoleun Moon --- diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs index 56f6290..ea7157f 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs @@ -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 IPAddressChanged { add