Tizen 2.1 base
[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     else
139     {
140         __pTelephonyServiceProxy->SetCallManagerImpl(*this);
141     }
142
143         return r;
144
145 CATCH:
146         for (int i = 0; i < _CALL_NOTI_MAX; i++)
147         {
148                     tel_deregister_noti_event(__pHandle, __pCallEventType[i]);
149         }
150
151         if (__pHandle != null)
152         {
153                 tel_deinit(__pHandle);
154             __pHandle = null;
155         }
156
157         return r;
158 }
159
160 result
161 _CallManagerImpl::SetCallForwardListener(ITelephonyCallForwardListener* pListener)
162 {
163         SysTryReturnResult(NID_TEL, __pTelephonyServiceProxy != null, E_SYSTEM, "A system error has occurred. IPC instance has not been constructed yet.");
164
165         result r = __pTelephonyServiceProxy->HasCallForwardPrivilege();
166         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
167
168         if (__pCallForwardListener != null)
169     {
170             __pCallForwardEvent->RemoveListener(*__pCallForwardListener);
171             __pCallForwardListener = null;
172     }
173
174
175         // Creates event object
176     if (__pCallForwardEvent == null && pListener != null)
177     {
178         std::unique_ptr<_CallForwardEvent> pCallForwardEvent(new (std::nothrow) _CallForwardEvent());
179
180          SysTryReturnResult(NID_TEL, pCallForwardEvent != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
181
182          r = pCallForwardEvent->Construct();
183          SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
184
185          __pCallForwardEvent = move(pCallForwardEvent);
186     }
187
188     // Adds listener
189     if (pListener != null)
190     {
191         __pCallForwardListener = pListener;
192         r = __pCallForwardEvent->AddListener(*__pCallForwardListener, true);
193     }
194
195     if (r != E_SUCCESS)
196     {
197         __pCallForwardEvent.reset(null);
198                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
199     }
200
201     return r;
202 }
203
204 result
205 _CallManagerImpl::RequestCallForward(const String& phoneNumber)
206 {
207         result r = E_SUCCESS;
208
209         switch (__curCallFwdState)
210         {
211         case _CALL_FORWARD_REQUESTING:
212         {
213                 SysLogException(NID_TEL, E_IN_PROGRESS, "[%s] The previous request is in progress.", GetErrorMessage(E_IN_PROGRESS));
214                 return E_IN_PROGRESS;
215         }
216
217         case  _CALL_FORWARD_ON_SERVICE:
218         case  _CALL_FORWARD_STOPPING:
219         {
220             SysLogException(NID_TEL, E_INVALID_STATE, "[%s] The current state of the instance prohibits the execution of this operation.", GetErrorMessage(E_IN_PROGRESS));
221                 return E_INVALID_STATE;
222         }
223
224         default:
225                 break;
226         }
227
228         SysLog(NID_TEL, "The phonenumber is %ls", phoneNumber.GetPointer());
229
230         SysTryReturnResult(NID_TEL, _NetworkManagerImpl::IsNetworkAvailable(), E_NETWORK_UNAVAILABLE,
231                                           "The operation failed because the device is in the offline mode.");
232         SysTryReturnResult(NID_TEL,  _NetworkManagerImpl::IsServiceAvailable(), E_SERVICE_UNAVAILABLE,
233                                           "The operation failed because the device is out of the coverage area or in the emergency mode.");
234         SysTryReturnResult(NID_TEL, !phoneNumber.IsEmpty(), E_INVALID_FORMAT, "The phone number is empty string.");
235         SysTryReturnResult(NID_TEL, IsPhoneNumberValid(phoneNumber), E_INVALID_FORMAT, "The phone number is invalid format");
236
237         r = __pTelephonyServiceProxy->RequestCallForward(phoneNumber);
238         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
239
240         __curCallFwdState = _CALL_FORWARD_REQUESTING;
241
242         return r;
243 }
244
245 result
246 _CallManagerImpl::StopCallForward(void)
247 {
248         switch (__curCallFwdState)
249         {
250         case _CALL_FORWARD_STOPPING:
251         {
252                 SysLogException(NID_TEL, E_IN_PROGRESS, "[%s] The previous request is in progress.", GetErrorMessage(E_IN_PROGRESS));
253                 return E_IN_PROGRESS;
254         }
255         case _CALL_FORWARD_IDLE:
256         case _CALL_FORWARD_REQUESTING:
257         {
258                 SysLogException(NID_TEL, E_INVALID_STATE, "[%s] The current state of the instance prohibits the execution of this operation.", GetErrorMessage(E_INVALID_STATE));
259                 return E_INVALID_STATE;
260         }
261         default:
262                 break;
263         }
264         SysTryReturnResult(NID_TEL, _NetworkManagerImpl::IsNetworkAvailable(), E_NETWORK_UNAVAILABLE,
265                                           "The operation has failed because the device is in the offline mode.");
266         SysTryReturnResult(NID_TEL, _NetworkManagerImpl::IsServiceAvailable(), E_SERVICE_UNAVAILABLE,
267                           "The operation failed because the device is out of the coverage area or in the emergency mode.");
268
269         result r = __pTelephonyServiceProxy->StopCallForward();
270         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
271
272         __curCallFwdState = _CALL_FORWARD_STOPPING;
273
274         return r;
275 }
276
277 result
278 _CallManagerImpl::GetCallForwardNumber(void)
279 {
280         SysTryReturnResult(NID_TEL, __pCallForwardListener != null, E_INVALID_OPERATION,
281                                           "The ITelephonyCallForwardListener has not been registered yet.");
282         SysTryReturnResult(NID_TEL, !__isReqCallFwdNumInProgress, E_IN_PROGRESS, "The previous request is in progress.");
283         SysTryReturnResult(NID_TEL,  _NetworkManagerImpl::IsNetworkAvailable(), E_NETWORK_UNAVAILABLE,
284                                           "The operation has failed because the device is in the offline mode.");
285         SysTryReturnResult(NID_TEL, _NetworkManagerImpl::IsServiceAvailable(), E_SERVICE_UNAVAILABLE,
286                                           "The operation failed because the device is out of the coverage area or in the emergency mode.");
287
288         result r = __pTelephonyServiceProxy->GetCallForwardNumber();
289         SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
290
291         __isReqCallFwdNumInProgress = true;
292
293         return r;
294 }
295
296 CallType
297 _CallManagerImpl::GetCurrentCallType(void) const
298 {
299         CallType type = TYPE_UNDEFINED_CALL;
300         int err = TAPI_API_SUCCESS;
301
302         err = tel_get_call_status_all(__pHandle, OnCallTypeCallback, &type);
303
304         return type;
305 }
306
307 CallStatus
308 _CallManagerImpl::GetCurrentCallStatus(void) const
309 {
310         return __curCallState;
311 }
312
313 void
314 _CallManagerImpl::OnCallStatusChangedCallback(TapiHandle* pHandle, const char* pNotiId, void* pData, void* pUserData)
315 {
316         SysLog(NID_TEL, "The pNotiId value is %s", pNotiId);
317
318         CallType callType = TYPE_UNDEFINED_CALL;
319         String phoneNumber;
320         int callId = 0;
321         _CallManagerImpl* pCallManagerImpl = static_cast <_CallManagerImpl*>(pUserData);
322
323         if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_IDLE) == 0
324             || strcmp(pNotiId,TAPI_NOTI_VIDEO_CALL_STATUS_IDLE) == 0)
325         {
326             TelCallStatusIdleNoti_t* pNotiData = (TelCallStatusIdleNoti_t*)pData;
327             callId = pNotiData->id;
328             pCallManagerImpl->__curCallState = CALL_STATUS_IDLE;
329         }
330         else
331         {
332             if (strcmp(pNotiId, TAPI_NOTI_VOICE_CALL_STATUS_ACTIVE) == 0
333                         || strcmp(pNotiId,TAPI_NOTI_VIDEO_CALL_STATUS_ACTIVE) == 0)
334             {
335                 TelCallStatusActiveNoti_t* pNotiData = (TelCallStatusActiveNoti_t*)pData;
336                 callId = pNotiData->id;
337             }
338             else if (strcmp(pNotiId,TAPI_NOTI_VOICE_CALL_STATUS_INCOMING) == 0
339                     || strcmp(pNotiId,TAPI_NOTI_VIDEO_CALL_STATUS_INCOMING) == 0)
340             {
341                 TelCallStatusIncomingNoti_t* pNotiData = (TelCallStatusIncomingNoti_t*)pData;
342                 callId = pNotiData->id;
343             }
344             else if (strcmp(pNotiId,TAPI_NOTI_VOICE_CALL_STATUS_DIALING) == 0
345                     || strcmp(pNotiId, TAPI_NOTI_VIDEO_CALL_STATUS_DIALING) == 0)
346             {
347                 TelCallStatusDialingNoti_t* pNotiData = (TelCallStatusDialingNoti_t*)pData;
348                 callId = pNotiData->id;
349             }
350             else if (strcmp(pNotiId,TAPI_NOTI_VOICE_CALL_STATUS_HELD) == 0)
351             {
352                 TelCallStatusHeldNoti_t* pNotiData = (TelCallStatusHeldNoti_t*)pData;
353                 callId = pNotiData->id;
354             }
355             else if (strcmp(pNotiId,TAPI_NOTI_CALL_INFO_HELD) == 0)
356             {
357                 TelCallInfoHeldNoti_t* pNotiData = (TelCallInfoHeldNoti_t*)pData;
358                 callId = pNotiData->id;
359             }
360             else if (strcmp(pNotiId,TAPI_NOTI_CALL_INFO_ACTIVE) == 0)
361             {
362                 TelCallInfoActiveNoti_t* pNotiData = (TelCallInfoActiveNoti_t*)pData;
363                 callId = pNotiData->id;
364             }
365
366             int err = tel_get_call_status_all(pHandle, OnCallStatusCallback, pCallManagerImpl);
367             SysLog(NID_TEL, "The tel_get_call_status_all() returned %d value", err);
368
369             phoneNumber = pCallManagerImpl->GetPhoneNumber(pHandle, callId);
370                 SysLog(NID_TEL, "The phonenumber is %ls", phoneNumber.GetPointer());
371         }
372
373
374         callType = pCallManagerImpl->GetCurrentCallType();
375
376         if (pCallManagerImpl->__curCallState != CALL_STATUS_UNDEFINED)
377         {
378                 unique_ptr<CallInfo> pCallInfo(null);
379             _CallInfoImpl* pCallInfoImpl = null;
380
381             pCallInfo.reset(new (std::nothrow) CallInfo());
382             SysTryReturnVoidResult(NID_TEL, pCallInfo != null, E_OUT_OF_MEMORY,
383                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
384
385             pCallInfoImpl = _CallInfoImpl::GetInstance(*pCallInfo);
386             pCallInfoImpl->SetCallType(callType);
387             pCallInfoImpl->SetNumber(phoneNumber);
388
389             _CallManagerEventArg* pEventArg = new (std::nothrow)_CallManagerEventArg(pCallManagerImpl->__curCallState, pCallInfo.get());
390             SysTryReturnVoidResult(NID_TEL,pEventArg != null, E_OUT_OF_MEMORY,
391                         "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
392
393                 pCallInfo.release();
394
395                 SysLog(NID_TEL, "The current call type is %d, and the phonenumber is %ls", callType, phoneNumber.GetPointer());
396             (void)pCallManagerImpl->__pCallManagerEvent->Fire(*pEventArg);
397         }
398 }
399
400 void
401 _CallManagerImpl::OnTelephonyCallForwardNumberReceived(Tizen::Base::String phoneNumber, result r)
402 {
403         SysLog(NID_TEL, "The listener has called with result %s and phonenumber is %ls", GetErrorMessage(r), phoneNumber.GetPointer());
404
405     _CallForwardEventArg* pEventArg = new (std::nothrow)_CallForwardEventArg(_CALL_FORWARD_EVENT_NUMBER_RECEIVED, phoneNumber, r);
406
407     SysTryReturnVoidResult(NID_TEL,pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
408
409     (void)__pCallForwardEvent->Fire(*pEventArg);
410
411     __isReqCallFwdNumInProgress = false;
412 }
413
414 void
415 _CallManagerImpl::OnTelephonyCallForwardResponseReceived(Tizen::Base::String phoneNumber, result r)
416 {       
417         SysLog(NID_TEL, "The listener has called with result %s and phonenumber is %ls", GetErrorMessage(r), phoneNumber.GetPointer());
418
419     _CallForwardEventArg* pEventArg = new (std::nothrow)_CallForwardEventArg(_CALL_FORWARD_EVENT_RESPONSE_RECEIVED, phoneNumber, r);
420
421     SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
422
423     (void)__pCallForwardEvent->Fire(*pEventArg);
424
425     if (r != E_SUCCESS)
426     {
427         __curCallFwdState = _CALL_FORWARD_IDLE;
428     }
429     else
430     {
431         __curCallFwdState = _CALL_FORWARD_ON_SERVICE;
432     }
433 }
434
435 void
436 _CallManagerImpl::OnTelephonyCallForwardStopped(Tizen::Base::String phoneNumber, result r)
437 {
438     SysLog(NID_TEL, "The listener has called with result %s and phonenumber is %ls", GetErrorMessage(r), phoneNumber.GetPointer());
439
440     _CallForwardEventArg* pEventArg = new (std::nothrow)_CallForwardEventArg(_CALL_FORWARD_EVENT_STOPPED, phoneNumber, r);
441
442     SysTryReturnVoidResult(NID_TEL, pEventArg != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
443
444     (void)__pCallForwardEvent->Fire(*pEventArg);
445
446     if (r != E_SUCCESS)
447     {
448        __curCallFwdState = _CALL_FORWARD_ON_SERVICE;
449     }
450     else
451     {
452        __curCallFwdState = _CALL_FORWARD_IDLE;
453     }
454 }
455
456 void
457 _CallManagerImpl::OnCallStatusCallback(TelCallStatus_t* status, void* pUserData)
458 {
459         _CallManagerImpl* pImpl = static_cast<_CallManagerImpl*>(pUserData);
460
461     // Priority : Ringing/Dialing > Communicating > Hold
462         // ToDO : multi party call scenario 
463
464         switch (status->CallState)
465         {
466         case TAPI_CALL_STATE_IDLE:
467             pImpl->__curCallState = CALL_STATUS_IDLE;
468             break;
469         case TAPI_CALL_STATE_ACTIVE:
470                 pImpl->__curCallState = CALL_STATUS_COMMUNICATING;
471                 break;
472         case TAPI_CALL_STATE_HELD:
473             pImpl->__curCallState = CALL_STATUS_HOLDING;
474             break;
475         case TAPI_CALL_STATE_INCOMING:
476             pImpl->__curCallState = CALL_STATUS_RINGING;
477             break;
478         case TAPI_CALL_STATE_DIALING:
479         case TAPI_CALL_STATE_ALERT:
480             pImpl->__curCallState = CALL_STATUS_DIALING;
481             break;
482         default:
483             break;
484         }
485
486         return;
487 }
488
489 void
490 _CallManagerImpl::OnCallTypeCallback(TelCallStatus_t* status, void* pUserData)
491 {
492         CallType* pCallType = static_cast<CallType*>(pUserData);
493
494         switch (status->CallType)
495         {
496         case TAPI_CALL_TYPE_VOICE:
497             *pCallType = TYPE_VOICE_CALL;
498             break;
499         case TAPI_CALL_TYPE_DATA:
500             *pCallType = TYPE_VIDEO_CALL;
501             break;
502         default:
503             break;
504         }
505
506         return;
507 }
508
509 bool
510 _CallManagerImpl::IsPhoneNumberValid(const String& phoneNumber) const
511 {
512         bool isValid = true;
513         int startIndex = 0;
514         wchar_t chr = 0;
515
516         if (phoneNumber.StartsWith("+", 0))
517         {
518                 startIndex = 1;
519         }
520
521         for (int i = startIndex; i < phoneNumber.GetLength(); i++)
522         {
523                 phoneNumber.GetCharAt(i, chr);
524
525                 if (!Character::IsDigit(chr))
526                 {
527                         isValid = false;
528                         break;
529                 }
530         }
531         return isValid;
532 }
533
534 result
535 _CallManagerImpl::InitializeInternalCallStatus(void)
536 {
537         int err = TAPI_API_SUCCESS;
538         result r = E_SUCCESS;
539
540         err = tel_get_call_status_all(__pHandle, OnCallStatusCallback, this);
541         SysLog(NID_TEL, "The tel_get_call_status_all() returned %d value", err);
542
543         if (err != TAPI_API_SUCCESS)
544         {
545             if (err == TAPI_API_OPERATION_FAILED)
546             {
547                 __curCallState = CALL_STATUS_IDLE;
548             }
549             else
550             {
551                 r = E_SYSTEM;
552             }
553         }
554
555         return r;
556 }
557
558 String
559 _CallManagerImpl::GetPhoneNumber(TapiHandle* pCallHandle, int callId) const
560 {
561         int err = TAPI_API_SUCCESS;
562         String phoneNumber;
563
564         TelCallStatus_t callStatus = {};
565         err = tel_get_call_status(pCallHandle, callId, &callStatus);
566         if (err == TAPI_API_SUCCESS)
567         {
568             (void)(StringUtil::Utf8ToString(callStatus.pNumber, phoneNumber));
569             SysLog(NID_TEL, "The phone number is %ls", phoneNumber.GetPointer());
570         }
571         else
572         {
573             SysLog(NID_TEL, "The tel_get_call_status_all() returned %d value", err);
574         }
575
576         return phoneNumber;
577 }
578
579 const char*
580 _CallManagerImpl::GetStringOfCallState(void) const
581 {
582         static const char* pStateStr[] =
583         {
584                 "CALL_STATUS_UNDEFINED",
585                 "CALL_STATUS_IDLE",
586                 "CALL_STATUS_ACTIVE",
587                 "CALL_STATUS_COMMUNICATING",
588                 "CALL_STATUS_RINGING",
589                 "CALL_STATUS_DIALING",
590                 "CALL_STATUS_HOLDING"
591         };
592
593         return pStateStr[__curCallState + 1];
594 }
595
596 const char*
597 _CallManagerImpl::GetStringOfCallFwdState(void) const
598 {
599         static const char* pFwdStateStr[] =
600         {
601                 "CALL_FORWARD_IDLE",
602                 "CALL_FORWARD_REQUESTING",
603                 "CALL_FORWARD_ON_SERVICE",
604                 "CALL_FORWARD_STOPPING"
605         };
606
607         return pFwdStateStr[__curCallFwdState];
608 }
609
610 const char*
611 _CallManagerImpl::GetStringOfCallEventType(int type) const
612 {
613         static const char* pEventType[] =
614         {
615                 "Voice Call End",
616                 "Voice Communicating",
617                 "Voice Ringing",
618                 "Voice Dialing",
619                 "Voice Holding",
620                 "Video Call End",
621                 "Video Communicating",
622                 "Video Ringing",
623                 "Video Dialing",
624                 "Peer Held",
625                 "Peer Retrieved"
626         };
627
628         return pEventType[type];
629 }
630
631 _CallManagerImpl*
632 _CallManagerImpl::GetInstance(CallManager& callManager)
633 {
634         return callManager.__pCallManagerImpl;
635 }
636
637 const _CallManagerImpl*
638 _CallManagerImpl::GetInstance(const CallManager& callManager)
639 {
640         return callManager.__pCallManagerImpl;
641 }
642
643 }} // Tizen::Telephony
644
645