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