iaupdate/IAD/engine/controller/src/iaupdatefwnodeimpl.cpp
changeset 0 ba25891c3a9e
child 77 d1838696558c
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2007-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:   This module contains the implementation of CIAUpdateFwNode class 
       
    15 *                member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #include <e32cmn.h>
       
    22 #include <etelmm.h>
       
    23 #include <ncdnode.h>
       
    24 #include <ncdnodecontentinfo.h>
       
    25 #include <ncdpurchasedownloadinfo.h>
       
    26 #include <ncdutils.h>
       
    27 
       
    28 #include "iaupdatefwnodeimpl.h"
       
    29 #include "iaupdatecontrollerimpl.h"
       
    30 #include "iaupdatefwpurchaseoperation.h"
       
    31 #include "iaupdatefwnodeobserver.h"
       
    32 #include "iaupdatenodedetails.h"
       
    33 #include "iaupdatedebug.h"
       
    34 
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CIAUpdateFwNode::NewLC
       
    38 // Two-phased constructor.
       
    39 // -----------------------------------------------------------------------------
       
    40 // 
       
    41 CIAUpdateFwNode* CIAUpdateFwNode::NewLC( 
       
    42     MNcdNode* aNode,
       
    43     CIAUpdateController& aController,
       
    44     MIAUpdateFwNode::TFwUpdateType aFwType )
       
    45     {
       
    46     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::NewLC() begin");
       
    47 
       
    48     CIAUpdateFwNode* self = 
       
    49         new( ELeave ) CIAUpdateFwNode( aController, aFwType );
       
    50     CleanupStack::PushL( self );    
       
    51     self->ConstructL( aNode );
       
    52 
       
    53     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::NewLC() end");
       
    54 
       
    55     return self;
       
    56     }
       
    57 
       
    58     
       
    59 // -----------------------------------------------------------------------------
       
    60 // CIAUpdateFwNode::NewL
       
    61 // Two-phased constructor.
       
    62 // -----------------------------------------------------------------------------
       
    63 //     
       
    64 CIAUpdateFwNode* CIAUpdateFwNode::NewL( 
       
    65     MNcdNode* aNode,
       
    66     CIAUpdateController& aController,
       
    67     MIAUpdateFwNode::TFwUpdateType aFwType )
       
    68     {
       
    69     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::NewL() begin");
       
    70 
       
    71     CIAUpdateFwNode* self = 
       
    72         CIAUpdateFwNode::NewLC( aNode, aController, aFwType );
       
    73     CleanupStack::Pop( self );
       
    74 
       
    75     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::NewL() end");
       
    76 
       
    77     return self;
       
    78     }
       
    79 
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CIAUpdateFwNode::CIAUpdateFwNode
       
    83 // C++ default constructor can NOT contain any code, that
       
    84 // might leave.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 CIAUpdateFwNode::CIAUpdateFwNode( CIAUpdateController& aController,
       
    88                                   MIAUpdateFwNode::TFwUpdateType aFwType ) 
       
    89 : CIAUpdateBaseNode( aController ),
       
    90   iType( aFwType )
       
    91     {
       
    92     }
       
    93 
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CIAUpdateFwNode::ConstructL
       
    97 // Symbian 2nd phase constructor can leave.
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CIAUpdateFwNode::ConstructL( MNcdNode* aNode )
       
   101     {
       
   102     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::ConstructL() begin");
       
   103 
       
   104     // Let the parent handle it all.
       
   105     CIAUpdateBaseNode::ConstructL( aNode );
       
   106 
       
   107     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::ConstructL() end");
       
   108     }
       
   109 
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CIAUpdateFwNode::~CIAUpdateFwNode
       
   113 // Destructor
       
   114 // -----------------------------------------------------------------------------
       
   115 //    
       
   116 CIAUpdateFwNode::~CIAUpdateFwNode()
       
   117     {
       
   118     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::~CIAUpdateFwNode() begin");
       
   119 
       
   120     if ( iPurchaseOperation )
       
   121         {
       
   122         // Because purchase operation exists, set the cancelling flag on. 
       
   123         // Then, observer callbacks are not called when the deletion of 
       
   124         // the object cancels the operation. 
       
   125         // Also, notice that instead of directly using the error code given 
       
   126         // to callbacks, we use the local cancel flag. So, we can handle cases 
       
   127         // when operation was able to finish and cancellation did not occur even
       
   128         // if it was requested. That would most likely never occur, but better to
       
   129         // be safe than sorry,.
       
   130         iCancelling = ETrue;
       
   131         // Notice, that callback function will delete the iPurchaseOperation.
       
   132         // So, do not call delete instead of cancel operation here because then
       
   133         // delete would be called twice for the same pointer. Instead, just use 
       
   134         // the CancelOperation function call.
       
   135         iPurchaseOperation->CancelOperation();
       
   136         // There should not be any need to call delete after cancel above. 
       
   137         // But, insert it here just in case the operation functionality changes. 
       
   138         // It does not hurt to call it here now
       
   139         // because pointer should always be NULL already.
       
   140         delete iPurchaseOperation;    
       
   141         }
       
   142 
       
   143     delete iContentUrl;
       
   144     
       
   145     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::~CIAUpdateFwNode() end");
       
   146     }
       
   147 
       
   148 
       
   149 // ---------------------------------------------------------------------------
       
   150 // MIAUpdateFwNode functions
       
   151 // 
       
   152 // ---------------------------------------------------------------------------
       
   153 
       
   154 
       
   155 // ---------------------------------------------------------------------------
       
   156 // CIAUpdateFwNode::FwType
       
   157 // 
       
   158 // ---------------------------------------------------------------------------
       
   159 //    
       
   160 MIAUpdateFwNode::TFwUpdateType CIAUpdateFwNode::FwType() const
       
   161     {
       
   162     return iType;
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CIAUpdateFwNode::FwVersion1
       
   168 // 
       
   169 // ---------------------------------------------------------------------------
       
   170 //    
       
   171 const TDesC& CIAUpdateFwNode::FwVersion1() const
       
   172     {
       
   173     return Details().FwVersion1();
       
   174     }
       
   175 
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CIAUpdateFwNode::FwVersion2
       
   179 // 
       
   180 // ---------------------------------------------------------------------------
       
   181 //    
       
   182 const TDesC& CIAUpdateFwNode::FwVersion2() const
       
   183     {
       
   184     return Details().FwVersion2();
       
   185     }
       
   186 
       
   187 
       
   188 // ---------------------------------------------------------------------------
       
   189 // CIAUpdateFwNode::FwVersion3
       
   190 // 
       
   191 // ---------------------------------------------------------------------------
       
   192 //    
       
   193 const TDesC& CIAUpdateFwNode::FwVersion3() const
       
   194     {
       
   195     return Details().FwVersion3();
       
   196     }
       
   197 
       
   198 
       
   199 // ---------------------------------------------------------------------------
       
   200 // CIAUpdateFwNode::InitDownloadDataL
       
   201 // 
       
   202 // ---------------------------------------------------------------------------
       
   203 //    
       
   204 TBool CIAUpdateFwNode::InitDownloadDataL( MIAUpdateFwNodeObserver& aObserver )
       
   205     {
       
   206     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::InitDownloadDataL() begin");
       
   207     
       
   208     if ( iPurchaseOperation )
       
   209         {
       
   210         IAUPDATE_TRACE("[IAUPDATE] ERROR: KErrInUse, operation already going on.");
       
   211         User::Leave( KErrInUse );
       
   212         }
       
   213 
       
   214     // Create new purchase operation and start it if purchase is necessary.
       
   215     IAUPDATE_TRACE("[IAUPDATE] Create new purchase operation");
       
   216     CIAUpdateContentOperation* tmpPurchaseOperation(
       
   217         CIAUpdateFwPurchaseOperation::NewLC( *this, *this ) );
       
   218     TBool operationStarted(
       
   219         tmpPurchaseOperation->StartOperationL() );
       
   220 
       
   221     if ( operationStarted )
       
   222         {
       
   223         IAUPDATE_TRACE("[IAUPDATE] Operation started");
       
   224 
       
   225         // Ownership will be transferred below to the member variable.
       
   226         // So, do not leve the operation into the stack.
       
   227         CleanupStack::Pop( tmpPurchaseOperation );
       
   228 
       
   229         // Now, that function can not leave, set the member variable values.
       
   230         // These values are required when the asynchronous purcahse operation
       
   231         // completes and callback functions are called.
       
   232         iPurchaseOperation = tmpPurchaseOperation;
       
   233         iObserver = &aObserver;        
       
   234         }
       
   235     else
       
   236         {
       
   237         // Because operation was not started,
       
   238         // delete the operation object.
       
   239         CleanupStack::PopAndDestroy( tmpPurchaseOperation );        
       
   240         tmpPurchaseOperation = NULL;
       
   241         }
       
   242 
       
   243     IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateFwNode::InitDownloadDataL() end: %d",
       
   244                      operationStarted);
       
   245 
       
   246     return operationStarted;
       
   247     }
       
   248 
       
   249 
       
   250 // ---------------------------------------------------------------------------
       
   251 // CIAUpdateFwNode::ContentUrl
       
   252 // 
       
   253 // ---------------------------------------------------------------------------
       
   254 //    
       
   255 const TDesC& CIAUpdateFwNode::ContentUrl() const
       
   256     {
       
   257     if ( !iContentUrl )
       
   258         {
       
   259         return KNullDesC();
       
   260         }
       
   261 
       
   262     return *iContentUrl;
       
   263     }
       
   264 
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CIAUpdateFwNode::NodeType
       
   268 // 
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 MIAUpdateAnyNode::TNodeType CIAUpdateFwNode::NodeType() const
       
   272     {
       
   273     return MIAUpdateAnyNode::ENodeTypeFw;
       
   274     }
       
   275 
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // CIAUpdateFwNode::Base
       
   279 // 
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 MIAUpdateBaseNode& CIAUpdateFwNode::Base()
       
   283     {
       
   284     return *this;   
       
   285     }
       
   286 
       
   287 
       
   288 // ---------------------------------------------------------------------------
       
   289 // MIAUpdateContentOperationObserver functions
       
   290 // 
       
   291 // ---------------------------------------------------------------------------
       
   292 
       
   293 
       
   294 // ---------------------------------------------------------------------------
       
   295 // CIAUpdateFwNode::ContentOperationComplete
       
   296 // 
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 void CIAUpdateFwNode::ContentOperationComplete( CIAUpdateBaseNode& /*aNode*/, 
       
   300                                                 TInt aError )
       
   301     {
       
   302     IAUPDATE_TRACE_1("[IAUPDATE] CIAUpdateFwNode::ContentOperationComplete() begin: %d",
       
   303                      aError);
       
   304     
       
   305     delete iPurchaseOperation;
       
   306     iPurchaseOperation = NULL;
       
   307 
       
   308     // Use the temporary variable here for the observer because, in some cases,
       
   309     // the observer may delete this object when callback is called and no
       
   310     // member variables should be used after that.
       
   311     MIAUpdateFwNodeObserver* tmpObserver( iObserver );
       
   312     // Do not delete observer because it is not owned here.
       
   313     // Just set it to NULL.
       
   314     iObserver = NULL;
       
   315 
       
   316     if ( !iCancelling )
       
   317         {
       
   318         IAUPDATE_TRACE("[IAUPDATE] Operation not cancelled.");
       
   319 
       
   320         // Because operation was not cancelled, 
       
   321         // set the URL if everything went OK.        
       
   322         if ( aError == KErrNone )
       
   323             {
       
   324             // If URL can not be set, then replace KErrNone value of aError
       
   325             // with the leave error. So, that value will be given for the observer.
       
   326             TRAP( aError, SetContentUrlL() );
       
   327             }
       
   328 
       
   329         IAUPDATE_TRACE_1("[IAUPDATE] Inform observer: %d", aError);
       
   330         tmpObserver->InitDownloadDataComplete( *this, aError );        
       
   331         }
       
   332         
       
   333     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::ContentOperationComplete() end");
       
   334     }
       
   335 
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 // CIAUpdateFwNode::ContentOperationProgress
       
   339 // 
       
   340 // ---------------------------------------------------------------------------
       
   341 //
       
   342 void CIAUpdateFwNode::ContentOperationProgress( CIAUpdateBaseNode& /*aNode*/, 
       
   343                                                 TInt /*aProgress*/, 
       
   344                                                 TInt /*aMaxProgress*/ )
       
   345     {
       
   346     
       
   347     }
       
   348 
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // CIAUpdateFwNode functions
       
   352 // 
       
   353 // ---------------------------------------------------------------------------
       
   354 
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // CIAUpdateFwNode::SetContentUrlL
       
   358 // 
       
   359 // ---------------------------------------------------------------------------
       
   360 //
       
   361 void CIAUpdateFwNode::SetContentUrlL()
       
   362     {
       
   363     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::SetContentUrlL() begin");
       
   364 
       
   365     // Before trying to set the new values for content URL,
       
   366     // delete old values.
       
   367     delete iContentUrl;
       
   368     iContentUrl = NULL;
       
   369 
       
   370     CNcdPurchaseDetails* details( PurchaseDetailsLC() );
       
   371 
       
   372     TArray< MNcdPurchaseDownloadInfo* > downloadInfos( 
       
   373         details->DownloadInfoL() );
       
   374     if ( downloadInfos.Count() == 0 )
       
   375         {
       
   376         IAUPDATE_TRACE("[IAUPDATE] ERROR: KErrNotFound, no download info");
       
   377         User::Leave( KErrNotFound );
       
   378         }
       
   379     else
       
   380         {
       
   381         IAUPDATE_TRACE_1("[IAUPDATE] Download info count: %d", 
       
   382                          downloadInfos.Count());
       
   383         // Always use the first download info even if there exists
       
   384         // multiple of them.
       
   385         MNcdPurchaseDownloadInfo* info( downloadInfos[ 0 ] );
       
   386         // Get the content uri and insert it to the member variable.
       
   387         iContentUrl = info->ContentUri().AllocL();
       
   388         IAUPDATE_TRACE_1("[IAUPDATE] Content uri set: %S",
       
   389                          iContentUrl); 
       
   390         }    
       
   391 
       
   392     CleanupStack::PopAndDestroy( details );
       
   393 
       
   394     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::SetContentUrlL() end");
       
   395     }
       
   396 
       
   397 // ---------------------------------------------------------------------------
       
   398 // CIAUpdateFwNode::SetNameL
       
   399 // 
       
   400 // ---------------------------------------------------------------------------
       
   401 //
       
   402 void CIAUpdateFwNode::SetNameL( const MNcdNodeMetadata& /*aMetaData*/ )
       
   403     {
       
   404     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::SetNameL() begin");
       
   405     RTelServer telServer;
       
   406     CleanupClosePushL( telServer );
       
   407     User::LeaveIfError( telServer.Connect() );
       
   408     RTelServer::TPhoneInfo teleinfo;
       
   409     User::LeaveIfError( telServer.GetPhoneInfo( 0, teleinfo ) );
       
   410     RMobilePhone phone;
       
   411     CleanupClosePushL( phone );
       
   412     User::LeaveIfError( phone.Open( telServer, teleinfo.iName ) );
       
   413     User::LeaveIfError(phone.Initialise()); 
       
   414     TUint32 teleidentityCaps;
       
   415     phone.GetIdentityCaps( teleidentityCaps );
       
   416     RMobilePhone::TMobilePhoneIdentityV1 telid;
       
   417     TRequestStatus status;
       
   418     phone.GetPhoneId( status, telid );
       
   419     User::WaitForRequest( status );
       
   420     delete iName;
       
   421     iName = NULL;
       
   422     if ( status==KErrNone )
       
   423         {
       
   424         iName = telid.iModel.AllocL(); 
       
   425         }
       
   426     else
       
   427         {
       
   428         iName = KNullDesC().AllocL();
       
   429         }
       
   430     CleanupStack::PopAndDestroy( &phone );
       
   431     CleanupStack::PopAndDestroy( &telServer );
       
   432      
       
   433     IAUPDATE_TRACE("[IAUPDATE] CIAUpdateFwNode::SetNameL() end");
       
   434     }