|
1 /* |
|
2 * Copyright (c) 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 the License "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: CBSSession.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32base.h> |
|
22 #include <apgcli.h> |
|
23 |
|
24 #include "cbssession.h" |
|
25 #include "cbsserver.h" |
|
26 #include "DebugTrace.h" |
|
27 #include "cbsbrandhandler.h" |
|
28 #include "cbsstoragemanager.h" |
|
29 #include "cbsstorage.h" |
|
30 #include "cbsbitmap.h" |
|
31 //#include "cbselement.h" |
|
32 #include "rbsobjowningptrarray.h" |
|
33 #include "bselementfactory.h" |
|
34 #include "bsimportconstants.h" |
|
35 #include <badesca.h> |
|
36 #include <s32buf.h> |
|
37 #include <s32mem.h> |
|
38 #include <utf.h> |
|
39 #include <e32property.h> |
|
40 |
|
41 // ============================================================== |
|
42 // ======================== SESSION ============================= |
|
43 // ============================================================== |
|
44 |
|
45 // Two-phased constructor. |
|
46 CBSSession* CBSSession::NewL() |
|
47 { |
|
48 TRACE( T_LIT("CBSSession::NewL begin") ); |
|
49 CBSSession* self = new( ELeave ) CBSSession(); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop( self ); |
|
53 TRACE( T_LIT("CBSSession::NewL end") ); |
|
54 return self; |
|
55 } |
|
56 |
|
57 // Symbian OS default constructor can leave. |
|
58 void CBSSession::ConstructL() |
|
59 { |
|
60 } |
|
61 |
|
62 |
|
63 // destructor |
|
64 CBSSession::~CBSSession() |
|
65 { |
|
66 TRACE( T_LIT("CBSSession[%d]::~CBSSession()"), this ); |
|
67 |
|
68 if( Server() ) |
|
69 { |
|
70 Server()->SessionDied( this ); |
|
71 } |
|
72 delete iText; |
|
73 delete iBuffer; |
|
74 delete iBranding; |
|
75 delete iSeveralData; |
|
76 |
|
77 #ifdef __WINSCW__ |
|
78 if( iStorageManager ) |
|
79 { |
|
80 iStorageManager->WriteIbyFiles(); |
|
81 } |
|
82 #endif |
|
83 delete iStorageManager; |
|
84 delete iSessionInfo; |
|
85 |
|
86 } |
|
87 |
|
88 |
|
89 // C++ default constructor can NOT contain any code, that |
|
90 // might leave. |
|
91 // |
|
92 CBSSession::CBSSession() |
|
93 { |
|
94 } |
|
95 |
|
96 // --------------------------------------------------------- |
|
97 // CBSSession::CreateL |
|
98 // |
|
99 // (other items were commented in a header). |
|
100 // --------------------------------------------------------- |
|
101 // |
|
102 void CBSSession::CreateL() |
|
103 { |
|
104 TRACE( T_LIT("CBSSession[%d]::CreateL()"), this ); |
|
105 Server()->SessionCreatedL( this ); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------- |
|
109 // CBSSession::ServiceL |
|
110 // |
|
111 // (other items were commented in a header). |
|
112 // --------------------------------------------------------- |
|
113 // |
|
114 void CBSSession::ServiceL( const RMessage2 &aMessage ) |
|
115 { |
|
116 |
|
117 /*if( !iSessionInfo ) |
|
118 { |
|
119 TRAPD( err, ExtractInfoL( aMessage ) ); |
|
120 TRACE( T_LIT("CBSSession::ServiceL() ExtractInfoL returned with [%d]"), err ); |
|
121 } |
|
122 */ |
|
123 if( DispatchMessageL( aMessage ) ) |
|
124 { |
|
125 if( !iMessageCompleted ) |
|
126 { |
|
127 aMessage.Complete( KErrNone ); |
|
128 } |
|
129 } |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------- |
|
133 // CBSSession::ServiceError |
|
134 // |
|
135 // (other items were commented in a header). |
|
136 // --------------------------------------------------------- |
|
137 // |
|
138 void CBSSession::ServiceError( const RMessage2& aMessage, |
|
139 TInt aError ) |
|
140 { |
|
141 aMessage.Complete( aError ); |
|
142 } |
|
143 |
|
144 // --------------------------------------------------------- |
|
145 // CBSSession::HandleBackupStateL |
|
146 // |
|
147 // (other items were commented in a header). |
|
148 // --------------------------------------------------------- |
|
149 // |
|
150 void CBSSession::HandleBackupStateL( TBackupState aState ) |
|
151 { |
|
152 iIsBackup = ETrue ; |
|
153 switch( aState ) |
|
154 { |
|
155 case EBackupNotActive: // backup is complete |
|
156 { |
|
157 // release session lock |
|
158 iBackupActive = EFalse; |
|
159 if( iStorageManager ) |
|
160 { |
|
161 iStorageManager->ReleaseLockL(); |
|
162 } |
|
163 |
|
164 // Sending backup active state change event after unlocking it |
|
165 if( iObserverActive ) |
|
166 { |
|
167 iObserverMessage.Complete( KErrNone ); |
|
168 iObserverActive = EFalse; |
|
169 } |
|
170 |
|
171 break; |
|
172 } |
|
173 case EBackupActive: // backup activated |
|
174 { |
|
175 |
|
176 // Lock session. Branding data is not available until |
|
177 // backup is completed. |
|
178 iBackupActive = ETrue; |
|
179 |
|
180 // Sending backup active state change event before locking it |
|
181 if( iObserverActive ) |
|
182 { |
|
183 iObserverMessage.Complete( KErrNone ); |
|
184 iObserverActive = EFalse; |
|
185 } |
|
186 |
|
187 if( iStorageManager ) |
|
188 { |
|
189 iStorageManager->LockStorage(); |
|
190 } |
|
191 break; |
|
192 } |
|
193 default: |
|
194 { |
|
195 // unknown state |
|
196 } |
|
197 } |
|
198 |
|
199 |
|
200 } |
|
201 |
|
202 // --------------------------------------------------------- |
|
203 // CBSSession::DispatchMessageL |
|
204 // |
|
205 // (other items were commented in a header). |
|
206 // --------------------------------------------------------- |
|
207 // |
|
208 TBool CBSSession::DispatchMessageL( const RMessage2& aMessage ) |
|
209 { |
|
210 TRACE( T_LIT("CBrandingSession[%d]::DispatchMessageL() %d"), |
|
211 this, aMessage.Function() ); |
|
212 iMessageCompleted = EFalse; |
|
213 TBool msgNeedsToBeCompleted = ETrue; |
|
214 |
|
215 if( iBackupActive ) |
|
216 { |
|
217 // if backup is active, we don't take requests. |
|
218 // We could take some requests which do not require disk |
|
219 // operations. This is not a good solution and a better one should be |
|
220 // investigated. I'm running out of time. |
|
221 TInt msg = aMessage.Function() ; |
|
222 if( msg == EBSObserveGetChange || |
|
223 msg == EBSObserveGetBackupState || |
|
224 msg == EBSObserveBrand) |
|
225 { |
|
226 //allow to do the operation |
|
227 } |
|
228 else |
|
229 { |
|
230 User::Leave( KErrNotReady ); |
|
231 } |
|
232 |
|
233 } |
|
234 |
|
235 switch( aMessage.Function() ) |
|
236 { |
|
237 case EBSInitInstall: |
|
238 { |
|
239 InitUpdateL( aMessage, EBSTxInstall ); |
|
240 break; |
|
241 } |
|
242 case EBSInitUninstall: |
|
243 { |
|
244 InitUpdateL( aMessage, EBSTxUninstall ); |
|
245 break; |
|
246 } |
|
247 case EBSInitAppend: |
|
248 { |
|
249 InitUpdateL( aMessage, EBSTxAppend ); |
|
250 break; |
|
251 } |
|
252 case EBSInitReplace: |
|
253 { |
|
254 InitUpdateL( aMessage, EBSTxReplace ); |
|
255 break; |
|
256 } |
|
257 case EBSInitAccess: |
|
258 { |
|
259 InitAccessL( aMessage ); |
|
260 break; |
|
261 } |
|
262 case EBSPrepareText: |
|
263 { |
|
264 GetTextL( aMessage ); |
|
265 break; |
|
266 } |
|
267 case EBSGetText: |
|
268 { |
|
269 if( iText ) |
|
270 { |
|
271 aMessage.WriteL( 2, *iText ); |
|
272 } |
|
273 else |
|
274 { |
|
275 aMessage.WriteL( 2, KNullDesC() ); |
|
276 } |
|
277 break; |
|
278 } |
|
279 |
|
280 case EBSIsBrandUpdateRequired: |
|
281 isBrandUpdateRequiredL (aMessage); |
|
282 break; |
|
283 |
|
284 case EBSGetInt: |
|
285 { |
|
286 GetIntL( aMessage ); |
|
287 break; |
|
288 } |
|
289 |
|
290 case EBSPrepareBuffer: |
|
291 { |
|
292 GetBufferL( aMessage ); |
|
293 break; |
|
294 } |
|
295 |
|
296 case EBSGetBuffer: |
|
297 { |
|
298 if( iBuffer ) |
|
299 { |
|
300 aMessage.WriteL( 2, *iBuffer ); |
|
301 } |
|
302 else |
|
303 { |
|
304 aMessage.WriteL( 2, KNullDesC8() ); |
|
305 } |
|
306 break; |
|
307 } |
|
308 |
|
309 case EBSGetFile: |
|
310 { |
|
311 GetFileL( aMessage ); |
|
312 break; |
|
313 } |
|
314 |
|
315 case EBSPrepareSeveral: |
|
316 { |
|
317 PrepareSeveralL( aMessage ); |
|
318 break; |
|
319 } |
|
320 |
|
321 case EBSGetSeveral: |
|
322 { |
|
323 GetSeveralL( aMessage ); |
|
324 break; |
|
325 } |
|
326 |
|
327 case EBSPrepareStructure: |
|
328 { |
|
329 PrepareStructureL( aMessage ); |
|
330 break; |
|
331 } |
|
332 |
|
333 case EBSGetStructure: |
|
334 { |
|
335 GetStructureL( aMessage ); |
|
336 break; |
|
337 } |
|
338 |
|
339 case EBSStartTransaction: |
|
340 { |
|
341 StartTransactionL( aMessage ); |
|
342 break; |
|
343 } |
|
344 |
|
345 case EBSStopTransaction: |
|
346 { |
|
347 StopTransactionL( aMessage ); |
|
348 break; |
|
349 } |
|
350 case EBSCancelTransaction: |
|
351 { |
|
352 CancelTransactionL( aMessage ); |
|
353 break; |
|
354 } |
|
355 |
|
356 case EBSInstall: |
|
357 { |
|
358 InstallL( aMessage ); |
|
359 break; |
|
360 } |
|
361 |
|
362 case EBSReplace: |
|
363 { |
|
364 ReplaceL( aMessage ); |
|
365 break; |
|
366 } |
|
367 |
|
368 case EBSAppend: |
|
369 { |
|
370 AppendL( aMessage ); |
|
371 break; |
|
372 } |
|
373 |
|
374 case EBSRemoveBrand: |
|
375 { |
|
376 RemoveBrandL( aMessage ); |
|
377 break; |
|
378 } |
|
379 case EBSRemoveApplication: |
|
380 { |
|
381 RemoveApplicationL( aMessage ); |
|
382 break; |
|
383 } |
|
384 |
|
385 case EBSObserveBrand: |
|
386 { |
|
387 if( iObserverActive ) |
|
388 { |
|
389 // complete the old observer request with KErrCancel |
|
390 iObserverMessage.Complete( KErrCancel ); |
|
391 } |
|
392 iObserverMessage = aMessage; |
|
393 iObserverActive = ETrue; |
|
394 msgNeedsToBeCompleted = EFalse; |
|
395 break; |
|
396 } |
|
397 |
|
398 case EBSObserveGetNewVersion: |
|
399 { |
|
400 TInt newVersion = GetNewVersionL(); |
|
401 TPckgC<TInt> pack( newVersion ); |
|
402 aMessage.WriteL( 0, pack ); |
|
403 break; |
|
404 } |
|
405 |
|
406 // Get what change happen |
|
407 case EBSObserveGetChange: |
|
408 { |
|
409 TPckgC<TInt> pack( iIsBackup ); |
|
410 aMessage.WriteL( 0, pack ); |
|
411 break ; |
|
412 } |
|
413 |
|
414 // Get the backup state |
|
415 case EBSObserveGetBackupState: |
|
416 { |
|
417 TPckgC<TInt> pack( iBackupActive ); |
|
418 aMessage.WriteL( 0, pack ); |
|
419 break ; |
|
420 } |
|
421 |
|
422 default: |
|
423 { |
|
424 User::Leave( KErrNotSupported ); |
|
425 break; |
|
426 } |
|
427 } |
|
428 |
|
429 return msgNeedsToBeCompleted; |
|
430 } |
|
431 |
|
432 |
|
433 // --------------------------------------------------------- |
|
434 // CBSSession::InitUpdateL |
|
435 // |
|
436 // (other items were commented in a header). |
|
437 // --------------------------------------------------------- |
|
438 // |
|
439 void CBSSession::InitUpdateL( const RMessage2 &aMessage, TTransactionType aType) |
|
440 { |
|
441 TRACE( T_LIT("CBSSession::InitUpdateL: begin TTransactionType[%d] "),aType ); |
|
442 |
|
443 // get the application id |
|
444 TInt bufferSize( aMessage.GetDesLength( 0 ) ); |
|
445 |
|
446 HBufC8* appId = HBufC8::NewLC( bufferSize ); |
|
447 TPtr8 appPtr = appId->Des(); |
|
448 aMessage.ReadL( 0, appPtr ); |
|
449 |
|
450 HBufC* tmpAppId = CnvUtfConverter::ConvertToUnicodeFromUtf8L( *appId ); |
|
451 CleanupStack::PopAndDestroy( appId ); |
|
452 |
|
453 delete iApplicationId; |
|
454 iApplicationId = tmpAppId; |
|
455 |
|
456 // get the brand id |
|
457 bufferSize = aMessage.GetDesLength( 1 ); |
|
458 HBufC8* streamBuf = HBufC8::NewLC( bufferSize ); |
|
459 TPtr8 streamPtr = streamBuf->Des(); |
|
460 aMessage.ReadL( 1, streamPtr ); |
|
461 |
|
462 RDesReadStream stream; |
|
463 CleanupClosePushL( stream ); |
|
464 stream.Open( streamPtr ); |
|
465 |
|
466 TInt descriptorLength = stream.ReadInt16L(); |
|
467 HBufC8* brandId = HBufC8::NewLC( descriptorLength ); |
|
468 TPtr8 brandPtr = brandId->Des(); |
|
469 stream.ReadL( brandPtr, descriptorLength ); |
|
470 |
|
471 HBufC* tmpBrandId = CnvUtfConverter::ConvertToUnicodeFromUtf8L( *brandId ); |
|
472 CleanupStack::PopAndDestroy( brandId ); |
|
473 delete iBrandId; |
|
474 iBrandId = tmpBrandId; |
|
475 |
|
476 descriptorLength = stream.ReadInt16L(); |
|
477 HBufC8* defaultBrandId = HBufC8::NewLC( descriptorLength ); |
|
478 TPtr8 defaultPtr = defaultBrandId->Des(); |
|
479 stream.ReadL( defaultPtr, descriptorLength ); |
|
480 |
|
481 HBufC* tmpDefaultBrandId = CnvUtfConverter::ConvertToUnicodeFromUtf8L( *defaultBrandId ); |
|
482 CleanupStack::PopAndDestroy( defaultBrandId ); |
|
483 delete iDefaultBrandId; |
|
484 iDefaultBrandId = tmpDefaultBrandId; |
|
485 |
|
486 CleanupStack::PopAndDestroy( 2, streamBuf ); // stream, streamBuf |
|
487 |
|
488 |
|
489 // get the language id |
|
490 iLanguageId = (TLanguage)aMessage.Int2(); |
|
491 |
|
492 // get the version |
|
493 iReserved = aMessage.Int3(); |
|
494 |
|
495 // Check if brand is discarded and client is trying to access/append/replace on that |
|
496 // give error message saying brand not found so that client will not use that brand |
|
497 if(aType == EBSTxAccess || aType == EBSTxAppend || aType == EBSTxReplace ) |
|
498 { |
|
499 if(!iStorageManager) |
|
500 { |
|
501 iStorageManager = CBSStorageManager::NewL( this, *iApplicationId ); |
|
502 } |
|
503 |
|
504 TBool brandDiscarded = EFalse ; |
|
505 brandDiscarded = iStorageManager->CheckBrandDiscarded(*iApplicationId, *iBrandId) ; |
|
506 |
|
507 if(brandDiscarded) |
|
508 { |
|
509 TRACE( T_LIT("CBSSession::InitUpdateL: Brand discarded!->LeaveWith KErrNotFound") ); |
|
510 ///Server()->DisplaySessionInfoL( this, KErrNotFound ); |
|
511 User::Leave( KErrNotFound ); |
|
512 } |
|
513 } |
|
514 |
|
515 if( aType == EBSTxAppend ) |
|
516 { |
|
517 PrepareAppendL(); |
|
518 } |
|
519 else if( aType == EBSTxReplace ) |
|
520 { |
|
521 PrepareReplaceL(); |
|
522 } |
|
523 else if(aType == EBSTxUninstall) |
|
524 { |
|
525 if( !iStorageManager ) |
|
526 { |
|
527 iStorageManager = CBSStorageManager::NewL( this, *iApplicationId ); |
|
528 } |
|
529 // if any client is accessing same brand leave with KErrInUse. |
|
530 // check if the brand has any active clients |
|
531 TBool brandActive = EFalse; |
|
532 CBSServer* server = Server(); |
|
533 if( server ) |
|
534 { |
|
535 brandActive = server->MatchSessionUninstallL( *iApplicationId, *iBrandId, |
|
536 this); |
|
537 } |
|
538 |
|
539 if(brandActive) |
|
540 { |
|
541 TRACE( T_LIT("CBSSession::InitUpdateL: UnInstallation aborted -> LeaveWith KErrInUse") ); |
|
542 //Server()->DisplaySessionInfoL( this,KErrInUse); |
|
543 //when changing this errorcode: please read the note in |
|
544 //UninstallL() ( installer.cpp ) |
|
545 User::Leave( KErrInUse ); |
|
546 } |
|
547 } |
|
548 else if( aType == EBSTxInstall ) |
|
549 { |
|
550 if( !iStorageManager ) |
|
551 { |
|
552 iStorageManager = CBSStorageManager::NewL( this, *iApplicationId ); |
|
553 } |
|
554 |
|
555 HBufC* drive = HBufC::NewLC(3); |
|
556 TRAPD( err, iStorageManager->GetNewestVersionL( *iApplicationId, |
|
557 *iBrandId, |
|
558 iLanguageId ) ); |
|
559 if( ( err == KErrNotFound ) || ( err == KErrPathNotFound ) ) |
|
560 { |
|
561 CleanupStack::PopAndDestroy(drive); |
|
562 // this brand is not yet there, which is the correct situation here |
|
563 // for starting install. We can just ignore this error |
|
564 } |
|
565 |
|
566 else if( !err ) |
|
567 { |
|
568 // there was no error, therefore this brand already exists in the ROM |
|
569 // (Z drive). |
|
570 // we leave with KErrAlreadyExists |
|
571 if( 0 == (drive->Des().Compare(KBSZDrive)) ) |
|
572 { |
|
573 CleanupStack::PopAndDestroy(drive); |
|
574 User::Leave( KErrAlreadyExists ); |
|
575 } |
|
576 else |
|
577 { |
|
578 //PopAndDestroy drive as it is not needed any longer. |
|
579 CleanupStack::PopAndDestroy(drive); |
|
580 |
|
581 // if any client is accessing same brand leave with KErrInUse. |
|
582 // check if the brand has any active clients |
|
583 TBool brandActive = EFalse; |
|
584 CBSServer* server = Server(); |
|
585 if( server ) |
|
586 { |
|
587 brandActive = server->MatchSessionL( *iApplicationId, *iBrandId, |
|
588 iLanguageId, this, iReserved ); |
|
589 } |
|
590 |
|
591 if(brandActive == EFalse) |
|
592 { |
|
593 TRACE( T_LIT("CBSSession::InitUpdateL: Brand not used -> remove") ); |
|
594 iStorageManager->RemoveBrandL( *iApplicationId, *iBrandId, |
|
595 iLanguageId, iReserved ); |
|
596 } |
|
597 else |
|
598 { |
|
599 TRACE( T_LIT("CBSSession::InitUpdateL: Installation aborted->LeaveWith KErrInUse") ); |
|
600 //Server()->DisplaySessionInfoL( this,KErrInUse); |
|
601 //when changing this errorcode: please read the note in |
|
602 //UninstallL() ( installer.cpp ) |
|
603 User::Leave( KErrInUse ); |
|
604 } |
|
605 } |
|
606 } |
|
607 else |
|
608 { |
|
609 CleanupStack::PopAndDestroy(drive); |
|
610 // some other error |
|
611 TRACE( T_LIT("CBSSession::InitUpdateL: ERROR aType[%d] LeaveWith[%d]"),aType,err ); |
|
612 User::Leave( err ); |
|
613 } |
|
614 } |
|
615 |
|
616 |
|
617 iInitialized = ETrue; |
|
618 |
|
619 TRACE( T_LIT("Server initialized") ); |
|
620 } |
|
621 |
|
622 |
|
623 |
|
624 // --------------------------------------------------------- |
|
625 // CBSSession::PrepareAppendL |
|
626 // |
|
627 // (other items were commented in a header). |
|
628 // --------------------------------------------------------- |
|
629 // |
|
630 void CBSSession::PrepareAppendL() |
|
631 { |
|
632 if( !iStorageManager ) |
|
633 { |
|
634 iStorageManager = CBSStorageManager::NewL( this, *iApplicationId ); |
|
635 } |
|
636 |
|
637 RFile brandHandle; |
|
638 iStorageManager->BrandHandleL( *iApplicationId, |
|
639 *iBrandId, iLanguageId, brandHandle, iReserved ); |
|
640 CleanupClosePushL( brandHandle ); |
|
641 RFileReadStream oldStream; |
|
642 oldStream.Attach( brandHandle ); |
|
643 CleanupClosePushL( oldStream ); |
|
644 TInt version = oldStream.ReadInt16L(); |
|
645 |
|
646 TInt count = oldStream.ReadInt16L(); |
|
647 |
|
648 if( !iStorageManager->Storage() ) |
|
649 { |
|
650 iStorageManager->CreateStorageL(); |
|
651 } |
|
652 for( TInt i = 0; i < count; i++ ) |
|
653 { |
|
654 MBSElement* element = InternalizeElementL( oldStream, ETrue ); |
|
655 CleanupDeletePushL( element ); |
|
656 // transfers ownership |
|
657 iStorageManager->Storage()->AppendElementsL( element ); |
|
658 CleanupStack::Pop(); // element |
|
659 } |
|
660 |
|
661 iStorageManager->Storage()->SetVersion( iReserved ); |
|
662 iStorageManager->Storage()->SetStorageIdL( *iBrandId ); |
|
663 iStorageManager->Storage()->SetApplicationIdL( *iApplicationId ); |
|
664 iStorageManager->Storage()->SetLanguageL( iLanguageId ); |
|
665 |
|
666 CleanupStack::PopAndDestroy( 2 ); // oldStream, brandHandle |
|
667 iAppending = ETrue; |
|
668 } |
|
669 // --------------------------------------------------------- |
|
670 // CBSSession::PrepareReplaceL |
|
671 // |
|
672 // (other items were commented in a header). |
|
673 // --------------------------------------------------------- |
|
674 // |
|
675 void CBSSession::PrepareReplaceL() |
|
676 { |
|
677 PrepareAppendL(); |
|
678 } |
|
679 |
|
680 // --------------------------------------------------------- |
|
681 // CBSSession::InitAccessL |
|
682 // |
|
683 // (other items were commented in a header). |
|
684 // --------------------------------------------------------- |
|
685 // |
|
686 void CBSSession::InitAccessL( const RMessage2 &aMessage ) |
|
687 { |
|
688 InitUpdateL( aMessage, EBSTxAccess ); |
|
689 |
|
690 iBranding = CBSBrandHandler::NewL( *iApplicationId, *iBrandId, *iDefaultBrandId, |
|
691 iLanguageId, this, iReserved ); |
|
692 |
|
693 |
|
694 iAccessInit = ETrue; |
|
695 TRACE( T_LIT("Access initialized") ); |
|
696 } |
|
697 |
|
698 |
|
699 // --------------------------------------------------------- |
|
700 // CBSSession::GetTextL |
|
701 // |
|
702 // (other items were commented in a header). |
|
703 // --------------------------------------------------------- |
|
704 // |
|
705 void CBSSession::GetTextL( const RMessage2 &aMessage ) |
|
706 { |
|
707 if( !iAccessInit ) |
|
708 { |
|
709 User::Leave( KErrNotReady ); |
|
710 } |
|
711 TInt idSize( aMessage.GetDesLength( 0 ) ); |
|
712 |
|
713 HBufC8* idBuffer = HBufC8::NewLC( idSize ); |
|
714 TPtr8 ptrId = idBuffer->Des(); |
|
715 aMessage.ReadL( 0, ptrId ); |
|
716 |
|
717 HBufC* temp = iBranding->GetTextL( ptrId ); |
|
718 delete iText; |
|
719 iText = temp; |
|
720 |
|
721 CleanupStack::PopAndDestroy( idBuffer ); |
|
722 TPckgC<TInt> pack( iText->Size() ); |
|
723 aMessage.WriteL( 1, pack ); |
|
724 TRACE( T_LIT("aMessage.WriteL( 1, %d );"), iText->Size() ); |
|
725 } |
|
726 |
|
727 void CBSSession :: isBrandUpdateRequiredL (const RMessage2 &aMessage) |
|
728 { |
|
729 if( !iAccessInit ) |
|
730 { |
|
731 User::Leave( KErrNotReady ); |
|
732 } |
|
733 TInt updateRequired = iBranding->isBrandUpdateRequiredL (); |
|
734 // iValue = updateRequired; |
|
735 TPckgC <TInt> pack (updateRequired); |
|
736 aMessage.WriteL( 0, pack ); |
|
737 } |
|
738 // --------------------------------------------------------- |
|
739 // CBSSession::GetIntL |
|
740 // |
|
741 // (other items were commented in a header). |
|
742 // --------------------------------------------------------- |
|
743 // |
|
744 void CBSSession::GetIntL( const RMessage2 &aMessage ) |
|
745 { |
|
746 if( !iInitialized ) |
|
747 { |
|
748 User::Leave( KErrNotReady ); |
|
749 } |
|
750 TInt idSize( aMessage.GetDesLength( 0 ) ); |
|
751 |
|
752 HBufC8* idBuffer = HBufC8::NewLC( idSize ); |
|
753 TPtr8 ptrId = idBuffer->Des(); |
|
754 aMessage.ReadL( 0, ptrId ); |
|
755 |
|
756 iValue = iBranding->GetIntL( ptrId ); |
|
757 TPckgC<TInt> pack( iValue ); |
|
758 aMessage.WriteL( 1, pack ); |
|
759 CleanupStack::PopAndDestroy( idBuffer ); |
|
760 } |
|
761 |
|
762 // --------------------------------------------------------- |
|
763 // CBSSession::GetBufferL |
|
764 // |
|
765 // (other items were commented in a header). |
|
766 // --------------------------------------------------------- |
|
767 // |
|
768 void CBSSession::GetBufferL( const RMessage2 &aMessage ) |
|
769 { |
|
770 if( !iAccessInit ) |
|
771 { |
|
772 User::Leave( KErrNotReady ); |
|
773 } |
|
774 TInt idSize( aMessage.GetDesLength( 0 ) ); |
|
775 |
|
776 HBufC8* idBuffer = HBufC8::NewLC( idSize ); |
|
777 TPtr8 ptrId = idBuffer->Des(); |
|
778 aMessage.ReadL( 0, ptrId ); |
|
779 |
|
780 HBufC8* temp = iBranding->GetBufferL( ptrId ); |
|
781 delete iBuffer; |
|
782 iBuffer = temp; |
|
783 |
|
784 CleanupStack::PopAndDestroy( idBuffer ); |
|
785 TPckgC<TInt> pack( iBuffer->Size() ); |
|
786 aMessage.WriteL( 1, pack ); |
|
787 TRACE( T_LIT("aMessage.WriteL( 1, %d );"), iBuffer->Size() ); |
|
788 } |
|
789 |
|
790 |
|
791 // --------------------------------------------------------- |
|
792 // CBSSession::GetFileL |
|
793 // |
|
794 // (other items were commented in a header). |
|
795 // --------------------------------------------------------- |
|
796 // |
|
797 void CBSSession::GetFileL( const RMessage2 &aMessage ) |
|
798 { |
|
799 TRACE( T_LIT("CBSSession::GetFileL begin") ); |
|
800 if( !iInitialized ) |
|
801 { |
|
802 User::Leave( KErrNotReady ); |
|
803 } |
|
804 TInt idSize( aMessage.GetDesLength( 2 ) ); |
|
805 HBufC8* idBuffer = HBufC8::NewLC( idSize ); |
|
806 TPtr8 ptrId = idBuffer->Des(); |
|
807 aMessage.ReadL( 2, ptrId ); |
|
808 |
|
809 RFile file; |
|
810 iBranding->GetFileL( ptrId, file ); |
|
811 |
|
812 CleanupStack::PopAndDestroy( idBuffer ); |
|
813 |
|
814 User::LeaveIfError( file.TransferToClient( aMessage, 0 ) ); |
|
815 |
|
816 iMessageCompleted = ETrue; |
|
817 |
|
818 file.Close(); |
|
819 TRACE( T_LIT("CBSSession::GetFileL end") ); |
|
820 } |
|
821 |
|
822 |
|
823 // --------------------------------------------------------- |
|
824 // CBSSession::InternalizeElementIdsL |
|
825 // |
|
826 // (other items were commented in a header). |
|
827 // --------------------------------------------------------- |
|
828 // |
|
829 void CBSSession::InternalizeElementIdsL( RReadStream& aStream, RBSObjOwningPtrArray<HBufC8>& aArray ) |
|
830 { |
|
831 TInt count = aStream.ReadInt16L(); |
|
832 |
|
833 for(TInt i = 0; i < count; i++ ) |
|
834 { |
|
835 TInt length = aStream.ReadInt16L(); |
|
836 HBufC8* id = HBufC8::NewLC( length ); |
|
837 TPtr8 ptrId = id->Des(); |
|
838 aStream.ReadL( ptrId, length ); |
|
839 aArray.AppendL( id ); |
|
840 CleanupStack::Pop( id ); |
|
841 } |
|
842 } |
|
843 |
|
844 // --------------------------------------------------------- |
|
845 // CBSSession::PrepareTextL |
|
846 // |
|
847 // (other items were commented in a header). |
|
848 // --------------------------------------------------------- |
|
849 // |
|
850 void CBSSession::PrepareSeveralL( const RMessage2 &aMessage ) |
|
851 { |
|
852 if( !iInitialized ) |
|
853 { |
|
854 User::Leave( KErrNotReady ); |
|
855 } |
|
856 |
|
857 TInt msgSize( aMessage.GetDesLength( 1 ) ); |
|
858 |
|
859 HBufC8* idBuffer = HBufC8::NewLC( msgSize ); |
|
860 TPtr8 ptrId = idBuffer->Des(); |
|
861 aMessage.ReadL( 1, ptrId ); |
|
862 |
|
863 RDesReadStream idStream; |
|
864 CleanupClosePushL( idStream ); |
|
865 idStream.Open( ptrId ); |
|
866 |
|
867 RBSObjOwningPtrArray<HBufC8> idArray; |
|
868 CleanupClosePushL( idArray ); |
|
869 |
|
870 InternalizeElementIdsL( idStream, idArray ); |
|
871 |
|
872 |
|
873 MBSElement* texts = iBranding->GetSeveralL( idArray ); |
|
874 |
|
875 CleanupStack::PopAndDestroy(); // idArray |
|
876 CleanupStack::PopAndDestroy(); // idStream |
|
877 CleanupStack::PopAndDestroy(); // idBuffer |
|
878 |
|
879 CleanupDeletePushL( texts ); |
|
880 |
|
881 // FIXME magic number |
|
882 CBufFlat* data = CBufFlat::NewL( 2000 ); |
|
883 CleanupStack::PushL( data ); |
|
884 |
|
885 RBufWriteStream writeStream; |
|
886 CleanupClosePushL( writeStream ); |
|
887 writeStream.Open( *data ); |
|
888 |
|
889 texts->ExternalizeL( writeStream ); |
|
890 |
|
891 CleanupStack::PopAndDestroy(); // writeStream |
|
892 |
|
893 delete iSeveralData; |
|
894 iSeveralData = data; |
|
895 CleanupStack::Pop( data ); |
|
896 |
|
897 CleanupStack::PopAndDestroy(); // texts |
|
898 |
|
899 delete iBuffer; |
|
900 iBuffer = NULL; |
|
901 iBuffer = iSeveralData->Ptr(0).AllocL(); |
|
902 |
|
903 delete iSeveralData; |
|
904 iSeveralData = NULL; |
|
905 TPckgC<TInt> pack( iBuffer->Size() ); |
|
906 TRACE( T_LIT("DispatchMessageL - EPlatSecPrepareSeveral writing size %d"), iBuffer->Size() ); |
|
907 aMessage.WriteL( 0, pack ); |
|
908 |
|
909 } |
|
910 |
|
911 // --------------------------------------------------------- |
|
912 // CBSSession::GetSeveralTextL |
|
913 // |
|
914 // (other items were commented in a header). |
|
915 // --------------------------------------------------------- |
|
916 // |
|
917 void CBSSession::GetSeveralL( const RMessage2 &aMessage ) |
|
918 { |
|
919 if( !iInitialized ) |
|
920 { |
|
921 User::Leave( KErrNotReady ); |
|
922 } |
|
923 aMessage.WriteL( 0, *iBuffer ); |
|
924 |
|
925 delete iBuffer; |
|
926 iBuffer = NULL; |
|
927 } |
|
928 |
|
929 |
|
930 // --------------------------------------------------------- |
|
931 // CBSSession::PrepareStructureL |
|
932 // |
|
933 // (other items were commented in a header). |
|
934 // --------------------------------------------------------- |
|
935 // |
|
936 void CBSSession::PrepareStructureL( const RMessage2 &aMessage ) |
|
937 { |
|
938 if( !iInitialized ) |
|
939 { |
|
940 User::Leave( KErrNotReady ); |
|
941 } |
|
942 TInt idSize( aMessage.GetDesLength( 1 ) ); |
|
943 |
|
944 RBSObjOwningPtrArray<MBSElement> valueArray; |
|
945 CleanupClosePushL( valueArray ); |
|
946 |
|
947 HBufC8* idBuffer = HBufC8::NewLC( idSize ); |
|
948 TPtr8 ptrId = idBuffer->Des(); |
|
949 aMessage.ReadL( 1, ptrId ); |
|
950 |
|
951 |
|
952 MBSElement* extElement = iBranding->GetStructureL( ptrId ); |
|
953 CleanupDeletePushL( extElement ); |
|
954 // FIXME magic number |
|
955 CBufFlat* data = CBufFlat::NewL( 2000 ); |
|
956 CleanupStack::PushL( data ); |
|
957 |
|
958 RBufWriteStream writeStream; |
|
959 CleanupClosePushL( writeStream ); |
|
960 writeStream.Open( *data ); |
|
961 |
|
962 extElement->ExternalizeL( writeStream ); |
|
963 |
|
964 CleanupStack::PopAndDestroy(); // writeStream |
|
965 |
|
966 delete iSeveralData; |
|
967 iSeveralData = data; |
|
968 CleanupStack::Pop( data ); |
|
969 |
|
970 CleanupStack::PopAndDestroy( extElement ); |
|
971 |
|
972 delete iBuffer; |
|
973 iBuffer = NULL; |
|
974 iBuffer = iSeveralData->Ptr(0).AllocL(); |
|
975 |
|
976 delete iSeveralData; |
|
977 iSeveralData = NULL; |
|
978 TPckgC<TInt> pack( iBuffer->Size() ); |
|
979 TRACE( T_LIT("DispatchMessageL - EPlatSecPrepareSeveral writing size %d"), iBuffer->Size() ); |
|
980 aMessage.WriteL( 0, pack ); |
|
981 |
|
982 |
|
983 CleanupStack::PopAndDestroy(idBuffer); |
|
984 |
|
985 CleanupStack::PopAndDestroy(); // valueArray |
|
986 |
|
987 } |
|
988 |
|
989 // --------------------------------------------------------- |
|
990 // CBSSession::GetStructureL |
|
991 // |
|
992 // (other items were commented in a header). |
|
993 // --------------------------------------------------------- |
|
994 // |
|
995 void CBSSession::GetStructureL( const RMessage2 &aMessage ) |
|
996 { |
|
997 if( !iInitialized ) |
|
998 { |
|
999 User::Leave( KErrNotReady ); |
|
1000 } |
|
1001 aMessage.WriteL( 0, *iBuffer ); |
|
1002 |
|
1003 delete iBuffer; |
|
1004 iBuffer = NULL; |
|
1005 } |
|
1006 |
|
1007 |
|
1008 |
|
1009 // --------------------------------------------------------- |
|
1010 // CBSSession::InstallL |
|
1011 // |
|
1012 // (other items were commented in a header). |
|
1013 // --------------------------------------------------------- |
|
1014 // |
|
1015 void CBSSession::InstallL( const RMessage2 &aMessage ) |
|
1016 { |
|
1017 TRACE( T_LIT( "CBSSession::InstallL begin") ); |
|
1018 if( !iInitialized || !iStorageManager ) |
|
1019 { |
|
1020 User::Leave( KErrNotReady ); |
|
1021 } |
|
1022 |
|
1023 if( !iStorageManager->Storage() ) |
|
1024 { |
|
1025 iStorageManager->CreateStorageL(); |
|
1026 } |
|
1027 |
|
1028 iStorageManager->ConnectTransactionL( *iApplicationId, |
|
1029 *iBrandId, iLanguageId, EFalse, iReserved ); |
|
1030 |
|
1031 TInt msgSize( aMessage.GetDesLength( 0 ) ); |
|
1032 |
|
1033 HBufC8* buffer = HBufC8::NewLC( msgSize ); |
|
1034 TPtr8 ptr = buffer->Des(); |
|
1035 aMessage.ReadL( 0, ptr ); |
|
1036 |
|
1037 RDesReadStream stream; |
|
1038 CleanupClosePushL( stream ); |
|
1039 stream.Open( ptr ); |
|
1040 |
|
1041 MBSElement* element = InternalizeElementL( stream ); |
|
1042 CleanupDeletePushL( element ); |
|
1043 |
|
1044 iStorageManager->Storage()->SetVersion( iReserved ); |
|
1045 iStorageManager->Storage()->SetStorageIdL( *iBrandId ); |
|
1046 iStorageManager->Storage()->SetApplicationIdL( *iApplicationId ); |
|
1047 iStorageManager->Storage()->SetLanguageL( iLanguageId ); |
|
1048 // transfers ownership |
|
1049 iStorageManager->Storage()->AppendElementsL( element ); |
|
1050 |
|
1051 CleanupStack::Pop(); // element |
|
1052 CleanupStack::PopAndDestroy( 2, buffer ); |
|
1053 iWriteNeeded = ETrue; |
|
1054 TRACE( T_LIT( "CBSSession::InstallL end") ); |
|
1055 } |
|
1056 |
|
1057 // --------------------------------------------------------- |
|
1058 // CBSSession::ReplaceL |
|
1059 // |
|
1060 // (other items were commented in a header). |
|
1061 // --------------------------------------------------------- |
|
1062 // |
|
1063 void CBSSession::ReplaceL( const RMessage2 &aMessage ) |
|
1064 { |
|
1065 TRACE( T_LIT( "CBSSession::ReplaceL begin") ); |
|
1066 if( !iInitialized || !iStorageManager ) |
|
1067 { |
|
1068 User::Leave( KErrNotReady ); |
|
1069 } |
|
1070 |
|
1071 iStorageManager->ConnectTransactionL( *iApplicationId, |
|
1072 *iBrandId, iLanguageId, EFalse, iReserved ); |
|
1073 |
|
1074 TInt msgSize( aMessage.GetDesLength( 0 ) ); |
|
1075 |
|
1076 HBufC8* buffer = HBufC8::NewLC( msgSize ); |
|
1077 TPtr8 ptr = buffer->Des(); |
|
1078 aMessage.ReadL( 0, ptr ); |
|
1079 |
|
1080 RDesReadStream stream; |
|
1081 CleanupClosePushL( stream ); |
|
1082 stream.Open( ptr ); |
|
1083 |
|
1084 MBSElement* element = InternalizeElementL( stream ); |
|
1085 CleanupDeletePushL( element ); |
|
1086 |
|
1087 // transfers ownership |
|
1088 iStorageManager->Storage()->ReplaceElementL( element ); |
|
1089 |
|
1090 CleanupStack::Pop(); // element |
|
1091 CleanupStack::PopAndDestroy( 2, buffer ); |
|
1092 iWriteNeeded = ETrue; |
|
1093 TRACE( T_LIT( "CBSSession::ReplaceL end") ); |
|
1094 } |
|
1095 |
|
1096 |
|
1097 // --------------------------------------------------------- |
|
1098 // CBSSession::AppendL |
|
1099 // |
|
1100 // (other items were commented in a header). |
|
1101 // --------------------------------------------------------- |
|
1102 // |
|
1103 void CBSSession::AppendL( const RMessage2 &aMessage ) |
|
1104 { |
|
1105 TRACE( T_LIT( "CBSSession::AppendL begin") ); |
|
1106 if( !iInitialized || !iStorageManager ) |
|
1107 { |
|
1108 User::Leave( KErrNotReady ); |
|
1109 } |
|
1110 |
|
1111 iStorageManager->ConnectTransactionL( *iApplicationId, |
|
1112 *iBrandId, iLanguageId, EFalse, iReserved ); |
|
1113 |
|
1114 TInt msgSize( aMessage.GetDesLength( 0 ) ); |
|
1115 |
|
1116 HBufC8* buffer = HBufC8::NewLC( msgSize ); |
|
1117 TPtr8 ptr = buffer->Des(); |
|
1118 aMessage.ReadL( 0, ptr ); |
|
1119 |
|
1120 RDesReadStream stream; |
|
1121 CleanupClosePushL( stream ); |
|
1122 stream.Open( ptr ); |
|
1123 |
|
1124 MBSElement* element = InternalizeElementL( stream ); |
|
1125 CleanupDeletePushL( element ); |
|
1126 |
|
1127 iStorageManager->Storage()->SetVersion( iReserved ); |
|
1128 iStorageManager->Storage()->SetStorageIdL( *iBrandId ); |
|
1129 iStorageManager->Storage()->SetApplicationIdL( *iApplicationId ); |
|
1130 iStorageManager->Storage()->SetLanguageL( iLanguageId ); |
|
1131 // transfers ownership |
|
1132 iStorageManager->Storage()->AppendElementsL( element ); |
|
1133 |
|
1134 CleanupStack::Pop(); // element |
|
1135 CleanupStack::PopAndDestroy( 2, buffer ); |
|
1136 iWriteNeeded = ETrue; |
|
1137 TRACE( T_LIT( "CBSSession::AppendL end") ); |
|
1138 } |
|
1139 |
|
1140 // --------------------------------------------------------- |
|
1141 // CBSSession::StartTransactionL |
|
1142 // |
|
1143 // (other items were commented in a header). |
|
1144 // --------------------------------------------------------- |
|
1145 // |
|
1146 void CBSSession::StartTransactionL( const RMessage2& /*aMessage*/ ) |
|
1147 { |
|
1148 if( !iStorageManager ) |
|
1149 { |
|
1150 iStorageManager = CBSStorageManager::NewL( this, *iApplicationId ); |
|
1151 } |
|
1152 // if we are appending or replacing, we don't need to |
|
1153 // create storage |
|
1154 if( !iAppending ) |
|
1155 { |
|
1156 iStorageManager->CreateStorageL(); |
|
1157 } |
|
1158 } |
|
1159 |
|
1160 |
|
1161 // --------------------------------------------------------- |
|
1162 // CBSSession::CancelTransactionL |
|
1163 // |
|
1164 // (other items were commented in a header). |
|
1165 // --------------------------------------------------------- |
|
1166 // |
|
1167 void CBSSession::CancelTransactionL( const RMessage2 &aMessage ) |
|
1168 { |
|
1169 // get the application id |
|
1170 TInt bufferSize( aMessage.GetDesLength( 0 ) ); |
|
1171 |
|
1172 HBufC8* appId = HBufC8::NewLC( bufferSize ); |
|
1173 TPtr8 appPtr = appId->Des(); |
|
1174 aMessage.ReadL( 0, appPtr ); |
|
1175 |
|
1176 |
|
1177 // get the brand id |
|
1178 bufferSize = aMessage.GetDesLength( 1 ); |
|
1179 HBufC8* brandId = HBufC8::NewLC( bufferSize ); |
|
1180 TPtr8 brandPtr = brandId->Des(); |
|
1181 aMessage.ReadL( 1, brandPtr ); |
|
1182 |
|
1183 // get the language id |
|
1184 TLanguage language = (TLanguage)aMessage.Int2(); |
|
1185 |
|
1186 // get the version |
|
1187 TInt version = aMessage.Int3(); |
|
1188 |
|
1189 |
|
1190 HBufC* tmpBrandId = CnvUtfConverter::ConvertToUnicodeFromUtf8L( *brandId ); |
|
1191 CleanupStack::PopAndDestroy( brandId ); |
|
1192 CleanupStack::PushL( tmpBrandId ); |
|
1193 HBufC* tmpAppId = CnvUtfConverter::ConvertToUnicodeFromUtf8L( *appId ); |
|
1194 CleanupStack::PushL( tmpAppId ); |
|
1195 |
|
1196 // check if the transaction is correct |
|
1197 iStorageManager->ConnectTransactionL( *tmpAppId, |
|
1198 *tmpBrandId, iLanguageId, |
|
1199 EFalse, iReserved ); |
|
1200 |
|
1201 CleanupStack::PopAndDestroy( 2, tmpBrandId ); // tmpBrandId, tmpAppId |
|
1202 CleanupStack::PopAndDestroy( appId ); |
|
1203 // cancel the transaction |
|
1204 iStorageManager->CancelTransactionL(); |
|
1205 iWriteNeeded = EFalse; |
|
1206 } |
|
1207 |
|
1208 // --------------------------------------------------------- |
|
1209 // CBSSession::StopTransactionL |
|
1210 // |
|
1211 // (other items were commented in a header). |
|
1212 // --------------------------------------------------------- |
|
1213 // |
|
1214 void CBSSession::StopTransactionL( const RMessage2 &aMessage ) |
|
1215 { |
|
1216 if( !iStorageManager ) |
|
1217 { |
|
1218 // transaction not found |
|
1219 User::Leave( KErrNotFound ); |
|
1220 } |
|
1221 if( iAppending ) |
|
1222 { |
|
1223 // find next available version number |
|
1224 TInt nextVersion = iStorageManager->NextAvailableVersionL(); |
|
1225 iStorageManager->SetVersion( nextVersion ); |
|
1226 iStorageManager->Storage()->SetVersion( nextVersion ); |
|
1227 } |
|
1228 |
|
1229 if( iWriteNeeded ) |
|
1230 { |
|
1231 iReserved = iStorageManager->WriteStorageFilesL(); |
|
1232 iWriteNeeded = EFalse; |
|
1233 } |
|
1234 |
|
1235 delete iStorageManager; |
|
1236 iStorageManager = NULL; |
|
1237 |
|
1238 TPckgC<TInt> pack( iReserved ); |
|
1239 aMessage.WriteL( 0, pack ); |
|
1240 |
|
1241 } |
|
1242 |
|
1243 |
|
1244 // --------------------------------------------------------- |
|
1245 // CBSSession::InternalizeElementL |
|
1246 // |
|
1247 // (other items were commented in a header). |
|
1248 // --------------------------------------------------------- |
|
1249 // |
|
1250 MBSElement* CBSSession::InternalizeElementL( RReadStream& aStream, TBool aAppending /*= EFalse*/ ) |
|
1251 { |
|
1252 MBSElement* returnValue = NULL; |
|
1253 |
|
1254 TBSElementType type = (TBSElementType)aStream.ReadInt16L(); |
|
1255 TInt idSize = aStream.ReadInt16L(); |
|
1256 HBufC8* elementId = HBufC8::NewLC( idSize ); |
|
1257 TPtr8 elementIdPtr = elementId->Des(); |
|
1258 aStream.ReadL( elementIdPtr, idSize ); |
|
1259 |
|
1260 |
|
1261 switch( type ) |
|
1262 { |
|
1263 case EBSInt: |
|
1264 { |
|
1265 TInt intData = aStream.ReadInt16L(); |
|
1266 returnValue = BSElementFactory::CreateBSElementL( *elementId, |
|
1267 EBSInt, |
|
1268 intData ); |
|
1269 break; |
|
1270 } |
|
1271 case EBSText: |
|
1272 { |
|
1273 TInt textSize = aStream.ReadInt16L(); |
|
1274 HBufC* textData = HBufC::NewLC( textSize ); |
|
1275 |
|
1276 TPtr textPtr = textData->Des(); |
|
1277 aStream.ReadL( textPtr, textSize ); |
|
1278 |
|
1279 returnValue = BSElementFactory::CreateBSElementL( *elementId, |
|
1280 type, |
|
1281 *textData ); |
|
1282 |
|
1283 CleanupStack::Pop( textData ); |
|
1284 break; |
|
1285 } |
|
1286 |
|
1287 case EBSFile: |
|
1288 { |
|
1289 TInt nameSize = aStream.ReadInt16L(); |
|
1290 HBufC* fileName = HBufC::NewLC( nameSize ); |
|
1291 |
|
1292 TPtr filePtr = fileName->Des(); |
|
1293 aStream.ReadL( filePtr, nameSize ); |
|
1294 |
|
1295 if( !aAppending ) |
|
1296 { |
|
1297 // we are installing, so the filename is pointing to a file |
|
1298 // that has to be installed |
|
1299 // Install file and get the filename without path |
|
1300 HBufC* strippedName = iStorageManager->InstallFileLC( *fileName ); |
|
1301 returnValue = BSElementFactory::CreateBSElementL( *elementId, |
|
1302 type, |
|
1303 *strippedName ); |
|
1304 CleanupStack::Pop( strippedName ); |
|
1305 CleanupStack::PopAndDestroy( fileName ); |
|
1306 } |
|
1307 else |
|
1308 { |
|
1309 // we are appending, so this is really the filename |
|
1310 returnValue = BSElementFactory::CreateBSElementL( *elementId, |
|
1311 type, |
|
1312 *fileName ); |
|
1313 CleanupStack::Pop( fileName ); |
|
1314 } |
|
1315 break; |
|
1316 } |
|
1317 |
|
1318 case EBSList: |
|
1319 { |
|
1320 RBSObjOwningPtrArray<MBSElement> listData; |
|
1321 CleanupClosePushL( listData ); |
|
1322 TInt listCount = aStream.ReadInt16L(); |
|
1323 for( TInt i = 0; i < listCount; i++ ) |
|
1324 { |
|
1325 MBSElement* listElement = InternalizeElementL( aStream ); |
|
1326 CleanupDeletePushL( listElement ); |
|
1327 listData.AppendL( listElement ); |
|
1328 CleanupStack::Pop(); // listElement |
|
1329 } |
|
1330 |
|
1331 returnValue = BSElementFactory::CreateBSElementL( *elementId, |
|
1332 EBSList, |
|
1333 listData ); |
|
1334 CleanupStack::Pop(); // listData |
|
1335 break; |
|
1336 } |
|
1337 case EBSBuffer: |
|
1338 { |
|
1339 TInt bufferSize = aStream.ReadInt16L(); |
|
1340 HBufC8* buffer = HBufC8::NewLC( bufferSize ); |
|
1341 |
|
1342 TPtr8 buffPtr = buffer->Des(); |
|
1343 aStream.ReadL( buffPtr, bufferSize ); |
|
1344 |
|
1345 returnValue = BSElementFactory::CreateBSElementL( *elementId, |
|
1346 EBSBuffer, |
|
1347 *buffer ); |
|
1348 |
|
1349 CleanupStack::Pop( buffer ); |
|
1350 break; |
|
1351 } |
|
1352 case EBSBitmap: |
|
1353 { |
|
1354 TInt length = aStream.ReadInt16L(); |
|
1355 HBufC8* fileId = HBufC8::NewLC( length ); |
|
1356 |
|
1357 TPtr8 fileIdPtr = fileId->Des(); |
|
1358 aStream.ReadL( fileIdPtr, length ); |
|
1359 |
|
1360 TInt bitmapId = aStream.ReadInt16L(); |
|
1361 TInt maskId = aStream.ReadInt16L(); |
|
1362 TInt skinId = aStream.ReadInt16L(); |
|
1363 TInt skinMaskId = aStream.ReadInt16L(); |
|
1364 |
|
1365 |
|
1366 CBSBitmap* bitmap = CBSBitmap::NewLC( bitmapId, |
|
1367 maskId, |
|
1368 skinId, |
|
1369 skinMaskId, |
|
1370 fileIdPtr ); |
|
1371 |
|
1372 returnValue = BSElementFactory::CreateBSElementL( *elementId, |
|
1373 EBSBitmap, |
|
1374 bitmap ); |
|
1375 CleanupStack::Pop( bitmap ); |
|
1376 CleanupStack::PopAndDestroy( fileId ); |
|
1377 break; |
|
1378 } |
|
1379 |
|
1380 default: |
|
1381 { |
|
1382 User::Leave( KErrArgument ); |
|
1383 break; |
|
1384 } |
|
1385 } |
|
1386 |
|
1387 CleanupStack::PopAndDestroy( elementId ); |
|
1388 |
|
1389 return returnValue; |
|
1390 } |
|
1391 |
|
1392 |
|
1393 // --------------------------------------------------------- |
|
1394 // CBSSession::MatchSessionL |
|
1395 // |
|
1396 // (other items were commented in a header). |
|
1397 // --------------------------------------------------------- |
|
1398 // |
|
1399 TBool CBSSession::MatchSessionL( const TDesC& aApplicationId, |
|
1400 const TDesC& aBrandId, |
|
1401 TLanguage aLanguageId, |
|
1402 TInt aReserved ) |
|
1403 { |
|
1404 TBool returnValue = EFalse; |
|
1405 if( iApplicationId && iBrandId ) |
|
1406 { |
|
1407 if( ( 0 == iApplicationId->Compare( aApplicationId ) ) && |
|
1408 ( 0 == iBrandId->Compare( aBrandId ) ) && |
|
1409 ( iLanguageId == aLanguageId ) && |
|
1410 ( iReserved == aReserved )) |
|
1411 { |
|
1412 returnValue = ETrue; |
|
1413 } |
|
1414 } |
|
1415 |
|
1416 return returnValue; |
|
1417 } |
|
1418 |
|
1419 // --------------------------------------------------------- |
|
1420 // CBSSession::MatchSessionL |
|
1421 // |
|
1422 // (other items were commented in a header). |
|
1423 // --------------------------------------------------------- |
|
1424 // |
|
1425 TBool CBSSession::MatchSessionUninstallL( const TDesC& aApplicationId, |
|
1426 const TDesC& aBrandId) |
|
1427 { |
|
1428 TBool returnValue = EFalse; |
|
1429 if( iApplicationId && iBrandId ) |
|
1430 { |
|
1431 if( ( 0 == iApplicationId->Compare( aApplicationId ) ) && |
|
1432 ( 0 == iBrandId->Compare( aBrandId ) ) ) |
|
1433 { |
|
1434 returnValue = ETrue; |
|
1435 } |
|
1436 } |
|
1437 |
|
1438 return returnValue; |
|
1439 } |
|
1440 // --------------------------------------------------------- |
|
1441 // CBSSession::BrandUpdatedL |
|
1442 // |
|
1443 // (other items were commented in a header). |
|
1444 // --------------------------------------------------------- |
|
1445 // |
|
1446 void CBSSession::BrandUpdatedL( const TDesC& aApplicationId, |
|
1447 const TDesC& aBrandId, |
|
1448 TLanguage aLanguageId, |
|
1449 TInt /*aReserved*/ ) |
|
1450 { |
|
1451 TRACE( T_LIT( "CBSSession::BrandUpdatedL begin aAppId[%S] aBrandId[%S]"), &aApplicationId, &aBrandId ); |
|
1452 iIsBackup = EFalse ; |
|
1453 if( iApplicationId && iBrandId ) |
|
1454 { |
|
1455 if( ( 0 == iApplicationId->Compare( aApplicationId ) ) && |
|
1456 ( 0 == iBrandId->Compare( aBrandId ) ) && |
|
1457 ( iLanguageId == aLanguageId ) ) |
|
1458 { |
|
1459 // this event is for us |
|
1460 // complete the observer request from client |
|
1461 if( iObserverActive ) |
|
1462 { |
|
1463 iObserverMessage.Complete( KErrNone ); |
|
1464 iObserverActive = EFalse; |
|
1465 } |
|
1466 } |
|
1467 } |
|
1468 TRACE( T_LIT( "CBSSession::BrandUpdatedL end") ); |
|
1469 } |
|
1470 |
|
1471 |
|
1472 // --------------------------------------------------------- |
|
1473 // CBSSession::RemoveBrandL |
|
1474 // |
|
1475 // (other items were commented in a header). |
|
1476 // --------------------------------------------------------- |
|
1477 // |
|
1478 void CBSSession::RemoveBrandL( const RMessage2& /*aMessage*/ ) |
|
1479 { |
|
1480 TRACE( T_LIT( "CBSSession::RemoveBrandL begin") ); |
|
1481 if( !iInitialized || !iStorageManager ) |
|
1482 { |
|
1483 User::Leave( KErrNotReady ); |
|
1484 } |
|
1485 |
|
1486 iStorageManager->RemoveBrandL( *iApplicationId, *iBrandId, |
|
1487 iLanguageId, iReserved ); |
|
1488 |
|
1489 |
|
1490 |
|
1491 TRACE( T_LIT( "CBSSession::RemoveBrandL end") ); |
|
1492 } |
|
1493 |
|
1494 // --------------------------------------------------------- |
|
1495 // CBSSession::RemoveApplicationL |
|
1496 // |
|
1497 // (other items were commented in a header). |
|
1498 // --------------------------------------------------------- |
|
1499 // |
|
1500 void CBSSession::RemoveApplicationL( const RMessage2& /*aMessage*/ ) |
|
1501 { |
|
1502 TRACE( T_LIT( "CBSSession::RemoveApplicationL begin") ); |
|
1503 if( !iInitialized || !iStorageManager ) |
|
1504 { |
|
1505 User::Leave( KErrNotReady ); |
|
1506 } |
|
1507 iStorageManager->RemoveApplicationL( *iApplicationId ); |
|
1508 TRACE( T_LIT( "CBSSession::RemoveApplicationL end") ); |
|
1509 } |
|
1510 |
|
1511 // --------------------------------------------------------- |
|
1512 // CBSSession::GetNewVersionL |
|
1513 // |
|
1514 // (other items were commented in a header). |
|
1515 // --------------------------------------------------------- |
|
1516 // |
|
1517 TInt CBSSession::GetNewVersionL() |
|
1518 { |
|
1519 if( !iStorageManager ) |
|
1520 { |
|
1521 iStorageManager = CBSStorageManager::NewL( this, KNullDesC ); |
|
1522 } |
|
1523 |
|
1524 return iStorageManager->GetNewestVersionL( *iApplicationId, *iBrandId, iLanguageId ); |
|
1525 } |
|
1526 |
|
1527 |
|
1528 // CBSSessionInfo |
|
1529 CBSSession::CBSSessionInfo* CBSSession::CBSSessionInfo::NewL( const TDesC& aFileName, |
|
1530 const TDesC& aCaption, |
|
1531 TThreadId aThreadId, |
|
1532 TProcessId aProcessId ) |
|
1533 { |
|
1534 CBSSessionInfo* self = new( ELeave ) CBSSessionInfo( aThreadId, aProcessId ); |
|
1535 CleanupStack::PushL( self ); |
|
1536 self->ConstructL( aFileName, aCaption ); |
|
1537 CleanupStack::Pop( self ); |
|
1538 return self; |
|
1539 } |
|
1540 void CBSSession::CBSSessionInfo::ConstructL( const TDesC& aFileName, const TDesC& aCaption ) |
|
1541 { |
|
1542 iFileName = aFileName.AllocL(); |
|
1543 iCaption = aCaption.AllocL(); |
|
1544 } |
|
1545 CBSSession::CBSSessionInfo::CBSSessionInfo( TThreadId aThreadId, TProcessId aProcessId ) |
|
1546 : iThreadId( aThreadId ), |
|
1547 iProcessId( aProcessId ) |
|
1548 { |
|
1549 } |
|
1550 CBSSession::CBSSessionInfo::~CBSSessionInfo() |
|
1551 { |
|
1552 delete iFileName; |
|
1553 delete iCaption; |
|
1554 } |
|
1555 |
|
1556 const TDesC& CBSSession::CBSSessionInfo::FileName() |
|
1557 { |
|
1558 return *iFileName; |
|
1559 } |
|
1560 const TDesC& CBSSession::CBSSessionInfo::Caption() |
|
1561 { |
|
1562 return *iCaption; |
|
1563 } |
|
1564 |
|
1565 TThreadId CBSSession::CBSSessionInfo::ThreadId() |
|
1566 { |
|
1567 return iThreadId; |
|
1568 } |
|
1569 TProcessId CBSSession::CBSSessionInfo::ProcessId() |
|
1570 { |
|
1571 return iProcessId; |
|
1572 } |
|
1573 |
|
1574 |
|
1575 // --------------------------------------------------------------------------- |
|
1576 // CBSSession::ExtractInfoL |
|
1577 // Extracts some information from the specified RMessage2 and saves it. |
|
1578 // --------------------------------------------------------------------------- |
|
1579 // |
|
1580 void CBSSession::ExtractInfoL( const RMessage2& aMessage ) |
|
1581 { |
|
1582 TRACE( T_LIT( "CBSSession::ExtractInfoL begin") ); |
|
1583 //Collect all necessary data |
|
1584 RThread thread; |
|
1585 TInt getProcessErr,getClientThreadErr; |
|
1586 getClientThreadErr = aMessage.Client( thread ); |
|
1587 CleanupClosePushL( thread ); |
|
1588 |
|
1589 if ( KErrNone == getClientThreadErr ) |
|
1590 { |
|
1591 TRACE( T_LIT( "CBSSession::ExtractInfoL Client retrieved OK") ); |
|
1592 TThreadId threadId = thread.Id(); |
|
1593 RProcess process; |
|
1594 getProcessErr = thread.Process( process ); |
|
1595 CleanupClosePushL( process ); |
|
1596 if ( getProcessErr == KErrNone ) |
|
1597 { |
|
1598 TRACE( T_LIT( "CBSSession::ExtractInfoL Processfilename retrieved OK") ); |
|
1599 TFileName fileName = process.FileName(); |
|
1600 TParsePtrC parser( fileName ); |
|
1601 TPtrC processFileNameAndExt( parser.NameAndExt() ); |
|
1602 |
|
1603 RApaLsSession session; |
|
1604 TInt connectErr = session.Connect(); |
|
1605 User :: LeaveIfError (connectErr); |
|
1606 session.GetAllApps(); |
|
1607 CleanupClosePushL( session ); |
|
1608 |
|
1609 TApaAppInfo info; |
|
1610 TPtrC captionPtr( KNullDesC ); |
|
1611 TPtrC printCaptionPtr( KNullDesC ); |
|
1612 TPtrC fullName( KNullDesC ); |
|
1613 while ( KErrNone == session.GetNextApp( info ) ) |
|
1614 { |
|
1615 fullName.Set( info.iFullName ); |
|
1616 printCaptionPtr.Set( info.iCaption ); |
|
1617 if( KErrNotFound != fullName.Find( processFileNameAndExt ) ) |
|
1618 { |
|
1619 captionPtr.Set( info.iCaption ); |
|
1620 TRACE( T_LIT( "CBSSession::ExtractInfoL caption saved: %S"),&captionPtr ); |
|
1621 break; |
|
1622 } |
|
1623 } |
|
1624 |
|
1625 CBSSessionInfo* temp = |
|
1626 CBSSessionInfo::NewL( processFileNameAndExt, |
|
1627 captionPtr, |
|
1628 threadId, |
|
1629 process.Id() ); |
|
1630 TRACE( T_LIT( "CBSSession::ExtractInfoL SessionInfo object creation OK") ); |
|
1631 delete iSessionInfo; |
|
1632 iSessionInfo = NULL; |
|
1633 iSessionInfo = temp; |
|
1634 CleanupStack::PopAndDestroy( &session ); |
|
1635 } |
|
1636 CleanupStack::PopAndDestroy( &process ); |
|
1637 } |
|
1638 CleanupStack::PopAndDestroy( &thread ); |
|
1639 TRACE( T_LIT( "CBSSession::ExtractInfoL end") ); |
|
1640 } |
|
1641 |
|
1642 |
|
1643 // --------------------------------------------------------------------------- |
|
1644 // CBSSession::FileName |
|
1645 // --------------------------------------------------------------------------- |
|
1646 // |
|
1647 const TDesC& CBSSession::FileName() |
|
1648 { |
|
1649 TRACE( T_LIT( "CBSSession::FileName begin") ); |
|
1650 if ( iSessionInfo ) |
|
1651 { |
|
1652 TRACE( T_LIT( "CBSSession::FileName SessionInfo exists") ); |
|
1653 return iSessionInfo->FileName(); |
|
1654 } |
|
1655 else |
|
1656 { |
|
1657 TRACE( T_LIT( "CBSSession::FileName SessionInfo does not exist") ); |
|
1658 return KNullDesC; |
|
1659 } |
|
1660 } |
|
1661 |
|
1662 // --------------------------------------------------------------------------- |
|
1663 // CBSSession::Caption |
|
1664 // --------------------------------------------------------------------------- |
|
1665 // |
|
1666 const TDesC& CBSSession::Caption() |
|
1667 { |
|
1668 TRACE( T_LIT( "CBSSession::Caption begin") ); |
|
1669 if ( iSessionInfo ) |
|
1670 { |
|
1671 TRACE( T_LIT( "CBSSession::Caption SessionInfo exists") ); |
|
1672 return iSessionInfo->Caption(); |
|
1673 } |
|
1674 else |
|
1675 { |
|
1676 TRACE( T_LIT( "CBSSession::Caption SessionInfo does not exist") ); |
|
1677 return KNullDesC; |
|
1678 } |
|
1679 } |
|
1680 |
|
1681 |
|
1682 // --------------------------------------------------------------------------- |
|
1683 // CBSSession::ThreadId |
|
1684 // --------------------------------------------------------------------------- |
|
1685 // |
|
1686 TInt CBSSession::ThreadId( TThreadId& aThreadId ) |
|
1687 { |
|
1688 TRACE( T_LIT( "CBSSession::ThreadId begin") ); |
|
1689 TInt err( KErrNotFound ); |
|
1690 if ( iSessionInfo ) |
|
1691 { |
|
1692 TRACE( T_LIT( "CBSSession::ThreadId SessionInfo exists") ); |
|
1693 aThreadId = iSessionInfo->ThreadId(); |
|
1694 err = KErrNone; |
|
1695 } |
|
1696 return err; |
|
1697 } |
|
1698 |
|
1699 |
|
1700 // --------------------------------------------------------------------------- |
|
1701 // CBSSession::ProcessId |
|
1702 // --------------------------------------------------------------------------- |
|
1703 // |
|
1704 TInt CBSSession::ProcessId( TProcessId& aProcessId ) |
|
1705 { |
|
1706 TRACE( T_LIT( "CBSSession::ProcessId begin") ); |
|
1707 TInt err( KErrNotFound ); |
|
1708 if ( iSessionInfo ) |
|
1709 { |
|
1710 TRACE( T_LIT( "CBSSession::ProcessId SessionInfo exists") ); |
|
1711 aProcessId = iSessionInfo->ProcessId(); |
|
1712 err = KErrNone; |
|
1713 } |
|
1714 return err; |
|
1715 } |
|
1716 |
|
1717 |
|
1718 // --------------------------------------------------------------------------- |
|
1719 // CBSSession::InfoAvailable |
|
1720 // --------------------------------------------------------------------------- |
|
1721 // |
|
1722 TBool CBSSession::InfoAvailable() |
|
1723 { |
|
1724 return iSessionInfo ? ETrue : EFalse; |
|
1725 } |
|
1726 |
|
1727 // END OF FILE |
|
1728 |
|
1729 |