002609ff06f5478e6f6873cefacac36e4c639dd9
[platform/core/csapi/tizenfx.git] / src / Tizen.Network.Connection / Tizen.Network.Connection / ConnectionManager.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using System.ComponentModel;
20 using System.Linq;
21 using System.Text;
22 using System.Threading.Tasks;
23 using System.Runtime.InteropServices;
24
25 namespace Tizen.Network.Connection
26 {
27     /// <summary>
28     /// This class manages the connection handle resources.
29     /// </summary>
30     /// <since_tizen> 3 </since_tizen>
31     [EditorBrowsable(EditorBrowsableState.Never)]
32     public sealed class SafeConnectionHandle : SafeHandle
33     {
34         internal SafeConnectionHandle(IntPtr handle) : base(handle, true)
35         {
36         }
37
38         /// <summary>
39         /// Checks whether the handle value is valid or not.
40         /// </summary>
41         /// <value>True if the handle is invalid, otherwise false.</value>
42         /// <since_tizen> 3 </since_tizen>
43         public override bool IsInvalid
44         {
45             get
46             {
47                 return this.handle == IntPtr.Zero;
48             }
49         }
50
51         /// <summary>
52         /// Frees the handle.
53         /// </summary>
54         /// <returns>True if the handle is released successfully, otherwise false.</returns>
55         protected override bool ReleaseHandle()
56         {
57             this.SetHandle(IntPtr.Zero);
58             return true;
59         }
60     }
61
62     /// <summary>
63     /// This is the ConnectionManager class. It provides functions to manage data connections.
64     /// </summary>
65     /// <since_tizen> 3 </since_tizen>
66     public static class ConnectionManager
67     {
68         private static ConnectionItem _currentConnection = null;
69
70         /// <summary>
71         /// An event is called when the type of the current connection is changed.
72         /// </summary>
73         /// <since_tizen> 3 </since_tizen>
74         /// <privilege>http://tizen.org/privilege/network.get</privilege>
75         /// <feature>http://tizen.org/feature/network.ethernet</feature>
76         /// <feature>http://tizen.org/feature/network.telephony</feature>
77         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
78         /// <feature>http://tizen.org/feature/network.wifi</feature>
79         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
80         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
81         public static event EventHandler<ConnectionTypeEventArgs> ConnectionTypeChanged
82         {
83             add
84             {
85                 ConnectionInternalManager.Instance.ConnectionTypeChanged += value;
86             }
87
88             remove
89             {
90                 ConnectionInternalManager.Instance.ConnectionTypeChanged -= value;
91             }
92         }
93
94         /// <summary>
95         /// An event for the ethernet cable is plugged [in/out] event.
96         /// </summary>
97         /// <since_tizen> 3 </since_tizen>
98         /// <privilege>http://tizen.org/privilege/network.get</privilege>
99         /// <feature>http://tizen.org/feature/network.ethernet</feature>
100         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
101         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
102         public static event EventHandler<EthernetCableStateEventArgs> EthernetCableStateChanged
103         {
104             add
105             {
106                 ConnectionInternalManager.Instance.EthernetCableStateChanged += value;
107             }
108
109             remove
110             {
111                 ConnectionInternalManager.Instance.EthernetCableStateChanged -= value;
112             }
113         }
114
115         /// <summary>
116         /// An event is called when the IP address is changed.
117         /// </summary>
118         /// <since_tizen> 3 </since_tizen>
119         /// <privilege>http://tizen.org/privilege/network.get</privilege>
120         /// <feature>http://tizen.org/feature/network.ethernet</feature>
121         /// <feature>http://tizen.org/feature/network.telephony</feature>
122         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
123         /// <feature>http://tizen.org/feature/network.wifi</feature>
124         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
125         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
126         public static event EventHandler<AddressEventArgs> IPAddressChanged
127         {
128             add
129             {
130                 ConnectionInternalManager.Instance.IPAddressChanged += value;
131             }
132
133             remove
134             {
135                 ConnectionInternalManager.Instance.IPAddressChanged -= value;
136             }
137         }
138
139         /// <summary>
140         /// An event is called when the proxy address is changed.
141         /// </summary>
142         /// <since_tizen> 3 </since_tizen>
143         /// <privilege>http://tizen.org/privilege/network.get</privilege>
144         /// <feature>http://tizen.org/feature/network.ethernet</feature>
145         /// <feature>http://tizen.org/feature/network.telephony</feature>
146         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
147         /// <feature>http://tizen.org/feature/network.wifi</feature>
148         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
149         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
150         public static event EventHandler<AddressEventArgs> ProxyAddressChanged
151         {
152             add
153             {
154                 ConnectionInternalManager.Instance.ProxyAddressChanged += value;
155             }
156
157             remove
158             {
159                 ConnectionInternalManager.Instance.ProxyAddressChanged -= value;
160             }
161         }
162
163         /// <summary>
164         /// Gets the connection handle.
165         /// </summary>
166         /// <since_tizen> 3 </since_tizen>
167         /// <returns>Instance of SafeConnectionHandle.</returns>
168         [EditorBrowsable(EditorBrowsableState.Never)]
169         public static SafeConnectionHandle GetConnectionHandle()
170         {
171             IntPtr handle = ConnectionInternalManager.Instance.GetHandle();
172             return new SafeConnectionHandle(handle);
173         }
174
175         /// <summary>
176         /// Gets the IP address of the current connection.
177         /// </summary>
178         /// <since_tizen> 3 </since_tizen>
179         /// <param name="family">The address family.</param>
180         /// <returns>IP address of the connection (global address in case of IPv6).</returns>
181         /// <privilege>http://tizen.org/privilege/network.get</privilege>
182         /// <feature>http://tizen.org/feature/network.ethernet</feature>
183         /// <feature>http://tizen.org/feature/network.telephony</feature>
184         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
185         /// <feature>http://tizen.org/feature/network.wifi</feature>
186         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
187         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
188         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
189         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
190         /// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to an invalid operation.</exception>
191         public static System.Net.IPAddress GetIPAddress(AddressFamily family)
192         {
193             return ConnectionInternalManager.Instance.GetIPAddress(family);
194         }
195
196         /// <summary>
197         /// Gets all the IPv6 addresses of the current connection.
198         /// </summary>
199         /// <since_tizen> 3 </since_tizen>
200         /// <param name="type">The type of current network connection.</param>
201         /// <returns>A list of IPv6 addresses of the connection.</returns>
202         /// <privilege>http://tizen.org/privilege/network.get</privilege>
203         /// <feature>http://tizen.org/feature/network.ethernet</feature>
204         /// <feature>http://tizen.org/feature/network.telephony</feature>
205         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
206         /// <feature>http://tizen.org/feature/network.wifi</feature>
207         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
208         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
209         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
210         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
211         /// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to an invalid operation.</exception>
212         public static IEnumerable<System.Net.IPAddress> GetAllIPv6Addresses(ConnectionType type)
213         {
214             return ConnectionInternalManager.Instance.GetAllIPv6Addresses(type);
215         }
216
217         /// <summary>
218         /// Gets the proxy address of the current connection.
219         /// </summary>
220         /// <since_tizen> 3 </since_tizen>
221         /// <param name="family">The address family.</param>
222         /// <returns>Proxy address of the connection.</returns>
223         /// <privilege>http://tizen.org/privilege/network.get</privilege>
224         /// <feature>http://tizen.org/feature/network.ethernet</feature>
225         /// <feature>http://tizen.org/feature/network.telephony</feature>
226         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
227         /// <feature>http://tizen.org/feature/network.wifi</feature>
228         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
229         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
230         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
231         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
232         /// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to an invalid operation.</exception>
233         public static string GetProxy(AddressFamily family)
234         {
235             return ConnectionInternalManager.Instance.GetProxy(family);
236         }
237
238         /// <summary>
239         /// Gets the MAC address of the Wi-Fi or ethernet.
240         /// </summary>
241         /// <since_tizen> 3 </since_tizen>
242         /// <param name="type">The type of current network connection.</param>
243         /// <returns>MAC address of the Wi-Fi or ethernet.</returns>
244         /// <privilege>http://tizen.org/privilege/network.get</privilege>
245         /// <feature>http://tizen.org/feature/network.ethernet</feature>
246         /// <feature>http://tizen.org/feature/network.telephony</feature>
247         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
248         /// <feature>http://tizen.org/feature/network.wifi</feature>
249         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
250         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
251         /// <exception cref="System.ArgumentException">Thrown when value is an invalid parameter.</exception>
252         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
253         /// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to an invalid operation.</exception>
254         public static string GetMacAddress(ConnectionType type)
255         {
256             return ConnectionInternalManager.Instance.GetMacAddress(type);
257         }
258
259         /// <summary>
260         /// Gets the statistics information.
261         /// </summary>
262         /// <since_tizen> 3 </since_tizen>
263         /// <param name="connectionType">The type of connection (only WiFi and Cellular are supported).</param>
264         /// <param name="statisticsType">The type of statistics.</param>
265         /// <returns>The statistics information associated with statisticsType.</returns>
266         /// <privilege>http://tizen.org/privilege/network.get</privilege>
267         /// <feature>http://tizen.org/feature/network.ethernet</feature>
268         /// <feature>http://tizen.org/feature/network.telephony</feature>
269         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
270         /// <feature>http://tizen.org/feature/network.wifi</feature>
271         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
272         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
273         /// <exception cref="System.ArgumentException">Thrown when value is an invalid parameter.</exception>
274         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
275         /// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to invalid operation.</exception>
276         public static long GetStatistics(ConnectionType connectionType, StatisticsType statisticsType)
277         {
278             return ConnectionInternalManager.Instance.GetStatistics(connectionType, statisticsType);
279         }
280
281         /// <summary>
282         /// Resets the statistics information.
283         /// </summary>
284         /// <since_tizen> 3 </since_tizen>
285         /// <param name="connectionType">The type of connection (only WiFi and Cellular are supported).</param>
286         /// <param name="statisticsType">The type of statistics.</param>
287         /// <privilege>http://tizen.org/privilege/network.get</privilege>
288         /// <privilege>http://tizen.org/privilege/network.set</privilege>
289         /// <feature>http://tizen.org/feature/network.ethernet</feature>
290         /// <feature>http://tizen.org/feature/network.telephony</feature>
291         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
292         /// <feature>http://tizen.org/feature/network.wifi</feature>
293         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
294         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
295         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
296         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
297         /// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to an invalid operation.</exception>
298         public static void ResetStatistics(ConnectionType connectionType, StatisticsType statisticsType)
299         {
300             ConnectionInternalManager.Instance.ResetStatistics(connectionType, statisticsType);
301         }
302
303         /// <summary>
304         /// Adds a route to the routing table.
305         /// </summary>
306         /// <since_tizen> 4 </since_tizen>
307         /// <param name="family">The address family.</param>
308         /// <param name="interfaceName">The name of the network interface.</param>
309         /// <param name="hostAddress">The IP address of the host.</param>
310         /// <param name="gateway">The gateway address.</param>
311         /// <privilege>http://tizen.org/privilege/network.get</privilege>
312         /// <privilege>http://tizen.org/privilege/network.set</privilege>
313         /// <feature>http://tizen.org/feature/network.telephony</feature>
314         /// <feature>http://tizen.org/feature/network.wifi</feature>
315         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
316         /// <feature>http://tizen.org/feature/network.ethernet</feature>
317         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
318         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
319         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
320         /// <exception cref="System.ArgumentNullException">Thrown when an interfaceName or a hostAddress or a gateway is null.</exception>
321         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
322         /// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to an invalid operation.</exception>
323         public static void AddRoute(AddressFamily family, string interfaceName, System.Net.IPAddress hostAddress, System.Net.IPAddress gateway)
324         {
325             ConnectionInternalManager.Instance.AddRoute(family, interfaceName, hostAddress, gateway);
326         }
327
328         /// <summary>
329         /// Removes a route from the routing table.
330         /// </summary>
331         /// <since_tizen> 4 </since_tizen>
332         /// <param name="family">The address family.</param>
333         /// <param name="interfaceName">The name of network interface.</param>
334         /// <param name="hostAddress">The IP address of the host.</param>
335         /// <param name="gateway">The gateway address.</param>
336         /// <privilege>http://tizen.org/privilege/network.get</privilege>
337         /// <privilege>http://tizen.org/privilege/network.set</privilege>
338         /// <feature>http://tizen.org/feature/network.telephony</feature>
339         /// <feature>http://tizen.org/feature/network.wifi</feature>
340         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
341         /// <feature>http://tizen.org/feature/network.ethernet</feature>
342         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
343         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
344         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
345         /// <exception cref="System.ArgumentNullException">Thrown when an interfaceName or a hostAddress or a gateway is null.</exception>
346         /// <exception cref="System.OutOfMemoryException">Thrown when memory is not enough to continue execution.</exception>
347         /// <exception cref="System.InvalidOperationException">Thrown when a connection instance is invalid or when a method fails due to an invalid operation.</exception>
348         public static void RemoveRoute(AddressFamily family, string interfaceName, System.Net.IPAddress hostAddress, System.Net.IPAddress gateway)
349         {
350             ConnectionInternalManager.Instance.RemoveRoute(family, interfaceName, hostAddress, gateway);
351         }
352
353         /// <summary>
354         /// The type and state of the current profile for data connection.
355         /// </summary>
356         /// <since_tizen> 3 </since_tizen>
357         /// <value>Instance of ConnectionItem.</value>
358         public static ConnectionItem CurrentConnection
359         {
360             get
361             {
362                 if (_currentConnection == null)
363                 {
364                     _currentConnection = new ConnectionItem();
365                 }
366
367                 return _currentConnection;
368             }
369         }
370
371         /// <summary>
372         /// Creates a cellular profile handle.
373         /// </summary>
374         /// <since_tizen> 3 </since_tizen>
375         /// <param name="type">The type of profile. Cellular profile type is supported.</param>
376         /// <param name="keyword">The keyword included in profile name.</param>
377         /// <returns>CellularProfile object.</returns>
378         /// <privilege>http://tizen.org/privilege/network.get</privilege>
379         /// <feature>http://tizen.org/feature/network.telephony</feature>
380         /// <feature>http://tizen.org/feature/network.wifi</feature>
381         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
382         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
383         /// <exception cref="System.ArgumentException">Thrown when a value is an invalid parameter.</exception>
384         /// <exception cref="System.ArgumentNullException">Thrown when a keyword value is null.</exception>
385         /// <exception cref="System.InvalidOperationException">Thrown when a method fails due to invalid operation.</exception>
386         public static CellularProfile CreateCellularProfile(ConnectionProfileType type, string keyword)
387         {
388             IntPtr profileHandle = IntPtr.Zero;
389             if (type == ConnectionProfileType.Cellular)
390             {
391                 profileHandle = ConnectionInternalManager.Instance.CreateCellularProfile(type, keyword);
392             }
393
394             else
395             {
396                 Log.Error(Globals.LogTag, "ConnectionProfile Type is not supported");
397                 ConnectionErrorFactory.ThrowConnectionException((int)ConnectionError.InvalidParameter);
398             }
399
400             return new CellularProfile(profileHandle);
401         }
402
403         /// <summary>
404         /// The state of the cellular connection.
405         /// </summary>
406         /// <since_tizen> 3 </since_tizen>
407         /// <value>Cellular network state.</value>
408         /// <feature>http://tizen.org/feature/network.telephony</feature>
409         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
410         public static CellularState CellularState
411         {
412             get
413             {
414                 return ConnectionInternalManager.Instance.CellularState;
415             }
416         }
417
418         /// <summary>
419         /// The state of the Wi-Fi connection.
420         /// </summary>
421         /// <since_tizen> 3 </since_tizen>
422         /// <value>WiFi connection state.</value>
423         /// <privilege>http://tizen.org/privilege/network.get</privilege>
424         /// <feature>http://tizen.org/feature/network.wifi</feature>
425         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
426         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
427         public static ConnectionState WiFiState
428         {
429             get
430             {
431                 return ConnectionInternalManager.Instance.WiFiState;
432             }
433         }
434
435         /// <summary>
436         /// The state of the Bluetooth connection.
437         /// </summary>
438         /// <since_tizen> 3 </since_tizen>
439         /// <value>Bluetooth connection state.</value>
440         /// <privilege>http://tizen.org/privilege/network.get</privilege>
441         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
442         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
443         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
444         public static ConnectionState BluetoothState
445         {
446             get
447             {
448                 return ConnectionInternalManager.Instance.BluetoothState;
449             }
450         }
451
452         /// <summary>
453         /// The Ethernet connection state.
454         /// </summary>
455         /// <since_tizen> 3 </since_tizen>
456         /// <value>Ethernet connection state.</value>
457         /// <privilege>http://tizen.org/privilege/network.get</privilege>
458         /// <feature>http://tizen.org/feature/network.ethernet</feature>
459         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
460         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
461         public static ConnectionState EthernetState
462         {
463             get
464             {
465                 return ConnectionInternalManager.Instance.EthernetState;
466             }
467         }
468
469         /// <summary>
470         /// Checks if the ethernet cable is attached or not.
471         /// </summary>
472         /// <since_tizen> 3 </since_tizen>
473         /// <value>Ethernet cable state.</value>
474         /// <privilege>http://tizen.org/privilege/network.get</privilege>
475         /// <feature>http://tizen.org/feature/network.ethernet</feature>
476         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
477         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
478         public static EthernetCableState EthernetCableState
479         {
480             get
481             {
482                 return ConnectionInternalManager.Instance.EthernetCableState;
483             }
484         }
485
486     } // class ConnectionManager
487
488     /// <summary>
489     /// This class contains connection information, such as connection type and state.
490     /// </summary>
491     /// <since_tizen> 3 </since_tizen>
492     public class ConnectionItem
493     {
494         internal ConnectionItem()
495         {
496         }
497
498         /// <summary>
499         /// The type of the current profile for data connection.
500         /// </summary>
501         /// <since_tizen> 3 </since_tizen>
502         /// <value>Data connection current profile.</value>
503         /// <privilege>http://tizen.org/privilege/network.get</privilege>
504         /// <feature>http://tizen.org/feature/network.ethernet</feature>
505         /// <feature>http://tizen.org/feature/network.telephony</feature>
506         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
507         /// <feature>http://tizen.org/feature/network.wifi</feature>
508         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
509         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
510         public ConnectionType Type
511         {
512             get
513             {
514                 return ConnectionInternalManager.Instance.ConnectionType;
515             }
516         }
517
518         /// <summary>
519         /// The state of the current profile for data connection.
520         /// </summary>
521         /// <since_tizen> 3 </since_tizen>
522         /// <value>Connection state of the current connection type.</value>
523         /// <privilege>http://tizen.org/privilege/network.get</privilege>
524         /// <feature>http://tizen.org/feature/network.ethernet</feature>
525         /// <feature>http://tizen.org/feature/network.telephony</feature>
526         /// <feature>http://tizen.org/feature/network.tethering.bluetooth</feature>
527         /// <feature>http://tizen.org/feature/network.wifi</feature>
528         /// <exception cref="System.NotSupportedException">Thrown when a feature is not supported.</exception>
529         /// <exception cref="System.UnauthorizedAccessException">Thrown when a permission is denied.</exception>
530         public ConnectionState State
531         {
532             get
533             {
534                 if (ConnectionInternalManager.Instance.ConnectionType == ConnectionType.Cellular)
535                 {
536                     if (ConnectionInternalManager.Instance.CellularState == CellularState.Connected)
537                     {
538                         return ConnectionState.Connected;
539                     }
540                     else if (ConnectionInternalManager.Instance.CellularState == CellularState.Available)
541                     {
542                         return ConnectionState.Disconnected;
543                     }
544                     else {
545                         return ConnectionState.Deactivated;
546                     }
547                 }
548                 else if (ConnectionInternalManager.Instance.ConnectionType == ConnectionType.Bluetooth)
549                 {
550                     return ConnectionInternalManager.Instance.BluetoothState;
551                 }
552                 else if (ConnectionInternalManager.Instance.ConnectionType == ConnectionType.WiFi)
553                 {
554                     return ConnectionInternalManager.Instance.WiFiState;
555                 }
556                 else if (ConnectionInternalManager.Instance.ConnectionType == ConnectionType.Ethernet)
557                 {
558                     return ConnectionInternalManager.Instance.EthernetState;
559                 }
560                 else { // TO DO : Add Net Proxy
561                     return ConnectionState.Disconnected;
562                 }
563             }
564         }
565     } // class ConnectionItem
566
567     /// <summary>
568     /// An extended EventArgs class, which contains changed connection type.
569     /// </summary>
570     /// <since_tizen> 3 </since_tizen>
571     public class ConnectionTypeEventArgs : EventArgs
572     {
573         private ConnectionType Type = ConnectionType.Disconnected;
574
575         internal ConnectionTypeEventArgs(ConnectionType type)
576         {
577             Type = type;
578         }
579
580         /// <summary>
581         /// The connection type.
582         /// </summary>
583         /// <since_tizen> 3 </since_tizen>
584         /// <value>Type of the connection.</value>
585         public ConnectionType ConnectionType
586         {
587             get
588             {
589                 return Type;
590             }
591         }
592     }
593
594     /// <summary>
595     /// An extended EventArgs class, which contains changed ethernet cable state.
596     /// </summary>
597     /// <since_tizen> 3 </since_tizen>
598     public class EthernetCableStateEventArgs : EventArgs
599     {
600         private EthernetCableState State;
601
602         internal EthernetCableStateEventArgs(EthernetCableState state)
603         {
604             State = state;
605         }
606
607         /// <summary>
608         /// The ethernet cable state.
609         /// </summary>
610         /// <since_tizen> 3 </since_tizen>
611         /// <value>Attached or detached state of the ethernet cable.</value>
612         public EthernetCableState EthernetCableState
613         {
614             get
615             {
616                 return State;
617             }
618         }
619     }
620
621     /// <summary>
622     /// An extended EventArgs class, which contains changed address.
623     /// </summary>
624     /// <since_tizen> 3 </since_tizen>
625     public class AddressEventArgs : EventArgs
626     {
627         private string IPv4 = "";
628         private string IPv6 = "";
629
630         internal AddressEventArgs(string ipv4, string ipv6)
631         {
632             IPv4 = ipv4;
633             IPv6 = ipv6;
634         }
635
636         /// <summary>
637         /// The IPV4 address.
638         /// </summary>
639         /// <since_tizen> 3 </since_tizen>
640         /// <value>IP address in the format of the IPV4 syntax.</value>
641         public string IPv4Address
642         {
643             get
644             {
645                 return IPv4;
646             }
647         }
648
649         /// <summary>
650         /// The IPV6 address.
651         /// </summary>
652         /// <since_tizen> 3 </since_tizen>
653         /// <value>IP address in the format of the IPV6 syntax.</value>
654         public string IPv6Address
655         {
656             get
657             {
658                 return IPv6;
659             }
660         }
661     }
662 }