|
1 /* |
|
2 * Copyright (c) 2007-2008 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 * Implementation of utilities functions. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 //User includes |
|
22 #include "wsfdbobserver.h" |
|
23 #include "wsfaicontroller.h" |
|
24 #include "wsflogger.h" |
|
25 |
|
26 #include <featmgr.h> |
|
27 |
|
28 #include <wlandevicesettingsinternalcrkeys.h> |
|
29 #include <centralrepository.h> |
|
30 |
|
31 |
|
32 const TInt KWlanSettingsUiDefaultScanNetwork = 300; |
|
33 |
|
34 // --------------------------------------------------------- |
|
35 // CWlanPluginDbObserver::CWlanPluginDbObserver |
|
36 // Constructor |
|
37 // --------------------------------------------------------- |
|
38 CWsfDbObserver::CWsfDbObserver( ) |
|
39 : CActive( EPriorityNormal ), |
|
40 iOuterScanState( EFalse ) |
|
41 { |
|
42 } |
|
43 |
|
44 // --------------------------------------------------------- |
|
45 // CWlanPluginDbObserver::NewL |
|
46 // --------------------------------------------------------- |
|
47 CWsfDbObserver* CWsfDbObserver::NewL( ) |
|
48 { |
|
49 CWsfDbObserver* self = new ( ELeave ) CWsfDbObserver( ); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop(); |
|
53 return self; |
|
54 } |
|
55 |
|
56 // --------------------------------------------------------- |
|
57 // CWlanPluginDbObserver::ConstructL |
|
58 // --------------------------------------------------------- |
|
59 void CWsfDbObserver::ConstructL() |
|
60 { |
|
61 #ifndef __WINS__ // client is not available on wins |
|
62 iWlanMgmtClient = CWlanMgmtClient::NewL(); |
|
63 #endif |
|
64 |
|
65 FeatureManager::InitializeLibL(); |
|
66 |
|
67 CActiveScheduler::Add(this); |
|
68 |
|
69 } |
|
70 |
|
71 // --------------------------------------------------------- |
|
72 // CWlanPluginDbObserver::~CWlanPluginDbObserver |
|
73 // Destructor |
|
74 // --------------------------------------------------------- |
|
75 CWsfDbObserver::~CWsfDbObserver() |
|
76 { |
|
77 |
|
78 |
|
79 Cancel(); |
|
80 |
|
81 delete iRecord; |
|
82 |
|
83 delete iSession; |
|
84 |
|
85 delete iWlanMgmtClient; |
|
86 |
|
87 FeatureManager::UnInitializeLib(); |
|
88 } |
|
89 |
|
90 // --------------------------------------------------------- |
|
91 // CWlanPluginDbObserver::RunL |
|
92 // --------------------------------------------------------- |
|
93 void CWsfDbObserver::RunL() |
|
94 { |
|
95 LOG_ENTERFN( "CWsfDbObserver::RunL" ); |
|
96 //iSession->OpenTransactionL(); |
|
97 //iRecord->RefreshL( *iSession ); |
|
98 iRecord->LoadL( *iSession ); |
|
99 //iSession->CommitTransactionL(); |
|
100 |
|
101 //if scanning state changed start or stop the server |
|
102 TInt i = iRecord->iBgScanInterval; |
|
103 TInt j = iRecord->iSavedBgScanInterval; |
|
104 LOG_WRITEF( "CWsfDbObserver::RunL -- Bg:%d bg2:%d O:%d", i, j, iOuterScanState ); |
|
105 if ( iRecord->iBgScanInterval == 0 && iOuterScanState ) |
|
106 { |
|
107 LOG_WRITE( "CWsfDbObserver::RunL -- Scan disabled" ); |
|
108 iController->DisableScanL(); |
|
109 iOuterScanState = EFalse; |
|
110 } |
|
111 else if(iRecord->iBgScanInterval != 0 && !iOuterScanState ) |
|
112 { |
|
113 LOG_WRITE( "CWsfDbObserver::RunL -- Scan enabled" ); |
|
114 iController->EnableScanL(); |
|
115 iOuterScanState = ETrue; |
|
116 } |
|
117 |
|
118 SetActive(); |
|
119 |
|
120 iRecord->RequestNotification(*iSession,iStatus); |
|
121 |
|
122 } |
|
123 |
|
124 // --------------------------------------------------------- |
|
125 // CWlanPluginDbObserver::DoCancel |
|
126 // --------------------------------------------------------- |
|
127 void CWsfDbObserver::DoCancel() |
|
128 { |
|
129 |
|
130 iRecord->CancelNotification( *iSession, iStatus ); |
|
131 |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------- |
|
135 // CWlanPluginDbObserver::ActivateIt |
|
136 // --------------------------------------------------------- |
|
137 void CWsfDbObserver::ActivateItL() |
|
138 { |
|
139 |
|
140 iSession = CMDBSession::NewL( KCDLatestVersion ); |
|
141 |
|
142 TMDBElementId tableId = 0; |
|
143 |
|
144 tableId = CCDWlanDeviceSettingsRecord::TableIdL( *iSession ); |
|
145 |
|
146 iRecord = new( ELeave ) |
|
147 CCDWlanDeviceSettingsRecord( tableId ); |
|
148 |
|
149 iRecord->iWlanDeviceSettingsType = KWlanUserSettings; |
|
150 |
|
151 |
|
152 if(iRecord->FindL( *iSession )) |
|
153 { |
|
154 iRecord->LoadL( *iSession ); |
|
155 } |
|
156 |
|
157 if ( iRecord->iBgScanInterval != 0 ) |
|
158 { |
|
159 iController->EnableScanL(); |
|
160 iOuterScanState = ETrue; |
|
161 } |
|
162 SetActive(); |
|
163 |
|
164 iRecord->RequestNotification(*iSession,iStatus); |
|
165 |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------- |
|
169 // CWlanPluginDbObserver::SetController |
|
170 // --------------------------------------------------------- |
|
171 void CWsfDbObserver::SetController( TWsfAiController* aController ) |
|
172 { |
|
173 iController = aController; |
|
174 } |
|
175 |
|
176 // --------------------------------------------------------- |
|
177 // CWlanPluginDbObserver::EnableScanL |
|
178 // --------------------------------------------------------- |
|
179 void CWsfDbObserver::EnableScanL() |
|
180 { |
|
181 if( !iOuterScanState ) |
|
182 { |
|
183 iSession->OpenTransactionL(); |
|
184 iRecord->RefreshL( *iSession ); |
|
185 if ( iRecord->iBgScanInterval == 0 ) // not scanning |
|
186 { |
|
187 TInt j; |
|
188 j = iRecord->iSavedBgScanInterval; |
|
189 if( j == 0 ) |
|
190 { |
|
191 j = DefaultScanIntervalL(); |
|
192 } |
|
193 iRecord->iBgScanInterval = j; |
|
194 iRecord->ModifyL( *iSession ); |
|
195 iOuterScanState = ETrue; |
|
196 } |
|
197 iSession->CommitTransactionL(); |
|
198 #ifndef __WINS__ |
|
199 // Notifying WLAN Engine about changes in settings |
|
200 iWlanMgmtClient->NotifyChangedSettings(); |
|
201 #endif |
|
202 } |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------- |
|
206 // CWlanPluginDbObserver::DisableScanL |
|
207 // --------------------------------------------------------- |
|
208 void CWsfDbObserver::DisableScanL() |
|
209 { |
|
210 if( iOuterScanState ) |
|
211 { |
|
212 iSession->OpenTransactionL(); |
|
213 iRecord->RefreshL( *iSession ); |
|
214 if ( iRecord->iBgScanInterval != 0 ) // scanning |
|
215 { |
|
216 TInt i; |
|
217 i = iRecord->iBgScanInterval; |
|
218 iRecord->iBgScanInterval = 0; |
|
219 iRecord->iSavedBgScanInterval = i; |
|
220 iRecord->ModifyL( *iSession ); |
|
221 iOuterScanState = EFalse; |
|
222 } |
|
223 iSession->CommitTransactionL(); |
|
224 #ifndef __WINS__ |
|
225 // Notifying WLAN Engine about changes in settings |
|
226 iWlanMgmtClient->NotifyChangedSettings(); |
|
227 #endif |
|
228 } |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------- |
|
232 // CWlanPluginDbObserver::DefaultScanInterval |
|
233 // --------------------------------------------------------- |
|
234 TInt CWsfDbObserver::DefaultScanIntervalL() |
|
235 { |
|
236 TBool iPsmSupported = FeatureManager::FeatureSupported( KFeatureIdPowerSave ); |
|
237 if ( iPsmSupported ) |
|
238 { |
|
239 // Read the default value from CenRep (different in PSM mode) |
|
240 TInt defaultScanInterval( KWlanSettingsUiDefaultScanNetwork ); |
|
241 |
|
242 CRepository* repository = CRepository::NewLC( KCRUidWlanDeviceSettingsRegistryId ); |
|
243 if ( repository ) |
|
244 { |
|
245 repository->Get( KWlanDefaultBGScanInterval, defaultScanInterval ); |
|
246 } |
|
247 CleanupStack::PopAndDestroy( repository ); |
|
248 return defaultScanInterval; |
|
249 } |
|
250 else |
|
251 { |
|
252 return KWlanSettingsUiDefaultScanNetwork; |
|
253 } |
|
254 } |
|
255 |