From d50d3bbe37d3153b0aae4595b0df2020078bae50 Mon Sep 17 00:00:00 2001 From: "chleun.moon" Date: Wed, 24 May 2017 14:20:24 +0900 Subject: [PATCH] Add API reference and exception as per the guidelines Change-Id: I36981d2b6456fb164fd3c8ec70e2c1a1564c0e07 Signed-off-by: cheoleun --- packaging/csapi-network-connection.spec | 2 +- .../Tizen.Network.Connection/CellularProfile.cs | 75 ++++++- .../Tizen.Network.Connection/ConnectionError.cs | 39 +++- .../ConnectionInternalManager.cs | 241 +++++++++++++++------ .../Tizen.Network.Connection/ConnectionManager.cs | 63 +++++- .../Tizen.Network.Connection/ConnectionProfile.cs | 59 ++++- .../ConnectionProfileManager.cs | 120 ++++++++-- .../IAddressInformation.cs | 48 +++- .../Tizen.Network.Connection/WiFiProfile.cs | 40 +++- 9 files changed, 560 insertions(+), 127 deletions(-) diff --git a/packaging/csapi-network-connection.spec b/packaging/csapi-network-connection.spec index 157f778..6d48f9f 100755 --- 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.16 +Version: 1.0.17 Release: 1 Group: Development/Libraries License: Apache-2.0 diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs index 628cc33..2c58096 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/CellularProfile.cs @@ -41,10 +41,17 @@ namespace Tizen.Network.Connection /// /// The APN (access point name). /// + /// Cellular access point name. + /// Thrown during set when feature is not supported. + /// Thrown during set when value is invalid parameter. + /// Thrown during set when value is null. + /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. + /// Thrown when operation is performed on a disposed object. public string Apn { get { + Log.Debug(Globals.LogTag, "Get Apn"); IntPtr Value; int ret = Interop.ConnectionCellularProfile.GetApn(ProfileHandle, out Value); if ((ConnectionError)ret != ConnectionError.None) @@ -55,13 +62,26 @@ namespace Tizen.Network.Connection Interop.Libc.Free(Value); return result; } + set { - int ret = Interop.ConnectionCellularProfile.SetApn(ProfileHandle, (string)value); - if ((ConnectionError)ret != ConnectionError.None) + Log.Debug(Globals.LogTag, "Set Apn"); + CheckDisposed(); + if (value != null) { - Log.Error(Globals.LogTag, "It failed to set apn, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); + int ret = Interop.ConnectionCellularProfile.SetApn(ProfileHandle, value); + if ((ConnectionError)ret != ConnectionError.None) + { + Log.Error(Globals.LogTag, "It failed to set apn, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); + ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } + } + + else + { + throw new ArgumentNullException("Value of Apn is null"); } } } @@ -69,10 +89,17 @@ namespace Tizen.Network.Connection /// /// The home URL. /// + /// Cellular home URL. + /// Thrown during set when feature is not supported. + /// Thrown during set when value is invalid parameter. + /// Thrown during set when value is null. + /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. + /// Thrown when operation is performed on a disposed object. public string HomeUri { get { + Log.Debug(Globals.LogTag, "Get HomeUri"); IntPtr Value; int ret = Interop.ConnectionCellularProfile.GetHomeUrl(ProfileHandle, out Value); if ((ConnectionError)ret != ConnectionError.None) @@ -83,25 +110,43 @@ namespace Tizen.Network.Connection Interop.Libc.Free(Value); return result; } + set { - int ret = Interop.ConnectionCellularProfile.SetHomeUrl(ProfileHandle, (string)value); - if ((ConnectionError)ret != ConnectionError.None) + Log.Debug(Globals.LogTag, "Set HomeUri"); + CheckDisposed(); + if (value != null) { - Log.Error(Globals.LogTag, "It failed to set home url, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); + int ret = Interop.ConnectionCellularProfile.SetHomeUrl(ProfileHandle, value); + if ((ConnectionError)ret != ConnectionError.None) + { + Log.Error(Globals.LogTag, "It failed to set home url, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); + ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } } + else + { + throw new ArgumentNullException("Value of HomeUri is null"); + } } } /// /// The service type. /// + /// Cellular service type. + /// Thrown during set when feature is not supported. + /// Thrown during set when value is invalid parameter. + /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. + /// Thrown when operation is performed on a disposed object. public CellularServiceType ServiceType { get { + Log.Debug(Globals.LogTag, "Get ServiceType"); int value; int ret = Interop.ConnectionCellularProfile.GetServiceType(ProfileHandle, out value); if ((ConnectionError)ret != ConnectionError.None) @@ -110,20 +155,26 @@ namespace Tizen.Network.Connection } return (CellularServiceType)value; } + set { + Log.Debug(Globals.LogTag, "Set ServiceType"); + CheckDisposed(); int ret = Interop.ConnectionCellularProfile.SetServiceType(ProfileHandle, (int)value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set service type, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); + ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } } /// - /// Gets cellular Authentification Information. + /// The cellular Authentication Information. /// + /// Cellular authentication information public CellularAuthInformation CellularAuthInfo { get @@ -135,6 +186,7 @@ namespace Tizen.Network.Connection /// /// Checks whether the profile is hidden. /// + /// True if the cellular profile is hidden, otherwise false. public bool Hidden { get @@ -152,6 +204,7 @@ namespace Tizen.Network.Connection /// /// Checks whether the profile is editable. /// + /// True if the cellular profile is editable, otherwise false. public bool Editable { get @@ -169,6 +222,7 @@ namespace Tizen.Network.Connection /// /// Checks whether the profile is default. /// + /// True if the cellular profile is default, otherwise false. public bool IsDefault { get @@ -203,6 +257,7 @@ namespace Tizen.Network.Connection /// /// The user name. /// + /// Cellular user name. public string UserName { get @@ -242,6 +297,7 @@ namespace Tizen.Network.Connection /// /// The password /// + /// Cellular password. public string Password { get @@ -279,6 +335,7 @@ namespace Tizen.Network.Connection /// /// The authentication type /// + /// Cellular authentication type. public CellularAuthType AuthType { get diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionError.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionError.cs index be0e5dc..9e8d587 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionError.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionError.cs @@ -24,7 +24,34 @@ namespace Tizen.Network.Connection { internal static class ConnectionErrorFactory { - internal static void ThrowConnectionException(int errno) + internal static void CheckFeatureUnsupportedException(int err, string message) + { + if ((ConnectionError)err == ConnectionError.NotSupported) + { + ThrowConnectionException(err, message); + } + } + + internal static void CheckPermissionDeniedException(int err, string message) + { + if ((ConnectionError)err == ConnectionError.PermissionDenied) + { + ThrowConnectionException(err, message); + } + } + + internal static void CheckHandleNullException(int err, bool isHandleInvalid, string message) + { + if ((ConnectionError)err == ConnectionError.InvalidParameter) + { + if (isHandleInvalid) + { + ThrowConnectionException((int)ConnectionError.InvalidOperation, message); + } + } + } + + internal static void ThrowConnectionException(int errno , string message = "") { ConnectionError _error = (ConnectionError)errno; Log.Debug(Globals.LogTag, "ThrowConnectionException " + _error); @@ -41,15 +68,15 @@ namespace Tizen.Network.Connection case ConnectionError.InvalidKey: throw new InvalidOperationException("Invalid Key"); case ConnectionError.InvalidOperation: - throw new InvalidOperationException("Invalid Operation"); + throw new InvalidOperationException("Invalid Operation " + message); case ConnectionError.InvalidParameter: - throw new InvalidOperationException("Invalid Parameter"); + throw new ArgumentException("Invalid Parameter"); case ConnectionError.NoConnection: throw new InvalidOperationException("No Connection"); case ConnectionError.NoReply: throw new InvalidOperationException("No Reply"); case ConnectionError.NotSupported: - throw new NotSupportedException("Not Supported"); + throw new NotSupportedException("Unsupported feature " + message); case ConnectionError.NowInProgress: throw new InvalidOperationException("Now In Progress"); case ConnectionError.OperationAborted: @@ -57,9 +84,9 @@ namespace Tizen.Network.Connection case ConnectionError.OperationFailed: throw new InvalidOperationException("Operation Failed"); case ConnectionError.OutOfMemoryError: - throw new InvalidOperationException("Out Of Memory Error"); + throw new OutOfMemoryException("Out Of Memory Error"); case ConnectionError.PermissionDenied: - throw new InvalidOperationException("Permission Denied"); + throw new UnauthorizedAccessException("Permission Denied " + message); } } } diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs index deb59d4..374f2c2 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionInternalManager.cs @@ -32,9 +32,14 @@ namespace Tizen.Network.Connection public HandleHolder() { - Log.Debug(Globals.LogTag, "HandleHolder() ^^"); - Interop.Connection.Create(out Handle); Log.Debug(Globals.LogTag, "Handle: " + Handle); + int ret = Interop.Connection.Create(out Handle); + if(ret != (int)ConnectionError.None) + { + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } } ~HandleHolder() @@ -71,6 +76,10 @@ namespace Tizen.Network.Connection private void Destroy() { Interop.Connection.Destroy(Handle); + if (Handle != IntPtr.Zero) + { + Handle = IntPtr.Zero; + } } } @@ -397,8 +406,11 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get IP address, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } + string result = Marshal.PtrToStringAnsi(ip); Interop.Libc.Free(ip); return result; @@ -411,8 +423,11 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get proxy, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } + string result = Marshal.PtrToStringAnsi(ip); Interop.Libc.Free(ip); return result; @@ -425,6 +440,8 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get mac address, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } string result = Marshal.PtrToStringAnsi(ip); @@ -526,60 +543,99 @@ namespace Tizen.Network.Connection internal IntPtr CreateCellularProfile(ConnectionProfileType type, string keyword) { - Log.Error(Globals.LogTag, "CreateCellularProfile, " + type + ", " + keyword); - IntPtr connectionHandle = GetHandle(); - if (connectionHandle == IntPtr.Zero) + + Log.Debug(Globals.LogTag, "CreateCellularProfile, " + type + ", " + keyword); + if (keyword != null) { - Log.Error(Globals.LogTag, "It failed to create connection handle"); - throw new InvalidOperationException("Invalid connection handle"); + IntPtr handle = IntPtr.Zero; + int ret = Interop.ConnectionProfile.Create((int)type, keyword, out handle); + if ((ConnectionError)ret != ConnectionError.None) + { + Log.Error(Globals.LogTag, "It failed to Create profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.telephony"); + ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } + + return handle; } - IntPtr handle = IntPtr.Zero; - int ret = Interop.ConnectionProfile.Create((int)type, keyword, out handle); - if ((ConnectionError)ret != ConnectionError.None) + else { - Log.Error(Globals.LogTag, "It failed to Create profile, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); + throw new ArgumentNullException("Keyword is null"); } - - return handle; } internal void AddCellularProfile(CellularProfile profile) { - if (profile.Type == ConnectionProfileType.Cellular) + + Log.Debug(Globals.LogTag, "AddCellularProfile"); + if (profile != null) { - int ret = Interop.Connection.AddProfile(GetHandle(), profile.ProfileHandle); - if ((ConnectionError)ret != ConnectionError.None) + if (profile.Type == ConnectionProfileType.Cellular) { - Log.Error(Globals.LogTag, "Failed to add cellular profile, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); + int ret = Interop.Connection.AddProfile(GetHandle(), profile.ProfileHandle); + if ((ConnectionError)ret != ConnectionError.None) + { + Log.Error(Globals.LogTag, "Failed to add cellular profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); + ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.profile)"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } + } + + else + { + throw new ArgumentException("Profile type is not cellular"); } } else { - throw new InvalidOperationException("Profile type is not cellular"); + throw new ArgumentNullException("Profile is null"); } } internal void RemoveProfile(ConnectionProfile profile) { - int ret = Interop.Connection.RemoveProfile(GetHandle(), profile.ProfileHandle); - if ((ConnectionError)ret != ConnectionError.None) + Log.Debug(Globals.LogTag, "RemoveProfile"); + if (profile != null) { - Log.Error(Globals.LogTag, "It failed to remove profile, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); + int ret = Interop.Connection.RemoveProfile(GetHandle(), profile.ProfileHandle); + if ((ConnectionError)ret != ConnectionError.None) + { + Log.Error(Globals.LogTag, "It failed to remove profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.telephony"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } + } + + else + { + throw new ArgumentNullException("Profile is null"); } } internal void UpdateProfile(ConnectionProfile profile) { - int ret = Interop.Connection.UpdateProfile(GetHandle(), profile.ProfileHandle); - if ((ConnectionError)ret != ConnectionError.None) + Log.Debug(Globals.LogTag, "UpdateProfile"); + if (profile != null) { - Log.Error(Globals.LogTag, "It failed to update profile, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); + int ret = Interop.Connection.UpdateProfile(GetHandle(), profile.ProfileHandle); + if ((ConnectionError)ret != ConnectionError.None) + { + Log.Error(Globals.LogTag, "It failed to update profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } + } + + else + { + throw new ArgumentNullException("Profile is null"); } } @@ -590,8 +646,12 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get current profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } + ConnectionProfile Profile = new ConnectionProfile(ProfileHandle); return Profile; } @@ -604,34 +664,49 @@ namespace Tizen.Network.Connection { Log.Error(Globals.LogTag, "Error: " + ret); Log.Error(Globals.LogTag, "It failed to get default cellular profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); + ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } + CellularProfile Profile = new CellularProfile(ProfileHandle); return Profile; } internal Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile) { - TaskCompletionSource task = new TaskCompletionSource(); - Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => + Log.Debug(Globals.LogTag, "SetDefaultCellularProfile"); + if (profile != null) { - if (Result != ConnectionError.None) + TaskCompletionSource task = new TaskCompletionSource(); + Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => + { + if (Result != ConnectionError.None) + { + Log.Error(Globals.LogTag, "Error occurs during set default cellular profile, " + Result); + task.SetException(new InvalidOperationException("Error occurs during set default cellular profile, " + Result)); + } + + task.SetResult(true); + }; + + int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, Callback, (IntPtr)0); + if ((ConnectionError)ret != ConnectionError.None) { - Log.Error(Globals.LogTag, "Error occurs during set default cellular profile, " + Result); - task.SetException(new InvalidOperationException("Error occurs during set default cellular profile, " + Result)); + Log.Error(Globals.LogTag, "It failed to set default cellular profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); } - task.SetResult(true); - }; + return task.Task; + } - int ret = Interop.Connection.SetDefaultCellularServiceProfileAsync(GetHandle(), (int)type, profile.ProfileHandle, Callback, (IntPtr)0); - if ((ConnectionError)ret != ConnectionError.None) + else { - Log.Error(Globals.LogTag, "It failed to set default cellular profile, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); + throw new ArgumentNullException("Profile is null"); } - - return task.Task; } @@ -645,6 +720,10 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get profile iterator, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.get)"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero), "Connection Handle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); } while (Interop.Connection.HasNextProfileIterator(iterator)) @@ -679,50 +758,76 @@ namespace Tizen.Network.Connection internal Task OpenProfileAsync(ConnectionProfile profile) { - TaskCompletionSource task = new TaskCompletionSource(); - Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => + Log.Debug(Globals.LogTag, "OpenProfileAsync"); + if (profile != null) { - if (Result != ConnectionError.None) + Log.Debug(Globals.LogTag, "OpenProfileAsync " + profile.Name); + TaskCompletionSource task = new TaskCompletionSource(); + Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => + { + Log.Debug(Globals.LogTag, "Connected " + profile.Name); + if (Result != ConnectionError.None) + { + Log.Error(Globals.LogTag, "Error occurs during connecting profile, " + Result); + task.SetException(new InvalidOperationException("Error occurs during connecting profile, " + Result)); + } + + task.SetResult(true); + }; + + int ret = Interop.Connection.OpenProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero); + if ((ConnectionError)ret != ConnectionError.None) { - Log.Error(Globals.LogTag, "Error occurs during connecting profile, " + Result); - task.SetException(new InvalidOperationException("Error occurs during connecting profile, " + Result)); + Log.Error(Globals.LogTag, "It failed to connect profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); } - task.SetResult(true); - }; + return task.Task; + } - int ret = Interop.Connection.OpenProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero); - if ((ConnectionError)ret != ConnectionError.None) + else { - Log.Error(Globals.LogTag, "It failed to connect profile, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); + throw new ArgumentNullException("Profile is null"); } - - return task.Task; } internal Task CloseProfileAsync(ConnectionProfile profile) { - TaskCompletionSource task = new TaskCompletionSource(); - Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => + Log.Debug(Globals.LogTag, "CloseProfileAsync"); + if (profile != null) { - if (Result != ConnectionError.None) + Log.Debug(Globals.LogTag, "CloseProfileAsync " + profile.Name); + TaskCompletionSource task = new TaskCompletionSource(); + Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) => + { + if (Result != ConnectionError.None) + { + Log.Error(Globals.LogTag, "Error occurs during disconnecting profile, " + Result); + task.SetException(new InvalidOperationException("Error occurs during disconnecting profile, " + Result)); + } + + task.SetResult(true); + }; + + int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero); + if ((ConnectionError)ret != ConnectionError.None) { - Log.Error(Globals.LogTag, "Error occurs during disconnecting profile, " + Result); - task.SetException(new InvalidOperationException("Error occurs during disconnecting profile, " + Result)); + Log.Error(Globals.LogTag, "It failed to disconnect profile, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth"); + ConnectionErrorFactory.CheckPermissionDeniedException(ret, "(http://tizen.org/privilege/network.set)"); + ConnectionErrorFactory.CheckHandleNullException(ret, (GetHandle() == IntPtr.Zero || profile.ProfileHandle == IntPtr.Zero), "Connection or Profile Handle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); } - task.SetResult(true); - }; + return task.Task; + } - int ret = Interop.Connection.CloseProfile(GetHandle(), profile.ProfileHandle, Callback, IntPtr.Zero); - if ((ConnectionError)ret != ConnectionError.None) + else { - Log.Error(Globals.LogTag, "It failed to disconnect profile, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); + throw new ArgumentNullException("Profile is null"); } - - return task.Task; } } -} \ No newline at end of file +} diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs index 4b1c65b..13c4e58 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionManager.cs @@ -40,6 +40,7 @@ namespace Tizen.Network.Connection /// /// Checks whether the handle value is valid or not. /// + /// True if the handle is invalid, otherwise false. public override bool IsInvalid { get @@ -48,6 +49,10 @@ namespace Tizen.Network.Connection } } + /// + /// Frees the handle. + /// + /// True if the handle is released successfully, otherwise false. protected override bool ReleaseHandle() { this.SetHandle(IntPtr.Zero); @@ -141,8 +146,17 @@ namespace Tizen.Network.Connection /// Gets the IP address of the current connection. /// /// The address family - /// IP address of the connection. - /// Thrown when method failed due to invalid operation + /// IP address of the connection (global address in case of IPv6). + /// http://tizen.org/privilege/network.get + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection instance is invalid or when method failed due to invalid operation. public static string GetIPAddress(AddressFamily family) { return ConnectionInternalManager.Instance.GetIPAddress(family); @@ -153,7 +167,16 @@ namespace Tizen.Network.Connection /// /// The address family /// Proxy address of the connection. - /// Thrown when method failed due to invalid operation + /// http://tizen.org/privilege/network.get + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection instance is invalid or when method failed due to invalid operation. public static string GetProxy(AddressFamily family) { return ConnectionInternalManager.Instance.GetProxy(family); @@ -164,7 +187,16 @@ namespace Tizen.Network.Connection /// /// The type of current network connection /// MAC address of the Wi-Fi or ethernet. - /// Thrown when method failed due to invalid operation + /// http://tizen.org/privilege/network.get + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection instance is invalid or when method failed due to invalid operation. public static string GetMacAddress(ConnectionType type) { return ConnectionInternalManager.Instance.GetMacAddress(type); @@ -173,6 +205,7 @@ namespace Tizen.Network.Connection /// /// Type and state of the current profile for data connection /// + /// Instance of ConnectionItem public static ConnectionItem CurrentConnection { get @@ -192,6 +225,14 @@ namespace Tizen.Network.Connection /// The type of profile. Cellular profile type is supported. /// The keyword included in profile name. /// CellularProfile object + /// http://tizen.org/privilege/network.get + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when keyword value is null. + /// Thrown when method failed due to invalid operation. public static CellularProfile CreateCellularProfile(ConnectionProfileType type, string keyword) { IntPtr profileHandle = IntPtr.Zero; @@ -212,6 +253,8 @@ namespace Tizen.Network.Connection /// /// The state of cellular connection. /// + /// Cellular network state. + /// http://tizen.org/privilege/network.get public static CellularState CellularState { get @@ -223,6 +266,7 @@ namespace Tizen.Network.Connection /// /// The state of the Wi-Fi. /// + /// WiFi connection state. /// http://tizen.org/privilege/network.get public static ConnectionState WiFiState { @@ -235,6 +279,7 @@ namespace Tizen.Network.Connection /// /// The state of the Bluetooth. /// + /// Bluetooth connection state. /// http://tizen.org/privilege/network.get public static ConnectionState BluetoothState { @@ -247,6 +292,7 @@ namespace Tizen.Network.Connection /// /// The Ethernet connection state. /// + /// Ethernet connection state. /// http://tizen.org/privilege/network.get public static ConnectionState EthernetState { @@ -259,6 +305,7 @@ namespace Tizen.Network.Connection /// /// Checks for ethernet cable is attached or not. /// + /// Ethernet cable state. /// http://tizen.org/privilege/network.get public static EthernetCableState EthernetCableState { @@ -282,6 +329,8 @@ namespace Tizen.Network.Connection /// /// The type of the current profile for data connection. /// + /// Data connection current profile. + /// http://tizen.org/privilege/network.get public ConnectionType Type { get @@ -293,6 +342,8 @@ namespace Tizen.Network.Connection /// /// The state of the current profile for data connection. /// + /// Connection state of the current connection type. + /// http://tizen.org/privilege/network.get public ConnectionState State { get @@ -345,6 +396,7 @@ namespace Tizen.Network.Connection /// /// The connection type. /// + /// Type of the connection. public ConnectionType ConnectionType { get @@ -369,6 +421,7 @@ namespace Tizen.Network.Connection /// /// The ethernet cable state. /// + /// Attached or detached state of the ethernet cable. public EthernetCableState EthernetCableState { get @@ -395,6 +448,7 @@ namespace Tizen.Network.Connection /// /// The IPV4 address. /// + /// IP address in the format of IPV4 syntax. public string IPv4Address { get @@ -406,6 +460,7 @@ namespace Tizen.Network.Connection /// /// The IPV6 address. /// + /// IP address in the format of IPV6 syntax. public string IPv6Address { get diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs index 7e70bc9..5087d8b 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfile.cs @@ -101,6 +101,9 @@ namespace Tizen.Network.Connection Dispose(false); } + /// + /// Disposes the memory allocated to unmanaged resources. + /// public void Dispose() { Dispose(true); @@ -133,11 +136,21 @@ namespace Tizen.Network.Connection private void Destroy() { Interop.ConnectionProfile.Destroy(ProfileHandle); + ProfileHandle = IntPtr.Zero; + } + + internal void CheckDisposed() + { + if (disposed) + { + throw new ObjectDisposedException(GetType().FullName); + } } /// /// The profile ID. /// + /// Unique ID of the profile. public string Id { get @@ -157,7 +170,7 @@ namespace Tizen.Network.Connection /// /// The profile name. /// - /// http://tizen.org/privilege/network.get + /// User friendly name of the profile. public string Name { get @@ -177,6 +190,7 @@ namespace Tizen.Network.Connection /// /// The network type. /// + /// Profile type of the network connection. public ConnectionProfileType Type { get @@ -192,8 +206,9 @@ namespace Tizen.Network.Connection } /// - /// The name of the network interface, e.g. eth0 and pdp0. + /// The name of the network interface. /// + /// Network interface name, e.g. eth0 and pdp0. public string InterfaceName { get @@ -230,6 +245,11 @@ namespace Tizen.Network.Connection /// /// The Proxy type. /// + /// Proxy type of the connection. + /// Thrown during set when feature is not supported. + /// Thrown during set when value is invalid parameter. + /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. + /// Thrown during set when operation is performed on a disposed object. public ProxyType ProxyType { get @@ -243,12 +263,16 @@ namespace Tizen.Network.Connection return (ProxyType)Value; } + set { + CheckDisposed(); int ret = Interop.ConnectionProfile.SetProxyType(ProfileHandle, (int)value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set proxy type, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } @@ -257,7 +281,13 @@ namespace Tizen.Network.Connection /// /// The proxy address. /// - public String ProxyAddress + /// Proxy address of the connection. + /// Thrown during set when feature is not supported. + /// Thrown during set when value is invalid parameter. + /// Thrown during set when value is null. + /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. + /// Thrown when operation is performed on a disposed object. + public string ProxyAddress { get { @@ -272,13 +302,25 @@ namespace Tizen.Network.Connection return result; } + set { - int ret = Interop.ConnectionProfile.SetProxyAddress(ProfileHandle, (int)AddressFamily.IPv4, value.ToString()); - if ((ConnectionError)ret != ConnectionError.None) + CheckDisposed(); + if (value != null) { - Log.Error(Globals.LogTag, "It failed to set proxy address, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); + int ret = Interop.ConnectionProfile.SetProxyAddress(ProfileHandle, (int)AddressFamily.IPv4, value); + if ((ConnectionError)ret != ConnectionError.None) + { + Log.Error(Globals.LogTag, "It failed to set proxy address, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } + } + + else + { + throw new ArgumentNullException("ProxyAddress is null"); } } } @@ -286,6 +328,7 @@ namespace Tizen.Network.Connection /// /// The subnet mask address(IPv4). /// + /// Instance of IAddressInformation with IPV4 address. public IAddressInformation IPv4Settings { get @@ -298,6 +341,7 @@ namespace Tizen.Network.Connection /// /// The subnet mask address(IPv4). /// + /// Instance of IAddressInformation with IPV6 address. public IAddressInformation IPv6Settings { get @@ -322,6 +366,7 @@ namespace Tizen.Network.Connection /// /// The profile state. /// + /// State type of the connection profile. public ProfileState State { get diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfileManager.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfileManager.cs index cbd2933..af696c4 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfileManager.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/ConnectionProfileManager.cs @@ -31,9 +31,19 @@ namespace Tizen.Network.Connection /// /// Adds a new profile /// - /// http://tizen.org/privilege/network.profile /// The cellular profile object - /// Thrown when method failed due to invalid operation + /// http://tizen.org/privilege/network.profile + /// http://tizen.org/privilege/network.get + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when value is null. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection or profile instance is invalid or when method failed due to invalid operation public static void AddCellularProfile(CellularProfile profile) { ConnectionInternalManager.Instance.AddCellularProfile(profile); @@ -42,9 +52,18 @@ namespace Tizen.Network.Connection /// /// Gets the list of profile with profile list type /// - /// http://tizen.org/privilege/network.get /// The type of profile /// List of connection profile objects. + /// http://tizen.org/privilege/network.get + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection instance has been disposed. public static Task> GetProfileListAsync(ProfileListType type) { return ConnectionInternalManager.Instance.GetProfileListAsync(type); @@ -53,11 +72,20 @@ namespace Tizen.Network.Connection /// /// Opens a connection of profile, asynchronously. /// - /// http://tizen.org/privilege/network.get - /// http://tizen.org/privilege/network.set /// The connection profile object /// A task indicates whether the ConnectProfileAsync method is done successfully or not. - /// Thrown when method failed due to invalid operation + /// http://tizen.org/privilege/network.get + /// http://tizen.org/privilege/network.set + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when value is null. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection or profile instance is invalid or when method failed due to invalid operation public static Task ConnectProfileAsync(ConnectionProfile profile) { return ConnectionInternalManager.Instance.OpenProfileAsync(profile); @@ -66,10 +94,20 @@ namespace Tizen.Network.Connection /// /// Closes a connection of profile. /// - /// http://tizen.org/privilege/network.set /// The connection profile object /// A task indicates whether the DisconnectProfileAsync method is done successfully or not. - /// Thrown when method failed due to invalid operation + /// http://tizen.org/privilege/network.get + /// http://tizen.org/privilege/network.set + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when value is null. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection or profile instance is invalid or when method failed due to invalid operation public static Task DisconnectProfileAsync(ConnectionProfile profile) { return ConnectionInternalManager.Instance.CloseProfileAsync(profile); @@ -78,10 +116,19 @@ namespace Tizen.Network.Connection /// /// Removes an existing profile. /// + /// The connection profile object /// http://tizen.org/privilege/network.get /// http://tizen.org/privilege/network.profile - /// The connection profile object - /// Thrown when method failed due to invalid operation + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when value is null. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection or profile instance is invalid or when method failed due to invalid operation public static void RemoveProfile(ConnectionProfile profile) { Log.Debug(Globals.LogTag, "RemoveProfile. Id: " + profile.Id + ", Name: " + profile.Name + ", Type: " + profile.Type); @@ -93,10 +140,19 @@ namespace Tizen.Network.Connection /// When a profile is changed, these changes will be not applied to the ConnectionProfileManager immediately. /// When you call this function, your changes affect the ConnectionProfileManager and the existing profile is updated. /// + /// The connection profile object /// http://tizen.org/privilege/network.get /// http://tizen.org/privilege/network.profile - /// The connection profile object - /// Thrown when method failed due to invalid operation + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when value is null. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection or profile instance is invalid or when method failed due to invalid operation public static void UpdateProfile(ConnectionProfile profile) { ConnectionInternalManager.Instance.UpdateProfile(profile); @@ -105,9 +161,17 @@ namespace Tizen.Network.Connection /// /// Gets the name of the default profile. /// - /// http://tizen.org/privilege/network.get /// Connection profile object. - /// Thrown when method failed due to invalid operation + /// http://tizen.org/privilege/network.get + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection instance is invalid or when method failed due to invalid operation public static ConnectionProfile GetCurrentProfile() { return ConnectionInternalManager.Instance.GetCurrentProfile(); @@ -116,10 +180,18 @@ namespace Tizen.Network.Connection /// /// Gets the default profile which provides the given cellular service. /// - /// http://tizen.org/privilege/network.get /// The cellular service type /// Connection profile object. - /// Thrown when method failed due to invalid operation + /// http://tizen.org/privilege/network.get + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection instance is invalid or when method failed due to invalid operation public static ConnectionProfile GetDefaultCellularProfile(CellularServiceType type) { return ConnectionInternalManager.Instance.GetDefaultCellularProfile(type); @@ -128,12 +200,21 @@ namespace Tizen.Network.Connection /// /// Sets the default profile which provides the given cellular service. /// - /// http://tizen.org/privilege/network.get - /// http://tizen.org/privilege/network.profile /// The cellular service type /// The connection profile object /// A task indicates whether the SetDefaultCellularProfile method is done successfully or not. - /// Thrown when method failed due to invalid operation + /// http://tizen.org/privilege/network.get + /// http://tizen.org/privilege/network.profile + /// http://tizen.org/feature/network.telephony + /// http://tizen.org/feature/network.wifi + /// http://tizen.org/feature/network.tethering.bluetooth + /// http://tizen.org/feature/network.ethernet + /// Thrown when feature is not supported. + /// Thrown when permission is denied. + /// Thrown when value is invalid parameter. + /// Thrown when value is null. + /// Thrown when memory is not enough to continue execution. + /// Thrown when connection or profile instance is invalid or when method failed due to invalid operation public static Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile) { return ConnectionInternalManager.Instance.SetDefaultCellularProfile(type, profile); @@ -155,6 +236,7 @@ namespace Tizen.Network.Connection /// /// The connection profile state. /// + /// State of the connection profile. public ConnectionProfileState ConnectionProfileState { get diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs index b9f76aa..767893d 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/IAddressInformation.cs @@ -32,31 +32,55 @@ namespace Tizen.Network.Connection /// /// The DNS address. /// + /// First DNS address of the connection. + /// Thrown during set when feature is not supported. + /// Thrown during set when value is invalid parameter. + /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. System.Net.IPAddress Dns1 { get; set; } /// /// The DNS address. /// + /// Second DNS address of the connection. + /// Thrown during set when feature is not supported. + /// Thrown during set when value is invalid parameter. + /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. System.Net.IPAddress Dns2 { get; set; } /// /// The gateway address. /// + /// Gateway address of the connection. + /// Thrown during set when feature is not supported. + /// Thrown during set when value is invalid parameter. + /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. System.Net.IPAddress Gateway { get; set; } /// /// The subnet mask address. /// + /// Subnet mask of the connection. + /// Thrown during set when feature is not supported. + /// Thrown during set when value is invalid parameter. + /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. System.Net.IPAddress SubnetMask { get; set; } /// /// The IP address. /// + /// IP address of the connection. + /// Thrown during set when feature is not supported. + /// Thrown during set when value is invalid parameter. + /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. System.Net.IPAddress IP { get; set; } /// /// The type of IP config. /// + /// IP config type of the connection. + /// Thrown during set when feature is not supported. + /// Thrown during set when value is invalid parameter. + /// Thrown during set when profile instance is invalid or when method failed due to invalid operation. IPConfigType IPConfigType { get; set; } } @@ -80,7 +104,6 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get dns1 address, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); } string result = Marshal.PtrToStringAnsi(Value); Interop.Libc.Free(Value); @@ -88,12 +111,15 @@ namespace Tizen.Network.Connection return System.Net.IPAddress.Parse("0.0.0.0"); return System.Net.IPAddress.Parse(result); } + set { int ret = Interop.ConnectionProfile.SetDnsAddress(_profileHandle, (int)_family, value.ToString()); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set dns1 address, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (_profileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } @@ -107,7 +133,6 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get dns2 address, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); } string result = Marshal.PtrToStringAnsi(Value); Interop.Libc.Free(Value); @@ -115,12 +140,15 @@ namespace Tizen.Network.Connection return System.Net.IPAddress.Parse("0.0.0.0"); return System.Net.IPAddress.Parse(result); } + set { int ret = Interop.ConnectionProfile.SetDnsAddress(_profileHandle, (int)_family, value.ToString()); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set dns2 address, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (_profileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } @@ -135,7 +163,6 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get gateway, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); } string result = Marshal.PtrToStringAnsi(Value); Interop.Libc.Free(Value); @@ -143,12 +170,15 @@ namespace Tizen.Network.Connection return System.Net.IPAddress.Parse("0.0.0.0"); return System.Net.IPAddress.Parse(result); } + set { int ret = Interop.ConnectionProfile.SetGatewayAddress(_profileHandle, (int)_family, value.ToString()); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set gateway, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (_profileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } @@ -164,7 +194,6 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get subnet mask, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); } string result = Marshal.PtrToStringAnsi(Value); Interop.Libc.Free(Value); @@ -172,12 +201,15 @@ namespace Tizen.Network.Connection return System.Net.IPAddress.Parse("0.0.0.0"); return System.Net.IPAddress.Parse(result); } + set { int ret = Interop.ConnectionProfile.SetSubnetMask(_profileHandle, (int)_family, value.ToString()); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set subnet mask, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (_profileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } @@ -193,7 +225,6 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get ip, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); } string result = Marshal.PtrToStringAnsi(Value); Interop.Libc.Free(Value); @@ -201,12 +232,15 @@ namespace Tizen.Network.Connection return System.Net.IPAddress.Parse("0.0.0.0"); return System.Net.IPAddress.Parse(result); } + set { int ret = Interop.ConnectionProfile.SetIPAddress(_profileHandle, (int)_family, value.ToString()); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set ip, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (_profileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } @@ -221,16 +255,18 @@ namespace Tizen.Network.Connection if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to get ip config type, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); } return (IPConfigType)Value; } + set { int ret = Interop.ConnectionProfile.SetIPConfigType(_profileHandle, (int)_family, (int)value); if ((ConnectionError)ret != ConnectionError.None) { Log.Error(Globals.LogTag, "It failed to set ip config type, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.telephony " + "http://tizen.org/feature/network.wifi " + "http://tizen.org/feature/network.tethering.bluetooth " + "http://tizen.org/feature/network.ethernet"); + ConnectionErrorFactory.CheckHandleNullException(ret, (_profileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); ConnectionErrorFactory.ThrowConnectionException(ret); } } diff --git a/src/Tizen.Network.Connection/Tizen.Network.Connection/WiFiProfile.cs b/src/Tizen.Network.Connection/Tizen.Network.Connection/WiFiProfile.cs index 8e22ce2..dddfb0b 100755 --- a/src/Tizen.Network.Connection/Tizen.Network.Connection/WiFiProfile.cs +++ b/src/Tizen.Network.Connection/Tizen.Network.Connection/WiFiProfile.cs @@ -38,6 +38,7 @@ namespace Tizen.Network.Connection /// /// The ESSID (Extended Service Set Identifier). /// + /// ESSID of the WiFi. public string Essid { get @@ -57,6 +58,7 @@ namespace Tizen.Network.Connection /// /// The BSSID (Basic Service Set Identifier). /// + /// BSSID of the WiFi. public string Bssid { get @@ -76,6 +78,7 @@ namespace Tizen.Network.Connection /// /// The RSSI. /// + /// RSSI of the WiFi. public int Rssi { get @@ -93,6 +96,7 @@ namespace Tizen.Network.Connection /// /// The frequency (MHz). /// + /// Frequency of the WiFi. public int Frequency { get @@ -110,6 +114,7 @@ namespace Tizen.Network.Connection /// /// The max speed (Mbps). /// + /// Maximum speed of the WiFi. public int MaxSpeed { get @@ -125,8 +130,9 @@ namespace Tizen.Network.Connection } /// - /// The security type of Wi-Fi. + /// The security type of WiFi. /// + /// Security type of the WiFi. public WiFiSecurityType SecurityType { get @@ -142,8 +148,9 @@ namespace Tizen.Network.Connection } /// - /// The encryption type of Wi-Fi. + /// The encryption type of WiFi. /// + /// Encryption mode of the WiFi. public WiFiEncryptionType EncryptionType { get @@ -161,6 +168,8 @@ namespace Tizen.Network.Connection /// /// Checks whether passphrase is required. /// + /// True if a passphrase is required, otherwise false. + /// This property is not valid if WiFiSecurityType is Eap. public bool PassphraseRequired { get @@ -178,6 +187,7 @@ namespace Tizen.Network.Connection /// /// Checks whether the WPS (Wi-Fi Protected Setup) is supported. /// + /// True if WPS is supported, otherwise false. public bool WpsSupported { get @@ -196,14 +206,30 @@ namespace Tizen.Network.Connection /// Sets the passphrase of the Wi-Fi WPA. /// /// The passphrase of Wi-Fi security - /// Thrown when method failed due to invalid operation + /// http://tizen.org/feature/network.wifi + /// Thrown when feature is not supported. + /// Thrown when value is invalid parameter. + /// Thrown when passphrase is null. + /// Thrown when profile instance is invalid or when method failed due to invalid operation. + /// Thrown when operation is performed on a disposed object. public void SetPassphrase(string passphrase) { - int ret = Interop.ConnectionWiFiProfile.SetPassphrase(ProfileHandle, (string)passphrase); - if ((ConnectionError)ret != ConnectionError.None) + CheckDisposed(); + if (passphrase != null) { - Log.Error(Globals.LogTag, "It failed to set passphrase, " + (ConnectionError)ret); - ConnectionErrorFactory.ThrowConnectionException(ret); + int ret = Interop.ConnectionWiFiProfile.SetPassphrase(ProfileHandle, passphrase); + if ((ConnectionError)ret != ConnectionError.None) + { + Log.Error(Globals.LogTag, "It failed to set passphrase, " + (ConnectionError)ret); + ConnectionErrorFactory.CheckFeatureUnsupportedException(ret, "http://tizen.org/feature/network.wifi"); + ConnectionErrorFactory.CheckHandleNullException(ret, (ProfileHandle == IntPtr.Zero), "ProfileHandle may have been disposed or released"); + ConnectionErrorFactory.ThrowConnectionException(ret); + } + } + + else + { + throw new ArgumentNullException("Value of passphrase is null"); } } } -- 2.7.4