Change License under the Apache License.
[platform/core/csapi/telephony.git] / 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         /// <priviledge>
59         /// http://tizen.org/privilege/telephony
60         /// </priviledge>
61         /// <returns>
62         /// The currently set preferred voicecall subscription value.
63         /// </returns>
64         public CallPreferredVoiceSubsubscription PreferredVoiceSubscription
65         {
66             get
67             {
68                 CallPreferredVoiceSubsubscription subs = CallPreferredVoiceSubsubscription.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 CallPreferredVoiceSubsubscription.Unknown;
74                 }
75
76                 return subs;
77             }
78         }
79
80         /// <summary>
81         /// Gets the list of the current call.
82         /// </summary>
83         /// <priviledge>
84         /// http://tizen.org/privilege/telephony
85         /// </priviledge>
86         /// <returns>
87         /// List of CallHandle for existing calls.
88         /// </returns>
89         /// <exception cref="InvalidOperationException">
90         /// This exception can occur due to one of the following reasons:
91         /// 1. Permission Denied
92         /// 2. Not Supported
93         /// 3. Operation Failed
94         /// </exception>
95         public List<CallHandle> GetCallHandleList()
96         {
97             uint count;
98             _callList = new IntPtr();
99             _list.Clear();
100             TelephonyError error = Interop.Call.GetCallList(_handle, out count, out _callList);
101             if (error != TelephonyError.None)
102             {
103                 Tizen.Log.Error(Interop.Telephony.LogTag, "GetCallList Failed with error " + error);
104                 throw ExceptionFactory.CreateException(error);
105             }
106
107             _callHandle.Clear();
108             if (count > 0)
109             {
110                 IntPtr[] handleArray = new IntPtr[count];
111                 Marshal.Copy(_callList, handleArray, 0, (int)count);
112                 foreach (IntPtr handle in handleArray)
113                 {
114                     CallHandle info = new CallHandle(handle);
115                     _list.Add(info);
116                 }
117
118                 _safeCallList = new Interop.Call.SafeCallList(_callList, count);
119             }
120             return _list;
121         }
122     }
123 }