Release 4.0.0-preview1-00051
[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         /// <since_tizen> 3 </since_tizen>
40         /// <param name="handle">
41         /// SlotHandle received in the Manager.Init API
42         /// </param>
43         /// <feature>http://tizen.org/feature/network.telephony</feature>
44         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
45         /// <exception cref="ArgumentNullException">
46         /// This exception occurs if handle provided is null
47         /// </exception>
48         public Call(SlotHandle handle)
49         {
50             if (handle == null)
51             {
52                 throw new ArgumentNullException();
53             }
54
55             _handle = handle._handle;
56         }
57
58         /// <summary>
59         /// Gets the current value for the preferred voice call subscription.
60         /// </summary>
61         /// <since_tizen> 3 </since_tizen>
62         /// <privilege>http://tizen.org/privilege/telephony</privilege>
63         /// <value>
64         /// The currently set preferred voicecall subscription value.
65         /// </value>
66         public CallPreferredVoiceSubscription PreferredVoiceSubscription
67         {
68             get
69             {
70                 CallPreferredVoiceSubscription subs = CallPreferredVoiceSubscription.Unknown;
71                 TelephonyError error = Interop.Call.GetPreferredVoiceSubscription(_handle, out subs);
72                 if (error != TelephonyError.None)
73                 {
74                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetPreferredVoiceSubscription Failed with error " + error);
75                     return CallPreferredVoiceSubscription.Unknown;
76                 }
77
78                 return subs;
79             }
80         }
81
82         /// <summary>
83         /// Gets the list of the current call.
84         /// </summary>
85         /// <since_tizen> 3 </since_tizen>
86         /// <returns>
87         /// List of CallHandle for existing calls.
88         /// </returns>
89         /// <privilege>http://tizen.org/privilege/telephony</privilege>
90         /// <feature>http://tizen.org/feature/network.telephony</feature>
91         /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
92         /// <exception cref="ArgumentException">Incase of Invalid parameter</exception>
93         /// <exception cref="InvalidOperationException">Incase of any System error</exception>
94         /// <exception cref="UnauthorizedAccessException">Incase of Privileges are not defined</exception>
95         /// <exception cref="OutOfMemoryException">Incase of Out of Memory</exception>
96         public IEnumerable<CallHandle> GetCallHandleList()
97         {
98             uint count;
99             _callList = new IntPtr();
100             _list.Clear();
101             TelephonyError error = Interop.Call.GetCallList(_handle, out count, out _callList);
102             if (error != TelephonyError.None)
103             {
104                 Tizen.Log.Error(Interop.Telephony.LogTag, "GetCallList Failed with error " + error);
105                 throw ExceptionFactory.CreateException(error);
106             }
107
108             _callHandle.Clear();
109             if (count > 0)
110             {
111                 IntPtr[] handleArray = new IntPtr[count];
112                 Marshal.Copy(_callList, handleArray, 0, (int)count);
113                 foreach (IntPtr handle in handleArray)
114                 {
115                     CallHandle info = new CallHandle(handle);
116                     _list.Add(info);
117                 }
118
119                 _safeCallList = new Interop.Call.SafeCallList(_callList, count);
120             }
121             return _list;
122         }
123     }
124 }