Synchronized tizen_2.1 branch with master
[platform/framework/native/telephony.git] / src / FTelNetworkInfo.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        FTelNetworkInfo.cpp
19  * @brief       This is the implementation file for NetworkInfo class.
20  */
21
22 #include <FTelNetworkInfo.h>
23 #include <FBaseSysLog.h>
24 #include <FSec_AccessController.h>
25 #include <FSys_SystemInfoImpl.h>
26 #include "FTel_NetworkInfoImpl.h"
27
28
29 using namespace Tizen::Base;
30 using namespace Tizen::Security;
31 using namespace Tizen::System;
32
33
34 namespace Tizen { namespace Telephony
35 {
36
37 NetworkInfo::NetworkInfo(void)
38         : __pNetworkInfoImpl(null)
39 {
40         __pNetworkInfoImpl = new (std::nothrow) _NetworkInfoImpl();
41         SysTryReturnVoidResult(NID_TEL, __pNetworkInfoImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
42 }
43
44 NetworkInfo::NetworkInfo(const NetworkInfo& value)
45 {
46         __pNetworkInfoImpl = new (std::nothrow) _NetworkInfoImpl(*(value.__pNetworkInfoImpl));
47         SysTryReturnVoidResult(NID_TEL, __pNetworkInfoImpl != null, E_OUT_OF_MEMORY, "Memory allocation failed.");
48 }
49
50 NetworkInfo::~NetworkInfo(void)
51 {
52         delete __pNetworkInfoImpl;
53 }
54
55 NetworkInfo&
56 NetworkInfo::operator=(const NetworkInfo& rhs)
57 {
58         if (this != &rhs)
59     {
60         *__pNetworkInfoImpl = *(rhs.__pNetworkInfoImpl);
61         }
62
63         return *this;
64 }
65
66 int
67 NetworkInfo::GetMnc(void) const
68 {
69         ClearLastResult();
70
71         int mnc = -1;
72         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
73
74         SysTryReturn(NID_TEL, r == E_SUCCESS, mnc, E_PRIVILEGE_DENIED,
75             "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
76
77         mnc = __pNetworkInfoImpl->GetMnc();
78
79         return mnc;
80 }
81
82 int
83 NetworkInfo::GetMcc(void) const
84 {
85         ClearLastResult();
86
87         int mcc = -1;
88         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
89
90         SysTryReturn(NID_TEL, r == E_SUCCESS, mcc, E_PRIVILEGE_DENIED,
91                     "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
92
93         mcc = __pNetworkInfoImpl->GetMcc();
94
95         return mcc;
96 }
97
98 String
99 NetworkInfo::GetPlmn(void) const
100 {
101         ClearLastResult();
102
103         String plmn;
104         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
105
106         SysTryReturn(NID_TEL, r == E_SUCCESS, plmn, E_PRIVILEGE_DENIED,
107                     "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
108
109         plmn = __pNetworkInfoImpl->GetPlmn();
110
111         return plmn;
112 }
113
114 int
115 NetworkInfo::GetCellId(void) const
116 {
117         ClearLastResult();
118
119         int cellId = -1;
120         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
121
122         SysTryReturn(NID_TEL, r == E_SUCCESS, cellId, E_PRIVILEGE_DENIED,
123                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
124
125         cellId = __pNetworkInfoImpl->GetCellId();
126
127         return cellId;
128 }
129
130 int
131 NetworkInfo::GetLac(void) const
132 {
133         ClearLastResult();
134
135         int lac = -1;
136         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
137
138         SysTryReturn(NID_TEL, r == E_SUCCESS, lac, E_PRIVILEGE_DENIED,
139                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
140
141         lac = __pNetworkInfoImpl->GetLac();
142
143         return lac;
144 }
145
146 String
147 NetworkInfo::GetOperatorName(void) const
148 {
149     ClearLastResult();
150
151     String operatorName;
152     result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
153
154     SysTryReturn(NID_TEL, r == E_SUCCESS, operatorName, E_PRIVILEGE_DENIED,
155                 "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
156
157     operatorName = __pNetworkInfoImpl->GetOperatorName();
158
159     return operatorName;
160 }
161
162 bool
163 NetworkInfo::Equals(const Object& obj) const
164 {
165         const NetworkInfo* pOther = dynamic_cast<const NetworkInfo*>(&obj);
166
167         if (pOther == null)
168         {
169         return false;
170         }
171
172         if (pOther == this)
173         {
174         return true;
175         }
176
177         return __pNetworkInfoImpl->Equals(*pOther->__pNetworkInfoImpl);
178 }
179
180 int
181 NetworkInfo::GetHashCode(void) const
182 {
183         return __pNetworkInfoImpl->GetHashCode();
184 }
185
186 int
187 NetworkInfo::GetRssi(void)
188 {
189         static const wchar_t _TELEPHONY[] = L"http://tizen.org/feature/network.telephony";
190
191         ClearLastResult();
192
193         int rssi = -1;
194         result r = _AccessController::CheckUserPrivilege(_PRV_SYSTEMINFO, _PRV_TELEPHONY);
195         SysTryReturn(NID_TEL, r == E_SUCCESS, rssi, E_PRIVILEGE_DENIED,
196                         "[%s] The application does not have the privilege to call this method.", GetErrorMessage(E_PRIVILEGE_DENIED));
197
198         bool isTelephonySupported = false;
199
200     r = _SystemInfoImpl::GetSysInfo(_TELEPHONY, isTelephonySupported);
201     SysTryReturn(NID_TEL, r == E_SUCCESS && isTelephonySupported, rssi, E_UNSUPPORTED_OPERATION,
202                 "[%s] Telephony is not supported.", GetErrorMessage(E_UNSUPPORTED_OPERATION));
203
204         rssi = _NetworkInfoImpl::GetRssi();
205
206         r = GetLastResult();
207
208         SysTryReturn(NID_TEL, r == E_SUCCESS, rssi, r, "[%s] Propagating.", GetErrorMessage(r));
209
210         return rssi;
211 }
212
213 }} // Tizen::Telephony