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 <FBaseRtMutexGuard.h>
29 #include <FBaseColArrayList.h>
30 #include <FTelNetworkStatus.h>
31 #include <FIo_IpcClient.h>
32 #include <FTel_ConnectivityIpcMessages.h>
33 #include "FTel_TelephonyIpcProxy.h"
34 #include "FTel_CallManagerImpl.h"
35 #include "FTel_NetworkManagerEvent.h"
36 #include "FTel_NetworkManagerEventArg.h"
37 #include "FTel_NetworkManagerImpl.h"
38 #include "FTel_NetworkStatusImpl.h"
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Runtime;
43 using namespace Tizen::Base::Collection;
44 using namespace Tizen::Io;
46 namespace Tizen { namespace Telephony
49 _TelephonyIpcProxy* _TelephonyIpcProxy::__pInstance = null;
51 _TelephonyIpcProxy::_TelephonyIpcProxy(void)
54 , __pNetworkEventList(null)
55 , __networkEventCount(0)
56 , __pNetworkManagerImplForGet(null)
57 , __pNetworkManagerImplForSelect(null)
58 , __pNetworkManagerImplForSearch(null)
59 , __pCallManagerImplForGet(null)
60 , __pCallManagerImplForStart(null)
61 , __pCallManagerImplForStop(null)
65 _TelephonyIpcProxy::~_TelephonyIpcProxy(void)
67 if ((__networkEventCount > 0) &&(__pIpcClient != null))
70 unsigned long ret = 0;
72 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_removeNetworkStatusEventListener(&ret));
73 SysTryReturnVoidResult(NID_TEL, pMessage != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
75 r = __pIpcClient->SendRequest(*pMessage);
76 SysLog(NID_TEL, "RemoveNetworkStatusEventListener[%s][%s]", GetErrorMessage(r), GetErrorMessage(ret));
81 _TelephonyIpcProxy::Construct(void)
85 unique_ptr<ArrayList> pNetworkEventList(new (std::nothrow) ArrayList());
86 SysTryReturnResult(NID_TEL, pNetworkEventList != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
88 r = pNetworkEventList->Construct();
89 SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
91 unique_ptr<Mutex> pLock(new (std::nothrow) Mutex());
92 SysTryReturnResult(NID_TEL, pLock != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
95 SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
97 unique_ptr<_IpcClient> pIpcClient(new (std::nothrow) _IpcClient());
98 SysTryReturnResult(NID_TEL, pIpcClient != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
100 r = pIpcClient->Construct(TELEPHONY_CONNECTIVITY_IPC_SERVER_NAME, this);
101 SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
103 __pIpcClient = move(pIpcClient);
104 __pLock = move(pLock);
105 __pNetworkEventList = move(pNetworkEventList);
106 __networkEventCount = 0;
112 _TelephonyIpcProxy::GetInstance(void)
114 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
116 if (__pInstance == null)
119 pthread_once(&onceBlock, InitSingleton);
120 result r = GetLastResult();
123 onceBlock = PTHREAD_ONCE_INIT;
131 _TelephonyIpcProxy::InitSingleton(void)
133 result r = E_SUCCESS;
135 unique_ptr<_TelephonyIpcProxy> pInstance(new (std::nothrow) _TelephonyIpcProxy());
136 SysTryReturnVoidResult(NID_TEL, pInstance != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
138 r = pInstance->Construct();
139 SysTryReturnVoidResult(NID_TEL, r == E_SUCCESS, r, "[%s] Propagating.", GetErrorMessage(r));
143 __pInstance = pInstance.release();
147 _TelephonyIpcProxy::GetImsi(Tizen::Base::String& imsi) const
149 result r = E_SUCCESS;
150 unsigned long ret = 0;
152 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_getImsi(&imsi, &ret));
153 SysTryReturnResult(NID_TEL, pMessage!= null , E_OUT_OF_MEMORY, "Memory allocation failed.");
155 r = __pIpcClient->SendRequest(*pMessage);
157 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
158 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
160 SysSecureLog(NID_TEL, "The Telephony Imsi obtained through IPC is %ls.", imsi.GetPointer());
166 _TelephonyIpcProxy::HasSystemPrivilege(void)
168 result r = E_SUCCESS;
169 unsigned long ret = 0;
171 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_hasSystemPrivilege(&ret));
172 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
174 r = __pIpcClient->SendRequest(*pMessage);
175 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
176 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
182 _TelephonyIpcProxy::GetNetworkSelectionMode(_NetworkManagerImpl* pNetworkManagerImpl)
184 result r = E_SUCCESS;
185 unsigned long ret = 0;
187 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_getNetworkSelectionMode(&ret));
188 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
190 r = __pIpcClient->SendRequest(*pMessage);
191 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
192 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
194 __pNetworkManagerImplForGet = pNetworkManagerImpl;
200 _TelephonyIpcProxy::SelectNetwork(_NetworkManagerImpl* pNetworkManagerImpl, const Tizen::Base::String& plmn, const int netwokrType)
202 result r = E_SUCCESS;
203 unsigned long ret = 0;
205 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_selectNetworkManual(plmn, netwokrType, &ret));
206 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
208 r = __pIpcClient->SendRequest(*pMessage);
209 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
210 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
212 __pNetworkManagerImplForSelect = pNetworkManagerImpl;
218 _TelephonyIpcProxy::SelectNetwork(_NetworkManagerImpl* pNetworkManagerImpl)
220 result r = E_SUCCESS;
221 unsigned long ret = 0;
223 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_selectNetworkAutomatic(&ret));
224 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
226 r = __pIpcClient->SendRequest(*pMessage);
227 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
228 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
230 __pNetworkManagerImplForSelect = pNetworkManagerImpl;
237 _TelephonyIpcProxy::SearchNetwork(_NetworkManagerImpl* pNetworkManagerImpl)
239 result r = E_SUCCESS;
240 unsigned long ret = 0;
242 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_searchNetwork(&ret));
243 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
245 r = __pIpcClient->SendRequest(*pMessage);
246 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
247 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
249 __pNetworkManagerImplForSearch = pNetworkManagerImpl;
256 _TelephonyIpcProxy::HasCallForwardPrivilege(void)
258 result r = E_SUCCESS;
259 unsigned long ret = 0;
261 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_hasCallForwardPrivilege(&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::RequestCallForward(_CallManagerImpl* pCallManagerImpl, const String& phoneNumber)
274 result r = E_SUCCESS;
275 unsigned long ret = 0;
277 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_requestCallForward(phoneNumber, &ret));
278 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
280 r = __pIpcClient->SendRequest(*pMessage);
281 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
282 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
284 __pCallManagerImplForStart = pCallManagerImpl;
290 _TelephonyIpcProxy::StopCallForward(_CallManagerImpl* pCallManagerImpl)
292 result r = E_SUCCESS;
293 unsigned long ret = 0;
295 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_stopCallForward(&ret));
296 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
298 r = __pIpcClient->SendRequest(*pMessage);
299 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
300 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
302 __pCallManagerImplForStop = pCallManagerImpl;
308 _TelephonyIpcProxy::GetCallForwardNumber(_CallManagerImpl* pCallManagerImpl)
310 result r = E_SUCCESS;
311 unsigned long ret = 0;
313 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_getCallForwardNumber(&ret));
314 SysTryReturnResult(NID_TEL, pMessage != null , E_OUT_OF_MEMORY, "Memory allocation failed.");
316 r = __pIpcClient->SendRequest(*pMessage);
317 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
318 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
320 __pCallManagerImplForGet = pCallManagerImpl;
326 _TelephonyIpcProxy::AddNetworkEvent(_NetworkManagerEvent* pEvent)
328 result r = E_SUCCESS;
330 SysTryReturnResult(NID_TEL, pEvent != null, E_INVALID_ARG, "Event is null.");
332 MutexGuard locked(*__pLock);
334 r = __pNetworkEventList->Add(*pEvent);
335 SysTryReturnResult(NID_TEL, r == E_SUCCESS, r, "Propagating.");
337 if (__networkEventCount == 0)
339 SysLog(NID_TEL, "Set network event callback.");
341 unsigned long ret = 0;
343 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_addNetworkStatusEventListener(&ret));
344 r = __pIpcClient->SendRequest(*pMessage);
345 SysTryReturnResult(NID_TEL, r == E_SUCCESS, E_SYSTEM, "A system error has been occurred. Failed to send a request.");
346 SysTryReturnResult(NID_TEL, ret == E_SUCCESS, ret, "Propagating.");
349 __networkEventCount++;
355 _TelephonyIpcProxy::RemoveNetworkEvent(_NetworkManagerEvent* pEvent)
357 SysTryReturnVoidResult(NID_TEL, pEvent != null, E_INVALID_ARG, "[E_INVALID_ARG] Event is null.");
359 MutexGuard locked(*__pLock);
361 __pNetworkEventList->Remove(*pEvent);
363 __networkEventCount--;
365 if (__networkEventCount == 0)
367 SysLog(NID_TEL, "Unset network event callback.");
369 result r = E_SUCCESS;
370 unsigned long ret = 0;
372 std::unique_ptr<IPC::Message> pMessage( new (std::nothrow) ConnectivityTelephonyServiceMsg_removeNetworkStatusEventListener(&ret));
373 SysTryReturnVoidResult(NID_TEL, pMessage != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
375 r = __pIpcClient->SendRequest(*pMessage);
376 SysLog(NID_TEL, "RemoveNetworkStatusEventListener[%s][%s]", GetErrorMessage(r), GetErrorMessage(ret));
381 _TelephonyIpcProxy::OnIpcResponseReceived(Tizen::Io::_IpcClient& client, const IPC::Message& message)
383 SysLog(NID_TEL, "OnIpcResponseReceived");
385 IPC_BEGIN_MESSAGE_MAP(_TelephonyIpcProxy, message)
386 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onNetworkSelectionModeReceived, OnNetworkSelectionModeReceived, &client)
387 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onNetworkSelectionCompleted, OnNetworkSelectionCompleted, &client)
388 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onNetworkSearchCompleted, OnNetworkSearchCompleted, &client)
389 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onCallForwardNumberReceived, OnTelephonyCallForwardNumberReceived, &client);
390 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onCallForwardResponseReceived, OnTelephonyCallForwardResponseReceived, &client);
391 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onCallForwardStopped, OnTelephonyCallForwardStopped, &client);
392 IPC_MESSAGE_HANDLER(ConnectivityTelephonyServiceMsg_onNetworkStatusChanged, OnNetworkStatusChanged, &client);
393 IPC_END_MESSAGE_MAP()
397 _TelephonyIpcProxy::OnNetworkSelectionModeReceived(bool isManual, unsigned long res)
399 SysLog(NID_TEL, "The listener has been called.");
401 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
403 __pNetworkManagerImplForGet->OnTelephonyNetworkSelectionModeReceived(isManual, res);
407 _TelephonyIpcProxy::OnNetworkSelectionCompleted(unsigned long res)
409 SysLog(NID_TEL, "The listener has been called.");
411 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
413 __pNetworkManagerImplForSelect->OnTelephonyNetworkSelectionCompleted(res);
417 _TelephonyIpcProxy::OnNetworkSearchCompleted(Tizen::Base::String message, unsigned long res)
419 SysLog(NID_TEL, "The listener has been called.");
421 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
423 __pNetworkManagerImplForSearch->OnTelephonyNetworkSearchCompleted(message, res);
427 _TelephonyIpcProxy::OnTelephonyCallForwardNumberReceived(Tizen::Base::String phoneNumber, unsigned long res)
429 SysLog(NID_TEL, "The listener has been called.");
431 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
433 __pCallManagerImplForGet->OnTelephonyCallForwardNumberReceived(phoneNumber, res);
437 _TelephonyIpcProxy::OnTelephonyCallForwardResponseReceived(Tizen::Base::String phoneNumber, unsigned long res)
439 SysLog(NID_TEL, "The listener has been called.");
441 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
443 __pCallManagerImplForStart->OnTelephonyCallForwardResponseReceived(phoneNumber, res);
447 _TelephonyIpcProxy::OnTelephonyCallForwardStopped(Tizen::Base::String phoneNumber, unsigned long res)
449 SysLog(NID_TEL, "The listener has been called.");
451 SysAssertf(__pIpcClient != null, "Not yet constructed. Construct() should be called before use.");
453 __pCallManagerImplForStop->OnTelephonyCallForwardStopped(phoneNumber, res);
457 _TelephonyIpcProxy::OnNetworkStatusChanged(bool isCallServiceAvailable, bool isDataServiceAvailable, bool isRoaming)
459 SysLog(NID_TEL, "Network status is changed. [%d][%d][%d]", isCallServiceAvailable, isDataServiceAvailable, isRoaming);
461 NetworkStatus networkStatus;
462 _NetworkManagerEvent* pEvent = null;
463 _NetworkManagerEventArg* pEventArg = null;
465 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsCallServiceAvailable(isCallServiceAvailable);
466 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsDataServiceAvailable(isDataServiceAvailable);
467 _NetworkStatusImpl::GetInstance(networkStatus)->SetIsRoaming(isRoaming);
469 unique_ptr<IEnumerator> pEnum(__pNetworkEventList->GetEnumeratorN());
472 while (pEnum->MoveNext() == E_SUCCESS)
474 pEvent = dynamic_cast<_NetworkManagerEvent*>(pEnum->GetCurrent());
477 pEventArg = new (std::nothrow)_NetworkManagerEventArg(networkStatus);
478 if (pEventArg != null)
480 pEvent->FireAsync(*pEventArg);
487 }} // Tizen::Telephony