⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gnhttpdown.h

📁 SYMIBNA 支持大型文件断点续传的引擎源代码
💻 H
字号:
/*
 ============================================================================
 Name        : GnHttpDown.h
 Author      : cheney.kan
 Version     : 1.0
 Copyright   : Your copyright notice
 Description : CGnHttpDown declaration
 ============================================================================
 */

#ifndef GNHTTPDOWN_H
#define GNHTTPDOWN_H

// INCLUDES
#include <e32std.h>
#include <e32base.h>

#include <rhttpsession.h>
#include <mhttptransactioncallback.h>
#include <httpstringconstants.h>
//#include <InternalGnHttpDown.h>

//#include "GnHDRec.h"

class CGnHDRec;
class CGnHDRecFmt;


enum TGnHttpDownErr
{
    EGnHttpDownNullPointer = -999
   ,EGnHttpDownBadStatus
   
};


// CLASS DECLARATION

class CHTTPFormEncoder;

/**
*
* @class    MHTTPExampleEngineObserver HTTPExampleEngine.h
* @brief    This is the engine observer interface
*
* Copyright (c) EMCC Software Ltd 2003
* @version    1.0
*
*/


class CGnHttpDown;

//*
class MGnHTTPTransactionCallback
{
public:
    virtual TBool ShouldUpdateTheResumeRecL(const TDesC8 & /*aData*/, CGnHttpDown * /*aGnHttpDown*/)
        { return ETrue; }
    virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent, const TDesC8 & aDataBlock, CGnHttpDown * aGnHttpDown) = 0;
    virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent, CGnHttpDown * aGnHttpDown) = 0;
};
//*/

/**
 *  CGnHttpDown
 * 
 */
class CGnHttpDown 
    : public CBase
    , public MHTTPTransactionCallback
    {
public:
    
    /**
     * Two-phased constructor.
     */
     // The status machine change to EUninitial.
    static CGnHttpDown* NewLC(MGnHTTPTransactionCallback & aNotifier);
    
    /**
     * Two-phased constructor.
     */
     // The status machine change to EUninitial.
    static CGnHttpDown* NewL(MGnHTTPTransactionCallback & aNotifier);

    // For example, the aUri is "http::\\cheney23.poco.cn\test.mp3".
    // If the rec file has been set, the status machine change to EInitial, 
    // or the status machine change to EUninitial.
    void SetFileUriL(const TDesC & aUri);

    HBufC * GetFileUriL() const;

    void RemoveUriInfoFromRecL(const TDesC & aUri);

    // For example, the aRecFile is "e:\\myapp\\resume.record".
    // If the uri file has been set, the status machine change to EInitial, 
    // or the status machine change to EUninitial.
    void SetRecFileL(const TDesC & aRecFile);
    
    const TDesC & GetRecFileName() const;

    enum TDownType
        {
        EGetReq = HTTP::EGET 
       ,EPostReq = HTTP::EPOST
        };

    // IF aToBytes < 0, will download all the data from aFromBytes, 
    // else download from aFromBytes to aToBytes.
    // the status machine change to EDownlonding.
    void DownloadL(CGnHttpDown::TDownType aReqType = CGnHttpDown::EGetReq, 
        TInt32 aFromBytes = 0, 
        TInt32 aToBytes = -1, 
        TBool aisSupportResume = EFalse);

    // IF aToBytes < 0, will download all the data from aFromBytes, 
    // else download from aFromBytes to aToBytes.
    // the status machine change to EDownlonding.
    TInt DownloadResumeL(CGnHttpDown::TDownType aReqType = CGnHttpDown::EGetReq, 
        TInt32 aToBytes = -1, TBool aisSupportResume = ETrue);

    void SetPostDataBodyL(const TDesC &aFieldName, const TDesC &aFieldValue);
    
    void Stop();

    // Cancel an outstanding transaction
    void Cancel();

    // status machine: 
    // EUninitial -> EInitial
    // EInitial -> EDownlonding OR EInitial -> EInitial
    // EDownlonding -> EInitial
    enum GnHDStatus{
        EUninitial
       ,EInitial
       ,EDownlonding
    };
    CGnHttpDown::GnHDStatus CurrentStatus();

    //void CloseAndReset();

public:
    // Constructors and destructor
    /**
     * Destructor.
     */
    virtual ~CGnHttpDown();
private:

    /**
     * Constructor for performing 1st stage construction
     */
    CGnHttpDown();

    /**
     * EPOC default constructor for performing 2nd stage construction
     */
    void ConstructL(MGnHTTPTransactionCallback & aNotifier);

    //void ParseUriL(const TDesC& aUri);
    void AddHeaderL(RHTTPHeaders aHeaders, TInt aHeaderField, const TDesC8& aHeaderValue);
    

// from MGnHTTPTransactionCallback
public:
    virtual void MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent);
    virtual TInt MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& aEvent);


private:
    RHTTPSession iSession;
    RHTTPTransaction iTransaction;

    HBufC * iResponseBuffer;
    //HBufC8 * iUri;
    TUriParser8 iUriParser;
    CHTTPFormEncoder* iFormEncoder;

    MGnHTTPTransactionCallback * iUiNotifier;

    TBool iIsSupportResume;
    TBuf8<30> iRange;

    //TUint32 iPosition;

    CGnHDRec * iRecEngine;
    TBool iHasSepecRecInfo;

    CGnHDRecFmt * iCurFileInfo;
    TBool iHasSepecUriInfo;

    GnHDStatus       iGnHDStatus;

    };

#endif // GNHTTPDOWN_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -