homesync/contentmanager/cmserver/cmfillmanager/src/cmfmdownloadmngr.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     2 * Copyright (c) 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:  Download manager class, handles file download events
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpavcontroller.h"
       
    20 #include "upnpfiledownloadsession.h"
       
    21 #include "cmfmtransferobserver.h"
       
    22 #include "cmfmdownloadmngr.h"
       
    23 #include "msdebug.h"
       
    24 
       
    25 // ---------------------------------------------------------------------------
       
    26 // CCmFmDownloadMngr::NewL
       
    27 // ---------------------------------------------------------------------------
       
    28 //
       
    29 CCmFmDownloadMngr* CCmFmDownloadMngr::NewL( MUPnPAVController* aAVController, 
       
    30     MCmFmTransferObserver* aObserver, const CUpnpAVDevice& aDevice,
       
    31     const TInt aDownloadId )
       
    32     {
       
    33     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::NewL() start"));    
       
    34     CCmFmDownloadMngr* self = CCmFmDownloadMngr::NewLC( aAVController, 
       
    35         aObserver, aDevice, aDownloadId );
       
    36     CleanupStack::Pop( self );
       
    37     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::NewL() end"));
       
    38     return self;
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CCmFmDownloadMngr::NewLC
       
    43 // ---------------------------------------------------------------------------
       
    44 //   
       
    45 CCmFmDownloadMngr* CCmFmDownloadMngr::NewLC( MUPnPAVController* aAVController, 
       
    46     MCmFmTransferObserver* aObserver, const CUpnpAVDevice& aDevice,
       
    47     const TInt aDownloadId )
       
    48     {
       
    49     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::NewLC() start"));    
       
    50     CCmFmDownloadMngr* self = 
       
    51         new ( ELeave ) CCmFmDownloadMngr( aAVController, 
       
    52             aObserver, aDownloadId );
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL( aDevice );
       
    55     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::NewLC() end"));
       
    56     return self;  
       
    57     }    
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CCmFmDownloadMngr::~CCmFmDownloadMngr
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CCmFmDownloadMngr::~CCmFmDownloadMngr()
       
    64     {
       
    65     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::~CCmFmDownloadMngr()"));
       
    66     CancelOperation();
       
    67     }
       
    68 
       
    69 // ---------------------------------------------------------------------------
       
    70 // CCmFmDownloadMngr::CCmFmDownloadMngr
       
    71 // ---------------------------------------------------------------------------
       
    72 //        
       
    73 CCmFmDownloadMngr::CCmFmDownloadMngr( MUPnPAVController* aAVController, 
       
    74     MCmFmTransferObserver* aObserver, const TInt aDownloadId )
       
    75     : iAVController( aAVController ), iObserver( aObserver ), 
       
    76       iDownloadId( aDownloadId ) 
       
    77       
       
    78     {
       
    79     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::CCmFmDownloadMngr()"));
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CCmFmDownloadMngr::ConstructL
       
    84 // ---------------------------------------------------------------------------
       
    85 // 
       
    86 void CCmFmDownloadMngr::ConstructL( const CUpnpAVDevice& aDevice )
       
    87     {
       
    88     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::ConstructL()"));
       
    89     
       
    90     iDownloadSession = &( iAVController->
       
    91             StartDownloadSessionL( aDevice ) );
       
    92     iDownloadSession->SetObserver( *this );
       
    93     }    
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CCmFmDownloadMngr::FetchFileL
       
    97 // ---------------------------------------------------------------------------
       
    98 //  
       
    99 void CCmFmDownloadMngr::FetchFileL( const CUpnpElement& aResElement, 
       
   100     const CUpnpItem& aItem, RFile& aFile, const TInt64 aInternalItemId )
       
   101     {
       
   102     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::FetchFileL()"));
       
   103     
       
   104     iDownloadSession->StartDownloadL( aResElement, aItem, 
       
   105         aFile, aInternalItemId );
       
   106     iDownloadSession->StartTrackingProgressL( aInternalItemId );                    
       
   107     iFileSize = 0;            
       
   108     }
       
   109 
       
   110 // ---------------------------------------------------------------------------
       
   111 // CCmFmDownloadMngr::CancelOperation
       
   112 // ---------------------------------------------------------------------------
       
   113 //     
       
   114 void CCmFmDownloadMngr::CancelOperation()
       
   115     {
       
   116     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::CancelOperation() start"));
       
   117     if( iAVController )
       
   118         {
       
   119         if( iDownloadSession )
       
   120             {
       
   121             iAVController->StopDownloadSession( *iDownloadSession );
       
   122             }
       
   123         }
       
   124     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::CancelOperation() end"));                
       
   125     }                
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CCmFmDownloadMngr::TransferStarted
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CCmFmDownloadMngr::TransferStarted( TInt aKey, TInt aStatus )
       
   132     {
       
   133     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::TransferStarted()"));
       
   134     iObserver->TransferStatus( ECmFmFileFetchStarted, iDownloadId, aKey, 
       
   135         aStatus, iFileSize );       
       
   136     }
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // CCmFmDownloadMngr::TransferCompleted
       
   140 // ---------------------------------------------------------------------------
       
   141 //
       
   142 void CCmFmDownloadMngr::TransferCompleted( TInt aKey, TInt aStatus,
       
   143         const TDesC& /*aFilePath*/ )
       
   144     {
       
   145     LOG(_L("[FILL MNGR]\t CCmFmDownloadMngr::TransferCompleted()"));
       
   146     iObserver->TransferStatus( ECmFmFileFetched, iDownloadId, aKey, aStatus, 
       
   147         iFileSize );           
       
   148     }
       
   149 
       
   150 // ---------------------------------------------------------------------------
       
   151 // CCmFmDownloadMngr::TransferProgress
       
   152 // ---------------------------------------------------------------------------
       
   153 //
       
   154 void CCmFmDownloadMngr::TransferProgress( TInt /*aKey*/, TInt aBytes,
       
   155         TInt /*aTotalBytes*/ )              
       
   156     {
       
   157     TRACE(Print(_L("[FILL MNGR]\t aBytes= %d"), aBytes ));
       
   158 
       
   159 	// Get the transferred bytes
       
   160     iFileSize = ( aBytes / KKilo );
       
   161     } 
       
   162 
       
   163 // ---------------------------------------------------------------------------
       
   164 // CCmFmDownloadMngr::MediaServerDisappeared
       
   165 // ---------------------------------------------------------------------------
       
   166 //
       
   167 void CCmFmDownloadMngr::MediaServerDisappeared( 
       
   168     TUPnPDeviceDisconnectedReason /*aReason*/ )
       
   169     {
       
   170     TRACE(Print(_L("[FILL MNGR]\t MediaServerDisappeared = %d"), iDownloadId ));
       
   171     iObserver->TransferStatus( ECmFmFileFetched, iDownloadId, KErrNone, 
       
   172         KErrDisconnected, KErrNone );
       
   173     }
       
   174     
       
   175 // End of file
       
   176 
       
   177