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 * @file FLocLocationProvider.cpp
20 * @brief This is the implementation file for the %LocationProvider class.
22 * This header file contains the definitions of the %LocationProvider class.
25 #include <FBaseSysLog.h>
26 #include <FLocLocation.h>
27 #include <FLocLocationProvider.h>
28 #include <FSecAccessController.h>
29 #include <FSec_AccessControlTypes.h>
30 #include "FLoc_LocationImpl.h"
31 #include "FLoc_LocationProviderImpl.h"
33 using namespace Tizen::Security;
35 namespace Tizen { namespace Locations
38 LocationProvider::LocationProvider(void)
39 : Tizen::Base::Object()
44 LocationProvider::~LocationProvider(void)
50 LocationProvider::Construct(const LocationCriteria& criteria, ILocationProviderListener& listener)
52 SysAssertf(__pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
54 __pImpl = new (std::nothrow) _LocationProviderImpl();
55 SysTryReturnResult(NID_LOC, __pImpl, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
57 result r = __pImpl->Construct(criteria, listener);
58 SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to construct location Provider.", GetErrorMessage(r));
69 LocationProvider::StartLocationUpdatesByInterval(int interval)
71 result r = AccessController::CheckPrivilege(_PRV_LOCATION);
72 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.");
74 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
76 r = __pImpl->StartLocationUpdatesByInterval(interval);
77 SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by interval.", GetErrorMessage(r));
83 LocationProvider::StartLocationUpdatesByDistance(double distance)
85 result r = AccessController::CheckPrivilege(_PRV_LOCATION);
86 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.");
88 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
90 r = __pImpl->StartLocationUpdatesByDistance(distance);
91 SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by distance.", GetErrorMessage(r));
97 LocationProvider::StopLocationUpdates(void)
99 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
101 result r = __pImpl->StopLocationUpdates();
102 SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to stop the location updates.", GetErrorMessage(r));
108 LocationProvider::KeepLocationUpdateAwake(bool enable)
110 result r = AccessController::CheckPrivilege(_PRV_LOCATION);
111 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.");
113 r = AccessController::CheckPrivilege(_PRV_POWER);
114 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.");
116 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
118 __pImpl->KeepLocationUpdateAwake(enable);
123 LocationProvider::AddMonitoringRegion(const Coordinates& regionCenter, double radius, RegionId& regionId)
125 result r = AccessController::CheckPrivilege(_PRV_LOCATION);
126 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.");
128 r = AccessController::CheckPrivilege(_PRV_POWER);
129 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.");
131 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
133 r = __pImpl->AddMonitoringRegion(regionCenter, radius, regionId);
134 SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to add monitoring region.", GetErrorMessage(r));
140 LocationProvider::RemoveMonitoringRegion(RegionId regionId)
142 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
144 result r = __pImpl->RemoveMonitoringRegion(regionId);
145 SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to remove monitoring region with Id (%d).", GetErrorMessage(r), regionId);
151 LocationProvider::RemoveAllMonitoringRegions(void)
153 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
155 return __pImpl->RemoveAllMonitoringRegions();
158 LocationServiceStatus
159 LocationProvider::GetLocationUpdateStatus(void) const
161 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
163 return __pImpl->GetLocationUpdateStatus();
166 LocationServiceStatus
167 LocationProvider::GetRegionMonitoringStatus(void) const
169 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
171 return __pImpl->GetRegionMonitoringStatus();
175 LocationProvider::GetCurrentAccuracy(void) const
177 SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
179 return __pImpl->GetCurrentAccuracy();
183 LocationProvider::GetLocation(const LocationCriteria& criteria)
185 result r = AccessController::CheckPrivilege(_PRV_LOCATION);
186 SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
188 return _LocationProviderImpl::GetLocation(criteria);
192 LocationProvider::GetLastKnownLocation(void)
194 result r = AccessController::CheckPrivilege(_PRV_LOCATION);
195 SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
197 return _LocationProviderImpl::GetLastKnownLocation();