|
1 /* |
|
2 * Copyright (c) 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <s32mem.h> |
|
19 #include "casrvsession.h" |
|
20 #include "caentriesarray.h" |
|
21 #include "caarraycleanup.inl" |
|
22 #include "castorageproxy.h" |
|
23 #include "caidsarray.h" |
|
24 #include "cainnerentry.h" |
|
25 #include "cainnerquery.h" |
|
26 #include "casrvnotifier.h" |
|
27 #include "casrvdef.h" |
|
28 #include "cautils.h" |
|
29 #include "cainnernotifierfilter.h" |
|
30 |
|
31 const TInt KParamIndNotif = 3; |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 |
|
34 // --------------------------------------------------------- |
|
35 // |
|
36 // --------------------------------------------------------- |
|
37 // |
|
38 CCaSrvSession::~CCaSrvSession() |
|
39 { |
|
40 RHashMap<TInt, CCaSrvNotifier*>::TIter iter( iNotifiers ); |
|
41 while( iter.NextValue() ) |
|
42 { |
|
43 delete *iter.CurrentValue(); |
|
44 } |
|
45 iNotifiers.Close(); |
|
46 iStorageProxy.RemoveSession( this ); |
|
47 iCaSrv.DecreaseSessionCount(); |
|
48 delete iSerializedGetEntriesResult; |
|
49 delete iSerializedGetIdsResult; |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------- |
|
53 // |
|
54 // --------------------------------------------------------- |
|
55 // |
|
56 CCaSrvSession* CCaSrvSession::NewL( CCaSrv& aCaSrv ) |
|
57 { |
|
58 CCaSrvSession* self = new ( ELeave ) CCaSrvSession( aCaSrv ); |
|
59 CleanupStack::PushL( self ); |
|
60 self->ConstructL(); |
|
61 CleanupStack::Pop( self ); |
|
62 return self; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------- |
|
66 // |
|
67 // --------------------------------------------------------- |
|
68 // |
|
69 CCaSrvSession::CCaSrvSession( CCaSrv& aCaSrv ) : |
|
70 iCaSrv( aCaSrv ), iNotifiers(), |
|
71 iStorageProxy( *iCaSrv.GetStorageProxy() ) |
|
72 { |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------- |
|
76 // |
|
77 // --------------------------------------------------------- |
|
78 // |
|
79 void CCaSrvSession::ConstructL() |
|
80 { |
|
81 iCaSrv.IncreaseSessionCount(); |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------- |
|
85 // |
|
86 // --------------------------------------------------------- |
|
87 // |
|
88 void CCaSrvSession::ServiceL( const RMessage2& aMessage ) |
|
89 { |
|
90 TInt err( KErrNone ); |
|
91 TBool panicedClient( EFalse ); |
|
92 TRAP( err , DispatchMessageL( aMessage, panicedClient ) ); |
|
93 if( !panicedClient && aMessage.Function() |
|
94 != EContentArsenalNotifierNotify ) |
|
95 { |
|
96 aMessage.Complete( err ); |
|
97 } |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // |
|
102 // ----------------------------------------------------------------------------- |
|
103 // |
|
104 void CCaSrvSession::DispatchMessageL( const RMessage2& aMessage, |
|
105 TBool& aPanicedClient ) |
|
106 { |
|
107 switch( aMessage.Function() ) |
|
108 { |
|
109 case EContentArsenalGetList_GetSize: |
|
110 GetListSizeL( aMessage, EFull ); |
|
111 break; |
|
112 case EContentArsenalGetList_GetData: |
|
113 GetListDataL( aMessage ); |
|
114 break; |
|
115 case EContentArsenalGetIds_GetSize: |
|
116 GetListSizeL( aMessage, EIds ); |
|
117 break; |
|
118 case EContentArsenalGetIds_GetData: |
|
119 GetIdsDataL( aMessage ); |
|
120 break; |
|
121 case EContentArsenalAdd: |
|
122 AddL( aMessage ); |
|
123 break; |
|
124 case EContentArsenalRemove: |
|
125 RemoveL( aMessage ); |
|
126 break; |
|
127 case EContentArsenalOrganize: |
|
128 OrganizeL( aMessage ); |
|
129 break; |
|
130 case EContentArsenalTouch: |
|
131 TouchL( aMessage ); |
|
132 break; |
|
133 case EContentArsenalNotifierOpen: |
|
134 NewNotifierL( aMessage ); |
|
135 break; |
|
136 case EContentArsenalNotifierClose: |
|
137 RemoveNotifierL( aMessage ); |
|
138 break; |
|
139 case EContentArsenalNotifierNotify: |
|
140 NotifierL( aMessage.Int3() )->NotifyL( aMessage ); |
|
141 break; |
|
142 case EContentArsenalNotifierCancel: |
|
143 NotifierL( aMessage.Int3() )->Cancel(); |
|
144 break; |
|
145 case EContentArsenalGetChangeInfo: |
|
146 GetChangeInfoL( aMessage ); |
|
147 break; |
|
148 case EContentArsenalCustomSort: |
|
149 CustomSortL( aMessage ); |
|
150 break; |
|
151 default: |
|
152 aMessage.Panic( KCaSrvName, KErrArgument ); |
|
153 aPanicedClient = ETrue; |
|
154 break; |
|
155 } |
|
156 } |
|
157 |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CCaSrvSession::GetListSizeL( const RMessage2& aMessage, |
|
163 TGetListType aType ) |
|
164 { |
|
165 CCaInnerQuery* query = CCaInnerQuery::NewLC(); |
|
166 MenuUtils::InternalizeObjectL( aMessage, *query ); |
|
167 TInt size( 0 ); |
|
168 if( aType == EIds ) |
|
169 { |
|
170 size = GetIdsL( query ); |
|
171 } |
|
172 else |
|
173 { |
|
174 size = GetEntriesL( query ); |
|
175 } |
|
176 TPckg<TInt> sizeDes( size ); |
|
177 aMessage.WriteL( KOutputPosition, sizeDes ); |
|
178 CleanupStack::PopAndDestroy( query ); |
|
179 } |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // |
|
183 // --------------- -------------------------------------------------------------- |
|
184 // |
|
185 TInt CCaSrvSession::GetEntriesL( const CCaInnerQuery* aQuery ) |
|
186 { |
|
187 RCaEntriesArray resultContainer; |
|
188 CleanupResetAndDestroyPushL( resultContainer ); |
|
189 iStorageProxy.GetEntriesL( aQuery, resultContainer ); |
|
190 delete iSerializedGetEntriesResult; |
|
191 iSerializedGetEntriesResult = NULL; |
|
192 iSerializedGetEntriesResult = |
|
193 MenuUtils::MarshalDataL( resultContainer, KDefaultExpandSize ); |
|
194 CleanupStack::PopAndDestroy( &resultContainer ); |
|
195 return iSerializedGetEntriesResult->Size(); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 // --------------- -------------------------------------------------------------- |
|
201 // |
|
202 TInt CCaSrvSession::GetIdsL( const CCaInnerQuery* aQuery ) |
|
203 { |
|
204 RCaIdsArray resultContainer; |
|
205 CleanupClosePushL( resultContainer ); |
|
206 iStorageProxy.GetEntriesIdsL( aQuery, resultContainer ); |
|
207 delete iSerializedGetIdsResult; |
|
208 iSerializedGetIdsResult = NULL; |
|
209 iSerializedGetIdsResult = |
|
210 MenuUtils::MarshalDataL( resultContainer, KDefaultExpandSize ); |
|
211 CleanupStack::PopAndDestroy( &resultContainer ); |
|
212 return iSerializedGetIdsResult->Size(); |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 void CCaSrvSession::GetListDataL( const RMessage2& aMessage ) |
|
220 { |
|
221 aMessage.WriteL( KOutputPosition, iSerializedGetEntriesResult->Des() ); |
|
222 } |
|
223 |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 // ----------------------------------------------------------------------------- |
|
227 // |
|
228 void CCaSrvSession::GetIdsDataL( const RMessage2& aMessage ) |
|
229 { |
|
230 aMessage.WriteL( KOutputPosition, iSerializedGetIdsResult->Des() ); |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // |
|
235 // --------------- -------------------------------------------------------------- |
|
236 // |
|
237 void CCaSrvSession::AddL( const RMessage2& aMessage) |
|
238 { |
|
239 CCaInnerEntry* entry = CCaInnerEntry::NewLC(); |
|
240 MenuUtils::InternalizeObjectL( aMessage, *entry ); |
|
241 iStorageProxy.AddL( entry, entry->GetId() > 0 ); |
|
242 TPckg<TInt> resultId( entry->GetId() ); |
|
243 aMessage.WriteL( KOutputPosition, resultId ); |
|
244 CleanupStack::PopAndDestroy( entry ); |
|
245 } |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // |
|
249 // --------------- -------------------------------------------------------------- |
|
250 // |
|
251 void CCaSrvSession::RemoveL( const RMessage2& aMessage ) |
|
252 { |
|
253 RCaIdsArray entryIds; |
|
254 CleanupClosePushL( entryIds ); |
|
255 MenuUtils::InternalizeObjectL( aMessage, entryIds ); |
|
256 iStorageProxy.RemoveL( entryIds ); |
|
257 CleanupStack::PopAndDestroy( &entryIds ); |
|
258 } |
|
259 |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 // --------------- -------------------------------------------------------------- |
|
263 // |
|
264 void CCaSrvSession::OrganizeL( const RMessage2& aMessage ) |
|
265 { |
|
266 RCaIdsArray entryIds; |
|
267 CleanupClosePushL( entryIds ); |
|
268 MenuUtils::InternalizeObjectL( aMessage, entryIds ); |
|
269 TCaOperationParams operationParams; |
|
270 TPckg<TCaOperationParams> data( operationParams ); |
|
271 aMessage.Read( KInputPosition2, data ); |
|
272 iStorageProxy.OrganizeL( entryIds, operationParams ); |
|
273 CleanupStack::PopAndDestroy( &entryIds ); |
|
274 } |
|
275 |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 // --------------- -------------------------------------------------------------- |
|
279 // |
|
280 void CCaSrvSession::TouchL( const RMessage2& aMessage ) |
|
281 { |
|
282 CCaInnerEntry* entry = CCaInnerEntry::NewLC(); |
|
283 MenuUtils::InternalizeObjectL( aMessage, *entry ); |
|
284 |
|
285 iStorageProxy.TouchL( entry ); |
|
286 |
|
287 CleanupStack::PopAndDestroy( entry ); |
|
288 } |
|
289 |
|
290 // --------------------------------------------------------- |
|
291 // |
|
292 // --------------------------------------------------------- |
|
293 // |
|
294 void CCaSrvSession::NewNotifierL( const RMessage2& aMessage ) |
|
295 { |
|
296 CCaSrvNotifier* obj = CCaSrvNotifier::NewLC(); |
|
297 TInt handle = reinterpret_cast<TInt> ( obj ); |
|
298 //address pointer of obj is added as unique key in RHashMap |
|
299 iNotifiers.InsertL( handle, obj ); |
|
300 CleanupStack::Pop( obj ); // Now we manage the notifier by handle. |
|
301 TPckgC<TInt> handlePckg( handle ); |
|
302 TInt err = aMessage.Write( KParamIndNotif, handlePckg ); |
|
303 if( err ) |
|
304 { |
|
305 delete obj; |
|
306 iNotifiers.Remove( handle ); |
|
307 User::Leave( err ); |
|
308 } |
|
309 if( iNotifiers.Count() == 1 ) |
|
310 { |
|
311 iStorageProxy.AddSessionL( this ); |
|
312 } |
|
313 } |
|
314 |
|
315 // --------------------------------------------------------- |
|
316 // |
|
317 // --------------------------------------------------------- |
|
318 // |
|
319 CCaSrvNotifier* CCaSrvSession::NotifierL( TInt aHandle ) |
|
320 { |
|
321 CCaSrvNotifier** obj = iNotifiers.Find( aHandle ); |
|
322 if( !obj ) |
|
323 { |
|
324 User::Leave( KErrBadHandle ); |
|
325 } |
|
326 return *obj; |
|
327 } |
|
328 |
|
329 // --------------------------------------------------------- |
|
330 // |
|
331 // --------------------------------------------------------- |
|
332 // |
|
333 void CCaSrvSession::RemoveNotifierL( const RMessage2& aMessage ) |
|
334 { |
|
335 CCaSrvNotifier* notifier = NotifierL( aMessage.Int3() ); |
|
336 if( notifier ) |
|
337 { |
|
338 delete notifier; |
|
339 iNotifiers.Remove( aMessage.Int3() ); |
|
340 if( iNotifiers.Count() == 0 ) |
|
341 { |
|
342 iStorageProxy.RemoveSession( this ); |
|
343 } |
|
344 } |
|
345 } |
|
346 |
|
347 // --------------------------------------------------------- |
|
348 // |
|
349 // --------------------------------------------------------- |
|
350 // |
|
351 void CCaSrvSession::GetChangeInfoL( const RMessage2& aMessage ) |
|
352 { |
|
353 CCaSrvNotifier* notifier = NotifierL( aMessage.Int3() ); |
|
354 if( !notifier ) |
|
355 { |
|
356 User::Leave( KErrBadHandle ); |
|
357 } |
|
358 notifier->GetChangeInfoL( aMessage ); |
|
359 } |
|
360 |
|
361 // --------------------------------------------------------- |
|
362 // |
|
363 // --------------------------------------------------------- |
|
364 // |
|
365 void CCaSrvSession::CustomSortL( const RMessage2& aMessage ) |
|
366 { |
|
367 RCaIdsArray entryIds; |
|
368 CleanupClosePushL( entryIds ); |
|
369 MenuUtils::InternalizeObjectL( aMessage, entryIds ); |
|
370 |
|
371 TInt gruopId; |
|
372 TPckg<TInt> data( gruopId ); |
|
373 aMessage.Read( KInputPosition2, data ); |
|
374 |
|
375 iStorageProxy.CustomSortL( entryIds, gruopId ); |
|
376 CleanupStack::PopAndDestroy( &entryIds ); |
|
377 } |
|
378 |
|
379 // --------------------------------------------------------- |
|
380 // |
|
381 // --------------------------------------------------------- |
|
382 // |
|
383 void CCaSrvSession::EntryChanged( const CCaInnerEntry* aEntry, |
|
384 TChangeType aChangeType, const RArray<TInt>& aParentIds ) |
|
385 { |
|
386 RHashMap<TInt, CCaSrvNotifier*>::TIter iter( iNotifiers ); |
|
387 while( iter.NextValue() ) |
|
388 { |
|
389 TRAP_IGNORE( ( *iter.CurrentValue() )-> |
|
390 EntryChangedL( aEntry, aChangeType, aParentIds ) ); |
|
391 } |
|
392 } |
|
393 |
|
394 // --------------------------------------------------------- |
|
395 // |
|
396 // --------------------------------------------------------- |
|
397 // |
|
398 void CCaSrvSession::EntryTouched( TInt aId ) |
|
399 { |
|
400 RHashMap<TInt, CCaSrvNotifier*>::TIter iter( iNotifiers ); |
|
401 while( iter.NextValue() ) |
|
402 { |
|
403 TRAP_IGNORE( ( *iter.CurrentValue() )->EntryTouchedL( aId ) ); |
|
404 } |
|
405 } |
|
406 |
|
407 // --------------------------------------------------------- |
|
408 // CCaSrvSession::GroupContentChanged |
|
409 // --------------------------------------------------------- |
|
410 // |
|
411 void CCaSrvSession::GroupContentChanged( const RArray<TInt>& aParentIds ) |
|
412 { |
|
413 RHashMap<TInt, CCaSrvNotifier*>::TIter iter( iNotifiers ); |
|
414 while( iter.NextValue() ) |
|
415 { |
|
416 TRAP_IGNORE( ( *iter.CurrentValue() )-> |
|
417 GroupContentChangedL( aParentIds ) ); |
|
418 } |
|
419 } |
|
420 |
|
421 // End of File |