Tizen 2.1 base
[platform/framework/native/telephony.git] / src / FTel_NetworkInfoImpl.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        FTel_NetworkInfoImpl.cpp
19  * @brief       This is the implementation file for _NetworkInfoImpl class.
20  */
21
22 #include <telephony_network.h>
23 #include <FTelNetworkInfo.h>
24 #include <FBaseErrors.h>
25 #include <FBaseSysLog.h>
26 #include "FTel_NetworkInfoImpl.h"
27
28 using namespace Tizen::Base;
29
30 namespace Tizen { namespace Telephony
31 {
32
33
34 _NetworkInfoImpl::_NetworkInfoImpl(void)
35         : __cellId(-1)
36         , __lac(-1)
37     , __mcc(-1)
38     , __mnc(-1)
39     , __networkType(_NETWORK_TYPE_UNDEFINED)
40 {
41 }
42
43 _NetworkInfoImpl::_NetworkInfoImpl(const _NetworkInfoImpl& value)
44     : __cellId(value.__cellId)
45     , __lac(value.__lac)
46     , __mcc(value.__mcc)
47     , __mnc(value.__mnc)
48     , __plmn(value.__plmn)
49     , __operatorName(value.__operatorName)
50     , __networkType(value.__networkType)
51 {
52 }
53
54 _NetworkInfoImpl::~_NetworkInfoImpl(void)
55 {
56 }
57
58 int
59 _NetworkInfoImpl::GetCellId(void) const
60 {
61     return __cellId;
62 }
63
64 int
65 _NetworkInfoImpl::GetLac(void) const
66 {
67     return __lac;
68 }
69
70 int
71 _NetworkInfoImpl::GetMcc(void) const
72 {
73     return __mcc;
74 }
75
76 int
77 _NetworkInfoImpl::GetMnc(void) const
78 {
79     return __mnc;
80 }
81 String
82 _NetworkInfoImpl::GetPlmn(void) const
83 {
84         return __plmn;
85 }
86
87 String
88 _NetworkInfoImpl::GetOperatorName(void) const
89 {
90     return __operatorName;
91 }
92
93 _NetworkType
94 _NetworkInfoImpl::GetNetworkType(void) const
95 {
96     return __networkType;
97 }
98
99 bool
100 _NetworkInfoImpl::Equals(const Object& obj) const
101 {
102         const _NetworkInfoImpl* pOther = static_cast<const _NetworkInfoImpl*>(&obj);
103
104     if (pOther == null
105         || __cellId != pOther->__cellId
106         || __lac != pOther->__lac
107         || __mcc != pOther->__mcc
108         || __mnc != pOther->__mnc
109         || __plmn != pOther->__plmn
110         || __operatorName != pOther->__operatorName
111         || __networkType != pOther->__networkType)
112     {
113         return false;
114     }
115
116         return true;
117 }
118
119 int
120 _NetworkInfoImpl::GetHashCode(void) const
121 {
122         static const int _PRIME_NUMBER = 31;
123         int hashCode = 0;
124
125     hashCode = _PRIME_NUMBER * __mcc;
126     hashCode = (_PRIME_NUMBER * hashCode) ^ __mnc;
127     hashCode = (_PRIME_NUMBER * hashCode) ^ __cellId;
128     hashCode = (_PRIME_NUMBER * hashCode) ^ __lac;
129     hashCode = (_PRIME_NUMBER * hashCode) ^ __plmn.GetHashCode();
130     hashCode = (_PRIME_NUMBER * hashCode) ^ __operatorName.GetHashCode();
131     hashCode = (_PRIME_NUMBER * hashCode) ^ __networkType;
132
133         return hashCode;
134 }
135 int
136 _NetworkInfoImpl::GetRssi(void)
137 {
138         static const int rssiArray[] = {10, 25, 45, 60, 75, 75, 90};
139         network_info_rssi_e rssi;
140         int err = NETWORK_INFO_ERROR_NONE;
141
142         err = network_info_get_rssi(&rssi);
143         SysLog(NID_TEL, "network_info_get_rssi() returned %d value and the rssi value is %d", err, rssi);
144         SysTryReturn(NID_TEL, err == NETWORK_INFO_ERROR_NONE, 0, E_SYSTEM,
145                 "[%s] A system error has occurred. Failed to get the received signal strength indication.", GetErrorMessage(E_SYSTEM));
146
147         return rssiArray[rssi];
148 }
149
150 void
151 _NetworkInfoImpl::SetCellId(int cellId)
152 {
153         __cellId = cellId;
154 }
155
156 void
157 _NetworkInfoImpl::SetLac(int lac)
158 {
159         __lac = lac;
160 }
161
162 void
163 _NetworkInfoImpl::SetMcc(int mcc)
164 {
165     __mcc = mcc;
166 }
167
168 void
169 _NetworkInfoImpl::SetMnc(int mnc)
170 {
171     __mnc = mnc;
172 }
173
174 void
175 _NetworkInfoImpl::SetPlmn(const String& plmn)
176 {
177     __plmn = plmn;
178 }
179
180 void
181 _NetworkInfoImpl::SetOperatorName(const String& operatorName)
182 {
183     __operatorName = operatorName;
184 }
185
186 void
187 _NetworkInfoImpl::SetNetworkType(_NetworkType networkType)
188 {
189     __networkType = networkType;
190 }
191
192
193 _NetworkInfoImpl&
194 _NetworkInfoImpl::operator=(const _NetworkInfoImpl& rhs)
195 {
196     if (this != &rhs)
197     {
198         __cellId = rhs.__cellId;
199         __lac = rhs.__lac;
200         __mcc = rhs.__mcc;
201         __mnc = rhs.__mnc;
202         __plmn = rhs.__plmn;
203         __operatorName = rhs.__operatorName;
204         __networkType = rhs.__networkType;
205
206     }
207     return *this;
208 }
209
210 _NetworkInfoImpl*
211 _NetworkInfoImpl::GetInstance(NetworkInfo& networkInfo)
212 {
213         return networkInfo.__pNetworkInfoImpl;
214 }
215
216 const _NetworkInfoImpl*
217 _NetworkInfoImpl::GetInstance(const NetworkInfo& networkInfo)
218 {
219         return networkInfo.__pNetworkInfoImpl;
220 }
221
222 }} // Tizen::Telephony