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