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_NetworkSettingEvent.cpp
20 * @brief This is the implementation file for the _NetworkSettingEvent Class.
22 * This header file contains implementation of the _NetworkSettingEvent Class.
25 #include <unique_ptr.h>
26 #include <FBaseRtIEventListener.h>
27 #include <FBaseColArrayList.h>
28 #include <FBaseSysLog.h>
29 #include <FBaseColAllElementsDeleter.h>
30 #include <FTelNetworkInfo.h>
31 #include <FTelITelephonyNetworkSettingListener.h>
32 #include "FTel_NetworkInfoImpl.h"
33 #include "FTel_NetworkSettingEvent.h"
34 #include "FTel_NetworkSettingEventArg.h"
37 using namespace Tizen::Base::Collection;
39 namespace Tizen { namespace Telephony
42 ////////////////////////////////////////////////////////////////////////////
43 _NetworkSettingEvent::_NetworkSettingEvent(void)
47 _NetworkSettingEvent::~_NetworkSettingEvent(void)
52 _NetworkSettingEvent::Construct(void)
54 return _Event::Initialize();
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Operation : Protected
61 _NetworkSettingEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
65 const _NetworkSettingEventArg* pArg = dynamic_cast<const _NetworkSettingEventArg*>(&arg);
66 SysTryReturnVoidResult(NID_TEL, pArg != null, E_INVALID_ARG, "[%s] Invalid argument used. The arg is a null pointer.", GetErrorMessage(E_INVALID_ARG));
68 ITelephonyNetworkSettingListener* pNetworkSettingListener = dynamic_cast<ITelephonyNetworkSettingListener*>(&listener);
69 SysTryReturnVoidResult(NID_TEL, pNetworkSettingListener != null, E_INVALID_ARG,
70 "[%s] Invalid argument used. The result of a dynamic_cast operation is null for network setting listener", GetErrorMessage(E_INVALID_ARG));
73 switch(pArg->GetEventType())
75 case _NETWORK_EVENT_GET_SELECTION_MODE:
76 pNetworkSettingListener->OnTelephonyNetworkSelectionModeReceived(pArg->GetIsManual(), pArg->GetError());
77 break; // _NETWORK_EVENT_GET_SELECTION_MODE
79 case _NETWORK_EVENT_SELECT_NETWORK:
80 pNetworkSettingListener->OnTelephonyNetworkSelectionCompleted(pArg->GetError());
81 break; // _NETWORK_EVENT_SELECT_NETWORK
83 case _NETWORK_EVENT_SEARCH_COMPLETED:
85 ArrayList* pSrcNetworkInfoList = dynamic_cast<ArrayList*>(pArg->GetNetworkInfoList());
86 SysTryCatch(NID_TEL, pSrcNetworkInfoList != null, , E_SYSTEM, "[%s] A system error has occured. Failed on dynamic casting", GetErrorMessage(E_SYSTEM));
88 unique_ptr<ArrayList, AllElementsDeleter> pDescNetworkInfoList(new (std::nothrow) ArrayList());
89 SysTryReturnVoidResult(NID_TEL, pDescNetworkInfoList != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
91 r = pDescNetworkInfoList->Construct(pSrcNetworkInfoList->GetCount());
92 SysTryCatch(NID_TEL, r == E_SUCCESS, , r, "[%s] Failed to construct", GetErrorMessage(r));
94 for (int i = 0; i < pSrcNetworkInfoList->GetCount(); i++)
96 NetworkInfo* pTempInfo = dynamic_cast<NetworkInfo*>(pSrcNetworkInfoList->GetAt(i));
97 SysTryCatch(NID_TEL, pTempInfo != null, , E_SYSTEM, "[%s] A system error has occured. Failed on dynamic casting", GetErrorMessage(E_SYSTEM));
99 _NetworkInfoImpl* pTempInfoImpl = _NetworkInfoImpl::GetInstance(*pTempInfo);
101 NetworkInfo* pNetworkInfo = new (std::nothrow) NetworkInfo();
102 SysTryCatch(NID_TEL, pNetworkInfo != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
104 _NetworkInfoImpl* pNetworkInfoImpl = _NetworkInfoImpl::GetInstance(*pNetworkInfo);
106 *pNetworkInfoImpl = *pTempInfoImpl;
108 r = pDescNetworkInfoList->Add(*pNetworkInfo);
109 SysTryCatch(NID_TEL, r == E_SUCCESS, , r, "[%s] Failed to make NetworkInfo list", GetErrorMessage(r));
113 SysLog(NID_TEL,"The number of network info list is %d", pDescNetworkInfoList->GetCount());
115 for (int i = 0 ; i < pDescNetworkInfoList->GetCount() ; i++)
117 NetworkInfo* pNetworkInfo = dynamic_cast<NetworkInfo*>(pDescNetworkInfoList->GetAt(i));
118 SysTryCatch(NID_TEL, pNetworkInfo != null, , E_SYSTEM, "[%s] A system error has occured. Failed on dynamic casting", GetErrorMessage(E_SYSTEM));
119 SysLog(NID_TEL, "The cellid is %d, lac is %d, mcc is %d, mnc is %d, operator name is %ls, and plmn is %ls"
120 , pNetworkInfo->GetCellId(), pNetworkInfo->GetLac(), pNetworkInfo->GetMcc(), pNetworkInfo->GetMnc(), pNetworkInfo->GetOperatorName().GetPointer(), pNetworkInfo->GetPlmn().GetPointer());
123 pNetworkSettingListener->OnTelephonyNetworkSearchCompletedN(pDescNetworkInfoList.release(), pArg->GetError());
125 break; // _NETWORK_EVENT_SEARCH_COMPLETED
135 if (r != E_SUCCESS && r != E_OUT_OF_MEMORY)
139 pNetworkSettingListener->OnTelephonyNetworkSearchCompletedN(null, r);
142 } } // Tizen::Telephony