1 /* |
|
2 * Copyright (c) 2002-2007 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: Notifies the changes in central repository values. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <centralrepository.h> |
|
22 #include "CSatCenRepChangeNotifier.h" |
|
23 #include "MSatSystemStateObserver.h" |
|
24 #include "Panic.h" |
|
25 #include "SatLog.h" |
|
26 |
|
27 // ============================ MEMBER FUNCTIONS =============================== |
|
28 |
|
29 // ----------------------------------------------------------------------------- |
|
30 // CSatCenRepChangeNotifier::CSatCenRepChangeNotifier |
|
31 // C++ default constructor can NOT contain any code, that |
|
32 // might leave. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CSatCenRepChangeNotifier::CSatCenRepChangeNotifier( |
|
36 const TUid& aCenRepCategory, |
|
37 TUint32 aCenRepId, |
|
38 MSatSystemStateObserver& aObserver, |
|
39 TInt aCenRepType ) : |
|
40 CActive( EPriorityStandard ), |
|
41 iObserver( aObserver ), |
|
42 iCenRepCategory( aCenRepCategory ), |
|
43 iCenRepId( aCenRepId ), |
|
44 iCenRepType( aCenRepType ) |
|
45 { |
|
46 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::\ |
|
47 CSatCenRepChangeNotifier calling" ) |
|
48 // Log parameters |
|
49 LOG2( NORMAL, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::\ |
|
50 CSatCenRepChangeNotifier Category: %d", aCenRepCategory ) |
|
51 LOG2( NORMAL, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::\ |
|
52 CSatCenRepChangeNotifier ID: %d", aCenRepId ) |
|
53 LOG2( NORMAL, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::\ |
|
54 CSatCenRepChangeNotifier Type: %d ", aCenRepType ) |
|
55 |
|
56 CActiveScheduler::Add( this ); |
|
57 |
|
58 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::\ |
|
59 CSatCenRepChangeNotifier exiting" ) |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CSatCenRepChangeNotifier::NewL |
|
64 // Two-phased constructor. |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CSatCenRepChangeNotifier* CSatCenRepChangeNotifier::NewL( |
|
68 const TUid& aCenRepCategory, |
|
69 TUint32 aCenRepId, |
|
70 MSatSystemStateObserver& aObserver, |
|
71 TInt aCenRepType ) |
|
72 { |
|
73 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::NewL calling" ) |
|
74 |
|
75 CSatCenRepChangeNotifier* self = |
|
76 new( ELeave ) CSatCenRepChangeNotifier( |
|
77 aCenRepCategory, aCenRepId, aObserver, aCenRepType ); |
|
78 |
|
79 CleanupStack::PushL( self ); |
|
80 self->ConstructL(); |
|
81 CleanupStack::Pop( self ); |
|
82 |
|
83 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::NewL exiting" ) |
|
84 return self; |
|
85 } |
|
86 |
|
87 |
|
88 // Destructor |
|
89 CSatCenRepChangeNotifier::~CSatCenRepChangeNotifier() |
|
90 { |
|
91 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::\ |
|
92 ~CSatCenRepChangeNotifier calling" ) |
|
93 |
|
94 Cancel(); |
|
95 if ( iCenRepClient ) |
|
96 { |
|
97 delete iCenRepClient; |
|
98 iCenRepClient = NULL; |
|
99 } |
|
100 |
|
101 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::\ |
|
102 ~CSatCenRepChangeNotifier exiting" ) |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CSatCenRepChangeNotifier::ConstructL |
|
107 // Creates central repository object. |
|
108 // (other items were commented in a header). |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void CSatCenRepChangeNotifier::ConstructL() |
|
112 { |
|
113 LOG( SIMPLE, |
|
114 "SATSYSTEMSTATE: CSatCenRepChangeNotifier::ConstructL calling" ) |
|
115 |
|
116 iCenRepClient = CRepository::NewL( iCenRepCategory ); |
|
117 |
|
118 LOG( SIMPLE, |
|
119 "SATSYSTEMSTATE: CSatCenRepChangeNotifier::ConstructL exiting" ) |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CSatCenRepChangeNotifier::NotifyChangeL |
|
124 // Issues notification request. |
|
125 // (other items were commented in a header). |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void CSatCenRepChangeNotifier::NotifyChangeL() |
|
129 { |
|
130 LOG( SIMPLE, |
|
131 "SATSYSTEMSTATE: CSatCenRepChangeNotifier::NotifyChangeL calling" ) |
|
132 |
|
133 __ASSERT_ALWAYS( !IsActive(), Panic( ESatSystemStateAllReadyActive ) ); |
|
134 ActivateL(); |
|
135 |
|
136 LOG( SIMPLE, |
|
137 "SATSYSTEMSTATE: CSatCenRepChangeNotifier::NotifyChangeL exiting" ) |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CSatCenRepChangeNotifier::CancelNotify |
|
142 // Cancels outstanding request. |
|
143 // (other items were commented in a header). |
|
144 // ----------------------------------------------------------------------------- |
|
145 // |
|
146 void CSatCenRepChangeNotifier::CancelNotify() |
|
147 { |
|
148 LOG( SIMPLE, |
|
149 "SATSYSTEMSTATE: CSatCenRepChangeNotifier::CancelNotify calling" ) |
|
150 |
|
151 Cancel(); |
|
152 |
|
153 LOG( SIMPLE, |
|
154 "SATSYSTEMSTATE: CSatCenRepChangeNotifier::CancelNotify exiting" ) |
|
155 } |
|
156 |
|
157 // ----------------------------------------------------------------------------- |
|
158 // CSatCenRepChangeNotifier::DoCancel |
|
159 // (other items were commented in a header). |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CSatCenRepChangeNotifier::DoCancel() |
|
163 { |
|
164 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::DoCancel calling" ) |
|
165 |
|
166 // Cancel all notifications. This causes notification mechanism to return |
|
167 // KInvalidNotificationId in the RunL function, so it must be handled there. |
|
168 iCenRepClient->NotifyCancelAll(); |
|
169 |
|
170 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::DoCancel exiting" ) |
|
171 } |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CSatCenRepChangeNotifier::RunL |
|
175 // Activates the request again and calls the observer. |
|
176 // (other items were commented in a header). |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void CSatCenRepChangeNotifier::RunL() |
|
180 { |
|
181 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::RunL calling" ) |
|
182 |
|
183 // In CenRep CRepository returns the key for the changed value in iStatus. |
|
184 const TUint32 cenRepId( iStatus.Int() ); |
|
185 LOG2( NORMAL, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::RunL \ |
|
186 iStatus: %d", iStatus.Int() ) |
|
187 // Makes sure that all the changes are notified. |
|
188 if ( KErrCancel != iStatus.Int() ) |
|
189 { |
|
190 ActivateL(); |
|
191 } |
|
192 |
|
193 // Check that notification came from that ID we are observing. |
|
194 if ( cenRepId == iCenRepId ) |
|
195 { |
|
196 LOG( SIMPLE, |
|
197 "SATSYSTEMSTATE: CSatCenRepChangeNotifier::RunL cenRepId == iCenRepId" ) |
|
198 switch ( iCenRepType ) |
|
199 { |
|
200 case ECRTypeInteger: |
|
201 { |
|
202 TInt value; |
|
203 iCenRepClient->Get( iCenRepId, value ); |
|
204 LOG2( NORMAL, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::RunL \ |
|
205 Notifying TInt value: %d", value ) |
|
206 iObserver.StateChanged( value ); |
|
207 break; |
|
208 } |
|
209 case ECRTypeReal: |
|
210 { |
|
211 TReal value; |
|
212 iCenRepClient->Get( iCenRepId, value ); |
|
213 LOG2( NORMAL, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::RunL \ |
|
214 Notifying TReal value: %d", value ) |
|
215 iObserver.StateChanged( value ); |
|
216 break; |
|
217 } |
|
218 case ECRTypeDesC8: |
|
219 { |
|
220 TBuf8<NCentralRepositoryConstants::KMaxBinaryLength> value; |
|
221 iCenRepClient->Get( iCenRepId, value ); |
|
222 LOG( NORMAL, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::RunL \ |
|
223 Notifying string value" ) |
|
224 iObserver.StateChanged( value ); |
|
225 break; |
|
226 } |
|
227 case ECRTypeDesC16: |
|
228 { |
|
229 TBuf16<NCentralRepositoryConstants::KMaxUnicodeStringLength> value; |
|
230 iCenRepClient->Get( iCenRepId, value ); |
|
231 LOG( NORMAL, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::RunL \ |
|
232 Notifying Unicode value" ) |
|
233 iObserver.StateChanged( value ); |
|
234 break; |
|
235 } |
|
236 case ECRTypeUnknown: |
|
237 default: |
|
238 { |
|
239 LOG( NORMAL, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::RunL \ |
|
240 Notifying without value" ) |
|
241 // If type is not defined, call StateChanged without parameters |
|
242 iObserver.StateChanged(); |
|
243 break; |
|
244 } |
|
245 } |
|
246 } |
|
247 |
|
248 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::RunL exiting" ) |
|
249 } |
|
250 |
|
251 // ----------------------------------------------------------------------------- |
|
252 // CSatCenRepChangeNotifier::ActivateL |
|
253 // (other items were commented in a header). |
|
254 // ----------------------------------------------------------------------------- |
|
255 // |
|
256 void CSatCenRepChangeNotifier::ActivateL() |
|
257 { |
|
258 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::ActivateL calling" ) |
|
259 |
|
260 // This request notifies all changes in this category, not just the one we |
|
261 // are observing. Thus we have to read the value from CenRep before |
|
262 // notification. |
|
263 User::LeaveIfError( iCenRepClient->NotifyRequest( iCenRepId, iStatus ) ); |
|
264 SetActive(); |
|
265 |
|
266 LOG( SIMPLE, "SATSYSTEMSTATE: CSatCenRepChangeNotifier::ActivateL exiting" ) |
|
267 } |
|
268 |
|
269 // End of File |
|