|
1 /* |
|
2 * Copyright (c) 2004-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: The Refresh handler to inform SAT refresses. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <centralrepository.h> |
|
22 #include <RSatRefresh.h> |
|
23 #include <BTSapDomainPSKeys.h> // BT SAP Central Repository key. |
|
24 #include <featmgr.h> |
|
25 |
|
26 #include "CSSSettingsRefreshHandler.h" |
|
27 #include "SSSettingsLogger.h" |
|
28 #include "CSSSettingsActiveObject.h" |
|
29 |
|
30 // ============================= LOCAL FUNCTIONS =============================== |
|
31 |
|
32 |
|
33 // CLASS DECLARATION |
|
34 |
|
35 /** |
|
36 * The Refresh notify observer info container. |
|
37 * |
|
38 * @lib SsSettings.lib |
|
39 * @since 2.6 |
|
40 */ |
|
41 class CSSSettingsNotifyInfo |
|
42 :public CBase |
|
43 { |
|
44 public: // Data |
|
45 |
|
46 // Refresh observer. |
|
47 MSSSettingsRefreshObserver* iObserver; |
|
48 |
|
49 // Observed file. |
|
50 TSatElementaryFiles iObservedFile; |
|
51 |
|
52 // Observed refresh type. |
|
53 TSatRefreshType iObservedRefreshType; |
|
54 }; |
|
55 |
|
56 |
|
57 |
|
58 // ============================ MEMBER FUNCTIONS =============================== |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CSSSettingsRefreshHandler::CSSSettingsRefreshHandler |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CSSSettingsRefreshHandler::CSSSettingsRefreshHandler() |
|
65 { |
|
66 } |
|
67 |
|
68 // ----------------------------------------------------------------------------- |
|
69 // CSSSettingsRefreshHandler::ConstructL |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 void CSSSettingsRefreshHandler::ConstructL() |
|
73 { |
|
74 __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::ConstructL"); |
|
75 iNotifyInfo = new ( ELeave ) CSSSettingsNotifyInfo; |
|
76 |
|
77 User::LeaveIfError ( iRSSSettings.Open() ); |
|
78 |
|
79 User::LeaveIfError ( iRCspCache.Open() ); |
|
80 |
|
81 iRSatSession.ConnectL(); |
|
82 |
|
83 iRSatRefresh = new ( ELeave ) RSatRefresh ( *this); |
|
84 iRSatRefresh->OpenL( iRSatSession ); |
|
85 iRSatRefresh->NotifyFileChangeL(); |
|
86 |
|
87 if ( FeatureManager::FeatureSupported ( KFeatureIdBtSap ) ) |
|
88 { |
|
89 //create the active object instance |
|
90 iBtSapNotifier = CSSSettingsActiveObject::NewL( |
|
91 KPSUidBluetoothSapConnectionState, |
|
92 KBTSapConnectionState, |
|
93 *this ); |
|
94 |
|
95 //subscribe for key event notifications |
|
96 iBtSapNotifier->NotifyKeyChange(); |
|
97 } |
|
98 __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::ConstructL"); |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CSSSettingsRefreshHandler::NewL |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 CSSSettingsRefreshHandler* CSSSettingsRefreshHandler::NewL() |
|
106 { |
|
107 __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::NewL"); |
|
108 CSSSettingsRefreshHandler* self = new( ELeave ) CSSSettingsRefreshHandler; |
|
109 |
|
110 CleanupStack::PushL( self ); |
|
111 self->ConstructL(); |
|
112 CleanupStack::Pop(); |
|
113 |
|
114 __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::NewL"); |
|
115 return self; |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CSSSettingsRefreshHandler::~CSSSettingsRefreshHandler |
|
120 // ----------------------------------------------------------------------------- |
|
121 // |
|
122 CSSSettingsRefreshHandler::~CSSSettingsRefreshHandler() |
|
123 { |
|
124 __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::~CSSSettingsRefreshHandler"); |
|
125 if ( iRSatRefresh ) |
|
126 { |
|
127 iRSatRefresh->Cancel(); |
|
128 iRSatRefresh->Close(); |
|
129 delete iRSatRefresh; |
|
130 iRSatRefresh = NULL; |
|
131 } |
|
132 iRSatSession.Close(); |
|
133 iRSSSettings.Close(); |
|
134 |
|
135 delete iNotifyInfo; |
|
136 iNotifyInfo = NULL; |
|
137 |
|
138 if ( FeatureManager::FeatureSupported ( KFeatureIdBtSap ) ) |
|
139 { |
|
140 if( iBtSapNotifier ) |
|
141 { |
|
142 iBtSapNotifier->CancelNotify(); |
|
143 } |
|
144 delete iBtSapNotifier; |
|
145 } |
|
146 |
|
147 iRCspCache.Close(); |
|
148 |
|
149 __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::~CSSSettingsRefreshHandler"); |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CSSSettingsRefreshHandler::NotifyFileChangeL |
|
154 // ----------------------------------------------------------------------------- |
|
155 // |
|
156 void CSSSettingsRefreshHandler::NotifyFileChangeL( |
|
157 MSSSettingsRefreshObserver& aObserver, |
|
158 TSatElementaryFiles aObservedFiles, |
|
159 TSatRefreshType aObservedRefreshType ) |
|
160 { |
|
161 __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::NotifyFileChangeL"); |
|
162 // Update variables. |
|
163 iNotifyInfo->iObserver = &aObserver; |
|
164 iNotifyInfo->iObservedFile = aObservedFiles; |
|
165 iNotifyInfo->iObservedRefreshType = aObservedRefreshType; |
|
166 __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::NotifyFileChangeL"); |
|
167 } |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CSSSettingsRefreshHandler::CancelNotify |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 void CSSSettingsRefreshHandler::CancelNotify() |
|
174 { |
|
175 iNotifyInfo->iObserver = NULL; |
|
176 } |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CSSSettingsRefreshHandler::ChangedCspTable |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 TInt CSSSettingsRefreshHandler::ChangedCspTable( |
|
183 TDes8& aChangedCsps, |
|
184 TDes8& aNewValues ) |
|
185 { |
|
186 __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::ChangedCspTable"); |
|
187 return iRCspCache.ChangedCspTable( |
|
188 aChangedCsps, |
|
189 aNewValues ); |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CSSSettingsRefreshHandler::AllowRefresh |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 TBool CSSSettingsRefreshHandler::AllowRefresh( |
|
197 TSatRefreshType aType, |
|
198 const TSatRefreshFiles& aFiles ) |
|
199 { |
|
200 __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::AllowRefresh"); |
|
201 return DoHandleRefresh( aType, aFiles, ESSSettingsAllowRefresh ); |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CSSSettingsRefreshHandler::Refresh |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 void CSSSettingsRefreshHandler::Refresh( |
|
209 TSatRefreshType aType, |
|
210 const TSatRefreshFiles& aFiles ) |
|
211 { |
|
212 __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::Refresh"); |
|
213 DoHandleRefresh( aType, aFiles, ESSSettingsRefresh ); |
|
214 __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::Refresh"); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CSSSettingsRefreshHandler::DoHandleRefresh |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 TBool CSSSettingsRefreshHandler::DoHandleRefresh( |
|
222 TSatRefreshType aType, |
|
223 const TSatRefreshFiles& aFiles, |
|
224 const TSSSettingsRefreshFunction aFunctionality ) |
|
225 { |
|
226 __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::DoHandleRefresh"); |
|
227 if ( aFunctionality == ESSSettingsRefresh ) |
|
228 { |
|
229 // Refresh handling needed only if the refresh has happened. |
|
230 iRCspCache.HandleRefresh(); |
|
231 iRSSSettings.HandleRefresh(); |
|
232 } |
|
233 |
|
234 // By default refresh is allowed. |
|
235 TBool allow(ETrue); |
|
236 |
|
237 // Handle only if there is observer. |
|
238 if ( iNotifyInfo->iObserver ) |
|
239 { |
|
240 // Handle only if observer wants to listen this event. |
|
241 if ( iNotifyInfo->iObservedRefreshType & aType ) |
|
242 { |
|
243 TInt changedFiles(0); |
|
244 // Only change notification will contain file list. |
|
245 if ( aType == EFileChangeNotification ) |
|
246 { |
|
247 if ( aFiles.Locate( KCspEf ) != KErrNotFound ) |
|
248 { |
|
249 changedFiles += KCspEf; |
|
250 } |
|
251 // Check if the changed files is what is wanted to be listened. |
|
252 changedFiles = changedFiles & iNotifyInfo->iObservedFile; |
|
253 } |
|
254 |
|
255 // For change notification the filelist must contain files, for |
|
256 // other refresh types it is empty. |
|
257 if ( ( aType != EFileChangeNotification ) || |
|
258 ( ( aType == EFileChangeNotification ) && |
|
259 changedFiles ) ) |
|
260 { |
|
261 if ( aFunctionality == ESSSettingsRefresh ) |
|
262 { |
|
263 // Inform the observer about the refresh event. |
|
264 iNotifyInfo->iObserver->Refresh( |
|
265 aType, |
|
266 ( TSatElementaryFiles ) changedFiles ); |
|
267 |
|
268 if ( aFiles.Locate( KCsp1Ef ) != KErrNotFound ) |
|
269 { |
|
270 iRSatRefresh->RefreshEFRead( ETrue ); |
|
271 } |
|
272 else if( aFiles.Locate( KCsp2Ef ) != KErrNotFound ) |
|
273 { |
|
274 iRSatRefresh->RefreshEFRead( ETrue ); |
|
275 } |
|
276 else |
|
277 { |
|
278 iRSatRefresh->RefreshEFRead( EFalse ); |
|
279 } |
|
280 } |
|
281 else // ESSSettingsAllowRefresh |
|
282 { |
|
283 // Inform the observer about the coming refresh event. |
|
284 allow = iNotifyInfo->iObserver->AllowRefresh( |
|
285 aType, |
|
286 ( TSatElementaryFiles ) changedFiles ); |
|
287 } |
|
288 } |
|
289 |
|
290 // If there is no client listening changed files SSSettings has to |
|
291 // check if some CSP file is into the list and send right response |
|
292 // since itself reads CSP files. |
|
293 if ( !changedFiles ) |
|
294 { |
|
295 if ( aFiles.Locate( KCsp1Ef ) != KErrNotFound ) |
|
296 { |
|
297 iRSatRefresh->RefreshEFRead( EFalse ); |
|
298 } |
|
299 else if( aFiles.Locate( KCsp2Ef ) != KErrNotFound ) |
|
300 { |
|
301 iRSatRefresh->RefreshEFRead( EFalse ); |
|
302 } |
|
303 else |
|
304 { |
|
305 iRSatRefresh->RefreshEFRead( ETrue ); |
|
306 } |
|
307 } |
|
308 __SSSLOGSTRING1("[SSS] DoHandleRefresh: changedFiles: %d", changedFiles); |
|
309 } |
|
310 else |
|
311 { |
|
312 iRSatRefresh->RefreshEFRead( EFalse ); |
|
313 } |
|
314 } |
|
315 |
|
316 if ( !iNotifyInfo->iObserver && ( aType == EFileChangeNotification |
|
317 || aType == ESimInitFileChangeNotification |
|
318 || aType == ESimInit ) ) |
|
319 { |
|
320 if ( aFiles.Locate( KCsp1Ef ) != KErrNotFound ) |
|
321 { |
|
322 iRSatRefresh->RefreshEFRead( EFalse ); |
|
323 } |
|
324 else if( aFiles.Locate( KCsp2Ef ) != KErrNotFound ) |
|
325 { |
|
326 iRSatRefresh->RefreshEFRead( EFalse ); |
|
327 } |
|
328 else |
|
329 { |
|
330 iRSatRefresh->RefreshEFRead( ETrue ); |
|
331 } |
|
332 } |
|
333 |
|
334 __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::DoHandleRefresh"); |
|
335 return allow; |
|
336 } |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // CSSSettingsRefreshHandler::HandlePubSubNotify |
|
340 // ----------------------------------------------------------------------------- |
|
341 // |
|
342 void CSSSettingsRefreshHandler::HandlePubSubNotify( const TUid aUid, |
|
343 const TUint32 aKeyId ) |
|
344 { |
|
345 __SSSLOGSTRING("[SSS]--> CSSSettingsRefreshHandler::HandlePubSubNotify"); |
|
346 if ( aUid == KPSUidBluetoothSapConnectionState && |
|
347 aKeyId == KBTSapConnectionState ) |
|
348 { |
|
349 TInt btSapState(EBTSapNotConnected); |
|
350 //get the current SAP state |
|
351 RProperty::Get( aUid, aKeyId, btSapState ); |
|
352 if ( btSapState == EBTSapNotConnected ) |
|
353 { |
|
354 // Refresh handling needed only if the BT SAP |
|
355 // state is not connected. |
|
356 iRCspCache.HandleRefresh(); |
|
357 iRSSSettings.HandleRefresh(); |
|
358 } |
|
359 __SSSLOGSTRING1("[SSS] HandlePubSubNotify: btSapState: %d", btSapState); |
|
360 } |
|
361 __SSSLOGSTRING("[SSS] <--CSSSettingsRefreshHandler::HandlePubSubNotify"); |
|
362 } |
|
363 |
|
364 |
|
365 // End of File |