|
1 /* |
|
2 * Copyright (c) 2002-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: |
|
15 * handler class for imps fundemental feature. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "impsfundcli.h" |
|
22 #include "impsfundhandler.h" |
|
23 #include "impsutils.h" |
|
24 #include "impscdatautils.h" |
|
25 #include "impserrors.h" |
|
26 #include "impscommonenums.h" |
|
27 |
|
28 // MACROS |
|
29 #ifndef _DEBUG |
|
30 #define _NO_IMPS_LOGGING_ |
|
31 #endif |
|
32 |
|
33 // ================= MEMBER FUNCTIONS ======================= |
|
34 |
|
35 // ---------------------------------------------------------------------------- |
|
36 // CImpsFundHandler2::CImpsFundHandler2 |
|
37 // ---------------------------------------------------------------------------- |
|
38 CImpsFundHandler2::CImpsFundHandler2( TInt aPriority, RImpsFundClient2& aClient ): |
|
39 // The base class adds this to the scheduler |
|
40 CImpsHandler2( aPriority, aClient), iClient( aClient ) |
|
41 { |
|
42 } |
|
43 |
|
44 // ---------------------------------------------------------------------------- |
|
45 // CImpsFundHandler2::NewL |
|
46 // ---------------------------------------------------------------------------- |
|
47 CImpsFundHandler2* CImpsFundHandler2::NewL( RImpsFundClient2& aClient, |
|
48 TInt aPriority ) |
|
49 { |
|
50 CImpsFundHandler2* self = new (ELeave) CImpsFundHandler2( aPriority , |
|
51 aClient); |
|
52 CleanupStack::PushL( self ); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop( self ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 // ---------------------------------------------------------------------------- |
|
59 // CImpsFundHandler2::~CImpsFundHandler2 |
|
60 // ---------------------------------------------------------------------------- |
|
61 CImpsFundHandler2::~CImpsFundHandler2() |
|
62 { |
|
63 delete iDataAccessor; |
|
64 delete iKey; |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // CImpsFundHandler2::HandleEventL |
|
69 // ---------------------------------------------------------------------------- |
|
70 void CImpsFundHandler2::HandleEventL( CImpsFields* aErrorFields ) |
|
71 { |
|
72 // get the event data from server thread. |
|
73 SImpsEventData* event = (SImpsEventData*)iEventData.Ptr(); |
|
74 #ifndef _NO_IMPS_LOGGING_ |
|
75 CImpsClientLogger::Log(_L("CImpsFundHandler2::HandleEventL opid=%d cli=%d"), |
|
76 event->iOpCode, (TInt)&iClient ); |
|
77 #endif |
|
78 if ( event->iStatus != ( Imps_ERROR_BASE - 200 ) && |
|
79 event->iStatus != KErrNone ) |
|
80 { |
|
81 HandleErrorEventL( event->iOpCode, event->iStatus, aErrorFields ); |
|
82 } |
|
83 // Call regular observer |
|
84 // iStatus is error code or message size |
|
85 else if ( iStatus >= 0 ) |
|
86 { |
|
87 HandleFundamentalEventL( ); |
|
88 } |
|
89 } |
|
90 |
|
91 // ---------------------------------------------------------------------------- |
|
92 // CImpsFundHandler2::HandleFundamentalEventL |
|
93 // ---------------------------------------------------------------------------- |
|
94 void CImpsFundHandler2::HandleFundamentalEventL( ) |
|
95 { |
|
96 // get the event data from server thread. |
|
97 |
|
98 MImpsSearchHandler2* searchhandler = NULL; |
|
99 SImpsEventData* event = ( SImpsEventData* )iEventData.Ptr(); |
|
100 TInt err( KErrNone ); |
|
101 //This must be a "response" to search stop |
|
102 if( event->iMessageType == EImpsStatus && |
|
103 event->iRequestType == EImpsServFundSearch ) |
|
104 { |
|
105 searchhandler = iClient.SearchHandler(); |
|
106 //Notice: Status message does not include a search ID, which is the |
|
107 //third parameter in HandleSearchStoppedL() method. In future, it |
|
108 //might be a good idea to expand the event structure so that a |
|
109 //response could always be mapped to the correct request regardless |
|
110 //of the message type. For now, just send a meaningless magic number 0. |
|
111 if( searchhandler != NULL ) |
|
112 { |
|
113 #ifndef _NO_IMPS_LOGGING_ |
|
114 CImpsClientLogger::Log( _L( "CImpsFundHandler2:: calls HandleSearchStoppedL opid=%d"), |
|
115 event->iOpCode ); |
|
116 #endif |
|
117 TRAP( err, searchhandler->HandleSearchStoppedL( event->iOpCode, |
|
118 /*event->iStatus,*/ KErrNone, *iClient.CspIdentifier() )); |
|
119 } |
|
120 else |
|
121 { |
|
122 #ifndef _NO_IMPS_LOGGING_ |
|
123 CImpsClientLogger::Log(_L("Search handler not instantiated!")); |
|
124 #endif |
|
125 return; |
|
126 } |
|
127 } |
|
128 else |
|
129 { |
|
130 MImpsInviteHandler2* invitehandler = iClient.InviteHandler(); |
|
131 switch( event->iMessageType ) |
|
132 { |
|
133 case EImpsSearchRes: |
|
134 HandleSearchResponseL( event->iOpCode ); |
|
135 break; |
|
136 case EImpsInviteUserReq: |
|
137 HandleInviteRequestL(); |
|
138 break; |
|
139 case EImpsInviteRes: |
|
140 HandleInviteResponseL(); |
|
141 break; |
|
142 case EImpsCancelInviteUserReq: |
|
143 HandleInviteCancelL(); |
|
144 break; |
|
145 default: |
|
146 if( invitehandler != NULL) |
|
147 { |
|
148 #ifndef _NO_IMPS_LOGGING_ |
|
149 CImpsClientLogger::Log( _L( "CImpsFundHandler2:: calls HandleCompleteL opid=%d"), |
|
150 event->iOpCode ); |
|
151 #endif |
|
152 TRAP( err, invitehandler->HandleCompleteL( event->iOpCode, /*event->iStatus,*/ *iClient.CspIdentifier() )); |
|
153 } |
|
154 else |
|
155 { |
|
156 #ifndef _NO_IMPS_LOGGING_ |
|
157 CImpsClientLogger::Log |
|
158 ( _L( "Invite handler not instantiated!" ) ); |
|
159 #endif |
|
160 return; |
|
161 } |
|
162 break; |
|
163 } |
|
164 iKey->Reset(); |
|
165 } |
|
166 #ifndef _NO_IMPS_LOGGING_ |
|
167 CImpsClientLogger::Log( _L( "CImpsFundHandler2::HandleFundamentalEventL ends" ) ); |
|
168 #endif |
|
169 } |
|
170 |
|
171 // ---------------------------------------------------------------------------- |
|
172 // CImpsFundHandler2::HandleSearchResponseL |
|
173 // ---------------------------------------------------------------------------- |
|
174 void CImpsFundHandler2::HandleSearchResponseL( const TInt aOpId ) |
|
175 { |
|
176 #ifndef _NO_IMPS_LOGGING_ |
|
177 CImpsClientLogger::Log |
|
178 ( _L( "CImpsFundHandler2::HandleSearchResponseL()" ) ); |
|
179 #endif |
|
180 MImpsSearchHandler2* search = iClient.SearchHandler(); |
|
181 if( search != NULL ) |
|
182 { |
|
183 TImpsSearchResultType resultType = EImpsUserResult; |
|
184 const TImpsContent* content = KSearchResponseElements; |
|
185 TImpsDataUtils::AddValuesFromArrayL( iKey, content, |
|
186 sizeof( KSearchResponseElements ) / |
|
187 sizeof( KSearchResponseElements[0] ) ); |
|
188 TInt searchId = IntegerElementL( EImpsKeySearchID, 0 ); //search ID |
|
189 TInt index = IntegerElementL( EImpsKeySearchIndex, 0 ); |
|
190 TInt results = IntegerElementL( EImpsKeySearchFindings, 0 ); |
|
191 TBool complete = BooleanElementL( EImpsKeyCompletionFlag, 0 ); |
|
192 CPtrC16Array* resultArray = results > 0 ? SearchResultsLC( resultType ) : NULL; |
|
193 |
|
194 TInt err( KErrNone ); |
|
195 TRAP( err, search->HandleSearchL( aOpId, |
|
196 searchId, index, |
|
197 results, complete, |
|
198 resultType, resultArray, *iClient.CspIdentifier() )); |
|
199 if( resultArray != NULL ) |
|
200 CleanupStack::PopAndDestroy(); //resultArray |
|
201 } |
|
202 else |
|
203 { |
|
204 #ifndef _NO_IMPS_LOGGING_ |
|
205 CImpsClientLogger::Log( _L( " Search handler not instantiated!" ) ); |
|
206 #endif |
|
207 } |
|
208 } |
|
209 |
|
210 // ---------------------------------------------------------------------------- |
|
211 // CImpsFundHandler2::HandleInviteRequestL |
|
212 // ---------------------------------------------------------------------------- |
|
213 void CImpsFundHandler2::HandleInviteRequestL() |
|
214 { |
|
215 #ifndef _NO_IMPS_LOGGING_ |
|
216 CImpsClientLogger::Log |
|
217 ( _L( "CImpsFundHandler2::HandleInviteRequestL()" ) ); |
|
218 #endif |
|
219 MImpsInviteHandler2* invite = iClient.InviteHandler(); |
|
220 if( invite != NULL ) |
|
221 { |
|
222 TInt err( KErrNone ); |
|
223 |
|
224 const TImpsContent* content = KInviteUserRequestElements; |
|
225 TImpsDataUtils::AddValuesFromArrayL( iKey, content, |
|
226 sizeof( KInviteUserRequestElements ) / |
|
227 sizeof( KInviteUserRequestElements[0] ) ); |
|
228 |
|
229 TInt inviteType = IntegerElementL( EImpsKeyInviteType, 0 ); |
|
230 TPtrC inviteID = DescriptorElementL( EImpsKeyInviteID, 0 ); |
|
231 TPtrC reason = DescriptorElementL( EImpsKeyInviteNote, 0 ); |
|
232 TInt validity = IntegerElementL( EImpsKeyValidity, 0 ); |
|
233 TPtrC groupName; |
|
234 groupName.Set( DescriptorElementL( EImpsKeyGroupID, 0 ) );//gr |
|
235 |
|
236 iKey->AddL( CREATEKEY( EImpsKeySender, 0 ) ); |
|
237 iKey->AddL( CREATEKEY( EImpsKeyUser, 0 ) ); |
|
238 TPtrC userID = DescriptorElementL( EImpsKeyUserID, 0 ); |
|
239 if ( inviteType == EImpsGR ) |
|
240 { |
|
241 TPtrC sName; |
|
242 if( userID.Length() == 0 ) |
|
243 { |
|
244 iKey->PopL(); //user |
|
245 iKey->AddL( CREATEKEY( EImpsKeyGroup, 0 ) ); // group |
|
246 iKey->AddL( CREATEKEY( EImpsKeyScreenName, 0 ) ); // ScreenName //gr |
|
247 sName.Set( DescriptorElementL( EImpsKeySName, 0 ) ); |
|
248 groupName.Set( DescriptorElementL( EImpsKeyGroupID, 0 ) ); |
|
249 } |
|
250 TRAP( err, invite->HandleGroupInviteL( inviteID, userID, sName, groupName, |
|
251 reason, validity, |
|
252 *iClient.CspIdentifier() ) ); |
|
253 } |
|
254 else if ( inviteType == EImpsIM ) |
|
255 { |
|
256 invite->HandleImInviteL( inviteID, userID, reason, |
|
257 validity, *iClient.CspIdentifier()); |
|
258 } |
|
259 else if ( inviteType == EImpsSC ) |
|
260 { |
|
261 CDesCArrayFlat* urlList = new ( ELeave ) CDesCArrayFlat( 4 ); |
|
262 CleanupStack::PushL( urlList ); |
|
263 TImpsCDataUtils::GetUrlListL( iDataAccessor, urlList ); |
|
264 TRAP( err, invite->HandleContentInviteL( inviteID, userID, urlList, |
|
265 reason, validity, *iClient.CspIdentifier())); |
|
266 CleanupStack::PopAndDestroy(); |
|
267 } |
|
268 else |
|
269 { |
|
270 #ifndef _NO_IMPS_LOGGING_ |
|
271 CImpsClientLogger::Log( _L( "CImpsFundHandler2: ERROR Unknown invite type %d" ), inviteType ); |
|
272 #endif |
|
273 User::Leave( KErrCorrupt ); |
|
274 } |
|
275 |
|
276 |
|
277 } |
|
278 else |
|
279 { |
|
280 #ifndef _NO_IMPS_LOGGING_ |
|
281 CImpsClientLogger::Log( _L( "Invite handler not instantiated!" ) ); |
|
282 #endif |
|
283 } |
|
284 } |
|
285 |
|
286 // ---------------------------------------------------------------------------- |
|
287 // CImpsFundHandler2::HandleInviteResponseL |
|
288 // ---------------------------------------------------------------------------- |
|
289 void CImpsFundHandler2::HandleInviteResponseL() |
|
290 { |
|
291 #ifndef _NO_IMPS_LOGGING_ |
|
292 CImpsClientLogger::Log |
|
293 ( _L( "CImpsFundHandler2::HandleInviteResponseL()" ) ); |
|
294 #endif |
|
295 MImpsInviteHandler2* invite = iClient.InviteHandler(); |
|
296 if( invite != NULL ) |
|
297 { |
|
298 TPtrC sName; |
|
299 TPtrC groupName; |
|
300 const TImpsContent* content = KInviteResponseElements; |
|
301 TImpsDataUtils::AddValuesFromArrayL( iKey, content, |
|
302 sizeof( KInviteResponseElements ) / |
|
303 sizeof( KInviteResponseElements[0] ) ); |
|
304 TPtrC inviteID = DescriptorElementL( EImpsKeyInviteID, 0 ); |
|
305 TBool accept = BooleanElementL( EImpsKeyAcceptance, 0 ); |
|
306 TPtrC response = DescriptorElementL( EImpsKeyResponseNote, 0 ); |
|
307 iKey->AddL( CREATEKEY( EImpsKeySender, 0 ) ); // sender |
|
308 iKey->AddL( CREATEKEY( EImpsKeyUser, 0 ) ); // user |
|
309 TPtrC userID = DescriptorElementL( EImpsKeyUserID, 0 ); |
|
310 if( userID.Length() == 0 ) |
|
311 { |
|
312 iKey->PopL(); //user |
|
313 iKey->AddL( CREATEKEY( EImpsKeyGroup, 0 ) ); // group |
|
314 iKey->AddL( CREATEKEY( EImpsKeyScreenName, 0 ) ); //screenName |
|
315 sName.Set( DescriptorElementL( EImpsKeySName, 0 ) ); |
|
316 groupName.Set( DescriptorElementL( EImpsKeyGroupID, 0 ) ); |
|
317 } |
|
318 TInt err( KErrNone ); |
|
319 TRAP( err, invite->HandleInviteResponseL( inviteID, accept, userID, |
|
320 sName, groupName, response, *iClient.CspIdentifier() )); |
|
321 } |
|
322 else |
|
323 { |
|
324 #ifndef _NO_IMPS_LOGGING_ |
|
325 CImpsClientLogger::Log( _L( "Invite handler not instantiated!" ) ); |
|
326 #endif |
|
327 } |
|
328 } |
|
329 |
|
330 // ---------------------------------------------------------------------------- |
|
331 // CImpsFundHandler2::HandleInviteCancelL |
|
332 // ---------------------------------------------------------------------------- |
|
333 void CImpsFundHandler2::HandleInviteCancelL() |
|
334 { |
|
335 #ifndef _NO_IMPS_LOGGING_ |
|
336 CImpsClientLogger::Log |
|
337 ( _L( "CImpsFundHandler2::HandleInviteCancelL()" ) ); |
|
338 #endif |
|
339 MImpsInviteHandler2* invite = iClient.InviteHandler(); |
|
340 if( invite != NULL ) |
|
341 { |
|
342 TPtrC sName; |
|
343 TPtrC groupName; |
|
344 const TImpsContent* content = KInviteCancelUserRequestElements; |
|
345 TImpsDataUtils::AddValuesFromArrayL( iKey, content, |
|
346 sizeof( KInviteCancelUserRequestElements ) / |
|
347 sizeof( KInviteCancelUserRequestElements[0] ) ); |
|
348 TPtrC inviteID = DescriptorElementL( EImpsKeyInviteID, 0 ); |
|
349 TPtrC response = DescriptorElementL( EImpsKeyInviteNote, 0 ); |
|
350 iKey->AddL( CREATEKEY( EImpsKeySender, 0 ) ); // sender |
|
351 iKey->AddL( CREATEKEY( EImpsKeyUser, 0 ) ); // user |
|
352 TPtrC userID = DescriptorElementL( EImpsKeyUserID, 0 ); |
|
353 if( userID.Length() == 0 ) |
|
354 { |
|
355 iKey->PopL(); //user |
|
356 iKey->AddL( CREATEKEY( EImpsKeyGroup, 0 ) ); //group |
|
357 iKey->AddL( CREATEKEY( EImpsKeyScreenName, 0 ) ); //screenName |
|
358 sName.Set( DescriptorElementL( EImpsKeyGroupID, 0 ) ); |
|
359 //screenName, group |
|
360 groupName.Set( DescriptorElementL( EImpsKeySName, 0 ) ); |
|
361 } |
|
362 TInt err( KErrNone ); |
|
363 TRAP( err, invite->HandleInviteCancelL( inviteID, userID, sName, |
|
364 groupName, response, |
|
365 *iClient.CspIdentifier() )); |
|
366 } |
|
367 else |
|
368 { |
|
369 #ifndef _NO_IMPS_LOGGING_ |
|
370 CImpsClientLogger::Log( _L( "Invite handler not instantiated!" ) ); |
|
371 #endif |
|
372 } |
|
373 } |
|
374 |
|
375 // ---------------------------------------------------------------------------- |
|
376 // CImpsFundHandler2::SearchResultsLC |
|
377 // ---------------------------------------------------------------------------- |
|
378 CPtrC16Array* CImpsFundHandler2::SearchResultsLC( |
|
379 TImpsSearchResultType& aResultType ) |
|
380 { |
|
381 #ifndef _NO_IMPS_LOGGING_ |
|
382 CImpsClientLogger::Log( _L( " CImpsFundHandler2::SearchResultsLC()" ) ); |
|
383 #endif |
|
384 TBool moreResults = ETrue; |
|
385 const TInt KArraySize = 5; |
|
386 CPtrC16Array* results = new ( ELeave ) CPtrC16Array( KArraySize ); |
|
387 CleanupStack::PushL( results ); |
|
388 iKey->AddL( CREATEKEY( EImpsKeySearchResult, 0 ) ); //*** search result |
|
389 iKey->AddL( CREATEKEY( EImpsKeyUserList, 0 ) ); //*** user list |
|
390 if( iDataAccessor->CheckBranchExistenceL( iKey ) ) |
|
391 { |
|
392 aResultType = EImpsUserResult; |
|
393 for( TInt i = 0;moreResults;i++ ) |
|
394 { |
|
395 iKey->AddL( CREATEKEY( EImpsKeyUser, i ) ); //*** user |
|
396 TPtrC userId = DescriptorElementL( EImpsKeyUserID, 0 ); |
|
397 if( userId.Length() > 0 ) |
|
398 { |
|
399 results->AppendL( userId ); |
|
400 #ifndef _NO_IMPS_LOGGING_ |
|
401 CImpsClientLogger::Log( _L( " Result no. %d: \"%S\"" ), i, &userId ); |
|
402 #endif |
|
403 } |
|
404 else |
|
405 { |
|
406 moreResults = EFalse; |
|
407 } |
|
408 iKey->PopL(); //user |
|
409 } |
|
410 iKey->PopL( 2 ); //user list, search result |
|
411 } |
|
412 else |
|
413 { |
|
414 aResultType = EImpsGroupResult; |
|
415 iKey->PopL(); //user list |
|
416 iKey->AddL( CREATEKEY( EImpsKeyGroupList, 0 ) ); //*** group list |
|
417 for( TInt i(0); moreResults; ++i ) |
|
418 { |
|
419 TPtrC groupId = DescriptorElementL( EImpsKeyGroupID, i ); |
|
420 if( groupId.Length() > 0 ) |
|
421 { |
|
422 results->AppendL( groupId ); |
|
423 #ifndef _NO_IMPS_LOGGING_ |
|
424 CImpsClientLogger::Log( _L( " Result no. %d: \"%S\"" ), i, &groupId ); |
|
425 #endif |
|
426 } |
|
427 else |
|
428 { |
|
429 moreResults = EFalse; |
|
430 } |
|
431 } |
|
432 iKey->PopL( 2 ); //group list, search result |
|
433 } |
|
434 return results; |
|
435 } |
|
436 |
|
437 // ---------------------------------------------------------------------------- |
|
438 // CImpsFundHandler2::DescriptorElementL |
|
439 // ---------------------------------------------------------------------------- |
|
440 TPtrC CImpsFundHandler2::DescriptorElementL( const TImpsContent aContent, |
|
441 const TInt aIndex ) |
|
442 { |
|
443 TDesC* ret = NULL; |
|
444 iKey->AddL( CREATEKEY( aContent, aIndex ) ); |
|
445 iDataAccessor->RestoreDescL( iKey, ret ); |
|
446 iKey->PopL(); |
|
447 return ret != NULL ? TPtrC( *ret ) : TPtrC(); |
|
448 } |
|
449 |
|
450 // ---------------------------------------------------------------------------- |
|
451 // CImpsFundHandler2::BooleanElementL |
|
452 // ---------------------------------------------------------------------------- |
|
453 TBool CImpsFundHandler2::BooleanElementL( const TImpsContent aContent, |
|
454 const TInt aIndex ) |
|
455 { |
|
456 TBool ret; |
|
457 iKey->AddL( CREATEKEY( aContent, aIndex ) ); |
|
458 iDataAccessor->RestoreBooleanL( iKey, ret ); |
|
459 iKey->PopL(); |
|
460 return ret; |
|
461 } |
|
462 |
|
463 // ---------------------------------------------------------------------------- |
|
464 // CImpsFundHandler2::IntegerElementL |
|
465 // ---------------------------------------------------------------------------- |
|
466 TInt CImpsFundHandler2::IntegerElementL( const TImpsContent aContent, |
|
467 const TInt aIndex ) |
|
468 { |
|
469 TInt ret = 0; |
|
470 iKey->AddL( CREATEKEY( aContent, aIndex ) ); |
|
471 iDataAccessor->RestoreIntegerL( iKey, ret ); |
|
472 iKey->PopL(); |
|
473 return ret; |
|
474 } |
|
475 |
|
476 // ---------------------------------------------------------------------------- |
|
477 // CImpsFundHandler2::ConstructL |
|
478 // ---------------------------------------------------------------------------- |
|
479 |
|
480 void CImpsFundHandler2::ConstructL() |
|
481 { |
|
482 CImpsHandler2::ConstructL( ); |
|
483 iDataAccessor = CImpsDataAccessor::NewL( iFields ); |
|
484 iKey = CImpsKey::NewL(); |
|
485 } |
|
486 |
|
487 // End of File |
|
488 |
|
489 |