homesync/contentmanager/cmserver/cmfillmanager/src/cmfmdownloadproxy.cpp
branchIOP_Improvements
changeset 40 08b5eae9f9ff
parent 39 6369bfd1b60d
child 41 b4d83ea1d6e2
equal deleted inserted replaced
39:6369bfd1b60d 40:08b5eae9f9ff
     1 /*
       
     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:  Proxy class to handle multiple download sessions
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "upnpavcontroller.h"
       
    20 #include "upnpavdevicelist.h"
       
    21 #include "upnpitem.h"
       
    22 #include "cmfmdownloadmngr.h"
       
    23 #include "cmfmdownloadproxy.h"
       
    24 #include "msdebug.h"
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // CCmFmDownloadProxy::NewL
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 CCmFmDownloadProxy* CCmFmDownloadProxy::NewL( )
       
    31     {
       
    32     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::NewL() start"));    
       
    33     CCmFmDownloadProxy* self = CCmFmDownloadProxy::NewLC( );
       
    34     CleanupStack::Pop( self );
       
    35     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::NewL() end"));
       
    36     return self;
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // CCmFmDownloadProxy::NewLC
       
    41 // ---------------------------------------------------------------------------
       
    42 //   
       
    43 CCmFmDownloadProxy* CCmFmDownloadProxy::NewLC( )
       
    44     {
       
    45     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::NewLC() start"));    
       
    46     CCmFmDownloadProxy* self = 
       
    47         new ( ELeave ) CCmFmDownloadProxy( );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL( );
       
    50     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::NewLC() end"));
       
    51     return self;  
       
    52     }    
       
    53 
       
    54 // ---------------------------------------------------------------------------
       
    55 // CCmFmDownloadProxy::~CCmFmDownloadProxy
       
    56 // ---------------------------------------------------------------------------
       
    57 //
       
    58 CCmFmDownloadProxy::~CCmFmDownloadProxy()
       
    59     {
       
    60     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::~CCmFmDownloadProxy()"));
       
    61     CancelOperation();
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // CCmFmDownloadProxy::CCmFmDownloadProxy
       
    66 // ---------------------------------------------------------------------------
       
    67 //        
       
    68 CCmFmDownloadProxy::CCmFmDownloadProxy( )
       
    69     {
       
    70     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::CCmFmDownloadProxy()"));
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CCmFmDownloadProxy::ConstructL
       
    75 // ---------------------------------------------------------------------------
       
    76 // 
       
    77 void CCmFmDownloadProxy::ConstructL()
       
    78     {
       
    79     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::ConstructL()"));
       
    80     }          
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CCmFmDownloadProxy::FetchFileL
       
    84 // ---------------------------------------------------------------------------
       
    85 //  
       
    86 void CCmFmDownloadProxy::FetchFileL( MCmFmTransferObserver* aObserver, 
       
    87     MUPnPAVController* aAVController, CUpnpAVDeviceList* aDevices, 
       
    88     const CUpnpElement& aResElement, const CUpnpItem& aItem, RFile& aFile, 
       
    89     const TInt aInternalDeviceIndex, const TInt64 aInternalItemId )
       
    90     {
       
    91     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::FetchFileL()"));
       
    92     
       
    93     // Starts download session if no session for defined device exists yet
       
    94     TInt index = StartNewDownloadSessionIfNeededL( aObserver, 
       
    95                                                    aAVController, 
       
    96                                                    aDevices, 
       
    97                                                    aInternalDeviceIndex );
       
    98         
       
    99     if( index > KErrNotFound && index < iDownloadSessions.Count() )
       
   100         {
       
   101         TRACE(Print(_L("[FILL MNGR]\t FetchFileL index = %d"), index ));
       
   102         iDownloadSessions[ index ]->
       
   103                 FetchFileL( aResElement, aItem, aFile, aInternalItemId );   
       
   104         }
       
   105     else
       
   106         {
       
   107         User::Leave( KErrNotFound );
       
   108         } 
       
   109     }
       
   110 
       
   111 // ---------------------------------------------------------------------------
       
   112 // CCmFmDownloadProxy::CloseDownloadSession
       
   113 // ---------------------------------------------------------------------------
       
   114 //
       
   115 TBool CCmFmDownloadProxy::CloseDownloadSession( const TInt aSessionId )
       
   116     {
       
   117     TRACE(Print(_L("[FILL MNGR]\t CloseDownloadSession = %d"), aSessionId ));
       
   118     TBool sessionsLeft( EFalse );
       
   119     
       
   120     if( KErrNotFound < aSessionId && 
       
   121         aSessionId < iDownloadSessions.Count() && 
       
   122         iDownloadSessions[ aSessionId ] )
       
   123         {
       
   124         // Delete defined download session
       
   125         delete iDownloadSessions[ aSessionId ];
       
   126         iDownloadSessions[ aSessionId ] = NULL;
       
   127         iDownloadSessionCount--;
       
   128         TInt temp( KErrNotFound );
       
   129         for( TInt i = 0; i < iSessionIndexes.Count(); i++ )
       
   130             {
       
   131             if( iSessionIndexes[i].iSessionIndex == aSessionId )
       
   132                 {
       
   133                 temp = i; 
       
   134                 }
       
   135             }
       
   136     
       
   137         if( temp != KErrNotFound )
       
   138             {
       
   139             iSessionIndexes.Remove( temp );
       
   140             }        
       
   141         }
       
   142     
       
   143     if( iDownloadSessionCount )
       
   144         {
       
   145         sessionsLeft = ETrue;
       
   146         }
       
   147     else
       
   148         {
       
   149         LOG(_L("[FILL MNGR]\t No sessions left!"));
       
   150         }
       
   151     
       
   152     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::CloseDownloadSession() end"));        
       
   153     return sessionsLeft;    
       
   154     }
       
   155     
       
   156 // ---------------------------------------------------------------------------
       
   157 // CCmFmDownloadProxy::CancelOperation
       
   158 // ---------------------------------------------------------------------------
       
   159 //     
       
   160 void CCmFmDownloadProxy::CancelOperation()
       
   161     {
       
   162     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::CancelOperation()"));
       
   163     iDownloadSessions.ResetAndDestroy();
       
   164     iSessionIndexes.Reset();
       
   165     iSessionIndexes.Close();
       
   166     iDownloadSessionCount  = 0;                
       
   167     }
       
   168                     
       
   169 // ---------------------------------------------------------------------------
       
   170 // CCmFmDownloadProxy::StartNewDownloadSessionIfNeededL
       
   171 // ---------------------------------------------------------------------------
       
   172 // 
       
   173 TInt CCmFmDownloadProxy::StartNewDownloadSessionIfNeededL( 
       
   174     MCmFmTransferObserver* aObserver, MUPnPAVController* aAVController, 
       
   175     CUpnpAVDeviceList* aDevices, const TInt aInternalDeviceIndex )
       
   176     {
       
   177     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::\
       
   178     StartNewDownloadSessionIfNeededL()"));
       
   179     
       
   180     TBool newServer( ETrue );
       
   181     TInt sessionIndex( KErrNotFound );
       
   182     for( TInt i = 0; i < iSessionIndexes.Count(); i++ )
       
   183         {
       
   184         if( iSessionIndexes[i].iDeviceIndex == aInternalDeviceIndex )
       
   185             {
       
   186             TRACE(Print(_L("[FILL MNGR]\t old server sessionIndex = %d"), 
       
   187                 i ));
       
   188             newServer = EFalse;
       
   189             sessionIndex = i;
       
   190             // Index found => end loop
       
   191             i = iSessionIndexes.Count();
       
   192             }
       
   193         }
       
   194     
       
   195     if( newServer )
       
   196         {
       
   197         TRACE(Print(_L("[FILL MNGR]\t New server found")));       
       
   198 
       
   199         CreateNewSessionL( aObserver, aAVController, aDevices, 
       
   200             iDownloadSessionCount, sessionIndex );              
       
   201         }
       
   202     TRACE(Print(_L("[FILL MNGR]\t started sessionIndex = %d"), sessionIndex ));        
       
   203     
       
   204     return sessionIndex;              
       
   205     }
       
   206 
       
   207 // ---------------------------------------------------------------------------
       
   208 // CCmFmDownloadProxy::CreateNewSessionL
       
   209 // ---------------------------------------------------------------------------
       
   210 // 
       
   211 void CCmFmDownloadProxy::CreateNewSessionL(  
       
   212     MCmFmTransferObserver* aObserver, MUPnPAVController* aAVController, 
       
   213     CUpnpAVDeviceList* aDevices, TInt aSessionCount, TInt& aSessionIndex )
       
   214     {
       
   215     LOG(_L("[FILL MNGR]\t CCmFmDownloadProxy::CreateNewSessionL()"));
       
   216     
       
   217     CCmFmDownloadMngr* mngr = CCmFmDownloadMngr::NewL( aAVController, aObserver,
       
   218        *(*aDevices)[aSessionCount], aSessionCount );
       
   219     CleanupStack::PushL( mngr );
       
   220     iDownloadSessions.AppendL( mngr );            
       
   221     CleanupStack::Pop( mngr );
       
   222     iDownloadSessionCount++;             
       
   223     TCmFmDownloadSessionIndexes index;
       
   224     index.iDeviceIndex = aSessionCount;   
       
   225     index.iSessionIndex = ( iDownloadSessions.Count() - 1 );
       
   226     iSessionIndexes.AppendL( index );
       
   227     aSessionIndex = index.iSessionIndex;     
       
   228     }
       
   229      
       
   230 // End of file
       
   231