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
|
//
// 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 FLocLocationProvider.cpp
* @brief This is the implementation file for the %LocationProvider class.
*
* This header file contains the definitions of the %LocationProvider class.
*/
#include <FBaseSysLog.h>
#include <FLocLocation.h>
#include <FLocLocationProvider.h>
#include <FSec_AccessController.h>
#include <FSec_AccessControlTypes.h>
#include "FLoc_LocationImpl.h"
#include "FLoc_LocationProviderImpl.h"
using namespace Tizen::Security;
namespace Tizen { namespace Locations
{
LocationProvider::LocationProvider(void)
: Tizen::Base::Object()
, __pImpl(null)
{
}
LocationProvider::~LocationProvider(void)
{
delete __pImpl;
}
result
LocationProvider::Construct(const LocationCriteria& criteria, ILocationProviderListener& listener)
{
SysAssertf(__pImpl == null, "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
__pImpl = new (std::nothrow) _LocationProviderImpl();
SysTryReturnResult(NID_LOC, __pImpl, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
result r = __pImpl->Construct(criteria, listener);
SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to construct location Provider.", GetErrorMessage(r));
return E_SUCCESS;
CATCH:
delete __pImpl;
__pImpl = null;
return r;
}
result
LocationProvider::StartLocationUpdatesByInterval(int interval)
{
result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "The application is not permitted to call this method.");
SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
r = __pImpl->StartLocationUpdatesByInterval(interval);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by interval.", GetErrorMessage(r));
return E_SUCCESS;
}
result
LocationProvider::StartLocationUpdatesByDistance(double distance)
{
result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "The application is not permitted to call this method.");
SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
r = __pImpl->StartLocationUpdatesByDistance(distance);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to start the location updates by distance.", GetErrorMessage(r));
return E_SUCCESS;
}
result
LocationProvider::StopLocationUpdates(void)
{
SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
result r = __pImpl->StopLocationUpdates();
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to stop the location updates.", GetErrorMessage(r));
return E_SUCCESS;
}
result
LocationProvider::KeepLocationUpdateAwake(bool enable)
{
result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.",GetErrorMessage(r));
r = _AccessController::CheckUserPrivilege(_PRV_POWER);
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.");
SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
__pImpl->KeepLocationUpdateAwake(enable);
return E_SUCCESS;
}
result
LocationProvider::AddMonitoringRegion(const Coordinates& regionCenter, double radius, RegionId& regionId)
{
result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
SysTryReturnResult(NID_LOC, r == E_SUCCESS, r, "[%s] The application is not permitted to call this method.",GetErrorMessage(r));
r = _AccessController::CheckUserPrivilege(_PRV_POWER);
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.");
SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
r = __pImpl->AddMonitoringRegion(regionCenter, radius, regionId);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to add monitoring region.", GetErrorMessage(r));
return E_SUCCESS;
}
result
LocationProvider::RemoveMonitoringRegion(RegionId regionId)
{
SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
result r = __pImpl->RemoveMonitoringRegion(regionId);
SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to remove monitoring region with Id (%d).", GetErrorMessage(r), regionId);
return E_SUCCESS;
}
void
LocationProvider::RemoveAllMonitoringRegions(void)
{
SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
return __pImpl->RemoveAllMonitoringRegions();
}
LocationServiceStatus
LocationProvider::GetLocationUpdateStatus(void) const
{
SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
return __pImpl->GetLocationUpdateStatus();
}
LocationServiceStatus
LocationProvider::GetRegionMonitoringStatus(void) const
{
SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
return __pImpl->GetRegionMonitoringStatus();
}
LocationAccuracy
LocationProvider::GetCurrentAccuracy(void) const
{
SysAssertf(__pImpl != null, "Not yet constructed. Construct() should be called before use.");
return __pImpl->GetCurrentAccuracy();
}
Location
LocationProvider::GetLocation(const LocationCriteria& criteria)
{
result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
return _LocationProviderImpl::GetLocation(criteria);
}
Location
LocationProvider::GetLastKnownLocation(void)
{
result r = _AccessController::CheckUserPrivilege(_PRV_LOCATION);
r = TransExceptionsExclusive(r, E_PRIVILEGE_DENIED, E_USER_NOT_CONSENTED);
SysTryReturn(NID_LOC, r == E_SUCCESS, _LocationImpl::GetLocationInstance(), r, "[%s] The application is not permitted to call this method.", GetErrorMessage(r));
return _LocationProviderImpl::GetLastKnownLocation();
}
}}
|