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 , __locationMethod("")
45 , __satelliteInformation("")
46 , __isLocationValid(false)
51 _LocationImpl::_LocationImpl(const _LocationImpl& rhs)
52 : __coordinate(rhs.__coordinate)
53 , __speed(rhs.__speed)
54 , __course(rhs.__course)
55 , __horizontalAccuracy(rhs.__horizontalAccuracy)
56 , __verticalAccuracy(rhs.__verticalAccuracy)
57 , __timestamp(rhs.__timestamp)
58 , __locationMethod(rhs.__locationMethod)
59 , __satelliteInformation(rhs.__satelliteInformation)
60 , __isLocationValid(rhs.__isLocationValid)
61 , __isDenied(rhs.__isDenied)
65 _LocationImpl::~_LocationImpl(void)
70 _LocationImpl::Equals(const _LocationImpl& rhs) const
76 _LocationImpl::GetHashCode(void) const
80 hashCode += __coordinate.GetHashCode();
81 hashCode += Double::GetHashCode(__speed) * 37;
82 hashCode += Double::GetHashCode(__course) * 37;
83 hashCode += Double::GetHashCode(__horizontalAccuracy) * 37;
84 hashCode += Double::GetHashCode(__verticalAccuracy) * 37;
85 hashCode += __locationMethod.GetHashCode();
86 hashCode += __satelliteInformation.GetHashCode();
87 hashCode *= (__isLocationValid ? 37 : 17);
98 _LocationImpl::GetTimestamp(void) const
100 TimeSpan timespan(__timestamp);
103 dateTime.SetValue(1970, 1, 1);
104 dateTime.Add(timespan);
106 SysLog(NID_LOC, "The location timeStamp is (%ls)", dateTime.ToString().GetPointer());
112 _LocationImpl::GetExtraInfo(const Tizen::Base::String& key) const
114 String reqValue = L"";
116 if (key.Equals(L"location_method", true))
118 reqValue = __locationMethod;
120 else if (key.Equals(L"satellite", true))
122 reqValue = __satelliteInformation;
125 SysLog(NID_LOC, "Requested information is '%ls' for the key '%ls'.", reqValue.GetPointer(), key.GetPointer());
131 _LocationImpl::GetInstance(Location& obj)
137 _LocationImpl::GetInstance(const Location& obj)
143 _LocationImpl::GetLocationInstanceN(void)
145 Location* pLoc = new (std::nothrow) Location();
146 SysTryReturn(NID_LOC, pLoc != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
151 _LocationImpl::GetLocationInstance(void)
159 _LocationImpl::SetCoordinates(const Coordinates& coordinate)
161 result r = E_SUCCESS;
163 r = __coordinate.Set(coordinate.GetLatitude(), coordinate.GetLongitude(), coordinate.GetAltitude());
164 SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Setting the latitude/longitude value failed.", GetErrorMessage(r));
170 _LocationImpl::SetExtraInfo(const Tizen::Base::String& key, const Tizen::Base::String& value)
172 if (key.Equals(L"location_method", true))
174 __locationMethod = value;
176 else if (key.Equals(L"satellite", true))
178 __satelliteInformation = value;
183 _LocationImpl::operator =(const _LocationImpl& rhs)
190 __coordinate = rhs.__coordinate;
191 __speed = rhs.__speed;
192 __course = rhs.__course;
193 __horizontalAccuracy = rhs.__horizontalAccuracy;
194 __verticalAccuracy = rhs.__verticalAccuracy;
195 __timestamp = rhs.__timestamp;
196 __locationMethod = rhs.__locationMethod;
197 __satelliteInformation = rhs.__satelliteInformation;
198 __isLocationValid = rhs.__isLocationValid;
204 _LocationImpl::operator ==(const _LocationImpl& rhs) const
207 if (!__coordinate.Equals(rhs.__coordinate))
212 if (__timestamp != rhs.__timestamp)
217 if (__locationMethod != rhs.__locationMethod)
222 if (!__satelliteInformation.Equals(rhs.__satelliteInformation))
227 if (__isLocationValid != rhs.__isLocationValid)
232 bool speedCheck = false;
233 bool courseCheck = false;
234 bool horAccCheck = false;
235 bool verAccCheck = false;
237 if (Double::IsNaN(__speed) || Double::IsNaN(rhs.__speed))
239 if (Double::IsNaN(__speed) && Double::IsNaN(rhs.__speed))
244 else if (Double::Compare(__speed, rhs.__speed) == 0)
249 if (Double::IsNaN(__course) || Double::IsNaN(rhs.__course))
251 if (Double::IsNaN(__course) && Double::IsNaN(rhs.__course))
256 else if (Double::Compare(__course, rhs.__course) == 0)
261 if (Double::IsNaN(__horizontalAccuracy) || Double::IsNaN(rhs.__horizontalAccuracy))
263 if (Double::IsNaN(__horizontalAccuracy) && Double::IsNaN(rhs.__horizontalAccuracy))
268 else if (Double::Compare(__horizontalAccuracy, rhs.__horizontalAccuracy) == 0)
273 if (Double::IsNaN(__verticalAccuracy) || Double::IsNaN(rhs.__verticalAccuracy))
275 if (Double::IsNaN(__verticalAccuracy) && Double::IsNaN(rhs.__verticalAccuracy))
280 else if (Double::Compare(__verticalAccuracy, rhs.__verticalAccuracy) == 0)
285 return (speedCheck && courseCheck && horAccCheck && verAccCheck);