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

📄 sitemgr.cpp

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

/****************************************************************************
 * 
 *  Basic PN implementation of the IHXSite classes.
 *
 *
 */
#include "hxcom.h"
#include "hxtypes.h"
#include "hxwintyp.h"
#include "hxmap.h"
#include "hxwin.h"
#include "hxengin.h"
#include "chxxtype.h"
#include "hxsite2.h"
#include "ihxpckts.h"
#include "hxslist.h"
#include "sitemgr.h"
#include "siteprxy.h"
#include "hxvctrl.h"
#include "hxvsurf.h"
#ifndef _WINCE
#ifdef _WINDOWS
#ifdef _WIN32
#include <vfw.h>
#else
#include <drawdib.h>
#endif /* _WIN32 */
#endif /* _WINDOWS */
#if defined(_MACINTOSH)
#include "maclibrary.h"
#include "hx_moreprocesses.h"
#endif
#endif

#include "hxstrutl.h"

#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE		
static const char HX_THIS_FILE[] = __FILE__;
#endif

#if !defined(HELIX_CONFIG_NOSTATICS)
INT32			CHXSiteManager::zm_nSiteManagerCount = 0;
#else
#include "globals/hxglobals.h"
const INT32		CHXSiteManager::zm_nSiteManagerCount = 0;
#endif

#if defined(_MACINTOSH) || defined(_MAC_UNIX)
CHXSimpleList CHXSiteManager::zm_SiteManagerList;
#endif

#ifdef _MACINTOSH

BOOL 	CHXSiteManager::zm_bWindowRemovedFromList = FALSE;

#endif


/************************************************************************
 *  Method:
 *    Destructor
 */
CHXSiteManager::CHXSiteManager()
    : m_lRefCount(0)
    , m_bInUnHookAll(FALSE)
    , m_bNeedFocus(FALSE)
{
#if defined(HELIX_CONFIG_NOSTATICS)
    INT32& zm_nSiteManagerCount =
	HXGlobalInt32::Get(&CHXSiteManager::zm_nSiteManagerCount);
#endif
    
#if defined(_MACINTOSH) || defined(_MAC_UNIX)
    zm_SiteManagerList.AddTail(this);
    zm_nSiteManagerCount++;
#endif
};

/************************************************************************
 *  Method:
 *    Destructor
 */
CHXSiteManager::~CHXSiteManager()
{
#if defined(HELIX_CONFIG_NOSTATICS)
    INT32& zm_nSiteManagerCount =
	HXGlobalInt32::Get(&CHXSiteManager::zm_nSiteManagerCount);
#endif
    
#if defined(_MACINTOSH) || defined(_MAC_UNIX)
    LISTPOSITION pos = zm_SiteManagerList.Find(this);
    zm_SiteManagerList.RemoveAt(pos);
    
    zm_nSiteManagerCount--;
#endif

    HX_ASSERT(m_MasterListOfSites.IsEmpty());
    HX_ASSERT(m_SitesToSUS.IsEmpty());

    RemoveMapStrToObj(&m_ChannelsToLists);
    RemoveMapStrToObj(&m_PersistentChannelsToLists);
    RemoveMapStrToObj(&m_LSGNamesToLists);
    RemoveMapStrToObj(&m_PersistentLSGNamesToLists);

    CHXMapStringToOb::Iterator ndx = m_EventHookMap.Begin();
    for (; ndx != m_EventHookMap.End(); ++ndx)
    {
        RemoveList((CHXSimpleList*)*ndx);
	delete (CHXSimpleList*)*ndx;
    }
    m_EventHookMap.RemoveAll();

    RemoveList(&m_UnnamedEventHookList);

    CleanupPendingValues();
}

HX_RESULT   
CHXSiteManager::ProcessSiteEvent(CHXEventHookElement* pElement, IHXSite* pSite, 
                                 HXxEvent* pEvent, EVENT_TYPE event_type)
{
    HX_RESULT   rc = HXR_OK;

    if (pElement)
    {
        switch (event_type)
        {
        case SITE_EVENT_GENERAL:
	    rc = pElement->m_pHook->HandleEvent(pSite, pEvent);
            break;
        case SITE_EVENT_REMOVED:
            rc = pElement->m_pHook->SiteRemoved(pSite);
            break;
        case SITE_EVENT_ADDED:
            rc = pElement->m_pHook->SiteAdded(pSite);
            break;
        default:
            HX_ASSERT(FALSE);
            break;
        }
    }

    return rc;
}


HX_RESULT
CHXSiteManager::HandleSiteEvent(const char* pRegionName, IHXSite* pSite, 
                                HXxEvent* pEvent, EVENT_TYPE event_type)
{
    HX_RESULT   rc = HXR_OK;

    // first, walk through named hooks
    CHXSimpleList* pList = NULL;
    if (m_EventHookMap.Lookup(pRegionName, (void*&)pList))
    {
	CHXSimpleList::Iterator iter = pList->Begin();
	for (; iter != pList->End(); ++iter)
	{
	    CHXEventHookElement* pElement =
		(CHXEventHookElement*)(*iter);
            
            rc = ProcessSiteEvent(pElement, pSite, pEvent, event_type);
	    if (pEvent && pEvent->handled)
	    {
		break;
	    }
	}
    }

    // try the null hooks
    if (pEvent && !pEvent->handled)
    {
	CHXSimpleList::Iterator iter = m_UnnamedEventHookList.Begin();
	for (; iter != m_UnnamedEventHookList.End(); ++iter)
	{
	    CHXEventHookElement* pElement =
		(CHXEventHookElement*)(*iter);

            rc = ProcessSiteEvent(pElement, pSite, pEvent, event_type);
	    if (pEvent && pEvent->handled)
	    {
		break;
	    }
	}
    }

    return rc;
}

void 
CHXSiteManager::HookupHelper(CHXMapPtrToPtr* pMap, char* pActualString, BOOL bIsPersistent, 
                             PTR_TYPE ptr_type, HOOK_TYPE hook_type)
{
    if (pMap)
    {
        CHXMapPtrToPtr::Iterator ndx = pMap->Begin();
        for (; ndx != pMap->End(); ++ndx)
        {
	    IHXBuffer* ptempValues = (IHXBuffer*)ndx.get_key(); 
            if (HOOKUP_BY_LSGNAMEWITHSTRING == hook_type)
            {
                HookupByLSGNameWithString((IHXSiteUserSupplier*) *ndx, 
                                          (char*)(ptempValues->GetBuffer()), 
                                          bIsPersistent);
            }
            else if ( !strcasecmp((char*)(ptempValues->GetBuffer()), pActualString ) ) 
	    {
                switch (hook_type)
                {
                case HOOKUP_BY_PLAYTOFROMWITHSTRING:
                    HookupByPlayToFromWithString((IHXSiteUserSupplier*) *ndx,
                                                 (char*)(ptempValues->GetBuffer()), 
                                                 bIsPersistent);
                    break;
                case HOOKUP_SINGLESITE_BY_LSGNAMEWITHSTRING:
		    HookupSingleSiteByLSGNameWithString((IHXSiteUser*) *ndx, 
                                                        (char*)(ptempValues->GetBuffer()), 
                                                        bIsPersistent);
                    break;
                case HOOKUP_SINGLESITE_BY_PLAYTOFROMWITHSTRING:
                    HookupSingleSiteByPlayToFromWithString((IHXSiteUser*) *ndx,
                                                           (char*)(ptempValues->GetBuffer()), 
                                                           bIsPersistent);

                    break;
                default:
                    HX_ASSERT(FALSE);
                    break;
                }
	    }
        }
    }
}

void 
CHXSiteManager::RemoveMapStrToObj(CHXMapStringToOb* pMap)
{
    if (pMap)
    {
        CHXMapStringToOb::Iterator ndx = pMap->Begin();
        for (; ndx != pMap->End(); ++ndx)
        {
	    CHXMapPtrToPtr* pNode = (CHXMapPtrToPtr*)(*ndx);
	    HX_ASSERT(pNode->IsEmpty());
	    delete pNode;
        }
        pMap->RemoveAll();
    }
}

void 
CHXSiteManager::RemoveMapPtrToPtr(CHXMapPtrToPtr* pMap)
{
    if (pMap)
    {
        CHXMapPtrToPtr::Iterator i;
        for(i = pMap->Begin(); i!= pMap->End();++i)
        {
            IHXBuffer* pValue = (IHXBuffer*)i.get_key();
	    CHXSiteUserSupplierProxy* pProxy = (CHXSiteUserSupplierProxy*) *i; 
	    HX_RELEASE(pValue);
	    HX_RELEASE(pProxy);
        }
        pMap->RemoveAll();
    }
}

void 
CHXSiteManager::RemoveList(CHXSimpleList* pList)
{
    if (pList)
    {
        CHXSimpleList::Iterator iter = pList->Begin();
        for (; iter != pList->End(); ++iter)
        {
	    CHXEventHookElement* pElement = (CHXEventHookElement*)(*iter);
	    delete pElement;
        }
        pList->RemoveAll();
    }
}

void CHXSiteManager::CleanupPendingValues()
{
    RemoveMapPtrToPtr(&m_PendingValueToSULSG);
    RemoveMapPtrToPtr(&m_PendingValueToSUSingleLSG);
    RemoveMapPtrToPtr(&m_PendingValueToSUPlayTo);
    RemoveMapPtrToPtr(&m_PendingValueToSUSinglePlayTo);
}

/************************************************************************
 *  Method:
 *    IUnknown::QueryInterface
 */
STDMETHODIMP 
CHXSiteManager::QueryInterface(REFIID riid, void** ppvObj)
{
    QInterfaceList qiList[] =
        {
            { GET_IIDHANDLE(IID_IHXSiteManager), (IHXSiteManager*)this },
            { GET_IIDHANDLE(IID_IHXEventHookMgr), (IHXEventHookMgr*)this },
            { GET_IIDHANDLE(IID_IHXSiteManager2), (IHXSiteManager2*)this },
            { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXSiteManager*)this },
        };
    
    return ::QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
}

/************************************************************************
 *  Method:
 *    IUnknown::AddRef
 */
STDMETHODIMP_(ULONG32) 
CHXSiteManager::AddRef()
{
    return InterlockedIncrement(&m_lRefCount);
}

/************************************************************************
 *  Method:
 *    IUnknown::Release
 */
STDMETHODIMP_(ULONG32) 
CHXSiteManager::Release()
{
    if (InterlockedDecrement(&m_lRefCount) > 0)
    {
        return m_lRefCount;
    }

    delete this;
    return 0;
}

/************************************************************************
 *  Method:
 *    IHXSiteManager::AddSiteByStringHelper
 */
STDMETHODIMP 
CHXSiteManager::AddSiteByStringHelper
(
    const char*		pString,
    IHXSite*		pSite,
    CHXMapStringToOb&	ByStringMap
)
{
    HRESULT	    hresFinal	    = HXR_OK;
    void*	    pVoid	    = NULL;
    CHXMapPtrToPtr* pSiteCollection = NULL;

    /*
     * The basic data structure is as follows: A map is kept 
     * from names to "lists" of sites. We don't actually use
     * a list because we want to quickly detect if the item is
     * already in the list so we use a map for the sites as well.
     */

    /*
     * Find the list in the name to list map, if there is no
     * list in the map then we need to create a new list object
     * and add it to the map.
     */
    if (!ByStringMap.Lookup(pString,pVoid))
    {
	pSiteCollection = new CHXMapPtrToPtr();
	ByStringMap.SetAt(pString,pSiteCollection);
    }
    else
    {
	pSiteCollection = (CHXMapPtrToPtr*)pVoid;
    }
    /*
     * Now that we have the collection of sites we want to see
     * if this item is already in the collection. If it is, then
     * we barf out an error!
     */
    if (pSiteCollection->Lookup(pSite,pVoid))
    {
	hresFinal = HXR_INVALID_PARAMETER;
	goto exit;
    }
    /*
     * Now that we know its cool to add this to the collection,
     * we do just that...
     */
    pSiteCollection->SetAt(pSite,pSite);

    /*
     * We also want to keep track of which collection we added
     * the site to so that we can more easily (quickly) delete
     * the site when it is removed. To do this we keep a master
     * map of pSite's to the pSiteList items.
     *
     * NOTE: This site should not already be in the master 
     * list. This debug check is a sanity check since our
     * previous efforts should have returned out as an error
     * in the event that a site was added twice!
     */
    HX_ASSERT(!m_MasterListOfSites.Lookup(pSite,pVoid));
    m_MasterListOfSites[pSite] = pSiteCollection;

exit:

    return hresFinal;
}


/************************************************************************
 *  Method:
 *    IHXSiteManager::AddSite
 */
STDMETHODIMP 
CHXSiteManager::AddSite(IHXSite* pSite)
{
    IHXValues*	    pProps = NULL;
    IHXBuffer*	    pValue = NULL;
    char*	    pActualString = NULL;
    HRESULT	    hresTemp;
    HRESULT	    hresFinal = HXR_OK;
    BOOL	    bIsPersistent = FALSE;

    /*
     * We need to get the IHXValues for the site so we know it
     * its for by LSGName or for by plattofrom use. If this is not
     * available then barf up an error.
     */
    hresTemp = pSite->QueryInterface(IID_IHXValues,(void**)&pProps);
    if (HXR_OK != hresTemp)
    {

⌨️ 快捷键说明

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