Change License under the Apache License.
[platform/core/csapi/telephony.git] / Tizen.Telephony / Tizen.Telephony / CallHandle.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 static Interop.Telephony;
19
20 namespace Tizen.Telephony
21 {
22     /// <summary>
23     /// This Class provides API's to get the information about calls.
24     /// </summary>
25     public class CallHandle
26     {
27         private IntPtr _callHandle;
28
29         /// <summary>
30         /// Enumeration for the call status.
31         /// </summary>
32         public enum CallStatus
33         {
34             /// <summary>
35             /// Idle status
36             /// </summary>
37             Idle,
38             /// <summary>
39             /// Active status
40             /// </summary>
41             Active,
42             /// <summary>
43             /// Held status
44             /// </summary>
45             Held,
46             /// <summary>
47             /// Dialing status
48             /// </summary>
49             Dialing,
50             /// <summary>
51             /// Alerting status
52             /// </summary>
53             Alerting,
54             /// <summary>
55             /// Incoming status
56             /// </summary>
57             Incoming,
58             /// <summary>
59             /// Unavailable
60             /// </summary>
61             Unavailable
62         };
63
64         /// <summary>
65         /// Enumeration for the call type.
66         /// </summary>
67         public enum CallType
68         {
69             /// <summary>
70             /// Voice call
71             /// </summary>
72             Voice,
73             /// <summary>
74             /// Video call
75             /// </summary>
76             Video,
77             /// <summary>
78             /// Emergency call
79             /// </summary>
80             E911,
81             /// <summary>
82             /// Unavailable
83             /// </summary>
84             Unavailable
85         };
86
87         /// <summary>
88         /// Enumeration for the call direction.
89         /// </summary>
90         public enum CallDirection
91         {
92             /// <summary>
93             /// MO(Mobile Originated) call
94             /// </summary>
95             Mo,
96             /// <summary>
97             /// MT(Mobile Terminated) call
98             /// </summary>
99             Mt,
100             /// <summary>
101             /// Unavailable
102             /// </summary>
103             Unavailable
104         };
105
106         /// <summary>
107         /// Gets the call handle ID.
108         /// </summary>
109         /// <returns>
110         /// The id of the call handle
111         /// 0 if unable to complete the operation
112         /// </returns>
113         public uint HandleId
114         {
115             get
116             {
117                 uint handleId;
118                 TelephonyError error = Interop.Call.GetHandleId(_callHandle, out handleId);
119                 if (error != TelephonyError.None)
120                 {
121                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetHandleId Failed with Error " + error);
122                     return 0;
123                 }
124
125                 return handleId;
126             }
127         }
128
129         /// <summary>
130         /// Gets the call number.
131         /// </summary>
132         /// <returns>
133         /// The number of the call
134         /// empty string if unable to complete the operation
135         /// </returns>
136         public string Number
137         {
138             get
139             {
140                 string number;
141                 TelephonyError error = Interop.Call.GetNumber(_callHandle, out number);
142                 if (error != TelephonyError.None)
143                 {
144                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetNumber Failed with Error " + error);
145                     return "";
146                 }
147
148                 return number;
149             }
150         }
151
152         /// <summary>
153         /// Gets the call type.
154         /// </summary>
155         /// <returns>
156         /// The type of the call
157         /// </returns>
158         public CallType Type
159         {
160             get
161             {
162                 CallType callType;
163                 TelephonyError error = Interop.Call.GetType(_callHandle, out callType);
164                 if (error != TelephonyError.None)
165                 {
166                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetType Failed with Error " + error);
167                     return CallType.Unavailable;
168                 }
169
170                 return callType;
171             }
172         }
173
174         /// <summary>
175         /// Gets the call status.
176         /// </summary>
177         /// <returns>
178         /// The status of the call
179         /// </returns>
180         public CallStatus Status
181         {
182             get
183             {
184                 CallStatus callStatus;
185                 TelephonyError error = Interop.Call.GetStatus(_callHandle, out callStatus);
186                 if (error != TelephonyError.None)
187                 {
188                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetStatus Failed with Error " + error);
189                     return CallStatus.Unavailable;
190                 }
191
192                 return callStatus;
193             }
194         }
195
196         /// <summary>
197         /// Gets whether the call is MO(Mobile Originated) call or MT(Mobile Terminated).
198         /// </summary>
199         /// <returns>
200         /// The direction of the call
201         /// </returns>
202         /// <exception cref="InvalidOperationException">
203         /// This Exception can occur due to:
204         /// 1. Operation Not Supported
205         /// </exception>
206         public CallDirection Direction
207         {
208             get
209             {
210                 CallDirection callDirection;
211                 TelephonyError error = Interop.Call.GetDirection(_callHandle, out callDirection);
212                 if (error != TelephonyError.None)
213                 {
214                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetDirection Failed with Error " + error);
215                     return CallDirection.Unavailable;
216                 }
217
218                 return callDirection;
219             }
220
221         }
222
223         /// <summary>
224         /// Gets whether the call is conference call or not.
225         /// </summary>
226         /// <returns>
227         /// The value whether the call is conference call or not. (true: Conference call, false: Single call)
228         /// </returns>
229         public bool ConferenceStatus
230         {
231             get
232             {
233                 bool callConfStatus;
234                 TelephonyError error = Interop.Call.GetConferenceStatus(_callHandle, out callConfStatus);
235                 if (error != TelephonyError.None)
236                 {
237                     Tizen.Log.Error(Interop.Telephony.LogTag, "GetConferenceStatus Failed with Error " + error);
238                     return false;
239                 }
240
241                 return callConfStatus;
242             }
243
244         }
245
246         internal CallHandle(IntPtr handle)
247         {
248             _callHandle = handle;
249         }
250     }
251 }