×

Discussion Board

Results 1 to 1 of 1
  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    118

    the problem of using download manager api,memory leak!

    downloadEngineNew.h
    Code:
    /*
     * downloadEngineNew.h
     *
     *  Created on: 2009-4-22
     *      Author: Administrator
     */
    
    #ifndef DOWNLOADENGINENEW_H_
    #define DOWNLOADENGINENEW_H_
    
    #include <downloadmgrclient.h> 
    
    class CDownloadMgrUiDownloadsList;
    class CDownloadMgrUiLibRegistry;
    class CDownloadMgrUiUserInteractions;
    
    
    const TUid KMyAppUid = {0xE08C8196};
    
    
    class CDownLoadMgr : public MHttpDownloadMgrObserver 
    
        {
    
    public:
         static CDownLoadMgr* NewL();
         static CDownLoadMgr* NewLC();
         
         ~CDownLoadMgr();
         
       //  void StartDownloading(const TDesC8& aUrl,const TDesC8& aDestFilename);
         void StartDownloading(const TDesC8& url,const TDesC8 & des);
         void DoSomethingWhenCompleted();
        
         //  To observe download events from MHttpDownloadMgrObserver
         void HandleDMgrEventL (RHttpDownload &aDownload, THttpDownloadEvent aEvent);
         
    
    private:
         void ConstructL();
         CDownLoadMgr();
         
    private: //Data
    
         // Return value of download creation
         TInt retVal ;
       
         //Download manager to download the sisx
         RHttpDownloadMgr iDMgr;
         //Registry to register ui component
         CDownloadMgrUiLibRegistry * iUiReg;
         // UI interaction component
         CDownloadMgrUiUserInteractions* idMgrUserInteractions;
         //Download list component
         CDownloadMgrUiDownloadsList * iMgrDownloadsList;
         
        };
    
    #endif /* DOWNLOADENGINENEW_H_ */
    downloadEngineNew.cpp

    Code:
    /*
     * downloadEngineNew.cpp
     *
     *  Created on: 2009-4-22
     *      Author: Administrator
     */
    
    #include <cdownloadmgruidownloadslist.h>
    #include <cdownloadmgruilibregistry.h> 
    #include <cdownloadmgruiuserinteractions.h> 
    #include <COMMDB.H>
    #include <aknnotewrappers.h> 
    #include "downloadEngineNew.h"
    
    // Change these descriptor values(Give the correct URL path and sisx name)
    
     _LIT8( KCodUrl, "http://192.168.1.112/gan/1.swf");
     
     _LIT( KTempPath , "c:\\Data\\Videos\\new.swf" );
    
    
    CDownLoadMgr* CDownLoadMgr::NewL()
        {
        CDownLoadMgr* self = CDownLoadMgr::NewLC();
        CleanupStack::Pop(self);
        return self;
        }
    
    CDownLoadMgr* CDownLoadMgr::NewLC()
        {
        CDownLoadMgr* self = new (ELeave) CDownLoadMgr;
        CleanupStack::PushL(self);
        self->ConstructL();
        return self;
        }
    
    CDownLoadMgr::CDownLoadMgr()
        {
      
        }
    
    void CDownLoadMgr::ConstructL()
        {
        
        // Connect to download manager
        
        iDMgr.ConnectL( KMyAppUid,*this, ETrue );
    	
        iUiReg = CDownloadMgrUiLibRegistry::NewL( iDMgr );
    	   
        idMgrUserInteractions = &iUiReg->RegisterUserInteractionsL();
    
    	iMgrDownloadsList = &iUiReg->RegisterDownloadsListL();
    	
    	iDMgr.DeleteAll();    
        }
        
    CDownLoadMgr::~CDownLoadMgr()
        {
      
       delete iUiReg;
        iDMgr.Close();
        
    	
        }
        
    // Fn to download sisx from URL    
    void  CDownLoadMgr::StartDownloading(const TDesC8& url,const TDesC8 & des)
        {
        
       // AccessPt retrievel from CommsDB
       
           TUint32 iapId(0);
                
           CCommsDatabase* cdb = CCommsDatabase::NewL(EDatabaseTypeIAP);
    	   CleanupStack::PushL(cdb);
    
    			CCommsDbConnectionPrefTableView* commDBView = cdb->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionOutgoing);
    			if(commDBView->GotoFirstRecord() == KErrNone)
    			{
    				CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref pref;
    				commDBView->ReadConnectionPreferenceL(pref);
    				iapId = pref.iBearer.iIapId;
    			}
    
    		CleanupStack::PopAndDestroy(commDBView);
    		CleanupStack::PopAndDestroy(cdb);
    		
    	 //Setting Attribute for download manger ( Access Point)
    	 
    	    User::LeaveIfError( iDMgr.SetIntAttribute( EDlMgrIap, (TInt32)iapId ) ); 
    	
    	    TBufC8<254> URL(url);
    	    
    	 //Creation of download obj   
    				 
    	    RHttpDownload& download = iDMgr.CreateDownloadL(URL,retVal);
    	    
    	 // Setting attributes for download object
    	    TBufC8<254> buf(des);
    	 
    	    TFileName filename(KTempPath);
    	    
    	    // Setting destination path for the downloaded file to be stored
    	    
            download.SetStringAttribute( EDlAttrDestFilename, filename );
    
            
    
            TBool silattr(ETrue);
            
         //download progress will be silent   
    
    	   download.SetBoolAttribute(EDlAttrSilent,silattr);  
    			
         // start downloading
         
         if(retVal)                
    				 {
    					TInt state = download.Start();
    				 }
    				 else
    				 {
    				  _LIT(Ktext,"Download creation failed");
    				  CAknInformationNote* informationNote;
                      informationNote = new ( ELeave ) CAknInformationNote;
                       informationNote->ExecuteLD(Ktext);
        			 }
    
    	
        }
        
     void  CDownLoadMgr::DoSomethingWhenCompleted()
        {  
     //   iMgrDownloadsList->DisplayDownloadsListL();
        User::InfoPrint( _L( "Completed" ) );			  
        }
        	
    
    //  To observe download events from MHttpDownloadMgrObserver
    void CDownLoadMgr::HandleDMgrEventL (RHttpDownload &aDownload, THttpDownloadEvent aEvent)
    	{
    	switch ( aEvent.iDownloadState )
    		{
    			case EHttpDlCreated:
    			{
    			break;
    			}
    			case EHttpDlInprogress:
    			{
    //			  _LIT(Ktext,"downing");
    //						  CAknInformationNote* informationNote;
    //		                  informationNote = new ( ELeave ) CAknInformationNote;
    //		                   informationNote->ExecuteLD(Ktext);
    			break;
    			}
    			case EHttpDlCompleted:
    			{
    			// On completion of download , call silent installation function
    //			TFileName filename(KTempPath );
    //			aDownload.SetStringAttribute( EDlAttrDestFilename, filename );
    //			aDownload.Move();
    
    			DoSomethingWhenCompleted();
    			break;
    			}
    			case EHttpDlFailed:
    			{
    			 _LIT(Kerr,"Downloading failed");
    			TInt32 iVal = 0L;	
    		    TBuf<40> derror;
    		
    			aDownload.GetIntAttribute(EDlAttrGlobalErrorId, iVal);
    			derror.Append(Kerr);
    			derror.AppendNum(iVal);
    			
    			CAknInformationNote* informationNote;
                informationNote = new ( ELeave ) CAknInformationNote;
                informationNote->ExecuteLD(derror);
    			
    		    aDownload.Delete();
    			break;
    			}
    			case EHttpDlPaused:
    			{
    				break;
    			}
    
    			default :
    			{
    		       break;
    			}
    		}
    		
    	}
    my problem:
    1、if i delete
    TBool silattr(ETrue);
    download.SetBoolAttribute(EDlAttrSilent,silattr);
    or change it to EFalse,when i exit my app,it notes that "the application is closed,alloc xxxxx",i don't know why?MY SDK is MR.
    hooklogger display that the problem happens in DownloadMgrUiLib.dll

    can anyone help me?
    Last edited by never115; 2009-05-04 at 08:58.

Similar Threads

  1. download file problem !!!
    By rokroff in forum Symbian
    Replies: 2
    Last Post: 2009-05-03, 13:31
  2. [Undocumented Evil] Download Manager API crashes and timeouts
    By Dexterp37 in forum Symbian Networking & Messaging (Closed)
    Replies: 6
    Last Post: 2008-07-01, 17:29
  3. SDK and IDE download problem
    By Nigga726 in forum Symbian Tools & SDKs
    Replies: 7
    Last Post: 2007-02-01, 14:40
  4. Download Manager API
    By fullscale in forum Symbian
    Replies: 0
    Last Post: 2005-10-03, 08:43

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •