|
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: NWSessionSlotID implementation. |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include "CPEngSessionSlotState.h" |
|
20 #include "CPEngSessionSlotId.h" |
|
21 #include "CPEngSessionSlotEvent.h" |
|
22 #include "PEngCoreUtilsTools.h" |
|
23 |
|
24 |
|
25 |
|
26 // CONSTANTS |
|
27 |
|
28 /** |
|
29 * Default array granurality. |
|
30 */ |
|
31 const TInt KArrayGranularity = 5; |
|
32 |
|
33 |
|
34 /** |
|
35 * Version of the session state storage format. |
|
36 */ |
|
37 const TInt KSessionStateVersion = 0x00000001; |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 // ====================== LOCAL FUNCTIONS ====================================== |
|
43 |
|
44 //LOCAL PANIC FUNCTIONS |
|
45 namespace |
|
46 { |
|
47 //SessionSlotState panic |
|
48 _LIT( KPEngSessionSlotStatePanic, "SessSlotState" ); |
|
49 |
|
50 //SessionSlotState panic reasons |
|
51 enum TPEngSessionSlotStatePanicReasons |
|
52 { |
|
53 EPEngNoSessionSlotId = 1, |
|
54 EPEngSessionUpdateInconsistent = 2, |
|
55 EPEngSessionOpenAppNotRegistered = 3, |
|
56 EPEngSessionCloseAppNotRegistered = 4, |
|
57 EPEngSessionOpenGlobalStateNotCorrect = 5, |
|
58 EPEngSessionHasActiveAppsAtClosedState = 6 |
|
59 }; |
|
60 |
|
61 //SessionSlotState panic function |
|
62 void PanicSessionSlotState( TPEngSessionSlotStatePanicReasons aPanicReason ) |
|
63 { |
|
64 User::Panic( KPEngSessionSlotStatePanic, aPanicReason ); |
|
65 } |
|
66 } |
|
67 |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // DesArrayExternalizeSize() |
|
71 // ----------------------------------------------------------------------------- |
|
72 TInt DesArrayExternalizeSize( const MDesC16Array& aArray ) |
|
73 { |
|
74 TInt size = 4; //array count |
|
75 |
|
76 const TInt count( aArray.MdcaCount() ); |
|
77 for ( TInt ix = 0 ; ix < count ; ix++ ) |
|
78 { |
|
79 //Below: descriptor length is streamed as 32 bit integer ==> 4 bytes |
|
80 size += aArray.MdcaPoint( ix ).Size() + 4; |
|
81 } |
|
82 return size; |
|
83 } |
|
84 |
|
85 |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // ExternalizeDesArrayWithSkipL() |
|
89 // ----------------------------------------------------------------------------- |
|
90 void ExternalizeDesArrayWithSkipL( const MDesC16Array& aArray, |
|
91 TInt aIxToSkip, |
|
92 RWriteStream& aStream ) |
|
93 { |
|
94 TInt count ( aArray.MdcaCount() ); |
|
95 aStream.WriteInt32L( count - ( aIxToSkip == KErrNotFound ? 0 : 1 ) ); |
|
96 |
|
97 for ( TInt ix = 0 ; ix < count ; ix++ ) |
|
98 { |
|
99 if ( ix == aIxToSkip ) |
|
100 { |
|
101 continue; |
|
102 } |
|
103 |
|
104 TPtrC16 data( aArray.MdcaPoint( ix ) ); |
|
105 aStream.WriteInt32L( data.Length() ); |
|
106 aStream.WriteL( data ); |
|
107 } |
|
108 } |
|
109 |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // InternalizeDesArrayL() |
|
113 // ----------------------------------------------------------------------------- |
|
114 void InternalizeDesArrayL( CDesCArray& aArray, |
|
115 RReadStream& aStream ) |
|
116 { |
|
117 aArray.Reset(); |
|
118 |
|
119 TInt count = aStream.ReadInt32L(); |
|
120 for ( TInt ii = 0; ii < count; ii++ ) |
|
121 { |
|
122 TInt length = aStream.ReadInt32L(); |
|
123 HBufC* buffer = HBufC::NewLC( length ); |
|
124 TPtr ptr( buffer->Des() ); |
|
125 aStream.ReadL( ptr, length ); |
|
126 aArray.AppendL( *buffer ); |
|
127 CleanupStack::PopAndDestroy( buffer ); |
|
128 } |
|
129 } |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 // ====================== MEMBER FUNCTIONS ====================================== |
|
135 |
|
136 // ----------------------------------------------------------------------------- |
|
137 // CPEngSessionSlotState::CPEngSessionSlotState |
|
138 // C++ constructor can NOT contain any code, that |
|
139 // might leave. |
|
140 // ----------------------------------------------------------------------------- |
|
141 // |
|
142 CPEngSessionSlotState::CPEngSessionSlotState() |
|
143 : iState( EPEngNWPresenceSessionClosed ), |
|
144 iActiveApps( KArrayGranularity ), |
|
145 iRegisteredApps( KArrayGranularity ), |
|
146 iActiveAdded( KErrNotFound ), |
|
147 iActiveRemoved( KErrNotFound ), |
|
148 iRegAdded( KErrNotFound ), |
|
149 iRegRemoved( KErrNotFound ) |
|
150 { |
|
151 } |
|
152 |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CPEngSessionSlotState::NewL() |
|
156 // Two-phased constructor. |
|
157 // ----------------------------------------------------------------------------- |
|
158 // |
|
159 EXPORT_C CPEngSessionSlotState* CPEngSessionSlotState::NewL() |
|
160 { |
|
161 CPEngSessionSlotState* self = new ( ELeave ) CPEngSessionSlotState(); |
|
162 return self; |
|
163 } |
|
164 |
|
165 |
|
166 // ----------------------------------------------------------------------------- |
|
167 // CPEngSessionSlotState::NewLC() |
|
168 // Two-phased constructor. |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 EXPORT_C CPEngSessionSlotState* CPEngSessionSlotState::NewLC() |
|
172 { |
|
173 CPEngSessionSlotState* self = new ( ELeave ) CPEngSessionSlotState(); |
|
174 CleanupStack::PushL( self ); |
|
175 return self; |
|
176 } |
|
177 |
|
178 |
|
179 // Destructor |
|
180 CPEngSessionSlotState::~CPEngSessionSlotState() |
|
181 { |
|
182 if ( iSessionIdOwned ) |
|
183 { |
|
184 delete iSessionId; |
|
185 } |
|
186 |
|
187 iActiveApps.Reset(); |
|
188 iRegisteredApps.Reset(); |
|
189 } |
|
190 |
|
191 |
|
192 |
|
193 // ============================================================================= |
|
194 // =============== Session ID support ========================================== |
|
195 // ============================================================================= |
|
196 |
|
197 // ----------------------------------------------------------------------------- |
|
198 // CPEngSessionSlotState::SessionSlotIndentification() |
|
199 // Session Slot ID identification |
|
200 // ----------------------------------------------------------------------------- |
|
201 // |
|
202 EXPORT_C CPEngSessionSlotId& CPEngSessionSlotState::SessionSlotId() const |
|
203 { |
|
204 __ASSERT_ALWAYS( iSessionId, PanicSessionSlotState( EPEngNoSessionSlotId ) ); |
|
205 return *iSessionId; |
|
206 } |
|
207 |
|
208 |
|
209 |
|
210 // ============================================================================= |
|
211 // =============== State identificationst ====================================== |
|
212 // ============================================================================= |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CPEngSessionSlotState::SessionSlotState() |
|
216 // Session slot Online state |
|
217 // ----------------------------------------------------------------------------- |
|
218 // |
|
219 EXPORT_C TPEngNWSessionSlotState CPEngSessionSlotState::SessionSlotState() const |
|
220 { |
|
221 return iState; |
|
222 } |
|
223 |
|
224 |
|
225 // ----------------------------------------------------------------------------- |
|
226 // CPEngSessionSlotState::RegisteredApplications() |
|
227 // Gets list of Application IDs which are active with this |
|
228 // ----------------------------------------------------------------------------- |
|
229 // |
|
230 EXPORT_C const MDesC16Array& CPEngSessionSlotState::RegisteredApplications() const |
|
231 { |
|
232 return iRegisteredApps; |
|
233 } |
|
234 |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CPEngSessionSlotState::ActiveApplications() |
|
238 // Gets list of Application IDs which are registered to this |
|
239 // ----------------------------------------------------------------------------- |
|
240 // |
|
241 EXPORT_C const MDesC16Array& CPEngSessionSlotState::ActiveApplications() const |
|
242 { |
|
243 return iActiveApps; |
|
244 } |
|
245 |
|
246 |
|
247 // ----------------------------------------------------------------------------- |
|
248 // CPEngSessionSlotState::AppState() |
|
249 // Gets state of the application in the session state |
|
250 // ----------------------------------------------------------------------------- |
|
251 // |
|
252 EXPORT_C TPEngNWSessionSlotState CPEngSessionSlotState::AppState( |
|
253 const TDesC& aAppId ) const |
|
254 { |
|
255 TInt pos( KErrNotFound ); |
|
256 if ( KErrNone == iActiveApps.FindIsq( aAppId, pos ) ) |
|
257 { |
|
258 return EPEngNWPresenceSessionOpen; |
|
259 } |
|
260 |
|
261 return EPEngNWPresenceSessionClosed; |
|
262 } |
|
263 |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CPEngSessionSlotState::ApplicationRegisteredL() |
|
267 // Check if application is registered to this session slot |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 EXPORT_C void CPEngSessionSlotState::ApplicationRegisteredL( |
|
271 const TDesC& aAppId ) const |
|
272 { |
|
273 __ASSERT_ALWAYS( ApplicationRegistered( aAppId ), User::Leave( KErrNotFound ) ); |
|
274 } |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 // ============================================================================= |
|
280 // =============== identification management ==================================== |
|
281 // ============================================================================= |
|
282 |
|
283 // ----------------------------------------------------------------------------- |
|
284 // CPEngSessionSlotState::SetSessionStlotId() |
|
285 // Set Session slot ID class |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 EXPORT_C void CPEngSessionSlotState::SetSessionSlotId( |
|
289 CPEngSessionSlotId& aSlotId, |
|
290 TBool aOwnershipTransfered /* EFalse */ ) |
|
291 { |
|
292 if ( iSessionId && iSessionIdOwned ) |
|
293 { |
|
294 delete iSessionId; |
|
295 } |
|
296 |
|
297 iSessionId = &aSlotId; |
|
298 iSessionIdOwned = aOwnershipTransfered; |
|
299 } |
|
300 |
|
301 |
|
302 // ----------------------------------------------------------------------------- |
|
303 // CPEngSessionSlotState::SetSessionSlotStateClosed() |
|
304 // Set state of the session slot closed |
|
305 // ----------------------------------------------------------------------------- |
|
306 // |
|
307 EXPORT_C void CPEngSessionSlotState::SetSessionSlotStateClosed() |
|
308 { |
|
309 iState = EPEngNWPresenceSessionClosed; |
|
310 iActiveApps.Reset(); |
|
311 iActiveAdded = KErrNotFound; |
|
312 iActiveRemoved = KErrNotFound; |
|
313 } |
|
314 |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CPEngSessionSlotState::UpdateStateL() |
|
318 // Update Session slot state based on the event |
|
319 // ----------------------------------------------------------------------------- |
|
320 // |
|
321 EXPORT_C TBool CPEngSessionSlotState::UpdateStateL( |
|
322 const CPEngSessionSlotEvent& aSessEvent ) |
|
323 { |
|
324 //Precheck - SlotId must match |
|
325 __ASSERT_ALWAYS( aSessEvent.SessionSlotIndentification().Match( SessionSlotId() ) == KErrNone, |
|
326 PanicSessionSlotState( EPEngSessionUpdateInconsistent ) ); |
|
327 |
|
328 |
|
329 // first commit last update |
|
330 CommitLastUpdate(); |
|
331 |
|
332 // set state in state from the event |
|
333 iState = aSessEvent.GlobSessSltState(); |
|
334 |
|
335 |
|
336 // Check what has happened |
|
337 TBool permanentStoreNeeded = EFalse; |
|
338 switch ( aSessEvent.Event() ) |
|
339 { |
|
340 case EPEngEventNWSessionSlotCreated: |
|
341 { |
|
342 // New Application Id was registered to the session |
|
343 AddRegisteredAppIdL( aSessEvent.ApplicationId() ); |
|
344 |
|
345 // this needs to be store to permanent |
|
346 permanentStoreNeeded = ETrue; |
|
347 break; |
|
348 } |
|
349 |
|
350 |
|
351 case EPEngEventNWSessionSlotRemoved: |
|
352 { |
|
353 // Application Id was removed from the session slot |
|
354 RemoveRegisteredAppIdL( aSessEvent.ApplicationId() ); |
|
355 |
|
356 // this needs to be store to permanent |
|
357 permanentStoreNeeded = ETrue; |
|
358 break; |
|
359 } |
|
360 |
|
361 |
|
362 case EPEngEventAppNWPresenceSessionOpened: |
|
363 { |
|
364 // New Application Id has activated session |
|
365 __ASSERT_ALWAYS( ApplicationRegistered( aSessEvent.ApplicationId() ), |
|
366 PanicSessionSlotState( EPEngSessionOpenAppNotRegistered ) ); |
|
367 |
|
368 __ASSERT_ALWAYS( iState == EPEngNWPresenceSessionOpen, |
|
369 PanicSessionSlotState( EPEngSessionOpenGlobalStateNotCorrect ) ); |
|
370 |
|
371 AddActiveAppIdL( aSessEvent.ApplicationId() ); |
|
372 break; |
|
373 } |
|
374 |
|
375 |
|
376 case EPEngEventAppNWPresenceSessionClosed: |
|
377 case EPEngEventNWSessionClosedByServer: |
|
378 { |
|
379 // Application Id has closed the session |
|
380 // Closing event does not have to have any App Id.. |
|
381 RemoveActiveAppId( aSessEvent.ApplicationId() ); |
|
382 break; |
|
383 } |
|
384 |
|
385 |
|
386 case EPEngEventNWSessionSlotChanged: |
|
387 case EPEngEventNWSessionTransport: |
|
388 default: |
|
389 { |
|
390 // default does nothing |
|
391 break; |
|
392 } |
|
393 } |
|
394 |
|
395 |
|
396 return permanentStoreNeeded; |
|
397 } |
|
398 |
|
399 |
|
400 // ----------------------------------------------------------------------------- |
|
401 // CPEngSessionSlotState::UpdateAndCommitStateL() |
|
402 // Update Session slot state based on the event and commit the state |
|
403 // ----------------------------------------------------------------------------- |
|
404 // |
|
405 EXPORT_C TBool CPEngSessionSlotState::UpdateAndCommitStateL( |
|
406 const CPEngSessionSlotEvent& aSessEvent ) |
|
407 { |
|
408 TBool storeNeed( UpdateStateL( aSessEvent ) ); |
|
409 CommitLastUpdate(); |
|
410 return storeNeed; |
|
411 } |
|
412 |
|
413 |
|
414 // ----------------------------------------------------------------------------- |
|
415 // CPEngSessionSlotState::RollBackLastUpdate() |
|
416 // Rollback last change |
|
417 // ----------------------------------------------------------------------------- |
|
418 // |
|
419 EXPORT_C void CPEngSessionSlotState::RollBackLastUpdate() |
|
420 { |
|
421 if ( iActiveAdded != KErrNotFound ) |
|
422 { |
|
423 iActiveApps.Delete( iActiveAdded ); |
|
424 iActiveAdded = KErrNotFound; |
|
425 } |
|
426 |
|
427 iActiveRemoved = KErrNotFound; |
|
428 if ( iRegAdded != KErrNotFound ) |
|
429 { |
|
430 iRegisteredApps.Delete( iRegAdded ); |
|
431 iRegAdded = KErrNotFound; |
|
432 } |
|
433 iRegRemoved = KErrNotFound; |
|
434 } |
|
435 |
|
436 |
|
437 // ----------------------------------------------------------------------------- |
|
438 // CPEngSessionSlotState::CommitLastUpdate() |
|
439 // Commit last change |
|
440 // ----------------------------------------------------------------------------- |
|
441 // |
|
442 EXPORT_C void CPEngSessionSlotState::CommitLastUpdate() |
|
443 { |
|
444 iActiveAdded = KErrNotFound; |
|
445 iRegAdded = KErrNotFound; |
|
446 if ( iActiveRemoved != KErrNotFound ) |
|
447 { |
|
448 iActiveApps.Delete( iActiveRemoved ); |
|
449 iActiveRemoved = KErrNotFound; |
|
450 } |
|
451 if ( iRegRemoved != KErrNotFound ) |
|
452 { |
|
453 iRegisteredApps.Delete( iRegRemoved ); |
|
454 iRegRemoved = KErrNotFound; |
|
455 } |
|
456 } |
|
457 |
|
458 |
|
459 |
|
460 // ============================================================================= |
|
461 // =============== Export, Import Functions ==================================== |
|
462 // ============================================================================= |
|
463 |
|
464 // ----------------------------------------------------------------------------- |
|
465 // CPEngSessionSlotState::InternalizeL() |
|
466 // Internalize Session Slot State from stream |
|
467 // ----------------------------------------------------------------------------- |
|
468 // |
|
469 EXPORT_C void CPEngSessionSlotState::InternalizeL( RReadStream& aStream, |
|
470 TPEngDataSelection aSelection ) |
|
471 { |
|
472 if ( EPermanentData & aSelection ) |
|
473 { |
|
474 TInt version( aStream.ReadInt32L() ); |
|
475 if ( version != KSessionStateVersion ) |
|
476 { |
|
477 User::Leave( KErrCorrupt ); |
|
478 } |
|
479 } |
|
480 |
|
481 |
|
482 // shall we unpack identification |
|
483 if ( EIdentification & aSelection ) |
|
484 { |
|
485 CPEngSessionSlotId* newId = CPEngSessionSlotId::NewLC(); |
|
486 newId->InternalizeL( aStream ); |
|
487 SetSessionSlotId( *newId, ETrue ); |
|
488 CleanupStack::Pop( newId ); |
|
489 } |
|
490 |
|
491 |
|
492 // shall we unpack Registered application IDs |
|
493 if ( ERegistredIDs & aSelection ) |
|
494 { |
|
495 InternalizeDesArrayL( iRegisteredApps, aStream ); |
|
496 } |
|
497 |
|
498 |
|
499 // shall we unpack State specific data |
|
500 if ( EStateSpecific & aSelection ) |
|
501 { |
|
502 iState = static_cast<TPEngNWSessionSlotState>( aStream.ReadInt32L() ); |
|
503 InternalizeDesArrayL( iActiveApps, aStream ); |
|
504 } |
|
505 |
|
506 } |
|
507 |
|
508 |
|
509 |
|
510 // ----------------------------------------------------------------------------- |
|
511 // CPEngSessionSlotState::ExternalizeL() |
|
512 // Externalize Session Slot state to stream |
|
513 // ----------------------------------------------------------------------------- |
|
514 // |
|
515 |
|
516 EXPORT_C void CPEngSessionSlotState::ExternalizeL( RWriteStream& aStream, |
|
517 TPEngDataSelection aSelection ) const |
|
518 { |
|
519 if ( EPermanentData & aSelection ) |
|
520 { |
|
521 // pack store version |
|
522 aStream.WriteInt32L( KSessionStateVersion ); |
|
523 } |
|
524 |
|
525 |
|
526 // shall we pack identification |
|
527 if ( EIdentification & aSelection ) |
|
528 { |
|
529 SessionSlotId().ExternalizeL( aStream ); |
|
530 } |
|
531 |
|
532 |
|
533 // shall we pack Registered application IDs |
|
534 if ( ERegistredIDs & aSelection ) |
|
535 { |
|
536 ExternalizeDesArrayWithSkipL( iRegisteredApps, iRegRemoved, aStream ); |
|
537 } |
|
538 |
|
539 |
|
540 // shall we pack State specific data |
|
541 if ( EStateSpecific & aSelection ) |
|
542 { |
|
543 aStream.WriteInt32L( iState ); |
|
544 ExternalizeDesArrayWithSkipL( iActiveApps, iActiveRemoved, aStream ); |
|
545 } |
|
546 } |
|
547 |
|
548 |
|
549 // ----------------------------------------------------------------------------- |
|
550 // CPEngSessionSlotState::Size() |
|
551 // Size of the buffer needed for externalization |
|
552 // ----------------------------------------------------------------------------- |
|
553 // |
|
554 EXPORT_C TInt CPEngSessionSlotState::Size( TPEngDataSelection aSelection ) const |
|
555 { |
|
556 TInt size = 0; |
|
557 |
|
558 if ( EPermanentData & aSelection ) |
|
559 { |
|
560 size += 4; //KSessionStateVersion |
|
561 } |
|
562 |
|
563 |
|
564 if ( EIdentification & aSelection ) |
|
565 { |
|
566 size += SessionSlotId().Size(); |
|
567 } |
|
568 |
|
569 |
|
570 if ( EStateSpecific & aSelection ) |
|
571 { |
|
572 size += 4; //iState |
|
573 size += DesArrayExternalizeSize( iActiveApps ); |
|
574 } |
|
575 |
|
576 |
|
577 if ( ERegistredIDs & aSelection ) |
|
578 { |
|
579 size += DesArrayExternalizeSize( iRegisteredApps ); |
|
580 } |
|
581 |
|
582 |
|
583 return size; |
|
584 } |
|
585 |
|
586 |
|
587 |
|
588 // ----------------------------------------------------------------------------- |
|
589 // CPEngSessionSlotState::PackDataLC() |
|
590 // Pack Session Slot state to the the des buffer |
|
591 // ----------------------------------------------------------------------------- |
|
592 // |
|
593 EXPORT_C HBufC8* CPEngSessionSlotState::PackDataLC( |
|
594 TPEngDataSelection aSelection ) const |
|
595 { |
|
596 HBufC8* packBuffer = HBufC8::NewLC( Size( aSelection ) ); |
|
597 TPtr8 pack( packBuffer->Des() ); |
|
598 |
|
599 RDesWriteStream ws; |
|
600 ws.Open( pack ); // CSI: 65 # |
|
601 CleanupClosePushL( ws ); |
|
602 |
|
603 ExternalizeL( ws, aSelection ); |
|
604 |
|
605 ws.CommitL(); |
|
606 CleanupStack::PopAndDestroy(); //ws |
|
607 |
|
608 packBuffer = packBuffer->ReAllocL( packBuffer->Length() ); |
|
609 CleanupStack::Pop(); |
|
610 CleanupStack::PushL( packBuffer ); //Due realloc |
|
611 |
|
612 return packBuffer; |
|
613 } |
|
614 |
|
615 // ----------------------------------------------------------------------------- |
|
616 // CPEngSessionSlotState::PackDataLC() |
|
617 // Pack Session Slot state to the the des buffer |
|
618 // ----------------------------------------------------------------------------- |
|
619 // |
|
620 EXPORT_C void CPEngSessionSlotState::PackDataL( |
|
621 TPEngDataSelection aSelection, |
|
622 RBuf8& aBuf ) const |
|
623 { |
|
624 TInt size( Size( aSelection ) ); |
|
625 if ( aBuf.MaxSize() < size ) |
|
626 { |
|
627 aBuf.ReAllocL( size ); |
|
628 } |
|
629 aBuf.Zero(); |
|
630 |
|
631 RDesWriteStream ws; |
|
632 ws.Open( aBuf ); // CSI: 65 # |
|
633 CleanupClosePushL( ws ); |
|
634 |
|
635 ExternalizeL( ws, aSelection ); |
|
636 |
|
637 ws.CommitL(); |
|
638 CleanupStack::PopAndDestroy(); //ws |
|
639 } |
|
640 |
|
641 // ----------------------------------------------------------------------------- |
|
642 // CPEngSessionSlotState::UnpackDataL() |
|
643 // Unpack Session Slot state from the passed Descriptor |
|
644 // ----------------------------------------------------------------------------- |
|
645 // |
|
646 EXPORT_C void CPEngSessionSlotState::UnpackDataL( |
|
647 const TDesC8& aDes, |
|
648 TPEngDataSelection aSelection ) |
|
649 { |
|
650 RDesReadStream rs; |
|
651 rs.Open( aDes ); // CSI: 65 # |
|
652 CleanupClosePushL( rs ); |
|
653 InternalizeL( rs, aSelection ); |
|
654 CleanupStack::PopAndDestroy(); // rs |
|
655 } |
|
656 |
|
657 |
|
658 |
|
659 // ============================================================================= |
|
660 // ============== New private helping functions of the class =================== |
|
661 // ============================================================================= |
|
662 |
|
663 |
|
664 // ----------------------------------------------------------------------------- |
|
665 // CPEngSessionSlotState::AddRegisteredAppIdL() |
|
666 // ----------------------------------------------------------------------------- |
|
667 // |
|
668 void CPEngSessionSlotState::AddRegisteredAppIdL( |
|
669 const TDesC& aAppId ) |
|
670 { |
|
671 __ASSERT_ALWAYS( aAppId.Length() > 0, User::Leave( KErrArgument ) ); |
|
672 |
|
673 iRegAdded = iRegisteredApps.InsertIsqL( aAppId ); |
|
674 } |
|
675 |
|
676 |
|
677 // ----------------------------------------------------------------------------- |
|
678 // CPEngSessionSlotState::RemoveRegisteredAppIdL() |
|
679 // ----------------------------------------------------------------------------- |
|
680 // |
|
681 void CPEngSessionSlotState::RemoveRegisteredAppIdL( |
|
682 const TDesC& aAppId ) |
|
683 { |
|
684 TInt pos( 0 ); |
|
685 if ( KErrNone != iActiveApps.Find( aAppId, pos ) ) |
|
686 { |
|
687 if ( KErrNone == iRegisteredApps.Find( aAppId, pos ) ) |
|
688 { |
|
689 // can we delete ID, isn't it last one |
|
690 if ( ( iRegisteredApps.Count() == 1 ) |
|
691 && |
|
692 ( iState == EPEngNWPresenceSessionOpen ) |
|
693 ) |
|
694 { |
|
695 // App Id cannot be deleted, last active one |
|
696 User::Leave( KErrNotSupported ); |
|
697 } |
|
698 iRegRemoved = pos; |
|
699 return; |
|
700 } |
|
701 // ID was not found |
|
702 User::Leave( KErrNotFound ); |
|
703 } |
|
704 // this application is still active, refuse deletion |
|
705 User::Leave( KErrNotSupported ); |
|
706 } |
|
707 |
|
708 |
|
709 // ----------------------------------------------------------------------------- |
|
710 // CPEngSessionSlotState::AddActiveAppIdL() |
|
711 // ----------------------------------------------------------------------------- |
|
712 // |
|
713 void CPEngSessionSlotState::AddActiveAppIdL( |
|
714 const TDesC& aAppId ) |
|
715 { |
|
716 // we relly on Presence Server that IDs are unique |
|
717 iActiveAdded = iActiveApps.InsertIsqL( aAppId ); |
|
718 } |
|
719 |
|
720 |
|
721 // ----------------------------------------------------------------------------- |
|
722 // CPEngSessionSlotState::RemoveActiveAppId() |
|
723 // ----------------------------------------------------------------------------- |
|
724 // |
|
725 void CPEngSessionSlotState::RemoveActiveAppId( const TDesC& aAppId ) |
|
726 { |
|
727 TInt pos( 0 ); |
|
728 if ( KErrNone == iActiveApps.Find( aAppId, pos ) ) |
|
729 { |
|
730 iActiveRemoved = pos; |
|
731 } |
|
732 } |
|
733 |
|
734 |
|
735 // ----------------------------------------------------------------------------- |
|
736 // CPEngSessionSlotState::ApplicationRegistered() |
|
737 // ----------------------------------------------------------------------------- |
|
738 // |
|
739 TBool CPEngSessionSlotState::ApplicationRegistered( const TDesC& aAppId ) const |
|
740 { |
|
741 TInt pos( KErrNotFound ); |
|
742 if ( KErrNone != iRegisteredApps.FindIsq( aAppId, pos ) ) |
|
743 { |
|
744 return EFalse; |
|
745 } |
|
746 |
|
747 return ETrue; |
|
748 } |
|
749 |
|
750 |
|
751 // End of File |
|
752 |
|
753 |