ncdengine/provider/client/src/ncdinstalloperationproxy.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006-2008 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:   Implements CNcdInstallOperationProxy
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <s32strm.h>
       
    20 #include "ncdinstalloperationproxy.h"
       
    21 #include "ncdinstalloperationobserver.h"
       
    22 #include "catalogsdebug.h"
       
    23 #include "catalogsclientserver.h"
       
    24 #include "ncdnodeproxy.h"
       
    25 #include "ncdnodemanagerproxy.h"
       
    26 #include "ncdinstallationservice.h"
       
    27 #include "ncddeviceinteractionfactory.h"
       
    28 #include "catalogsutils.h"
       
    29 #include "catalogsconstants.h"
       
    30 #include "ncdfileinfo.h"
       
    31 #include "ncdinstallinfo.h"
       
    32 #include "ncdpanics.h"
       
    33 #include "ncdoperationproxyremovehandler.h"
       
    34 #include "ncderrors.h"
       
    35 
       
    36 
       
    37 // ======== MEMBER FUNCTIONS ========
       
    38 
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // NewLC
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 CNcdInstallOperationProxy* CNcdInstallOperationProxy::NewLC( 
       
    45     MCatalogsClientServer& aSession,
       
    46     TInt aHandle,
       
    47     MNcdOperationProxyRemoveHandler* aRemoveHandler,
       
    48     CNcdNodeProxy* aNode,
       
    49     CNcdNodeManagerProxy* aNodeManager,
       
    50     MNcdInstallOperationObserver* aObserver,
       
    51     MNcdInstallationService& aInstallationService )
       
    52     {
       
    53     CNcdInstallOperationProxy* self =
       
    54         new( ELeave ) CNcdInstallOperationProxy( aInstallationService );
       
    55     
       
    56     self->AddRef();
       
    57     CleanupReleasePushL( *self );    
       
    58     self->ConstructL( aSession, aHandle, aRemoveHandler, aNode, aNodeManager,
       
    59         aObserver );
       
    60     return self;
       
    61     }
       
    62 
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // From MNcdInstallOperation
       
    66 // 
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 TInt CNcdInstallOperationProxy::FileCount()
       
    70     {
       
    71     return iFileCount;
       
    72     }
       
    73 
       
    74 
       
    75 // ---------------------------------------------------------------------------
       
    76 // From MNcdInstallOperation
       
    77 // 
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 TInt CNcdInstallOperationProxy::CurrentFile()
       
    81     {
       
    82     return iCurrentFile;
       
    83     }
       
    84 
       
    85 
       
    86 // ---------------------------------------------------------------------------
       
    87 // From MNcdOperation
       
    88 // Starts the operation
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CNcdInstallOperationProxy::StartOperationL()
       
    92     {
       
    93     DLTRACEIN((""));
       
    94     if ( OperationStateL() != MNcdOperation::EStateStopped )
       
    95         {
       
    96         DLINFO(("Already running"));
       
    97         return;
       
    98         }
       
    99     else if ( !iFileCount ) 
       
   100         {
       
   101         DLERROR(( "No files to install"));
       
   102         User::Leave( KErrNotFound );
       
   103         }
       
   104     
       
   105     // Inform the install report that the install operation has
       
   106     // been started.
       
   107     StartInstallReportL();
       
   108 
       
   109     SetInstallationErrorCode( KErrNone );
       
   110 
       
   111     SetState( MNcdOperation::EStateRunning );        
       
   112     iStatus = KRequestPending;
       
   113     SetActive();
       
   114     TRequestStatus* ptr = &iStatus;
       
   115     User::RequestComplete( ptr, KErrNone );
       
   116     DLTRACEOUT((""));
       
   117     }
       
   118 
       
   119 
       
   120 
       
   121 // ---------------------------------------------------------------------------
       
   122 // From MNcdOperation
       
   123 // Cancels the operation
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 void CNcdInstallOperationProxy::CancelOperation()
       
   127         {
       
   128         DLTRACEIN((""));
       
   129 
       
   130         // Set the installation error value as KErrCancel here. The child
       
   131         // classes may change this in their DoCancel function. So, the correct
       
   132         // value is available after Cancel is called below.
       
   133         SetInstallationErrorCode( KErrCancel );
       
   134         
       
   135         Cancel();
       
   136         iInstaller = NULL;
       
   137 
       
   138         // Use the installation error code here. It may be set by the child class
       
   139         // if installation result is checked. In some cases, the installation may 
       
   140         // have been completed even if the cancel was called.
       
   141         TRAP_IGNORE( CompleteInstallReportL( InstallationErrorCode() ) );
       
   142         
       
   143         if ( iObserver != NULL )
       
   144             {
       
   145             // According to the MNcdOperation interface
       
   146             // OperationComplete() will be called for each observer with KErrCancel
       
   147             // as the error parameter when CancelOperation is called. So, inform observer.
       
   148             iObserver->OperationComplete( *this, KErrCancel );            
       
   149             }
       
   150 
       
   151         DLTRACEOUT((""));        
       
   152         }
       
   153 
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // From MNcdOperation
       
   157 // Operation type getter
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 TNcdInterfaceId CNcdInstallOperationProxy::OperationType() const
       
   161     {
       
   162     return static_cast<TNcdInterfaceId>(MNcdInstallOperation::KInterfaceUid);
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // Constructor
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 CNcdInstallOperationProxy::CNcdInstallOperationProxy( 
       
   171     MNcdInstallationService& aInstallationService )
       
   172     : CNcdOperation< MNcdInstallOperation >( NULL ),
       
   173       iInstaller( &aInstallationService ), iFileCount( 1 ), iCurrentFile( 0 )
       
   174     {
       
   175     }
       
   176 
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // Destructor
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 CNcdInstallOperationProxy::~CNcdInstallOperationProxy()
       
   183     {
       
   184     DLTRACEIN(( "" ));
       
   185     Cancel();     
       
   186     iInstaller = NULL;    
       
   187     iMimeTypes.ResetAndDestroy();
       
   188     iPurposes.Reset();
       
   189     
       
   190     delete iCurrentInfo;
       
   191     
       
   192     iFileHandle.Close();
       
   193     if ( iRemoveHandler )
       
   194         iRemoveHandler->RemoveOperationProxy( *this );
       
   195     DLTRACEOUT(( "" ));    
       
   196     }
       
   197 
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // ConstructL
       
   201 // ---------------------------------------------------------------------------
       
   202 //
       
   203 void CNcdInstallOperationProxy::ConstructL( MCatalogsClientServer& aSession,
       
   204     TInt aHandle,
       
   205     MNcdOperationProxyRemoveHandler* aRemoveHandler,
       
   206     CNcdNodeProxy* aNode,
       
   207     CNcdNodeManagerProxy* aNodeManager,
       
   208     MNcdInstallOperationObserver* aObserver )
       
   209     {
       
   210     DLTRACEIN(( "" ));
       
   211     CNcdBaseOperationProxy::ConstructL( aSession, aHandle, aRemoveHandler,
       
   212         aNode, aNodeManager );
       
   213     
       
   214     // Copy data id
       
   215     iObserver = aObserver;
       
   216             
       
   217     // Initialize the operation
       
   218     // Notice, that this will create also the install report in the server side.
       
   219     InitializeOperationL();
       
   220     DLTRACEOUT(( "" ));    
       
   221     }
       
   222     
       
   223 
       
   224     
       
   225 // ---------------------------------------------------------------------------
       
   226 // Handle progress callback
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CNcdInstallOperationProxy::ProgressCallback()
       
   230     {
       
   231     DLTRACEIN( ( "" ) );
       
   232     DASSERT( 0 );
       
   233     }
       
   234     
       
   235     
       
   236 // ---------------------------------------------------------------------------
       
   237 // Handle query received callback
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CNcdInstallOperationProxy::QueryReceivedCallback( CNcdQuery* /* aQuery */ )
       
   241     {
       
   242     DLTRACEIN( ( "" ) );
       
   243     DASSERT( 0 );
       
   244     }
       
   245     
       
   246     
       
   247 // ---------------------------------------------------------------------------
       
   248 // Handle operation complete
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 void CNcdInstallOperationProxy::CompleteCallback( TInt aError )
       
   252     {
       
   253     DLTRACEIN( ( "Error: %d", aError ) );
       
   254     (void) aError; // suppress warning
       
   255         
       
   256     DASSERT( 0 );
       
   257 
       
   258     // NOTICE:
       
   259     // If this function will be called in some future versions, then the
       
   260     // code below may be required.
       
   261     // Because the operation is completed, insert the completion time
       
   262     // and the error code into the purchase history.
       
   263     /*
       
   264     DLINFO(("Update purchase history"));
       
   265     TRAP_IGNORE( UpdateOperationInfoToPurchaseHistoryL( aError ) );
       
   266     TRAP_IGNORE( NodeManager()->InternalizeRelatedNodesL( *NodeProxy() ) );
       
   267     */
       
   268     }
       
   269     
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // Create initialization data sent to the server-side
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 HBufC8* CNcdInstallOperationProxy::CreateInitializationBufferL()
       
   276     {
       
   277     DLTRACEIN((""));
       
   278     // The default implementation: return an empty buffer to be sent
       
   279     // if there's no input value to send in the message
       
   280     return HBufC8::NewL( 0 );
       
   281     }
       
   282 
       
   283 
       
   284 // ---------------------------------------------------------------------------
       
   285 // Handle initialization callback
       
   286 // ---------------------------------------------------------------------------
       
   287 //
       
   288 void CNcdInstallOperationProxy::InitializationCallback( 
       
   289     RReadStream& aReadStream, TInt /* aDataLength */ )
       
   290     {
       
   291     DLTRACEIN( ( "" ) );
       
   292     TRAPD( ignore, 
       
   293         {
       
   294         // Read file count from the stream
       
   295         iFileCount = aReadStream.ReadInt32L();
       
   296         
       
   297         DLTRACE(("done"));
       
   298         });
       
   299     DLTRACEOUT( ( "Ignored error: %d", ignore ) );
       
   300     ignore = ignore; // to suppress compiler warning
       
   301     }
       
   302 
       
   303 
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // Handles callbacks from the installation service
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 void CNcdInstallOperationProxy::InstallationCompleteL( const TDesC& aFileName,
       
   310                                                        const TUid& aAppUid,
       
   311                                                        TInt aError )
       
   312     {
       
   313     DLTRACEIN(( _L("File: %S, uid: %X, error: %d"),
       
   314                 &aFileName, aAppUid.iUid, aError ));
       
   315 
       
   316     // Because the operation is completed. Insert the completion time
       
   317     // and the error code into the purchase history.
       
   318     DLINFO(("Update purchase history"));
       
   319     iFileHandle.Close();
       
   320     
       
   321     // Ignore possible errors here because this just updates the purchase history info
       
   322     // and there is not anything that we can do later if this fails. If this fails,
       
   323     // then some information in the purchase history will not be entirely up to date.
       
   324     TRAP_IGNORE( UpdateOperationInfoToPurchaseHistoryL( aError ) );
       
   325     
       
   326     SetInstallationErrorCode( aError );
       
   327     if ( aError != KErrNone && 
       
   328          aError != KNcdThemeReinstalled &&
       
   329          aError != KNcdThemePossiblyReinstalled ) 
       
   330         {
       
   331         DLERROR(( "Installation failed with: %d", aError ));
       
   332         // Complete the request
       
   333         TRequestStatus* statusPtr = &iStatus;
       
   334         User::RequestComplete( statusPtr, aError );
       
   335         return;        
       
   336         }        
       
   337         
       
   338     // Update file's info to the server.
       
   339     // If something went wrong here, 
       
   340     // then inform the observer with that error code in the end of this function.
       
   341     TRAPD( trapError, UpdateInfoToServerL( aFileName, aAppUid, aError ) );
       
   342     DLINFO(("UpdateInfoToServerL errorCode: %d", trapError));
       
   343     
       
   344     DLINFO(("Internalizing related node"));
       
   345     // Get the possible error from here because the internalization may have gone wrong
       
   346     // for some nodes.
       
   347     TRAPD( trapErrorNodes, NodeManager()->InternalizeRelatedNodesL( *NodeProxy() ) );
       
   348     DLINFO(("Node internalized; %d", trapErrorNodes));
       
   349 
       
   350     // Check what error code should be returned.
       
   351     // If the update info to server failed, then return that error code.
       
   352     // If update info to server was successfull, then use the node internalization
       
   353     // error code.
       
   354     TInt retError( trapError );
       
   355     if ( retError == KErrNone )
       
   356         {
       
   357         retError = trapErrorNodes;
       
   358         }
       
   359     DLINFO(("retError: %d", retError));
       
   360         
       
   361     // Complete the request
       
   362     TRequestStatus* statusPtr = &iStatus;
       
   363     User::RequestComplete( statusPtr, retError );
       
   364 
       
   365     DLTRACEOUT((""));
       
   366     }
       
   367     
       
   368 
       
   369 // ---------------------------------------------------------------------------
       
   370 // From CActive
       
   371 // ?implementation_description
       
   372 // ---------------------------------------------------------------------------
       
   373 //
       
   374 void CNcdInstallOperationProxy::RunL()
       
   375     {
       
   376     DLTRACEIN(("current file: %d, file count: %d", iCurrentFile, iFileCount ));
       
   377     if ( iCurrentFile != iFileCount && iStatus.Int() == KErrNone )
       
   378         {
       
   379         TNcdProgress progress( iCurrentFile, 
       
   380                                iFileCount );
       
   381 
       
   382         DLTRACE(("Calling observer for progress"));            
       
   383         iObserver->InstallProgress( *this, progress );
       
   384         
       
   385         DLINFO(("Still %d more file(s) to install", iFileCount - iCurrentFile ));
       
   386         DASSERT( iInstaller );
       
   387         
       
   388         // Start installing the next file
       
   389         TRAPD( err, InstallNextFileL() );        
       
   390         
       
   391         // Handle case where everything has been installed but some
       
   392         // files were not reinstalled, eg. dependencies that were not
       
   393         // downloaded
       
   394         if ( err == KNcdErrorNothingToInstall ) 
       
   395             {
       
   396             DLTRACE(("Complete operation because everything is installed"));
       
   397             CompleteInstallReportL( KErrNone );
       
   398             iObserver->OperationComplete( *this, KErrNone );
       
   399             }
       
   400         else if ( err != KErrNone )
       
   401             {
       
   402             User::Leave( err );
       
   403             }        
       
   404         }
       
   405     else 
       
   406         {
       
   407         iFileHandle.Close();
       
   408         if ( iStatus.Int() != KErrNone ) 
       
   409             {
       
   410             SetInstallationErrorCode( iStatus.Int() );
       
   411             }
       
   412         DLTRACE(("Call OperationComplete for the observer"));
       
   413         CompleteInstallReportL( InstallationErrorCode() );
       
   414         iObserver->OperationComplete( *this, InstallationErrorCode() );
       
   415         }
       
   416     DLTRACEOUT((""));
       
   417     }
       
   418     
       
   419 // ---------------------------------------------------------------------------
       
   420 // From CActive
       
   421 // ?implementation_description
       
   422 // ---------------------------------------------------------------------------
       
   423 //
       
   424 
       
   425 void CNcdInstallOperationProxy::DoCancel()
       
   426     {
       
   427     DLTRACEIN((""));
       
   428     // Cannot actually cancel anything.
       
   429     // Because the operation is pending now in Cancel function, we have to set
       
   430     // iStatus here to make sure that the Cancel operation may continue and
       
   431     // it does not stuck when waiting for the request complete from the service
       
   432     // provider.
       
   433     if ( iStatus == KRequestPending ) 
       
   434         {
       
   435         TRequestStatus* status = &iStatus;
       
   436         User::RequestComplete( status, KErrCancel );
       
   437         }
       
   438     }
       
   439 
       
   440     
       
   441 // ---------------------------------------------------------------------------
       
   442 // From CActive
       
   443 // ?implementation_description
       
   444 // ---------------------------------------------------------------------------
       
   445 //
       
   446 TInt CNcdInstallOperationProxy::RunError( TInt aError )
       
   447     {
       
   448     DLTRACEIN(("error: %d", aError));
       
   449     
       
   450     // Leave has occurred in RunL.
       
   451     // If active object is set active, then complete request.
       
   452     // And return KErrNone in the end to avoid panic.
       
   453 
       
   454     SetInstallationErrorCode( aError );
       
   455     iObserver->OperationComplete( *this, iInstallationError );    
       
   456     return KErrNone;
       
   457     }
       
   458     
       
   459 
       
   460 // ---------------------------------------------------------------------------
       
   461 // Installs the next file
       
   462 // ---------------------------------------------------------------------------
       
   463 //
       
   464 void CNcdInstallOperationProxy::InstallNextFileL()
       
   465     {
       
   466     DLTRACEIN((""));
       
   467     if ( iCurrentFile >= iFileCount ) 
       
   468         {
       
   469         DLTRACE(("no more files to install"));
       
   470         User::Leave( KNcdErrorNothingToInstall );
       
   471         }
       
   472 
       
   473     // set observer
       
   474     iInstaller->SetObserver( *this );
       
   475         
       
   476     iCurrentInfo = InstallInfoL( iCurrentFile );
       
   477 
       
   478     if ( iCurrentFile >= iFileCount ) 
       
   479         {
       
   480         DLTRACE(("Everything has been installed"));
       
   481         User::Leave( KNcdErrorNothingToInstall );
       
   482         }
       
   483     
       
   484     NCD_ASSERT_ALWAYS( iCurrentInfo->FileInfoCount(), ENcdPanicNoData ); 
       
   485     
       
   486     CNcdFileInfo& file( iCurrentInfo->FileInfo( 0 ) );
       
   487 
       
   488     // Open the source file. Using member variable so that the file can
       
   489     // be closed after installation
       
   490     iFileHandle.Close();
       
   491     iFileHandle = OpenFileL( iCurrentFile );
       
   492     iStatus = KRequestPending;
       
   493     SetActive();
       
   494 
       
   495     UseInstallServiceL( file );
       
   496         
       
   497     DLTRACE(("Setting active"));
       
   498     }
       
   499     
       
   500     
       
   501 // ---------------------------------------------------------------------------
       
   502 // Calls the functions of the installer. Child classes may call different functions.
       
   503 // ---------------------------------------------------------------------------
       
   504 //
       
   505 void CNcdInstallOperationProxy::UseInstallServiceL( 
       
   506     const CNcdFileInfo& aFile )
       
   507     {
       
   508     DLTRACEIN((""));
       
   509     // Choose correct installation type
       
   510     switch( CurrentInfo().InstallType() )
       
   511         {
       
   512         case CNcdInstallInfo::ENcdInstallNormal:
       
   513             {            
       
   514             Installer().InstallL( 
       
   515                 iFileHandle, 
       
   516                 aFile.MimeType(), 
       
   517                 aFile.Purpose() );
       
   518             break;
       
   519             }
       
   520         
       
   521         case CNcdInstallInfo::ENcdInstallJar: // flow through
       
   522         case CNcdInstallInfo::ENcdInstallJad:
       
   523             {
       
   524             Installer().InstallJavaL( 
       
   525                 iFileHandle, 
       
   526                 aFile.MimeType(), 
       
   527                 aFile.Data() );
       
   528              
       
   529             break;
       
   530             }            
       
   531         
       
   532         
       
   533         default:
       
   534             {
       
   535             // All cases should be handled
       
   536             DASSERT( 0 );
       
   537             break;
       
   538             }
       
   539         }
       
   540     DLTRACEOUT((""));   
       
   541     }
       
   542 
       
   543 // ---------------------------------------------------------------------------
       
   544 // Gives the installer that handles the installation.
       
   545 // ---------------------------------------------------------------------------
       
   546 //
       
   547 MNcdInstallationService& CNcdInstallOperationProxy::Installer()
       
   548     {
       
   549     DLTRACEIN((""));
       
   550     DASSERT( iInstaller != NULL );
       
   551     return *iInstaller;
       
   552     }
       
   553 
       
   554 
       
   555 CNcdInstallInfo& CNcdInstallOperationProxy::CurrentInfo()
       
   556     {
       
   557     DLTRACEIN((""));
       
   558     DASSERT( iCurrentInfo != NULL );
       
   559     return *iCurrentInfo;
       
   560     }
       
   561 
       
   562 
       
   563 // ---------------------------------------------------------------------------
       
   564 // Gets info for a file from the server
       
   565 // ---------------------------------------------------------------------------
       
   566 //
       
   567 CNcdInstallInfo* CNcdInstallOperationProxy::InstallInfoL( TInt /*aIndex*/ )
       
   568     {
       
   569     DLTRACEIN((""));
       
   570     InitBuffersL( 0, 0 );
       
   571         
       
   572     CBufBase* buf = CBufFlat::NewL( KBufExpandSize );
       
   573     CleanupStack::PushL( buf );
       
   574 
       
   575     RBufWriteStream stream( *buf );
       
   576     CleanupClosePushL( stream );
       
   577     
       
   578     // write file index
       
   579     stream.WriteInt32L( iCurrentFile );    
       
   580     
       
   581     CleanupStack::PopAndDestroy( &stream );
       
   582     
       
   583     HBufC8* data = NULL;
       
   584 
       
   585     
       
   586     // Get file info for the file
       
   587     User::LeaveIfError( ClientServerSession().SendSyncAlloc( 
       
   588         ENCDOperationFunctionGetData,
       
   589         buf->Ptr( 0 ),        
       
   590         data,
       
   591         Handle(),
       
   592         0 ) );
       
   593     
       
   594     CleanupStack::PopAndDestroy( buf );
       
   595     
       
   596     if ( !data ) 
       
   597         {
       
   598         DLERROR(("No data"));
       
   599         User::Leave( KErrNotFound );
       
   600         }
       
   601     
       
   602     CleanupStack::PushL( data );
       
   603     
       
   604     DLTRACE(("Data length: %d", data->Length() ));
       
   605     
       
   606     // Open a stream to the data
       
   607     RDesReadStream readStream( *data );
       
   608     CleanupClosePushL( readStream );
       
   609     
       
   610     TInt32 completionId = readStream.ReadInt32L();
       
   611     
       
   612     if ( completionId != ENCDOperationMessageCompletionComplete ) 
       
   613         {
       
   614         DLERROR(("Message failed! CompletionId: %d", completionId ));
       
   615         User::Leave( KErrGeneral );
       
   616         }
       
   617     
       
   618     // internalize file info from the stream
       
   619     CNcdInstallInfo* info = CNcdInstallInfo::NewLC( readStream );
       
   620     
       
   621     // update current file index in case some files were skipped on 
       
   622     // server-side
       
   623     iCurrentFile = info->Index();
       
   624         
       
   625     CleanupStack::Pop( info );
       
   626     CleanupStack::PopAndDestroy( 2, data ); // readStream, data
       
   627         
       
   628     DLTRACEOUT((""));
       
   629     return info;
       
   630     }
       
   631 
       
   632 
       
   633 // ---------------------------------------------------------------------------
       
   634 // Sets info for a file in the server
       
   635 // ---------------------------------------------------------------------------
       
   636 //
       
   637 void CNcdInstallOperationProxy::UpdateInfoToServerL( const TDesC& aFileName,
       
   638                                                      const TUid& aAppUid,
       
   639                                                      TInt aError )
       
   640     {
       
   641     DLTRACEIN((""));
       
   642 
       
   643     // Update file's info to the server
       
   644     
       
   645     InitBuffersL( 0, 0 );
       
   646         
       
   647     CBufBase* buf = CBufFlat::NewL( KBufExpandSize );
       
   648     CleanupStack::PushL( buf );
       
   649 
       
   650     RBufWriteStream stream( *buf );
       
   651     CleanupClosePushL( stream );
       
   652 
       
   653     // write file index
       
   654     stream.WriteInt32L( iCurrentFile );    
       
   655     
       
   656     // get the purpose info from the original file    
       
   657     TNcdItemPurpose oldPurpose = iCurrentInfo->FileInfo( 0 ).Purpose();    
       
   658     
       
   659     // delete current info
       
   660     delete iCurrentInfo;
       
   661     iCurrentInfo = NULL;
       
   662 
       
   663     TUid uid( aAppUid );
       
   664     if ( uid.iUid == KNcdThemeSisUid ) 
       
   665         {
       
   666         // ensure that purpose for themes is theme
       
   667         oldPurpose = ENcdItemPurposeTheme;
       
   668         
       
   669         // nullify appuid so it won't be added as an application
       
   670         uid = TUid::Null();
       
   671         }
       
   672     
       
   673     // Update purpose if we didn't get it from ContentInfo
       
   674     if ( oldPurpose == ENcdItemPurposeUnknown && uid != TUid::Null() ) 
       
   675         {
       
   676         oldPurpose = ENcdItemPurposeApplication;
       
   677         }
       
   678         
       
   679     // Write updated file info
       
   680     CNcdFileInfo* info = NULL;
       
   681     
       
   682     if ( aError == KNcdThemeReinstalled || 
       
   683          aError == KNcdThemePossiblyReinstalled ) 
       
   684         {
       
   685         info = 
       
   686             CNcdFileInfo::NewLC( aFileName, 
       
   687                                  KNullDesC,
       
   688                                  ENcdItemPurposeTheme );
       
   689 
       
   690         }
       
   691     else 
       
   692         {
       
   693         info = 
       
   694             CNcdFileInfo::NewLC( aFileName, 
       
   695                                  KNullDesC,
       
   696                                  oldPurpose );
       
   697         }
       
   698     
       
   699     info->ExternalizeL( stream );
       
   700     CleanupStack::PopAndDestroy( info );
       
   701             
       
   702     // write app uid
       
   703     if ( uid != TUid::Null() ) 
       
   704         {
       
   705         DLTRACE(( _L("Writing UID: %S"), &uid.Name() ));
       
   706         stream.WriteInt32L( 1 );
       
   707         stream.WriteInt32L( uid.iUid );
       
   708         }
       
   709     else
       
   710         {        
       
   711         stream.WriteInt32L( 0 ); // 0 uids 
       
   712         }    
       
   713         
       
   714     CleanupStack::PopAndDestroy( &stream );
       
   715     
       
   716     HBufC8* data = NULL;
       
   717 
       
   718     TInt err = ClientServerSession().SendSyncAlloc(
       
   719         ENCDOperationFunctionSetData,
       
   720         buf->Ptr( 0 ),        
       
   721         data, 
       
   722         Handle(),
       
   723         0 );
       
   724     
       
   725     // We could check the completion code but why bother...
       
   726     delete data;
       
   727     data = NULL;
       
   728     
       
   729     DLTRACE(( "err: %d", err));
       
   730     User::LeaveIfError( err );
       
   731 
       
   732     CleanupStack::PopAndDestroy( buf );    
       
   733     
       
   734     // Ensure that file is closed before trying to delete
       
   735     iFileHandle.Close();
       
   736     
       
   737     DLTRACE(("Installation successful, delete original file"));
       
   738     DeleteCurrentFileL();
       
   739     
       
   740     // handle the next file
       
   741     iCurrentFile++;
       
   742     }
       
   743 
       
   744     
       
   745 void CNcdInstallOperationProxy::SetInstallationErrorCode( const TInt& aErrorCode )
       
   746     {
       
   747     DLTRACEIN((""));
       
   748     iInstallationError = aErrorCode;
       
   749     }
       
   750 
       
   751 
       
   752 TInt CNcdInstallOperationProxy::InstallationErrorCode() const
       
   753     {
       
   754     DLTRACEIN((""));
       
   755     return iInstallationError;
       
   756     }
       
   757 
       
   758 
       
   759 void CNcdInstallOperationProxy::StartInstallReportL()
       
   760     {
       
   761     DLTRACEIN((""));
       
   762     
       
   763     // Inform the install report that the install operation has
       
   764     // been started. The install report is handled in the server side.
       
   765     // So, send the information to the server side operation that will
       
   766     // handle the reports.
       
   767     
       
   768     TInt tmp( 0 );
       
   769     TInt error( 
       
   770         ClientServerSession().
       
   771             SendSync( ENCDOperationFunctionReportStart,
       
   772                       KNullDesC,
       
   773                       tmp,
       
   774                       Handle() ) );  
       
   775     User::LeaveIfError( error );
       
   776     }
       
   777 
       
   778 
       
   779 void CNcdInstallOperationProxy::CompleteInstallReportL( TInt aErrorCode )
       
   780     {
       
   781     DLTRACEIN((""));
       
   782     
       
   783     // Inform the install report that the install operation has
       
   784     // been completed. The install report is handled in the server side.
       
   785     // So, send the information to the server side operation that will
       
   786     // handle the reports.
       
   787     
       
   788     RCatalogsBufferWriter writer;
       
   789     writer.OpenLC();
       
   790     RWriteStream& stream( writer() );
       
   791 
       
   792     stream.WriteInt32L( aErrorCode );
       
   793 
       
   794     TInt tmp( 0 );
       
   795     TInt error =
       
   796     ClientServerSession().
       
   797         SendSync( ENCDOperationFunctionReportComplete,
       
   798                   writer.PtrL(),
       
   799                   tmp,
       
   800                   Handle() );
       
   801     User::LeaveIfError( error ); 
       
   802 
       
   803     CleanupStack::PopAndDestroy( &writer );
       
   804     }
       
   805 
       
   806 
       
   807 // ---------------------------------------------------------------------------
       
   808 // Deletes the current content file
       
   809 // ---------------------------------------------------------------------------
       
   810 //
       
   811 void CNcdInstallOperationProxy::DeleteCurrentFileL()
       
   812     {
       
   813     TRAPD( err, DeleteFileL( iCurrentFile ) );
       
   814     LeaveIfNotErrorL( err, KErrNotFound );        
       
   815     }
       
   816 
       
   817 
       
   818 // ---------------------------------------------------------------------------
       
   819 // File opener
       
   820 // ---------------------------------------------------------------------------
       
   821 //
       
   822 RFile CNcdInstallOperationProxy::OpenFileL( TInt aFileIndex )
       
   823     {
       
   824     DLTRACEIN((""));
       
   825 
       
   826     RCatalogsBufferWriter buffer;
       
   827     buffer.OpenLC();
       
   828     
       
   829     buffer().WriteInt32L( aFileIndex );
       
   830     
       
   831     RFile fileHandle = ClientServerSession().SendSyncFileOpenL( 
       
   832         ENcdOperationFunctionOpenFile,
       
   833         buffer.PtrL(),        
       
   834         Handle() );
       
   835         
       
   836     CleanupStack::PopAndDestroy( &buffer );
       
   837         
       
   838     DLTRACEOUT((""));
       
   839     return fileHandle;
       
   840     }
       
   841 
       
   842 
       
   843 // ---------------------------------------------------------------------------
       
   844 // File deleter
       
   845 // ---------------------------------------------------------------------------
       
   846 //        
       
   847 void CNcdInstallOperationProxy::DeleteFileL( TInt aFileIndex )
       
   848     {
       
   849     DLTRACEIN((""));
       
   850 
       
   851     RCatalogsBufferWriter buffer;
       
   852     buffer.OpenLC();
       
   853     
       
   854     buffer().WriteInt32L( aFileIndex );
       
   855     
       
   856     TInt output = 0;
       
   857     User::LeaveIfError( ClientServerSession().SendSync( 
       
   858         ENcdOperationFunctionDeleteFile,
       
   859         buffer.PtrL(),
       
   860         output,
       
   861         Handle() ) );
       
   862         
       
   863     CleanupStack::PopAndDestroy( &buffer );
       
   864         
       
   865     DLTRACEOUT((""));
       
   866     }
       
   867