|
1 /* |
|
2 * Copyright (c) 2005 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: SAP settings central repository event notifier. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 |
|
21 #include <e32std.h> |
|
22 #include <e32svr.h> |
|
23 #include <centralrepository.h> |
|
24 #include "CIMPSSAPNotifier.h" |
|
25 #include "mimpssapobserver.h" |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // These consts define cenrep Ids which when changed cause notification event. |
|
30 // For now it is the whole SAP Settings Id range for all access groups. |
|
31 const TUint32 KNotifyMask = 0x00000000; |
|
32 const TUint32 KNotifyIds = 0x00000000; |
|
33 |
|
34 const TUint32 KGroupMask = 0xFC000000; // SAP base id mask: 6 first bits |
|
35 const TUint32 KPECGroup = 0xC0000000; // do not modify |
|
36 const TUint32 KIMGroup = 0xC4000000; // do not modify |
|
37 |
|
38 // ============================ MEMBER FUNCTIONS =============================== |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CIMPSSAPNotifier::CIMPSSAPNotifier |
|
42 // C++ default constructor can NOT contain any code, that |
|
43 // might leave. |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 CIMPSSAPNotifier::CIMPSSAPNotifier( TInt aPriority ) : CActive( aPriority ) |
|
47 { |
|
48 CActiveScheduler::Add( this ); |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CIMPSSAPNotifier::ConstructL |
|
53 // Symbian 2nd phase constructor can leave. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 void CIMPSSAPNotifier::ConstructL( TUid aRepositoryUid ) |
|
57 { |
|
58 iRepository = CRepository::NewL( aRepositoryUid ); |
|
59 } |
|
60 |
|
61 // ----------------------------------------------------------------------------- |
|
62 // CIMPSSAPNotifier::NewL |
|
63 // Two-phased constructor. |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CIMPSSAPNotifier* CIMPSSAPNotifier::NewL( TInt aPriority, TUid aRepositoryUid ) |
|
67 { |
|
68 CIMPSSAPNotifier* self = new( ELeave ) CIMPSSAPNotifier( aPriority ); |
|
69 |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL( aRepositoryUid ); |
|
72 CleanupStack::Pop(); |
|
73 |
|
74 return self; |
|
75 } |
|
76 |
|
77 // Destructor |
|
78 CIMPSSAPNotifier::~CIMPSSAPNotifier() |
|
79 { |
|
80 Cancel(); |
|
81 iObservers.Close(); |
|
82 delete iRepository; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CIMPSSAPNotifier::AddObserverL() |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 void CIMPSSAPNotifier::AddObserverL( MIMPSSAPObserver* aObserver, |
|
90 TIMPSAccessGroup aGroup ) |
|
91 { |
|
92 if ( !aObserver ) |
|
93 { |
|
94 User::Leave( KErrArgument ); |
|
95 } |
|
96 |
|
97 TIMPSObserverTypePair obs( aObserver, aGroup ); |
|
98 |
|
99 iObservers.AppendL( obs ); |
|
100 if ( iObservers.Count() == 1 ) |
|
101 { |
|
102 RequestNotificationL(); // request only once |
|
103 } |
|
104 } |
|
105 |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CIMPSSAPNotifier::RemoveObserver() |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void CIMPSSAPNotifier::RemoveObserver( MIMPSSAPObserver* aObserver ) |
|
112 { |
|
113 if ( !aObserver ) |
|
114 { |
|
115 return; |
|
116 } |
|
117 TInt count( iObservers.Count() ); |
|
118 for ( TInt i( 0 ); i < count; i++ ) |
|
119 { |
|
120 if ( iObservers[ i ].Observer() == aObserver ) |
|
121 { |
|
122 iObservers.Remove( i ); |
|
123 } |
|
124 } |
|
125 |
|
126 if ( iObservers.Count() == 0 ) |
|
127 { |
|
128 //cancel any outstanding notification request |
|
129 Cancel(); |
|
130 } |
|
131 } |
|
132 |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CIMPSSAPNotifier::RunL() |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 void CIMPSSAPNotifier::RunL() |
|
139 { |
|
140 if ( iStatus != KErrCancel ) |
|
141 { |
|
142 NotifyObservers(); |
|
143 RequestNotificationL(); |
|
144 } |
|
145 } |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // CIMPSSAPNotifier::RunError() |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 TInt CIMPSSAPNotifier::RunError( TInt /*aError*/ ) |
|
152 { |
|
153 return KErrNone; |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CIMPSSAPNotifier::DoCancel() |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CIMPSSAPNotifier::DoCancel() |
|
161 { |
|
162 iRepository->NotifyCancelAll(); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CIMPSSAPNotifier::RequestNotificationL() |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 |
|
170 void CIMPSSAPNotifier::RequestNotificationL() |
|
171 { |
|
172 User::LeaveIfError( iRepository->NotifyRequest( KNotifyIds, KNotifyMask, |
|
173 iStatus ) ); |
|
174 SetActive(); // we have outstanding request now |
|
175 } |
|
176 |
|
177 |
|
178 // ----------------------------------------------------------------------------- |
|
179 // CIMPSSAPNotifier::NotifyObservers() |
|
180 // ----------------------------------------------------------------------------- |
|
181 // |
|
182 |
|
183 void CIMPSSAPNotifier::NotifyObservers() |
|
184 { |
|
185 TInt count( iObservers.Count() ); |
|
186 TUint32 completionValue( iStatus.Int() ); |
|
187 completionValue &= KGroupMask; |
|
188 |
|
189 for ( TInt ii( count ); --ii >= 0; ) |
|
190 { |
|
191 if ( completionValue == KPECGroup ) |
|
192 { |
|
193 if ( iObservers[ ii ].Group() == EIMPSPECAccessGroup ) |
|
194 { |
|
195 iObservers[ ii ].Observer()->HandleSAPEvent( |
|
196 MIMPSSAPObserver::ESAPSettingChanged ); |
|
197 } |
|
198 } |
|
199 |
|
200 else if ( completionValue == KIMGroup ) |
|
201 { |
|
202 if ( iObservers[ ii ].Group() == EIMPSIMAccessGroup ) |
|
203 { |
|
204 iObservers[ ii ].Observer()->HandleSAPEvent( |
|
205 MIMPSSAPObserver::ESAPSettingChanged ); |
|
206 } |
|
207 } |
|
208 else |
|
209 { |
|
210 // no notifications for unknown access groups |
|
211 } |
|
212 |
|
213 } |
|
214 } |
|
215 |
|
216 |
|
217 |
|
218 // End of File |