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_LocationManager.h
20 * @brief This is the header file for the %_LocationManager class.
22 * This header file contains the declarations of the %_LocationManager class methods.
25 #ifndef _FLOC_INTERNAL_LOCATION_MANAGER_H_
26 #define _FLOC_INTERNAL_LOCATION_MANAGER_H_
28 #include <unique_ptr.h>
29 #include <location/locations.h>
30 #include <FBaseColAllElementsDeleter.h>
31 #include <FBaseRtEventDrivenThread.h>
32 #include <FLocLocation.h>
33 #include "FLoc_ILocationManagerListener.h"
34 #include "FLoc_Types.h"
36 namespace Tizen { namespace Locations
39 class _LocationMonitor;
40 class _LocationRequestInfo;
41 class _SyncLocationRequestInfo;
43 class _LocationManager
44 : public Tizen::Base::Runtime::EventDrivenThread
45 , public Tizen::Base::Runtime::ITimerEventListener
48 // This method adds the location request into the list of requests and requests for location updates from native location provider.
52 result StartLocationUpdates(LocationAccuracy accuracy, int interval, _ILocationManagerListener* pListener, RequestId& reqId);
54 // This method removes the location request wrt to the reqId provided. If the list entries is zero, then stops the native location provider.
58 result StopLocationUpdates(RequestId reqId);
60 // This method updates the requested interval from the location provider.
64 result ChangeUpdateInterval(RequestId reqId, int interval);
66 // This method initiates the synchronous location retrieval. The location monitor instance provided is used to intimate back the location.
70 result RegisterLocationMonitor(_LocationMonitor* pLocationMonitor);
72 // This method returns the stored location.
76 Location GetLastKnownLocation(void);
78 // This method converts the horizontal accuracy in meters to the LocationAccuracy enum type.
82 LocationAccuracy GetAccuracyLevel(double horAcc) const;
84 // This method gets the location setting information of this particular application.
88 bool IsAppEnabled(void);
90 // This method returns the single instance of the location maanger.
94 static _LocationManager* GetInstance(void);
97 // This default constructor is intentionally declared as private to implement the Singleton semantic.
101 _LocationManager(void);
103 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
107 _LocationManager(const _LocationManager& value);
109 // This destructor is intentionally declared as private to implement the Singleton semantic.
113 ~_LocationManager(void);
115 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
119 _LocationManager& operator =(const _LocationManager& rhs);
121 // The method adds the _LocationRequestInfo instance to the array list.
125 void AddToLocRequestInfoList(const _LocationRequestInfo* pLocRequestInfo);
127 // The method removes the _LocationRequestInfo instance corresponding to a reqId from the array list.
131 void RemoveFromLocRequestInfoList(RequestId reqId);
133 // The method adds the _SyncLocationRequestInfo instance to the array list.
137 void AddToSyncLocationRequestInfoList(_SyncLocationRequestInfo& syncLocRequestInfo);
139 // The method removes the _SyncLocationRequestInfo instance from the list.
143 void RemoveSyncLocRetrievalRequest(_SyncLocationRequestInfo& syncLocRequestInfo);
145 // The method restarts all (GPS, WPS and CPS) the native location providers.
149 void RestartLocationUpdates(void);
151 // The method restarts the update timer after calculating the GCD of the timeout values requested by each location provider.
155 void RestartUpdateTimer(void);
157 // The method is called everytime the sync retrieval timer is expired.
161 void HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncLocRequestInfo);
163 // The method is called everytime the Async update timer is expired to set the location information.
167 result SetLocationInformation(double latitude, double longitude, double altitude, time_t timestamp, location_method_e locMethod, Location* pLocation);
169 // The method is called to send back the callbacks in case of async location updates.
173 void SendLocationCallbacks(void);
175 // This method resets the member variables.
181 // The method calls the construct method of the event driven thread.
185 result Construct(void);
187 // This method is gets the last known location from Native side for the given method.
191 Location GetLastKnownLocation(location_method_e nativeLocMethod);
193 // This method returns the most recent location among available last known locations.
197 Location GetRecentLocationAvailable(void);
199 // This method updates the timer interval for a particular request Id.
203 void UpdateLocRequestInfoList(RequestId reqId, int interval);
205 // This method gets the better location among the three location providers.
209 const Location* FindBestLocation(void);
211 // This method gets the location from the native side depending on the location handle.
215 result GetLocation(location_method_e nativeLocMethod);
217 // @see @ref Tizen::Base::Runtime::EventDrivenThread::OnStart()
221 virtual bool OnStart(void);
223 // @see @ref Tizen::Base::Runtime::EventDrivenThread::OnStop()
227 virtual void OnStop(void);
229 // @see @ref Tizen::Base::Runtime::EventDrivenThread::OnUserEventReceivedN()
233 virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs);
235 // @see @ref Tizen::Base::Runtime::ITimerEventListener::OnTimerExpired()
239 virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
241 // This callback is recieved from native location manager for satellite information.
245 static bool SatelliteInfoUpdated(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_active, void* user_data);
247 // This method is called by the native location provider when the service state of GPS method is changed.
251 static void GpsServiceUpdateCallback(location_service_state_e state, void* user_data);
253 // This method is called by the native location provider when the service state of WPS method is changed.
257 static void WpsServiceUpdateCallback(location_service_state_e state, void* user_data);
259 // This method is called by the native location provider when the service state of CPS method is changed.
263 static void CpsServiceUpdateCallback(location_service_state_e state, void* user_data);
265 // This method initializes the single instance of the location manager.
269 static void InitLocationManager(void);
271 // This method is called when the location manager thread is destroyed.
275 static void DestroyLocationManager(void);
277 // This method gets app's accessibility from native side, adding the app into the location
278 // setting, if it is not registerd.
282 static bool GetAppAccessibility(void);
285 const static RequestId REQ_ID_START_LOC_UPDATES = 1;
286 const static RequestId REQ_ID_STOP_LOC_UPDATES = 2;
287 const static RequestId REQ_ID_RESTART_LOC_UPDATES = 3;
288 const static RequestId REQ_ID_SUSTAIN_GPS = 4;
289 const static RequestId REQ_ID_SUSTAIN_WPS = 5;
290 const static RequestId REQ_ID_SUSTAIN_CPS = 6;
291 const static RequestId REQ_ID_SYNC_LOC_RETRIEVAL = 7;
292 const static RequestId REQ_ID_GET_APP_ACCESSIBILITY = 8;
293 const static RequestId REQ_ID_GET_LAST_LOCATION = 9;
294 const static RequestId REQ_ID_UPDATE_INTERVAL = 10;
296 enum _LocationMethodRequested
298 LOC_METHOD_REQUESTED_NONE,
299 LOC_METHOD_REQUESTED_GPS,
300 LOC_METHOD_REQUESTED_WPS,
301 LOC_METHOD_REQUESTED_CPS,
302 LOC_METHOD_REQUESTED_ALL,
304 __locMethodRequested;
306 enum _LocationManagerState
309 LOC_MGR_STATE_FAST_SENSING,
310 LOC_MGR_STATE_FAST_SENSING_SETTLED
314 class __LocationManagerHandle
317 __LocationManagerHandle(void)
318 : serviceState(LOCATIONS_SERVICE_DISABLED)
324 ~__LocationManagerHandle(void)
329 location_service_state_e serviceState;
330 location_manager_h handle;
331 std::unique_ptr< Tizen::Locations::Location > pLocation;
334 LocationAccuracy __minRequestedAccuracy;
337 __LocationManagerHandle __gpsHandler;
338 __LocationManagerHandle __wpsHandler;
339 __LocationManagerHandle __cpsHandler;
340 std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pLocRequestInfoList;
341 std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pSyncLocRequestInfoList;
342 std::unique_ptr< Tizen::Base::Runtime::Timer > __pLocUpdateTimer;
343 static _LocationManager* __pUniqueInstance;
345 friend class std::default_delete< _LocationManager >;
346 }; // class _LocationManager
347 }} // Tizen::Locations
348 #endif // _FLOC_INTERNAL_LOCATION_MANAGER_H_