2 // Open Service Platform
3 // Copyright (c) 2012 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 #include <unique_ptr.h>
20 #include <FBaseColArrayList.h>
21 #include <FBaseSysLog.h>
22 #include <FBaseDouble.h>
23 #include <FBaseDouble.h>
24 #include <FBaseUtilMath.h>
25 #include <FLocCoordinates.h>
26 #include <FLocLocation.h>
27 #include "FLoc_LocationImpl.h"
28 #include "FLoc_Types.h"
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Base::Utility;
35 namespace Tizen { namespace Locations
38 _LocationImpl::_LocationImpl(void)
39 : __speed(Tizen::Locations::NaN)
40 , __course(Tizen::Locations::NaN)
41 , __horizontalAccuracy(Tizen::Locations::NaN)
42 , __verticalAccuracy(Tizen::Locations::NaN)
44 , __isLocationValid(false)
49 _LocationImpl::_LocationImpl(const _LocationImpl& rhs)
50 : __coordinate(rhs.__coordinate)
51 , __speed(rhs.__speed)
52 , __course(rhs.__course)
53 , __horizontalAccuracy(rhs.__horizontalAccuracy)
54 , __verticalAccuracy(rhs.__verticalAccuracy)
55 , __timestamp(rhs.__timestamp)
56 , __locationMethod(rhs.__locationMethod)
57 , __satelliteInformation(rhs.__satelliteInformation)
58 , __isLocationValid(rhs.__isLocationValid)
59 , __isDenied(rhs.__isDenied)
63 _LocationImpl::~_LocationImpl(void)
68 _LocationImpl::Equals(const _LocationImpl& rhs) const
74 _LocationImpl::GetHashCode(void) const
78 hashCode += __coordinate.GetHashCode();
79 hashCode += Double::GetHashCode(__speed) * 37;
80 hashCode += Double::GetHashCode(__course) * 37;
81 hashCode += Double::GetHashCode(__horizontalAccuracy) * 37;
82 hashCode += Double::GetHashCode(__verticalAccuracy) * 37;
83 hashCode += __locationMethod.GetHashCode();
84 hashCode += __satelliteInformation.GetHashCode();
85 hashCode *= (__isLocationValid ? 37 : 17);
95 _LocationImpl::GetTimestamp(void) const
97 TimeSpan timespan(__timestamp);
100 dateTime.SetValue(1970, 1, 1);
101 dateTime.Add(timespan);
102 SysSecureLog(NID_LOC, "The location timeStamp is (%ls)", dateTime.ToString().GetPointer());
107 _LocationImpl::GetExtraInfo(const Tizen::Base::String& key) const
109 String reqValue = L"";
111 if (key.Equals(L"location_method", true))
113 reqValue = __locationMethod;
115 else if (key.Equals(L"satellite", true))
117 reqValue = __satelliteInformation;
120 SysLog(NID_LOC, "Requested information is '%ls' for the key '%ls'.", reqValue.GetPointer(), key.GetPointer());
125 _LocationImpl::GetInstance(Location& obj)
131 _LocationImpl::GetInstance(const Location& obj)
137 _LocationImpl::GetLocationInstanceN(void)
139 Location* pLoc = new (std::nothrow) Location();
140 SysTryReturn(NID_LOC, pLoc != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
145 _LocationImpl::GetLocationInstance(void)
152 _LocationImpl::SetCoordinates(const Coordinates& coordinate)
154 result r = __coordinate.Set(coordinate.GetLatitude(), coordinate.GetLongitude(), coordinate.GetAltitude());
155 SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Setting the latitude/longitude value failed.", GetErrorMessage(r));
160 _LocationImpl::SetExtraInfo(const Tizen::Base::String& key, const Tizen::Base::String& value)
162 if (key.Equals(L"location_method", true))
164 __locationMethod = value;
166 else if (key.Equals(L"satellite", true))
168 __satelliteInformation = value;
173 _LocationImpl::operator =(const _LocationImpl& rhs)
180 __coordinate = rhs.__coordinate;
181 __speed = rhs.__speed;
182 __course = rhs.__course;
183 __horizontalAccuracy = rhs.__horizontalAccuracy;
184 __verticalAccuracy = rhs.__verticalAccuracy;
185 __timestamp = rhs.__timestamp;
186 __locationMethod = rhs.__locationMethod;
187 __satelliteInformation = rhs.__satelliteInformation;
188 __isLocationValid = rhs.__isLocationValid;
194 _LocationImpl::operator ==(const _LocationImpl& rhs) const
197 if (!__coordinate.Equals(rhs.__coordinate))
201 if (__timestamp != rhs.__timestamp)
205 if (__locationMethod != rhs.__locationMethod)
209 if (!__satelliteInformation.Equals(rhs.__satelliteInformation))
213 if (__isLocationValid != rhs.__isLocationValid)
218 bool speedCheck = false;
219 bool courseCheck = false;
220 bool horAccCheck = false;
221 bool verAccCheck = false;
223 if (Double::IsNaN(__speed) || Double::IsNaN(rhs.__speed))
225 if (Double::IsNaN(__speed) && Double::IsNaN(rhs.__speed))
230 else if (Double::Compare(__speed, rhs.__speed) == 0)
235 if (Double::IsNaN(__course) || Double::IsNaN(rhs.__course))
237 if (Double::IsNaN(__course) && Double::IsNaN(rhs.__course))
242 else if (Double::Compare(__course, rhs.__course) == 0)
247 if (Double::IsNaN(__horizontalAccuracy) || Double::IsNaN(rhs.__horizontalAccuracy))
249 if (Double::IsNaN(__horizontalAccuracy) && Double::IsNaN(rhs.__horizontalAccuracy))
254 else if (Double::Compare(__horizontalAccuracy, rhs.__horizontalAccuracy) == 0)
259 if (Double::IsNaN(__verticalAccuracy) || Double::IsNaN(rhs.__verticalAccuracy))
261 if (Double::IsNaN(__verticalAccuracy) && Double::IsNaN(rhs.__verticalAccuracy))
266 else if (Double::Compare(__verticalAccuracy, rhs.__verticalAccuracy) == 0)
270 return (speedCheck && courseCheck && horAccCheck && verAccCheck);