Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.Tapi / Tizen.Tapi / Network.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.Runtime.InteropServices;
20 using System.Threading.Tasks;
21
22 namespace Tizen.Tapi
23 {
24     /// <summary>
25     /// This class provides functions for managing telephony service network.
26     /// </summary>
27     public class Network
28     {
29         private IntPtr _handle;
30         private Dictionary<IntPtr, Interop.Tapi.TapiResponseCallback> _response_map = new Dictionary<IntPtr, Interop.Tapi.TapiResponseCallback>();
31         private int _requestId = 0;
32
33         /// <summary>
34         /// A public constructor for Network class to create a Network instance for the given tapi handle.
35         /// </summary>
36         /// <param name="handle">The tapi handle.</param>
37         public Network(TapiHandle handle)
38         {
39             if (handle == null)
40             {
41                 throw new ArgumentNullException("TapiHandle parameter is null");
42             }
43
44             _handle = handle._handle;
45         }
46
47         /// <summary>
48         /// Request the lower layers to select the network automatically asynchronously.
49         /// </summary>
50         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
51         /// <privlevel>platform</privlevel>
52         /// <feature>http://tizen.org/feature/network.telephony</feature>
53         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
54         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
55         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
56         public Task SelectNetworkAutomatic()
57         {
58             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
59             IntPtr id;
60             id = (IntPtr)_requestId++;
61             _response_map[id] = (IntPtr handle, int result, IntPtr data, IntPtr key) =>
62             {
63                 Task resultTask = new Task(() =>
64                 {
65                     if (result != (int)TapiError.Success)
66                     {
67                         Log.Error(TapiUtility.LogTag, "Error occurs during selecting the network, " + (TapiError)result);
68                         task.SetException(new InvalidOperationException("Error occurs during selecting the network, " + (TapiError)result));
69                         return;
70                     }
71
72                     task.SetResult(true);
73                 });
74
75                 resultTask.Start();
76                 resultTask.Wait();
77                 _response_map.Remove(key);
78             };
79
80             int ret = Interop.Tapi.Network.SelectAutoNetwork(_handle, _response_map[id], id);
81             if (ret != (int)TapiError.Success)
82             {
83                 Log.Error(TapiUtility.LogTag, "Failed to select the network automatically, Error: " + (TapiError)ret);
84                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
85             }
86
87             return task.Task;
88         }
89
90         /// <summary>
91         /// Request the lower layers to select the network which is selected by the user from the network list asynchronously.
92         /// </summary>
93         /// <param name="plmn">The user selected plmn.</param>
94         /// <param name="act">The user selected access technology.</param>
95         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
96         /// <privlevel>platform</privlevel>
97         /// <feature>http://tizen.org/feature/network.telephony</feature>
98         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
99         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
100         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
101         public Task SelectNetworkManual(string plmn, int act)
102         {
103             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
104             IntPtr id;
105             id = (IntPtr)_requestId++;
106             _response_map[id] = (IntPtr handle, int result, IntPtr data, IntPtr key) =>
107             {
108                 Task resultTask = new Task(() =>
109                 {
110                     if (result != (int)TapiError.Success)
111                     {
112                         Log.Error(TapiUtility.LogTag, "Error occurs during selecting the network, " + (TapiError)result);
113                         task.SetException(new InvalidOperationException("Error occurs during selecting the network, " + (TapiError)result));
114                         return;
115                     }
116
117                     task.SetResult(true);
118                 });
119
120                 resultTask.Start();
121                 resultTask.Wait();
122                 _response_map.Remove(key);
123             };
124
125             int ret = Interop.Tapi.Network.SelectManualNetwork(_handle, plmn, act, _response_map[id], id);
126             if (ret != (int)TapiError.Success)
127             {
128                 Log.Error(TapiUtility.LogTag, "Failed to select the network manually, Error: " + (TapiError)ret);
129                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
130             }
131
132             return task.Task;
133         }
134
135         /// <summary>
136         /// Sends a request to do manual search for the available networks and provides the Network List to the user asynchronously.
137         /// </summary>
138         /// <returns>Instance of NetworkPlmnList.</returns>
139         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
140         /// <privlevel>platform</privlevel>
141         /// <feature>http://tizen.org/feature/network.telephony</feature>
142         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
143         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
144         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
145         public Task<NetworkPlmnList> SearchNetwork()
146         {
147             TaskCompletionSource<NetworkPlmnList> task = new TaskCompletionSource<NetworkPlmnList>();
148             IntPtr id;
149             id = (IntPtr)_requestId++;
150             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
151             {
152                 Task resultTask = new Task(() =>
153                 {
154                     if (result != (int)TapiError.Success)
155                     {
156                         Log.Error(TapiUtility.LogTag, "Error occurs during manual search for the available networks, " + (TapiError)result);
157                         task.SetException(new InvalidOperationException("Error occurs during manual search for the available networks, " + (TapiError)result));
158                         return;
159                     }
160
161                     NetworkPlmnListStruct listStruct = Marshal.PtrToStructure<NetworkPlmnListStruct>(dataResponse);
162                     NetworkPlmnList plmnClass = NetworkStructConversions.ConvertNetworkPlmnListStruct(listStruct);
163                     task.SetResult(plmnClass);
164                 });
165
166                 resultTask.Start();
167                 resultTask.Wait();
168                 _response_map.Remove(key);
169             };
170
171             int ret = Interop.Tapi.Network.SearchNetwork(_handle, _response_map[id], id);
172             if (ret != (int)TapiError.Success)
173             {
174                 Log.Error(TapiUtility.LogTag, "Failed to do manual search for the available networks, Error: " + (TapiError)ret);
175                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
176             }
177
178             return task.Task;
179         }
180
181         /// <summary>
182         /// Get the present network selection mode i.e. automatic or manual asynchronously.
183         /// </summary>
184         /// <returns>Value of NetworkSelectionMode.</returns>
185         /// <privilege>http://tizen.org/privilege/telephony</privilege>
186         /// <feature>http://tizen.org/feature/network.telephony</feature>
187         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
188         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
189         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
190         public Task<NetworkSelectionMode> GetNetworkSelectionMode()
191         {
192             TaskCompletionSource<NetworkSelectionMode> task = new TaskCompletionSource<NetworkSelectionMode>();
193             IntPtr id;
194             id = (IntPtr)_requestId++;
195             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
196             {
197                 Task resultTask = new Task(() =>
198                 {
199                     if (result != (int)TapiError.Success)
200                     {
201                         Log.Error(TapiUtility.LogTag, "Error occurs during getting the present network selection mode, " + (TapiError)result);
202                         task.SetException(new InvalidOperationException("Error occurs during getting the present network selection mode, " + (TapiError)result));
203                         return;
204                     }
205
206                     task.SetResult((NetworkSelectionMode)Marshal.ReadInt32(dataResponse));
207                 });
208
209                 resultTask.Start();
210                 resultTask.Wait();
211                 _response_map.Remove(key);
212             };
213
214             int ret = Interop.Tapi.Network.GetNetworkSelectMode(_handle, _response_map[id], id);
215             if (ret != (int)TapiError.Success)
216             {
217                 Log.Error(TapiUtility.LogTag, "Failed to get the present network selection mode, Error: " + (TapiError)ret);
218                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
219             }
220
221             return task.Task;
222         }
223
224         /// <summary>
225         /// Set the network preferred plmn asynchronously.
226         /// </summary>
227         /// <param name="operation">The operation to be done on the preferred plmn.</param>
228         /// <param name="info">The preferred plmn info.</param>
229         /// <returns>A task indicating whether the SetNetworkPreferredPlmn method is done or not.</returns>
230         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
231         /// <privlevel>platform</privlevel>
232         /// <feature>http://tizen.org/feature/network.telephony</feature>
233         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
234         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
235         /// <exception cref="System.ArgumentNullException">Thrown when NetworkPreferredPlmnInfo argument is null.</exception>
236         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
237         public Task SetNetworkPreferredPlmn(NetworkPreferredPlmnOp operation, NetworkPreferredPlmnInfo info)
238         {
239             if (info != null)
240             {
241                 TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
242                 IntPtr id;
243                 id = (IntPtr)_requestId++;
244                 _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
245                 {
246                     Task resultTask = new Task(() =>
247                     {
248                         if (result != (int)TapiError.Success)
249                         {
250                             Log.Error(TapiUtility.LogTag, "Error occurs during setting the network preferred plmn, " + (TapiError)result);
251                             task.SetException(new InvalidOperationException("Error occurs during setting the network preferred plmn, " + (TapiError)result));
252                             return;
253                         }
254
255                         task.SetResult(true);
256                     });
257
258                     resultTask.Start();
259                     resultTask.Wait();
260                     _response_map.Remove(key);
261                 };
262
263                 NetworkPreferredPlmnStruct plmnStruct = NetworkClassConversions.ConvertNetworkPreferredPlmn(info);
264                 int ret = Interop.Tapi.Network.SetNetworkPreferredPlmn(_handle, operation, ref plmnStruct, _response_map[id], id);
265                 if (ret != (int)TapiError.Success)
266                 {
267                     Log.Error(TapiUtility.LogTag, "Failed to set the network preferred plmn, Error: " + (TapiError)ret);
268                     TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
269                 }
270
271                 return task.Task;
272             }
273
274             else
275             {
276                 throw new ArgumentNullException("NetworkPreferredPlmnInfo argument is null");
277             }
278         }
279
280         /// <summary>
281         /// Get the preferred plmn list asynchronously.
282         /// </summary>
283         /// <returns>List of NetworkPreferredPlmnInfo.</returns>
284         /// <privilege>http://tizen.org/privilege/telephony</privilege>
285         /// <feature>http://tizen.org/feature/network.telephony</feature>
286         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
287         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
288         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
289         public Task<IEnumerable<NetworkPreferredPlmnInfo>> GetNetworkPreferredPlmn()
290         {
291             TaskCompletionSource<IEnumerable<NetworkPreferredPlmnInfo>> task = new TaskCompletionSource<IEnumerable<NetworkPreferredPlmnInfo>>();
292             IntPtr id;
293             id = (IntPtr)_requestId++;
294             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
295             {
296                 Task resultTask = new Task(() =>
297                 {
298                     if (result != (int)TapiError.Success)
299                     {
300                         Log.Error(TapiUtility.LogTag, "Error occurs during getting the preferred plmn list, " + (TapiError)result);
301                         task.SetException(new InvalidOperationException("Error occurs during getting the preferred plmn list, " + (TapiError)result));
302                         return;
303                     }
304
305                     NetworkPreferredPlmnListStruct plmnStruct = Marshal.PtrToStructure<NetworkPreferredPlmnListStruct>(dataResponse);
306                     IEnumerable<NetworkPreferredPlmnInfo> plmnInfo = NetworkStructConversions.ConvertNetworkPreferredPlmnStruct(plmnStruct);
307                     task.SetResult(plmnInfo);
308                 });
309
310                 resultTask.Start();
311                 resultTask.Wait();
312                 _response_map.Remove(key);
313             };
314
315             int ret = Interop.Tapi.Network.GetNetworkPreferredPlmn(_handle, _response_map[id], id);
316             if (ret != (int)TapiError.Success)
317             {
318                 Log.Error(TapiUtility.LogTag, "Failed to get the preferred plmn list, Error: " + (TapiError)ret);
319                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
320             }
321
322             return task.Task;
323         }
324
325         /// <summary>
326         /// Cancel the triggered manual network search asynchronously.
327         /// </summary>
328         /// <returns>A task indicating whether the CancelNetworkManualSearch method is done or not.</returns>
329         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
330         /// <privlevel>platform</privlevel>
331         /// <feature>http://tizen.org/feature/network.telephony</feature>
332         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
333         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
334         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
335         public Task CancelNetworkManualSearch()
336         {
337             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
338             IntPtr id;
339             id = (IntPtr)_requestId++;
340             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
341             {
342                 Task resultTask = new Task(() =>
343                 {
344                     if (result != (int)TapiError.Success)
345                     {
346                         Log.Error(TapiUtility.LogTag, "Error occurs during cancelling the network manual search, " + (TapiError)result);
347                         task.SetException(new InvalidOperationException("Error occurs during cancelling the network manual search, " + (TapiError)result));
348                         return;
349                     }
350
351                     task.SetResult(true);
352                 });
353
354                 resultTask.Start();
355                 resultTask.Wait();
356                 _response_map.Remove(key);
357             };
358
359             int ret = Interop.Tapi.Network.CancelNetworkManualSearch(_handle, _response_map[id], id);
360             if (ret != (int)TapiError.Success)
361             {
362                 Log.Error(TapiUtility.LogTag, "Failed to cancel the network manual search, Error: " + (TapiError)ret);
363                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
364             }
365
366             return task.Task;
367         }
368
369         /// <summary>
370         /// Get the network serving information asynchronously.
371         /// </summary>
372         /// <returns>Instance of NetworkServing.</returns>
373         /// <privilege>http://tizen.org/privilege/telephony</privilege>
374         /// <feature>http://tizen.org/feature/network.telephony</feature>
375         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
376         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
377         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
378         public Task<NetworkServing> GetNetworkServing()
379         {
380             TaskCompletionSource<NetworkServing> task = new TaskCompletionSource<NetworkServing>();
381             IntPtr id;
382             id = (IntPtr)_requestId++;
383             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
384             {
385                 Task resultTask = new Task(() =>
386                 {
387                     if (result != (int)TapiError.Success)
388                     {
389                         Log.Error(TapiUtility.LogTag, "Error occurs during getting the network serving information, " + (TapiError)result);
390                         task.SetException(new InvalidOperationException("Error occurs during getting the network serving information, " + (TapiError)result));
391                         return;
392                     }
393
394                     NetworkServingStruct servStruct = Marshal.PtrToStructure<NetworkServingStruct>(dataResponse);
395                     NetworkServing servingInfo = NetworkStructConversions.ConvertNetworkServingStruct(servStruct);
396                     task.SetResult(servingInfo);
397                 });
398
399                 resultTask.Start();
400                 resultTask.Wait();
401                 _response_map.Remove(key);
402             };
403
404             int ret = Interop.Tapi.Network.GetNetworkServing(_handle, _response_map[id], id);
405             if (ret != (int)TapiError.Success)
406             {
407                 Log.Error(TapiUtility.LogTag, "Failed to get the network serving information, Error: " + (TapiError)ret);
408                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
409             }
410
411             return task.Task;
412         }
413
414         /// <summary>
415         /// Set the network mode asynchronously.
416         /// </summary>
417         /// <param name="mode">The network mode.</param>
418         /// <returns>A task indicating whether the SetNetworkMode method is done or not.</returns>
419         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
420         /// <privlevel>platform</privlevel>
421         /// <feature>http://tizen.org/feature/network.telephony</feature>
422         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
423         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
424         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
425         public Task SetNetworkMode(NetworkMode mode)
426         {
427             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
428             IntPtr id;
429             id = (IntPtr)_requestId++;
430             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
431             {
432                 Task resultTask = new Task(() =>
433                 {
434                     if (result != (int)TapiError.Success)
435                     {
436                         Log.Error(TapiUtility.LogTag, "Error occurs during getting the network mode, " + (TapiError)result);
437                         task.SetException(new InvalidOperationException("Error occurs during getting the network mode, " + (TapiError)result));
438                         return;
439                     }
440
441                     task.SetResult(true);
442                 });
443
444                 resultTask.Start();
445                 resultTask.Wait();
446                 _response_map.Remove(key);
447             };
448
449             int ret = Interop.Tapi.Network.SetNetworkMode(_handle, (int)mode, _response_map[id], id);
450             if (ret != (int)TapiError.Success)
451             {
452                 Log.Error(TapiUtility.LogTag, "Failed to get the network mode, Error: " + (TapiError)ret);
453                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
454             }
455
456             return task.Task;
457         }
458
459         /// <summary>
460         /// Get the network mode asynchronously.
461         /// </summary>
462         /// <returns>Value of NetworkMode.</returns>
463         /// <privilege>http://tizen.org/privilege/telephony</privilege>
464         /// <feature>http://tizen.org/feature/network.telephony</feature>
465         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
466         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
467         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
468         public Task<NetworkMode> GetNetworkMode()
469         {
470             TaskCompletionSource<NetworkMode> task = new TaskCompletionSource<NetworkMode>();
471             IntPtr id;
472             id = (IntPtr)_requestId++;
473             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
474             {
475                 Task resultTask = new Task(() =>
476                 {
477                     if (result != (int)TapiError.Success)
478                     {
479                         Log.Error(TapiUtility.LogTag, "Error occurs during getting the network mode, " + (TapiError)result);
480                         task.SetException(new InvalidOperationException("Error occurs during getting the network mode, " + (TapiError)result));
481                         return;
482                     }
483
484                     task.SetResult((NetworkMode)Marshal.ReadInt32(dataResponse));
485                 });
486
487                 resultTask.Start();
488                 resultTask.Wait();
489                 _response_map.Remove(key);
490             };
491
492             int ret = Interop.Tapi.Network.GetNetworkMode(_handle, _response_map[id], id);
493             if (ret != (int)TapiError.Success)
494             {
495                 Log.Error(TapiUtility.LogTag, "Failed to get the network mode, Error: " + (TapiError)ret);
496                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
497             }
498
499             return task.Task;
500         }
501
502         /// <summary>
503         /// Get the neighboring cell info asynchronously.
504         /// </summary>
505         /// <returns>Instance of NetworkNeighboringCell.</returns>
506         /// <privilege>http://tizen.org/privilege/telephony</privilege>
507         /// <feature>http://tizen.org/feature/network.telephony</feature>
508         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
509         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
510         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
511         public Task<NetworkNeighboringCell> GetNeighborCellNetwork()
512         {
513             TaskCompletionSource<NetworkNeighboringCell> task = new TaskCompletionSource<NetworkNeighboringCell>();
514             IntPtr id;
515             id = (IntPtr)_requestId++;
516             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
517             {
518                 Task resultTask = new Task(() =>
519                 {
520                     if (result != (int)TapiError.Success)
521                     {
522                         Log.Error(TapiUtility.LogTag, "Error occurs during getting the neigboring cell info, " + (TapiError)result);
523                         task.SetException(new InvalidOperationException("Error occurs during getting the neigboring cell info, " + (TapiError)result));
524                         return;
525                     }
526
527                     NetworkNeighboringCellStruct cellStruct = Marshal.PtrToStructure<NetworkNeighboringCellStruct>(dataResponse);
528                     NetworkNeighboringCell cell = NetworkStructConversions.ConvertNeighborCellStruct(cellStruct);
529                     task.SetResult(cell);
530                 });
531
532                 resultTask.Start();
533                 resultTask.Wait();
534                 _response_map.Remove(key);
535             };
536
537             int ret = Interop.Tapi.Network.GetNetworkNeighborCell(_handle, _response_map[id], id);
538             if (ret != (int)TapiError.Success)
539             {
540                 Log.Error(TapiUtility.LogTag, "Failed to get the neigboring cell info, Error: " + (TapiError)ret);
541                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
542             }
543
544             return task.Task;
545         }
546
547         /// <summary>
548         /// Enters or exits the emergency callback mode asynchronously.
549         /// </summary>
550         /// <param name="mode">The emergency callback mode.</param>
551         /// <returns>A task indicating whether the SetEmergencyCallbackMode method is done or not.</returns>
552         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
553         /// <privlevel>platform</privlevel>
554         /// <feature>http://tizen.org/feature/network.telephony</feature>
555         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
556         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
557         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
558         public Task SetEmergencyCallbackMode(NetworkEmergencyCallbackMode mode)
559         {
560             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
561             IntPtr id;
562             id = (IntPtr)_requestId++;
563             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
564             {
565                 Task resultTask = new Task(() =>
566                 {
567                     if (result != (int)TapiError.Success)
568                     {
569                         Log.Error(TapiUtility.LogTag, "Error occurs during setting the emergency callback mode, " + (TapiError)result);
570                         task.SetException(new InvalidOperationException("Error occurs during setting the emergency callback mode, " + (TapiError)result));
571                         return;
572                     }
573
574                     task.SetResult(true);
575                 });
576
577                 resultTask.Start();
578                 resultTask.Wait();
579                 _response_map.Remove(key);
580             };
581
582             int ret = Interop.Tapi.Network.SetNetworkEmergencyCallback(_handle, mode, _response_map[id], id);
583             if (ret != (int)TapiError.Success)
584             {
585                 Log.Error(TapiUtility.LogTag, "Failed to set the emergency callback mode, Error: " + (TapiError)ret);
586                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
587             }
588
589             return task.Task;
590         }
591
592         /// <summary>
593         /// Set the network roaming preference asynchronously.
594         /// </summary>
595         /// <param name="roamPref">The network roaming preference.</param>
596         /// <returns>A task indicating whether the SetRoamingPreference method is done or not.</returns>
597         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
598         /// <privlevel>platform</privlevel>
599         /// <feature>http://tizen.org/feature/network.telephony</feature>
600         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
601         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
602         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
603         public Task SetRoamingPreference(NetworkPreferred roamPref)
604         {
605             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
606             IntPtr id;
607             id = (IntPtr)_requestId++;
608             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
609             {
610                 Task resultTask = new Task(() =>
611                 {
612                     if (result != (int)TapiError.Success)
613                     {
614                         Log.Error(TapiUtility.LogTag, "Error occurs during setting the network roaming preference, " + (TapiError)result);
615                         task.SetException(new InvalidOperationException("Error occurs during setting the network roaming preference, " + (TapiError)result));
616                         return;
617                     }
618
619                     task.SetResult(true);
620                 });
621
622                 resultTask.Start();
623                 resultTask.Wait();
624                 _response_map.Remove(key);
625             };
626
627             int ret = Interop.Tapi.Network.SetNetworkRoamPreference(_handle, roamPref, _response_map[id], id);
628             if (ret != (int)TapiError.Success)
629             {
630                 Log.Error(TapiUtility.LogTag, "Failed to set the network roaming preference, Error: " + (TapiError)ret);
631                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
632             }
633
634             return task.Task;
635         }
636
637         /// <summary>
638         /// Get the network roaming preference asynchronously.
639         /// </summary>
640         /// <returns>Value of NetworkPreferred.</returns>
641         /// <privilege>http://tizen.org/privilege/telephony</privilege>
642         /// <feature>http://tizen.org/feature/network.telephony</feature>
643         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
644         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
645         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
646         public Task<NetworkPreferred> GetRoamingPreference()
647         {
648             TaskCompletionSource<NetworkPreferred> task = new TaskCompletionSource<NetworkPreferred>();
649             IntPtr id;
650             id = (IntPtr)_requestId++;
651             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
652             {
653                 Task resultTask = new Task(() =>
654                 {
655                     if (result != (int)TapiError.Success)
656                     {
657                         Log.Error(TapiUtility.LogTag, "Error occurs during getting the network roaming preference, " + (TapiError)result);
658                         task.SetException(new InvalidOperationException("Error occurs during getting the network roaming preference, " + (TapiError)result));
659                         return;
660                     }
661
662                     task.SetResult((NetworkPreferred)Marshal.ReadInt32(dataResponse));
663                 });
664
665                 resultTask.Start();
666                 resultTask.Wait();
667                 _response_map.Remove(key);
668             };
669
670             int ret = Interop.Tapi.Network.GetNetworkRoamPreference(_handle, _response_map[id], id);
671             if (ret != (int)TapiError.Success)
672             {
673                 Log.Error(TapiUtility.LogTag, "Failed to get the network roaming preference, Error: " + (TapiError)ret);
674                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
675             }
676
677             return task.Task;
678         }
679
680         /// <summary>
681         /// Set the default data subscription asynchronously.
682         /// </summary>
683         /// <returns>A task indicating whether the SetDefaultDataSubscription method is done or not.</returns>
684         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
685         /// <privlevel>platform</privlevel>
686         /// <feature>http://tizen.org/feature/network.telephony</feature>
687         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
688         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
689         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
690         public Task SetDefaultDataSubscription()
691         {
692             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
693             IntPtr id;
694             id = (IntPtr)_requestId++;
695             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
696             {
697                 Task resultTask = new Task(() =>
698                 {
699                     if (result != (int)TapiError.Success)
700                     {
701                         Log.Error(TapiUtility.LogTag, "Error occurs during setting the default data subscription, " + (TapiError)result);
702                         task.SetException(new InvalidOperationException("Error occurs during setting the default data subscription, " + (TapiError)result));
703                         return;
704                     }
705
706                     task.SetResult(true);
707                 });
708
709                 resultTask.Start();
710                 resultTask.Wait();
711                 _response_map.Remove(key);
712             };
713
714             int ret = Interop.Tapi.Network.SetNetworkDefaultDataSubs(_handle, _response_map[id], id);
715             if (ret != (int)TapiError.Success)
716             {
717                 Log.Error(TapiUtility.LogTag, "Failed to set the default data subscription, Error: " + (TapiError)ret);
718                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
719             }
720
721             return task.Task;
722         }
723
724         /// <summary>
725         /// Get the default data subscription.
726         /// </summary>
727         /// <returns>Value of NetworkDefaultDataSubscription.</returns>
728         /// <privilege>http://tizen.org/privilege/telephony</privilege>
729         /// <feature>http://tizen.org/feature/network.telephony</feature>
730         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
731         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
732         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
733         public NetworkDefaultDataSubscription GetDefaultDataSubscription()
734         {
735             NetworkDefaultDataSubscription defaultDataSubs;
736             int ret = Interop.Tapi.Network.GetNetworkDefaultDataSubs(_handle, out defaultDataSubs);
737             if (ret != (int)TapiError.Success)
738             {
739                 Log.Error(TapiUtility.LogTag, "Failed to get the default data subscription, Error: " + (TapiError)ret);
740                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
741             }
742
743             return defaultDataSubs;
744         }
745
746         /// <summary>
747         /// Set the default subscription for voice asynchronously.
748         /// </summary>
749         /// <returns>A task indicating whether the SetNetworkDefaultSubscription method is done or not.</returns>
750         /// <privilege>http://tizen.org/privilege/telephony.admin</privilege>
751         /// <privlevel>platform</privlevel>
752         /// <feature>http://tizen.org/feature/network.telephony</feature>
753         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
754         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
755         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
756         public Task SetNetworkDefaultSubscription()
757         {
758             TaskCompletionSource<bool> task = new TaskCompletionSource<bool>();
759             IntPtr id;
760             id = (IntPtr)_requestId++;
761             _response_map[id] = (IntPtr handle, int result, IntPtr dataResponse, IntPtr key) =>
762             {
763                 Task resultTask = new Task(() =>
764                 {
765                     if (result != (int)TapiError.Success)
766                     {
767                         Log.Error(TapiUtility.LogTag, "Error occurs during setting the default subscription for voice, " + (TapiError)result);
768                         task.SetException(new InvalidOperationException("Error occurs during setting the default subscription for voice, " + (TapiError)result));
769                         return;
770                     }
771
772                     task.SetResult(true);
773                 });
774
775                 resultTask.Start();
776                 resultTask.Wait();
777                 _response_map.Remove(key);
778             };
779
780             int ret = Interop.Tapi.Network.SetNetworkDefaultDataSubs(_handle, _response_map[id], id);
781             if (ret != (int)TapiError.Success)
782             {
783                 Log.Error(TapiUtility.LogTag, "Failed to set the default subscription for voice, Error: " + (TapiError)ret);
784                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony.admin");
785             }
786
787             return task.Task;
788         }
789
790         /// <summary>
791         /// Get the default subscription for voice.
792         /// </summary>
793         /// <returns>Value of NetworkDefaultSubscription.</returns>
794         /// <privilege>http://tizen.org/privilege/telephony</privilege>
795         /// <feature>http://tizen.org/feature/network.telephony</feature>
796         /// <exception cref="System.NotSupportedException">Thrown when feature is not supported.</exception>
797         /// <exception cref="System.UnauthorizedAccessException">Thrown when privilege access is denied.</exception>
798         /// <exception cref="System.InvalidOperationException">Thrown when network instance is invalid or when method failed due to invalid operation.</exception>
799         public NetworkDefaultSubscription GetNetworkDefaultSubscription()
800         {
801             NetworkDefaultSubscription defaultSubs;
802             int ret = Interop.Tapi.Network.GetNetworkDefaultSubs(_handle, out defaultSubs);
803             if (ret != (int)TapiError.Success)
804             {
805                 Log.Error(TapiUtility.LogTag, "Failed to get the default subscription, Error: " + (TapiError)ret);
806                 TapiUtility.ThrowTapiException(ret, _handle, "http://tizen.org/privilege/telephony");
807             }
808
809             return defaultSubs;
810         }
811     }
812 }