// // 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. // /** * @file FLocLocationProvider.cpp * @brief This is the implementation file for the %LocationProvider class. * * This header file contains the definitions of the %LocationProvider class. */ #include #include #include #include #include #include "FLoc_LocationImpl.h" #include "FLoc_LocationProviderImpl.h" using namespace Tizen::Security; namespace Tizen { namespace Locations { LocationProvider::LocationProvider(void) : Tizen::Base::Object() , __pImpl(null) { } LocationProvider::~LocationProvider(void) { delete __pImpl; } result LocationProvider::Construct(const LocationCriteria& criteria, ILocationProviderListener& listener) { SysAssertf(__pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class."); __pImpl = new (std::nothrow) _LocationProviderImpl(); SysTryReturnResult(NID_LOC, __pImpl, E_OUT_OF_MEMORY, "Memory allocation failed."); result r = __pImpl->Construct(criteria, listener); SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to construct location Provider.", GetErrorMessage(r)); return E_SUCCESS; CATCH: delete __pImpl; __pImpl = null; return r; } result LocationProvider::StartLocationUpdatesByInterval(int interval) { result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION); r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "The application is not permitted to call this method."); SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); r = __pImpl->StartLocationUpdatesByInterval(interval); SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by interval.", GetErrorMessage(r)); return E_SUCCESS; } result LocationProvider::StartLocationUpdatesByDistance(double distance) { result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION); r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "The application is not permitted to call this method."); SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); r = __pImpl->StartLocationUpdatesByDistance(distance); SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by distance.", GetErrorMessage(r)); return E_SUCCESS; } result LocationProvider::StopLocationUpdates(void) { SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); result r = __pImpl->StopLocationUpdates(); SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to stop the location updates.", GetErrorMessage(r)); return E_SUCCESS; } result LocationProvider::KeepLocationUpdateAwake(bool enable) { result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION); r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "The application is not permitted to call this method."); r = _AccessController::CheckUserPrivilege(_PRV_POWER); SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."); SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); __pImpl->KeepLocationUpdateAwake(enable); return E_SUCCESS; } result LocationProvider::AddMonitoringRegion(const Coordinates& regionCenter, double radius, RegionId& regionId) { result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION); r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "The application is not permitted to call this method."); r = _AccessController::CheckUserPrivilege(_PRV_POWER); SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method."); SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); r = __pImpl->AddMonitoringRegion(regionCenter, radius, regionId); SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to add monitoring region.", GetErrorMessage(r)); return E_SUCCESS; } result LocationProvider::RemoveMonitoringRegion(RegionId regionId) { SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); result r = __pImpl->RemoveMonitoringRegion(regionId); SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to remove monitoring region with Id (%d).", GetErrorMessage(r), regionId); return E_SUCCESS; } void LocationProvider::RemoveAllMonitoringRegions(void) { SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); return __pImpl->RemoveAllMonitoringRegions(); } LocationServiceStatus LocationProvider::GetLocationUpdateStatus(void) const { SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); return __pImpl->GetLocationUpdateStatus(); } LocationServiceStatus LocationProvider::GetRegionMonitoringStatus(void) const { SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); return __pImpl->GetRegionMonitoringStatus(); } LocationAccuracy LocationProvider::GetCurrentAccuracy(void) const { SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use."); return __pImpl->GetCurrentAccuracy(); } Location LocationProvider::GetLocation(const LocationCriteria& criteria) { result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION); r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r)); return _LocationProviderImpl::GetLocation(criteria); } Location LocationProvider::GetLastKnownLocation(void) { result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION); r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED); SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r)); return _LocationProviderImpl::GetLastKnownLocation(); } }}