|
1 /* |
|
2 * Copyright (c) 2002-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: |
|
15 * This file contains the methods which interface with Location Acquisition |
|
16 * API for getting location information |
|
17 * |
|
18 */ |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <evtmgmteditorui.rsg> |
|
22 #include <f32file.h> |
|
23 #include <sysutil.h> |
|
24 #include <lbs/epos_cposmoduleidlist.h> |
|
25 #include <lbs/epos_cposmodules.h> |
|
26 #include <aknnotewrappers.h> |
|
27 #include <eikenv.h> |
|
28 #include <StringLoader.h> |
|
29 #include <centralrepository.h> |
|
30 #include "locnotprefplugindomaincrkeys.h" |
|
31 #include "evtmgmtuilocationserviceadapter.h" |
|
32 #include "evteditorconsts.h" |
|
33 #include "evtdebug.h" |
|
34 |
|
35 // ---------------------------------------------------------------------------- |
|
36 // CEvtMgmtUiLocationServiceAdapter::NewL |
|
37 // Two-phased constructor. |
|
38 // ---------------------------------------------------------------------------- |
|
39 CEvtMgmtUiLocationServiceAdapter* CEvtMgmtUiLocationServiceAdapter::NewL( MEvtMgmtUiLocationServiceObserver& aObserver ) |
|
40 { |
|
41 CEvtMgmtUiLocationServiceAdapter* self = new ( ELeave ) CEvtMgmtUiLocationServiceAdapter( aObserver ); |
|
42 CleanupStack::PushL( self ); |
|
43 self->ConstructL(); |
|
44 CleanupStack::Pop(); // self |
|
45 return self; |
|
46 } |
|
47 |
|
48 // --------------------------------------------------------- |
|
49 // CEvtMgmtUiLocationServiceAdapter::~CEvtMgmtUiLocationServiceAdapter |
|
50 // --------------------------------------------------------- |
|
51 CEvtMgmtUiLocationServiceAdapter::~CEvtMgmtUiLocationServiceAdapter() |
|
52 { |
|
53 EVTUIDEBUG("+ CEvtMgmtUiLocationServiceAdapter::~CEvtMgmtUiLocationServiceAdapter()" ); |
|
54 Cancel(); |
|
55 iPositioner.Close(); |
|
56 iServer.Close(); |
|
57 EVTUIDEBUG("- CEvtMgmtUiLocationServiceAdapter::~CEvtMgmtUiLocationServiceAdapter()" ); |
|
58 } |
|
59 |
|
60 // --------------------------------------------------------- |
|
61 // CEvtMgmtUiLocationServiceAdapter::ConstructL |
|
62 // --------------------------------------------------------- |
|
63 void CEvtMgmtUiLocationServiceAdapter::ConstructL() |
|
64 { |
|
65 //conect to position server |
|
66 User::LeaveIfError(iServer.Connect()); |
|
67 |
|
68 //create subsesion with server |
|
69 User::LeaveIfError(iPositioner.Open( iServer )); |
|
70 |
|
71 //set timeout value |
|
72 TPositionUpdateOptions updateOptions; |
|
73 updateOptions.SetUpdateTimeOut( TTimeIntervalMicroSeconds(KLocAcqTimeOut)); |
|
74 User::LeaveIfError( iPositioner.SetUpdateOptions(updateOptions) ); |
|
75 |
|
76 //set requestor |
|
77 _LIT(KRequestorName, "LocationSerivce"); |
|
78 User::LeaveIfError( iPositioner.SetRequestor( |
|
79 CRequestor::ERequestorService, |
|
80 CRequestor::EFormatApplication, |
|
81 KRequestorName )); |
|
82 |
|
83 //add to active scheduler for asychrnous operation |
|
84 CActiveScheduler::Add( this ); |
|
85 } |
|
86 |
|
87 // ---------------------------------------------------------------------------- |
|
88 // CLmkLocationService::CLmkLocationService |
|
89 // C++ default constructor can NOT contain any code, that |
|
90 // might leave. |
|
91 // ---------------------------------------------------------------------------- |
|
92 CEvtMgmtUiLocationServiceAdapter::CEvtMgmtUiLocationServiceAdapter( MEvtMgmtUiLocationServiceObserver& aObserver ) |
|
93 : CActive(EPriorityStandard), iObserver( aObserver ) |
|
94 { |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------- |
|
98 // CEvtMgmtUiLocationServiceAdapter::LocationRequestL |
|
99 // It is used to request current location |
|
100 // --------------------------------------------------------- |
|
101 void CEvtMgmtUiLocationServiceAdapter::LocationRequestL() |
|
102 { |
|
103 EVTUIDEBUG("+ CEvtMgmtUiLocationServiceAdapter::LocationRequestL()" ); |
|
104 if ( IsActive() ) |
|
105 { |
|
106 User::Leave( KErrInUse ); |
|
107 } |
|
108 SetActive(); |
|
109 iStatus = KRequestPending; |
|
110 iPositioner.NotifyPositionUpdate( iPositionInfo, iStatus ); |
|
111 EVTUIDEBUG("- CEvtMgmtUiLocationServiceAdapter::LocationRequestL()" ); |
|
112 } |
|
113 |
|
114 // --------------------------------------------------------- |
|
115 // CEvtMgmtUiLocationServiceAdapter::CurrentPosition |
|
116 // It is used to retrieve current location |
|
117 // @ret Recently retrieved current location |
|
118 // --------------------------------------------------------- |
|
119 TPosition& CEvtMgmtUiLocationServiceAdapter::CurrentPosition() |
|
120 { |
|
121 return iPosition; |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------- |
|
125 // CEvtMgmtUiLocationServiceAdapter::AllPositionMethodsDisabled |
|
126 // Check if all positioning methods are disabled. |
|
127 // @ret true if disabled else false |
|
128 // --------------------------------------------------------- |
|
129 // |
|
130 TBool CEvtMgmtUiLocationServiceAdapter::AllPositionMethodsDisabledL() |
|
131 { |
|
132 CPosModules* moduleDb = CPosModules::OpenL(); |
|
133 CleanupStack::PushL(moduleDb); |
|
134 CPosModuleIdList* psyList = moduleDb->ModuleIdListL(); |
|
135 CleanupStack::PushL(psyList); |
|
136 |
|
137 TBool allDisabled =ETrue; |
|
138 |
|
139 TPositionModuleInfo moduleInfo; |
|
140 for(TInt index=0; index< psyList->Count(); index++) |
|
141 { |
|
142 TPositionModuleId moduleId = psyList->At( index ); |
|
143 TRAPD(error, moduleDb->GetModuleInfoL( moduleId, moduleInfo);); |
|
144 if(error == KErrNone ) |
|
145 { |
|
146 if( moduleInfo.IsAvailable() ) |
|
147 { |
|
148 allDisabled = EFalse; |
|
149 break; |
|
150 } |
|
151 } |
|
152 } |
|
153 |
|
154 CleanupStack::PopAndDestroy(2); // psyList, moduleDb |
|
155 return allDisabled; |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------- |
|
159 // CEvtMgmtUiLocationServiceAdapter::CancelRequest |
|
160 // It is used to cancel recently issued location request |
|
161 // --------------------------------------------------------- |
|
162 void CEvtMgmtUiLocationServiceAdapter::CancelRequest() |
|
163 { |
|
164 Cancel(); |
|
165 TRAP_IGNORE( iObserver.HandleLocationServiceErrorL( KErrCancel ) ); |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------- |
|
169 // CEvtMgmtUiLocationServiceAdapter::RunL |
|
170 // Derived from CActive |
|
171 // --------------------------------------------------------- |
|
172 void CEvtMgmtUiLocationServiceAdapter::RunL() |
|
173 { |
|
174 EVTUIDEBUG1("+ CEvtMgmtUiLocationServiceAdapter::RunL() - %d", iStatus.Int() ); |
|
175 |
|
176 //TInt err = KErrTimedOut; |
|
177 //switch ( err ) |
|
178 switch ( iStatus.Int() ) |
|
179 { |
|
180 case KErrNone: |
|
181 case KPositionPartialUpdate: |
|
182 { |
|
183 //retrieve current location information |
|
184 iPositionInfo.GetPosition( iPosition ); |
|
185 TReal32 altitude = iPosition.Altitude(); |
|
186 if ( Math::IsNaN( altitude ) ) |
|
187 { |
|
188 TRealX nan; |
|
189 nan.SetNaN(); |
|
190 iPosition.SetVerticalAccuracy( nan ); |
|
191 } |
|
192 |
|
193 //notify observer about successful completion of operation |
|
194 iObserver.HandleLocationServiceResponseL( iStatus.Int() ); |
|
195 break; |
|
196 } |
|
197 case KErrAccessDenied: |
|
198 case KPositionQualityLoss: |
|
199 case KErrTimedOut: |
|
200 case KErrNotFound: // No PSY selected. |
|
201 case KErrUnknown: |
|
202 case KErrCancel: |
|
203 case KErrArgument: |
|
204 default: |
|
205 { |
|
206 TRAP_IGNORE( iObserver.HandleLocationServiceErrorL( iStatus.Int() ) ); |
|
207 break; |
|
208 } |
|
209 } |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------- |
|
213 // CEvtMgmtUiLocationServiceAdapter::RunError |
|
214 // Derived from CActive |
|
215 // --------------------------------------------------------- |
|
216 // |
|
217 TInt CEvtMgmtUiLocationServiceAdapter::RunError(TInt aError) |
|
218 { |
|
219 TRAP_IGNORE( iObserver.HandleLocationServiceErrorL( aError ) ); |
|
220 return KErrNone; |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------- |
|
224 // CEvtMgmtUiLocationServiceAdapter::DoCancel |
|
225 // Derived from CActive |
|
226 // --------------------------------------------------------- |
|
227 // |
|
228 void CEvtMgmtUiLocationServiceAdapter::DoCancel() |
|
229 { |
|
230 EVTUIDEBUG("+ CEvtMgmtUiLocationServiceAdapter::DoCancel()" ); |
|
231 iPositioner.CancelRequest( EPositionerNotifyPositionUpdate ); |
|
232 EVTUIDEBUG("- CEvtMgmtUiLocationServiceAdapter::DoCancel()" ); |
|
233 } |
|
234 // End of File |