iaupdate/IAD/engine/controller/src/iaupdateselfupdaterinitializer.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2009 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:   ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 // NCD headers:
       
    22 // Purchase history contains items
       
    23 #include <ncdpurchasehistory.h>
       
    24 // Contains CBase-class headers of the ncd purchase classes.
       
    25 #include <ncdutils.h>
       
    26 #include <ncdprovider.h>
       
    27 
       
    28 #include "iaupdateselfupdaterinitializer.h"
       
    29 #include "iaupdatenodeimpl.h"
       
    30 #include "iaupdateselfupdaterinitobserver.h"
       
    31 #include "iaupdatecontrollerimpl.h"
       
    32 #include "iaupdateselfupdaterctrl.h"
       
    33 #include "iaupdaterfilelist.h"
       
    34 #include "iaupdaterfileinfo.h"
       
    35 #include "iaupdateridentifier.h"
       
    36 #include "iaupdatedebug.h"
       
    37 
       
    38 
       
    39 CIAUpdateSelfUpdaterInitializer* CIAUpdateSelfUpdaterInitializer::NewL(
       
    40     CIAUpdateNode& aNode,
       
    41     MIAUpdateSelfUpdaterInitObserver& aObserver )
       
    42     {
       
    43     CIAUpdateSelfUpdaterInitializer* self =
       
    44         CIAUpdateSelfUpdaterInitializer::NewLC( aNode, aObserver );
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 
       
    50 CIAUpdateSelfUpdaterInitializer* CIAUpdateSelfUpdaterInitializer::NewLC(
       
    51     CIAUpdateNode& aNode,
       
    52     MIAUpdateSelfUpdaterInitObserver& aObserver )
       
    53     {
       
    54     CIAUpdateSelfUpdaterInitializer* self =
       
    55         new( ELeave ) CIAUpdateSelfUpdaterInitializer( aNode, aObserver );
       
    56     CleanupStack::PushL( self );
       
    57     self->ConstructL();
       
    58     return self;
       
    59     }
       
    60 
       
    61 
       
    62 CIAUpdateSelfUpdaterInitializer::CIAUpdateSelfUpdaterInitializer( 
       
    63     CIAUpdateNode& aNode,
       
    64     MIAUpdateSelfUpdaterInitObserver& aObserver )
       
    65 : CActive( CActive::EPriorityStandard ),
       
    66   iNode( aNode ),
       
    67   iObserver( aObserver ) 
       
    68     {
       
    69 
       
    70     }
       
    71 
       
    72 
       
    73 void CIAUpdateSelfUpdaterInitializer::ConstructL()
       
    74     {
       
    75     User::LeaveIfError( FileServer().Connect() );
       
    76     CActiveScheduler::Add( this );
       
    77     }
       
    78 
       
    79 
       
    80 CIAUpdateSelfUpdaterInitializer::~CIAUpdateSelfUpdaterInitializer()
       
    81     {
       
    82     Cancel();
       
    83 
       
    84     FileServer().Close();
       
    85 
       
    86     // Notice, that file list can be also NULL if
       
    87     // the ownership has been transferred to else where.
       
    88     delete iFileList;
       
    89     }
       
    90     
       
    91 
       
    92 void CIAUpdateSelfUpdaterInitializer::StartL()
       
    93     {
       
    94     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::Start() begin");
       
    95     
       
    96     if ( !IsActive()
       
    97          && iState == ENotStarted )
       
    98         {
       
    99         // Start the active loop, which will
       
   100         // set the content files into the file list.
       
   101         iState = EInitialize;            
       
   102         iStatus = KRequestPending;
       
   103         SetActive();
       
   104         TRequestStatus* ptrStatus = &iStatus;
       
   105         User::RequestComplete( ptrStatus, KErrNone );        
       
   106         }
       
   107     else
       
   108         {
       
   109         User::Leave( KErrInUse );
       
   110         }
       
   111 
       
   112     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::Start() end");
       
   113     }
       
   114 
       
   115 
       
   116 void CIAUpdateSelfUpdaterInitializer::DoCancel()
       
   117     {
       
   118     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::DoCancel() begin");
       
   119     
       
   120     iState = ENotStarted;
       
   121 
       
   122     // The ownership has not been transferred yet.
       
   123     // So, delete filelist here.    
       
   124     delete iFileList;
       
   125     iFileList = NULL;
       
   126     
       
   127     // Also inform observer that the cancellation happened.
       
   128     Observer().SelfUpdateInitComplete( KErrCancel );
       
   129 
       
   130     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::DoCancel() end");
       
   131     }
       
   132 
       
   133 
       
   134 void CIAUpdateSelfUpdaterInitializer::RunL()
       
   135     {
       
   136     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::RunL() begin");
       
   137     
       
   138     switch( State() )
       
   139         {
       
   140         case EInitialize:
       
   141             // Initialize things for the self update and set file list info.
       
   142             // Create the file list here. If an error occurs below, RunError will
       
   143             // delete the file list. If everything goes ok, then ownership is
       
   144             // transferred to other object.
       
   145             iFileList = CIAUpdaterFileList::NewL();
       
   146             SetContentFileListL();
       
   147             // Inform observer that setup is complete.
       
   148             // The ownership of the file list will be transferred here.
       
   149             InitCompleteL();
       
   150             break;
       
   151                 
       
   152         default:
       
   153             // Unknown state.
       
   154             // Let RunError handle this.
       
   155             User::Leave( KErrArgument );
       
   156             break;
       
   157         }
       
   158 
       
   159     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::RunL() end");
       
   160     }
       
   161 
       
   162 
       
   163 TInt CIAUpdateSelfUpdaterInitializer::RunError( TInt aError )
       
   164     {
       
   165     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::RunError() begin");
       
   166     
       
   167     iState = ENotStarted;
       
   168     
       
   169     // Delete file list because error occurred.
       
   170     delete iFileList;
       
   171     iFileList = NULL;
       
   172 
       
   173     // Inform observer about the error.
       
   174     Observer().SelfUpdateInitComplete( aError );
       
   175 
       
   176     // We do not continue the operation anymore.
       
   177 
       
   178     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::RunError() end");
       
   179 
       
   180     return KErrNone;
       
   181     }
       
   182 
       
   183 
       
   184 const CIAUpdateSelfUpdaterInitializer::TUpdaterState& CIAUpdateSelfUpdaterInitializer::State() const
       
   185     {
       
   186     return iState;
       
   187     }
       
   188 
       
   189 
       
   190 CIAUpdateNode& CIAUpdateSelfUpdaterInitializer::Node()
       
   191     {
       
   192     return iNode;
       
   193     }
       
   194 
       
   195 
       
   196 MIAUpdateSelfUpdaterInitObserver& CIAUpdateSelfUpdaterInitializer::Observer()
       
   197     {
       
   198     return iObserver;
       
   199     }
       
   200 
       
   201 
       
   202 RFs& CIAUpdateSelfUpdaterInitializer::FileServer()
       
   203     {
       
   204     return iFs;
       
   205     }
       
   206 
       
   207 
       
   208 void CIAUpdateSelfUpdaterInitializer::SetContentFileListL()
       
   209     {
       
   210     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::SetContentFileListL() begin");
       
   211     
       
   212     // The file list will have one common name for all the files if the content
       
   213     // is given as a bundle.
       
   214     iFileList->SetBundleNameL( Node().Name() );
       
   215     iFileList->SetHidden( Node().Hidden() );
       
   216     CIAUpdaterIdentifier& identifier( iFileList->Identifier() );
       
   217     identifier.SetIdL( Node().MetaId() );
       
   218     identifier.SetNamespaceL( Node().MetaNamespace() );
       
   219     identifier.SetUid( Node().Uid() );
       
   220 
       
   221     MNcdProvider& provider =
       
   222         Node().Controller().ProviderL();
       
   223 
       
   224     MNcdPurchaseHistory* history( provider.PurchaseHistoryL() );
       
   225     CleanupReleasePushL( *history );
       
   226 
       
   227     // Create filter. So, we will get
       
   228     // all the purchase history items.
       
   229     CNcdPurchaseHistoryFilter* filter =
       
   230         CNcdPurchaseHistoryFilter::NewLC();
       
   231 
       
   232     // Add family uid to the filter
       
   233     RArray< TUid > uids;
       
   234     CleanupClosePushL( uids );
       
   235     uids.AppendL( Node().Controller().FamilyUid() );
       
   236     filter->SetClientUids( uids.Array() );
       
   237     CleanupStack::PopAndDestroy( &uids );
       
   238 
       
   239     // Add other filter values.
       
   240     // We only want content information for this node.
       
   241     filter->SetNamespaceL( Node().MetaNamespace() );
       
   242     filter->SetEntityIdL(  Node().MetaId() );
       
   243     
       
   244     // Get the ids. So, we can next get all the corresponding
       
   245     // details.
       
   246     RArray< TUint > ids =
       
   247         history->PurchaseIdsL( *filter );
       
   248     CleanupStack::PopAndDestroy( filter );
       
   249     CleanupClosePushL( ids );
       
   250     
       
   251     if ( ids.Count() > 0 )
       
   252         {
       
   253         IAUPDATE_TRACE("[IAUPDATE] Ids found.");
       
   254     
       
   255         // If there are any details, then the latest should be the first
       
   256         // one in the array. So, use that.
       
   257         CNcdPurchaseDetails* details( 
       
   258             history->PurchaseDetailsL( ids[ 0 ] , EFalse ) );        
       
   259 
       
   260         if ( details )
       
   261             {
       
   262             IAUPDATE_TRACE("[IAUPDATE] Details found.");
       
   263         
       
   264             // We got the newest details. Get its file information.
       
   265             CleanupStack::PushL( details );
       
   266 
       
   267             const MDesCArray& files = details->DownloadedFiles();        
       
   268             TInt count( files.MdcaCount() );
       
   269             IAUPDATE_TRACE_1("[IAUPDATE] Files count: %d", count);    
       
   270             for( TInt i = 0; i < count; ++i )
       
   271                 {
       
   272                 CIAUpdaterFileInfo* info( CIAUpdaterFileInfo::NewLC() );
       
   273                 info->SetFilePathL( files.MdcaPoint( i ) );
       
   274                 iFileList->AddFileInfoL( info );
       
   275                 CleanupStack::Pop( info );
       
   276                 info = NULL;                    
       
   277                 IAUPDATE_TRACE("[IAUPDATE] Info added to file list.");
       
   278                 }
       
   279             
       
   280             CleanupStack::PopAndDestroy( details );
       
   281             details = NULL;
       
   282             }
       
   283         }
       
   284 
       
   285     CleanupStack::PopAndDestroy( &ids );
       
   286     CleanupStack::PopAndDestroy( history );
       
   287 
       
   288     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::SetContentFileListL() end");
       
   289     }
       
   290 
       
   291 
       
   292 void CIAUpdateSelfUpdaterInitializer::InitCompleteL()
       
   293     {
       
   294     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::InitComplete() begin");
       
   295 
       
   296     // Everything has been done.
       
   297     // Set the state.
       
   298     iState = ENotStarted;
       
   299 
       
   300     if ( iFileList->FileInfos().Count() > 0 )
       
   301         {
       
   302         IAUPDATE_TRACE("[IAUPDATE] Add filelist into the controller list.");
       
   303         // Insert the file list for the use.
       
   304         // If this leaves, then let RunError handle the error situation.
       
   305         // It will also inform observer.
       
   306         Node().Controller().SelfUpdaterCtrl().AddFileListL( iFileList );
       
   307         // Ownership was transferred.
       
   308         iFileList = NULL;
       
   309         Observer().SelfUpdateInitComplete( KErrNone );
       
   310         }
       
   311     else
       
   312         {
       
   313         IAUPDATE_TRACE("[IAUPDATE] No files found. Error?");
       
   314         // No files to install. Think this as an error.
       
   315         // And, do not start the self updater because there is no need for that.
       
   316         // Let RunError handle the error situation.
       
   317         User::Leave( KErrNotFound );
       
   318         }
       
   319 
       
   320     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateSelfUpdaterInitializer::InitComplete() end");
       
   321     }