Modify ConnectionManager to non-static
authorchleun.moon <chleun.moon@samsung.com>
Fri, 13 Jan 2017 02:11:08 +0000 (11:11 +0900)
committerchleun.moon <chleun.moon@samsung.com>
Fri, 13 Jan 2017 07:19:26 +0000 (16:19 +0900)
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 <chleun.moon@samsung.com>
packaging/csapi-network-connection.spec
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/ConnectionProfileManager.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/RequestCellularProfile.cs
src/Tizen.Network.Connection/Tizen.Network.Connection/RequestWiFiProfile.cs

index bab0516..6e9ef3e 100644 (file)
@@ -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
index 03b9463..8f64a5c 100644 (file)
@@ -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<ConnectionError> SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
+        public Task<ConnectionError> SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
         {
             var task = new TaskCompletionSource<ConnectionError>();
             Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) =>
@@ -327,7 +362,7 @@ namespace Tizen.Network.Connection
         }
 
 
-        static public Task<IEnumerable<ConnectionProfile>> GetProfileListAsync(ProfileListType type)
+        public Task<IEnumerable<ConnectionProfile>> GetProfileListAsync(ProfileListType type)
         {
             var task = new TaskCompletionSource<IEnumerable<ConnectionProfile>>();
 
@@ -369,7 +404,7 @@ namespace Tizen.Network.Connection
             return task.Task;
         }
 
-        static public Task<ConnectionError> OpenProfileAsync(ConnectionProfile profile)
+        public Task<ConnectionError> OpenProfileAsync(ConnectionProfile profile)
         {
             var task = new TaskCompletionSource<ConnectionError>();
             Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) =>
@@ -386,7 +421,7 @@ namespace Tizen.Network.Connection
             return task.Task;
         }
 
-        static public Task<ConnectionError> CloseProfileAsync(ConnectionProfile profile)
+        public Task<ConnectionError> CloseProfileAsync(ConnectionProfile profile)
         {
             var task = new TaskCompletionSource<ConnectionError>();
             Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) =>
index 3a6e50b..8575c24 100644 (file)
@@ -29,20 +29,51 @@ namespace Tizen.Network.Connection
     /// <summary>
     /// This class is ConnectionManager
     /// </summary>
-    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;
+        }
 
         /// <summary>
         /// Event that is called when the type of the current connection is changed.
         /// </summary>
-        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
         /// <summary>
         /// Event for ethernet cable is plugged [in/out] event.
         /// </summary>
-        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
         /// <summary>
         /// Event that is called when the IP address is changed.
         /// </summary>
-        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
         /// <summary>
         /// Event that is called when the proxy address is changed.
         /// </summary>
-        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;
-        }
-
-
         /// <summary>
         /// Gets the IP address of the current connection.
         /// </summary>
         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
-        static public string GetIpAddress(AddressFamily family)
+        public string GetIpAddress(AddressFamily family)
         {
-            return ConnectionInternalManager.GetIpAddress(family);
+            return _internalManager.GetIpAddress(family);
         }
 
         /// <summary>
         /// Gets the proxy address of the current connection.
         /// </summary>
         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
-        static public string GetProxy(AddressFamily family)
+        public string GetProxy(AddressFamily family)
         {
-            return ConnectionInternalManager.GetProxy(family);
+            return _internalManager.GetProxy(family);
         }
 
         /// <summary>
         /// Gets the MAC address of the Wi-Fi or ethernet.
         /// </summary>
         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
-        static public string GetMacAddress(ConnectionType type)
+        public string GetMacAddress(ConnectionType type)
         {
-            return ConnectionInternalManager.GetMacAddress(type);
+            return _internalManager.GetMacAddress(type);
         }
 
         /// <summary>
-        /// Gets the type of the current profile for data connection.
+        /// Gets type and state of the current profile for data connection
         /// </summary>
-        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;
+        }
+
         /// <summary>
         /// Gets the state of cellular connection.
         /// </summary>
-        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.
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
-        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.
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
-        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.
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
-        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.
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
-        static public EthernetCableState EthernetCableState
+        public EthernetCableState EthernetCableState
         {
             get
             {
-                return ConnectionInternalManager.EthernetCableState;
+                return _internalManager.EthernetCableState;
             }
         }
-    }
+
+    } // class ConnectionManager
 
     /// <summary>
-    ///
+    /// class which contains connection information such as connection type and state
     /// </summary>
     public class ConnectionItem
     {
-        internal ConnectionItem()
+        ConnectionInternalManager _internalManager = null;
+        internal ConnectionItem(ConnectionInternalManager manager)
         {
+            _internalManager = manager;
         }
 
         /// <summary>
@@ -396,24 +420,24 @@ namespace Tizen.Network.Connection
         {
             get
             {
-                return ConnectionInternalManager.ConnectionType;
+                return _internalManager.ConnectionType;
             }
         }
 
         /// <summary>
-        /// Gets the type of the current profile for data connection.
+        /// Gets the state of the current profile for data connection.
         /// </summary>
         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
 
     /// <summary>
     /// An extended EventArgs class which contains changed connection type.
index 6849fc0..6c7aa8c 100644 (file)
@@ -33,6 +33,11 @@ namespace Tizen.Network.Connection
         private bool disposed = false;
         private EventHandler _ProfileStateChanged;
 
+        internal IntPtr GetHandle()
+        {
+            return ProfileHandle;
+        }
+
         /// <summary>
         /// The event that is called when the state of profile is changed.
         /// </summary>
@@ -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;
         }
 
index ada4cc6..5d530ed 100644 (file)
@@ -24,27 +24,27 @@ using System.Collections;
 namespace Tizen.Network.Connection
 {
     /// <summary>
-    /// This class is ConnectionProfileManager
+    /// This class is ConnectionManager
     /// </summary>
-    public class ConnectionProfileManager
+    public partial class ConnectionManager
     {
         /// <summary>
         /// Adds a new profile
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
-        static public int AddProfile(RequestProfile profile)
+        public int AddProfile(RequestProfile profile)
         {
-            return ConnectionInternalManager.AddProfile(profile);
+            return _internalManager.AddProfile(profile);
         }
 
         /// <summary>
         /// Gets the list of profile with profile list type
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
-        static public Task<IEnumerable<ConnectionProfile>> GetProfileListAsync(ProfileListType type)
+        public Task<IEnumerable<ConnectionProfile>> GetProfileListAsync(ProfileListType type)
         {
-            return ConnectionInternalManager.GetProfileListAsync(type);
+            return _internalManager.GetProfileListAsync(type);
         }
 
         /// <summary>
@@ -52,18 +52,18 @@ namespace Tizen.Network.Connection
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <privilege>http://tizen.org/privilege/network.set</privilege>
-        static public Task<ConnectionError> ConnectProfileAsync(ConnectionProfile profile)
+        public Task<ConnectionError> ConnectProfileAsync(ConnectionProfile profile)
         {
-            return ConnectionInternalManager.OpenProfileAsync(profile);
+            return _internalManager.OpenProfileAsync(profile);
         }
 
         /// <summary>
         /// Closes a connection of profile.
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.set</privilege>
-        static public Task<ConnectionError> DisconnectProfileAsync(ConnectionProfile profile)
+        public Task<ConnectionError> DisconnectProfileAsync(ConnectionProfile profile)
         {
-            return ConnectionInternalManager.CloseProfileAsync(profile);
+            return _internalManager.CloseProfileAsync(profile);
         }
 
         /// <summary>
@@ -72,10 +72,10 @@ namespace Tizen.Network.Connection
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
-        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);
         }
 
         /// <summary>
@@ -86,9 +86,9 @@ namespace Tizen.Network.Connection
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
-        static public int UpdateProfile(ConnectionProfile profile)
+        public int UpdateProfile(ConnectionProfile profile)
         {
-            return ConnectionInternalManager.UpdateProfile(profile);
+            return _internalManager.UpdateProfile(profile);
         }
 
         /// <summary>
@@ -96,9 +96,9 @@ namespace Tizen.Network.Connection
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
-        static public ConnectionProfile GetCurrentProfile()
+        public ConnectionProfile GetCurrentProfile()
         {
-            return ConnectionInternalManager.GetCurrentProfile();
+            return _internalManager.GetCurrentProfile();
         }
 
         /// <summary>
@@ -106,9 +106,9 @@ namespace Tizen.Network.Connection
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
-        static public ConnectionProfile GetDefaultCellularProfile(CellularServiceType type)
+        public ConnectionProfile GetDefaultCellularProfile(CellularServiceType type)
         {
-            return ConnectionInternalManager.GetDefaultCellularProfile(type);
+            return _internalManager.GetDefaultCellularProfile(type);
         }
 
         /// <summary>
@@ -117,9 +117,9 @@ namespace Tizen.Network.Connection
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
         /// <privilege>http://tizen.org/privilege/network.profile</privilege>
         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
-        static public Task<ConnectionError> SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
+        public Task<ConnectionError> SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
         {
-            return ConnectionInternalManager.SetDefaultCellularProfile(type, profile);
+            return _internalManager.SetDefaultCellularProfile(type, profile);
         }
     }
     
index 5d08604..e4ffcce 100644 (file)
@@ -40,15 +40,13 @@ namespace Tizen.Network.Connection
         /// The constructor of CellularProfile class with profile type and keyword.
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
-        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);
         }
 
index 965317c..16af8e1 100644 (file)
@@ -37,11 +37,11 @@ namespace Tizen.Network.Connection
         /// The constructor of WiFiProfile class with profile type and keyword.
         /// </summary>
         /// <privilege>http://tizen.org/privilege/network.get</privilege>
-        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);
         }