|
1 /* |
|
2 * Copyright (c) 2000 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 policymanagement components |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDES |
|
20 |
|
21 #include "DMUtilObserver.h" |
|
22 #include "DMUtilActiveObserver.h" |
|
23 #include "PMUtilInternalCRKeys.h" |
|
24 #include "policymnginternalpskeys.h" |
|
25 #include "debug.h" |
|
26 |
|
27 #include <s32file.h> |
|
28 #include <centralrepository.h> |
|
29 #include <e32property.h> |
|
30 |
|
31 |
|
32 // CONSTANTS |
|
33 |
|
34 _LIT( KPolicyChangeCounterIni, "pcounter.ini"); |
|
35 _LIT( KRFSCounterIni, "rfscounter.ini"); |
|
36 |
|
37 // MACROS |
|
38 // DATA TYPES |
|
39 // FUNCTION PROTOTYPES |
|
40 // FORWARD DECLARATIONS |
|
41 |
|
42 namespace ObserverUtils |
|
43 { |
|
44 TBool CheckValueL( const TDesC& aFile, const TUint32& aCentRepKey) |
|
45 { |
|
46 TBool retVal = EFalse; |
|
47 CRepository* repository = CRepository::NewLC( KCRUidPolicyManagementUtilInternalKeys); |
|
48 |
|
49 //get counter value from central repository |
|
50 TInt counterPreValue(0); |
|
51 TInt counterRealValue(0); |
|
52 User::LeaveIfError( repository->Get( aCentRepKey, counterRealValue)); |
|
53 CleanupStack::PopAndDestroy( repository); |
|
54 |
|
55 //create binary presentation for values |
|
56 TPckg<TInt> realCounterPack( counterRealValue); |
|
57 TPckg<TInt> preCounterPack( counterPreValue); |
|
58 |
|
59 //Open file |
|
60 RFs rfs; |
|
61 User::LeaveIfError( rfs.Connect()); |
|
62 CleanupClosePushL( rfs); |
|
63 |
|
64 RFile file; |
|
65 CleanupClosePushL( file); |
|
66 TBuf<100> fullName; |
|
67 User::LeaveIfError( rfs.PrivatePath( fullName)); |
|
68 fullName.Append( aFile); |
|
69 |
|
70 TInt err = file.Open( rfs, fullName, EFileRead|EFileWrite); |
|
71 |
|
72 if ( err == KErrPathNotFound) |
|
73 { |
|
74 //create private path if not exists |
|
75 User::LeaveIfError( rfs.CreatePrivatePath( EDriveC)); |
|
76 err = KErrNotFound; |
|
77 } |
|
78 |
|
79 if ( err == KErrNotFound) |
|
80 { |
|
81 //create file with current counter value |
|
82 User::LeaveIfError( file.Create( rfs, fullName, EFileRead|EFileWrite)); |
|
83 User::LeaveIfError( file.Write( realCounterPack)); |
|
84 User::LeaveIfError( file.Flush()); |
|
85 } |
|
86 else |
|
87 { |
|
88 //read pre-counter value |
|
89 User::LeaveIfError( err); |
|
90 User::LeaveIfError( file.Read( preCounterPack)); |
|
91 |
|
92 |
|
93 if ( counterPreValue != counterRealValue) |
|
94 { |
|
95 //if counter values has changed, changes return value and update pre-value... |
|
96 retVal = ETrue; |
|
97 TInt offset(0); |
|
98 User::LeaveIfError( file.Seek( ESeekStart, offset)); |
|
99 User::LeaveIfError( file.Write( realCounterPack)); |
|
100 User::LeaveIfError( file.Flush()); |
|
101 } |
|
102 |
|
103 } |
|
104 |
|
105 //close sessions |
|
106 CleanupStack::PopAndDestroy( 2, &rfs); |
|
107 |
|
108 return retVal; |
|
109 } |
|
110 } |
|
111 |
|
112 // ----------------------------------------------------------------------------- |
|
113 // TDMUtilPassiveObserver::IsPolicyChangedL |
|
114 // ----------------------------------------------------------------------------- |
|
115 // |
|
116 |
|
117 EXPORT_C TBool TDMUtilPassiveObserver::IsPolicyChangedL() |
|
118 { |
|
119 return ObserverUtils::CheckValueL( KPolicyChangeCounterIni, KPolicyChangeCounter); |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // TDMUtilStaticObserver::IsRFSPerformedL |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 |
|
127 EXPORT_C TBool TDMUtilPassiveObserver::IsRFSPerformedL() |
|
128 { |
|
129 return ObserverUtils::CheckValueL( KRFSCounterIni, KRFSCounterKey ); |
|
130 } |
|
131 |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CDMUtilActiveObserver::CDMUtilActiveObserver |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 |
|
138 CDMUtilActiveObserver::CDMUtilActiveObserver() |
|
139 : iActiveObserver(0) |
|
140 { |
|
141 |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CDMUtilActiveObserver::~CDMUtilActiveObserver |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 |
|
149 CDMUtilActiveObserver::~CDMUtilActiveObserver() |
|
150 { |
|
151 delete iActiveObserver; |
|
152 } |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CDMUtilActiveObserver::NewL |
|
156 // ----------------------------------------------------------------------------- |
|
157 // |
|
158 EXPORT_C CDMUtilActiveObserver* CDMUtilActiveObserver::NewL( TPolicyManagementEventTypes aType) |
|
159 { |
|
160 CDMUtilActiveObserver* self = new (ELeave) CDMUtilActiveObserver(); |
|
161 CleanupStack::PushL( self); |
|
162 self->iActiveObserver = CActiveObserver::NewL( aType); |
|
163 |
|
164 CleanupStack::Pop( self); |
|
165 return self; |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CDMUtilActiveObserver::SubscribeEventL |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 EXPORT_C void CDMUtilActiveObserver::SubscribeEventL( MActiveCallBackObserver* aDynamicCallBackObserver) |
|
173 { |
|
174 iActiveObserver->SubscribeEventL( aDynamicCallBackObserver); |
|
175 } |
|
176 |
|
177 // ----------------------------------------------------------------------------- |
|
178 // CDMUtilActiveObserver::UnSubscribeEventL |
|
179 // ----------------------------------------------------------------------------- |
|
180 // |
|
181 EXPORT_C void CDMUtilActiveObserver::UnSubscribeEvent() |
|
182 { |
|
183 iActiveObserver->UnSubscribeEvent(); |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CActiveObserver::CActiveObserver |
|
188 // ----------------------------------------------------------------------------- |
|
189 // |
|
190 |
|
191 CActiveObserver::CActiveObserver( TPolicyManagementEventTypes aType) |
|
192 : CActive(0), type( aType), iSubscribed( 0) |
|
193 { |
|
194 |
|
195 } |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CActiveObserver::~CActiveObserver |
|
199 // ----------------------------------------------------------------------------- |
|
200 // |
|
201 |
|
202 CActiveObserver::~CActiveObserver() |
|
203 { |
|
204 iProperty.Close(); |
|
205 iSubcribers.Close(); |
|
206 Deque(); |
|
207 } |
|
208 |
|
209 // ----------------------------------------------------------------------------- |
|
210 // CActiveObserver::NewL |
|
211 // ----------------------------------------------------------------------------- |
|
212 // |
|
213 |
|
214 CActiveObserver* CActiveObserver::NewL( TPolicyManagementEventTypes aType) |
|
215 { |
|
216 CActiveObserver* self = new (ELeave) CActiveObserver( aType); |
|
217 return self; |
|
218 } |
|
219 |
|
220 // ----------------------------------------------------------------------------- |
|
221 // CActiveObserver::SubscribeEventL |
|
222 // ----------------------------------------------------------------------------- |
|
223 // |
|
224 void CActiveObserver::SubscribeEventL( MActiveCallBackObserver* aDynamicCallBackObserver) |
|
225 { |
|
226 //add subsribers info to list |
|
227 iSubcribers.Append( aDynamicCallBackObserver); |
|
228 |
|
229 if ( !iSubscribed) |
|
230 { |
|
231 //subscribe event |
|
232 TUint32 key = SubscribeKey( type); |
|
233 iProperty.Attach( KPolicyMngProperty, key); |
|
234 iProperty.Subscribe( iStatus); |
|
235 |
|
236 //init.... |
|
237 CActiveScheduler::Add( this); |
|
238 SetActive(); |
|
239 } |
|
240 |
|
241 iSubscribed = ETrue; |
|
242 } |
|
243 |
|
244 |
|
245 // ----------------------------------------------------------------------------- |
|
246 // CActiveObserver::UnSubscribeEventL |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 TUint32 CActiveObserver::SubscribeKey( TPolicyManagementEventTypes aType) |
|
250 { |
|
251 TUint32 retVal = 0; |
|
252 |
|
253 switch ( aType) |
|
254 { |
|
255 case EPolicyChangedEvent: |
|
256 retVal = KPolicyChangedCounter; |
|
257 break; |
|
258 default: |
|
259 break; |
|
260 } |
|
261 |
|
262 return retVal; |
|
263 } |
|
264 |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // CActiveObserver::UnSubscribeEventL |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 void CActiveObserver::UnSubscribeEvent() |
|
271 { |
|
272 DoCancel(); |
|
273 iSubscribed = EFalse; |
|
274 } |
|
275 |
|
276 |
|
277 // ----------------------------------------------------------------------------- |
|
278 // CActiveObserver::UnSubscribeEventL |
|
279 // ----------------------------------------------------------------------------- |
|
280 // |
|
281 void CActiveObserver::RunL() |
|
282 { |
|
283 //notify subscribers.... |
|
284 for ( TInt i(0); i < iSubcribers.Count(); i++) |
|
285 { |
|
286 iSubcribers[i]->EventLaunchedL(); |
|
287 } |
|
288 |
|
289 //subscribe again... |
|
290 SetActive(); |
|
291 iProperty.Subscribe( iStatus); |
|
292 } |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CActiveObserver::DoCancel |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 void CActiveObserver::DoCancel() |
|
299 { |
|
300 iProperty.Close(); |
|
301 iSubcribers.Reset(); |
|
302 } |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 |