ncdengine/provider/server/inc/ncdcontentdownloadoperation.h
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef C_NCDCONTENTDOWNLOADOPERATION_H
       
    20 #define C_NCDCONTENTDOWNLOADOPERATION_H
       
    21 
       
    22 #include "ncdbaseoperation.h"
       
    23 #include "ncdoperationdatatypes.h"
       
    24 #include "ncddownloadoperationstates.h"
       
    25 #include "ncdoperationobserver.h"
       
    26 #include "ncdstoragedataitem.h"
       
    27 #include "ncddownloadreportobserver.h"
       
    28 #include "catalogshttpincludes.h"
       
    29 
       
    30 class MCatalogsHttpSession;
       
    31 class CNcdNodeManager;
       
    32 class MNcdStorageClient;
       
    33 class CNcdNodeIdentifier;
       
    34 class MNcdSessionHandler;
       
    35 class MNcdConfigurationManager;
       
    36 class MCatalogsContext;
       
    37 class MNcdOperationRemoveHandler;
       
    38 class MCatalogsHttpHeaders;
       
    39 class MNcdDatabaseStorage;
       
    40 class MCatalogsAccessPointManager;
       
    41 class CNcdNode;
       
    42 class CNcdNodeDownload;
       
    43 class CNcdDownloadSubOperation;
       
    44 class CNcdDescriptorDownloadSubOperation;
       
    45 class CNcdContentDescriptor;
       
    46 class CNcdSendNotificationSubOperation;
       
    47 class CNcdPurchaseDetails;
       
    48 class CNcdGeneralManager;
       
    49 
       
    50 /** 
       
    51  * Content download operation
       
    52  * 
       
    53  */
       
    54 class CNcdContentDownloadOperation : public CNcdBaseOperation,
       
    55     public MNcdStorageDataItem
       
    56     {
       
    57 public:
       
    58     
       
    59     /**
       
    60      * NewL
       
    61      *
       
    62      * @param aHttpSession HTTP session used for creating download operations
       
    63      *
       
    64      * @note Preferably the HTTP session has suitable defaults but if not then
       
    65      * Config() can be used to retrieve and change the settings for the 
       
    66      * download.
       
    67      * @note At least the target directory and access point must be set to the 
       
    68      * configuration.
       
    69      */
       
    70     static CNcdContentDownloadOperation* NewL( 
       
    71         MNcdOperationRemoveHandler& aRemoveHandler,
       
    72         const CNcdNodeIdentifier& aNodeId,
       
    73         CNcdGeneralManager& aGeneralManager,
       
    74         MCatalogsHttpSession& aHttpSession,
       
    75         MNcdDownloadReportObserver& aReportObserver,
       
    76         MNcdSessionHandler* aSessionHandler,
       
    77         MNcdDatabaseStorage& aDownloadStorage,
       
    78         MCatalogsSession& aSession,
       
    79         TInt aDownloadIndex );
       
    80 
       
    81     /**
       
    82      * NewL
       
    83      *
       
    84      * Internalizes the download from the stream
       
    85      */     
       
    86     static CNcdContentDownloadOperation* NewLC( 
       
    87         MNcdOperationRemoveHandler& aRemoveHandler,
       
    88         CNcdGeneralManager& aGeneralManager,
       
    89         MCatalogsHttpSession& aHttpSession,
       
    90         MNcdDownloadReportObserver& aReportObserver,
       
    91         MNcdDatabaseStorage& aDownloadStorage,
       
    92         MCatalogsSession& aSession );
       
    93 
       
    94     
       
    95     /**
       
    96      * Destructor
       
    97      */
       
    98     ~CNcdContentDownloadOperation();
       
    99         
       
   100     
       
   101 public: // From CNcdBaseOperation
       
   102 
       
   103     /**
       
   104      * @see CNcdBaseOperation::Cancel()
       
   105      */
       
   106     void Cancel();    
       
   107     
       
   108     
       
   109     /**
       
   110      * @see CNcdBaseOperation::ReceiveMessage()
       
   111      */
       
   112     void ReceiveMessage( 
       
   113         MCatalogsBaseMessage* aMessage,
       
   114         TInt aFunctionNumber );    
       
   115 
       
   116 
       
   117     /**
       
   118      * @see CNcdBaseOperation::CounterPartLost()
       
   119      */
       
   120     void CounterPartLost( const MCatalogsSession& aSession );
       
   121 
       
   122 public: // From MNcdStorageDataItem
       
   123 
       
   124     /**
       
   125      * @see MNcdStorageDataItem::ExternalizeL()
       
   126      */
       
   127     void ExternalizeL( RWriteStream& aStream );
       
   128 
       
   129 
       
   130     /**
       
   131      * @see MNcdStorageDataItem::InternalizeL()
       
   132      */
       
   133     void InternalizeL( RReadStream& aStream );
       
   134 
       
   135 
       
   136 public: // New methods
       
   137 
       
   138     TBool MatchDownload( const CNcdNodeIdentifier& aId, 
       
   139         TNcdDownloadDataType& aType, TInt aIndex ) const;
       
   140 
       
   141 
       
   142     /**
       
   143      * Node id getter
       
   144      *
       
   145      * @return Node id of the node used by the operation
       
   146      */
       
   147     const CNcdNodeIdentifier& NodeId() const;
       
   148     
       
   149     /**
       
   150      * Metadata id getter
       
   151      *
       
   152      * @return Metadata id of the node used by the operation
       
   153      */     
       
   154     const CNcdNodeIdentifier& MetadataId() const;
       
   155     
       
   156     /**     
       
   157      */
       
   158     TBool IsOk() const;
       
   159     
       
   160     TInt CurrentDownload() const;
       
   161     
       
   162 
       
   163 protected: // From MNcdOperationObserver
       
   164 
       
   165     /**
       
   166      * @see MNcdOperationObserver::Progress()
       
   167      */
       
   168     void Progress( CNcdBaseOperation& aOperation );
       
   169     
       
   170     /**
       
   171      * @see MNcdOperationObserver::QueryReceived()
       
   172      */
       
   173     void QueryReceived( CNcdBaseOperation& aOperation,
       
   174                                 CNcdQuery* aQuery );
       
   175 
       
   176     /**
       
   177      * @see MNcdOperationObserver::OperationComplete()
       
   178      */
       
   179     void OperationComplete( CNcdBaseOperation* aOperation,
       
   180                                     TInt aError );
       
   181 
       
   182 
       
   183 protected: // From CNcdBaseOperation
       
   184 
       
   185     /**
       
   186      * @see CNcdBaseOperation::RunOperation()
       
   187      */
       
   188     TInt RunOperation();        
       
   189     
       
   190 
       
   191     /**
       
   192      * @see CNcdBaseOperation::Initialize()
       
   193      */    
       
   194     TInt Initialize();
       
   195     
       
   196 
       
   197 protected:
       
   198    
       
   199 
       
   200     // Constructor
       
   201     CNcdContentDownloadOperation( 
       
   202         MNcdOperationRemoveHandler& aRemoveHandler,
       
   203         CNcdGeneralManager& aGeneralManager, 
       
   204         MCatalogsHttpSession& aHttpSession, 
       
   205         MNcdDownloadReportObserver& aReportObserver,
       
   206         MNcdSessionHandler* aSessionHandler,
       
   207         MCatalogsSession& aSession,
       
   208         MNcdDatabaseStorage& aDownloadStorage );
       
   209         
       
   210     void ConstructL( const CNcdNodeIdentifier& aNodeId, 
       
   211         TInt aDownloadIndex );
       
   212 
       
   213     void ConstructL();
       
   214 
       
   215 private: // enumerations
       
   216 
       
   217     enum TContentDownloadState
       
   218         {
       
   219         ENoDownload,
       
   220         ERightsDownload,
       
   221         EEmbeddedDescriptor,        
       
   222         EDescriptorDownload,
       
   223         EContentDownload,          
       
   224         EDownloadDone    
       
   225         };
       
   226         
       
   227     enum TDescriptorType
       
   228         {
       
   229         EDescriptorUnknown,
       
   230         EDescriptorDd,
       
   231         EDescriptorJad
       
   232         };
       
   233     
       
   234 private:
       
   235 
       
   236     // Does the actual operation initialization
       
   237     void DoInitializationL();
       
   238 
       
   239     void FinishDescriptorDownloadL();
       
   240 
       
   241     /** Initializes the download in the given index (or in the next
       
   242      *  index that needs to be downloaded)
       
   243      *  @throw KNoDownloads if there are no downloads that need to be 
       
   244      *  downloaded
       
   245      */
       
   246     void InitializeDownloadL( TInt aIndex );
       
   247     
       
   248     void StartDownloadL();
       
   249 
       
   250     TBool FinishDownloadL();
       
   251 
       
   252     void UpdatePurchaseHistoryL( 
       
   253         const TDesC& aDownloadedFile );
       
   254 
       
   255     // Updates skipped downloads to purchase history
       
   256     void UpdateSkippedDownloadToPurchaseHistoryL( TInt aIndex );
       
   257 
       
   258 
       
   259     // Update the download request headers
       
   260     void UpdateHeadersL( MCatalogsHttpHeaders& aHeaders );
       
   261     
       
   262     
       
   263     void ReleaseDownload( CNcdBaseOperation* aOperation );
       
   264 
       
   265 
       
   266     void HandleDescriptorL( 
       
   267         const TDesC& aDescriptorType, const TDesC8& aDescriptor );
       
   268 
       
   269     // Checks if the download is a dependency/upgrade and whether
       
   270     // it is currently installed or not
       
   271     TBool IsFileInstalledL( TInt aIndex, TBool aCheckOnly );
       
   272     
       
   273     TBool SkipInstalledFilesL();
       
   274     
       
   275     TInt CalculateMissingFilesL();
       
   276     
       
   277     void SaveStateL();
       
   278     
       
   279     void GenerateStorageUidL();
       
   280     
       
   281     void RemoveTempInfoL();
       
   282     
       
   283     TDescriptorType MatchDescriptor( const TDesC& aMimeType ) const;
       
   284     
       
   285     CNcdPurchaseDetails* GetPurchaseDetailsLC();
       
   286     
       
   287     void UpdateAccessPointsL( 
       
   288         const CNcdNodeIdentifier& aNodeId );
       
   289 
       
   290     void ReportStatusL( 
       
   291         const TNcdReportStatusInfo& aStatus,
       
   292         TBool aSendable = ETrue );
       
   293     
       
   294     void SendOmaNotificationL( const TNcdReportStatusInfo& aStatus );
       
   295     
       
   296     // Updates dependencies from CNcdNodeDependency to purchase history
       
   297     // so that they are up-to-date
       
   298     void UpdateDependenciesL();
       
   299         
       
   300     void GetPausableStateL( MCatalogsBaseMessage& aMessage );
       
   301 
       
   302     // Registers a download to report manager for download reporting
       
   303     void RegisterDownloadL(
       
   304         const TDesC& aUri,
       
   305         const CNcdNodeIdentifier& aIdentifier );
       
   306     
       
   307 private:
       
   308 
       
   309     MCatalogsHttpSession& iHttpSession;
       
   310     MNcdDownloadReportObserver& iReportObserver;
       
   311     MNcdSessionHandler* iSessionHandler;
       
   312     MNcdConfigurationManager& iConfigurationManager;
       
   313     MCatalogsAccessPointManager& iAccessPointManager;
       
   314     MNcdDatabaseStorage& iStorage;
       
   315     CNcdNode* iNode;
       
   316     
       
   317     const MCatalogsContext& iContext;
       
   318     
       
   319     TNcdDownloadState iDownloadState;    
       
   320     HBufC* iSessionId;
       
   321     
       
   322 
       
   323     CNcdDownloadSubOperation* iDownload;
       
   324     CNcdDescriptorDownloadSubOperation* iDescriptorDownload;
       
   325     
       
   326     CNcdNodeDownload* iNodeDownload;
       
   327     
       
   328     // Access point used for content downloads
       
   329     TCatalogsConnectionMethod iApId;
       
   330     TCatalogsConnectionMethod iReportAp;
       
   331     
       
   332     TInt iDownloadIndex;   
       
   333     
       
   334     HBufC* iMimeType;
       
   335     TBool iMimeUpdated;
       
   336     
       
   337     TBool iStartNextFile;
       
   338     TContentDownloadState iContentDownloadState;
       
   339     HBufC8* iDescriptor;
       
   340     TBool iDeleting;
       
   341     CNcdContentDescriptor* iContentDescriptor;
       
   342     
       
   343     TPtrC iContentUri;    
       
   344     TPtrC iContentMime;
       
   345     HBufC* iContentFilename;
       
   346     TPtrC iNotificationUri;
       
   347    
       
   348     TDescriptorType iDownloadType;
       
   349     
       
   350     // ETrue if the operation was created successfully
       
   351     // This is used to circumvent the cumbersome 
       
   352     // storage error handling
       
   353     TBool iIsOk; 
       
   354     TBool iUnhandledEvent;
       
   355     HBufC* iStorageUid;
       
   356     TNcdReportId iReportId;
       
   357     TBool iDependenciesUpdated;
       
   358     TInt iTotalFileCount;
       
   359     TInt iCurrentFile;
       
   360     };
       
   361 
       
   362 #endif // C_NCDCONTENTDOWNLOADOPERATION_H