Tizen 2.1 base
[framework/osp/locations.git] / src / FLocLocationProvider.cpp
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        FLocLocationProvider.cpp
20  * @brief       This is the implementation file for the %LocationProvider class.
21  *
22  * This header file contains the definitions of the %LocationProvider class.
23  */
24
25 #include <FBaseSysLog.h>
26 #include <FLocLocation.h>
27 #include <FLocLocationProvider.h>
28 #include <FSecAccessController.h>
29 #include <FSec_AccessControlTypes.h>
30 #include "FLoc_LocationImpl.h"
31 #include "FLoc_LocationProviderImpl.h"
32
33 using namespace Tizen::Security;
34
35 namespace Tizen { namespace Locations
36 {
37
38 LocationProvider::LocationProvider(void)
39         : Tizen::Base::Object()
40         , __pImpl(null)
41 {
42 }
43
44 LocationProvider::~LocationProvider(void)
45 {
46         delete __pImpl;
47 }
48
49 result
50 LocationProvider::Construct(const LocationCriteria& criteria, ILocationProviderListener& listener)
51 {
52         SysAssertf(__pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
53
54         __pImpl = new (std::nothrow) _LocationProviderImpl();
55         SysTryReturnResult(NID_LOC, __pImpl, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
56
57         result r = __pImpl->Construct(criteria, listener);
58         SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to construct location Provider.", GetErrorMessage(r));
59
60         return E_SUCCESS;
61
62 CATCH:
63         delete __pImpl;
64         __pImpl = null;
65         return r;
66 }
67
68 result
69 LocationProvider::StartLocationUpdatesByInterval(int interval)
70 {
71         result r = AccessController::CheckPrivilege(_PRV_LOCATION);
72         SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
73
74         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
75
76         r = __pImpl->StartLocationUpdatesByInterval(interval);
77         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by interval.", GetErrorMessage(r));
78
79         return E_SUCCESS;
80 }
81
82 result
83 LocationProvider::StartLocationUpdatesByDistance(double distance)
84 {
85         result r = AccessController::CheckPrivilege(_PRV_LOCATION);
86         SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
87
88         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
89
90         r = __pImpl->StartLocationUpdatesByDistance(distance);
91         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by distance.", GetErrorMessage(r));
92
93         return E_SUCCESS;
94 }
95
96 result
97 LocationProvider::StopLocationUpdates(void)
98 {
99         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
100
101         result r = __pImpl->StopLocationUpdates();
102         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to stop the location updates.", GetErrorMessage(r));
103
104         return E_SUCCESS;
105 }
106
107 result
108 LocationProvider::KeepLocationUpdateAwake(bool enable)
109 {
110         result r = AccessController::CheckPrivilege(_PRV_LOCATION);
111         SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
112
113         r = AccessController::CheckPrivilege(_PRV_POWER);
114         SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
115
116         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
117
118         __pImpl->KeepLocationUpdateAwake(enable);
119         return E_SUCCESS;
120 }
121
122 result
123 LocationProvider::AddMonitoringRegion(const Coordinates& regionCenter, double radius, RegionId& regionId)
124 {
125         result r = AccessController::CheckPrivilege(_PRV_LOCATION);
126         SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
127
128         r = AccessController::CheckPrivilege(_PRV_POWER);
129         SysTryReturn(NID_LOC, r == E_SUCCESS, E_PRIVILEGE_DENIED, E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
130
131         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
132
133         r = __pImpl->AddMonitoringRegion(regionCenter, radius, regionId);
134         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to add monitoring region.", GetErrorMessage(r));
135
136         return E_SUCCESS;
137 }
138
139 result
140 LocationProvider::RemoveMonitoringRegion(RegionId regionId)
141 {
142         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
143
144         result r = __pImpl->RemoveMonitoringRegion(regionId);
145         SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to remove monitoring region with Id (%d).", GetErrorMessage(r), regionId);
146
147         return E_SUCCESS;
148 }
149
150 void
151 LocationProvider::RemoveAllMonitoringRegions(void)
152 {
153         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
154
155         return __pImpl->RemoveAllMonitoringRegions();
156 }
157
158 LocationServiceStatus
159 LocationProvider::GetLocationUpdateStatus(void) const
160 {
161         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
162
163         return __pImpl->GetLocationUpdateStatus();
164 }
165
166 LocationServiceStatus
167 LocationProvider::GetRegionMonitoringStatus(void) const
168 {
169         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
170
171         return __pImpl->GetRegionMonitoringStatus();
172 }
173
174 LocationAccuracy
175 LocationProvider::GetCurrentAccuracy(void) const
176 {
177         SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
178
179         return __pImpl->GetCurrentAccuracy();
180 }
181
182 Location
183 LocationProvider::GetLocation(const LocationCriteria& criteria)
184 {
185         result r = AccessController::CheckPrivilege(_PRV_LOCATION);
186         SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
187
188         return _LocationProviderImpl::GetLocation(criteria);
189 }
190
191 Location
192 LocationProvider::GetLastKnownLocation(void)
193 {
194         result r = AccessController::CheckPrivilege(_PRV_LOCATION);
195         SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), E_PRIVILEGE_DENIED, "[E_PRIVILEGE_DENIED] The application does not have the privilege to call this method.");
196
197         return _LocationProviderImpl::GetLastKnownLocation();
198 }
199
200
201 }}