[DCM-1064] Fix the network status event issue.
[platform/framework/native/telephony.git] / src / FTel_NetworkSettingEvent.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 /**
19  * @file    FTel_NetworkSettingEvent.cpp
20  * @brief   This is the implementation file for the _NetworkSettingEvent Class.
21  *
22  * This header file contains implementation of the _NetworkSettingEvent Class.
23  */
24
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"
35
36 using namespace std;
37 using namespace Tizen::Base::Collection;
38
39 namespace Tizen { namespace Telephony
40 {
41
42 ////////////////////////////////////////////////////////////////////////////
43 _NetworkSettingEvent::_NetworkSettingEvent(void)
44 {
45 }
46
47 _NetworkSettingEvent::~_NetworkSettingEvent(void)
48 {
49 }
50
51 result
52 _NetworkSettingEvent::Construct(void)
53 {
54     return _Event::Initialize();
55 }
56
57 ////////////////////////////////////////////////////////////////////////////////
58 /// Operation : Protected
59
60 void
61 _NetworkSettingEvent::FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg)
62 {
63     result r = E_SUCCESS;
64
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));
67
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));
71
72
73     switch(pArg->GetEventType())
74     {
75     case _NETWORK_EVENT_GET_SELECTION_MODE:
76         pNetworkSettingListener->OnTelephonyNetworkSelectionModeReceived(pArg->GetIsManual(), pArg->GetError());
77         break; // _NETWORK_EVENT_GET_SELECTION_MODE
78
79     case _NETWORK_EVENT_SELECT_NETWORK:
80         pNetworkSettingListener->OnTelephonyNetworkSelectionCompleted(pArg->GetError());
81         break; // _NETWORK_EVENT_SELECT_NETWORK
82
83     case _NETWORK_EVENT_SEARCH_COMPLETED:
84                 {
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));
87
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));
90
91                         r = pDescNetworkInfoList->Construct(pSrcNetworkInfoList->GetCount());
92                         SysTryCatch(NID_TEL, r == E_SUCCESS, , r, "[%s] Failed to construct", GetErrorMessage(r));
93
94                         for (int i = 0; i < pSrcNetworkInfoList->GetCount(); i++)
95                         {
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));
98
99                                 _NetworkInfoImpl* pTempInfoImpl = _NetworkInfoImpl::GetInstance(*pTempInfo);
100
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));
103
104                                 _NetworkInfoImpl* pNetworkInfoImpl = _NetworkInfoImpl::GetInstance(*pNetworkInfo);
105
106                                 *pNetworkInfoImpl = *pTempInfoImpl;
107
108                                 r = pDescNetworkInfoList->Add(*pNetworkInfo);
109                                 SysTryCatch(NID_TEL, r == E_SUCCESS, , r, "[%s] Failed to make NetworkInfo list", GetErrorMessage(r));
110                         }
111
112                         // Total Count
113                         SysLog(NID_TEL,"The number of network info list is %d", pDescNetworkInfoList->GetCount());
114
115                         for (int i = 0 ; i < pDescNetworkInfoList->GetCount() ; i++)
116                         {
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());
121                         }
122
123                         pNetworkSettingListener->OnTelephonyNetworkSearchCompletedN(pDescNetworkInfoList.release(), pArg->GetError());
124                 }
125         break; // _NETWORK_EVENT_SEARCH_COMPLETED
126
127     default:
128         break; // default
129     }
130
131     return;
132
133 CATCH:
134
135     if (r != E_SUCCESS && r != E_OUT_OF_MEMORY)
136     {
137         r = E_SYSTEM;
138     }
139     pNetworkSettingListener->OnTelephonyNetworkSearchCompletedN(null, r);
140 }
141
142 } } // Tizen::Telephony