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

📄 chxcache2.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
字号:
/* ***** 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 ***** */ 


#include "hxtypes.h"

#include "hxcom.h"      // IUnknown
#include "hxiids.h"     // GUIDs
#include "hxslist.h"    // CHXSimpleList
#include "debug.h"      // DPRINTF()
#include "hxthread.h"   // HXMutex
#include "hxstring.h"   // memcpy()
#include "hxcomm.h"     // IHXCommonClassFactory
#include "ihxpckts.h"   // IHXBuffer
#include "hxcache2.h"   // IHXCache2, IHXCacheObject, IHXCacheObjectResponse
#include "chxcache2.h"
#include "memcache.h"

#ifdef HELIX_FEATURE_HTTP_FILECACHE
    #include "filecache.h"
#endif

/****************************************************************************
 *  CHXcache2::CHXCache2
 *
 *  Constructor
 */

CHXCache2::CHXCache2()
    : m_RefCount(0)
{
    DPRINTF(D_CACHE2, ("CHXCache2()\n"));

}


// IUnknown COM Interface Methods

/****************************************************************************
 *  IUnknown::AddRef
 *
 *  This routine increases the object reference count in a thread safe
 *  manner. The reference count is used to manage the lifetime of an object.
 *  This method must be explicitly called by the user whenever a new
 *  reference to an object is used.
 */

STDMETHODIMP_(UINT32) CHXCache2::AddRef(void)
{
    return InterlockedIncrement(&m_RefCount);
}


/****************************************************************************
 *  IUnknown::Release
 *
 *  This routine decreases the object reference count in a thread safe
 *  manner, and deletes the object if no more references to it exist. It must
 *  be called explicitly by the user whenever an object is no longer needed.
 */

STDMETHODIMP_(UINT32) CHXCache2::Release(void)
{
    if (InterlockedDecrement(&m_RefCount) > 0)
    {
	return m_RefCount;
    }

    delete this;
    return 0;
}


/****************************************************************************
 *  IUnknown::QueryInterface
 *
 *  This routine indicates which interfaces this object supports. If a given
 *  interface is supported, the object's reference count is incremented, and
 *  a reference to that interface is returned. Otherwise a NULL object and
 *  error code are returned. This method is called by other objects to
 *  discover the functionality of this object.
 */

STDMETHODIMP CHXCache2::QueryInterface(REFIID interfaceID,
					       void** ppInterfaceObj)
{
    // By definition all COM objects support the IUnknown interface
    if (IsEqualIID(interfaceID, IID_IUnknown))
    {
	AddRef();
	*ppInterfaceObj = (IUnknown*)(IHXCache2*)this;
	return HXR_OK;
    }
    // IHXCacheObject interface is supported
    else if (IsEqualIID(interfaceID, IID_IHXCache2))
    {
	AddRef();
	*ppInterfaceObj = (IHXCache2*)this;
	return HXR_OK;
    }

    // No other interfaces are supported
    *ppInterfaceObj = NULL;
    return HXR_NOINTERFACE;
}


/*
 *	IHXCache2 methods
 */

 /************************************************************************
 *	Method:
 *
 *	    IHXCache2::CreateMemCacheObject
 *
 *	Purpose:
 *
 *      Creates an object which implements the IHXCacheObject interface.
 *      This object uses ONLY the memory for caching.
 */

STDMETHODIMP CHXCache2::CreateMemCacheObject(THIS_
				             IHXCacheObject**    /*OUT*/	ppObject,
                                             IHXCommonClassFactory*  /*IN*/      pClassFactory)
{
    DPRINTF(D_CACHE2, ("CreateCacheMem()\n"));

    if(pClassFactory == NULL)
    {
        return HXR_INVALID_PARAMETER;
    }

    HX_RESULT res = HXR_OUTOFMEMORY;

    // Create a new CCacheMem object which implements the caching methods.
    CHXMemCacheObject *pCacheObj = new CHXMemCacheObject(pClassFactory);

    if(pCacheObj != NULL)
    {
        pCacheObj->QueryInterface(IID_IHXCacheObject, (void **)ppObject);

        res = (*ppObject != NULL)? HXR_OK: HXR_UNEXPECTED;
    }

    return res;

} // CreateMemCacheObject()

#ifdef HELIX_FEATURE_HTTP_FILECACHE

/************************************************************************
 *	Method:
 *
 *	    IHXCache2::CreateFileCacheObject
 *
 *	Purpose:
 *
 *      Creates an object which implements the IHXCacheObject interface.
 */

STDMETHODIMP
CHXCache2::CreateFileCacheObject(IHXCacheObject**    /*OUT*/	ppObject,
                                 IHXCommonClassFactory*  /*IN*/ pClassFactory,
                                 UINT32              /*IN*/      ulFileLength,
                                 char*               /*IN*/      pFileName)
{
    DPRINTF(D_CACHE2, ("CreateFileCacheObject()\n"));

    if( (pClassFactory == NULL) || (ulFileLength == 0) || (pFileName == NULL) ) 
    {
        return HXR_INVALID_PARAMETER;
    }

    HX_RESULT res = HXR_OUTOFMEMORY;

    // Create a new CHXFileCacheObject object which implements the caching methods.
    CHXFileCacheObject *pCacheObj = new CHXFileCacheObject(pClassFactory,
                                                           ulFileLength,
                                                           pFileName);

    if(pCacheObj != NULL)
    {
        pCacheObj->QueryInterface(IID_IHXCacheObject, (void **)ppObject);

        res = (*ppObject != NULL)? HXR_OK: HXR_UNEXPECTED;
    }

    return res;

} // CreateFileCacheObject()

#endif // HELIX_FEATURE_HTTP_FILECACHE

⌨️ 快捷键说明

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