Synchronized tizen_2.1 branch with master
[platform/framework/native/telephony.git] / src / FTelCallManager.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        CallManager.cpp
19  * @brief       This is the implementation file for CallManager class.
20  */
21
22 #include <FTelCallManager.h>
23 #include <FBaseSysLog.h>
24 #include <FSec_AccessController.h>
25 #include <FSys_SystemInfoImpl.h>
26 #include "FTel_CallManagerImpl.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Security;
30 using namespace Tizen::System;
31
32
33 namespace Tizen { namespace Telephony
34 {
35 CallManager::CallManager(void)
36         : __pCallManagerImpl(null)
37 {
38 }
39
40 CallManager::~CallManager(void)
41 {
42         delete __pCallManagerImpl;
43 }
44
45 result
46 CallManager::Construct(void)
47 {
48         static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
49
50         SysAssertf(__pCallManagerImpl  == null,
51                         "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
52
53         result r = E_SUCCESS;
54         bool isTelephonySupported = false;
55
56     r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
57     SysTryReturnResult(NID_TEL, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
58
59         __pCallManagerImpl = new (std::nothrow) _CallManagerImpl();
60         SysTryReturnResult(NID_TEL, __pCallManagerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
61
62         r = __pCallManagerImpl->Construct();
63         if (r != E_SUCCESS)
64         {
65                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
66                 delete __pCallManagerImpl;
67                 __pCallManagerImpl = null;
68         }
69
70         return r;
71 }
72
73 result
74 CallManager::Construct(ITelephonyCallEventListener& listener)
75 {
76         static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
77
78         SysAssertf(__pCallManagerImpl == null,
79                 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
80
81         result r = E_SUCCESS;
82         bool isTelephonySupported = false;
83
84     r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
85     SysTryReturnResult(NID_TEL, r == E_SUCCESS && isTelephonySupported, E_UNSUPPORTED_OPERATION, "Telephony is not supported.");
86
87         __pCallManagerImpl = new (std::nothrow) _CallManagerImpl();
88         SysTryReturnResult(NID_TEL, __pCallManagerImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
89
90         r = __pCallManagerImpl->Construct(&listener);
91
92         if (r != E_SUCCESS)
93         {
94                 SysLogException(NID_TEL, r, "[%s] Propagating.", GetErrorMessage(r));
95                 delete __pCallManagerImpl;
96                 __pCallManagerImpl = null;
97         }
98
99         return r;
100 }
101
102 result
103 CallManager::SetCallForwardListener(ITelephonyCallForwardListener* pListener)
104 {
105         SysAssertf(__pCallManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
106
107         result r = E_SUCCESS;
108
109         r = __pCallManagerImpl->SetCallForwardListener(pListener);
110
111     if (r == E_PRIVILEGE_DENIED)
112     {
113         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
114     }
115     else if( r != E_SUCCESS)
116     {
117         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
118     }
119
120         return r;
121 }
122
123 result
124 CallManager::RequestCallForward(const String& phoneNumber)
125 {
126         SysAssertf(__pCallManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
127
128         result r = E_SUCCESS;
129
130         r = __pCallManagerImpl->RequestCallForward(phoneNumber);
131
132     if (r == E_PRIVILEGE_DENIED)
133     {
134         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
135     }
136     else if( r != E_SUCCESS)
137     {
138         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
139     }
140
141         return r;
142 }
143
144 result
145 CallManager::StopCallForward(void)
146 {
147         SysAssertf(__pCallManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
148
149         result r = E_SUCCESS;
150
151         r = __pCallManagerImpl->StopCallForward();
152
153     if (r == E_PRIVILEGE_DENIED)
154     {
155         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
156     }
157     else if( r != E_SUCCESS)
158     {
159         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
160     }
161
162         return r;
163 }
164
165 result
166 CallManager::GetCallForwardNumber(void) const
167 {
168         SysAssertf(__pCallManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
169
170         result r = E_SUCCESS;
171
172         r = __pCallManagerImpl->GetCallForwardNumber();
173
174     if (r == E_PRIVILEGE_DENIED)
175     {
176         SysLogException(NID_TEL, E_PRIVILEGE_DENIED, "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
177     }
178     else if( r != E_SUCCESS)
179     {
180         SysLogException(NID_TEL, r,"[%s] Propagating.", GetErrorMessage(r));
181     }
182
183         return r;
184 }
185
186 CallType
187 CallManager::GetCurrentCallType(void) const
188 {
189         SysAssertf(__pCallManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
190
191         CallType callType = TYPE_UNDEFINED_CALL;
192
193         callType = __pCallManagerImpl->GetCurrentCallType();
194
195         return callType;
196 }
197
198 CallStatus
199 CallManager::GetCurrentCallStatus(void) const
200 {
201         SysAssertf(__pCallManagerImpl != null, "Not yet constructed. Construct() should be called before use.");
202
203         CallStatus callStatus = CALL_STATUS_UNDEFINED;
204
205         callStatus = __pCallManagerImpl->GetCurrentCallStatus();
206
207         return callStatus;
208 }
209
210 }} // Tizen::Telephony