// // Open Service Platform // Copyright (c) 2012 Samsung Electronics Co., Ltd. // // Licensed under the Apache License, Version 2.0 (the License); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // #include #include #include #include #include #include #include #include #include #include "FLoc_LocationImpl.h" #include "FLoc_Types.h" using namespace Tizen::Base; using namespace Tizen::Base::Collection; using namespace Tizen::Base::Utility; using namespace std; namespace Tizen { namespace Locations { _LocationImpl::_LocationImpl(void) : __speed(Tizen::Locations::NaN) , __course(Tizen::Locations::NaN) , __horizontalAccuracy(Tizen::Locations::NaN) , __verticalAccuracy(Tizen::Locations::NaN) , __timestamp(0) , __isLocationValid(false) , __isDenied(false) { } _LocationImpl::_LocationImpl(const _LocationImpl& rhs) : __coordinate(rhs.__coordinate) , __speed(rhs.__speed) , __course(rhs.__course) , __horizontalAccuracy(rhs.__horizontalAccuracy) , __verticalAccuracy(rhs.__verticalAccuracy) , __timestamp(rhs.__timestamp) , __locationMethod(rhs.__locationMethod) , __satelliteInformation(rhs.__satelliteInformation) , __isLocationValid(rhs.__isLocationValid) , __isDenied(rhs.__isDenied) { } _LocationImpl::~_LocationImpl(void) { } bool _LocationImpl::Equals(const _LocationImpl& rhs) const { return *this == rhs; } int _LocationImpl::GetHashCode(void) const { int hashCode = 0; hashCode += __coordinate.GetHashCode(); hashCode += Double::GetHashCode(__speed) * 37; hashCode += Double::GetHashCode(__course) * 37; hashCode += Double::GetHashCode(__horizontalAccuracy) * 37; hashCode += Double::GetHashCode(__verticalAccuracy) * 37; hashCode += __locationMethod.GetHashCode(); hashCode += __satelliteInformation.GetHashCode(); hashCode *= (__isLocationValid ? 37 : 17); if (hashCode < 0) { hashCode *= (-1); } return hashCode; } DateTime _LocationImpl::GetTimestamp(void) const { TimeSpan timespan(__timestamp); DateTime dateTime; dateTime.SetValue(1970, 1, 1); dateTime.Add(timespan); SysLog(NID_LOC, "The location timeStamp is (%ls)", dateTime.ToString().GetPointer()); return dateTime; } Tizen::Base::String _LocationImpl::GetExtraInfo(const Tizen::Base::String& key) const { String reqValue = L""; if (key.Equals(L"location_method", true)) { reqValue = __locationMethod; } else if (key.Equals(L"satellite", true)) { reqValue = __satelliteInformation; } SysLog(NID_LOC, "Requested information is '%ls' for the key '%ls'.", reqValue.GetPointer(), key.GetPointer()); return reqValue; } _LocationImpl* _LocationImpl::GetInstance(Location& obj) { return obj.__pImpl; } const _LocationImpl* _LocationImpl::GetInstance(const Location& obj) { return obj.__pImpl; } Location* _LocationImpl::GetLocationInstanceN(void) { Location* pLoc = new (std::nothrow) Location(); SysTryReturn(NID_LOC, pLoc != null, null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY)); return pLoc; } Location _LocationImpl::GetLocationInstance(void) { Location invalidLoc; return invalidLoc; } result _LocationImpl::SetCoordinates(const Coordinates& coordinate) { result r = E_SUCCESS; r = __coordinate.Set(coordinate.GetLatitude(), coordinate.GetLongitude(), coordinate.GetAltitude()); SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Setting the latitude/longitude value failed.", GetErrorMessage(r)); return E_SUCCESS; } void _LocationImpl::SetExtraInfo(const Tizen::Base::String& key, const Tizen::Base::String& value) { if (key.Equals(L"location_method", true)) { __locationMethod = value; } else if (key.Equals(L"satellite", true)) { __satelliteInformation = value; } } _LocationImpl& _LocationImpl::operator =(const _LocationImpl& rhs) { if (this == &rhs) { return *this; } __coordinate = rhs.__coordinate; __speed = rhs.__speed; __course = rhs.__course; __horizontalAccuracy = rhs.__horizontalAccuracy; __verticalAccuracy = rhs.__verticalAccuracy; __timestamp = rhs.__timestamp; __locationMethod = rhs.__locationMethod; __satelliteInformation = rhs.__satelliteInformation; __isLocationValid = rhs.__isLocationValid; return *this; } bool _LocationImpl::operator ==(const _LocationImpl& rhs) const { if (!__coordinate.Equals(rhs.__coordinate)) { return false; } if (__timestamp != rhs.__timestamp) { return false; } if (__locationMethod != rhs.__locationMethod) { return false; } if (!__satelliteInformation.Equals(rhs.__satelliteInformation)) { return false; } if (__isLocationValid != rhs.__isLocationValid) { return false; } bool speedCheck = false; bool courseCheck = false; bool horAccCheck = false; bool verAccCheck = false; if (Double::IsNaN(__speed) || Double::IsNaN(rhs.__speed)) { if (Double::IsNaN(__speed) && Double::IsNaN(rhs.__speed)) { speedCheck = true; } } else if (Double::Compare(__speed, rhs.__speed) == 0) { speedCheck = true; } if (Double::IsNaN(__course) || Double::IsNaN(rhs.__course)) { if (Double::IsNaN(__course) && Double::IsNaN(rhs.__course)) { courseCheck = true; } } else if (Double::Compare(__course, rhs.__course) == 0) { courseCheck = true; } if (Double::IsNaN(__horizontalAccuracy) || Double::IsNaN(rhs.__horizontalAccuracy)) { if (Double::IsNaN(__horizontalAccuracy) && Double::IsNaN(rhs.__horizontalAccuracy)) { horAccCheck = true; } } else if (Double::Compare(__horizontalAccuracy, rhs.__horizontalAccuracy) == 0) { horAccCheck = true; } if (Double::IsNaN(__verticalAccuracy) || Double::IsNaN(rhs.__verticalAccuracy)) { if (Double::IsNaN(__verticalAccuracy) && Double::IsNaN(rhs.__verticalAccuracy)) { verAccCheck = true; } } else if (Double::Compare(__verticalAccuracy, rhs.__verticalAccuracy) == 0) { verAccCheck = true; } return (speedCheck && courseCheck && horAccCheck && verAccCheck); } }}