2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
19 * @file FTel_TelephonyIpcProxy.cpp
20 * @brief This is the implementation file for the %_TelephonyIpcProxy class.
22 * This file contains the implementation of the %_TelephonyIpcProxy class.
26 #include <unique_ptr.h>
27 #include <FBaseSysLog.h>
28 #include <FIo_IpcClient.h>
29 #include <FTel_ConnectivityIpcMessages.h>
30 #include "FTel_TelephonyIpcProxy.h"
31 #include "FTel_CallManagerImpl.h"
32 #include "FTel_NetworkManagerImpl.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Io;
37 namespace Tizen { namespace Telephony
40 _TelephonyIpcProxy* _TelephonyIpcProxy::__pInstance = null;
42 _TelephonyIpcProxy::_TelephonyIpcProxy(void)
44 , __pNetworkManagerImpl(null)
45 , __pCallManagerImpl(null)
49 _TelephonyIpcProxy::~_TelephonyIpcProxy(void)
55 _TelephonyIpcProxy::Construct(void)
59 __pIpcClient = new (std::nothrow) _IpcClient();
60 SysTryReturnResult(NID_TEL, __pIpcClient != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
62 r = __pIpcClient->Construct(TELEPHONY_CONNECTIVITY_IPC_SERVER_NAME, this);
63 SysTryReturnResult(NID_TEL, r != E_OUT_OF_MEMORY, r, "Propagating.");
67 SysLogException(NID_TEL, r, "[%s] Propagating", GetErrorMessage(r));
76 _TelephonyIpcProxy::GetInstance(void)
78 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
80 if (__pInstance == null)
83 pthread_once(&onceBlock, InitSingleton);
84 result r = GetLastResult();
87 onceBlock = PTHREAD_ONCE_INIT;
95 _TelephonyIpcProxy::InitSingleton(void)
98 static _TelephonyIpcProxy instance;
100 r = instance.Construct();
101 SysTryReturnVoidResult(NID_TEL, r == E_SUCCESS, r, "[%s] Propagating", GetErrorMessage(r));
103 __pInstance = &instance;
107 _TelephonyIpcProxy::GetImsi(Tizen::Base::String& imsi) const
109 result r = E_SUCCESS;
110 unsigned long ret = 0;
112 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_getImsi(&imsi, &ret));
113 SysTryReturnResult(NID_TEL, pMessage!= null , E_OUT_OF_MEMORY, "Memory allocation failed.");
115 r = __pIpcClient->SendRequest(*pMessage);
117 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
118 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
120 SysLog(NID_TEL, "The Telephony Imsi obtained through IPC is %ls.", imsi.GetPointer());
126 _TelephonyIpcProxy::HasSystemPrivilege(void)
128 result r = E_SUCCESS;
129 unsigned long ret = 0;
131 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_hasSystemPrivilege(&ret));
132 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
134 r = __pIpcClient->SendRequest(*pMessage);
135 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
136 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
142 _TelephonyIpcProxy::GetNetworkSelectionMode(void)
144 result r = E_SUCCESS;
145 unsigned long ret = 0;
147 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_getNetworkSelectionMode(&ret));
148 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
150 r = __pIpcClient->SendRequest(*pMessage);
151 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
152 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
158 _TelephonyIpcProxy::SelectNetwork(const Tizen::Base::String& plmn, const int netwokrType)
160 result r = E_SUCCESS;
161 unsigned long ret = 0;
163 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_selectNetworkManual(plmn, netwokrType, &ret));
164 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
166 r = __pIpcClient->SendRequest(*pMessage);
167 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
168 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
174 _TelephonyIpcProxy::SelectNetwork(void)
176 result r = E_SUCCESS;
177 unsigned long ret = 0;
179 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_selectNetworkAutomatic(&ret));
180 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
182 r = __pIpcClient->SendRequest(*pMessage);
183 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
184 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
191 _TelephonyIpcProxy::SearchNetwork(void)
193 result r = E_SUCCESS;
194 unsigned long ret = 0;
196 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_searchNetwork(&ret));
197 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
199 r = __pIpcClient->SendRequest(*pMessage);
200 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
201 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
208 _TelephonyIpcProxy::HasCallForwardPrivilege(void)
210 result r = E_SUCCESS;
211 unsigned long ret = 0;
213 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_hasCallForwardPrivilege(&ret));
214 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
216 r = __pIpcClient->SendRequest(*pMessage);
217 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
218 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
224 _TelephonyIpcProxy::RequestCallForward(const String& phoneNumber)
226 result r = E_SUCCESS;
227 unsigned long ret = 0;
229 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_requestCallForward(phoneNumber, &ret));
230 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
232 r = __pIpcClient->SendRequest(*pMessage);
233 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
234 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
240 _TelephonyIpcProxy::StopCallForward(void)
242 result r = E_SUCCESS;
243 unsigned long ret = 0;
245 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_stopCallForward(&ret));
246 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
248 r = __pIpcClient->SendRequest(*pMessage);
249 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
250 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
256 _TelephonyIpcProxy::GetCallForwardNumber(void)
258 result r = E_SUCCESS;
259 unsigned long ret = 0;
261 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_getCallForwardNumber(&ret));
262 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
264 r = __pIpcClient->SendRequest(*pMessage);
265 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
266 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
272 _TelephonyIpcProxy::SetNetworkManagerImpl(_NetworkManagerImpl& impl)
274 __pNetworkManagerImpl = &impl;
278 _TelephonyIpcProxy::SetCallManagerImpl(_CallManagerImpl& impl)
280 __pCallManagerImpl = &impl;
284 _TelephonyIpcProxy::OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message)
286 SysLog(NID_TEL, "OnIpcResponseReceived");
288 IPC_BEGIN_MESSAGE_MAP(_TelephonyIpcProxy, message)
289 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onNetworkSelectionModeReceived, OnNetworkSelectionModeReceived, &client)
290 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onNetworkSelectionCompleted, OnNetworkSelectionCompleted, &client)
291 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onNetworkSearchCompleted, OnNetworkSearchCompleted, &client)
292 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onCallForwardNumberReceived, OnTelephonyCallForwardNumberReceived, &client);
293 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onCallForwardResponseReceived, OnTelephonyCallForwardResponseReceived, &client);
294 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onCallForwardStopped, OnTelephonyCallForwardStopped, &client);
295 IPC_END_MESSAGE_MAP()
299 _TelephonyIpcProxy::OnNetworkSelectionModeReceived(bool isManual, unsigned long res)
301 SysLog(NID_TEL, "The listener has been called.");
303 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
305 __pNetworkManagerImpl->OnTelephonyNetworkSelectionModeReceived(isManual, res);
309 _TelephonyIpcProxy::OnNetworkSelectionCompleted(unsigned long res)
311 SysLog(NID_TEL, "The listener has been called.");
313 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
315 __pNetworkManagerImpl->OnTelephonyNetworkSelectionCompleted(res);
319 _TelephonyIpcProxy::OnNetworkSearchCompleted(Tizen::Base::String message, unsigned long res)
321 SysLog(NID_TEL, "The listener has been called.");
323 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
325 __pNetworkManagerImpl->OnTelephonyNetworkSearchCompleted(message, res);
329 _TelephonyIpcProxy::OnTelephonyCallForwardNumberReceived(Tizen::Base::String phoneNumber, unsigned long res)
331 SysLog(NID_TEL, "The listener has been called.");
333 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
335 __pCallManagerImpl->OnTelephonyCallForwardNumberReceived(phoneNumber, res);
339 _TelephonyIpcProxy::OnTelephonyCallForwardResponseReceived(Tizen::Base::String phoneNumber, unsigned long res)
341 SysLog(NID_TEL, "The listener has been called.");
343 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
345 __pCallManagerImpl->OnTelephonyCallForwardResponseReceived(phoneNumber, res);
349 _TelephonyIpcProxy::OnTelephonyCallForwardStopped(Tizen::Base::String phoneNumber, unsigned long res)
351 SysLog(NID_TEL, "The listener has been called.");
353 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
355 __pCallManagerImpl->OnTelephonyCallForwardStopped(phoneNumber, res);
358 }} // Tizen::Telephony