brandingserver/bsclient/cbsclient.cpp
changeset 0 e6b17d312c8b
child 21 cfd5c2994f10
equal deleted inserted replaced
-1:000000000000 0:e6b17d312c8b
       
     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 "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: CBSClient.cpp
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INCLUDE FILES
       
    20 #include "cbsclient.h"
       
    21 #include "bsclientdefs.h"
       
    22 #include "bsprocessstarter.h"
       
    23 #include "bsserverdefs.h"
       
    24 #include "mbselement.h"
       
    25 #include "bselementfactory.h"
       
    26 #include "cbsbitmap.h"
       
    27 #include "cbsbrandobserver.h"
       
    28 #include <e32base.h>
       
    29 #include <s32mem.h>
       
    30 #include "debugtrace.h"
       
    31 
       
    32 // ==============================================================
       
    33 // ======================== CLIENT ==============================
       
    34 // ==============================================================
       
    35 
       
    36 // Destructor
       
    37 RBSClient::~RBSClient()
       
    38     {
       
    39 #if _BullseyeCoverage
       
    40     cov_write();
       
    41 #endif
       
    42     }
       
    43 
       
    44 // C++ default constructor can NOT contain any code, that
       
    45 // might leave.
       
    46 //
       
    47 RBSClient::RBSClient()
       
    48     {
       
    49     }
       
    50 
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // RBSClient::Connect()
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 TInt RBSClient::Connect()
       
    57     {
       
    58     TRACE( T_LIT("RBSClient::Connect() begin") );
       
    59     TFileName fullExePath;
       
    60     BSProcessStarter::FullExePathForClienLocation( KBSServerExe,
       
    61                                                  fullExePath );
       
    62 
       
    63     return BSProcessStarter::ConnectToServer( fullExePath,
       
    64                                             KNullDesC,
       
    65                                             NULL,
       
    66                                             *this,
       
    67                                             KBSServerName,
       
    68                                             TVersion( KBSVersionMajor,
       
    69                                                       KBSVersionMinor,
       
    70                                                       KBSVersionBuild ),
       
    71                                             KBSMsgSlotCount );
       
    72     }
       
    73 
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // RBSClient::Close()
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void RBSClient::Close()
       
    80     {
       
    81     TRACE( T_LIT("RBSClient::Close() begin") );
       
    82     RSessionBase::Close();
       
    83     }
       
    84 
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // RBSClient::Close()
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void RBSClient::StartTransactionL(  const TDesC8& aApplicationId,
       
    91         				  const TDesC8& aBrandId,
       
    92         				  const TDesC8& aDefaultBrandId,
       
    93         				  TLanguage aLanguage,
       
    94         				  TTransactionType aType,
       
    95         				  TInt aReserved )
       
    96 	{
       
    97 	TRACE( T_LIT("RBSClient::StartTransactionL() begin") );
       
    98 	InitClientL( aApplicationId, aBrandId, aDefaultBrandId, 
       
    99 				 aLanguage, aType, aReserved );
       
   100 	}
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // RBSClient::Close()
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 TInt RBSClient::StopTransactionL( const TDesC8& /*aApplicationId*/,
       
   107         				  const TDesC8& /*aBrandId*/,
       
   108         				  TLanguage /*aLanguage*/,
       
   109         				  TInt /*aReserved*/ )
       
   110 	{
       
   111 	TRACE( T_LIT("RBSClient::StopTransactionL() begin") );
       
   112 	TInt returnValue = 0;
       
   113     TPckg<TInt> pack( returnValue );
       
   114     TIpcArgs args( &pack );
       
   115     TInt err = SendReceive( EBSStopTransaction, args );
       
   116     User::LeaveIfError( err );
       
   117 	return returnValue;
       
   118 	}
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // RBSClient::Close()
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void RBSClient::CancelTransactionL( const TDesC8& aApplicationId,
       
   125         				  const TDesC8& aBrandId,
       
   126         				  TLanguage aLanguage,
       
   127         				  TInt aReserved )
       
   128 	{
       
   129 	TIpcArgs args = CreateArgumentsL( aApplicationId, aBrandId,
       
   130 					  				  aLanguage, aReserved );
       
   131 					  				  
       
   132 	TInt err = SendReceive( EBSCancelTransaction, args );
       
   133 	User::LeaveIfError( err );
       
   134 	}
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // RBSClient::InitClientL()
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 void RBSClient::InitClientL( const TDesC8& aApplicationId,
       
   141         				  const TDesC8& aBrandId,
       
   142         				  const TDesC8& aDefaultBrandId,
       
   143         				  TLanguage aLanguage,
       
   144         				  TTransactionType aType,
       
   145         				  TInt aReserved )
       
   146 	{
       
   147 	TRACE( T_LIT("RBSClient::InitClientL() begin aAppId[%S],aBrandId[%S],TAType[%d]"),&aApplicationId,&aBrandId,aType );
       
   148 	CBufFlat* flatBuf = CBufFlat::NewL( aDefaultBrandId.Length() + aBrandId.Length() + 2 );
       
   149 	CleanupStack::PushL( flatBuf );
       
   150 
       
   151  	RBufWriteStream stream;
       
   152 	CleanupClosePushL( stream );
       
   153 	stream.Open( *flatBuf );
       
   154 	stream.WriteInt16L( aBrandId.Length() );
       
   155 	stream.WriteL( aBrandId );
       
   156 	stream.WriteInt16L( aDefaultBrandId.Length() );
       
   157 	stream.WriteL( aDefaultBrandId );
       
   158 
       
   159     TPtr8 ptrElement( flatBuf->Ptr(0) );
       
   160 
       
   161 	// set the arguments for the message
       
   162 	TIpcArgs args(  &aApplicationId );
       
   163     args.Set( 1,  &ptrElement );
       
   164     args.Set( 2, aLanguage );
       
   165     args.Set( 3, aReserved );
       
   166     
       
   167 	TInt operation = 0;
       
   168 	switch( aType )
       
   169 		{
       
   170 		case EBSTxInstall:
       
   171 			{
       
   172 			operation = EBSInitInstall;
       
   173 			break;
       
   174 			}
       
   175 		case EBSTxUninstall:
       
   176 			{
       
   177 			operation = EBSInitUninstall;
       
   178 			break;
       
   179 			}
       
   180 		case EBSTxAppend:
       
   181 			{
       
   182 			operation = EBSInitAppend;
       
   183 			break;
       
   184 			}
       
   185 		case EBSTxReplace:
       
   186 			{
       
   187 			operation = EBSInitReplace;
       
   188 			break;
       
   189 			}
       
   190 		case EBSTxAccess:
       
   191 			{
       
   192 			operation = EBSInitAccess;
       
   193 			break;
       
   194 			}
       
   195 		default:
       
   196 			{
       
   197 			User::Leave( KErrArgument );
       
   198 			break;
       
   199 			}
       
   200 		}		
       
   201 	TInt err = SendReceive( operation, args );
       
   202 	TRACE( T_LIT("RBSClient::InitClientL() 1st SendReceive err=%d"),err );
       
   203 	CleanupStack::PopAndDestroy( 2, flatBuf ); // stream, flatBuf
       
   204 	
       
   205 	User::LeaveIfError( err );
       
   206 
       
   207 	User::LeaveIfError( SendReceive( EBSStartTransaction ) );
       
   208 	TRACE( T_LIT("RBSClient::InitClientL() end") );
       
   209 	}
       
   210    
       
   211 // -----------------------------------------------------------------------------
       
   212 // RBSClient::CreateArgumentsL()
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 TIpcArgs RBSClient::CreateArgumentsL( const TDesC8& aApplicationId,
       
   216         				  const TDesC8& aBrandId,
       
   217         				  TLanguage aLanguage,
       
   218         				  TInt aReserved )
       
   219 	{
       
   220 	// set the arguments for the message
       
   221 	TIpcArgs args(  &aApplicationId );
       
   222     args.Set( 1,  &aBrandId );
       
   223     args.Set( 2, aLanguage );
       
   224     args.Set( 3, aReserved );
       
   225     
       
   226     return args;
       
   227 	}
       
   228 
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // RBSClient::InsertL()
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 void RBSClient::InsertL( MBSElement* aElement )
       
   235 	{
       
   236 	SendUpdateL( aElement, EBSInstall );
       
   237 	}
       
   238 
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // RBSClient::ReplaceL()
       
   242 // -----------------------------------------------------------------------------
       
   243 //
       
   244 void RBSClient::ReplaceL( MBSElement* aElement )
       
   245 	{
       
   246 	SendUpdateL( aElement, EBSReplace );
       
   247 	}
       
   248 	
       
   249 // -----------------------------------------------------------------------------
       
   250 // RBSClient::AppendL()
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 void RBSClient::AppendL( MBSElement* aElement )
       
   254 	{
       
   255 	SendUpdateL( aElement, EBSAppend );
       
   256 	}
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // RBSClient::SendUpdateL()
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void RBSClient::SendUpdateL( MBSElement* aElement, TBSMessages aMessage )
       
   263 	{
       
   264 	// FIXME magic number
       
   265 	CBufFlat* flatBuf = CBufFlat::NewL( 128 );
       
   266 	CleanupStack::PushL( flatBuf );
       
   267 
       
   268  	RBufWriteStream elementStream;
       
   269 	CleanupClosePushL( elementStream );
       
   270 	elementStream.Open( *flatBuf );
       
   271 
       
   272 	aElement->ExternalizeL( elementStream );
       
   273 
       
   274     TPtr8 ptrElement( flatBuf->Ptr(0) );
       
   275 	TIpcArgs args( &ptrElement );
       
   276 	
       
   277 	TInt err = SendReceive( aMessage, args );
       
   278 
       
   279 	CleanupStack::PopAndDestroy(); // elementStream
       
   280 	CleanupStack::PopAndDestroy( flatBuf );
       
   281 	User::LeaveIfError( err );
       
   282 	}
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // RBSClient::GetTextL()
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 void RBSClient::GetTextL( const TDesC8& aId, HBufC*& aValue )
       
   289     {
       
   290 	TInt size = 0;
       
   291     TPckg<TInt> pack( size );
       
   292     
       
   293 	TIpcArgs args( &aId );
       
   294 	args.Set( 1, &pack );
       
   295     TInt err = SendReceive( EBSPrepareText, args );
       
   296     User::LeaveIfError( err );
       
   297     
       
   298 	aValue = HBufC::NewL( size );
       
   299 	TPtr ptrBuf( aValue->Des() );
       
   300 
       
   301     args.Set( 2, &ptrBuf );    
       
   302     err = SendReceive( EBSGetText, args );
       
   303     
       
   304     if( err )
       
   305     	{
       
   306     	delete aValue;
       
   307     	aValue = NULL;
       
   308     	User::Leave( err );
       
   309     	}
       
   310     }
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // RBSClient::GetIntL()
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 void RBSClient::GetIntL( const TDesC8& aId, TInt& aValue )
       
   317     {
       
   318     TPckg<TInt> pack( aValue );
       
   319     TIpcArgs args( &aId);
       
   320     args.Set( 1, &pack );
       
   321     TInt err = SendReceive( EBSGetInt, args );
       
   322     User::LeaveIfError( err );
       
   323     }
       
   324 
       
   325 void RBSClient :: isBrandUpdateRequiredL (TInt & aUpdateRequired)
       
   326 {
       
   327 	//TIpcArgs args;
       
   328 
       
   329     TPckg<TInt> pack (aUpdateRequired);
       
   330 	//args.Set (0, &pack);
       
   331 	TInt err = SendReceive (EBSIsBrandUpdateRequired, TIpcArgs (&pack));
       
   332 
       
   333 	User :: LeaveIfError (err);
       
   334 }
       
   335 // -----------------------------------------------------------------------------
       
   336 // RBSClient::GetTextL()
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 void RBSClient::GetBufferL( const TDesC8& aId, HBufC8*& aValue )
       
   340     {
       
   341 	TInt size = 0;
       
   342     TPckg<TInt> pack( size );
       
   343     
       
   344 	TIpcArgs args( &aId );
       
   345 	args.Set( 1, &pack );
       
   346     TInt err = SendReceive( EBSPrepareBuffer, args );
       
   347     User::LeaveIfError( err );
       
   348     
       
   349 	aValue = HBufC8::NewL( size );
       
   350 	TPtr8 ptrBuf( aValue->Des() );
       
   351 
       
   352     args.Set( 2, &ptrBuf );    
       
   353     err = SendReceive( EBSGetBuffer, args );
       
   354     
       
   355     if( err )
       
   356     	{
       
   357     	delete aValue;
       
   358     	aValue = NULL;
       
   359     	User::Leave( err );
       
   360     	}
       
   361     }
       
   362 
       
   363 // -----------------------------------------------------------------------------
       
   364 // RBSClient::GetSeveralL()
       
   365 // -----------------------------------------------------------------------------
       
   366 //
       
   367 MBSElement* RBSClient::GetSeveralL( MDesC8Array& aIds )
       
   368 	{
       
   369 	TInt size = 0;
       
   370 
       
   371     TPckg<TInt> pack( size );
       
   372     TIpcArgs args;
       
   373     args.Set( 0, &pack );
       
   374 
       
   375 
       
   376 	// FIXME magic number
       
   377 	CBufFlat* flatBuf = CBufFlat::NewL( 128 );
       
   378 	CleanupStack::PushL( flatBuf );
       
   379 
       
   380  	RBufWriteStream idStream;
       
   381 	CleanupClosePushL( idStream );
       
   382 	idStream.Open( *flatBuf );
       
   383 
       
   384 	ExternalizeIdArrayL( idStream, aIds );
       
   385 	
       
   386 	TPtr8 flatPtr = flatBuf->Ptr(0);
       
   387 	args.Set( 1, &flatPtr );
       
   388 	// get the size of the data
       
   389 	TInt err = SendReceive( EBSPrepareSeveral, args );
       
   390 
       
   391 	CleanupStack::PopAndDestroy(); // idStream
       
   392 	CleanupStack::PopAndDestroy( flatBuf );
       
   393 	User::LeaveIfError( err );
       
   394 
       
   395     HBufC8* buf = HBufC8::NewLC( size );
       
   396     TPtr8 ptrBuf( buf->Des() );
       
   397 
       
   398     TIpcArgs msgArgs;
       
   399     msgArgs.Set( 0, &ptrBuf );
       
   400 
       
   401 	err = SendReceive( EBSGetSeveral, msgArgs );
       
   402 
       
   403 	TInt length = buf->Size();
       
   404 
       
   405 	RDesReadStream readStream;
       
   406 	CleanupClosePushL( readStream );
       
   407 	readStream.Open( *buf );
       
   408 
       
   409 	MBSElement* returnValue = InternalizeElementL( readStream );
       
   410 	
       
   411 	CleanupStack::PopAndDestroy(); // readStream
       
   412 	CleanupStack::PopAndDestroy( buf ); // buf
       
   413 
       
   414 	User::LeaveIfError( err );
       
   415 	return returnValue;
       
   416 	}
       
   417 
       
   418 
       
   419 // -----------------------------------------------------------------------------
       
   420 // RBSClient::GetFileL()
       
   421 // -----------------------------------------------------------------------------
       
   422 //
       
   423 void RBSClient::GetFileL( const TDesC8& aId, RFile& aFile )
       
   424 	{
       
   425 	TInt fsh;
       
   426 
       
   427 	TPckgBuf<TInt> fh;
       
   428 
       
   429 	TIpcArgs args( &fh );
       
   430 	args.Set( 2, &aId );
       
   431 
       
   432 	fsh = SendReceive( EBSGetFile, args );
       
   433 	TInt err = aFile.AdoptFromServer( fsh, fh() );
       
   434 
       
   435 	User::LeaveIfError( err );
       
   436 	}
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // RBSClient::GetStructureL()
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 MBSElement* RBSClient::GetStructureL( const TDesC8& aId )
       
   443 	{
       
   444 	TInt size = 0;
       
   445 
       
   446     TPckg<TInt> pack( size );
       
   447     TIpcArgs args;
       
   448     args.Set( 0, &pack );
       
   449 
       
   450 	args.Set( 1, &aId );
       
   451 	// get the size of the data
       
   452 	TInt err = SendReceive( EBSPrepareStructure, args );
       
   453 
       
   454 	User::LeaveIfError( err );
       
   455 
       
   456 
       
   457     HBufC8* buf = HBufC8::NewLC( size );
       
   458     TPtr8 ptrBuf( buf->Des() );
       
   459 
       
   460     TIpcArgs msgArgs;
       
   461     msgArgs.Set( 0, &ptrBuf );
       
   462 
       
   463 	err = SendReceive( EBSGetStructure, msgArgs );
       
   464 
       
   465 	TInt length = buf->Size();
       
   466 
       
   467 	RDesReadStream readStream;
       
   468 	CleanupClosePushL( readStream );
       
   469 	readStream.Open( *buf );
       
   470 
       
   471 	MBSElement* returnValue = InternalizeElementL( readStream );
       
   472 	CleanupStack::PopAndDestroy(); // readStream
       
   473 	CleanupStack::PopAndDestroy( buf ); // buf
       
   474 
       
   475 	User::LeaveIfError( err );
       
   476 
       
   477 	return returnValue;
       
   478 	}
       
   479 
       
   480 // -----------------------------------------------------------------------------
       
   481 // RBSClient::InternalizeElementL()
       
   482 // -----------------------------------------------------------------------------
       
   483 //
       
   484 MBSElement* RBSClient::InternalizeElementL( RReadStream& aStream )
       
   485     {
       
   486     MBSElement* returnValue= NULL;
       
   487     // Write common header for all elements
       
   488     TBSElementType type = (TBSElementType)aStream.ReadInt16L();
       
   489     
       
   490     TInt idSize = aStream.ReadInt16L();
       
   491 
       
   492 	HBufC8* elementId = HBufC8::NewLC( idSize );
       
   493 	TPtr8 elementIdPtr = elementId->Des();
       
   494 
       
   495     if( idSize > 0 )
       
   496         {
       
   497         // read ID only if it's defined
       
   498         aStream.ReadL( elementIdPtr, idSize );
       
   499         elementIdPtr.SetLength( idSize );// Set length
       
   500         }
       
   501         
       
   502 // Ptr() returns a pointer to the start address of decriptor data,
       
   503 // TPtrC constructor then parses the data until null terminator met.
       
   504 // This results in wrong descriptor length & bad data!
       
   505 // Solution is either 
       
   506 // 1) to use PtrZ() which appends a zero terminator,
       
   507 // or 2) pass to constructor an object that has length data.
       
   508 // Option 2) is less prone to errors, so use it.
       
   509 // In general, assignment operator with descriptors should be avoided!
       
   510 // So use TPtrC16(const TDesC16 &aDes) instead 
       
   511 // of TPtrC16(const TUint16 *aString)!
       
   512     TPtrC8 idPtrC( *elementId );//idPtrC creation moved here so it will be updated correctly.
       
   513 
       
   514 	if( elementId->Length() == 0 )
       
   515 		{
       
   516 		CleanupStack::PopAndDestroy( elementId );
       
   517 		elementId = NULL;
       
   518 		idPtrC.Set( KNullDesC8 );
       
   519 		}
       
   520 		
       
   521     // Write element type specific data
       
   522     switch( type )
       
   523         {
       
   524         case EBSInt:
       
   525             {
       
   526             TInt intData = aStream.ReadInt16L();
       
   527 			returnValue = BSElementFactory::CreateBSElementL( idPtrC,
       
   528 															  EBSInt,
       
   529 															  intData );					
       
   530 
       
   531             break;
       
   532             }
       
   533         case EBSText:     // flowthrough
       
   534         case EBSFile:
       
   535             {
       
   536 			TInt textSize = aStream.ReadInt16L();
       
   537 			HBufC* textData = HBufC::NewLC( textSize );
       
   538 
       
   539 			TPtr textPtr = textData->Des();
       
   540 			aStream.ReadL( textPtr, textSize );
       
   541 			
       
   542 			returnValue = BSElementFactory::CreateBSElementL( idPtrC, 
       
   543 															  type,
       
   544 															  *textData );
       
   545 			CleanupStack::PopAndDestroy( textData );
       
   546             break;
       
   547             }
       
   548         case EBSList:
       
   549             {
       
   550 			RBSObjOwningPtrArray<MBSElement> listData;
       
   551 			CleanupClosePushL( listData );
       
   552 			TInt count = aStream.ReadInt16L();
       
   553 			
       
   554 			for( TInt i = 0; i < count; i++ )
       
   555 				{
       
   556 				MBSElement* subElement = InternalizeElementL( aStream );
       
   557 				CleanupClosePushL( *subElement );
       
   558 				listData.AppendL( subElement );
       
   559 				CleanupStack::Pop(); // subElement
       
   560 				}
       
   561 
       
   562 			returnValue = BSElementFactory::CreateBSElementL( idPtrC, 
       
   563 															  EBSList,
       
   564 															  listData );
       
   565 
       
   566 			CleanupStack::Pop(); // listData
       
   567 
       
   568             break;
       
   569             }
       
   570 
       
   571         case EBSBuffer:
       
   572         	{
       
   573 			TInt bufferSize = aStream.ReadInt16L();
       
   574 			HBufC8* buffeData = HBufC8::NewLC( bufferSize );
       
   575 
       
   576 			TPtr8 bufferPtr = buffeData->Des();
       
   577 			aStream.ReadL( bufferPtr, bufferSize );
       
   578 
       
   579 			returnValue = BSElementFactory::CreateBSElementL( idPtrC, 
       
   580 															  EBSBuffer,
       
   581 															  *buffeData );
       
   582 
       
   583 			CleanupStack::PopAndDestroy( buffeData );
       
   584         	break;
       
   585         	}
       
   586 
       
   587         case EBSBitmap:
       
   588             {
       
   589 			TInt length = aStream.ReadInt16L();
       
   590 			HBufC8* fileId = HBufC8::NewLC( length );
       
   591 			
       
   592 			TPtr8 fileIdPtr = fileId->Des();
       
   593 			aStream.ReadL( fileIdPtr, length );
       
   594 			
       
   595 			TInt bitmapId = aStream.ReadInt16L();
       
   596 			TInt maskId = aStream.ReadInt16L();
       
   597 			TInt skinId = aStream.ReadInt16L();
       
   598 			TInt skinMaskId = aStream.ReadInt16L();
       
   599 
       
   600 			CBSBitmap* bitmap = CBSBitmap::NewLC( bitmapId,
       
   601 												  maskId,
       
   602 												  skinId,
       
   603 												  skinMaskId,
       
   604 												  fileIdPtr );
       
   605 												  
       
   606 			returnValue = BSElementFactory::CreateBSElementL( idPtrC, 
       
   607 															  EBSBitmap,
       
   608 															  bitmap );
       
   609 			CleanupStack::Pop( bitmap ); // bitmap
       
   610 			CleanupStack::PopAndDestroy( fileId ); // bitmap
       
   611 			
       
   612             break;
       
   613             }
       
   614 
       
   615         default:
       
   616             {
       
   617             // unknown type!
       
   618             User::Leave( KErrCorrupt );
       
   619             break;
       
   620             }
       
   621         }
       
   622         
       
   623 	if( elementId )
       
   624 		{
       
   625 		CleanupStack::PopAndDestroy( elementId );
       
   626 		}
       
   627         
       
   628 	return returnValue;
       
   629     }
       
   630     
       
   631     
       
   632 // -----------------------------------------------------------------------------
       
   633 // RBSClient::InternalizeElementL()
       
   634 // -----------------------------------------------------------------------------
       
   635 //
       
   636 void RBSClient::ExternalizeIdArrayL( RWriteStream& aStream, MDesC8Array& aArray )
       
   637 	{
       
   638 	TInt count = aArray.MdcaCount();
       
   639 	aStream.WriteInt16L( count );
       
   640 	
       
   641 	for( TInt i = 0; i < count; i++ )
       
   642 		{
       
   643 		TPtrC8 ptr = aArray.MdcaPoint(i);
       
   644 		aStream.WriteInt16L( aArray.MdcaPoint( i ).Length() );
       
   645 		aStream.WriteL( aArray.MdcaPoint( i ) );
       
   646 		}
       
   647 	
       
   648 	}
       
   649 
       
   650 // -----------------------------------------------------------------------------
       
   651 // RBSClient::RemoveBrandL()
       
   652 // -----------------------------------------------------------------------------
       
   653 //
       
   654 void RBSClient::RemoveBrandL( const TDesC8& aApplicationId,
       
   655 								   const TDesC8& aBrandId )
       
   656 	{
       
   657 	// set the arguments for the message
       
   658 	TIpcArgs args(  &aApplicationId );
       
   659 	args.Set( 1, &aBrandId );
       
   660 	TInt err = SendReceive( EBSRemoveBrand, args );
       
   661 	User::LeaveIfError( err );
       
   662 	}
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // RBSClient::RemoveBrandsL()
       
   666 // -----------------------------------------------------------------------------
       
   667 //
       
   668 void RBSClient::RemoveBrandsL( const TDesC8& aApplicationId )
       
   669 	{
       
   670 	// set the arguments for the message
       
   671 	TIpcArgs args(  &aApplicationId );
       
   672 		
       
   673 	TInt err = SendReceive( EBSRemoveApplication, args );
       
   674 	User::LeaveIfError( err );
       
   675 	}
       
   676 
       
   677 // -----------------------------------------------------------------------------
       
   678 // RBSClient::RegisterObserverL()
       
   679 // -----------------------------------------------------------------------------
       
   680 //
       
   681 void RBSClient::RegisterObserverL( MBSBrandChangeObserver* aObserver, MBSBackupRestoreStateObserver* aBackupStateObserver )
       
   682 	{
       
   683 	CBSBrandObserver* tempObserver = CBSBrandObserver::NewL( aObserver, aBackupStateObserver, this );
       
   684 	if( iObserver )
       
   685 		{
       
   686 		delete iObserver;
       
   687 		}
       
   688 	iObserver = tempObserver;
       
   689 	}
       
   690 
       
   691 // -----------------------------------------------------------------------------
       
   692 // RBSClient::UnRegisterObserverL()
       
   693 // -----------------------------------------------------------------------------
       
   694 //
       
   695 void RBSClient::UnRegisterObserverL( MBSBrandChangeObserver* /*aObserver*/, MBSBackupRestoreStateObserver* /*aBackupStateObserver*/ )
       
   696 	{
       
   697 	delete iObserver;
       
   698 	iObserver = NULL;
       
   699 	}
       
   700 
       
   701 // -----------------------------------------------------------------------------
       
   702 // RBSClient::UnRegisterObserverL()
       
   703 // -----------------------------------------------------------------------------
       
   704 //
       
   705 void RBSClient::RegisterObserverToServerL( TRequestStatus& aStatus )
       
   706 	{
       
   707 	TIpcArgs args;
       
   708 	SendReceive( EBSObserveBrand, args, aStatus );
       
   709 	}
       
   710 
       
   711 // -----------------------------------------------------------------------------
       
   712 // RBSClient::GetNewVersionL()
       
   713 // -----------------------------------------------------------------------------
       
   714 //
       
   715 TInt RBSClient::GetNewVersionL()
       
   716 	{
       
   717     return GetValueL( EBSObserveGetNewVersion);
       
   718 	}
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // RBSClient::GetValueL()
       
   722 // -----------------------------------------------------------------------------
       
   723 //
       
   724 TInt RBSClient::GetValueL(TInt msg)
       
   725 	{
       
   726 	TInt returnValue = 0;
       
   727     TPckg<TInt> pack( returnValue );
       
   728     TIpcArgs args( &pack );
       
   729     TInt err = SendReceive( msg, args );
       
   730     User::LeaveIfError( err );	
       
   731     return returnValue;
       
   732 	}
       
   733 
       
   734 // -----------------------------------------------------------------------------
       
   735 // RBSClient::GetBackupStateL()
       
   736 // -----------------------------------------------------------------------------
       
   737 //
       
   738 TInt RBSClient::GetBackupStateL()	
       
   739 	{
       
   740     return GetValueL( EBSObserveGetBackupState);
       
   741 	}
       
   742 
       
   743 // -----------------------------------------------------------------------------
       
   744 // RBSClient::GetBackupRestoreL()
       
   745 // -----------------------------------------------------------------------------
       
   746 //
       
   747 TInt RBSClient::GetBackupRestoreL()	
       
   748 	{
       
   749     return GetValueL( EBSObserveGetChange);
       
   750 	}
       
   751 
       
   752 //  END OF FILE
       
   753