|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: This is SUPL PSY location requestor |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32cmn.h> |
|
22 #include <centralrepository.h> |
|
23 #include <lbsSuplPsyAdaptation.h> |
|
24 #include "suplpsyrequestor.h" |
|
25 #include "suplpsygenericinfouser.h" |
|
26 #include "suplpsylogging.h" |
|
27 #include "suplpsypanic.h" |
|
28 #include "suplpsy.hrh" |
|
29 |
|
30 // ===================== == == == == AL FUNCTIONS =============================== |
|
31 |
|
32 |
|
33 // ==================== == == == == BER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CSuplPsyRequestor::CSuplPsyRequestor |
|
37 // C++default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 CSuplPsyRequestor::CSuplPsyRequestor( const TCallBack& aObserver ) : |
|
42 iObserver( aObserver ), |
|
43 iFirstReq(ETrue), |
|
44 iPrevFixSuccess(EFalse), |
|
45 iRequestIdCount(0) |
|
46 { |
|
47 } |
|
48 |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CSuplPsyRequestor::ConstructL |
|
52 // Symbian 2nd phase constructor can leave. |
|
53 // ----------------------------------------------------------------------------- |
|
54 // |
|
55 void CSuplPsyRequestor::ConstructL() |
|
56 { |
|
57 TRACESTRING( "CSuplPsyRequestor::ConstructL start" ) |
|
58 |
|
59 //Create PSY Adapataion object |
|
60 iPsyAdaptation = CLbsSuplPsyAdaptation::NewL(*this); |
|
61 |
|
62 //Construct iPositionInfo; |
|
63 iPositionInfo = ConstructGenericInfoL(); |
|
64 |
|
65 CRepository *repository = CRepository::NewL(KCRUidSuplPsy); |
|
66 |
|
67 //TInt keyValue; |
|
68 |
|
69 TInt ret = repository->Get(KPSYTimeToNextFix, iTtnf); |
|
70 |
|
71 delete repository; |
|
72 repository = NULL; |
|
73 |
|
74 TRACESTRING( "CSuplPsyRequestor::ConstructL end" ) |
|
75 } |
|
76 |
|
77 // ----------------------------------------------------------------------------- |
|
78 // CSuplPsyRequestor::ConstructGenericInfoL |
|
79 // ----------------------------------------------------------------------------- |
|
80 // |
|
81 HPositionGenericInfo* CSuplPsyRequestor::ConstructGenericInfoL( |
|
82 TInt aBufferSize ) const |
|
83 { |
|
84 TRACESTRING( "CSuplPsyRequestor::ConstructGenericInfoL start" ) |
|
85 HPositionGenericInfo* positionInfo = HPositionGenericInfo::NewL( aBufferSize ); |
|
86 |
|
87 //Set all requested fields |
|
88 TInt count = SuplPsyGenericInfoUser::SupportedFieldsCount(); |
|
89 for ( TInt i = 0; i < count; i++ ) |
|
90 { |
|
91 positionInfo->SetRequestedField( |
|
92 SuplPsyGenericInfoUser::SupportedFieldAt( i ) ); |
|
93 } |
|
94 TRACESTRING( "CSuplPsyRequestor::ConstructGenericInfoL end" ) |
|
95 return positionInfo; |
|
96 } |
|
97 |
|
98 |
|
99 // ----------------------------------------------------------------------------- |
|
100 // CSuplPsyRequestor::NewL |
|
101 // Two - phased constructor. |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 CSuplPsyRequestor* CSuplPsyRequestor::NewL( |
|
105 const TCallBack& aObserver ) |
|
106 { |
|
107 CSuplPsyRequestor* self = new( ELeave ) CSuplPsyRequestor( aObserver ); |
|
108 |
|
109 CleanupStack::PushL( self ); |
|
110 self->ConstructL(); |
|
111 CleanupStack::Pop( self ); |
|
112 |
|
113 return self; |
|
114 } |
|
115 |
|
116 |
|
117 // ----------------------------------------------------------------------------- |
|
118 // CSuplPsyRequestor::~CSuplPsyRequestor |
|
119 // Destructor |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 CSuplPsyRequestor::~CSuplPsyRequestor() |
|
123 { |
|
124 //Cancel(); |
|
125 delete iPositionInfo; |
|
126 iPositionInfo = NULL; |
|
127 delete iPsyAdaptation; |
|
128 iPsyAdaptation = NULL; |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CSuplPsyRequestor::OnLocationUpdate |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 void CSuplPsyRequestor::OnLocationUpdate(TUint aRequestId, TPositionInfoBase& aPosition, TInt aReason) |
|
136 { |
|
137 TRACESTRING2( "CSuplPsyRequestor::OnLocationUpdate reason =%d", aReason ) |
|
138 |
|
139 if (iRequestId != aRequestId) |
|
140 aReason = KErrGeneral; |
|
141 |
|
142 iPosResult = aReason; |
|
143 |
|
144 //Call callback function |
|
145 if ( aReason >= KErrNone ) |
|
146 { |
|
147 //Get position info |
|
148 TRACESTRING( "Extracting position... " ) |
|
149 HPositionGenericInfo* posInfo = static_cast < HPositionGenericInfo*> ( &aPosition ); |
|
150 |
|
151 if ( aReason >= KErrNone ) |
|
152 { |
|
153 //Set module Id |
|
154 iPositionInfo->SetModuleId( TUid::Uid( KSuplPsyImplUid ) ); |
|
155 |
|
156 //Set time |
|
157 TPosition pos; |
|
158 posInfo->GetPosition( pos ); |
|
159 TTime now; |
|
160 now.UniversalTime(); |
|
161 pos.SetTime( now ); |
|
162 iPositionInfo->SetPosition( pos ); |
|
163 iPrevFixSuccess = ETrue; |
|
164 //posInfo = NULL; |
|
165 } |
|
166 else |
|
167 { |
|
168 //delete posInfo; |
|
169 //posInfo = NULL; |
|
170 iPrevFixSuccess = EFalse; |
|
171 } |
|
172 } |
|
173 iObserver.CallBack(); |
|
174 TRACESTRING( "CSuplPsyRequestor::OnLocationUpdate end" ) |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CSuplPsyRequestor::RequestLocation |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 void CSuplPsyRequestor::RequestLocation() |
|
182 { |
|
183 TRACESTRING( "CSuplPsyRequestor::RequestLocation start" ) |
|
184 |
|
185 // Check if the request is made withing TTNF, |
|
186 // if so return the previous computed position |
|
187 // if it was success |
|
188 |
|
189 if (!iFirstReq && iPrevFixSuccess) |
|
190 if (IsRequestInTtnf()) |
|
191 { |
|
192 iObserver.CallBack(); |
|
193 TRACESTRING( "Interval is within TTNF, returning. Returning Previous Position." ) |
|
194 return; |
|
195 } |
|
196 |
|
197 |
|
198 TRACESTRING( "Calling SUPL FW RunSession... " ) |
|
199 //Make location request |
|
200 iRequestId = GetRequestId(); |
|
201 |
|
202 const TUint KProtocolModuleUidValue = 0x102871EC; |
|
203 const TUid KProtocolModuleUid = { KProtocolModuleUidValue }; |
|
204 iPsyAdaptation->RequestLocationUpdate(iRequestId, ETrue, KProtocolModuleUid); |
|
205 if (iFirstReq) |
|
206 { |
|
207 iFirstReq = EFalse; |
|
208 } |
|
209 TRACESTRING( "CSuplPsyRequestor::RequestLocation end" ) |
|
210 } |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CSuplPsyRequestor::GetRequestResult |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 TInt CSuplPsyRequestor::GetRequestResult() |
|
217 { |
|
218 TRACESTRING( "CSuplPsyRequestor::GetRequestResult " ) |
|
219 return iPosResult; |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CSuplPsyRequestor::GetLocation |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 const HPositionGenericInfo& CSuplPsyRequestor::GetLocation() |
|
227 { |
|
228 TRACESTRING( "CSuplPsyRequestor::GetLocation " ) |
|
229 return *iPositionInfo; |
|
230 } |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CSuplPsyRequestor::ResetLastPosition |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 void CSuplPsyRequestor::ResetLastPosition() |
|
237 { |
|
238 // iPositionInfo->ClearPositionData(); |
|
239 } |
|
240 |
|
241 TBool CSuplPsyRequestor::IsRequestInTtnf() |
|
242 { |
|
243 TRACESTRING( "CSuplPsyRequestor::IsRequestInTtnf start" ) |
|
244 TTime now; |
|
245 now.UniversalTime(); |
|
246 |
|
247 TInt diff = 1000000; |
|
248 |
|
249 TPosition pos; |
|
250 |
|
251 iPositionInfo->GetPosition( pos ); |
|
252 |
|
253 TTimeIntervalSeconds secs; |
|
254 |
|
255 now.SecondsFrom(pos.Time(), secs); |
|
256 |
|
257 diff = diff * secs.Int(); |
|
258 |
|
259 TRACESTRING2( "Time diff. for request...:%d", diff ) |
|
260 if (diff <= iTtnf) |
|
261 return ETrue; |
|
262 |
|
263 TRACESTRING( "CSuplPsyRequestor::IsRequestInTtnf end" ) |
|
264 return EFalse; |
|
265 } |
|
266 |
|
267 void CSuplPsyRequestor::OnSessionComplete(TUint aRequestId, TInt aReason) |
|
268 { |
|
269 if (iRequestId != aRequestId) |
|
270 aReason = KErrGeneral; |
|
271 iPosResult = aReason; |
|
272 iObserver.CallBack(); |
|
273 } |
|
274 |
|
275 void CSuplPsyRequestor::Cancel() |
|
276 { |
|
277 TRACESTRING( "CSuplPsyRequestor::Cancel " ) |
|
278 iPsyAdaptation->CancelLocationRequest(iRequestId, KErrCancel); |
|
279 } |
|
280 |
|
281 TUint CSuplPsyRequestor::GetRequestId() |
|
282 { |
|
283 TRACESTRING( "CSuplPsyRequestor::GetRequestId " ) |
|
284 return iRequestIdCount++; |
|
285 } |
|
286 |
|
287 TVersion CSuplPsyRequestor::Version() |
|
288 { |
|
289 TRACESTRING( "CSuplPsyRequestor::Version " ) |
|
290 TVersion version; |
|
291 return version; |
|
292 } |
|
293 |
|
294 // End of File |