×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    14

    Question Download Manager API - Unexpected Usage Issue

    Greetings:

    We are trying to develop a program that can do downloads of files from a http location using the download manager API.

    Our platform is as follows:

    Symbian OS 8.1a
    S60 2nd Edition FP3 SDK
    Nokia N70 Handset

    We wrote the following code using the documentation from the "S60 Platform Download Manager API Developers Guide" documentation from this forum.

    The files implementing the download calls are as follows:
    CDownloadTestManager.h and CDownloadTestManager.cpp

    Code:
    #ifndef CDOWNLOADTESTMANAGER_H
    #define CDOWNLOADTESTMANAGER_H
    
    // INCLUDES
    #include <e32std.h>
    #include <e32base.h>
    #include <downloadmgrclient.h>
    
    // CLASS DECLARATION
    
    /**
     *  CCDownloadTestManager
     * 
     */
    class CCDownloadTestManager : public MHttpDownloadMgrObserver
    	{
    public:
    	// Constructors and destructor
    
    	/**
    	 * Destructor.
    	 */
    	virtual ~CCDownloadTestManager();
    
    	/**
    	 * Two-phased constructor.
    	 */
    	static CCDownloadTestManager* NewL();
    
    	/**
    	 * Two-phased constructor.
    	 */
    	static CCDownloadTestManager* NewLC();
    	
    	void   Download();
    
    private:
    
    	/**
    	 * Constructor for performing 1st stage construction
    	 */
    	CCDownloadTestManager();
    
    	/**
    	 * EPOC default constructor for performing 2nd stage construction
    	 */
    	void ConstructL();
    	
    	void HandleDMgrEventL (RHttpDownload &aDownload, THttpDownloadEvent aEvent);
    	
    	void  Log(TDesC8&  msg);
    	
    	RHttpDownloadMgr iDMgr;	
    
    	};
    
    #endif // CDOWNLOADTESTMANAGER_H

    Code:
    #include "CDownloadTestManager.h"
    #include "commdb.h"
    #include "rtimemethods.h"
    
    const TUid KMyAppUid = {0xE38EBD11};
    
    CCDownloadTestManager::CCDownloadTestManager()
    	{
    	// No implementation required
    	}
    
    CCDownloadTestManager::~CCDownloadTestManager()
    	{
    	iDMgr.Close();
    	}
    
    CCDownloadTestManager* CCDownloadTestManager::NewLC()
    	{
    	CCDownloadTestManager* self = new (ELeave) CCDownloadTestManager();
    	CleanupStack::PushL(self);
    	self->ConstructL();
    	return self;
    	}
    
    CCDownloadTestManager* CCDownloadTestManager::NewL()
    	{
    	CCDownloadTestManager* self = CCDownloadTestManager::NewLC();
    	CleanupStack::Pop(); // self;
    	return self;
    	}
    
    void CCDownloadTestManager::ConstructL()
    	{
    	// Connect to the Download Manager
    	iDMgr.ConnectL( KMyAppUid,*this, ETrue );
    	// Create the UI Library Registry
    	iDMgr.DeleteAll();
    
    	}
    
    void CCDownloadTestManager::Download()
    	{
    	
    	//
    	// Selecting the default Access Point (IAP) on handset 
    	//
    	TUint32 IapId = 0;
    	CCommsDatabase * cdb = CCommsDatabase::NewL(EDatabaseTypeIAP);
    	CleanupStack::PushL(cdb);
    	CCommsDbConnectionPrefTableView * commDBView = cdb->OpenConnectionPrefTableInRankOrderLC(ECommDbConnectionDirectionUnknown);
    	if (commDBView->GotoFirstRecord() == KErrNone) {
    		CCommsDbConnectionPrefTableView::TCommDbIapConnectionPref  pref;
    		commDBView->ReadConnectionPreferenceL(pref);
    		IapId = pref.iBearer.iIapId;
    	}
    	CleanupStack::PopAndDestroy(commDBView);
    	CleanupStack::PopAndDestroy(cdb);
    	
    	User::LeaveIfError( iDMgr.SetIntAttribute( EDlMgrIap, IapId ) );
    	
    	// 
    	// Set the URL for the download 
    	//
    	
    	_LIT8( KCodUrl, "http://202.164.36.66:80/mdms/downloads/sampletext.txt");
    	TBool retVal;
    	TBuf8<256> URL(KCodUrl);
    	RHttpDownload& download = iDMgr.CreateDownloadL(URL,retVal);
    	
    	//
    	// Launch on startup
    	//
    	User::LeaveIfError(download.SetIntAttribute(EDlAttrAction, ELaunch));
    	
    	if(retVal)
    	{
    		download.Start();
    		Log((TDesC8&)_L8("download started\n"));
    	}
    	else
    	{
    		Log((TDesC8&)_L8("download failed\n"));
    	}
    
    	}
    void CCDownloadTestManager::HandleDMgrEventL (RHttpDownload &aDownload, THttpDownloadEvent aEvent)
    	{
    		Log((TDesC8&)_L8("called\n"));
    	}
    
    void  CCDownloadTestManager::Log(TDesC8&  msg)
    {
    RFs fs;
    fs.Connect();
    
    RFile file;
    TInt result = file.Open(fs,_L("CRMADownloads.txt"), EFileWrite);
    if (result == KErrNotFound) {
    	file.Create(fs,_L("CRMADownloads.txt"), EFileWrite);
    }
    
    TInt pos = 0;
    file.Seek(ESeekEnd,pos);
    
    TBuf8<256>  wStr;
    wStr.Copy(RTimeMethods::GetCurrentTimeStamp());
    wStr.Append(_L8(" - "));
    wStr.Append(msg);
    wStr.Append(_L8("\n"));
    file.Write(wStr);
    
    file.Close();
    fs.Close();
    }
    and the main file uses an object of above as follows:

    Code:
    CCDownloadTestManager * mgr = CCDownloadTestManager::NewL();
    CleanupStack::PushL(mgr);
    mgr->Download();
    User::After(30000000);
    CleanupStack::PopAndDestroy(mgr);
    Our problem is that this program test does not perform as expected. The download gets started but there are no events returned to our test program through the "MHttpDownloadMgrObserver" interface.

    Is there an apparent problem with the code above. Kindly advise as to why our download does not get initiated programmatically whereas on the Nokia N70 its initiated just fine using the "Web=>Download" interface of the handset.

    Note:
    GPRS is enabled on the handset.
    We did set the default IAP profile.

    Your kind time and consideration stands to be appreciated.

    Thanks.

    Prabhjot.

  2. #2
    Super Contributor
    Join Date
    Nov 2004
    Location
    Wiltshire, UK
    Posts
    3,644

    Re: Download Manager API - Unexpected Usage Issue

    I would be suprised if the example included
    User::After(30000000);
    Calling User::After and User::WaitForRequest block the current thread and stop any active objects executing.
    You need to use a proper active object to get the callbacks working
    Download Symbian OS now! [url]http://developer.symbian.org[/url]

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    14

    Question Re: Download Manager API - Unexpected Usage Issue

    Greetings!

    Thanks for the tip. Certainly making an Active Object create and manage an instance of the "CDownloadTestManager" class does make the download events to stream in - but only EHttpDlCreated and EHttpDlInprogress.

    We are now not getting the EHttpDlCompleted event in the method HandleDMgrEventL.
    Neither can we find the completely downloaded test file anywhere on the handset.

    We were setting the following download properties:

    Code:
    TFileName  fileName(_L("c:\\Nokia\\RMAServer\\myfile.txt"));
    	User::LeaveIfError(download.SetStringAttribute(EDlAttrDestFilename,fileName));
            
            User::LeaveIfError(download.SetIntAttribute(EDlAttrAction, EDoNothing));
    	
    	User::LeaveIfError(download.SetIntAttribute(EDlAttrAction, ELaunch));
    before invoking download.start() method. Any suggestions on what might be going wrong?

    Thanks.

    Prabhjot.

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    14

    Thumbs up Re: Download Manager API - Unexpected Usage Issue

    Greetings!

    Thanks for suggestions.

    The code now works fine once I introduce the following attributes being set before the download is
    started.

    Code:
    User::LeaveIfError(download.SetStringAttribute(EDlAttrDestFilename,fileName));
    			
    TBool  silentAttr(ETrue);
    User::LeaveIfError(download.SetBoolAttribute(EDlAttrSilent, silentAttr));
    	
    User::LeaveIfError(download.SetIntAttribute(EDlAttrAction, ELaunch));
    Thanking you all,

    Prabhjot

    (PS: Note - EDlAttrDestFilename expects a fileName which includes pathName.)

  5. #5
    Registered User
    Join Date
    Jun 2011
    Posts
    4

    Re: Download Manager API - Unexpected Usage Issue

    Hi,
    Can you show all source code of your's solution or upload this project!
    Thank you very much

  6. #6
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,165

    Re: Download Manager API - Unexpected Usage Issue

    most often people are not sharing all source codes of their projects, since they could indeed be doing commercial development. Also there are often not too much point on popping up old threads, instead I would suggest you to open a new thread, in which you would explain on what you are trying to do, what youn have done sofar, and what kind of problems you are facing

Similar Threads

  1. PC Suite error: (Code: Init IMediaControl2) HELP?!
    By chunkyspudmonkey in forum General Development Questions
    Replies: 30
    Last Post: 2014-07-15, 05:44
  2. Download manager hangs during file download on N95
    By ActiveRosh in forum Symbian Networking & Messaging (Closed)
    Replies: 1
    Last Post: 2009-10-13, 21:59
  3. s60 SDK C++ download issue
    By ticktock in forum News and Announcements
    Replies: 6
    Last Post: 2007-02-05, 23:59

Posting Permissions

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