📄 sitemgr.cpp
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: sitemgr.cpp,v 1.6.8.1 2004/07/09 02:08:40 hubbe Exp $ * * Portions Copyright (c) 1995-2004 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 (the "RPSL") available at * http://www.helixcommunity.org/content/rpsl unless you have licensed * the file under the current version of the RealNetworks Community * Source License (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. * * Alternatively, the contents of this file may be used under the * terms of the GNU General Public License Version 2 or later (the * "GPL") in which case the provisions of the GPL are applicable * instead of those above. If you wish to allow use of your version of * this file only under the terms of the GPL, and not to allow others * to use your version of this file under the terms of either the RPSL * or RCSL, indicate your decision by deleting the provisions above * and replace them with the notice and other provisions required by * the GPL. If you do not delete the provisions above, a recipient may * use your version of this file under the terms of any one of the * RPSL, the RCSL or the GPL. * * 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 _MACINTOSHBOOL 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_RESULTCHXSiteManager::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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -