|
1 /* |
|
2 * Copyright (c) 2002-2006 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: CCFCacheElement class implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CFCacheElement.h" |
|
20 #include "CFContextObjectImpl.h" |
|
21 #include "cftrace.h" |
|
22 #include "cfcontextsourceinterface.h" |
|
23 |
|
24 // CONSTANTS |
|
25 |
|
26 #ifdef _DEBUG |
|
27 // Panic category |
|
28 _LIT( KPanicCat, "CONTEXTCACHE" ); |
|
29 |
|
30 // Panic codes |
|
31 enum TPanicReason |
|
32 { |
|
33 EInvalidSubscriptionIndex, |
|
34 }; |
|
35 |
|
36 // Local panic function |
|
37 LOCAL_C void Panic( TInt aCode ) |
|
38 { |
|
39 User::Panic( KPanicCat, aCode ); |
|
40 } |
|
41 #endif |
|
42 |
|
43 // MEMBER FUNCTIONS |
|
44 |
|
45 CCFCacheElement* CCFCacheElement::NewL() |
|
46 { |
|
47 FUNC_LOG; |
|
48 |
|
49 CCFCacheElement* self = CCFCacheElement::NewLC(); |
|
50 CleanupStack::Pop( self ); |
|
51 |
|
52 return self; |
|
53 } |
|
54 |
|
55 CCFCacheElement* CCFCacheElement::NewLC() |
|
56 { |
|
57 FUNC_LOG; |
|
58 |
|
59 CCFCacheElement* self = new( ELeave ) CCFCacheElement; |
|
60 CleanupStack::PushL( self ); |
|
61 self->ConstructL(); |
|
62 |
|
63 return self; |
|
64 } |
|
65 |
|
66 CCFCacheElement::~CCFCacheElement() |
|
67 { |
|
68 FUNC_LOG; |
|
69 |
|
70 delete iContext; |
|
71 iSubscriptions.Close(); |
|
72 } |
|
73 |
|
74 CCFCacheElement::CCFCacheElement() |
|
75 { |
|
76 FUNC_LOG; |
|
77 } |
|
78 |
|
79 void CCFCacheElement::ConstructL() |
|
80 { |
|
81 FUNC_LOG; |
|
82 |
|
83 iContext = CCFContextObject::NewL(); |
|
84 } |
|
85 |
|
86 // METHODS |
|
87 |
|
88 //----------------------------------------------------------------------------- |
|
89 // CCFCacheElement::Context |
|
90 //----------------------------------------------------------------------------- |
|
91 // |
|
92 CCFContextObject& CCFCacheElement::Context() const |
|
93 { |
|
94 FUNC_LOG; |
|
95 |
|
96 return *iContext; |
|
97 } |
|
98 |
|
99 //----------------------------------------------------------------------------- |
|
100 // CCFCacheElement::AddSubscriptionL |
|
101 //----------------------------------------------------------------------------- |
|
102 // |
|
103 void CCFCacheElement::AddSubscriptionL( |
|
104 CCFContextSubscriptionImpl& aSubscription ) |
|
105 { |
|
106 FUNC_LOG; |
|
107 |
|
108 iSubscriptions.AppendL( &aSubscription ); |
|
109 |
|
110 // notify context source if this was the first subscription |
|
111 if (iSubscriptions.Count() == 1 && iPublisher ) |
|
112 { |
|
113 iPublisher->Subscribers( iContext->Source(), iContext->Type() ); |
|
114 } |
|
115 } |
|
116 |
|
117 //----------------------------------------------------------------------------- |
|
118 // CCFCacheElement::RemoveSubscription |
|
119 //----------------------------------------------------------------------------- |
|
120 // |
|
121 void CCFCacheElement::RemoveSubscription( TInt aIndex ) |
|
122 { |
|
123 FUNC_LOG; |
|
124 |
|
125 __ASSERT_DEBUG( aIndex >= 0 && aIndex < iSubscriptions.Count(), |
|
126 Panic( EInvalidSubscriptionIndex ) ); |
|
127 |
|
128 iSubscriptions.Remove( aIndex ); |
|
129 |
|
130 // notify context source if this was the first subscription |
|
131 if (iSubscriptions.Count() == 0 && iPublisher ) |
|
132 { |
|
133 iPublisher->NoSubscribers( iContext->Source(), iContext->Type() ); |
|
134 } |
|
135 } |
|
136 |
|
137 //----------------------------------------------------------------------------- |
|
138 // CCFCacheElement::NullifySubscription |
|
139 //----------------------------------------------------------------------------- |
|
140 // |
|
141 void CCFCacheElement::NullifySubscription( TInt aIndex ) |
|
142 { |
|
143 FUNC_LOG; |
|
144 |
|
145 __ASSERT_DEBUG( aIndex >= 0 && aIndex < iSubscriptions.Count(), |
|
146 Panic( EInvalidSubscriptionIndex ) ); |
|
147 |
|
148 iSubscriptions[ aIndex ] = NULL; |
|
149 } |
|
150 |
|
151 //----------------------------------------------------------------------------- |
|
152 // CCFCacheElement::RemoveNullSubscriptions |
|
153 //----------------------------------------------------------------------------- |
|
154 // |
|
155 void CCFCacheElement::RemoveNullSubscriptions() |
|
156 { |
|
157 FUNC_LOG; |
|
158 |
|
159 TInt count = iSubscriptions.Count(); |
|
160 for ( TInt i = count - 1; i >= 0; --i ) |
|
161 { |
|
162 CCFContextSubscriptionImpl* subscription = iSubscriptions[ i ]; |
|
163 if ( !subscription ) |
|
164 { |
|
165 iSubscriptions.Remove( i ); |
|
166 } |
|
167 } |
|
168 |
|
169 // notify context source if no more subscriptions exist |
|
170 if ( count && iSubscriptions.Count() == 0 && iPublisher ) |
|
171 { |
|
172 iPublisher->NoSubscribers( iContext->Source(), iContext->Type() ); |
|
173 } |
|
174 } |
|
175 |
|
176 //----------------------------------------------------------------------------- |
|
177 // CCFCacheElement::Subscriptions |
|
178 //----------------------------------------------------------------------------- |
|
179 // |
|
180 const RPointerArray<CCFContextSubscriptionImpl>& CCFCacheElement::Subscriptions() const |
|
181 { |
|
182 FUNC_LOG; |
|
183 |
|
184 return iSubscriptions; |
|
185 } |
|
186 |
|
187 //----------------------------------------------------------------------------- |
|
188 // CCFCacheElement::SetReadSecurityPolicy |
|
189 //----------------------------------------------------------------------------- |
|
190 // |
|
191 void CCFCacheElement::SetReadSecurityPolicy( |
|
192 const TSecurityPolicy& aSecurityPolicy ) |
|
193 { |
|
194 FUNC_LOG; |
|
195 |
|
196 iReadSecurityPolicy = aSecurityPolicy; |
|
197 } |
|
198 |
|
199 //----------------------------------------------------------------------------- |
|
200 // CCFCacheElement::GetReadSecurityPolicy |
|
201 //----------------------------------------------------------------------------- |
|
202 // |
|
203 const TSecurityPolicy& CCFCacheElement::GetReadSecurityPolicy() const |
|
204 { |
|
205 FUNC_LOG; |
|
206 |
|
207 return iReadSecurityPolicy; |
|
208 } |
|
209 |
|
210 //----------------------------------------------------------------------------- |
|
211 // CCFCacheElement::SetWriteSecurityPolicy |
|
212 //----------------------------------------------------------------------------- |
|
213 // |
|
214 void CCFCacheElement::SetWriteSecurityPolicy( |
|
215 const TSecurityPolicy& aSecurityPolicy ) |
|
216 { |
|
217 FUNC_LOG; |
|
218 |
|
219 iWriteSecurityPolicy = aSecurityPolicy; |
|
220 } |
|
221 |
|
222 //----------------------------------------------------------------------------- |
|
223 // CCFCacheElement::GetWriteSecurityPolicy |
|
224 //----------------------------------------------------------------------------- |
|
225 // |
|
226 const TSecurityPolicy& CCFCacheElement::GetWriteSecurityPolicy() const |
|
227 { |
|
228 FUNC_LOG; |
|
229 |
|
230 return iWriteSecurityPolicy; |
|
231 } |
|
232 |
|
233 |
|
234 //----------------------------------------------------------------------------- |
|
235 // CCFCacheElement::SetContextPublisher |
|
236 //----------------------------------------------------------------------------- |
|
237 // |
|
238 void CCFCacheElement::SetContextPublisher( MCFContextSource* aPublisher ) |
|
239 { |
|
240 FUNC_LOG; |
|
241 |
|
242 iPublisher = aPublisher; |
|
243 } |
|
244 |
|
245 //----------------------------------------------------------------------------- |
|
246 // CCFCacheElement::SetContextPublisher |
|
247 //----------------------------------------------------------------------------- |
|
248 // |
|
249 void CCFCacheElement::SetContextPublisher( |
|
250 MCFContextSource* aPublisher, const TUid& aPublisherUid ) |
|
251 { |
|
252 FUNC_LOG; |
|
253 |
|
254 iPublisher = aPublisher; |
|
255 iPublisherUid = aPublisherUid; |
|
256 } |
|
257 |
|
258 //----------------------------------------------------------------------------- |
|
259 // CCFCacheElement::ContextPublisher |
|
260 //----------------------------------------------------------------------------- |
|
261 // |
|
262 const MCFContextSource* CCFCacheElement::ContextPublisher() const |
|
263 { |
|
264 FUNC_LOG; |
|
265 |
|
266 return iPublisher; |
|
267 } |
|
268 |
|
269 //----------------------------------------------------------------------------- |
|
270 // CCFCacheElement::PublisherUid |
|
271 //----------------------------------------------------------------------------- |
|
272 // |
|
273 const TUid& CCFCacheElement::PublisherUid() const |
|
274 { |
|
275 FUNC_LOG; |
|
276 |
|
277 return iPublisherUid; |
|
278 } |
|
279 |
|
280 |
|
281 //----------------------------------------------------------------------------- |
|
282 // CCFCacheElement::CompareByTypeAndSource |
|
283 //----------------------------------------------------------------------------- |
|
284 // |
|
285 TInt CCFCacheElement::CompareByTypeAndSource( |
|
286 const CCFCacheElement& aFirst, |
|
287 const CCFCacheElement& aSecond) |
|
288 { |
|
289 FUNC_LOG; |
|
290 |
|
291 return CCFContextObjectImpl::CompareByTypeAndSource( |
|
292 *aFirst.iContext, *aSecond.iContext ); |
|
293 } |
|
294 |
|
295 //----------------------------------------------------------------------------- |
|
296 // CCFCacheElement::CompareByType |
|
297 //----------------------------------------------------------------------------- |
|
298 // |
|
299 TInt CCFCacheElement::CompareByType( |
|
300 const CCFCacheElement& aFirst, |
|
301 const CCFCacheElement& aSecond) |
|
302 { |
|
303 FUNC_LOG; |
|
304 |
|
305 return CCFContextObjectImpl::CompareByType( |
|
306 *aFirst.iContext, *aSecond.iContext); |
|
307 } |