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

📄 sitemgr.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    /*
     * That's all we need to know, if we get this far then we
     * know there exists at least one site by this string.
     */
    bAvailable = TRUE;

exit:

    return bAvailable;
}

/************************************************************************
 *  Method:
 *    CHXSiteManager::IsSiteAvailableByLSGName
 */
BOOL
CHXSiteManager::IsSiteAvailableByLSGName(IHXValues* pProps, BOOL bIsPersistent)
{
    IHXBuffer*	    pValue = NULL;
    char*	    pActualString = NULL;
    HRESULT	    hresTemp;
    BOOL	    bAvailable = FALSE;

    /*
     * The properties passed here are the properties of the
     * site user not the site. When associating by LSG name
     * the site's "LayoutGroup" property must match the site
     * users "name" property. So we get the "name" property
     * from the props and look it in our LSGName list.
     */
    hresTemp = pProps->GetPropertyCString("name",pValue);
    HX_ASSERT(HXR_OK == hresTemp);
    pActualString = (char*)pValue->GetBuffer();
    if(bIsPersistent)
    {
	bAvailable = IsSiteAvailableByStringHelper(pActualString,m_PersistentLSGNamesToLists);
    }
    else
    {
	bAvailable = IsSiteAvailableByStringHelper(pActualString,m_LSGNamesToLists);
    }
    pValue->Release();
    return bAvailable;
}

/************************************************************************
 *  Method:
 *    CHXSiteManager::IsSiteAvailableByPlayToFrom
 */
BOOL
CHXSiteManager::IsSiteAvailableByPlayToFrom(IHXValues* pProps, BOOL bIsPersistent)
{
    IHXBuffer*	    pValue = NULL;
    char*	    pActualString = NULL;
    HRESULT	    hresTemp;
    BOOL	    bAvailable = FALSE;

    /*
     * The properties passed here are the properties of the
     * site user not the site. When associating by PlayToFrom
     * the site's "channel" property must match the site
     * users "playto" property. So we get the "playto" property
     * from the props and look it in our Channel list.
     */
    hresTemp = pProps->GetPropertyCString("playto",pValue);
    HX_ASSERT(HXR_OK == hresTemp);
    pActualString = (char*)pValue->GetBuffer();
    if(bIsPersistent)
    {
	bAvailable = IsSiteAvailableByStringHelper(pActualString,m_PersistentChannelsToLists);
    }
    else
    {
	bAvailable = IsSiteAvailableByStringHelper(pActualString,m_ChannelsToLists);
    }
    pValue->Release();
    return bAvailable;
}

/************************************************************************
 *  Method:
 *    IHXSiteManager::HookupByStringHelper
 */
BOOL
CHXSiteManager::HookupByStringHelper
(
    const char*		    pString,
    CHXMapStringToOb&	    ByStringMap,
    IHXSiteUserSupplier*   pSUS,
    BOOL		    bIsPersistent
)
{
    void*	    pVoid	    = NULL;
    CHXMapPtrToPtr* pSiteCollection = NULL;
    CHXMapPtrToPtr::Iterator ndxSite;

    /*
     * 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 know it is surely not available.
     */
    if (!ByStringMap.Lookup(pString,pVoid))
    {
	return FALSE;
    }

    /*
     * Now that we have the collection of sites we want to actually
     * hook the site user supplier up to each site in the collection.
     */
    pSiteCollection = (CHXMapPtrToPtr*)pVoid;

    ndxSite = pSiteCollection->Begin();

    for (; ndxSite != pSiteCollection->End(); ++ndxSite)
    {
	IHXSite* pSite	    = (IHXSite*)(*ndxSite);
	IHXSiteUser* pUser = NULL;
	
	// If the site has a user then we should not attempt to attach him
	// further, if he has a user it probably means that we have 
	// already attached him and we are in Wall of TVs mode.
	if (pSite->GetUser(pUser) != HXR_OK || !pUser)
	{
	    HookupSite2SUS(pSite, pSUS, bIsPersistent);
	}

	HX_RELEASE(pUser);
    }

    return TRUE;
}


//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\.
////\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//\\//.
/************************************************************************
 *  Method:
 *    IHXSiteManager::HookupSite2SUS
 */
BOOL
CHXSiteManager::HookupSite2SUS
(
    IHXSite*		    pSite, 
    IHXSiteUserSupplier*   pSUS,
    BOOL		    bIsPersistent
)
{
    BOOL		    retVal	    = TRUE;
    void*		    pVoid	    = NULL;
    IHXSiteWindowed*	    pSiteWindowed   = NULL;
    IHXSiteUser*	    pUser	    = NULL;
    BOOL		    bWindowed	    = FALSE;
    BOOL		    bNeedsWindowed  = FALSE;

    /*
     * We need to find out if this site user needs windowed
     * sites. The first step is to determine if this is a
     * windowed site.
     */
    bWindowed = (HXR_OK == pSite->QueryInterface(
					IID_IHXSiteWindowed,
					(void**)&pSiteWindowed));

    HX_RELEASE(pSiteWindowed);

    /*
     * If the site user supplier needs windowed sites and this
     * site is windowed, or if the site user supplier can handle
     * windowless sites, then proceed.
     */
    bNeedsWindowed = pSUS->NeedsWindowedSites();
    if (!bNeedsWindowed || (bNeedsWindowed && bWindowed))
    {

	/*
	 * Ask the site user supplier to create a new site user
	 * for this particular site.
	 */
	if (HXR_OK == pSUS->CreateSiteUser(pUser))
	{
	    /*
	     * Now actually hook up the site to the site user!
	     *
	     * NOTE: The IHXSite is responsible for calling the
	     *	     IHXSiteUser::AttachSite() method.
	     *
	     * NOTE: If this is a layout site user than it will
	     *	     create child site in response to the AttachSite()
	     *	     method call.
	     */
	    pSite->AttachUser(pUser);

	    /*
	     * We also record the site's that we have created users for
	     * here so that we can unhook everything the next time the
	     * layout is changed. We record the site user supplier
	     * that created the site user so that we can delete that user
	     * as well. NOTE: we shouldn't have already created this
	     * user!
	     */
	    if(bIsPersistent)
	    {
		HX_ASSERT(!m_PersistentSitesToSUS.Lookup(pSite,pVoid));
		m_PersistentSitesToSUS[pSite] = pSUS;
	    }
	    else
	    {
		HX_ASSERT(!m_SitesToSUS.Lookup(pSite,pVoid));
		m_SitesToSUS[pSite] = pSUS;
	    }
	    pSite->AddRef();
	    pSUS->AddRef();

	    pUser->Release();
	}
	else
	{
	    retVal = FALSE;
	}
    }
    else
    {
	retVal = FALSE;
    }
    return retVal;	
}


/************************************************************************
 *  Method:
 *    CHXSiteManager::HookupByLSGNameWithString
 */
BOOL 
CHXSiteManager::HookupByLSGNameWithString
(
    IHXSiteUserSupplier*   pSUS, 
    char*		    pActualString,
    BOOL		    bIsPersistent
)
{
    BOOL res = FALSE;
    if(bIsPersistent)
    {
	res = HookupByStringHelper(pActualString,m_PersistentLSGNamesToLists,pSUS, bIsPersistent);
	if(!res)
	{
	    // check for existence of string in non-persistent list, then move it if it exists
	    void* pVoid = NULL;
	    if(m_LSGNamesToLists.Lookup(pActualString, pVoid))
	    {
		m_LSGNamesToLists.RemoveKey(pActualString);
		m_PersistentLSGNamesToLists.SetAt(pActualString, pVoid);
		res = HookupByStringHelper(pActualString,m_PersistentLSGNamesToLists,pSUS, bIsPersistent);
	    }
	}
    }
    else
    {
	res = HookupByStringHelper(pActualString,m_LSGNamesToLists,pSUS, bIsPersistent);
    }
    return res;
}

/************************************************************************
 *  Method:
 *    CHXSiteManager::HookupByLSGName
 */
BOOL 
CHXSiteManager::HookupByLSGName
(
    IHXSiteUserSupplier*   pSUS, 
    IHXValues*		    pProps,
    BOOL		    bIsPersistent
)
{
    IHXBuffer*	    pValue = NULL;
    char*	    pActualString = NULL;
    HRESULT	    hresTemp;

    /*
     * This method is responsible for fully hooking up the
     * site user supplier with any and all sites associate with
     * it's LSG name. NOTE: The Properties passed in are those
     * of this site user supplier, so first thing is to map from
     * the appropriate property to the collection of sites having
     * that property. This is the same as the process for determining
     * availability.
     */
    hresTemp = pProps->GetPropertyCString("name",pValue);
    HX_ASSERT(HXR_OK == hresTemp);
    pActualString = (char*)pValue->GetBuffer();

    CHXSiteUserSupplierProxy* pProxy = new CHXSiteUserSupplierProxy(this,
	pSUS, pActualString);
    pProxy->AddRef();

    BOOL res = HookupByLSGNameWithString(pProxy, pActualString, bIsPersistent);
    // when it fails, save the pProxy & pValue for pending hookup
    // which is done later during AddSite()
    if (!res)
    {
	m_PendingValueToSULSG.SetAt(pValue, pProxy);
    }
    else
    {
        pValue->Release();
	pProxy->Release();	// now owned by the hookup list
    }

    return res;
}

/************************************************************************
 *  Method:
 *    CHXSiteManager::HookupByPlayToFromWithSting
 */
BOOL
CHXSiteManager::HookupByPlayToFromWithString
(
    IHXSiteUserSupplier*   pSUS, 
    char*		    pActualString,
    BOOL		    bIsPersistent
)
{
    BOOL res = FALSE;
    if(bIsPersistent)
    {
	res = HookupByStringHelper(pActualString,m_PersistentChannelsToLists,pSUS,bIsPersistent);
	if(!res)
	{
	    // check for existence of string in non-persistent list, then move it if it exists
	    void* pVoid = NULL;
	    if(m_ChannelsToLists.Lookup(pActualString, pVoid))
	    {
		m_ChannelsToLists.RemoveKey(pActualString);
		m_PersistentChannelsToLists.SetAt(pActualString, pVoid);
		res = HookupByStringHelper(pActualString,m_PersistentChannelsToLists,pSUS,bIsPersistent);
	    }
	}
    }
    else
    {
	res = HookupByStringHelper(pActualString,m_ChannelsToLists,pSUS,bIsPersistent);
    }
    return res;
}


/************************************************************************
 *  Method:
 *    CHXSiteManager::HookupByPlayToFrom
 */
BOOL
CHXSiteManager::HookupByPlayToFrom
(
    IHXSiteUserSupplier*   pSUS, 
    IHXValues*		    pProps,
    BOOL		    bIsPersistent
)
{
    IHXBuffer*	    pValue = NULL;
    char*	    pActualString = NULL;
    HRESULT	    hresTemp;

    /*
     * This method is responsible for fully hooking up the
     * site user supplier with any and all sites associate with
     * it's playto/from infor. NOTE: The Properties passed in 
     * are those of this site user supplier, so first thing is 
     * to map from the appropriate property to the collection 
     * of sites having that property. This is the same as the 
     * process for determining availability.
     */
    hresTemp = pProps->GetPropertyCString("playto",pValue);
    HX_ASSERT(HXR_OK == hresTemp);
    pActualString = (char*)pValue->GetBuffer();

    CHXSiteUserSupplierProxy* pProxy = new CHXSiteUserSupplierProxy(this,
	pSUS, pActualString);
    pProxy->AddRef();

    BOOL res = HookupByPlayToFromWithString(pProxy, pActualString, bIsPersistent);

    // when it fails, save the pSU & pValue for pending hookup
    // which is done later during AddSite()
    if (!res)
    {
	m_PendingValueToSUPlayTo.SetAt(pValue, pProxy);
    }
    else
    {
        pValue->Release();
	pProxy->Release();	// now owned by hookup list
    }

    return res;
}

void
CHXSiteManager::RemoveSitesByLSGName(IHXValues* pProps, BOOL bIsPersistent)
{
    IHXBuffer* pValue = 0;
    HX_RESULT rc = pProps->GetPropertyCString("name", pValue);
    if(HXR_OK == rc)
    {
	const char* pActualString = (const char*)pValue->GetBuffer();
	if(bIsPersistent)
	{
	    void* pVoid;
	    if(m_PersistentLSGNamesToLists.Lookup(pActualString, pVoid))
	    {
		/*
		 * Now that we have the collection of sites we want to actually
		 * hook the site user supplier up to each site in the collection.
		 */
		CHXMapPtrToPtr* pSiteCollection = (CHXMapPtrToPtr*)pVoid;
		CHXMapPtrToPtr::Iterator ndxSite = pSiteCollection->Begin();

		for (; ndxSite != pSiteCollection->End(); ++ndxSite)
		{
		    IHXSite* pSite = (IHXSite*)(*ndxSite);
		    RemoveSite(pSite);
		}

		delete pSiteCollection;
		m_PersistentLSGNamesToLists.RemoveKey(pActualString);
	    }
	}
	pValue->Release();
    }
}


/************************************************************************
 *  Method:
 *    CHXSiteManager::UnhookSite
 */
void 
CHXSiteManager::UnhookSite(IHXSite* pSite, BOOL bIsPersistent)
{
    HX_ASSERT(pSite);
    /*
     * To unhook all the items we simple run through the site users
     * we created, ask them for their site, tell the site to detach
     * from the user, and tell the site user supplier to destroy the
     * site user. That's simple enough...
     */

    IHXSiteUserSupplier*	pSUS  = 0;
    IHXSiteUser*		pUser = 0;

    /* Check in both */
    if(m_PersistentSitesToSUS.Lookup(pSite, (void*&)pSUS))
    {
	m_PersistentSitesToSUS.RemoveKey(pSite);
	pSite->GetUser(pUser);
	pSite->DetachUser();
	if(pUser && pSUS)
	{
	    pSUS->DestroySiteUser(pUser);

⌨️ 快捷键说明

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