|
1 /* |
|
2 * Copyright (c) 2010 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: Implementation of positioning settings engine private class. |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "possettingsengineprivate.h" |
|
19 #include "possettingsengine.h" |
|
20 #include <qglobal.h> |
|
21 #include <epos_csuplsettings.h> |
|
22 #include <lbtcommon.h> |
|
23 #include <epos_cposmodules.h> |
|
24 #include <epos_cposmoduleidlist.h> |
|
25 #include <epos_cposmoduleupdate.h> |
|
26 |
|
27 //--------------------------------------------------------------------- |
|
28 // PosSettingsEnginePrivate::PosSettingsEnginePrivate() |
|
29 // (other items were commented in a header). |
|
30 //--------------------------------------------------------------------- |
|
31 PosSettingsEnginePrivate::PosSettingsEnginePrivate( |
|
32 PositionTechnologyChangeObserver& |
|
33 posTechChangeObserver): |
|
34 mPosTechChangeObserver( |
|
35 posTechChangeObserver ) |
|
36 { |
|
37 // Open session to LBT server. |
|
38 int error = mLbtServer.Connect(); |
|
39 if( error != KErrNone ) |
|
40 { |
|
41 throw( error ); |
|
42 } |
|
43 //Open subsession to LBT server. |
|
44 error = mLbtManager.Open( mLbtServer ); |
|
45 if( error != KErrNone ) |
|
46 { |
|
47 throw( error ); |
|
48 } |
|
49 QT_TRAP_THROWING( mSuplSettings = CSuplSettings::NewL(); |
|
50 mPosModules = CPosModules::OpenL(); |
|
51 |
|
52 populatePsyModuleInfoListL(); |
|
53 // Get back ground position status |
|
54 GetBackGroundPositioingStateL(); |
|
55 // Register for settings change. |
|
56 mPosModules->SetObserverL( *this ) |
|
57 ); |
|
58 } |
|
59 |
|
60 |
|
61 //--------------------------------------------------------------------- |
|
62 // PosSettingsEnginePrivate::~PosSettingsEnginePrivate() |
|
63 // (other items were commented in a header). |
|
64 //--------------------------------------------------------------------- |
|
65 PosSettingsEnginePrivate::~PosSettingsEnginePrivate() |
|
66 { |
|
67 mLbtManager.Close(); |
|
68 mLbtServer.Close(); |
|
69 delete mSuplSettings; |
|
70 mSuplSettings = NULL; |
|
71 // remove observer |
|
72 mPosModules->RemoveObserver(); |
|
73 delete mPosModules; |
|
74 mPosModules = NULL; |
|
75 |
|
76 mPsyModuleInfoList.Close(); |
|
77 } |
|
78 |
|
79 |
|
80 //--------------------------------------------------------------------- |
|
81 // PosSettingsEnginePrivate::isPositionTechnologyAvailable() |
|
82 // (other items were commented in a header). |
|
83 //--------------------------------------------------------------------- |
|
84 bool PosSettingsEnginePrivate::isPositionTechnologyAvailable( |
|
85 PositionTechnology posTechnology ) |
|
86 { |
|
87 // Iterate through the PSY list to find the specified position |
|
88 // technology. |
|
89 TInt cnt = mPsyModuleInfoList.Count(); |
|
90 for( TInt i=0;i<cnt;++i ) |
|
91 { |
|
92 if( mPsyModuleInfoList[i].mPosTech == posTechnology ) |
|
93 { |
|
94 return true; |
|
95 } |
|
96 } |
|
97 return false; |
|
98 } |
|
99 |
|
100 //--------------------------------------------------------------------- |
|
101 // PosSettingsEnginePrivate::setPositionTypeState() |
|
102 // (other items were commented in a header). |
|
103 //--------------------------------------------------------------------- |
|
104 int PosSettingsEnginePrivate::setPositionTechnologyState( |
|
105 State posTechnologyState, |
|
106 PositionTechnology posTechnology ) |
|
107 { |
|
108 // If the specified position technology is unavailable, return error. |
|
109 if( !isPositionTechnologyAvailable( posTechnology ) ) |
|
110 { |
|
111 return KErrNotFound; |
|
112 } |
|
113 |
|
114 int error = KErrNone; |
|
115 TRAP( error,setPositionTechnologyStateL( posTechnologyState,posTechnology ) ); |
|
116 return error; |
|
117 } |
|
118 |
|
119 //--------------------------------------------------------------------- |
|
120 // PosSettingsEnginePrivate::isPositionTechnologyEnabled() |
|
121 // (other items were commented in a header). |
|
122 //--------------------------------------------------------------------- |
|
123 bool PosSettingsEnginePrivate::isPositionTechnologyEnabled( |
|
124 PositionTechnology posTechnology ) |
|
125 { |
|
126 // Iterate through the PSY info list to find specified position |
|
127 // technology and its corresponding state. |
|
128 TInt cnt = mPsyModuleInfoList.Count(); |
|
129 for( TInt i=0;i<cnt;++i ) |
|
130 { |
|
131 if( mPsyModuleInfoList[i].mPosTech == posTechnology && |
|
132 mPsyModuleInfoList[i].mState == StateEnable ) |
|
133 { |
|
134 return true; |
|
135 } |
|
136 } |
|
137 return false; |
|
138 } |
|
139 |
|
140 //--------------------------------------------------------------------- |
|
141 // PosSettingsEnginePrivate::setBackGroundPositioningState() |
|
142 // (other items were commented in a header). |
|
143 //--------------------------------------------------------------------- |
|
144 int PosSettingsEnginePrivate::setBackGroundPositioningState( |
|
145 State backGroundPosState ) |
|
146 { |
|
147 // Check if any of the position technology are available. |
|
148 if( !mPsyModuleInfoList.Count() ) |
|
149 { |
|
150 return KErrNotSupported; |
|
151 } |
|
152 int error = KErrNone; |
|
153 // Change the state of back ground positioning only if its current |
|
154 // state is different from the requested state. |
|
155 if( backGroundPosState != mBackGroundPositioningState ) |
|
156 { |
|
157 TRAP( error,setBackGroundPositioningStateL( backGroundPosState ) ); |
|
158 } |
|
159 return error; |
|
160 } |
|
161 |
|
162 //--------------------------------------------------------------------- |
|
163 // PosSettingsEnginePrivate::isBackGroundPositioningEnabled() |
|
164 // (other items were commented in a header). |
|
165 //--------------------------------------------------------------------- |
|
166 bool PosSettingsEnginePrivate::isBackGroundPositioningEnabled() |
|
167 { |
|
168 if( mBackGroundPositioningState == StateEnable ) |
|
169 { |
|
170 return true; |
|
171 } |
|
172 return false; |
|
173 } |
|
174 |
|
175 //--------------------------------------------------------------------- |
|
176 // PosSettingsEnginePrivate::HandleSettingsChangeL() |
|
177 // (other items were commented in a header). |
|
178 //--------------------------------------------------------------------- |
|
179 void PosSettingsEnginePrivate::HandleSettingsChangeL( |
|
180 TPosModulesEvent aEvent ) |
|
181 { |
|
182 // Reset the module info list and repopulate again. |
|
183 mPsyModuleInfoList.Reset(); |
|
184 populatePsyModuleInfoListL(); |
|
185 |
|
186 if( aEvent.iType == EPosModulesEventModuleInstalled || aEvent.iType == EPosModulesEventModuleRemoved |
|
187 || aEvent.iType == EPosModulesEventVisibilityChanged ) |
|
188 { |
|
189 mPosTechChangeObserver.handlePositionTechnologyChange(); |
|
190 } |
|
191 } |
|
192 |
|
193 //--------------------------------------------------------------------- |
|
194 // PosSettingsEnginePrivate::setPositionTechnologyStateL() |
|
195 // (other items were commented in a header). |
|
196 //--------------------------------------------------------------------- |
|
197 void PosSettingsEnginePrivate::setPositionTechnologyStateL( |
|
198 State posTechnologyState, |
|
199 PositionTechnology posTechnology ) |
|
200 { |
|
201 CPosModuleUpdate* updateParams = CPosModuleUpdate::NewLC(); |
|
202 |
|
203 if( posTechnologyState == StateEnable ) |
|
204 { |
|
205 updateParams->SetUpdateAvailability( ETrue ); |
|
206 } |
|
207 else |
|
208 { |
|
209 updateParams->SetUpdateAvailability( EFalse ); |
|
210 } |
|
211 TInt cnt = mPsyModuleInfoList.Count(); |
|
212 for( TInt i=0;i<cnt;++i ) |
|
213 { |
|
214 // Change the state only if position technology of PSY matches |
|
215 // with the position technology specified and if the state of |
|
216 // the PSY is different from the requested state. |
|
217 if( mPsyModuleInfoList[i].mPosTech == posTechnology && |
|
218 mPsyModuleInfoList[i].mState != posTechnologyState ) |
|
219 { |
|
220 mPosModules->UpdateModuleL( mPsyModuleInfoList[i].mPsyModuleId, |
|
221 *updateParams ); |
|
222 mPsyModuleInfoList[i].mState = posTechnologyState; |
|
223 } |
|
224 } |
|
225 CleanupStack::PopAndDestroy( updateParams ); |
|
226 } |
|
227 |
|
228 //--------------------------------------------------------------------- |
|
229 // PosSettingsEnginePrivate::setBackGroundPositioningStateL() |
|
230 // (other items were commented in a header). |
|
231 //--------------------------------------------------------------------- |
|
232 void PosSettingsEnginePrivate::setBackGroundPositioningStateL( |
|
233 State backGroundPosState ) |
|
234 { |
|
235 if( backGroundPosState == StateEnable ) |
|
236 { |
|
237 mLbtManager.SetTriggeringMechanismStateL( |
|
238 ETriggeringMechanismOn ); |
|
239 User::LeaveIfError( mSuplSettings->SetSuplTriggeredServiceStatus( |
|
240 CSuplSettings::ESuplTriggerOn ) ); |
|
241 mBackGroundPositioningState = StateEnable; |
|
242 } |
|
243 else |
|
244 { |
|
245 mLbtManager.SetTriggeringMechanismStateL( |
|
246 ETriggeringMechanismOff ); |
|
247 User::LeaveIfError( mSuplSettings->SetSuplTriggeredServiceStatus( |
|
248 CSuplSettings::ESuplTriggerOff ) ); |
|
249 mBackGroundPositioningState = StateDisable; |
|
250 } |
|
251 } |
|
252 |
|
253 //--------------------------------------------------------------------- |
|
254 // PosSettingsEnginePrivate::populatePsyModuleInfoListL() |
|
255 // (other items were commented in a header). |
|
256 //--------------------------------------------------------------------- |
|
257 void PosSettingsEnginePrivate::populatePsyModuleInfoListL() |
|
258 { |
|
259 CPosModuleIdList* idList = mPosModules->ModuleIdListLC(); |
|
260 TInt cnt = idList->Count(); |
|
261 for ( TInt i = 0; i < cnt; ++i ) |
|
262 { |
|
263 TPositionModuleInfo moduleInfo; |
|
264 mPosModules->GetModuleInfoL( (*idList)[i], moduleInfo ); |
|
265 |
|
266 // Psy module info hold the information regarding PSY that are |
|
267 // essential for our operation. |
|
268 PsyModuleInfo psyModuleInfo; |
|
269 |
|
270 // Set the module Id. |
|
271 psyModuleInfo.mPsyModuleId = moduleInfo.ModuleId(); |
|
272 |
|
273 // Set position technology type. |
|
274 if( moduleInfo.TechnologyType() == TPositionModuleInfo::ETechnologyTerminal || |
|
275 moduleInfo.TechnologyType() == TPositionModuleInfo::ETechnologyAssisted ) |
|
276 { |
|
277 psyModuleInfo.mPosTech = PositionTechnologyGps; |
|
278 } |
|
279 else if ( moduleInfo.TechnologyType() == TPositionModuleInfo::ETechnologyNetwork ) |
|
280 { |
|
281 psyModuleInfo.mPosTech = PositionTechnologyNetwork; |
|
282 } |
|
283 |
|
284 // Set state of Psy. |
|
285 if( moduleInfo.IsAvailable() ) |
|
286 { |
|
287 psyModuleInfo.mState = StateEnable; |
|
288 } |
|
289 else |
|
290 { |
|
291 psyModuleInfo.mState = StateDisable; |
|
292 } |
|
293 |
|
294 mPsyModuleInfoList.Append( psyModuleInfo ); |
|
295 } |
|
296 CleanupStack::PopAndDestroy( idList ); |
|
297 } |
|
298 |
|
299 |
|
300 //--------------------------------------------------------------------- |
|
301 // PosSettingsEnginePrivate::GetBackGroundPositioingStateL() |
|
302 // (other items were commented in a header). |
|
303 //--------------------------------------------------------------------- |
|
304 void PosSettingsEnginePrivate::GetBackGroundPositioingStateL() |
|
305 { |
|
306 // Get the SUPL service status. |
|
307 CSuplSettings::TSuplTriggerStatus suplTriggerStatus; |
|
308 User::LeaveIfError( mSuplSettings->GetSuplTriggeredServiceStatus( |
|
309 suplTriggerStatus ) ); |
|
310 |
|
311 // Get LBT service status. |
|
312 TLbtTriggeringSystemManagementSettings triggeringSystemSettings; |
|
313 mLbtManager.GetTriggeringSystemSettingsL( triggeringSystemSettings ); |
|
314 |
|
315 // Back ground positioning state is considered to be enabled only |
|
316 // if both LBT and SUPL services are enabled. |
|
317 if( suplTriggerStatus == CSuplSettings::ESuplTriggerOn && |
|
318 triggeringSystemSettings.TriggeringMechanismState() == |
|
319 ETriggeringMechanismOn ) |
|
320 { |
|
321 mBackGroundPositioningState = StateEnable; |
|
322 } |
|
323 else |
|
324 { |
|
325 mBackGroundPositioningState = StateDisable; |
|
326 } |
|
327 } |
|
328 |
|
329 // End of file |