ncdengine/engine/transport/src/catalogshttpdownloadmanagerimpl.cpp
branchRCL_3
changeset 66 8b7f4e561641
parent 65 7333d7932ef7
--- a/ncdengine/engine/transport/src/catalogshttpdownloadmanagerimpl.cpp	Tue Aug 31 15:21:33 2010 +0300
+++ b/ncdengine/engine/transport/src/catalogshttpdownloadmanagerimpl.cpp	Wed Sep 01 12:22:02 2010 +0100
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -32,11 +32,7 @@
 #include "catalogsconnection.h"
 
 #include "catalogsdebug.h"
-#include <QString>
-#include <QVector>
-#include <QList>
-#include <downloadevent.h>
-#include <xqconversions.h>
+
 // ======== MEMBER FUNCTIONS ========
 
 // ---------------------------------------------------------------------------
@@ -63,7 +59,6 @@
             
     DLTRACE(("constructor ok"));
     CleanupStack::PushL( self );
-   
     self->ConstructL( aCleanup );
     CleanupStack::Pop( self );
     return self;
@@ -78,7 +73,7 @@
     DLTRACEIN( ( "" ) );
 
     Cancel();
-    // HLa iEventQueue.Close();
+    iEventQueue.Close();
 
     // Release downloads
     TInt count = iDownloads.Count() - 1;
@@ -107,17 +102,15 @@
         iNetworkManager->RemoveObserver( *this );
         }
 
-
-    if ( iDmgr ) 
+    if ( iDmgr.Handle() ) 
         {
         DLTRACE(("We were connected to DL manager"));
         DeleteHangingDownloads();
         }
-      
+        
     // Close download manager session    
-    iDmgr->removeAll();
+    iDmgr.Close();
     
-   
     delete iDefaultConfig;
     iManager.Release();
     
@@ -131,20 +124,24 @@
     {
     DLTRACEIN((""));
     // This pauses all downloads in addition to disconnecting
- 	iDmgr->pauseAll(); 
-   TInt count = iDownloads.Count();
-    for ( TInt i = 0; i < count; ++i )
-        {
-         TInt32 deleteStatus = 0;
-         deleteStatus = dynamic_cast<CCatalogsHttpDownload*>(iDownloads[i])->GetStatusState();
-       
-         if ( deleteStatus == CCatalogsHttpDownload::EDownloadCanBeDeleted ) 
+    iDmgr.Disconnect();
+    const CDownloadArray& downloads( iDmgr.CurrentDownloads() );
+
+    TInt count = downloads.Count();
+    while( count-- )
+        {                         
+        RHttpDownload& dl = *( downloads[ count ] );
+        TInt32 deleteStatus = 0;
+        dl.GetIntAttribute( EDlAttrUserData, deleteStatus );
+        DLTRACE(("DeleteStatus: %d", deleteStatus ));
+        
+        if ( deleteStatus == CCatalogsHttpDownload::EDownloadCanBeDeleted ) 
             {
             DLTRACE(("Deleting download"));
-            iDmgr->removeOne(dynamic_cast<CCatalogsHttpDownload*>(iDownloads[i])->GetDownload());
+            dl.Delete();
             }
-        }        
         
+        }
     }
 
 // ---------------------------------------------------------------------------
@@ -175,18 +172,16 @@
     {
     DLTRACEIN((""));
     // Create a new download
-    QString Url = XQConversions::s60Desc8ToQString(aUrl);  
-    iDownload = iDmgr->createDownload( Url );
-    
     CCatalogsHttpDownload* dl = CCatalogsHttpDownload::NewLC( 
         *this,
         //download,
-        iDownload,
+        NULL,
         *iDefaultConfig );
     
     dl->SetUriL( aUrl );
     dl->SetFileServerSession( iFs );
-        // If the given observer != NULL, set it as the observer for the download
+    
+    // If the given observer != NULL, set it as the observer for the download
     if ( aObserver ) 
         {        
         dl->Config().SetObserver( aObserver );        
@@ -212,7 +207,6 @@
     TInt count = iDownloads.Count();
     for ( TInt i = 0; i < count; ++i )
         {
-        	
         if ( iDownloads[i]->OperationId() == aId ) 
             {
             return iDownloads[i];
@@ -402,19 +396,12 @@
     DLTRACEIN((""));
     if ( aMethod != iCurrentAp )
         {
-		try
-		{
         DLTRACE( ( "Set AP, type: %d, id: %u, apn: %d", 
             aMethod.iType, aMethod.iId, aMethod.iApnId ));
-		 iDmgr->pauseAll(); 
-		 
+        User::LeaveIfError( iDmgr.Disconnect() );    
+        User::LeaveIfError( iDmgr.SetIntAttribute( EDlMgrIap, aMethod.iApnId ) );
         iCurrentAp = aMethod;
         DLTRACE(("AP set"));
-		}
-		 catch(const std::exception& exception)
-		 {
-		 qt_symbian_exception2LeaveL(exception);
-		 }
         }    
     }
 
@@ -473,23 +460,40 @@
     {
     return iSessionId;
     }
-
+    
+    
 // ---------------------------------------------------------------------------
 // Handles download manager events
 // ---------------------------------------------------------------------------
-//    
- void CCatalogsHttpDownloadManager::downloadMgrEventRecieved(WRT::DownloadManagerEvent* dlmEvent)
-  {
-  	
-  	switch(dlmEvent ->type())
-		{
- 
-    default:
-    	break;
-		};
+//
+void CCatalogsHttpDownloadManager::HandleDMgrEventL( RHttpDownload& aDownload,
+	THttpDownloadEvent aEvent )
+    {
+    DLTRACEIN(( "Dl state: %i, pr: %i, DL: %x", aEvent.iDownloadState, 
+        aEvent.iProgressState, &aDownload ));
+        
+    TDownloadEvent event( aDownload, aEvent );
 
-  	
-  }  
+    if ( IsOneOf( aEvent.iDownloadState, EHttpDlDeleted, EHttpDlDeleting ) )
+        {
+        DLTRACEOUT(("Download was deleted"))
+        RemoveUnhandledEvents( event );
+        }
+    // Handle everything but Download name change events
+    else if ( aEvent.iProgressState != EHttpProgDlNameChanged )     
+        {        
+        DLTRACE(("Adding event to queue"));        
+        
+        if ( aEvent.iProgressState == EHttpProgResponseBodyReceived ) 
+            {
+            // Filter unhandled progress events from the queue
+            RemoveUnhandledProgressEvents( event );
+            }
+        
+        iEventQueue.AppendL( event );    
+        ContinueEventHandling();    
+        }
+    }
 
 
 // ---------------------------------------------------------------------------
@@ -503,19 +507,8 @@
     DLTRACEIN((""));
     if ( aEvent == ECatalogsAccessPointClosed ) 
         {
-		try
-		{
         DLTRACE(("Disconnecting download manager"));
-
-		iDmgr->pauseAll();
-	}
-
- 		catch(const std::exception& exception) 
-               { 
-               qt_symbian_exception2LeaveL(exception); 
-               } 
-            
-
+        User::LeaveIfError( iDmgr.Disconnect() );
         }
     }
 
@@ -563,11 +556,6 @@
     
     // shared so that RFiles can be given to Download manager
     User::LeaveIfError( iFs.ShareProtected() ); 
-   	
-   	QString DmgrUid(QString::number(KNCDEngineAppID));
-    iDmgr =  new DownloadManager(DmgrUid);
-    iDmgr->initialize();
-    iQTmgr = new CCatalogsHttpQTDownloadManager(this,iDmgr);
     
     TUid sessionId( TUid::Uid( iSessionId ) );
     if ( aCleanup ) 
@@ -593,6 +581,7 @@
     
     do    
         {
+        TRAP( err, iDmgr.ConnectL( sessionId, *this, ETrue ) );
         if ( err != KErrNone ) 
             {
             DLERROR(("DL manager connection failed with err: %d, retry attempts left", 
@@ -618,17 +607,13 @@
     iNetworkManager = &CCatalogsHttpSessionManager::NetworkManagerL();
     iNetworkManager->AddObserverL( *this );    
     
+    iDmgr.SetIntAttribute( EDlMgrExitAction, EExitPause );
     // Restore downloads from previous sessions
-//    RestoreDownloadsL();
- 
+    RestoreDownloadsL();
     DLTRACEOUT((""));
-
     }
     
-DownloadManager* CCatalogsHttpDownloadManager::GetDownloadManager()
-{
-	return iDmgr;
-}
+
 // ---------------------------------------------------------------------------
 // Restore downloads from previous session
 // ---------------------------------------------------------------------------
@@ -636,20 +621,17 @@
 void CCatalogsHttpDownloadManager::RestoreDownloadsL()
     {
     DLTRACEIN((""));
-    
-    const TInt KMaxUrlLength = 2048; // HLa
-    TBuf8<KMaxUrlLength> url;
+    const CDownloadArray& downloads = iDmgr.CurrentDownloads();    
     
+    TBuf8<KMaxUrlLength> url;
+    TBuf<KMaxPath> filename;
     
-    QList<WRT::Download*> downloads = iDmgr->currentDownloads();
-
-
     // Go through downloads, create wrappers for DL manager downloads and
     // add them to HttpDownloadManager
-    for ( TInt i = 0; i < downloads.size(); ++i ) 
+    for ( TInt i = 0; i < downloads.Count(); ++i ) 
         {                 
         DLTRACE(( "Restoring dl %i", i ));
-        WRT::Download *dlPtr = downloads[i];
+        RHttpDownload* dlPtr = downloads[i];
 
         // Create the download and push it to cleanup stack
         CCatalogsHttpDownload* dl = CCatalogsHttpDownload::NewLC( *this,
@@ -657,9 +639,8 @@
 
         // set file server session
         dl->SetFileServerSession( iFs );
-       
-         QString name   =  dlPtr->attribute(FileName).toString();
-         TBuf<KMaxPath> filename(name.utf16());
+        
+        dlPtr->GetStringAttribute( EDlAttrDestFilename, filename );
 
         // Separate the filename from the path
         TParsePtrC parser( filename );
@@ -694,8 +675,7 @@
 // ---------------------------------------------------------------------------
 // Finds the index for the given download in iDownloads
 // ---------------------------------------------------------------------------
-//   
-/* HLa
+//            
 TInt CCatalogsHttpDownloadManager::FindInDownloads( 
     const RCatalogsHttpOperationArray& aArray,
     RHttpDownload* aDownload ) const
@@ -703,7 +683,7 @@
     DASSERT( aDownload );
     
     TInt32 id = 0;
-    //aDownload->GetIntAttribute( EDlAttrId, id );    
+    aDownload->GetIntAttribute( EDlAttrId, id );    
             
     TInt count = aArray.Count();
     for ( TInt i = 0; i < count; ++i )
@@ -715,7 +695,7 @@
         }
     return KErrNotFound;
     }
-*/
+
 
 // ---------------------------------------------------------------------------
 // Finds the index for the given download in the given array
@@ -740,7 +720,7 @@
     {
     DLTRACEIN(( "" ));
     DASSERT( aOperation );
-    TInt err = iManager.StartOperation( aOperation, EFalse );
+    TInt err = iManager.StartOperation( aOperation );
     if ( err == KErrNone || err == KCatalogsHttpOperationQueued ) 
         {
         TInt err2 = MoveRestoredDlToCurrentDls( *aOperation );
@@ -837,7 +817,6 @@
     DLTRACEIN(( "Event queue count: %d", iEventQueue.Count() ));
    
     // Handle the event queue 
-    /* HLa
     while ( iEventQueue.Count() ) 
         {
         
@@ -899,7 +878,6 @@
                 }
             }
         }
-        */
     }
     
     
@@ -925,7 +903,6 @@
 void CCatalogsHttpDownloadManager::ContinueEventHandling()
     {
     DLTRACEIN((""));
-    /* HLa
     if( iEventQueue.Count() && !IsActive() ) 
         {
         DLTRACE(("More events to handle"));
@@ -934,11 +911,9 @@
         TRequestStatus* status = &iStatus;
         User::RequestComplete( status, KErrNone );
         }
-        */
     }
-
     
-    /* HLa
+    
 void CCatalogsHttpDownloadManager::RemoveUnhandledEvents( 
     const TDownloadEvent& aEvent )
     {
@@ -953,9 +928,8 @@
             }        
         }    
     }
-*/
 
-/* HLa
+
 void CCatalogsHttpDownloadManager::RemoveUnhandledProgressEvents( 
     const TDownloadEvent& aEvent )
     {
@@ -972,7 +946,7 @@
             }        
         }    
     }
-*/
+
 
 TInt CCatalogsHttpDownloadManager::NewDownloadId()
     {
@@ -980,23 +954,8 @@
     }
 
 
-Download& CCatalogsHttpDownloadManager::CreatePlatformDownloadL( 
+RHttpDownload& CCatalogsHttpDownloadManager::CreatePlatformDownloadL( 
     const TDesC8& aUrl )
     {
-    
-   	QString myString=	QString::fromRawData( reinterpret_cast<const QChar*>(aUrl.Ptr()),aUrl.Length());
-
-    return *(iDmgr->createDownload( myString ));
+    return iDmgr.CreateDownloadL( aUrl );
     }
-    
-CCatalogsHttpQTDownloadManager::CCatalogsHttpQTDownloadManager(CCatalogsHttpDownloadManager* aDownloadManager,DownloadManager* aDmgr)
-	{
-		iDownloadManager = aDownloadManager;
-		iDmgr = aDmgr;
-		connect(iDmgr, SIGNAL(downloadManagerEvent(DownloadManagerEvent*)), this,SLOT(downloadMgrEventRecieved(DownloadManagerEvent*)));
-	}
-	
-void CCatalogsHttpQTDownloadManager::downloadMgrEventRecieved(DownloadManagerEvent* aEvent)
-	{
-		iDownloadManager->downloadMgrEventRecieved(aEvent);
-	}
\ No newline at end of file