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 <FBaseRtIEventListener.h>
32 #include <FBaseRtITimerEventListener.h>
33 #include <FBaseRtTimer.h>
34 #include <FLocLocationCriteria.h>
35 #include <FSysAlarm.h>
36 #include <FSysIAlarmEventListener.h>
37 #include <FBaseRt_Event.h>
38 #include "FLoc_ILocationManagerListener.h"
39 #include "FLoc_ILocProviderEventListener.h"
40 #include "FLoc_LocProviderEventArg.h"
41 #include "FLoc_RegionInfo.h"
43 namespace Tizen { namespace Locations
47 class _LocationManager;
48 class _LocProviderEventArg;
50 enum LocationUpdateType
52 _LOCATION_UPDATE_TYPE_NONE,
53 _LOCATION_UPDATE_TYPE_INTERVAL,
54 _LOCATION_UPDATE_TYPE_DISTANCE
57 class _LocationProviderImpl
58 : public Tizen::Base::Runtime::_Event
59 , public Tizen::Locations::_ILocationManagerListener
60 , public Tizen::Locations::_ILocProviderEventListener
61 , public Tizen::App::IActiveAppEventListener
62 , public Tizen::Base::Runtime::ITimerEventListener
63 , public Tizen::System::IAlarmEventListener
67 * This is the default constructor of this class.
71 _LocationProviderImpl(void);
74 * This is the destructor of this class
78 virtual ~_LocationProviderImpl(void);
81 * @see @ref Tizen::Locations::LocationProvider::Construct()
83 result Construct(const LocationCriteria& criteria, ILocationProviderListener& listener);
86 * @see @ref Tizen::Locations::LocationProvider::StartLocationUpdates()
88 result StartLocationUpdatesByInterval(int interval);
91 * @see @ref Tizen::Locations::LocationProvider::StartLocationUpdates()
93 result StartLocationUpdatesByDistance(double distance);
96 * @see @ref Tizen::Locations::LocationProvider::StopLocationUdpates()
98 result StopLocationUpdates(void);
101 * @see @ref Tizen::Locations::LocationProvider::KeepLocationUpdateAwake()
103 void KeepLocationUpdateAwake(bool enable);
106 * @see @ref Tizen::Locations::LocationProvider::AddRegionMonitoring()
108 result AddMonitoringRegion(const Tizen::Locations::Coordinates& regionCenter, double radius, RegionId& regionId);
111 * @see @ref Tizen::Locations::LocationProvider::RemoveRegionMonitoring()
113 result RemoveMonitoringRegion(int regionId);
116 * @see @ref Tizen::Locations::LocationProvider::RemoveAllRegionMonitoring()
118 void RemoveAllMonitoringRegions(void);
121 * @see @ref Tizen::Locations::LocationProvider::GetLocationUpdateStatus()
123 LocationServiceStatus GetLocationUpdateStatus(void) const;
126 * @see @ref Tizen::Locations::LocationProvider::GetRegionMonitoringStatus()
128 LocationServiceStatus GetRegionMonitoringStatus(void) const;
131 * @see @ref Tizen::Locations::LocationProvider::GetCurrentAccuracy()
133 LocationAccuracy GetCurrentAccuracy(void) const;
136 * @see @ref Tizen::Locations::LocationProvider::GetLocation()
138 static Location GetLocation(const LocationCriteria& criteria);
141 * @see @ref Tizen::Locations::LocationProvider::GetLocation()
143 static Location GetLastKnownLocation(void);
146 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
150 _LocationProviderImpl(const _LocationProviderImpl& rhs);
152 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
156 _LocationProviderImpl& operator =(const _LocationProviderImpl& rhs);
159 * @see @ref Tizen::Locations::_ILocationManagerListener::OnLocationUpdated()
161 virtual void OnLocationUpdated(RequestId reqId, const Tizen::Locations::Location& location);
164 * @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationEventReceivedN()
166 virtual void OnLocationEventReceivedN(RequestId reqId, Tizen::Locations::Location& location);
169 * @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationUpdateStatusChanged()
171 virtual void OnLocationUpdateStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);
174 * @see @ref Tizen::Locations::_ILocProviderEventListener::OnRegionMonitoringStatusChanged()
176 virtual void OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);
179 * @see @ref Tizen::App::IActiveAppEventListener::OnActiveAppChanged()
181 virtual void OnActiveAppChanged(const Tizen::App::AppId& appId);
184 * @see @ref Tizen::System::IAlarmEventListener::OnAlarmExpired()
186 virtual void OnAlarmExpired(Tizen::System::Alarm& alarm);
189 * @see @ref Tizen::Base::Runtime::ITimerEventListener::OnTimerExpired()
191 virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
193 // This method requests the location update to the Location Manager.
197 result StartLocationUpdates(LocationUpdateType updateType, int interval, double distance);
199 // This method is used to check if the new position is at a certain distance from the original position.
203 bool CheckDistanceThreshold(const Tizen::Locations::Location& oldPosition, const Tizen::Locations::Location& newPosition);
205 // This method is used to reset the member variables.
209 void ResetLocationUpdates(void);
211 // @see @ref Tizen::Base::Runtime::Event::FireImpl()
215 virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
217 // This method is handles the location udpates.
221 void HandleLocationUpdate(Tizen::Locations::Location& location, bool isLocationValid);
223 // This method handles the region monitoring.
227 void HandleRegionMonitoring(Tizen::Locations::Location& location, bool isLocationValid);
229 // This method sends the callbacks to the applications regarding the Region events.
232 void NotifyRegionCrossedStatus(const Tizen::Locations::Location& location);
234 // This method finds the region status of a particular region w.r.t the given location.
237 _RegionState GetRegionCurrentState(const _RegionInfo& region, const Location& location);
239 // This method sends the service status update callback to the application.
242 void NotifyServiceStatus(_LocProviderEventType eventType, LocationServiceStatus svcStatus);
244 // This method returns the bool value depicting the privilege details depending on the location settings.
248 static bool GetUserPrivilege(void);
250 // This method starts the location updates and the timer for region monitoring.
254 result ActivateRegionMonitoring(void);
256 // This method stops the location updates and cancels the timer and alarm set for the area monitoring.
260 void StopRegionMonitoring(void);
262 // This method determines the time for the alarm to be set for next cycle of region monitoring.
266 void SetNextRegionMonitoringTime(void);
269 class _LocationUpdater
272 _LocationUpdater(void)
273 : firstLocationUpdate(true)
274 , awakeEnabled(false)
276 , status(LOC_SVC_STATUS_IDLE)
277 , type(_LOCATION_UPDATE_TYPE_NONE)
279 , distanceThreshold(0.0)
284 ~_LocationUpdater(void)
289 bool firstLocationUpdate;
292 LocationServiceStatus status;
293 LocationUpdateType type;
295 double distanceThreshold;
296 std::unique_ptr<Tizen::Locations::Location> pLocation;
304 , status(LOC_SVC_STATUS_IDLE)
312 ~_RegionMonitor(void)
318 LocationServiceStatus status;
319 std::unique_ptr<Tizen::Base::Runtime::Timer> pTimer;
320 std::unique_ptr<Tizen::System::Alarm> pAlarm;
321 std::unique_ptr<Tizen::Locations::Location> pLocation;
322 std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pRegionList;
325 LocationAccuracy __lastLocationAccuracy;
326 LocationCriteria __criteria;
327 ILocationProviderListener* __pLocationListener;
328 _LocationManager* __pLocationManager;
330 }; // _LocationProviderImpl
331 }} // Tizen::Locations
333 #endif // _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_