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 FLoc_LocationProviderImpl.h
20 * @brief This is the header file for the %_LocationProviderImpl class.
22 * This header file contains the declarations of the %_LocationProviderImpl class.
25 #ifndef _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_
26 #define _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_
28 #include <unique_ptr.h>
29 #include <FAppIActiveAppEventListener.h>
30 #include <FBaseColAllElementsDeleter.h>
31 #include <FBaseRtTimer.h>
32 #include <FBaseRtIEventListener.h>
33 #include <FLocLocationCriteria.h>
34 #include <FBaseRt_Event.h>
35 #include "FLoc_ILocationManagerListener.h"
36 #include "FLoc_ILocProviderEventListener.h"
37 #include "FLoc_LocProviderEventArg.h"
38 #include "FLoc_RegionInfo.h"
40 namespace Tizen { namespace Locations
44 class _LocationManager;
45 class _LocProviderEventArg;
47 enum LocationUpdateType
49 _LOCATION_UPDATE_TYPE_NONE,
50 _LOCATION_UPDATE_TYPE_INTERVAL,
51 _LOCATION_UPDATE_TYPE_DISTANCE
54 class _LocationProviderImpl
55 : public Tizen::Base::Runtime::_Event
56 , public Tizen::Locations::_ILocationManagerListener
57 , public Tizen::Locations::_ILocProviderEventListener
58 , public Tizen::App::IActiveAppEventListener
62 * This is the default constructor of this class.
66 _LocationProviderImpl(void);
69 * This is the destructor of this class
73 virtual ~_LocationProviderImpl(void);
76 * @see @ref Tizen::Locations::LocationProvider::Construct()
78 result Construct(const LocationCriteria& criteria, ILocationProviderListener& listener);
81 * @see @ref Tizen::Locations::LocationProvider::StartLocationUpdates()
83 result StartLocationUpdatesByInterval(int interval);
86 * @see @ref Tizen::Locations::LocationProvider::StartLocationUpdates()
88 result StartLocationUpdatesByDistance(double distance);
91 * @see @ref Tizen::Locations::LocationProvider::StopLocationUdpates()
93 result StopLocationUpdates(void);
96 * @see @ref Tizen::Locations::LocationProvider::KeepLocationUpdateAwake()
98 void KeepLocationUpdateAwake(bool enable);
101 * @see @ref Tizen::Locations::LocationProvider::AddRegionMonitoring()
103 result AddMonitoringRegion(const Tizen::Locations::Coordinates& regionCenter, double radius, RegionId& regionId);
106 * @see @ref Tizen::Locations::LocationProvider::RemoveRegionMonitoring()
108 result RemoveMonitoringRegion(int regionId);
111 * @see @ref Tizen::Locations::LocationProvider::RemoveAllRegionMonitoring()
113 void RemoveAllMonitoringRegions(void);
116 * @see @ref Tizen::Locations::LocationProvider::GetLocationUpdateStatus()
118 LocationServiceStatus GetLocationUpdateStatus(void) const;
121 * @see @ref Tizen::Locations::LocationProvider::GetRegionMonitoringStatus()
123 LocationServiceStatus GetRegionMonitoringStatus(void) const;
126 * @see @ref Tizen::Locations::LocationProvider::GetCurrentAccuracy()
128 LocationAccuracy GetCurrentAccuracy(void) const;
131 * @see @ref Tizen::Locations::LocationProvider::GetLocation()
133 static Location GetLocation(const LocationCriteria& criteria);
136 * @see @ref Tizen::Locations::LocationProvider::GetLocation()
138 static Location GetLastKnownLocation(void);
141 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
145 _LocationProviderImpl(const _LocationProviderImpl& rhs);
147 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
151 _LocationProviderImpl& operator =(const _LocationProviderImpl& rhs);
154 * @see @ref Tizen::Locations::_ILocationManagerListener::OnLocationUpdated()
156 virtual void OnLocationUpdated(RequestId reqId, const Tizen::Locations::Location& location);
159 * @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationEventReceivedN()
161 virtual void OnLocationEventReceivedN(RequestId reqId, Tizen::Locations::Location& location);
164 * @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationUpdateStatusChanged()
166 virtual void OnLocationUpdateStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);
169 * @see @ref Tizen::Locations::_ILocProviderEventListener::OnRegionMonitoringStatusChanged()
171 virtual void OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);
174 * @see @ref Tizen::App::IActiveAppEventListener::OnActiveAppChanged()
176 virtual void OnActiveAppChanged(const Tizen::App::AppId& appId);
178 // This method requests the location update to the Location Manager.
182 result StartLocationUpdates(LocationUpdateType updateType, int interval, double distance);
184 // This method is used to check if the new position is at a certain distance from the original position.
188 bool CheckDistanceThreshold(const Tizen::Locations::Location& oldPosition, const Tizen::Locations::Location& newPosition);
190 // This method is used to reset the member variables.
194 void ResetLocationUpdates(void);
196 // @see @ref Tizen::Base::Runtime::Event::FireImpl()
200 virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
202 // This method is handles the location udpates.
206 void HandleLocationUpdate(Tizen::Locations::Location& location, bool isLocationValid);
208 // This method handles the region monitoring.
212 void HandleRegionMonitoring(Tizen::Locations::Location& location, bool isLocationValid);
214 // This method sends the callbacks to the applications regarding the Region events.
217 void NotifyRegionCrossedStatus(const Tizen::Locations::Location& location);
219 // This method finds the region status of a particular region w.r.t the given location.
222 _RegionState GetRegionCurrentState(const _RegionInfo& region, const Location& location);
224 // This method sends the service status update callback to the application.
227 void NotifyServiceStatus(_LocProviderEventType eventType, LocationServiceStatus svcStatus);
229 // This method is returns the bool value depicting the privilege details depending on the location settings.
233 static bool GetUserPrivilege(void);
236 bool __firstLocationUpdate;
237 bool __regionMonitoringActive;
239 int __updateInterval;
240 LocationUpdateType __locationUpdateType;
241 LocationServiceStatus __locationUpdateStatus;
242 LocationServiceStatus __regionMonitorStatus;
243 LocationAccuracy __lastLocationAccuracy;
245 RequestId __regionReqId;
246 double __distanceThreshold;
247 LocationCriteria __criteria;
248 ILocationProviderListener* __pLocationListener;
249 _LocationManager* __pLocationManager;
250 std::unique_ptr< Tizen::Locations::Location > __pLastLocation;
251 std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pRegionList;
252 }; // _LocationProviderImpl
253 }} // Tizen::Locations
255 #endif // _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_