summaryrefslogtreecommitdiff
path: root/src/FLoc_LocationManager.h
blob: 531eabb0bd84138e7e57441b1d16b534f410b2ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
//
// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

/**
 * @file	FLoc_LocationManager.h
 * @brief	This is the header file for the %_LocationManager class.
 *
 * This header file contains the declarations of the %_LocationManager class methods.
 */

#ifndef _FLOC_INTERNAL_LOCATION_MANAGER_H_
#define _FLOC_INTERNAL_LOCATION_MANAGER_H_

#include <unique_ptr.h>
#include <location/locations.h>
#include <FBaseColAllElementsDeleter.h>
#include <FBaseRtEventDrivenThread.h>
#include <FLocLocation.h>
#include "FLoc_ILocationManagerListener.h"
#include "FLoc_Types.h"

namespace Tizen { namespace Locations
{

class _LocationMonitor;
class _LocationRequestInfo;
class _SyncLocationRequestInfo;

class _LocationManager
	: public Tizen::Base::Runtime::EventDrivenThread
	, public Tizen::Base::Runtime::ITimerEventListener
{
public:
	// This method adds the location request into the list of requests and requests for location updates from native location provider.
	//
	// @since 2.0
	//
	result StartLocationUpdates(LocationAccuracy accuracy, int interval, _ILocationManagerListener* pListener, RequestId& reqId);

	// This method removes the location request wrt to the reqId provided. If the list entries is zero, then stops the native location provider.
	//
	// @since 2.0
	//
	result StopLocationUpdates(RequestId reqId);

	// This method initiates the synchronous location retrieval. The location monitor instance provided is used to intimate back the location.
	//
	// @since 2.0
	//
	result RegisterLocationMonitor(_LocationMonitor* pLocationMonitor);

	// This method returns the stored location.
	//
	// @since 2.0
	//
	Location GetLastKnownLocation(void);

	// This method converts the horizontal accuracy in meters to the LocationAccuracy enum type.
	//
	// @since 2.0
	//
	LocationAccuracy GetAccuracyLevel(double horAcc) const;

	// This method gets the location setting information of this particular application.
	//
	// @since 2.0
	//
	bool IsAppEnabled(void);

	// This method returns the single instance of the location maanger.
	//
	// @since 2.0
	//
	static _LocationManager* GetInstance(void);

private:
	// This default constructor is intentionally declared as private to implement the Singleton semantic.
	//
	// @since 2.0
	//
	_LocationManager(void);

	// The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
	//
	// @since 2.0
	//
	_LocationManager(const _LocationManager& value);

	// This destructor is intentionally declared as private to implement the Singleton semantic.
	//
	// @since 2.0
	//
	~_LocationManager(void);

	// The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
	//
	// @since 2.0
	//
	_LocationManager& operator =(const _LocationManager& rhs);

	// The method adds the _LocationRequestInfo instance to the array list.
	//
	// @since 2.0
	//
	void AddToLocRequestInfoList(const _LocationRequestInfo* pLocRequestInfo);

	// The method removes the _LocationRequestInfo instance corresponding to a reqId from the array list.
	//
	// @since 2.0
	//
	void RemoveFromLocRequestInfoList(RequestId reqId);

	// The method adds the _SyncLocationRequestInfo instance to the array list.
	//
	// @since 2.0
	//
	void AddToSyncLocationRequestInfoList(_SyncLocationRequestInfo& syncLocRequestInfo);

	// The method removes the _SyncLocationRequestInfo instance from the list.
	//
	// @since 2.0
	//
	void RemoveSyncLocRetrievalRequest(_SyncLocationRequestInfo& syncLocRequestInfo);

	// The method restarts all (GPS, WPS and CPS) the native location providers.
	//
	// @since 2.0
	//
	void RestartLocationUpdates(void);

	// The method restarts the update timer after calculating the GCD of the timeout values requested by each location provider.
	//
	// @since 2.0
	//
	void RestartUpdateTimer(void);

	// The method is called everytime the sync retrieval timer is expired.
	//
	// @since 2.0
	//
	void HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncLocRequestInfo);

	// The method is called everytime the Async update timer is expired to set the location information.
	//
	// @since 2.0
	//
	result SetLocationInformation(double latitude, double longitude, double altitude, time_t timestamp, location_method_e locMethod);

	// The method is called to send back the callbacks in case of async location updates.
	//
	// @since 2.0
	//
	void SendLocationCallbacks(void);

	// This method resets the member variables.
	//
	// @since 2.0
	//
	void Reset(void);

	// The method calls the construct method of the event driven thread.
	//
	// @since 2.0
	//
	result Construct(void);

	// This method is gets the last known location from Native side for the given method.
	//
	// @since 2.0
	//
	Location GetLastKnownLocation(location_method_e nativeLocMethod);

	// @see @ref Tizen::Base::Runtime::EventDrivenThread::OnStart()
	//
	// @since 2.0
	//
	virtual bool OnStart(void);

	// @see @ref Tizen::Base::Runtime::EventDrivenThread::OnStop()
	//
	// @since 2.0
	//
	virtual void OnStop(void);

	// @see @ref Tizen::Base::Runtime::EventDrivenThread::OnUserEventReceivedN()
	//
	// @since 2.0
	//
	virtual void OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs);

	// @see @ref Tizen::Base::Runtime::ITimerEventListener::OnTimerExpired()
	//
	// @since 2.0
	//
	virtual void OnTimerExpired(Tizen::Base::Runtime::Timer& timer);

	// This callback is recieved from native location manager for satellite information.
	//
	// @since 2.0
	//
	static bool SatelliteInfoUpdated(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_active, void* user_data);

	// This method is called by the native location provider when the service state of GPS method is changed.
	//
	// @since 2.0
	//
	static void GpsServiceUpdateCallback(location_service_state_e state, void* user_data);

	// This method is called by the native location provider when the service state of WPS method is changed.
	//
	// @since 2.0
	//
	static void WpsServiceUpdateCallback(location_service_state_e state, void* user_data);

	// This method is called by the native location provider when the service state of CPS method is changed.
	//
	// @since 2.0
	//
	static void CpsServiceUpdateCallback(location_service_state_e state, void* user_data);

	// This method initializes the single instance of the location manager.
	//
	// @since 2.0
	//
	static void InitLocationManager(void);

	// This method is called when the location manager thread is destroyed.
	//
	// @since 2.0
	//
	static void DestroyLocationManager(void);

	// This method gets app's accessibility from native side, adding the app into the location
	// setting, if it is not registerd.
	//
	// @since 2.0
	//
	static bool GetAppAccessibility(void);

	// This method returns the most recent location among available last known locations.
	//
	// @since 2.0
	//
	Location GetRecentLocationAvailable(void);

private:
	const static RequestId REQ_ID_START_LOC_UPDATES = 1;
	const static RequestId REQ_ID_STOP_LOC_UPDATES = 2;
	const static RequestId REQ_ID_RESTART_LOC_UPDATES = 3;
	const static RequestId REQ_ID_SUSTAIN_GPS = 4;
	const static RequestId REQ_ID_SUSTAIN_WPS = 5;
	const static RequestId REQ_ID_SUSTAIN_CPS = 6;
	const static RequestId REQ_ID_SYNC_LOC_RETRIEVAL = 7;
	const static RequestId REQ_ID_GET_APP_ACCESSIBILITY = 8;
	const static RequestId REQ_ID_GET_LAST_LOCATION = 9;

	enum _LocationMethodRequested
	{
		LOC_METHOD_REQUESTED_NONE,
		LOC_METHOD_REQUESTED_GPS,
		LOC_METHOD_REQUESTED_WPS,
		LOC_METHOD_REQUESTED_CPS,
		LOC_METHOD_REQUESTED_ALL,
	}
	__locMethodRequested;

	enum _LocationManagerState
	{
		LOC_MGR_STATE_IDLE,
		LOC_MGR_STATE_FAST_SENSING,
		LOC_MGR_STATE_FAST_SENSING_SETTLED
	}
	__locationMgrState;

	LocationAccuracy __minRequestedAccuracy;
	location_service_state_e __nativeGPSServiceState;
	location_service_state_e __nativeWPSServiceState;
	location_service_state_e __nativeCPSServiceState;
	int __timerInterval;
	int __timerTicks;
	location_manager_h __gpsHandler;
	location_manager_h __wpsHandler;
	location_manager_h __cpsHandler;
	std::unique_ptr< Tizen::Locations::Location > __pCurrentLocation;
	std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pLocRequestInfoList;
	std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pSyncLocRequestInfoList;
	std::unique_ptr< Tizen::Base::Runtime::Mutex > __pLocMgrMutex;
	std::unique_ptr< Tizen::Base::Runtime::Timer > __pLocUpdateTimer;
	static _LocationManager* __pUniqueInstance;

	friend class std::default_delete< _LocationManager >;
};      // class _LocationManager
}}  // Tizen::Locations
#endif // _FLOC_INTERNAL_LOCATION_MANAGER_H_