Fix TC crash.
[platform/framework/native/telephony.git] / src / FTel_CallManagerImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 /**
18  * @file    FTel_CallManagerImpl.cpp
19  * @brief   This is the implementation file for _CallManagerImpl class.
20  */
21
22 #include <string.h>
23 #include <glib.h>
24 #include <tapi_common.h>
25 #include <tapi_event.h>
26 #include <TapiUtility.h>
27 #include <ITapiCall.h>
28 #include <FBaseString.h>
29 #include <FBaseUtilStringUtil.h>
30 #include <FTelITelephonyCallEventListener.h>
31 #include <FTelITelephonyCallForwardListener.h>
32 #include <FTelCallManager.h>
33 #include <FBaseSysLog.h>
34 #include "FTel_CallInfoImpl.h"
35 #include "FTel_CallManagerImpl.h"
36 #include "FTel_CallManagerEvent.h"
37 #include "FTel_CallManagerEventArg.h"
38 #include "FTel_CallForwardEvent.h"
39 #include "FTel_CallForwardEventArg.h"
40 #include "FTel_TelephonyIpcProxy.h"
41 #include "FTel_NetworkManagerImpl.h"
42
43 using namespace std;
44 using namespace Tizen::App;
45 using namespace Tizen::Base;
46 using namespace Tizen::Base::Utility;
47
48
49 namespace Tizen { namespace Telephony
50 {
51
52 _CallManagerImpl::_CallManagerImpl(void)
53         : __pCallEventListener(null)
54         , __pCallForwardListener(null)
55         , __pHandle(null)
56         , __callFwdSubscriptionId(0)
57         , __callFwdStatusSubscriptionId(0)
58         , __callFwdReqId(INVALID_REQUEST_ID)
59         , __callFwdReqNumId(INVALID_REQUEST_ID)
60         , __isReqCallFwdNumInProgress(false)
61         , __curCallState(CALL_STATUS_IDLE)
62         , __curCallFwdState(_CALL_FORWARD_IDLE)
63     , __pCallManagerEvent(null)
64     , __pCallForwardEvent(null)
65
66 {
67         __pCallEventType[_CALL_NOTI_VOICE_CALL_IDLE] = TAPI_NOTI_VOICE_CALL_STATUS_IDLE;
68         __pCallEventType[_CALL_NOTI_VOICE_CALL_COMMUNICATING] = TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE;
69         __pCallEventType[_CALL_NOTI_VOICE_CALL_RINGING] = TAPI_NOTI_VOICE_CALL_STATUS_INCOMING;
70         __pCallEventType[_CALL_NOTI_VOICE_CALL_DIALING] = TAPI_NOTI_VOICE_CALL_STATUS_DIALING;
71         __pCallEventType[_CALL_NOTI_VOICE_CALL_HOLDING] = TAPI_NOTI_VOICE_CALL_STATUS_HELD;
72         __pCallEventType[_CALL_NOTI_VIDEO_CALL_IDLE] = TAPI_NOTI_VIDEO_CALL_STATUS_IDLE;
73         __pCallEventType[_CALL_NOTI_VIDEO_CALL_COMMUNICATING] = TAPI_NOTI_VIDEO_CALL_STATUS_ACTIVE;
74         __pCallEventType[_CALL_NOTI_VIDEO_CALL_RINGING] = TAPI_NOTI_VIDEO_CALL_STATUS_INCOMING;
75         __pCallEventType[_CALL_NOTI_VIDEO_CALL_DIALING] = TAPI_NOTI_VIDEO_CALL_STATUS_DIALING;
76         __pCallEventType[_CALL_NOTI_PEER_CALL_HELD] = TAPI_NOTI_CALL_INFO_HELD;
77         __pCallEventType[_CALL_NOTI_PEER_CALL_RETRIEVED] = TAPI_NOTI_CALL_INFO_ACTIVE;
78
79 }
80
81 _CallManagerImpl::~_CallManagerImpl(void)
82 {
83         if (__pHandle != null)
84         {
85                 for (int i = 0; i < _CALL_NOTI_MAX; i++)
86                 {
87                         tel_deregister_noti_event(__pHandle, __pCallEventType[i]);
88         }
89
90                 tel_deinit(__pHandle);
91         }
92 }
93
94 result
95 _CallManagerImpl::Construct(ITelephonyCallEventListener* pListener)
96 {
97         SysLog(NID_TEL, "The current call state is %s", GetStringOfCallState());
98
99         result r = E_SUCCESS;
100         int err = TAPI_API_SUCCESS;
101
102         __pHandle = tel_init(null);
103         SysTryCatch(NID_TEL, __pHandle != null, r = E_SYSTEM, E_SYSTEM, "[%s] A system error has occurred. Failed to initialize TApi library.", GetErrorMessage(E_SYSTEM));
104
105         if (pListener != null)
106         {
107                 for (int i = 0; i < _CALL_NOTI_MAX; i++)
108                 {
109                         err = tel_register_noti_event(__pHandle, __pCallEventType[i], OnCallStatusChangedCallback, this);
110                         SysLog(NID_TEL, "The registered call type is %s", GetStringOfCallEventType(_CALL_NOTI_VOICE_CALL_IDLE + i));
111
112                         SysTryCatch(NID_TEL, err == TAPI_API_SUCCESS, r = E_SYSTEM, E_SYSTEM,
113                                 "[%s] A system error has occurred. Failed to register the callback function.", GetErrorMessage(E_SYSTEM));
114                 }
115
116                 unique_ptr<_CallManagerEvent> pCallManagerEvent(new (std::nothrow) _CallManagerEvent);
117         SysTryReturnResult(NID_TEL, pCallManagerEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
118
119         r = pCallManagerEvent->Construct();
120         SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
121         SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has occurred. Failed to construct CallManagerEvent.");
122
123         pCallManagerEvent->AddListener(*pListener, true);
124
125         __pCallManagerEvent = move(pCallManagerEvent);
126
127         }
128
129         r = InitializeInternalCallStatus();
130         SysTryCatch(NID_TEL, r == E_SUCCESS, , E_SYSTEM, "[%s] A system error has occurred. Failed to initialize internal call state.", GetErrorMessage(E_SYSTEM));
131
132         __pTelephonyServiceProxy = _TelephonyIpcProxy::GetInstance();
133
134         if (__pTelephonyServiceProxy == null)
135     {
136         SysLog(NID_TEL, "Creating an IPC instance to connect with the Connectivity service daemon has failed.");
137     }
138
139         return r;
140
141 CATCH:
142         for (int i = 0; i < _CALL_NOTI_MAX; i++)
143         {
144                     tel_deregister_noti_event(__pHandle, __pCallEventType[i]);
145         }
146
147         if (__pHandle != null)
148         {
149                 tel_deinit(__pHandle);
150             __pHandle = null;
151         }
152
153         return r;
154 }
155
156 result
157 _CallManagerImpl::SetCallForwardListener(ITelephonyCallForwardListener* pListener)
158 {
159         SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "A system error has occurred. IPC instance has not been constructed yet.");
160
161         result r = __pTelephonyServiceProxy->HasCallForwardPrivilege();
162         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
163
164         if (__pCallForwardListener != null)
165     {
166             __pCallForwardEvent->RemoveListener(*__pCallForwardListener);
167             __pCallForwardListener = null;
168     }
169
170
171         // Creates event object
172     if (__pCallForwardEvent == null && pListener != null)
173     {
174         std::unique_ptr<_CallForwardEvent> pCallForwardEvent(new (std::nothrow) _CallForwardEvent());
175
176          SysTryReturnResult(NID_TEL, pCallForwardEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
177
178          r = pCallForwardEvent->Construct();
179          SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
180
181          __pCallForwardEvent = move(pCallForwardEvent);
182     }
183
184     // Adds listener
185     if (pListener != null)
186     {
187         __pCallForwardListener = pListener;
188         r = __pCallForwardEvent->AddListener(*__pCallForwardListener, true);
189     }
190
191     if (r != E_SUCCESS)
192     {
193         __pCallForwardEvent.reset(null);
194                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
195     }
196
197     return r;
198 }
199
200 result
201 _CallManagerImpl::RequestCallForward(const String& phoneNumber)
202 {
203         result r = E_SUCCESS;
204
205         switch (__curCallFwdState)
206         {
207         case _CALL_FORWARD_REQUESTING:
208         {
209                 SysLogException(NID_TEL, E_IN_PROGRESS, "[%s] The previous request is in progress.", GetErrorMessage(E_IN_PROGRESS));
210                 return E_IN_PROGRESS;
211         }
212
213         case  _CALL_FORWARD_ON_SERVICE:
214         case  _CALL_FORWARD_STOPPING:
215         {
216             SysLogException(NID_TEL, E_INVALID_STATE, "[%s] The current state of the instance prohibits the execution of this operation.", GetErrorMessage(E_IN_PROGRESS));
217                 return E_INVALID_STATE;
218         }
219
220         default:
221                 break;
222         }
223
224         SysLog(NID_TEL, "The phonenumber is %ls", phoneNumber.GetPointer());
225
226         SysTryReturnResult(NID_TEL, _NetworkManagerImpl::IsNetworkAvailable(), E_NETWORK_UNAVAILABLE,
227                                           "The operation failed because the device is in the offline mode.");
228         SysTryReturnResult(NID_TEL,  _NetworkManagerImpl::IsServiceAvailable(), E_SERVICE_UNAVAILABLE,
229                                           "The operation failed because the device is out of the coverage area or in the emergency mode.");
230         SysTryReturnResult(NID_TEL, !phoneNumber.IsEmpty(), E_INVALID_FORMAT, "The phone number is empty string.");
231         SysTryReturnResult(NID_TEL, IsPhoneNumberValid(phoneNumber), E_INVALID_FORMAT, "The phone number is invalid format");
232
233         r = __pTelephonyServiceProxy->RequestCallForward(this, phoneNumber);
234         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
235
236         __curCallFwdState = _CALL_FORWARD_REQUESTING;
237
238         return r;
239 }
240
241 result
242 _CallManagerImpl::StopCallForward(void)
243 {
244         switch (__curCallFwdState)
245         {
246         case _CALL_FORWARD_STOPPING:
247         {
248                 SysLogException(NID_TEL, E_IN_PROGRESS, "[%s] The previous request is in progress.", GetErrorMessage(E_IN_PROGRESS));
249                 return E_IN_PROGRESS;
250         }
251         case _CALL_FORWARD_IDLE:
252         case _CALL_FORWARD_REQUESTING:
253         {
254                 SysLogException(NID_TEL, E_INVALID_STATE, "[%s] The current state of the instance prohibits the execution of this operation.", GetErrorMessage(E_INVALID_STATE));
255                 return E_INVALID_STATE;
256         }
257         default:
258                 break;
259         }
260         SysTryReturnResult(NID_TEL, _NetworkManagerImpl::IsNetworkAvailable(), E_NETWORK_UNAVAILABLE,
261                                           "The operation has failed because the device is in the offline mode.");
262         SysTryReturnResult(NID_TEL, _NetworkManagerImpl::IsServiceAvailable(), E_SERVICE_UNAVAILABLE,
263                           "The operation failed because the device is out of the coverage area or in the emergency mode.");
264
265         result r = __pTelephonyServiceProxy->StopCallForward(this);
266         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
267
268         __curCallFwdState = _CALL_FORWARD_STOPPING;
269
270         return r;
271 }
272
273 result
274 _CallManagerImpl::GetCallForwardNumber(void)
275 {
276         SysTryReturnResult(NID_TEL, __pCallForwardListener != null, E_INVALID_OPERATION,
277                                           "The ITelephonyCallForwardListener has not been registered yet.");
278         SysTryReturnResult(NID_TEL, !__isReqCallFwdNumInProgress, E_IN_PROGRESS, "The previous request is in progress.");
279         SysTryReturnResult(NID_TEL,  _NetworkManagerImpl::IsNetworkAvailable(), E_NETWORK_UNAVAILABLE,
280                                           "The operation has failed because the device is in the offline mode.");
281         SysTryReturnResult(NID_TEL, _NetworkManagerImpl::IsServiceAvailable(), E_SERVICE_UNAVAILABLE,
282                                           "The operation failed because the device is out of the coverage area or in the emergency mode.");
283
284         result r = __pTelephonyServiceProxy->GetCallForwardNumber(this);
285         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
286
287         __isReqCallFwdNumInProgress = true;
288
289         return r;
290 }
291
292 CallType
293 _CallManagerImpl::GetCurrentCallType(void) const
294 {
295         CallType type = TYPE_UNDEFINED_CALL;
296         int err = TAPI_API_SUCCESS;
297
298         err = tel_get_call_status_all(__pHandle, OnCallTypeCallback, &type);
299
300         return type;
301 }
302
303 CallStatus
304 _CallManagerImpl::GetCurrentCallStatus(void) const
305 {
306         return __curCallState;
307 }
308
309 void
310 _CallManagerImpl::OnCallStatusChangedCallback(TapiHandle* pHandle, const char* pNotiId, void* pData, void* pUserData)
311 {
312         SysLog(NID_TEL, "The pNotiId value is %s", pNotiId);
313
314         CallType callType = TYPE_UNDEFINED_CALL;
315         String phoneNumber;
316         int callId = 0;
317         _CallManagerImpl* pCallManagerImpl = static_cast <_CallManagerImpl*>(pUserData);
318
319         if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_IDLE) == 0
320             || strcmp(pNotiId,TAPI_NOTI_VIDEO_CALL_STATUS_IDLE) == 0)
321         {
322             TelCallStatusIdleNoti_t* pNotiData = (TelCallStatusIdleNoti_t*)pData;
323             callId = pNotiData->id;
324             pCallManagerImpl->__curCallState = CALL_STATUS_IDLE;
325         }
326         else
327         {
328             if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE) == 0
329                         || strcmp(pNotiId,TAPI_NOTI_VIDEO_CALL_STATUS_ACTIVE) == 0)
330             {
331                 TelCallStatusActiveNoti_t* pNotiData = (TelCallStatusActiveNoti_t*)pData;
332                 callId = pNotiData->id;
333             }
334             else if (strcmp(pNotiId,TAPI_NOTI_VOICE_CALL_STATUS_INCOMING) == 0
335                     || strcmp(pNotiId,TAPI_NOTI_VIDEO_CALL_STATUS_INCOMING) == 0)
336             {
337                 TelCallStatusIncomingNoti_t* pNotiData = (TelCallStatusIncomingNoti_t*)pData;
338                 callId = pNotiData->id;
339             }
340             else if (strcmp(pNotiId,TAPI_NOTI_VOICE_CALL_STATUS_DIALING) == 0
341                     || strcmp(pNotiId, TAPI_NOTI_VIDEO_CALL_STATUS_DIALING) == 0)
342             {
343                 TelCallStatusDialingNoti_t* pNotiData = (TelCallStatusDialingNoti_t*)pData;
344                 callId = pNotiData->id;
345             }
346             else if (strcmp(pNotiId,TAPI_NOTI_VOICE_CALL_STATUS_HELD) == 0)
347             {
348                 TelCallStatusHeldNoti_t* pNotiData = (TelCallStatusHeldNoti_t*)pData;
349                 callId = pNotiData->id;
350             }
351             else if (strcmp(pNotiId,TAPI_NOTI_CALL_INFO_HELD) == 0)
352             {
353                 TelCallInfoHeldNoti_t* pNotiData = (TelCallInfoHeldNoti_t*)pData;
354                 callId = pNotiData->id;
355             }
356             else if (strcmp(pNotiId,TAPI_NOTI_CALL_INFO_ACTIVE) == 0)
357             {
358                 TelCallInfoActiveNoti_t* pNotiData = (TelCallInfoActiveNoti_t*)pData;
359                 callId = pNotiData->id;
360             }
361
362             int err = tel_get_call_status_all(pHandle, OnCallStatusCallback, pCallManagerImpl);
363             SysLog(NID_TEL, "The tel_get_call_status_all() returned %d value", err);
364
365             phoneNumber = pCallManagerImpl->GetPhoneNumber(pHandle, callId);
366                 SysLog(NID_TEL, "The phonenumber is %ls", phoneNumber.GetPointer());
367         }
368
369
370         callType = pCallManagerImpl->GetCurrentCallType();
371
372         if (pCallManagerImpl->__curCallState != CALL_STATUS_UNDEFINED)
373         {
374                 unique_ptr<CallInfo> pCallInfo(null);
375             _CallInfoImpl* pCallInfoImpl = null;
376
377             pCallInfo.reset(new (std::nothrow) CallInfo());
378             SysTryReturnVoidResult(NID_TEL, pCallInfo != null, E_OUT_OF_MEMORY,
379                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
380
381             pCallInfoImpl = _CallInfoImpl::GetInstance(*pCallInfo);
382             pCallInfoImpl->SetCallType(callType);
383             pCallInfoImpl->SetNumber(phoneNumber);
384
385             _CallManagerEventArg* pEventArg = new (std::nothrow)_CallManagerEventArg(pCallManagerImpl->__curCallState, pCallInfo.get());
386             SysTryReturnVoidResult(NID_TEL,pEventArg != null, E_OUT_OF_MEMORY,
387                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
388
389                 pCallInfo.release();
390
391                 SysLog(NID_TEL, "The current call type is %d, and the phonenumber is %ls", callType, phoneNumber.GetPointer());
392             (void)pCallManagerImpl->__pCallManagerEvent->Fire(*pEventArg);
393         }
394 }
395
396 void
397 _CallManagerImpl::OnTelephonyCallForwardNumberReceived(Tizen::Base::String phoneNumber, result r)
398 {
399         SysLog(NID_TEL, "The listener has called with result %s and phonenumber is %ls", GetErrorMessage(r), phoneNumber.GetPointer());
400
401     _CallForwardEventArg* pEventArg = new (std::nothrow)_CallForwardEventArg(_CALL_FORWARD_EVENT_NUMBER_RECEIVED, phoneNumber, r);
402
403     SysTryReturnVoidResult(NID_TEL,pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
404
405     (void)__pCallForwardEvent->Fire(*pEventArg);
406
407     __isReqCallFwdNumInProgress = false;
408 }
409
410 void
411 _CallManagerImpl::OnTelephonyCallForwardResponseReceived(Tizen::Base::String phoneNumber, result r)
412 {       
413         SysLog(NID_TEL, "The listener has called with result %s and phonenumber is %ls", GetErrorMessage(r), phoneNumber.GetPointer());
414
415     _CallForwardEventArg* pEventArg = new (std::nothrow)_CallForwardEventArg(_CALL_FORWARD_EVENT_RESPONSE_RECEIVED, phoneNumber, r);
416
417     SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
418
419     (void)__pCallForwardEvent->Fire(*pEventArg);
420
421     if (r != E_SUCCESS)
422     {
423         __curCallFwdState = _CALL_FORWARD_IDLE;
424     }
425     else
426     {
427         __curCallFwdState = _CALL_FORWARD_ON_SERVICE;
428     }
429 }
430
431 void
432 _CallManagerImpl::OnTelephonyCallForwardStopped(Tizen::Base::String phoneNumber, result r)
433 {
434     SysLog(NID_TEL, "The listener has called with result %s and phonenumber is %ls", GetErrorMessage(r), phoneNumber.GetPointer());
435
436     _CallForwardEventArg* pEventArg = new (std::nothrow)_CallForwardEventArg(_CALL_FORWARD_EVENT_STOPPED, phoneNumber, r);
437
438     SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
439
440     (void)__pCallForwardEvent->Fire(*pEventArg);
441
442     if (r != E_SUCCESS)
443     {
444        __curCallFwdState = _CALL_FORWARD_ON_SERVICE;
445     }
446     else
447     {
448        __curCallFwdState = _CALL_FORWARD_IDLE;
449     }
450 }
451
452 void
453 _CallManagerImpl::OnCallStatusCallback(TelCallStatus_t* status, void* pUserData)
454 {
455         _CallManagerImpl* pImpl = static_cast<_CallManagerImpl*>(pUserData);
456
457     // Priority : Ringing/Dialing > Communicating > Hold
458         // ToDO : multi party call scenario 
459
460         switch (status->CallState)
461         {
462         case TAPI_CALL_STATE_IDLE:
463             pImpl->__curCallState = CALL_STATUS_IDLE;
464             break;
465         case TAPI_CALL_STATE_ACTIVE:
466                 pImpl->__curCallState = CALL_STATUS_COMMUNICATING;
467                 break;
468         case TAPI_CALL_STATE_HELD:
469             pImpl->__curCallState = CALL_STATUS_HOLDING;
470             break;
471         case TAPI_CALL_STATE_INCOMING:
472             pImpl->__curCallState = CALL_STATUS_RINGING;
473             break;
474         case TAPI_CALL_STATE_DIALING:
475         case TAPI_CALL_STATE_ALERT:
476             pImpl->__curCallState = CALL_STATUS_DIALING;
477             break;
478         default:
479             break;
480         }
481
482         return;
483 }
484
485 void
486 _CallManagerImpl::OnCallTypeCallback(TelCallStatus_t* status, void* pUserData)
487 {
488         CallType* pCallType = static_cast<CallType*>(pUserData);
489
490         switch (status->CallType)
491         {
492         case TAPI_CALL_TYPE_VOICE:
493             *pCallType = TYPE_VOICE_CALL;
494             break;
495         case TAPI_CALL_TYPE_DATA:
496             *pCallType = TYPE_VIDEO_CALL;
497             break;
498         default:
499             break;
500         }
501
502         return;
503 }
504
505 bool
506 _CallManagerImpl::IsPhoneNumberValid(const String& phoneNumber) const
507 {
508         bool isValid = true;
509         int startIndex = 0;
510         wchar_t chr = 0;
511
512         if (phoneNumber.StartsWith("+", 0))
513         {
514                 startIndex = 1;
515         }
516
517         for (int i = startIndex; i < phoneNumber.GetLength(); i++)
518         {
519                 phoneNumber.GetCharAt(i, chr);
520
521                 if (!Character::IsDigit(chr))
522                 {
523                         isValid = false;
524                         break;
525                 }
526         }
527         return isValid;
528 }
529
530 result
531 _CallManagerImpl::InitializeInternalCallStatus(void)
532 {
533         int err = TAPI_API_SUCCESS;
534         result r = E_SUCCESS;
535
536         err = tel_get_call_status_all(__pHandle, OnCallStatusCallback, this);
537         SysLog(NID_TEL, "The tel_get_call_status_all() returned %d value", err);
538
539         if (err != TAPI_API_SUCCESS)
540         {
541             if (err == TAPI_API_OPERATION_FAILED)
542             {
543                 __curCallState = CALL_STATUS_IDLE;
544             }
545             else
546             {
547                 r = E_SYSTEM;
548             }
549         }
550
551         return r;
552 }
553
554 String
555 _CallManagerImpl::GetPhoneNumber(TapiHandle* pCallHandle, int callId) const
556 {
557         int err = TAPI_API_SUCCESS;
558         String phoneNumber;
559
560         TelCallStatus_t callStatus = {};
561         err = tel_get_call_status(pCallHandle, callId, &callStatus);
562         if (err == TAPI_API_SUCCESS)
563         {
564             (void)(StringUtil::Utf8ToString(callStatus.pNumber, phoneNumber));
565             SysLog(NID_TEL, "The phone number is %ls", phoneNumber.GetPointer());
566         }
567         else
568         {
569             SysLog(NID_TEL, "The tel_get_call_status_all() returned %d value", err);
570         }
571
572         return phoneNumber;
573 }
574
575 const char*
576 _CallManagerImpl::GetStringOfCallState(void) const
577 {
578         static const char* pStateStr[] =
579         {
580                 "CALL_STATUS_UNDEFINED",
581                 "CALL_STATUS_IDLE",
582                 "CALL_STATUS_ACTIVE",
583                 "CALL_STATUS_COMMUNICATING",
584                 "CALL_STATUS_RINGING",
585                 "CALL_STATUS_DIALING",
586                 "CALL_STATUS_HOLDING"
587         };
588
589         return pStateStr[__curCallState + 1];
590 }
591
592 const char*
593 _CallManagerImpl::GetStringOfCallFwdState(void) const
594 {
595         static const char* pFwdStateStr[] =
596         {
597                 "CALL_FORWARD_IDLE",
598                 "CALL_FORWARD_REQUESTING",
599                 "CALL_FORWARD_ON_SERVICE",
600                 "CALL_FORWARD_STOPPING"
601         };
602
603         return pFwdStateStr[__curCallFwdState];
604 }
605
606 const char*
607 _CallManagerImpl::GetStringOfCallEventType(int type) const
608 {
609         static const char* pEventType[] =
610         {
611                 "Voice Call End",
612                 "Voice Communicating",
613                 "Voice Ringing",
614                 "Voice Dialing",
615                 "Voice Holding",
616                 "Video Call End",
617                 "Video Communicating",
618                 "Video Ringing",
619                 "Video Dialing",
620                 "Peer Held",
621                 "Peer Retrieved"
622         };
623
624         return pEventType[type];
625 }
626
627 _CallManagerImpl*
628 _CallManagerImpl::GetInstance(CallManager& callManager)
629 {
630         return callManager.__pCallManagerImpl;
631 }
632
633 const _CallManagerImpl*
634 _CallManagerImpl::GetInstance(const CallManager& callManager)
635 {
636         return callManager.__pCallManagerImpl;
637 }
638
639 }} // Tizen::Telephony
640
641