ncdengine/provider/client/src/ncdnodeinstallproxy.cpp
changeset 0 ba25891c3a9e
child 44 329d304c1aa1
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:   Contains CNcdNodeInstallProxy class implementation
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <bamdesca.h>
       
    20 #include <bautils.h>
       
    21 #include <s32mem.h>
       
    22 
       
    23 #include "ncdnodeinstallproxy.h"
       
    24 #include "ncdnodeproxy.h"
       
    25 #include "ncdnodemetadataproxy.h"
       
    26 #include "ncdproviderproxy.h"
       
    27 #include "ncdnodemanagerproxy.h"
       
    28 #include "ncdserverreportmanagerproxy.h"
       
    29 #include "ncdoperationimpl.h"
       
    30 #include "ncdinstalloperationproxy.h"
       
    31 #include "ncdsilentinstalloperationproxy.h"
       
    32 #include "ncdoperationmanagerproxy.h"
       
    33 #include "ncdoperationdatatypes.h"
       
    34 #include "catalogsclientserver.h"
       
    35 #include "ncdnodeidentifier.h"
       
    36 #include "ncdnodefunctionids.h"
       
    37 #include "ncdnodeclassids.h"
       
    38 #include "catalogsinterfaceidentifier.h"
       
    39 #include "catalogsutils.h"
       
    40 #include "catalogsdebug.h"
       
    41 #include "ncdpanics.h"
       
    42 #include "catalogsconstants.h"
       
    43 #include "ncdinstallinfo.h"
       
    44 #include "ncdfileinfo.h"
       
    45 #include "ncdinstallationservice.h"
       
    46 #include "ncddeviceinteractionfactory.h"
       
    47 #include "ncdinstalledapplicationimpl.h"
       
    48 #include "ncdinstalledthemeimpl.h"
       
    49 #include "ncdinstalledfileimpl.h"
       
    50 #include "ncdinstalledcontent.h"
       
    51 #include "ncderrors.h"
       
    52 #include "ncdextendedinstallinfo.h"
       
    53 #include "ncdnodedownloadproxy.h"
       
    54 
       
    55 // ======== PUBLIC MEMBER FUNCTIONS ========
       
    56 
       
    57 CNcdNodeInstallProxy::CNcdNodeInstallProxy(
       
    58     MCatalogsClientServer& aSession,
       
    59     TInt aHandle,
       
    60     CNcdNodeMetadataProxy& aMetadata )
       
    61 : CNcdInterfaceBaseProxy( aSession, aHandle, &aMetadata ),
       
    62   iMetadata( aMetadata )
       
    63     {
       
    64     }
       
    65 
       
    66 
       
    67 void CNcdNodeInstallProxy::ConstructL()
       
    68     {
       
    69     // Register the interface
       
    70     MNcdNodeInstall* interface( this );
       
    71     AddInterfaceL( 
       
    72         CCatalogsInterfaceIdentifier::NewL( interface, this,
       
    73             MNcdNodeInstall::KInterfaceUid ) );
       
    74     
       
    75     iInstallationService = 
       
    76         &Metadata().Node().OperationManager().InstallationServiceL(); 
       
    77     
       
    78     InternalizeL();                    
       
    79     }
       
    80 
       
    81 
       
    82 CNcdNodeInstallProxy* CNcdNodeInstallProxy::NewL(
       
    83     MCatalogsClientServer& aSession,
       
    84     TInt aHandle,
       
    85     CNcdNodeMetadataProxy& aMetadata )
       
    86     {
       
    87     CNcdNodeInstallProxy* self = 
       
    88         CNcdNodeInstallProxy::NewLC( aSession, aHandle, aMetadata );
       
    89     CleanupStack::Pop( self );
       
    90     return self;
       
    91     }
       
    92 
       
    93 CNcdNodeInstallProxy* CNcdNodeInstallProxy::NewLC(
       
    94     MCatalogsClientServer& aSession,
       
    95     TInt aHandle,
       
    96     CNcdNodeMetadataProxy& aMetadata )
       
    97     {
       
    98     CNcdNodeInstallProxy* self = 
       
    99         new( ELeave ) CNcdNodeInstallProxy( aSession, aHandle, aMetadata );
       
   100     // Using PushL because the object does not have any references yet
       
   101     CleanupStack::PushL( self );
       
   102     self->ConstructL();
       
   103     return self;
       
   104     }
       
   105 
       
   106 
       
   107 CNcdNodeInstallProxy::~CNcdNodeInstallProxy()
       
   108     {
       
   109     DLTRACEIN((""));
       
   110     // Remove interfaces implemented by this class from the interface list.
       
   111     // So, the interface list is up to date when this class object is deleted.
       
   112     RemoveInterface( MNcdNodeInstall::KInterfaceUid );
       
   113    
       
   114     // Delete member variables here
       
   115     // Do not delete installation service, node and operation manager because
       
   116     // this object does not own them.    
       
   117     
       
   118     // Release all content objects
       
   119     iContent.ResetAndDestroy();
       
   120     }
       
   121 
       
   122 
       
   123 CNcdNodeMetadataProxy& CNcdNodeInstallProxy::Metadata() const
       
   124     {
       
   125     return iMetadata;
       
   126     }
       
   127 
       
   128 
       
   129 void CNcdNodeInstallProxy::InternalizeL()
       
   130     {
       
   131     DLTRACEIN((""));
       
   132 
       
   133     HBufC8* data( NULL );
       
   134         
       
   135     // Because we do not know the exact size of the data, use
       
   136     // the alloc method, which creates the buffer of the right size
       
   137     // and sets the pointer to point to the created buffer.
       
   138     // Get all the data that is necessary to internalize this object
       
   139     // from the server side.
       
   140     User::LeaveIfError(
       
   141         ClientServerSession().
       
   142         SendSyncAlloc( NcdNodeFunctionIds::ENcdInternalize,
       
   143                        KNullDesC8,
       
   144                        data,
       
   145                        Handle(),
       
   146                        0 ) );
       
   147 
       
   148     if ( data == NULL )
       
   149         {
       
   150         DLERROR((""));
       
   151         User::Leave(  KErrNotFound );
       
   152         }
       
   153 
       
   154     CleanupStack::PushL( data );
       
   155 
       
   156     // Read the data from the stream and insert it to the member variables
       
   157     RDesReadStream stream( *data );
       
   158     CleanupClosePushL( stream );
       
   159     
       
   160     InternalizeDataL( stream );
       
   161     
       
   162     // Closes the stream
       
   163     CleanupStack::PopAndDestroy( &stream ); 
       
   164     CleanupStack::PopAndDestroy( data );
       
   165 
       
   166     DLTRACEOUT((""));    
       
   167     }
       
   168 
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // Checks if this item has the purpose
       
   172 // ---------------------------------------------------------------------------
       
   173 // 
       
   174 TBool CNcdNodeInstallProxy::IsPurpose( TNcdItemPurpose aPurpose ) const
       
   175     {
       
   176     return iPurpose & aPurpose;    
       
   177     }
       
   178     
       
   179 
       
   180 // MNcdNodeInstall functions
       
   181     
       
   182 // ---------------------------------------------------------------------------
       
   183 // Creates an install operation
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 MNcdInstallOperation* CNcdNodeInstallProxy::InstallL( 
       
   187     MNcdInstallOperationObserver& aObserver )
       
   188     {
       
   189     DLTRACEIN((""));
       
   190 
       
   191     // Create operation
       
   192     
       
   193     // Using proxy as the observer. Forwards callbacks to the real operation
       
   194     // observer
       
   195     CNcdInstallOperationProxy* op = 
       
   196         Metadata().Node().OperationManager().CreateInstallOperationL(
       
   197         Metadata().Node(), this );
       
   198     iOperationObserver = &aObserver;
       
   199         
       
   200     DLTRACEOUT((""));    
       
   201 
       
   202     return op;
       
   203     }
       
   204 
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // Creates an install operation
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 MNcdInstallOperation* CNcdNodeInstallProxy::SilentInstallL( 
       
   211     MNcdInstallOperationObserver& aObserver,
       
   212     const SwiUI::TInstallOptions& aInstallOptions )
       
   213     {
       
   214     DLTRACEIN((""));
       
   215 
       
   216     // Create operation
       
   217     
       
   218     // Using proxy as the observer. Forwards callbacks to the real operation
       
   219     // observer.
       
   220     // Notice that TrustedUI capabilites are checked when silent install operation is
       
   221     // created in the server side.
       
   222     CNcdInstallOperationProxy* op = 
       
   223         Metadata().Node().OperationManager().CreateSilentInstallOperationL(
       
   224         Metadata().Node(), this, aInstallOptions );
       
   225     iOperationObserver = &aObserver;
       
   226        
       
   227     DLTRACEOUT((""));    
       
   228 
       
   229     return op;
       
   230     }
       
   231 
       
   232 
       
   233 // ---------------------------------------------------------------------------
       
   234 // Returns installed status
       
   235 // ---------------------------------------------------------------------------
       
   236 //
       
   237 TBool CNcdNodeInstallProxy::IsInstalledL() const
       
   238     {
       
   239     DLTRACEIN((""));
       
   240     if ( !iInstalled || !iContent.Count() )
       
   241         {
       
   242         DLTRACEOUT(("Not installed"));
       
   243         return EFalse;
       
   244         }
       
   245         
       
   246     for ( TInt i = 0; i < iContent.Count(); ++i )
       
   247         {
       
   248         if ( !iContent[i]->IsInstalledL() )
       
   249             {
       
   250             DLTRACEOUT(("Not installed (entirely)"));
       
   251             return EFalse;
       
   252             }
       
   253         }
       
   254     DLTRACEOUT(("Installed"));
       
   255     return ETrue;
       
   256     }
       
   257 
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // IsLaunchableL
       
   261 // ---------------------------------------------------------------------------
       
   262 //
       
   263 TBool CNcdNodeInstallProxy::IsLaunchable() const
       
   264     {        
       
   265     DLTRACEIN((""));
       
   266     for ( TInt i = 0; i < iContent.Count(); ++i )
       
   267         {
       
   268         if ( iContent[i]->IsLaunchable() )
       
   269             {
       
   270             DLTRACEOUT(("Item contains something launchable"));
       
   271             return ETrue;
       
   272             }
       
   273         }
       
   274     
       
   275     DLTRACEOUT(("Item doesn't contain anything launchable"));
       
   276     return EFalse;
       
   277     }
       
   278     
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // InstalledContentL
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 RCatalogsArray<MNcdInstalledContent> 
       
   285     CNcdNodeInstallProxy::InstalledContentL()
       
   286     {
       
   287     DLTRACEIN(("this-ptr: %x, refcount: %d", this, TotalRefCount() ));
       
   288     RCatalogsArray<MNcdInstalledContent> array;
       
   289     CleanupResetAndDestroyPushL( array );
       
   290     
       
   291     array.ReserveL( iContent.Count() );
       
   292     MNcdInstalledContent* content = NULL;
       
   293     for ( TInt i = 0; i < iContent.Count(); ++i )
       
   294         {
       
   295         content = iContent[i];
       
   296         array.AppendL( content );
       
   297         content->AddRef();
       
   298         }
       
   299     CleanupStack::Pop( &array );
       
   300     DLTRACEOUT(("this-ptr: %x, refcount: %d", this, TotalRefCount() ));
       
   301     return array;
       
   302     }
       
   303 
       
   304 
       
   305 // ---------------------------------------------------------------------------
       
   306 // SetAsInstalledL
       
   307 // ---------------------------------------------------------------------------
       
   308 //
       
   309 void CNcdNodeInstallProxy::SetApplicationInstalledL( TInt aErrorCode )
       
   310     {
       
   311     DLTRACEIN(("error code: %d", aErrorCode));
       
   312 
       
   313     // This function can only be called if download operation has already been done.
       
   314     CNcdNodeDownloadProxy* download( Metadata().Download() );
       
   315     if ( download == NULL 
       
   316          || !download->IsDownloadedL() )
       
   317         {
       
   318         DLINFO(("download has not been done"));
       
   319         User::Leave( KErrAbort );
       
   320         }
       
   321 
       
   322     // Handle the information in the server side.
       
   323     // This will also delete the content install files if they
       
   324     // still exist after succesfull installation.
       
   325     CBufBase* buf = CBufFlat::NewL( KBufExpandSize );
       
   326     CleanupStack::PushL( buf );
       
   327     RBufWriteStream stream( *buf );
       
   328     CleanupClosePushL( stream );
       
   329 
       
   330     stream.WriteInt32L( aErrorCode );
       
   331 
       
   332     CleanupStack::PopAndDestroy( &stream );
       
   333     TPtrC8 ptr = buf->Ptr( 0 );    
       
   334         
       
   335     TInt tmp( 0 );
       
   336     TInt error =
       
   337     ClientServerSession().
       
   338         SendSync( NcdNodeFunctionIds::ENcdSetApplicationInstalled,
       
   339                   ptr,
       
   340                   tmp,
       
   341                   Handle() );
       
   342     User::LeaveIfError( error ); 
       
   343 
       
   344     CleanupStack::PopAndDestroy( buf );
       
   345 
       
   346 
       
   347     CNcdNodeManagerProxy& nodeManager( 
       
   348         Metadata().Node().NodeManager() );
       
   349         
       
   350    CNcdProviderProxy& provider(
       
   351         nodeManager.Provider() );
       
   352 
       
   353     // Send an error report.
       
   354     // Report manager is checking if the install report list already contains the
       
   355     // corresonding report and replaces an old one if necessary. But, in all the
       
   356     // cases set this report. If install has been set as success or failure,
       
   357     // always send the information. Even if the node state has been installed before
       
   358     // this operation, send new report because this may be a new try to install
       
   359     // the content for some reason. So, success and failure information is necessary
       
   360     // then also.
       
   361     provider.ServerReportManager().NodeSetAsInstalledL( Metadata().Node(), 
       
   362                                                         aErrorCode );
       
   363 
       
   364     // Internalize node and all corresponding nodes.
       
   365     // This way, all their information will be up-to-date.
       
   366     // For example, the installation state may have changed because of the
       
   367     // settings above.
       
   368     nodeManager.InternalizeRelatedNodesL( Metadata().Node() );
       
   369     }
       
   370 
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 // Installationservice getter
       
   374 // ---------------------------------------------------------------------------
       
   375 //
       
   376 MNcdInstallationService& CNcdNodeInstallProxy::InstallationService()
       
   377     {
       
   378     return *iInstallationService;
       
   379     }
       
   380 
       
   381 
       
   382 // ---------------------------------------------------------------------------
       
   383 // File session getter
       
   384 // ---------------------------------------------------------------------------
       
   385 //
       
   386 RFs& CNcdNodeInstallProxy::FileSession()
       
   387     {
       
   388     return iInstallationService->FileServerSession();
       
   389     }
       
   390 
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // File opener
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 RFile CNcdNodeInstallProxy::OpenFileL( TInt aFileIndex )
       
   397     {
       
   398     DLTRACEIN((""));
       
   399 
       
   400     // Convert index to a descriptor
       
   401     HBufC8* filenumber = IntToDes8LC( aFileIndex );
       
   402     
       
   403     RFile fileHandle = ClientServerSession().SendSyncFileOpenL( 
       
   404         NcdNodeFunctionIds::ENcdInstallOpenFile,
       
   405         *filenumber,        
       
   406         Handle() );
       
   407         
       
   408     CleanupStack::PopAndDestroy( filenumber );
       
   409         
       
   410     DLTRACEOUT((""));
       
   411     return fileHandle;
       
   412     }
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 // Handles progress information
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 void CNcdNodeInstallProxy::InstallProgress( MNcdInstallOperation& aOperation,
       
   419     TNcdProgress aProgress )
       
   420     {
       
   421     DLTRACEIN((""));
       
   422     DASSERT( iOperationObserver );
       
   423     
       
   424     iOperationObserver->InstallProgress( aOperation, aProgress );
       
   425     DLTRACEOUT((""));
       
   426     }
       
   427 
       
   428 
       
   429 // ---------------------------------------------------------------------------
       
   430 // Handles querys
       
   431 // ---------------------------------------------------------------------------
       
   432 //
       
   433 void CNcdNodeInstallProxy::QueryReceived( MNcdInstallOperation& aOperation,
       
   434     MNcdQuery* aQuery )
       
   435     {
       
   436     DLTRACEIN((""));
       
   437     DASSERT( iOperationObserver );
       
   438     iOperationObserver->QueryReceived( aOperation, aQuery );
       
   439     DLTRACEOUT((""));
       
   440     }
       
   441 
       
   442 
       
   443 // ---------------------------------------------------------------------------
       
   444 // Handles operation complete callbacks
       
   445 // ---------------------------------------------------------------------------
       
   446 //
       
   447 void CNcdNodeInstallProxy::OperationComplete( 
       
   448     MNcdInstallOperation& aOperation, TInt aError )
       
   449     {
       
   450     DLTRACEIN(( "Error: %d", aError ));
       
   451     DASSERT( iOperationObserver );
       
   452 
       
   453 
       
   454     if ( aError == KErrNone || aError == KNcdThemeReinstalled ) 
       
   455         {
       
   456         // update proxy's status from the server       
       
   457         TRAPD( err, iMetadata.InternalizeL() );
       
   458         if ( err != KErrNone ) 
       
   459             {
       
   460             DLERROR(("Error during internalization: %d", err));
       
   461             aError = err;
       
   462             }            
       
   463         }
       
   464      
       
   465     iOperationObserver->OperationComplete( aOperation, aError );
       
   466     DLTRACEOUT((""));
       
   467     }
       
   468     
       
   469     
       
   470 
       
   471 // Other functions
       
   472 
       
   473 void CNcdNodeInstallProxy::InternalizeDataL( RReadStream& aStream )
       
   474     {
       
   475     DLTRACEIN((""));
       
   476 
       
   477     // Use catalogsutils.h functions to internalize
       
   478     // memebervariables according to the data received
       
   479     // from the server.
       
   480     // Make sure that the variables are set here in the same
       
   481     // order as they are externalized in the server side.
       
   482     // Small mistake here messes up everything!
       
   483 
       
   484     // First read the class id. Because, it is the first thing in the stream.
       
   485     TInt classId( aStream.ReadInt32L() );
       
   486     
       
   487     if ( classId != NcdNodeClassIds::ENcdNodeInstallClassId )
       
   488         {
       
   489         // classId is not recognized
       
   490         DLERROR(("Class id was not recognized!"));
       
   491         // For testing purposes assert here
       
   492         DASSERT( EFalse );
       
   493         
       
   494         // Otherwise leave is adequate
       
   495         User::Leave( KErrCorrupt );
       
   496         }
       
   497 
       
   498     iPurpose = aStream.ReadInt32L();
       
   499     DLINFO(("Purpose: %u", iPurpose));
       
   500     
       
   501     iInstalled = aStream.ReadInt32L();
       
   502     DLINFO(("Installed: %d", iInstalled));
       
   503     
       
   504     iLaunchable = aStream.ReadInt32L();
       
   505     DLINFO(("Launchable: %d", iLaunchable));
       
   506     
       
   507     iContent.ResetAndDestroy();
       
   508     
       
   509     if ( iInstalled )
       
   510         {
       
   511         DLTRACE(("Reading infos"));
       
   512         TInt infos = aStream.ReadInt32L();
       
   513         TInt fileIndex = 0;        
       
   514         
       
   515         CNcdExtendedInstallInfo* tempInfo = NULL;
       
   516         while ( infos )
       
   517             {
       
   518             tempInfo = CNcdExtendedInstallInfo::NewLC();
       
   519             tempInfo->InternalizeL( aStream );
       
   520             CreateInstalledContentL( *tempInfo, fileIndex );
       
   521             CleanupStack::PopAndDestroy( tempInfo );
       
   522             tempInfo = NULL;
       
   523             --infos;
       
   524             ++fileIndex;
       
   525             }
       
   526         }    
       
   527 
       
   528     DLTRACEOUT((""));
       
   529     }
       
   530     
       
   531     
       
   532 void CNcdNodeInstallProxy::CreateInstalledContentL(
       
   533     const CNcdExtendedInstallInfo& aInfo, 
       
   534     TInt aFileIndex )
       
   535     {
       
   536     DLTRACEIN((""));
       
   537     CNcdInstalledContent* content = NULL;
       
   538     if ( aInfo.Filename() != KNullDesC() ) 
       
   539         {
       
   540         DLTRACE(( _L("Installed file: %S"), &aInfo.Filename() ));
       
   541 
       
   542         CNcdFileInfo* fileInfo = CNcdFileInfo::NewLC( 
       
   543             aInfo.Filename(), aInfo.MimeType() );
       
   544         CleanupStack::Pop( fileInfo );
       
   545         
       
   546         // fileInfo is deleted in CNcdInstalledFile if NewLC leaves            
       
   547         CNcdInstalledFile* file = 
       
   548             CNcdInstalledFile::NewLC( *this, fileInfo, aFileIndex );
       
   549         content = file;
       
   550         }
       
   551     else if ( aInfo.ApplicationUid() != TUid::Null() ) 
       
   552         {
       
   553         DLTRACE(("Application"));
       
   554         CNcdInstalledApplication* app = 
       
   555             CNcdInstalledApplication::NewLC( 
       
   556                 *this, 
       
   557                 aInfo.ApplicationUid(),
       
   558                 aInfo.ApplicationVersion(),
       
   559                 aInfo.Parameter(),
       
   560                 aInfo.ContentType(),
       
   561                 aInfo.UriExists() );
       
   562         content = app;
       
   563         }
       
   564     else // assume theme
       
   565         {
       
   566         DLTRACE(( _L("Theme: %S"), &aInfo.ThemeName() ));
       
   567         CNcdInstalledTheme* theme = CNcdInstalledTheme::NewLC(
       
   568             *this, aInfo.ThemeName().AllocL() );
       
   569         content = theme;
       
   570         }
       
   571 
       
   572     DASSERT( content );
       
   573     content->AddRef();
       
   574     content->SetLaunchable( aInfo.IsLaunchable() );
       
   575     
       
   576     DLTRACE(("Content refcount: %d", content->RefCount() ));
       
   577     iContent.AppendL( content );
       
   578     
       
   579     CleanupStack::Pop(); // file, app or theme
       
   580 
       
   581     DLTRACEOUT(("Content added successfully"));
       
   582     }