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

📄 httpfileobj.h

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 H
字号:
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
 *      
 * The contents of this file, and the files included with this file, are 
 * subject to the current version of the RealNetworks Public Source License 
 * Version 1.0 (the "RPSL") available at 
 * http://www.helixcommunity.org/content/rpsl unless you have licensed 
 * the file under the RealNetworks Community Source License Version 1.0 
 * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
 * in which case the RCSL will apply. You may also obtain the license terms 
 * directly from RealNetworks.  You may not use this file except in 
 * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
 * applicable to this file, the RCSL.  Please see the applicable RPSL or 
 * RCSL for the rights, obligations and limitations governing use of the 
 * contents of the file.  
 *  
 * This file is part of the Helix DNA Technology. RealNetworks is the 
 * developer of the Original Code and owns the copyrights in the portions 
 * it created. 
 *  
 * This file, and the files included with this file, is distributed and made 
 * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
 * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
 * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
 * 
 * Technology Compatibility Kit Test Suite(s) Location: 
 *    http://www.helixcommunity.org/content/tck 
 * 
 * Contributor(s): 
 *  
 * ***** END LICENSE BLOCK ***** */ 
#ifndef _HTTPFILEOBJ_H_
#define _HTTPFILEOBJ_H_


/****************************************************************************
 * Includes
 */
#include "hxcom.h"
#include "hxfiles.h"        // IHXFileObject, IHXRequestHandler, etc. 
#include "hxcache2.h"       // IHXCache2, IHXCacheObject, IHXCacheObjectResponse
#include "hxengin.h"        // IHXTCPResponse, IHXTCPSocket, IHXNetworkServices
#include "hxbuffer.h"
#include "hxurl.h"          // CHXURL
#include "memcache.h"       // uses only memory

#ifdef HELIX_FEATURE_HTTP_FILECACHE // Create a file cache object
    #include "filecache.h"  // uses filesystem + memory   
#endif




/****************************************************************************
 *
 *  CHXHTTPFileObject Class
 *
 *  This class inherits the interfaces required to create a File Object,
 *  which is used by the File System plug-in to handle file I/O. This class
 *  implements the IHXFileObject interface which handles the actual low
 *  level file access. The IHXRequestHandler interface is used to obtain
 *  the requested URL; while the IHXFileExists interface determines if the
 *  requested file actually exists. Since we are using COM, this class also
 *  inherits COM's IUnknown interface to handle reference counting and
 *  interface query.
 */
class CHXHTTPFileObject :  public IHXFileObject,
			   public IHXRequestHandler,
			   public IHXFileStat,
                           public IHXCacheObjectResponse,
                           public IHXTCPResponse,
                           public IHXCallback

{
public:

    CHXHTTPFileObject(IUnknown*  pContext, IHXValues* pOptions);
    ~CHXHTTPFileObject(void);


    /************************************************************************
     *  IHXFileObject Interface Methods
     */
    STDMETHOD(Init       ) (THIS_ UINT32 access,IHXFileResponse* pFileResp);
    STDMETHOD(GetFilename) (THIS_ REF(const char*) pFileName);
    STDMETHOD(Read       ) (THIS_ UINT32 byteCount);
    STDMETHOD(Write      ) (THIS_ IHXBuffer* pDataToWrite);
    STDMETHOD(Seek       ) (THIS_ UINT32 offset, BOOL bRelative);
    STDMETHOD(Advise     ) (THIS_ UINT32 useage);
    STDMETHOD(Close      ) (THIS);


    /************************************************************************
     *  IHXRequestHandler Interface Methods
     */
    STDMETHOD(SetRequest) (THIS_     IHXRequest*  pRequest);
    STDMETHOD(GetRequest) (THIS_ REF(IHXRequest*) pRequest);


    /************************************************************************
     *  IUnknown COM Interface Methods
     */
    STDMETHOD (QueryInterface ) (THIS_ REFIID ID, void** ppInterfaceObj);
    STDMETHOD_(UINT32, AddRef ) (THIS);
    STDMETHOD_(UINT32, Release) (THIS);

    /************************************************************************
     *  IHXFileStat Interface Methods
     */
    STDMETHOD(Stat)(THIS_ IHXFileStatResponse* pFileStatResponse);

    /************************************************************************
     *	IHXCacheObjectResponse methods
     */
    STDMETHOD(InitDone)		                (THIS_
				                HX_RESULT	/*IN*/	status);
    STDMETHOD(ChangeCapacityDone)		(THIS_
				                HX_RESULT	/*IN*/	status);
    STDMETHOD(AddBlockDone)	                (THIS_
				                HX_RESULT	/*IN*/	status);
    STDMETHOD(VerifyBlockDone)	                (THIS_
				                BOOL	        /*IN*/	bExist);
    STDMETHOD(ReadBlockDone)	                (THIS_
				                HX_RESULT	/*IN*/	status,
				                IHXBuffer*	/*IN*/	pBuffer);
    STDMETHOD(FlushDone)	                (THIS_
				                HX_RESULT	/*IN*/	status);


    /************************************************************************
     *	IHXTCPResponse methods
     */
    STDMETHOD(ConnectDone)	(THIS_
				HX_RESULT		status);
    
    STDMETHOD(ReadDone)		(THIS_
				HX_RESULT		status,
				IHXBuffer*		pBuffer);

    STDMETHOD(WriteReady)	(THIS_
    				HX_RESULT		status);

    STDMETHOD(Closed)		(THIS_
				HX_RESULT		status);

    /************************************************************************
     *	IHXCallback methods
     */
    STDMETHOD(Func)     	(THIS);

private:

    // The struct used to represent chunks of HTTP header as 
    // they arrive. The chunks are consolidated after the
    // last header chunk arrives.
    struct HdrChunk
    {
        IHXBuffer*  pPartOfHdr;
        HdrChunk*    next;
    };

    // If a read can't be fully satisfied by the cache, a buffer
    // is created for it and is filled in installments. Information 
    // for the pnding read, such as where to start reading for the next
    // installment, where to write in the pending read buffer, etc is 
    // stored in this struct.
    struct PendingReadInfo
    {
        UINT32 ulWriteOffset;       // Where to start writing in the buffer
        UINT32 ulReadOffset;        // From where should the next installment begin.
        UINT32 ulSize;              // Size left to be read
        IHXBuffer* pPendingReadBuff;// The buffer to be filled
    } m_pPendingReadInfo;

    /****** Private Class Variables ****************************************/
    INT32                   m_RefCount;             // Object's reference count
    IUnknown*               m_pContext;
    IHXValues*              m_pOptions;
    IHXCommonClassFactory*  m_pClassFactory;        // Creates common classes
    IHXFileResponse*        m_pFileResponse;        // Provides completion notif.
    IHXRequest*             m_pRequest;             // Used to get requested URL
    IHXCacheObject*         m_pCache;               // Non-persistent cache object
    IHXTCPSocket*           m_pSocket;              // Socket used to connect to the HTTP server
    CHXURL*                 m_pCHXURL;              // URL parser
    UINT32                  m_ulCurrentReadOffset;  // Offset to be used for the next read
    int                     m_lNewReadOffset;       // Offset requested by Seek()
    BOOL                    m_bInSeekDone;
    BOOL                    m_bInReadDone;
    BOOL                    m_bReadPending;         // Is a read pending?
    BOOL                    m_bIncompleteReadPending;   // A read was only partially satisfied by the cache.
                                                        // Need to read in installments from the cache.
    UINT32                  m_ulFileLength;         // The Content-Length returned in HTTP header
    HdrChunk*               m_pHdrListRoot;         // List for storing the header chunks
    BOOL                    m_bHeaderCompletelyRead;// Has the HTTP header been completely read?
    CHXBuffer*              m_pHeader;              // The HTTP Header
    BOOL                    m_bStartAllOverAgain;   // A backward seek failed. Start all over again.
    IHXScheduler*	    m_pScheduler;           // For scheduling callbacks.
    UINT32                  m_ulCallbackHandle;
    UINT32                  m_ulCallBackInterval;   // millisec
    BOOL                    m_bFirstChunk;          // Is it the first chunk of TCP data we got from the n/w service?
    BOOL                    m_bInitResponsePending; // Init() is completed. Call InitDone() on fileformat obj
    BOOL                    m_bInitialized;         // Has been already initialized
    UINT32                  m_ulFileDataRead;       // How much of the file has been read
    BOOL                    m_bAddBlockPending;     // A block was previously rejected by cache. Add it when
                                                    // cache becomes free again.
    IHXBuffer*              m_pPendingAddBlock;     // The block which was rejected by cache
    BOOL                    m_bDisconnected;
    
    /****** Private Class Methods ******************************************/
    STDMETHOD(_CleanUp) (THIS);                     // Called by Close() and destructor
    STDMETHOD(_Start) (THIS);                       // Starts connecting to server

    // Retrives cache preferences like "whether to cache or not", 
    // "where to cache", etc which are set by the user.
    STDMETHOD(_GetCachePreferences) (THIS_
                                     REF(BOOL)      /*OUT*/ bCacheEnabled,
                                     REF(char *)    /*OUT*/ pCacheFile);


    STDMETHOD(_PrepareHTTP10GetMessage) (THIS_
                                         REF(char *)    /*OUT*/ pGetMsg,
                                         REF(UINT32)    /*OUT*/ ulMsgLen);
                                     
    
};

#endif  /* _HTTPFILEOBJ_H_ */

⌨️ 快捷键说明

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