Change return-type from List to IEnumerable
[platform/core/csapi/tizenfx.git] / src / Tizen.Telephony / Tizen.Telephony / Call.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 static Interop.Telephony;
21
22 namespace Tizen.Telephony
23 {
24     /// <summary>
25     /// The Call API's allows you to get the voice and video call states.
26     /// It provides the List of CallHandle which can be used to get the information about call related actions.
27     /// </summary>
28     public class Call
29     {
30         internal IntPtr _handle;
31         private List<IntPtr> _callHandle = new List<IntPtr>();
32         private List<CallHandle> _list = new List<CallHandle>();
33         private IntPtr _callList;
34         private Interop.Call.SafeCallList _safeCallList;
35
36         /// <summary>
37         /// Public Constructor
38         /// </summary>
39         /// <param name="handle">
40         /// SlotHandle received in the Manager.Init API
41         /// </param>
42         /// <exception cref="ArgumentNullException">
43         /// This exception occurs if handle provided is null
44         /// </exception>
45         public Call(SlotHandle handle)
46         {
47             if (handle == null)
48             {
49                 throw new ArgumentNullException();
50             }
51
52             _handle = handle._handle;
53         }
54
55         /// <summary>
56         /// Gets the current value for the preferred voice call subscription.
57         /// </summary>
58         /// <privilege>
59         /// http://tizen.org/privilege/telephony
60         /// </privilege>
61         /// <returns>
62         /// The currently set preferred voicecall subscription value.
63         /// </returns>
64         public CallPreferredVoiceSubscription PreferredVoiceSubscription
65         {
66             get
67             {
68                 CallPreferredVoiceSubscription subs = CallPreferredVoiceSubscription.Unknown;
69                 TelephonyError error = Interop.Call.GetPreferredVoiceSubscription(_handle, out subs);
70                 if (error != TelephonyError.None)
71                 {
72                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetPreferredVoiceSubscription Failed with error " + error);
73                     return CallPreferredVoiceSubscription.Unknown;
74                 }
75
76                 return subs;
77             }
78         }
79
80         /// <summary>
81         /// Gets the list of the current call.
82         /// </summary>
83         /// <privilege>
84         /// http://tizen.org/privilege/telephony
85         /// </privilege>
86         /// <returns>
87         /// List of CallHandle for existing calls.
88         /// </returns>
89         /// <exception cref="ArgumentException">Incase of Invalid parameter</exception>
90         /// <exception cref="InvalidOperationException">Incase of any System error</exception>
91         /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined</exception>
92         /// <exception cref="NotSupportedException">Incase of Telephony is not supported</exception>>
93         /// <exception cref="OutOfMemoryException">Incase of Out of Memory</exception>>
94         public IEnumerable<CallHandle> GetCallHandleList()
95         {
96             uint count;
97             _callList = new IntPtr();
98             _list.Clear();
99             TelephonyError error = Interop.Call.GetCallList(_handle, out count, out _callList);
100             if (error != TelephonyError.None)
101             {
102                 Tizen.Log.Error(Interop.Telephony.LogTag, "GetCallList Failed with error " + error);
103                 throw ExceptionFactory.CreateException(error);
104             }
105
106             _callHandle.Clear();
107             if (count > 0)
108             {
109                 IntPtr[] handleArray = new IntPtr[count];
110                 Marshal.Copy(_callList, handleArray, 0, (int)count);
111                 foreach (IntPtr handle in handleArray)
112                 {
113                     CallHandle info = new CallHandle(handle);
114                     _list.Add(info);
115                 }
116
117                 _safeCallList = new Interop.Call.SafeCallList(_callList, count);
118             }
119             return _list;
120         }
121     }
122 }