summaryrefslogtreecommitdiff
path: root/src/FLoc_LocationProviderImpl.h
blob: 450380bd810ad0d0f784672e6ce7f1a33af5620f (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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
//
// 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_LocationProviderImpl.h
 * @brief	This is the header file for the %_LocationProviderImpl class.
 *
 * This header file contains the declarations of the %_LocationProviderImpl class.
 */

#ifndef _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_
#define _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_

#include <unique_ptr.h>
#include <FAppIActiveAppEventListener.h>
#include <FBaseColAllElementsDeleter.h>
#include <FBaseRtIEventListener.h>
#include <FBaseRtITimerEventListener.h>
#include <FBaseRtTimer.h>
#include <FLocLocationCriteria.h>
#include <FBaseRt_Event.h>
#include <FLoc_Config.h>
#include "FLoc_ILocationManagerListener.h"
#include "FLoc_ILocProviderEventListener.h"
#include "FLoc_LocProviderEventArg.h"
#include "FLoc_RegionInfo.h"

namespace Tizen { namespace Locations
{

class Coordinates;
class _LocationManager;
class _LocProviderEventArg;

enum LocationUpdateType
{
	_LOCATION_UPDATE_TYPE_NONE,
	_LOCATION_UPDATE_TYPE_INTERVAL,
	_LOCATION_UPDATE_TYPE_DISTANCE
};

class _LocationProviderImpl
	: public Tizen::Base::Runtime::_Event
	, public Tizen::Locations::_ILocationManagerListener
	, public Tizen::Locations::_ILocProviderEventListener
	, public Tizen::App::IActiveAppEventListener
	, public Tizen::Base::Runtime::ITimerEventListener
{
public:
	/**
	* This is the default constructor of this class.
	*
	* @since 2.0
	*/
	_LocationProviderImpl(void);

	/**
	* This is the destructor of this class
	*
	* @since 2.0
	*/
	virtual ~_LocationProviderImpl(void);

	/**
	 * @see @ref Tizen::Locations::LocationProvider::Construct()
	 */
	result Construct(const LocationCriteria& criteria, ILocationProviderListener& listener);

	/**
	 * @see @ref Tizen::Locations::LocationProvider::StartLocationUpdates()
	 */
	result StartLocationUpdatesByInterval(int interval);

	/**
	 * @see @ref Tizen::Locations::LocationProvider::StartLocationUpdates()
	 */
	result StartLocationUpdatesByDistance(double distance);

	/**
	 * @see @ref Tizen::Locations::LocationProvider::StopLocationUdpates()
	 */
	result StopLocationUpdates(void);

	/**
	 * @see @ref Tizen::Locations::LocationProvider::KeepLocationUpdateAwake()
	 */
	void KeepLocationUpdateAwake(bool enable);

	/**
	 * @see @ref Tizen::Locations::LocationProvider::AddRegionMonitoring()
	 */
	result AddMonitoringRegion(const Tizen::Locations::Coordinates& regionCenter, double radius, RegionId& regionId);

	/**
	 * @see @ref Tizen::Locations::LocationProvider::RemoveRegionMonitoring()
	 */
	result RemoveMonitoringRegion(int regionId);

	/**
	 * @see @ref Tizen::Locations::LocationProvider::RemoveAllRegionMonitoring()
	 */
	void RemoveAllMonitoringRegions(void);

	/**
	 * @see @ref Tizen::Locations::LocationProvider::GetLocationUpdateStatus()
	 */
	LocationServiceStatus GetLocationUpdateStatus(void) const;

	/**
	 * @see @ref Tizen::Locations::LocationProvider::GetRegionMonitoringStatus()
	 */
	LocationServiceStatus GetRegionMonitoringStatus(void) const;

	/**
	 * @see @ref Tizen::Locations::LocationProvider::GetCurrentAccuracy()
	 */
	LocationAccuracy GetCurrentAccuracy(void) const;

	/**
	 * @see @ref Tizen::Locations::LocationProvider::GetLocation()
	 */
	static Location GetLocation(const LocationCriteria& criteria);

	/**
	 * @see @ref Tizen::Locations::LocationProvider::GetLocation()
	 */
	static Location GetLastKnownLocation(void);

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

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

	/**
	 * @see @ref Tizen::Locations::_ILocationManagerListener::OnLocationUpdated()
	 */
	virtual void OnLocationUpdated(RequestId reqId, const Tizen::Locations::Location& location);

	/**
	 * @see @ref Tizen::Locations::_ILocationManagerListener::OnAlarmExpired()
	 */
	virtual void OnAlarmExpired(void);

	/**
	 * @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationEventReceivedN()
	 */
	virtual void OnLocationEventReceivedN(RequestId reqId, Tizen::Locations::Location& location);

	/**
	 * @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationUpdateStatusChanged()
	 */
	virtual void OnLocationUpdateStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);

	/**
	 * @see @ref Tizen::Locations::_ILocProviderEventListener::OnRegionMonitoringStatusChanged()
	 */
	virtual void OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);

	/**
	 * @see @ref Tizen::Locations::_ILocProviderEventListener::OnAlarmExpiredEventReceived()
	 */
	virtual void OnAlarmExpiredEventReceived(void);

	/**
	 * @see @ref Tizen::App::IActiveAppEventListener::OnActiveAppChanged()
	 */
	virtual void OnActiveAppChanged(const Tizen::App::AppId& appId);

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

	// This method requests the location update to the Location Manager.
	//
	// @since 2.0
	//
	result StartLocationUpdates(LocationUpdateType updateType, int interval, double distance);

	// This method is used to check if the new position is at a certain distance from the original position.
	//
	// @since 2.0
	//
	bool CheckDistanceThreshold(const Tizen::Locations::Location& oldPosition, const Tizen::Locations::Location& newPosition);

	// This method is used to reset the member variables.
	//
	// @since 2.0
	//
	void ResetLocationUpdates(void);

	// @see @ref Tizen::Base::Runtime::Event::FireImpl()
	//
	// @since 2.0
	//
	virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);

	// This method is handles the location udpates.
	//
	// @since 2.0
	//
	void HandleLocationUpdate(Tizen::Locations::Location& location, bool isLocationValid);

	// This method handles the region monitoring.
	//
	// @since 2.0
	//
	void HandleRegionMonitoring(Tizen::Locations::Location& location, bool isLocationValid);

	// This method sends the callbacks to the applications regarding the Region events.
	// @since 2.0
	//
	void NotifyRegionCrossedStatus(const Tizen::Locations::Location& location);

	// This method finds the region status of a particular region w.r.t the given location.
	// @since 2.0
	//
	_RegionState GetRegionCurrentState(const _RegionInfo& region, const Location& location);

	// This method sends the service status update callback to the application.
	// @since 2.0
	//
	void NotifyServiceStatus(_LocProviderEventType eventType, LocationServiceStatus svcStatus);

	// This method returns the bool value depicting the privilege details depending on the location settings.
	//
	// @since 2.0
	//
	static bool GetUserPrivilege(void);

	// This method starts the location updates and the timer for region monitoring.
	//
	// @since 2.0
	//
	result ActivateRegionMonitoring(bool startUpdate);

	// This method stops the location updates and cancels the timer and alarm set for the area monitoring.
	//
	// @since 2.0
	//
	void StopRegionMonitoring(void);

	// This method determines the time for the alarm to be set for next cycle of region monitoring.
	//
	// @since 2.0
	//
	void SetNextRegionMonitoringTime(void);

private:
	class _LocationUpdater
	{
	public:
		_LocationUpdater(void)
			: firstLocationUpdate(true)
			, awakeEnabled(false)
			, updateInterval(0)
			, status(LOC_SVC_STATUS_IDLE)
			, type(_LOCATION_UPDATE_TYPE_NONE)
			, reqId(-1)
			, distanceThreshold(0.0)
			, pLocation(null)
		{
		}

		~_LocationUpdater(void)
		{
		}

	public:
		bool firstLocationUpdate;
		bool awakeEnabled;
		int updateInterval;
		LocationServiceStatus status;
		LocationUpdateType type;
		RequestId reqId;
		double distanceThreshold;
		std::unique_ptr< Tizen::Locations::Location > pLocation;
	}
	__locationUpdater;

	class _RegionMonitor
	{
	public:
		_RegionMonitor(void)
			: reqId(-1)
			, status(LOC_SVC_STATUS_IDLE)
			, speed(DEFAULT_AVG_SPEED)
			, pTimer(null)
			, pLocation(null)
			, pRegionList(null)
		{
		}

		~_RegionMonitor(void)
		{
		}

	public:
		RequestId reqId;
		LocationServiceStatus status;
		double speed;
		std::unique_ptr< Tizen::Base::Runtime::Timer > pTimer;
		std::unique_ptr< Tizen::Locations::Location > pLocation;
		std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pRegionList;
	}
	__regionMonitor;

	LocationAccuracy __lastLocationAccuracy;
	LocationCriteria __criteria;
	ILocationProviderListener* __pLocationListener;
	_LocationManager* __pLocationManager;

}; // _LocationProviderImpl
}}  // Tizen::Locations

#endif // _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_