Name: csapi-network-connection
Summary: Tizen Connection API for C#
-Version: 1.0.15
+Version: 1.0.16
Release: 1
Group: Development/Libraries
License: Apache-2.0
public delegate void ConnectionAddressChangedCallback(IntPtr ipv4, IntPtr ipv6, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void ConnectionCallback(ConnectionError result, IntPtr userData);
- [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
- public delegate bool IPv6AddressCallback(IntPtr ipv6, IntPtr userData);
[DllImport(Libraries.Connection, EntryPoint = "connection_create")]
public static extern int Create(out IntPtr handle);
[DllImport(Libraries.Connection, EntryPoint = "connection_get_ip_address")]
public static extern int GetIPAddress(IntPtr handle, int family, out IntPtr address);
- [DllImport(Libraries.Connection, EntryPoint = "connection_foreach_ipv6_address")]
- public static extern int GetAllIPv6Addresses(IntPtr handle, int type, IPv6AddressCallback callback, IntPtr userData);
-
[DllImport(Libraries.Connection, EntryPoint = "connection_get_proxy")]
public static extern int GetProxy(IntPtr handle, int family, out IntPtr address);
[DllImport(Libraries.Connection, EntryPoint = "connection_get_bt_state")]
public static extern int GetBtState(IntPtr handle, out int state);
- [DllImport(Libraries.Connection, EntryPoint = "connection_get_statistics")]
- public static extern int GetStatistics(IntPtr handle, int connectionType, int statisticsType, out long size);
-
- [DllImport(Libraries.Connection, EntryPoint = "connection_reset_statistics")]
- public static extern int ResetStatistics(IntPtr handle, int connectionType, int statisticsType);
-
[DllImport(Libraries.Connection, EntryPoint = "connection_set_type_changed_cb")]
public static extern int SetTypeChangedCallback(IntPtr handle, ConnectionTypeChangedCallback callback, IntPtr userData);
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_state")]
public static extern int GetState(IntPtr profileHandle, out int type);
- [DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_ipv6_state")]
- public static extern int GetIPv6State(IntPtr profileHandle, out int type);
-
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_ip_config_type")]
public static extern int GetIPConfigType(IntPtr profileHandle, int family, out int type);
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_proxy_address")]
public static extern int GetProxyAddress(IntPtr profileHandle, int family, out IntPtr address);
- [DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_prefix_length")]
- public static extern int GetPrefixLength(IntPtr profileHandle, int family, out int length);
-
- [DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_dns_config_type")]
- public static extern int GetDnsConfigType(IntPtr profileHandle, int family, out int type);
-
- [DllImport(Libraries.Connection, EntryPoint = "connection_profile_refresh")]
- public static extern int Refresh(IntPtr profileHandle);
-
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_set_ip_config_type")]
public static extern int SetIPConfigType(IntPtr profileHandle, int family, int type);
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_set_proxy_address")]
public static extern int SetProxyAddress(IntPtr profileHandle, int family, string address);
- [DllImport(Libraries.Connection, EntryPoint = "connection_profile_set_prefix_length")]
- public static extern int SetPrefixLength(IntPtr profileHandle, int family, int length);
-
- [DllImport(Libraries.Connection, EntryPoint = "connection_profile_set_dns_config_type")]
- public static extern int SetDnsConfigType(IntPtr profileHandle, int family, int type);
-
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_set_state_changed_cb")]
public static extern int SetStateChangeCallback(IntPtr profileHandle, ProfileStateChangedCallback callback, IntPtr userData);
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_cellular_home_url")]
public static extern int GetHomeUrl(IntPtr profileHandle, out IntPtr homeUrl);
- [DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_cellular_pdn_type")]
- public static extern int GetPdnType(IntPtr profileHandle, out int pdnType);
-
- [DllImport(Libraries.Connection, EntryPoint = "connection_profile_get_cellular_roam_pdn_type")]
- public static extern int GetRoamingPdnType(IntPtr profileHandle, out int roamPdnType);
-
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_is_cellular_roaming")]
public static extern int IsRoaming(IntPtr profileHandle, out bool roaming);
[DllImport(Libraries.Connection, EntryPoint = "connection_profile_set_cellular_home_url")]
public static extern int SetHomeUrl(IntPtr profileHandle, string homeUrl);
- [DllImport(Libraries.Connection, EntryPoint = "connection_profile_set_cellular_pdn_type")]
- public static extern int SetPdnType(IntPtr profileHandle, int pdnType);
-
- [DllImport(Libraries.Connection, EntryPoint = "connection_profile_set_cellular_roam_pdn_type")]
- public static extern int SetRoamingPdnType(IntPtr profileHandle, int roamPdnType);
}
internal static partial class ConnectionWiFiProfile
}
/// <summary>
- /// The cellular pdn type.
- /// </summary>
- /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
- /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
- public CellularPdnType PdnType
- {
- get
- {
- Log.Debug(Globals.LogTag, "Get PdnType");
- int value;
- int ret = Interop.ConnectionCellularProfile.GetPdnType(ProfileHandle, out value);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to get pdn type, " + (ConnectionError)ret);
- }
- return (CellularPdnType)value;
- }
-
- set
- {
- Log.Debug(Globals.LogTag, "Set PdnType");
- CheckDisposed();
- int ret = Interop.ConnectionCellularProfile.SetPdnType(ProfileHandle, (int)value);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to set pdn 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);
- }
- }
- }
-
- /// <summary>
- /// The cellular roaming pdn type.
- /// </summary>
- /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
- /// <exception cref="System.ObjectDisposedException">Thrown when operation is performed on a disposed object.</exception>
- public CellularPdnType RoamingPdnType
- {
- get
- {
- Log.Debug(Globals.LogTag, "Get RoamingPdnType");
- int value;
- int ret = Interop.ConnectionCellularProfile.GetRoamingPdnType(ProfileHandle, out value);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to get roam pdn type, " + (ConnectionError)ret);
- }
- return (CellularPdnType)value;
- }
-
- set
- {
- Log.Debug(Globals.LogTag, "Set RoamingPdnType");
- CheckDisposed();
- int ret = Interop.ConnectionCellularProfile.SetRoamingPdnType(ProfileHandle, (int)value);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to set roam pdn 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);
- }
- }
- }
-
- /// <summary>
/// Gets cellular Authentification Information.
/// </summary>
public CellularAuthInformation CellularAuthInfo
{
internal static class ConnectionErrorFactory
{
- 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 = "")
+ internal static void ThrowConnectionException(int errno)
{
ConnectionError _error = (ConnectionError)errno;
Log.Debug(Globals.LogTag, "ThrowConnectionException " + _error);
case ConnectionError.InvalidKey:
throw new InvalidOperationException("Invalid Key");
case ConnectionError.InvalidOperation:
- throw new InvalidOperationException("Invalid Operation " + message);
+ throw new InvalidOperationException("Invalid Operation");
case ConnectionError.InvalidParameter:
- throw new ArgumentException("Invalid Parameter");
+ throw new InvalidOperationException("Invalid Parameter");
case ConnectionError.NoConnection:
throw new InvalidOperationException("No Connection");
case ConnectionError.NoReply:
throw new InvalidOperationException("No Reply");
case ConnectionError.NotSupported:
- throw new NotSupportedException("Unsupported feature " + message);
+ throw new NotSupportedException("Not Supported");
case ConnectionError.NowInProgress:
throw new InvalidOperationException("Now In Progress");
case ConnectionError.OperationAborted:
case ConnectionError.OperationFailed:
throw new InvalidOperationException("Operation Failed");
case ConnectionError.OutOfMemoryError:
- throw new OutOfMemoryException("Out Of Memory Error");
+ throw new InvalidOperationException("Out Of Memory Error");
case ConnectionError.PermissionDenied:
- throw new UnauthorizedAccessException("Permission Denied " + message);
+ throw new InvalidOperationException("Permission Denied");
}
}
}
public HandleHolder()
{
+ Log.Debug(Globals.LogTag, "HandleHolder() ^^");
Interop.Connection.Create(out Handle);
Log.Debug(Globals.LogTag, "Handle: " + Handle);
}
internal IntPtr GetHandle()
{
+ Log.Debug(Globals.LogTag, "GetHandle, Thread Id = " + Thread.CurrentThread.ManagedThreadId);
return s_threadName.Value.GetHandle();
}
return Interop.Connection.DestroyProfileIterator(iterator);
}
- internal System.Net.IPAddress GetIPAddress(AddressFamily family)
+ internal string GetIPAddress(AddressFamily family)
{
- Log.Debug(Globals.LogTag, "GetIPAddress " + family);
IntPtr ip;
int ret = Interop.Connection.GetIPAddress(GetHandle(), (int)family, out ip);
if ((ConnectionError)ret != ConnectionError.None)
}
string result = Marshal.PtrToStringAnsi(ip);
Interop.Libc.Free(ip);
- return System.Net.IPAddress.Parse(result);
- }
-
- internal IEnumerable<System.Net.IPAddress> GetAllIPv6Addresses(ConnectionType type)
- {
- Log.Debug(Globals.LogTag, "GetAllIPv6Addresses");
- List<System.Net.IPAddress> ipList = new List<System.Net.IPAddress>();
- Interop.Connection.IPv6AddressCallback callback = (IntPtr ipv6Address, IntPtr userData) =>
- {
- if (ipv6Address != IntPtr.Zero)
- {
- string ipv6 = Marshal.PtrToStringAnsi(ipv6Address);
- ipList.Add(System.Net.IPAddress.Parse(ipv6));
- return true;
- }
- return false;
- };
-
- int ret = Interop.Connection.GetAllIPv6Addresses(GetHandle(), (int)type, callback, IntPtr.Zero);
- if (ret != (int)ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "Failed to get all IPv6 addresses, Error - " + (ConnectionError)ret);
- ConnectionErrorFactory.ThrowConnectionException(ret);
- }
-
- return ipList;
+ return result;
}
-
internal string GetProxy(AddressFamily family)
{
- Log.Debug(Globals.LogTag, "GetProxy " + family);
IntPtr ip;
int ret = Interop.Connection.GetProxy(GetHandle(), (int)family, out ip);
if ((ConnectionError)ret != ConnectionError.None)
internal string GetMacAddress(ConnectionType type)
{
- Log.Debug(Globals.LogTag, "GetMacAddress " + type);
- IntPtr mac;
- int ret = Interop.Connection.GetMacAddress(GetHandle(), (int)type, out mac);
+ IntPtr ip;
+ int ret = Interop.Connection.GetMacAddress(GetHandle(), (int)type, out ip);
if ((ConnectionError)ret != ConnectionError.None)
{
Log.Error(Globals.LogTag, "It failed to get mac address, " + (ConnectionError)ret);
ConnectionErrorFactory.ThrowConnectionException(ret);
}
- string result = Marshal.PtrToStringAnsi(mac);
- Interop.Libc.Free(mac);
+ string result = Marshal.PtrToStringAnsi(ip);
+ Interop.Libc.Free(ip);
return result;
}
- internal long GetStatistics(ConnectionType connectionType, StatisticsType statisticsType)
- {
- Log.Debug(Globals.LogTag, "GetStatistics " + connectionType + ", " + statisticsType);
- long size;
- int ret = Interop.Connection.GetStatistics(GetHandle(), (int)connectionType,
- (int)statisticsType, out size);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to get statistics, " + (ConnectionError)ret);
- ConnectionErrorFactory.ThrowConnectionException(ret);
- }
- return size;
- }
-
- internal void ResetStatistics(ConnectionType connectionType, StatisticsType statisticsType)
- {
- Log.Debug(Globals.LogTag, "ResetStatistics " + connectionType + ", " + statisticsType);
- int ret = Interop.Connection.ResetStatistics(GetHandle(), (int)connectionType,
- (int)statisticsType);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to reset statistics, " + (ConnectionError)ret);
- ConnectionErrorFactory.ThrowConnectionException(ret);
- }
- }
-
internal ConnectionType ConnectionType
{
get
{
- Log.Debug(Globals.LogTag, "get ConnectionType");
int type = 0;
+ Log.Debug(Globals.LogTag, "Handle: " + GetHandle());
int ret = Interop.Connection.GetType(GetHandle(), out type);
if ((ConnectionError)ret != ConnectionError.None)
{
{
get
{
- Log.Debug(Globals.LogTag, "get CellularState");
int type = 0;
+ Log.Debug(Globals.LogTag, "CellularState Handle: " + GetHandle());
int ret = Interop.Connection.GetCellularState(GetHandle(), out type);
if ((ConnectionError)ret != ConnectionError.None)
{
{
get
{
- Log.Debug(Globals.LogTag, "get WiFiState");
int type = 0;
int ret = Interop.Connection.GetWiFiState(GetHandle(), out type);
if ((ConnectionError)ret != ConnectionError.None)
{
get
{
- Log.Debug(Globals.LogTag, "get BluetoothState");
int type = 0;
int ret = Interop.Connection.GetBtState(GetHandle(), out type);
if ((ConnectionError)ret != ConnectionError.None)
{
get
{
- Log.Debug(Globals.LogTag, "get ConnectionType");
int type = 0;
int ret = Interop.Connection.GetEthernetState(GetHandle(), out type);
if ((ConnectionError)ret != ConnectionError.None)
{
get
{
- Log.Debug(Globals.LogTag, "get EthernetCableState");
int type = 0;
int ret = Interop.Connection.GetEthernetCableState(GetHandle(), out type);
if ((ConnectionError)ret != ConnectionError.None)
internal IntPtr CreateCellularProfile(ConnectionProfileType type, string keyword)
{
- Log.Debug(Globals.LogTag, "CreateCellularProfile, " + type + ", " + keyword);
+ Log.Error(Globals.LogTag, "CreateCellularProfile, " + type + ", " + keyword);
IntPtr connectionHandle = GetHandle();
if (connectionHandle == IntPtr.Zero)
{
internal void AddCellularProfile(CellularProfile profile)
{
- Log.Debug(Globals.LogTag, "AddCellularProfile");
if (profile.Type == ConnectionProfileType.Cellular)
{
int ret = Interop.Connection.AddProfile(GetHandle(), profile.ProfileHandle);
internal void RemoveProfile(ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "RemoveProfile");
int ret = Interop.Connection.RemoveProfile(GetHandle(), profile.ProfileHandle);
if ((ConnectionError)ret != ConnectionError.None)
{
internal void UpdateProfile(ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "UpdateProfile");
int ret = Interop.Connection.UpdateProfile(GetHandle(), profile.ProfileHandle);
if ((ConnectionError)ret != ConnectionError.None)
{
internal ConnectionProfile GetCurrentProfile()
{
- Log.Debug(Globals.LogTag, "GetCurrentProfile");
IntPtr ProfileHandle;
int ret = Interop.Connection.GetCurrentProfile(GetHandle(), out ProfileHandle);
if ((ConnectionError)ret != ConnectionError.None)
internal ConnectionProfile GetDefaultCellularProfile(CellularServiceType type)
{
- Log.Debug(Globals.LogTag, "GetDefaultCellularProfile");
IntPtr ProfileHandle;
int ret = Interop.Connection.GetDefaultCellularServiceProfile(GetHandle(), (int)type, out ProfileHandle);
if ((ConnectionError)ret != ConnectionError.None)
internal Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "SetDefaultCellularProfile");
TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) =>
{
internal Task<IEnumerable<ConnectionProfile>> GetProfileListAsync(ProfileListType type)
{
- Log.Debug(Globals.LogTag, "GetProfileListAsync");
var task = new TaskCompletionSource<IEnumerable<ConnectionProfile>>();
+
List<ConnectionProfile> Result = new List<ConnectionProfile>();
IntPtr iterator;
int ret = Interop.Connection.GetProfileIterator(GetHandle(), (int)type, out iterator);
internal Task OpenProfileAsync(ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "OpenProfileAsync " + profile.Name);
TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
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);
internal Task CloseProfileAsync(ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "CloseProfileAsync " + profile.Name);
TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
Interop.Connection.ConnectionCallback Callback = (ConnectionError Result, IntPtr Data) =>
{
return task.Task;
}
}
-}
+}
\ No newline at end of file
/// Gets the IP address of the current connection.
/// </summary>
/// <param name="family">The address family</param>
- /// <returns>IP address of the connection (global address in case of IPv6).</returns>
- /// <privilege>http://tizen.org/privilege/network.get</privilege>
- /// <feature>http://tizen.org/feature/network.telephony</feature>
- /// <feature>http://tizen.org/feature/network.wifi</feature>
- /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
- /// <feature>http://tizen.org/feature/network.ethernet</feature>
- /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
- /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
- /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
- /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown when connection instance is invalid or when method failed due to invalid operation.</exception>
- public static System.Net.IPAddress GetIPAddress(AddressFamily family)
+ /// <returns>IP address of the connection.</returns>
+ /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
+ public static string GetIPAddress(AddressFamily family)
{
return ConnectionInternalManager.Instance.GetIPAddress(family);
}
/// <summary>
- /// Gets the all IPv6 addresses of the current connection.
- /// </summary>
- /// <param name="type">The type of current network connection</param>
- /// <returns>A list of IPv6 addresses of the connection.</returns>
- /// <privilege>http://tizen.org/privilege/network.get</privilege>
- /// <feature>http://tizen.org/feature/network.telephony</feature>
- /// <feature>http://tizen.org/feature/network.wifi</feature>
- /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
- /// <feature>http://tizen.org/feature/network.ethernet</feature>
- /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
- /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
- /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
- /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown when connection instance is invalid or when method failed due to invalid operation.</exception>
- public static IEnumerable<System.Net.IPAddress> GetAllIPv6Addresses(ConnectionType type)
- {
- return ConnectionInternalManager.Instance.GetAllIPv6Addresses(type);
- }
-
- /// <summary>
/// Gets the proxy address of the current connection.
/// </summary>
/// <param name="family">The address family</param>
/// <returns>Proxy address of the connection.</returns>
- /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown when connection instance is invalid or when method failed due to invalid operation.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
public static string GetProxy(AddressFamily family)
{
return ConnectionInternalManager.Instance.GetProxy(family);
/// </summary>
/// <param name="type">The type of current network connection</param>
/// <returns>MAC address of the Wi-Fi or ethernet.</returns>
- /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
- /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown when connection instance is invalid or when method failed due to invalid operation.</exception>
+ /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
public static string GetMacAddress(ConnectionType type)
{
return ConnectionInternalManager.Instance.GetMacAddress(type);
}
/// <summary>
- /// Gets the statistics information.
- /// </summary>
- /// <param name="connectionType">The type of connection (only WiFi and Cellular are supported)</param>
- /// <param name="statisticsType">The type of statistics</param>
- /// <returns>The statistics information associated with statisticsType</returns>
- /// <privilege>http://tizen.org/privilege/network.get</privilege>
- /// <feature>http://tizen.org/feature/network.telephony</feature>
- /// <feature>http://tizen.org/feature/network.wifi</feature>
- /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
- /// <feature>http://tizen.org/feature/network.ethernet</feature>
- /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
- /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
- /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
- /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown when connection instance is invalid or when method failed due to invalid operation.</exception>
- public static long GetStatistics(ConnectionType connectionType, StatisticsType statisticsType)
- {
- return ConnectionInternalManager.Instance.GetStatistics(connectionType, statisticsType);
- }
-
- /// <summary>
- /// Resets the statistics information.
- /// </summary>
- /// <param name="connectionType">The type of connection (only WiFi and Cellular are supported)</param>
- /// <param name="statisticsType">The type of statistics</param>
- /// <privilege>http://tizen.org/privilege/network.get</privilege>
- /// <privilege>http://tizen.org/privilege/network.set</privilege>
- /// <feature>http://tizen.org/feature/network.telephony</feature>
- /// <feature>http://tizen.org/feature/network.wifi</feature>
- /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
- /// <feature>http://tizen.org/feature/network.ethernet</feature>
- /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
- /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
- /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
- /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown when connection instance is invalid or when method failed due to invalid operation.</exception>
- public static void ResetStatistics(ConnectionType connectionType, StatisticsType statisticsType)
- {
- ConnectionInternalManager.Instance.ResetStatistics(connectionType, statisticsType);
- }
-
- /// <summary>
/// Type and state of the current profile for data connection
/// </summary>
public static ConnectionItem CurrentConnection
/// <param name="type">The type of profile. Cellular profile type is supported.</param>
/// <param name="keyword">The keyword included in profile name.</param>
/// <returns>CellularProfile object</returns>
- /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
- /// <exception cref="System.UnauthorizedAccessException">Thrown when permission is denied.</exception>
- /// <exception cref="System.ArgumentException">Thrown when value is invalid parameter.</exception>
- /// <exception cref="System.ArgumentNullException">Thrown when keyword value is null.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown when method failed due to invalid operation.</exception>
public static CellularProfile CreateCellularProfile(ConnectionProfileType type, string keyword)
{
IntPtr profileHandle = IntPtr.Zero;
{
add
{
- Log.Debug(Globals.LogTag, "ProfileStateChanged add");
if (_ProfileStateChanged == null)
{
ProfileStateChangedStart();
}
remove
{
- Log.Debug(Globals.LogTag, "ProfileStateChanged remove");
_ProfileStateChanged -= value;
if (_ProfileStateChanged == null)
{
}
};
- Log.Debug(Globals.LogTag, "ProfileStateChangedStart");
int ret = Interop.ConnectionProfile.SetStateChangeCallback(ProfileHandle, _profileChangedCallback, IntPtr.Zero);
if ((ConnectionError)ret != ConnectionError.None)
{
private void ProfileStateChangedStop()
{
- Log.Debug(Globals.LogTag, "ProfileStateChangedStop");
int ret = Interop.ConnectionProfile.UnsetStateChangeCallback(ProfileHandle);
if ((ConnectionError)ret != ConnectionError.None)
{
private void Destroy()
{
Interop.ConnectionProfile.Destroy(ProfileHandle);
- ProfileHandle = IntPtr.Zero;
- }
-
- internal void CheckDisposed()
- {
- if (disposed)
- {
- throw new ObjectDisposedException(GetType().FullName);
- }
}
/// <summary>
}
/// <summary>
- /// Refreshes the profile information.
+ /// The profile state.
/// </summary>
- /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
- public void Refresh()
+ public ProfileState State
{
- int ret = Interop.ConnectionProfile.Refresh(ProfileHandle);
- if ((ConnectionError)ret != ConnectionError.None)
+ get
{
- Log.Error(Globals.LogTag, "It failed to get network interface name, " + (ConnectionError)ret);
- ConnectionErrorFactory.ThrowConnectionException(ret);
- }
- }
-
- /// <summary>
- /// Get the network state.
- /// </summary>
- /// <param name="family">The address family</param>
- /// <returns>The network state.</returns>
- public ProfileState GetState(AddressFamily family)
- {
int Value;
- int ret = (int)ConnectionError.None;
- if (family == AddressFamily.IPv4)
- {
- ret = Interop.ConnectionProfile.GetState(ProfileHandle, out Value);
- }
- else
- {
- ret = Interop.ConnectionProfile.GetIPv6State(ProfileHandle, out Value);
- }
-
+ int ret = Interop.ConnectionProfile.GetState(ProfileHandle, out Value);
if ((ConnectionError)ret != ConnectionError.None)
{
Log.Error(Globals.LogTag, "It failed to get profile state, " + (ConnectionError)ret);
}
return (ProfileState)Value;
+ }
}
/// <summary>
}
/// <summary>
- /// The address information (IPv4)
+ /// The subnet mask address(IPv4).
/// </summary>
public IAddressInformation IPv4Settings
{
}
/// <summary>
- /// The address information (IPv6)
+ /// The subnet mask address(IPv4).
/// </summary>
public IAddressInformation IPv6Settings
{
/// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
public static void AddCellularProfile(CellularProfile profile)
{
- Log.Debug(Globals.LogTag, "AddCellularProfile");
ConnectionInternalManager.Instance.AddCellularProfile(profile);
}
/// <returns>List of connection profile objects.</returns>
public static Task<IEnumerable<ConnectionProfile>> GetProfileListAsync(ProfileListType type)
{
- Log.Debug(Globals.LogTag, "GetProfileListAsync");
return ConnectionInternalManager.Instance.GetProfileListAsync(type);
}
/// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
public static Task ConnectProfileAsync(ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "ConnectProfile");
return ConnectionInternalManager.Instance.OpenProfileAsync(profile);
}
/// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
public static Task DisconnectProfileAsync(ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "DisconnectProfileAsync");
return ConnectionInternalManager.Instance.CloseProfileAsync(profile);
}
/// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
public static void UpdateProfile(ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "UpdateProfile");
ConnectionInternalManager.Instance.UpdateProfile(profile);
}
/// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
public static ConnectionProfile GetCurrentProfile()
{
- Log.Debug(Globals.LogTag, "GetCurrentProfile");
return ConnectionInternalManager.Instance.GetCurrentProfile();
}
/// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
public static ConnectionProfile GetDefaultCellularProfile(CellularServiceType type)
{
- Log.Debug(Globals.LogTag, "GetDefaultCurrentProfile");
return ConnectionInternalManager.Instance.GetDefaultCellularProfile(type);
}
/// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
public static Task SetDefaultCellularProfile(CellularServiceType type, ConnectionProfile profile)
{
- Log.Debug(Globals.LogTag, "SetDefaultCellularProfile");
return ConnectionInternalManager.Instance.SetDefaultCellularProfile(type, profile);
}
}
/// </summary>
public enum AddressFamily
{
- IPv4 = 0, /**< IPv4 Address */
- IPv6 = 1 /**< IPv6 Address */
+ IPv4 = 0,
+ IPv6 = 1
}
/// <summary>
}
/// <summary>
- /// Enumeration for statistics type.
- /// </summary>
- public enum StatisticsType
- {
- LastReceivedData = 0, /**< Last received data */
- LastSentData = 1, /**< Last sent data */
- TotalReceivedData = 2, /**< Total received data */
- TotalSentData = 3, /**< Total sent data */
- }
-
- /// <summary>
/// Enumeration for network connection type.
/// </summary>
public enum ConnectionProfileType
Application = 6, /**< Specific application */
}
- /// <summary>
- /// Enumeration for cellular pdn type.
- /// </summary>
- public enum CellularPdnType
- {
- Unknown = 0, /**< Unknown */
- IPv4 = 1, /**< IPv4 */
- IPv6 = 2, /**< IPv6 */
- IPv4_IPv6 = 3, /**< Both IPv4 and IPv6 */
- }
-
- /// <summary>
- /// Enumeration for DNS configuration type.
- /// </summary>
- public enum DnsConfigType
- {
- None = 0, /**< Not defined */
- Static = 1, /**< Manual DNS configuration */
- Dynamic = 2, /**< Config DNS using DHCP client */
- }
-
static internal class ConnectionErrorValue
{
internal const int Base = -0x01C10000;
/// <summary>
/// The DNS address.
/// </summary>
- /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
System.Net.IPAddress Dns1 { get; set; }
/// <summary>
/// The DNS address.
/// </summary>
- /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
System.Net.IPAddress Dns2 { get; set; }
/// <summary>
/// The gateway address.
/// </summary>
- /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
System.Net.IPAddress Gateway { get; set; }
/// <summary>
/// The subnet mask address.
/// </summary>
- /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
System.Net.IPAddress SubnetMask { get; set; }
/// <summary>
/// The IP address.
/// </summary>
- /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
System.Net.IPAddress IP { get; set; }
/// <summary>
/// The type of IP config.
/// </summary>
- /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
IPConfigType IPConfigType { get; set; }
-
- /// <summary>
- /// The prefix length.
- /// </summary>
- /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
- int PrefixLength { get; set; }
-
- /// <summary>
- /// The DNS config type.
- /// </summary>
- /// <exception cref="System.NotSupportedException">Thrown during set when feature is not supported.</exception>
- /// <exception cref="System.ArgumentException">Thrown during set when value is invalid parameter.</exception>
- /// <exception cref="System.InvalidOperationException">Thrown during set when profile instance is invalid or when method failed due to invalid operation.</exception>
- DnsConfigType DnsConfigType { get; set; }
}
internal class ConnectionAddressInformation : IAddressInformation
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);
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());
}
}
}
-
- public int PrefixLength
- {
- get
- {
- int Value;
- int ret = Interop.ConnectionProfile.GetPrefixLength(_profileHandle, (int)_family, out Value);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to get prefix length, " + (ConnectionError)ret);
- }
- return Value;
- }
-
- set
- {
- int ret = Interop.ConnectionProfile.SetPrefixLength(_profileHandle, (int)_family, value);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to set prefix length, " + (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);
- }
- }
- }
-
- public DnsConfigType DnsConfigType
- {
- get
- {
- int Value;
- int ret = Interop.ConnectionProfile.GetDnsConfigType(_profileHandle, (int)_family, out Value);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to get DNS config type, " + (ConnectionError)ret);
- }
- return (DnsConfigType)Value;
- }
-
- set
- {
- int ret = Interop.ConnectionProfile.SetDnsConfigType(_profileHandle, (int)_family, (int)value);
- if ((ConnectionError)ret != ConnectionError.None)
- {
- Log.Error(Globals.LogTag, "It failed to set DNS 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);
- }
- }
- }
}
}