From 96ed479938230b686c4d43d4f2fc31d5d560cbc3 Mon Sep 17 00:00:00 2001 From: "chleun.moon" Date: Fri, 13 Jan 2017 11:11:08 +0900 Subject: [PATCH] Modify ConnectionManager to non-static Static class ConnectionManager cannot be created multiple time. It causes a problem in multi-thread environment. Handle created in one thread cannot be used in other threads due to characteristics of handle-based native connection capi. Therefore ConnectionManager is modified to map one ConnectionManager instance to one native capi handle. Change-Id: If1e80df24400bc6477717f33eaadb05a198c3322 Signed-off-by: cheoleun --- packaging/csapi-network-connection.spec | 2 +- .../ConnectionInternalManager.cs | 89 ++++++--- .../Tizen.Network.Connection/ConnectionManager.cs | 217 ++++++++++++--------- .../Tizen.Network.Connection/ConnectionProfile.cs | 11 +- .../ConnectionProfileManager.cs | 40 ++-- .../RequestCellularProfile.cs | 8 +- .../Tizen.Network.Connection/RequestWiFiProfile.cs | 6 +- 7 files changed, 217 insertions(+), 156 deletions(-) diff --git a/packaging/csapi-network-connection.spec b/packaging/csapi-network-connection.spec index bab0516..6e9ef3e 100644 --- a/packaging/csapi-network-connection.spec +++ b/packaging/csapi-network-connection.spec @@ -1,6 +1,6 @@ Name: csapi-network-connection Summary: Tizen Connection API for C# -Version: 1.0.4 +Version: 1.0.5 Release: 1 Group: Development/Libraries License: Apache-2.0 diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs index 03b9463..8f64a5c 100644 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs @@ -59,42 +59,71 @@ namespace Tizen.Network.Connection if (disposing) { // Free managed objects. + Interop.Connection.Destroy(Handle); } - Interop.Connection.Destroy(Handle); disposed = true; } } - static class ConnectionInternalManager + internal class ConnectionInternalManager { - private static HandleHolder Holder = new HandleHolder(); + private HandleHolder Holder = null; + private bool disposed = false; + + internal ConnectionInternalManager() + { + Holder = new HandleHolder(); + } + + ~ConnectionInternalManager() + { + Dispose(false); + } - static public IntPtr GetHandle() + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + Holder.Dispose(); + } + disposed = true; + } + + public IntPtr GetHandle() { return Holder.GetHandle(); } - static internal int GetProfileIterator(ProfileListType type, out IntPtr iterator) + internal int GetProfileIterator(ProfileListType type, out IntPtr iterator) { return Interop.Connection.GetProfileIterator(Holder.GetHandle(), (int)type, out iterator); } - static internal bool HasNext(IntPtr iterator) + internal bool HasNext(IntPtr iterator) { return Interop.Connection.HasNextProfileIterator(iterator); } - static internal int NextProfileIterator(IntPtr iterator, out IntPtr profileHandle) + internal int NextProfileIterator(IntPtr iterator, out IntPtr profileHandle) { return Interop.Connection.GetNextProfileIterator(iterator, out profileHandle); } - static internal int DestoryProfileIterator(IntPtr iterator) + internal int DestoryProfileIterator(IntPtr iterator) { return Interop.Connection.DestroyProfileIterator(iterator); } - static public string GetIpAddress(AddressFamily family) + public string GetIpAddress(AddressFamily family) { IntPtr ip; int ret = Interop.Connection.GetIpAddress(Holder.GetHandle(), (int)family, out ip); @@ -108,7 +137,7 @@ namespace Tizen.Network.Connection return result; } - static public string GetProxy(AddressFamily family) + public string GetProxy(AddressFamily family) { IntPtr ip; int ret = Interop.Connection.GetProxy(Holder.GetHandle(), (int)family, out ip); @@ -122,7 +151,7 @@ namespace Tizen.Network.Connection return result; } - static public string GetMacAddress(ConnectionType type) + public string GetMacAddress(ConnectionType type) { IntPtr ip; int ret = Interop.Connection.GetMacAddress(Holder.GetHandle(), (int)type, out ip); @@ -136,7 +165,7 @@ namespace Tizen.Network.Connection return result; } - static public ConnectionType ConnectionType + public ConnectionType ConnectionType { get { @@ -146,26 +175,29 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get connection type, " + (ConnectionError)ret); + ConnectionErrorFactory.ThrowConnectionException(ret); } return (ConnectionType)type; } } - static public CellularState CellularState + public CellularState CellularState { get { int type = 0; + Log.Debug(Globals.LogTag, "CellularState Handle: " + Holder.GetHandle()); int ret = Interop.Connection.GetCellularState(Holder.GetHandle(), out type); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get cellular state, " + (ConnectionError)ret); + ConnectionErrorFactory.ThrowConnectionException(ret); } return (CellularState)type; } } - static public ConnectionState WiFiState + public ConnectionState WiFiState { get { @@ -174,12 +206,13 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get wifi state, " + (ConnectionError)ret); + ConnectionErrorFactory.ThrowConnectionException(ret); } return (ConnectionState)type; } } - static public ConnectionState BluetoothState + public ConnectionState BluetoothState { get { @@ -188,12 +221,13 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get bluetooth state, " + (ConnectionError)ret); + ConnectionErrorFactory.ThrowConnectionException(ret); } return (ConnectionState)type; } } - static public ConnectionState EthernetState + public ConnectionState EthernetState { get { @@ -202,12 +236,13 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get ethernet state, " + (ConnectionError)ret); + ConnectionErrorFactory.ThrowConnectionException(ret); } return (ConnectionState)type; } } - static public EthernetCableState EthernetCableState + public EthernetCableState EthernetCableState { get { @@ -216,6 +251,7 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get ethernet cable state, " + (ConnectionError)ret); + ConnectionErrorFactory.ThrowConnectionException(ret); } return (EthernetCableState)type; } @@ -224,7 +260,6 @@ namespace Tizen.Network.Connection static public IntPtr CreateRequestProfile(ConnectionProfileType type, string keyword) { Log.Error(Globals.LogTag, "CreateRequestProfile, " + type + ", " + keyword); - Log.Debug(Globals.LogTag, "Handle: " + GetHandle()); IntPtr handle = IntPtr.Zero; int ret = Interop.ConnectionProfile.Create((int)type, keyword, out handle); if ((ConnectionError)ret != ConnectionError.None) @@ -236,7 +271,7 @@ namespace Tizen.Network.Connection return handle; } - static public int AddProfile(RequestProfile profile) + public int AddProfile(RequestProfile profile) { int ret = 0; if (profile.Type == ConnectionProfileType.Cellular) @@ -260,7 +295,7 @@ namespace Tizen.Network.Connection return ret; } - static public int RemoveProfile(ConnectionProfile profile) + public int RemoveProfile(ConnectionProfile profile) { int ret = Interop.Connection.RemoveProfile(Holder.GetHandle(), profile.ProfileHandle); if ((ConnectionError)ret != ConnectionError.None) @@ -271,7 +306,7 @@ namespace Tizen.Network.Connection return ret; } - static public int UpdateProfile(ConnectionProfile profile) + public int UpdateProfile(ConnectionProfile profile) { int ret = Interop.Connection.UpdateProfile(Holder.GetHandle(), profile.ProfileHandle); if ((ConnectionError)ret != ConnectionError.None) @@ -282,7 +317,7 @@ namespace Tizen.Network.Connection return ret; } - static public ConnectionProfile GetCurrentProfile() + public ConnectionProfile GetCurrentProfile() { IntPtr ProfileHandle; int ret = Interop.Connection.GetCurrentProfile(Holder.GetHandle(), out ProfileHandle); @@ -295,7 +330,7 @@ namespace Tizen.Network.Connection return Profile; } - static public ConnectionProfile GetDefaultCellularProfile(CellularServiceType type) + public ConnectionProfile GetDefaultCellularProfile(CellularServiceType type) { IntPtr ProfileHandle; int ret = Interop.Connection.GetDefaultCellularServiceProfile(Holder.GetHandle(), (int)type, out ProfileHandle); @@ -309,7 +344,7 @@ namespace Tizen.Network.Connection return Profile; } - static public Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile) + public Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile) { var task = new TaskCompletionSource(); Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => @@ -327,7 +362,7 @@ namespace Tizen.Network.Connection } - static public Task> GetProfileListAsync(ProfileListType type) + public Task> GetProfileListAsync(ProfileListType type) { var task = new TaskCompletionSource>(); @@ -369,7 +404,7 @@ namespace Tizen.Network.Connection return task.Task; } - static public Task OpenProfileAsync(ConnectionProfile profile) + public Task OpenProfileAsync(ConnectionProfile profile) { var task = new TaskCompletionSource(); Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => @@ -386,7 +421,7 @@ namespace Tizen.Network.Connection return task.Task; } - static public Task CloseProfileAsync(ConnectionProfile profile) + public Task CloseProfileAsync(ConnectionProfile profile) { var task = new TaskCompletionSource(); Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs index 3a6e50b..8575c24 100644 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs @@ -29,20 +29,51 @@ namespace Tizen.Network.Connection /// /// This class is ConnectionManager /// - public class ConnectionManager : IDisposable + public partial class ConnectionManager : IDisposable { - static internal ConnectionItem CurConnction = new ConnectionItem(); + private ConnectionInternalManager _internalManager = null; + private ConnectionItem _currentConnection = null; private bool disposed = false; - static private EventHandler _ConnectionTypeChanged = null; - static private EventHandler _IPAddressChanged = null; - static private EventHandler _EthernetCableStateChanged = null; - static private EventHandler _ProxyAddressChanged = null; + private EventHandler _ConnectionTypeChanged = null; + private EventHandler _IPAddressChanged = null; + private EventHandler _EthernetCableStateChanged = null; + private EventHandler _ProxyAddressChanged = null; + + public ConnectionManager() + { + _internalManager = new ConnectionInternalManager(); + _currentConnection = new ConnectionItem(_internalManager); + } + + ~ConnectionManager() + { + Dispose(false); + } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + private void Dispose(bool disposing) + { + if (disposed) + return; + + if (disposing) + { + // Free managed objects. + _internalManager.Dispose(); + } + disposed = true; + } /// /// Event that is called when the type of the current connection is changed. /// - static public event EventHandler ConnectionTypeChanged + public event EventHandler ConnectionTypeChanged { add { @@ -62,25 +93,27 @@ namespace Tizen.Network.Connection } } - static private void ConnectionTypeChangedStart() + private void ConnectionTypeChangedStart() { - int ret = Interop.Connection.SetTypeChangedCallback(ConnectionInternalManager.GetHandle(), TypeChangedCallback, IntPtr.Zero); + int ret = Interop.Connection.SetTypeChangedCallback(_internalManager.GetHandle(), TypeChangedCallback, IntPtr.Zero); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to register connection type changed callback, " + (ConnectionError)ret); + ConnectionErrorFactory.ThrowConnectionException(ret); } } - static private void ConnectionTypeChangedStop() + private void ConnectionTypeChangedStop() { - int ret = Interop.Connection.UnsetTypeChangedCallback(ConnectionInternalManager.GetHandle()); + int ret = Interop.Connection.UnsetTypeChangedCallback(_internalManager.GetHandle()); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to unregister connection type changed callback, " + (ConnectionError)ret); + ConnectionErrorFactory.ThrowConnectionException(ret); } } - static private void TypeChangedCallback(ConnectionType type, IntPtr user_data) + private void TypeChangedCallback(ConnectionType type, IntPtr user_data) { if (_ConnectionTypeChanged != null) { @@ -91,7 +124,7 @@ namespace Tizen.Network.Connection /// /// Event for ethernet cable is plugged [in/out] event. /// - static public event EventHandler EthernetCableStateChanged + public event EventHandler EthernetCableStateChanged { add { @@ -111,9 +144,9 @@ namespace Tizen.Network.Connection } } - static private void EthernetCableStateChangedStart() + private void EthernetCableStateChangedStart() { - int ret = Interop.Connection.SetEthernetCableStateChagedCallback(ConnectionInternalManager.GetHandle(), EthernetCableStateChangedCallback, IntPtr.Zero); + int ret = Interop.Connection.SetEthernetCableStateChagedCallback(_internalManager.GetHandle(), EthernetCableStateChangedCallback, IntPtr.Zero); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to register ethernet cable state changed callback, " + (ConnectionError)ret); @@ -121,9 +154,9 @@ namespace Tizen.Network.Connection } } - static private void EthernetCableStateChangedStop() + private void EthernetCableStateChangedStop() { - int ret = Interop.Connection.UnsetEthernetCableStateChagedCallback(ConnectionInternalManager.GetHandle()); + int ret = Interop.Connection.UnsetEthernetCableStateChagedCallback(_internalManager.GetHandle()); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to unregister ethernet cable state changed callback, " + (ConnectionError)ret); @@ -131,7 +164,7 @@ namespace Tizen.Network.Connection } } - static private void EthernetCableStateChangedCallback(EthernetCableState state, IntPtr user_data) + private void EthernetCableStateChangedCallback(EthernetCableState state, IntPtr user_data) { if (_EthernetCableStateChanged != null) { @@ -142,7 +175,7 @@ namespace Tizen.Network.Connection /// /// Event that is called when the IP address is changed. /// - static public event EventHandler IpAddressChanged + public event EventHandler IpAddressChanged { add { @@ -162,25 +195,26 @@ namespace Tizen.Network.Connection } } - static private void IpAddressChangedStart() + private void IpAddressChangedStart() { - int ret = Interop.Connection.SetIpAddressChangedCallback(ConnectionInternalManager.GetHandle(), IPAddressChangedCallback, IntPtr.Zero); + Log.Debug(Globals.LogTag, "Handle: " + _internalManager.GetHandle()); + int ret = Interop.Connection.SetIpAddressChangedCallback(_internalManager.GetHandle(), IPAddressChangedCallback, IntPtr.Zero); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to register callback for changing IP address, " + (ConnectionError)ret); } } - static private void IpAddressChangedStop() + private void IpAddressChangedStop() { - int ret = Interop.Connection.UnsetIpAddressChangedCallback(ConnectionInternalManager.GetHandle()); + int ret = Interop.Connection.UnsetIpAddressChangedCallback(_internalManager.GetHandle()); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to unregister callback for changing IP address, " + (ConnectionError)ret); } } - static private void IPAddressChangedCallback(IntPtr Ipv4, IntPtr Ipv6, IntPtr UserData) + private void IPAddressChangedCallback(IntPtr Ipv4, IntPtr Ipv6, IntPtr UserData) { if (_IPAddressChanged != null) { @@ -197,7 +231,7 @@ namespace Tizen.Network.Connection /// /// Event that is called when the proxy address is changed. /// - static public event EventHandler ProxyAddressChanged + public event EventHandler ProxyAddressChanged { add { @@ -219,25 +253,25 @@ namespace Tizen.Network.Connection } } - static private void ProxyAddressChangedStart() + private void ProxyAddressChangedStart() { - int ret = Interop.Connection.SetProxyAddressChangedCallback(ConnectionInternalManager.GetHandle(), IPAddressChangedCallback, IntPtr.Zero); + int ret = Interop.Connection.SetProxyAddressChangedCallback(_internalManager.GetHandle(), IPAddressChangedCallback, IntPtr.Zero); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to register callback for changing proxy address, " + (ConnectionError)ret); } } - static private void ProxyAddressChangedStop() + private void ProxyAddressChangedStop() { - int ret = Interop.Connection.UnsetProxyAddressChangedCallback(ConnectionInternalManager.GetHandle()); + int ret = Interop.Connection.UnsetProxyAddressChangedCallback(_internalManager.GetHandle()); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to unregister callback for changing proxy address, " + (ConnectionError)ret); } } - static private void ProxyAddressChangedCallback(IntPtr Ipv4, IntPtr Ipv6, IntPtr UserData) + private void ProxyAddressChangedCallback(IntPtr Ipv4, IntPtr Ipv6, IntPtr UserData) { if (_ProxyAddressChanged != null) { @@ -250,84 +284,71 @@ namespace Tizen.Network.Connection } } - internal ConnectionManager() - { - } - - ~ConnectionManager() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - private void Dispose(bool disposing) - { - if (disposed) - return; - - if (disposing) - { - // Free managed objects. - } - ProxyAddressChangedStop(); - ConnectionTypeChangedStop(); - EthernetCableStateChangedStop(); - IpAddressChangedStop(); - disposed = true; - } - - /// /// Gets the IP address of the current connection. /// /// Thrown when method failed due to invalid operation - static public string GetIpAddress(AddressFamily family) + public string GetIpAddress(AddressFamily family) { - return ConnectionInternalManager.GetIpAddress(family); + return _internalManager.GetIpAddress(family); } /// /// Gets the proxy address of the current connection. /// /// Thrown when method failed due to invalid operation - static public string GetProxy(AddressFamily family) + public string GetProxy(AddressFamily family) { - return ConnectionInternalManager.GetProxy(family); + return _internalManager.GetProxy(family); } /// /// Gets the MAC address of the Wi-Fi or ethernet. /// /// Thrown when method failed due to invalid operation - static public string GetMacAddress(ConnectionType type) + public string GetMacAddress(ConnectionType type) { - return ConnectionInternalManager.GetMacAddress(type); + return _internalManager.GetMacAddress(type); } /// - /// Gets the type of the current profile for data connection. + /// Gets type and state of the current profile for data connection /// - static public ConnectionItem CurrentConnection + public ConnectionItem CurrentConnection { get { - return CurConnction; + return _currentConnection; } } + public RequestProfile CreateRequestProfile(ConnectionProfileType type, string keyword) + { + IntPtr ProfileHandle = ConnectionInternalManager.CreateRequestProfile(type, keyword); + if (type == ConnectionProfileType.WiFi) + { + return new RequestWiFiProfile(ProfileHandle); + } + else if (type == ConnectionProfileType.Cellular) + { + return new RequestCellularProfile(ProfileHandle); + } + else + { + Log.Error(Globals.LogTag, "Nut supported profile type"); + ConnectionErrorFactory.ThrowConnectionException((int)ConnectionError.InvalidParameter); + } + return null; + } + /// /// Gets the state of cellular connection. /// - static public CellularState CellularState + public CellularState CellularState { get { - return ConnectionInternalManager.CellularState; + return _internalManager.CellularState; } } @@ -335,11 +356,11 @@ namespace Tizen.Network.Connection /// Gets the state of the Wi-Fi. /// /// http://tizen.org/privilege/network.get - static public ConnectionState WiFiState + public ConnectionState WiFiState { get { - return ConnectionInternalManager.WiFiState; + return _internalManager.WiFiState; } } @@ -347,11 +368,11 @@ namespace Tizen.Network.Connection /// The state of the Bluetooth. /// /// http://tizen.org/privilege/network.get - static public ConnectionState BluetoothState + public ConnectionState BluetoothState { get { - return ConnectionInternalManager.BluetoothState; + return _internalManager.BluetoothState; } } @@ -359,11 +380,11 @@ namespace Tizen.Network.Connection /// The Ethernet connection state. /// /// http://tizen.org/privilege/network.get - static public ConnectionState EthernetState + public ConnectionState EthernetState { get { - return ConnectionInternalManager.EthernetState; + return _internalManager.EthernetState; } } @@ -371,22 +392,25 @@ namespace Tizen.Network.Connection /// Checks for ethernet cable is attached or not. /// /// http://tizen.org/privilege/network.get - static public EthernetCableState EthernetCableState + public EthernetCableState EthernetCableState { get { - return ConnectionInternalManager.EthernetCableState; + return _internalManager.EthernetCableState; } } - } + + } // class ConnectionManager /// - /// + /// class which contains connection information such as connection type and state /// public class ConnectionItem { - internal ConnectionItem() + ConnectionInternalManager _internalManager = null; + internal ConnectionItem(ConnectionInternalManager manager) { + _internalManager = manager; } /// @@ -396,24 +420,24 @@ namespace Tizen.Network.Connection { get { - return ConnectionInternalManager.ConnectionType; + return _internalManager.ConnectionType; } } /// - /// Gets the type of the current profile for data connection. + /// Gets the state of the current profile for data connection. /// public ConnectionState State { get { - if (ConnectionInternalManager.ConnectionType == ConnectionType.Cellular) + if (_internalManager.ConnectionType == ConnectionType.Cellular) { - if (ConnectionInternalManager.CellularState == CellularState.Connected) + if (_internalManager.CellularState == CellularState.Connected) { return ConnectionState.Connected; } - else if (ConnectionInternalManager.CellularState == CellularState.Available) + else if (_internalManager.CellularState == CellularState.Available) { return ConnectionState.Disconnected; } @@ -421,25 +445,24 @@ namespace Tizen.Network.Connection return ConnectionState.Deactivated; } } - else if (ConnectionInternalManager.ConnectionType == ConnectionType.Bluetooth) + else if (_internalManager.ConnectionType == ConnectionType.Bluetooth) { - return ConnectionInternalManager.BluetoothState; + return _internalManager.BluetoothState; } - else if (ConnectionInternalManager.ConnectionType == ConnectionType.WiFi) + else if (_internalManager.ConnectionType == ConnectionType.WiFi) { - return ConnectionInternalManager.WiFiState; + return _internalManager.WiFiState; } - else if (ConnectionInternalManager.ConnectionType == ConnectionType.Ethernet) + else if (_internalManager.ConnectionType == ConnectionType.Ethernet) { - return ConnectionInternalManager.EthernetState; + return _internalManager.EthernetState; } else { // TO DO : Add Net Proxy return ConnectionState.Disconnected; } } } - - } + } // class ConnectionItem /// /// An extended EventArgs class which contains changed connection type. diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs index 6849fc0..6c7aa8c 100644 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs @@ -33,6 +33,11 @@ namespace Tizen.Network.Connection private bool disposed = false; private EventHandler _ProfileStateChanged; + internal IntPtr GetHandle() + { + return ProfileHandle; + } + /// /// The event that is called when the state of profile is changed. /// @@ -82,7 +87,7 @@ namespace Tizen.Network.Connection } } - public ConnectionProfile(IntPtr handle) + internal ConnectionProfile(IntPtr handle) { ProfileHandle = handle; Ipv4 = new ConnectionAddressInformation(ProfileHandle, AddressFamily.Ipv4); @@ -108,9 +113,9 @@ namespace Tizen.Network.Connection if (disposing) { // Free managed objects. +// ProfileStateChangedStop(); + Interop.ConnectionProfile.Destroy(ProfileHandle); } - Interop.ConnectionProfile.Destroy(ProfileHandle); - ProfileStateChangedStop(); disposed = true; } diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfileManager.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfileManager.cs index ada4cc6..5d530ed 100644 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfileManager.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfileManager.cs @@ -24,27 +24,27 @@ using System.Collections; namespace Tizen.Network.Connection { /// - /// This class is ConnectionProfileManager + /// This class is ConnectionManager /// - public class ConnectionProfileManager + public partial class ConnectionManager { /// /// Adds a new profile /// /// http://tizen.org/privilege/network.profile /// Thrown when method failed due to invalid operation - static public int AddProfile(RequestProfile profile) + public int AddProfile(RequestProfile profile) { - return ConnectionInternalManager.AddProfile(profile); + return _internalManager.AddProfile(profile); } /// /// Gets the list of profile with profile list type /// /// http://tizen.org/privilege/network.get - static public Task> GetProfileListAsync(ProfileListType type) + public Task> GetProfileListAsync(ProfileListType type) { - return ConnectionInternalManager.GetProfileListAsync(type); + return _internalManager.GetProfileListAsync(type); } /// @@ -52,18 +52,18 @@ namespace Tizen.Network.Connection /// /// http://tizen.org/privilege/network.get /// http://tizen.org/privilege/network.set - static public Task ConnectProfileAsync(ConnectionProfile profile) + public Task ConnectProfileAsync(ConnectionProfile profile) { - return ConnectionInternalManager.OpenProfileAsync(profile); + return _internalManager.OpenProfileAsync(profile); } /// /// Closes a connection of profile. /// /// http://tizen.org/privilege/network.set - static public Task DisconnectProfileAsync(ConnectionProfile profile) + public Task DisconnectProfileAsync(ConnectionProfile profile) { - return ConnectionInternalManager.CloseProfileAsync(profile); + return _internalManager.CloseProfileAsync(profile); } /// @@ -72,10 +72,10 @@ namespace Tizen.Network.Connection /// http://tizen.org/privilege/network.get /// http://tizen.org/privilege/network.profile /// Thrown when method failed due to invalid operation - static public int RemoveProfile(ConnectionProfile profile) + public int RemoveProfile(ConnectionProfile profile) { Log.Debug(Globals.LogTag, "RemoveProfile. Id: " + profile.Id + ", Name: " + profile.Name + ", Type: " + profile.Type); - return ConnectionInternalManager.RemoveProfile(profile); + return _internalManager.RemoveProfile(profile); } /// @@ -86,9 +86,9 @@ namespace Tizen.Network.Connection /// http://tizen.org/privilege/network.get /// http://tizen.org/privilege/network.profile /// Thrown when method failed due to invalid operation - static public int UpdateProfile(ConnectionProfile profile) + public int UpdateProfile(ConnectionProfile profile) { - return ConnectionInternalManager.UpdateProfile(profile); + return _internalManager.UpdateProfile(profile); } /// @@ -96,9 +96,9 @@ namespace Tizen.Network.Connection /// /// http://tizen.org/privilege/network.get /// Thrown when method failed due to invalid operation - static public ConnectionProfile GetCurrentProfile() + public ConnectionProfile GetCurrentProfile() { - return ConnectionInternalManager.GetCurrentProfile(); + return _internalManager.GetCurrentProfile(); } /// @@ -106,9 +106,9 @@ namespace Tizen.Network.Connection /// /// http://tizen.org/privilege/network.get /// Thrown when method failed due to invalid operation - static public ConnectionProfile GetDefaultCellularProfile(CellularServiceType type) + public ConnectionProfile GetDefaultCellularProfile(CellularServiceType type) { - return ConnectionInternalManager.GetDefaultCellularProfile(type); + return _internalManager.GetDefaultCellularProfile(type); } /// @@ -117,9 +117,9 @@ namespace Tizen.Network.Connection /// http://tizen.org/privilege/network.get /// http://tizen.org/privilege/network.profile /// Thrown when method failed due to invalid operation - static public Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile) + public Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile) { - return ConnectionInternalManager.SetDefaultCellularProfile(type, profile); + return _internalManager.SetDefaultCellularProfile(type, profile); } } diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/RequestCellularProfile.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/RequestCellularProfile.cs index 5d08604..e4ffcce 100644 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/RequestCellularProfile.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/RequestCellularProfile.cs @@ -40,15 +40,13 @@ namespace Tizen.Network.Connection /// The constructor of CellularProfile class with profile type and keyword. /// /// http://tizen.org/privilege/network.get - public RequestCellularProfile(string keyword) + internal RequestCellularProfile(IntPtr handle) { - Log.Debug(Globals.LogTag, "RequestCellularProfile : " + keyword); - ProfileHandle = ConnectionInternalManager.CreateRequestProfile(ConnectionProfileType.Cellular, keyword); - Log.Debug(Globals.LogTag, "RequestCellularProfile is created : " + ProfileHandle); + Log.Debug(Globals.LogTag, "RequestCellularProfile is created : " + handle); + ProfileHandle = handle; Ipv4 = new ConnectionAddressInformation(ProfileHandle, AddressFamily.Ipv4); Ipv6 = new ConnectionAddressInformation(ProfileHandle, AddressFamily.Ipv6); - AuthInfo = new CellularAuthInformation(ProfileHandle); } diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/RequestWiFiProfile.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/RequestWiFiProfile.cs index 965317c..16af8e1 100644 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/RequestWiFiProfile.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/RequestWiFiProfile.cs @@ -37,11 +37,11 @@ namespace Tizen.Network.Connection /// The constructor of WiFiProfile class with profile type and keyword. /// /// http://tizen.org/privilege/network.get - public RequestWiFiProfile(string keyword) + internal RequestWiFiProfile(IntPtr handle) { - Log.Debug(Globals.LogTag, "RequestWiFiProfile : " + keyword); - ProfileHandle = ConnectionInternalManager.CreateRequestProfile(ConnectionProfileType.WiFi, keyword); + Log.Debug(Globals.LogTag, "RequestWiFiProfile is created : " + handle); + ProfileHandle = handle; Ipv4 = new ConnectionAddressInformation(ProfileHandle, AddressFamily.Ipv4); Ipv6 = new ConnectionAddressInformation(ProfileHandle, AddressFamily.Ipv6); } -- 2.7.4