upnp/upnpstack/upnphttptransfer/src/httpdownloader.cpp
changeset 0 f5a58ecadc66
equal deleted inserted replaced
-1:000000000000 0:f5a58ecadc66
       
     1 /** @file
       
     2 * Copyright (c) 2007 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:  Handles downloads
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System include files
       
    20 #include <es_sock.h>
       
    21 
       
    22 // User include files
       
    23 #include "httpdownloader.h"
       
    24 #include "httpdownloadworker.h"
       
    25 #include "httptransferbase.h"
       
    26 #include "httptransferobserver.h"
       
    27 #include "httpworkerobserver.h"
       
    28 
       
    29 // Constants
       
    30 const TUint KMaxParallelTransfers = 5;
       
    31 
       
    32 // ======== MEMBER FUNCTIONS ========
       
    33 
       
    34 // --------------------------------------------------------------------------
       
    35 // CHttpDownloader::CHttpDownloader()
       
    36 // --------------------------------------------------------------------------
       
    37 //
       
    38 CHttpDownloader::CHttpDownloader( 
       
    39                        MHttpTransferObserver& aObserver,
       
    40                        TUint aIAPId,
       
    41                        TUint aBufferSize,
       
    42                        TUint aParallelTransfers = KDefaultParallelTransfers )
       
    43     {
       
    44     iObserver = &aObserver;
       
    45     iIAPId = aIAPId;
       
    46     iBufferSize = aBufferSize;
       
    47 
       
    48     if ( aParallelTransfers <= 0 )
       
    49         {
       
    50         iParallelTransfers = KDefaultParallelTransfers;
       
    51         }
       
    52     else if ( aParallelTransfers > KMaxParallelTransfers )
       
    53         {
       
    54         iParallelTransfers = KMaxParallelTransfers;
       
    55         }
       
    56     else
       
    57         {
       
    58         iParallelTransfers = aParallelTransfers;
       
    59         }
       
    60     }
       
    61 
       
    62 // --------------------------------------------------------------------------
       
    63 // CHttpDownloader::ConstructL()
       
    64 // (See comments in header file)
       
    65 // --------------------------------------------------------------------------
       
    66 //
       
    67 void CHttpDownloader::ConstructL()
       
    68     {
       
    69     
       
    70     for ( TInt i=0; i < iParallelTransfers; i++ )
       
    71         {
       
    72         iWorkerArray.Append( CHttpDownloadWorker::NewL( *iObserver,
       
    73                                                         iIAPId,
       
    74                                                         iBufferSize,
       
    75                                                         *this ) );
       
    76         }
       
    77 
       
    78     }
       
    79 
       
    80 // --------------------------------------------------------------------------
       
    81 // CHttpDownloader::NewL()
       
    82 // (See comments in header file)
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C CHttpDownloader* CHttpDownloader::NewL( 
       
    86                                         MHttpTransferObserver& aObserver,
       
    87                                         TUint aIAPId,
       
    88                                         TUint aBufferSize,
       
    89                                         TUint aParallelTransfers )
       
    90     {
       
    91     CHttpDownloader* self = CHttpDownloader::NewLC( aObserver, 
       
    92                                                     aIAPId, 
       
    93                                                     aBufferSize,
       
    94                                                     aParallelTransfers );
       
    95     CleanupStack::Pop( self );
       
    96     return self;
       
    97     }
       
    98 
       
    99 // --------------------------------------------------------------------------
       
   100 // CHttpDownloader::NewLC()
       
   101 // (See comments in header file)
       
   102 // --------------------------------------------------------------------------
       
   103 //
       
   104 EXPORT_C CHttpDownloader* CHttpDownloader::NewLC( 
       
   105                                          MHttpTransferObserver& aObserver,
       
   106                                          TUint aIAPId,
       
   107                                          TUint aBufferSize,
       
   108                                          TUint aParallelTransfers )
       
   109 
       
   110     {
       
   111     CHttpDownloader* self = 
       
   112                 new( ELeave ) CHttpDownloader( aObserver, 
       
   113                                                aIAPId,
       
   114                                                aBufferSize,
       
   115                                                aParallelTransfers );
       
   116     CleanupStack::PushL( self );
       
   117     self->ConstructL();
       
   118     return self;
       
   119     }
       
   120 
       
   121 // --------------------------------------------------------------------------
       
   122 // CHttpDownloader::~CHttpDownloader()
       
   123 // (See comments in header file)
       
   124 // --------------------------------------------------------------------------
       
   125 //
       
   126 CHttpDownloader::~CHttpDownloader()
       
   127     {
       
   128     }
       
   129 
       
   130 // --------------------------------------------------------------------------
       
   131 // CHttpDownloader::DownloadFileL
       
   132 // (See comments in header file)
       
   133 // --------------------------------------------------------------------------
       
   134 //
       
   135 EXPORT_C void CHttpDownloader::DownloadFileL( const TDesC8& aUri, 
       
   136                                               const TDesC& aTargetPath, 
       
   137                                               TAny* aKey )
       
   138     {
       
   139     // if aKey already exists -> leave
       
   140     for ( TInt i=0; i < iFileQueue.Count(); i++ )
       
   141         {
       
   142         if ( iFileQueue[i]->Key() == aKey )
       
   143             {
       
   144             User::Leave( KErrAlreadyExists );
       
   145             }
       
   146         }
       
   147 
       
   148     // Add new CHttpFile into the iFileQueue
       
   149     CreateAndQueueHttpFileL( aUri, aTargetPath, aKey );
       
   150 
       
   151     // Activate new request
       
   152     ActivateNewTransferRequest();
       
   153     }
       
   154 
       
   155 // --------------------------------------------------------------------------
       
   156 // CHttpDownloader::DownloadFileL
       
   157 // (See comments in header file)
       
   158 // --------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C void CHttpDownloader::DownloadFileL( const TDesC8& aUri, 
       
   161                                               const RFile& aFileHandle, 
       
   162                                               TAny* aKey )
       
   163     {
       
   164     // if aKey already exists -> leave
       
   165     for ( TInt i=0; i < iFileQueue.Count(); i++ )
       
   166         {
       
   167         if ( iFileQueue[i]->Key() == aKey )
       
   168             {
       
   169             User::Leave( KErrAlreadyExists );
       
   170             }
       
   171         }
       
   172 
       
   173     // Add new CHttpFile into the iFileQueue
       
   174     CreateAndQueueHttpFileL( aUri, aFileHandle, aKey );
       
   175 
       
   176     // Activate new request
       
   177     ActivateNewTransferRequest();
       
   178     }
       
   179 
       
   180 // end of file