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 initiates the synchronous location retrieval. The location monitor instance provided is used to intimate back the location.
64 result RegisterLocationMonitor(_LocationMonitor* pLocationMonitor);
66 // This method returns the stored location.
70 Location GetLastKnownLocation(void);
72 // This method converts the horizontal accuracy in meters to the LocationAccuracy enum type.
76 LocationAccuracy GetAccuracyLevel(double horAcc) const;
78 // This method gets the location setting information of this particular application.
82 bool IsAppEnabled(void);
84 // This method returns the single instance of the location maanger.
88 static _LocationManager* GetInstance(void);
91 // This default constructor is intentionally declared as private to implement the Singleton semantic.
95 _LocationManager(void);
97 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
101 _LocationManager(const _LocationManager& value);
103 // This destructor is intentionally declared as private to implement the Singleton semantic.
107 ~_LocationManager(void);
109 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
113 _LocationManager& operator =(const _LocationManager& rhs);
115 // The method adds the _LocationRequestInfo instance to the array list.
119 void AddToLocRequestInfoList(const _LocationRequestInfo* pLocRequestInfo);
121 // The method removes the _LocationRequestInfo instance corresponding to a reqId from the array list.
125 void RemoveFromLocRequestInfoList(RequestId reqId);
127 // The method adds the _SyncLocationRequestInfo instance to the array list.
131 void AddToSyncLocationRequestInfoList(_SyncLocationRequestInfo& syncLocRequestInfo);
133 // The method removes the _SyncLocationRequestInfo instance from the list.
137 void RemoveSyncLocRetrievalRequest(_SyncLocationRequestInfo& syncLocRequestInfo);
139 // The method restarts all (GPS, WPS and CPS) the native location providers.
143 void RestartLocationUpdates(void);
145 // The method restarts the update timer after calculating the GCD of the timeout values requested by each location provider.
149 void RestartUpdateTimer(void);
151 // The method is called everytime the sync retrieval timer is expired.
155 void HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncLocRequestInfo);
157 // The method is called everytime the Async update timer is expired to set the location information.
161 result SetLocationInformation(double latitude, double longitude, double altitude, time_t timestamp, location_method_e locMethod);
163 // The method is called to send back the callbacks in case of async location updates.
167 void SendLocationCallbacks(void);
169 // This method resets the member variables.
175 // The method calls the construct method of the event driven thread.
179 result Construct(void);
181 // This method is gets the last known location from Native side for the given method.
185 Location GetLastKnownLocation(location_method_e nativeLocMethod);
187 // @see @ref Tizen::Base::Runtime::EventDrivenThread::OnStart()
191 virtual bool OnStart(void);
193 // @see @ref Tizen::Base::Runtime::EventDrivenThread::OnStop()
197 virtual void OnStop(void);
199 // @see @ref Tizen::Base::Runtime::EventDrivenThread::OnUserEventReceivedN()
203 virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs);
205 // @see @ref Tizen::Base::Runtime::ITimerEventListener::OnTimerExpired()
209 virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);
211 // This callback is recieved from native location manager for satellite information.
215 static bool SatelliteInfoUpdated(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_active, void* user_data);
217 // This method is called by the native location provider when the service state of GPS method is changed.
221 static void GpsServiceUpdateCallback(location_service_state_e state, void* user_data);
223 // This method is called by the native location provider when the service state of WPS method is changed.
227 static void WpsServiceUpdateCallback(location_service_state_e state, void* user_data);
229 // This method is called by the native location provider when the service state of CPS method is changed.
233 static void CpsServiceUpdateCallback(location_service_state_e state, void* user_data);
235 // This method initializes the single instance of the location manager.
239 static void InitLocationManager(void);
241 // This method is called when the location manager thread is destroyed.
245 static void DestroyLocationManager(void);
247 // This method gets app's accessibility from native side, adding the app into the location
248 // setting, if it is not registerd.
252 static bool GetAppAccessibility(void);
254 // This method returns the most recent location among available last known locations.
258 Location GetRecentLocationAvailable(void);
261 const static RequestId REQ_ID_START_LOC_UPDATES = 1;
262 const static RequestId REQ_ID_STOP_LOC_UPDATES = 2;
263 const static RequestId REQ_ID_RESTART_LOC_UPDATES = 3;
264 const static RequestId REQ_ID_SUSTAIN_GPS = 4;
265 const static RequestId REQ_ID_SUSTAIN_WPS = 5;
266 const static RequestId REQ_ID_SUSTAIN_CPS = 6;
267 const static RequestId REQ_ID_SYNC_LOC_RETRIEVAL = 7;
268 const static RequestId REQ_ID_GET_APP_ACCESSIBILITY = 8;
269 const static RequestId REQ_ID_GET_LAST_LOCATION = 9;
271 enum _LocationMethodRequested
273 LOC_METHOD_REQUESTED_NONE,
274 LOC_METHOD_REQUESTED_GPS,
275 LOC_METHOD_REQUESTED_WPS,
276 LOC_METHOD_REQUESTED_CPS,
277 LOC_METHOD_REQUESTED_ALL,
279 __locMethodRequested;
281 enum _LocationManagerState
284 LOC_MGR_STATE_FAST_SENSING,
285 LOC_MGR_STATE_FAST_SENSING_SETTLED
289 LocationAccuracy __minRequestedAccuracy;
290 location_service_state_e __nativeGPSServiceState;
291 location_service_state_e __nativeWPSServiceState;
292 location_service_state_e __nativeCPSServiceState;
295 location_manager_h __gpsHandler;
296 location_manager_h __wpsHandler;
297 location_manager_h __cpsHandler;
298 std::unique_ptr< Tizen::Locations::Location > __pCurrentLocation;
299 std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pLocRequestInfoList;
300 std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pSyncLocRequestInfoList;
301 std::unique_ptr< Tizen::Base::Runtime::Mutex > __pLocMgrMutex;
302 std::unique_ptr< Tizen::Base::Runtime::Timer > __pLocUpdateTimer;
303 static _LocationManager* __pUniqueInstance;
305 friend class std::default_delete< _LocationManager >;
306 }; // class _LocationManager
307 }} // Tizen::Locations
308 #endif // _FLOC_INTERNAL_LOCATION_MANAGER_H_