Tizen 2.0 Release
[framework/osp/locations.git] / src / FLoc_LocationProviderImpl.h
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17
18 /**
19  * @file        FLoc_LocationProviderImpl.h
20  * @brief       This is the header file for the %_LocationProviderImpl class.
21  *
22  * This header file contains the declarations of the %_LocationProviderImpl class.
23  */
24
25 #ifndef _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_
26 #define _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_
27
28 #include <unique_ptr.h>
29 #include <FAppIActiveAppEventListener.h>
30 #include <FBaseColAllElementsDeleter.h>
31 #include <FBaseRtTimer.h>
32 #include <FBaseRtIEventListener.h>
33 #include <FLocLocationCriteria.h>
34 #include <FBaseRt_Event.h>
35 #include "FLoc_ILocationManagerListener.h"
36 #include "FLoc_ILocProviderEventListener.h"
37 #include "FLoc_LocProviderEventArg.h"
38 #include "FLoc_RegionInfo.h"
39
40 namespace Tizen { namespace Locations
41 {
42
43 class Coordinates;
44 class _LocationManager;
45 class _LocProviderEventArg;
46
47 enum LocationUpdateType
48 {
49         _LOCATION_UPDATE_TYPE_NONE,
50         _LOCATION_UPDATE_TYPE_INTERVAL,
51         _LOCATION_UPDATE_TYPE_DISTANCE
52 };
53
54 class _LocationProviderImpl
55         : public Tizen::Base::Runtime::_Event
56         , public Tizen::Locations::_ILocationManagerListener
57         , public Tizen::Locations::_ILocProviderEventListener
58         , public Tizen::App::IActiveAppEventListener
59 {
60 public:
61         /**
62         * This is the default constructor of this class.
63         *
64         * @since 2.0
65         */
66         _LocationProviderImpl(void);
67
68         /**
69         * This is the destructor of this class
70         *
71         * @since 2.0
72         */
73         virtual ~_LocationProviderImpl(void);
74
75         /**
76          * @see @ref Tizen::Locations::LocationProvider::Construct()
77          */
78         result Construct(const LocationCriteria& criteria, ILocationProviderListener& listener);
79
80         /**
81          * @see @ref Tizen::Locations::LocationProvider::StartLocationUpdates()
82          */
83         result StartLocationUpdatesByInterval(int interval);
84
85         /**
86          * @see @ref Tizen::Locations::LocationProvider::StartLocationUpdates()
87          */
88         result StartLocationUpdatesByDistance(double distance);
89
90         /**
91          * @see @ref Tizen::Locations::LocationProvider::StopLocationUdpates()
92          */
93         result StopLocationUpdates(void);
94
95         /**
96          * @see @ref Tizen::Locations::LocationProvider::KeepLocationUpdateAwake()
97          */
98         void KeepLocationUpdateAwake(bool enable);
99
100         /**
101          * @see @ref Tizen::Locations::LocationProvider::AddRegionMonitoring()
102          */
103         result AddMonitoringRegion(const Tizen::Locations::Coordinates& regionCenter, double radius, RegionId& regionId);
104
105         /**
106          * @see @ref Tizen::Locations::LocationProvider::RemoveRegionMonitoring()
107          */
108         result RemoveMonitoringRegion(int regionId);
109
110         /**
111          * @see @ref Tizen::Locations::LocationProvider::RemoveAllRegionMonitoring()
112          */
113         void RemoveAllMonitoringRegions(void);
114
115         /**
116          * @see @ref Tizen::Locations::LocationProvider::GetLocationUpdateStatus()
117          */
118         LocationServiceStatus GetLocationUpdateStatus(void) const;
119
120         /**
121          * @see @ref Tizen::Locations::LocationProvider::GetRegionMonitoringStatus()
122          */
123         LocationServiceStatus GetRegionMonitoringStatus(void) const;
124
125         /**
126          * @see @ref Tizen::Locations::LocationProvider::GetCurrentAccuracy()
127          */
128         LocationAccuracy GetCurrentAccuracy(void) const;
129
130         /**
131          * @see @ref Tizen::Locations::LocationProvider::GetLocation()
132          */
133         static Location GetLocation(const LocationCriteria& criteria);
134
135         /**
136          * @see @ref Tizen::Locations::LocationProvider::GetLocation()
137          */
138         static Location GetLastKnownLocation(void);
139
140 private:
141         // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
142         //
143         // @since 2.0
144         //
145         _LocationProviderImpl(const _LocationProviderImpl& rhs);
146
147         // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
148         //
149         // @since 2.0
150         //
151         _LocationProviderImpl& operator =(const _LocationProviderImpl& rhs);
152
153         /**
154          * @see @ref Tizen::Locations::_ILocationManagerListener::OnLocationUpdated()
155          */
156         virtual void OnLocationUpdated(RequestId reqId, const Tizen::Locations::Location& location);
157
158         /**
159          * @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationEventReceivedN()
160          */
161         virtual void OnLocationEventReceivedN(RequestId reqId, Tizen::Locations::Location& location);
162
163         /**
164          * @see @ref Tizen::Locations::_ILocProviderEventListener::OnLocationUpdateStatusChanged()
165          */
166         virtual void OnLocationUpdateStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);
167
168         /**
169          * @see @ref Tizen::Locations::_ILocProviderEventListener::OnRegionMonitoringStatusChanged()
170          */
171         virtual void OnRegionMonitoringStatusChanged(Tizen::Locations::LocationServiceStatus locSvcStatus);
172
173         /**
174          * @see @ref Tizen::App::IActiveAppEventListener::OnActiveAppChanged()
175          */
176         virtual void OnActiveAppChanged(const Tizen::App::AppId& appId);
177
178         // This method requests the location update to the Location Manager.
179         //
180         // @since 2.0
181         //
182         result StartLocationUpdates(LocationUpdateType updateType, int interval, double distance);
183
184         // This method is used to check if the new position is at a certain distance from the original position.
185         //
186         // @since 2.0
187         //
188         bool CheckDistanceThreshold(const Tizen::Locations::Location& oldPosition, const Tizen::Locations::Location& newPosition);
189
190         // This method is used to reset the member variables.
191         //
192         // @since 2.0
193         //
194         void ResetLocationUpdates(void);
195
196         // @see @ref Tizen::Base::Runtime::Event::FireImpl()
197         //
198         // @since 2.0
199         //
200         virtual void FireImpl(Tizen::Base::Runtime::IEventListener& listener, const Tizen::Base::Runtime::IEventArg& arg);
201
202         // This method is handles the location udpates.
203         //
204         // @since 2.0
205         //
206         void HandleLocationUpdate(Tizen::Locations::Location& location, bool isLocationValid);
207
208         // This method handles the region monitoring.
209         //
210         // @since 2.0
211         //
212         void HandleRegionMonitoring(Tizen::Locations::Location& location, bool isLocationValid);
213
214         // This method sends the callbacks to the applications regarding the Region events.
215         // @since 2.0
216         //
217         void NotifyRegionCrossedStatus(const Tizen::Locations::Location& location);
218
219         // This method finds the region status of a particular region w.r.t the given location.
220         // @since 2.0
221         //
222         _RegionState GetRegionCurrentState(const _RegionInfo& region, const Location& location);
223
224         // This method sends the service status update callback to the application.
225         // @since 2.0
226         //
227         void NotifyServiceStatus(_LocProviderEventType eventType, LocationServiceStatus svcStatus);
228
229         // This method is returns the bool value depicting the privilege details depending on the location settings.
230         //
231         // @since 2.0
232         //
233         static bool GetUserPrivilege(void);
234
235 private:
236         bool __firstLocationUpdate;
237         bool __regionMonitoringActive;
238         bool __awakeEnabled;
239         int __updateInterval;
240         LocationUpdateType __locationUpdateType;
241         LocationServiceStatus __locationUpdateStatus;
242         LocationServiceStatus __regionMonitorStatus;
243         LocationAccuracy __lastLocationAccuracy;
244         RequestId __reqId;
245         RequestId __regionReqId;
246         double __distanceThreshold;
247         LocationCriteria __criteria;
248         ILocationProviderListener* __pLocationListener;
249         _LocationManager* __pLocationManager;
250         std::unique_ptr< Tizen::Locations::Location > __pLastLocation;
251         std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > __pRegionList;
252 }; // _LocationProviderImpl
253 }}  // Tizen::Locations
254
255 #endif // _FLOC_INTERNAL_LOCATION_PROVIDER_IMPL_H_