2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
21 using System.Threading.Tasks;
22 using System.Runtime.InteropServices;
25 namespace Tizen.Network.Connection
28 /// This Class is RequestCellularProfile.
29 /// CellularServiceType should be set before AddProfile method of ConnectionProfileManager is called.
31 public class RequestCellularProfile : RequestProfile
33 internal IntPtr ProfileHandle = IntPtr.Zero;
34 private IAddressInformation Ipv4;
35 private IAddressInformation Ipv6;
36 private bool disposed = false;
38 private CellularAuthInformation AuthInfo;
40 /// The constructor of CellularProfile class with profile type and keyword.
42 /// <privilege>http://tizen.org/privilege/network.get</privilege>
43 public RequestCellularProfile(string keyword)
45 Log.Debug(Globals.LogTag, "RequestCellularProfile : " + keyword);
46 ProfileHandle = ConnectionInternalManager.CreateRequestProfile(ConnectionProfileType.Cellular, keyword);
47 Log.Debug(Globals.LogTag, "RequestCellularProfile is created : " + ProfileHandle);
49 Ipv4 = AddressFactory.CreateAddressInformation(ProfileHandle, AddressFamily.Ipv4, AddressInformationType.Connection);
50 Ipv6 = AddressFactory.CreateAddressInformation(ProfileHandle, AddressFamily.Ipv6, AddressInformationType.Connection);
52 AuthInfo = new CellularAuthInformation(ProfileHandle);
56 /// The destructor of CellularProfile class
58 ~RequestCellularProfile()
66 GC.SuppressFinalize(this);
69 private void Dispose(bool disposing)
76 // Free managed objects.
78 Interop.ConnectionProfile.Destroy(ProfileHandle);
83 /// Gets the network type.
85 public ConnectionProfileType Type
90 int ret = Interop.ConnectionProfile.GetType(ProfileHandle, out Value);
91 if ((ConnectionError)ret != ConnectionError.None)
93 Log.Error(Globals.LogTag, "It failed to get profile type, " + (ConnectionError)ret);
95 return (ConnectionProfileType)Value;
100 /// Gets the Proxy type.
102 public ProxyType ProxyType
107 int ret = Interop.ConnectionProfile.GetProxyType(ProfileHandle, out Value);
108 if ((ConnectionError)ret != ConnectionError.None)
110 Log.Error(Globals.LogTag, "It failed to get proxy type, " + (ConnectionError)ret);
112 return (ProxyType)Value;
117 int ret = Interop.ConnectionProfile.SetProxyType(ProfileHandle, (int)value);
118 if ((ConnectionError)ret != ConnectionError.None)
120 Log.Error(Globals.LogTag, "It failed to set proxy type, " + (ConnectionError)ret);
121 ConnectionErrorFactory.ThrowConnectionException(ret);
127 /// The proxy address.
129 public System.Net.IPAddress ProxyAddress
134 int ret = Interop.ConnectionProfile.GetProxyAddress(ProfileHandle, (int)AddressFamily.Ipv4, out Value);
135 if ((ConnectionError)ret != ConnectionError.None)
137 Log.Error(Globals.LogTag, "It failed to get proxy address, " + (ConnectionError)ret);
139 string result = Marshal.PtrToStringAnsi(Value);
140 Interop.Libc.Free(Value);
142 return System.Net.IPAddress.Parse("0.0.0.0");
143 return System.Net.IPAddress.Parse(result);
148 int ret = Interop.ConnectionProfile.SetProxyAddress(ProfileHandle, (int)AddressFamily.Ipv4, value.ToString());
149 if ((ConnectionError)ret != ConnectionError.None)
151 Log.Error(Globals.LogTag, "It failed to set proxy address, " + (ConnectionError)ret);
152 ConnectionErrorFactory.ThrowConnectionException(ret);
159 /// The subnet mask address(Ipv4).
161 public IAddressInformation Ipv4Settings
171 /// The subnet mask address(Ipv4).
173 public IAddressInformation Ipv6Settings
182 /// Gets the APN (access point name).
189 int ret = Interop.ConnectionCellularProfile.GetApn(ProfileHandle, out Value);
190 if ((ConnectionError)ret != ConnectionError.None)
192 Log.Error(Globals.LogTag, "It failed to get apn, " + (ConnectionError)ret);
194 string result = Marshal.PtrToStringAnsi(Value);
195 Interop.Libc.Free(Value);
200 int ret = Interop.ConnectionCellularProfile.SetApn(ProfileHandle, (string)value);
201 if ((ConnectionError)ret != ConnectionError.None)
203 Log.Error(Globals.LogTag, "It failed to set apn, " + (ConnectionError)ret);
204 ConnectionErrorFactory.ThrowConnectionException(ret);
210 /// Gets the home URL.
212 public string HomeUri
217 int ret = Interop.ConnectionCellularProfile.GetHomeUrl(ProfileHandle, out Value);
218 if ((ConnectionError)ret != ConnectionError.None)
220 Log.Error(Globals.LogTag, "It failed to get home uri, " + (ConnectionError)ret);
222 string result = Marshal.PtrToStringAnsi(Value);
223 Interop.Libc.Free(Value);
228 int ret = Interop.ConnectionCellularProfile.SetHomeUrl(ProfileHandle, value);
229 Log.Error(Globals.LogTag, "home uri " + value);
230 if ((ConnectionError)ret != ConnectionError.None)
232 Log.Error(Globals.LogTag, "It failed to set home uri, " + (ConnectionError)ret);
233 ConnectionErrorFactory.ThrowConnectionException(ret);
239 /// Gets the service type.
241 public CellularServiceType ServiceType
246 int ret = Interop.ConnectionCellularProfile.GetServiceType(ProfileHandle, out value);
247 if ((ConnectionError)ret != ConnectionError.None)
249 Log.Error(Globals.LogTag, "It failed to get service type, " + (ConnectionError)ret);
251 return (CellularServiceType)value;
255 int ret = Interop.ConnectionCellularProfile.SetServiceType(ProfileHandle, (int)value);
256 if ((ConnectionError)ret != ConnectionError.None)
258 Log.Error(Globals.LogTag, "It failed to set service type, " + (ConnectionError)ret);
259 ConnectionErrorFactory.ThrowConnectionException(ret);
265 /// Gets cellular Authentification Information.
267 public CellularAuthInformation CellularAuthInfo