📄 basehand.cpp
字号:
} HX_RELEASE(pBuffer); }#endif fileNameWithPath += (char*) m_pFileName->GetBuffer(); // 1st load the DLL into memory HX_PRIME_ACCUMULATOR( 'pdll', "Total DLL Load Time" ); int dllLoadResult = m_pDLLAccess->open(fileNameWithPath); HX_UPDATE_ACCUMULATOR( 'pdll' ); if( dllLoadResult != DLLAccess::DLL_OK ) { m_pBaseHandler->ReportError( HXLOG_DEBUG, (char *) m_pFileName->GetBuffer(), m_pDLLAccess->getErrorString() ); return CANT_OPEN_DLL; } HX_LOG_CHECKPOINT( "DLL Loaded" ); // Now look for the HXCreateInstance exported function m_fpCreateInstance = (FPCREATEINSTANCE) m_pDLLAccess->getSymbol(HXCREATEINSTANCESTR); if (NULL == m_fpCreateInstance) { m_pBaseHandler->ReportError( HXLOG_DEBUG, "NO HXCreateInstance", NULL ); return NO_HX_CREATE_INSTANCE; } // And look for HXShutdown exported function... not required. m_fpShutdown = (FPSHUTDOWN) m_pDLLAccess->getSymbol(HXSHUTDOWNSTR); // and look for CanUnload2 exported function //JE 3/26/01: look for CanUnload2 instead of CanUnload. This way we will //not try and unload any DLLs that may have incorrectly implemented the old // CanUnload. If you implement CanUnload2, you better get it right ;) m_fCanUnload = (FPSHUTDOWN) m_pDLLAccess->getSymbol("CanUnload2"); HX_LOG_CHECKPOINT( "Exported symbols found" ); // Does this thing support the IHXPlugin Interface // Now we will test to see if the DLL contains multiple Plugins. HX_PRIME_ACCUMULATOR( 'plmk', "Total Plugin Allocation time" ); HX_RESULT createResult = m_fpCreateInstance( &pInstance ); HX_UPDATE_ACCUMULATOR( 'plmk' ); if( HXR_OK != createResult ) { m_pBaseHandler->ReportError( HXLOG_DEBUG, "HXCreateInstance Failure", NULL ); result = CREATE_INSTANCHXR_FAILURE; goto cleanup; } HX_LOG_CHECKPOINT( "Plugin instance created" ); // To be a valid plugin a DLL must support IHXPlugin // In addition, it may support IHXPluginFactory if( SUCCEEDED( pInstance->QueryInterface( IID_IHXPluginFactory, (void**) &pIFactory ) ) ) { m_bHas_factory = TRUE; m_NumOfPlugins = pIFactory->GetNumPlugins(); HX_RELEASE( pIFactory ); } else if( SUCCEEDED( pInstance->QueryInterface( IID_IHXPlugin, (void**) &pPlugin ) ) ) { m_bHas_factory = FALSE; m_NumOfPlugins = 1; IHXComponentPlugin* pIPackage = NULL; if (SUCCEEDED (pInstance->QueryInterface (IID_IHXComponentPlugin, (void**) &pIPackage))) {#ifndef _WINDOWS // XXXHP TEMPORARY - viper team has requested that this shouldn't assert for now on windows. HX_ASSERT (m_fpShutdown);#endif pPlugin->InitPlugin (pContext); m_packageName = pIPackage->GetPackageName (); HX_RELEASE (pIPackage); } HX_RELEASE( pPlugin ); } else { result = BAD_PLUGIN; goto cleanup; } // We are now loaded. HX_RELEASE(pInstance); m_bLoaded = TRUE;cleanup: HX_LOG_CHECKPOINT( "BaseHandler::PluginDLL::Load() exiting" ); return result;}HX_RESULT BaseHandler::PluginDLL::Unload(BOOL safe){ if (m_bLoaded) { if (!safe || ( m_fCanUnload && m_fCanUnload()==HXR_OK ) ) { if (m_fpShutdown) { if (FAILED (m_fpShutdown ())) return HXR_FAIL; m_fpShutdown = NULL; } if (DLLAccess::DLL_OK == m_pDLLAccess->close()) { m_bLoaded = FALSE; return HXR_OK; } } } return HXR_FAIL;}BOOL BaseHandler::PluginDLL::IsLoaded(){ return m_bLoaded;}BaseHandler::Errors BaseHandler::PluginDLL::CreateInstance(IUnknown** ppUnk, UINT32 uIndex){ if (!m_bLoaded) return PLUGIN_NOT_FOUND; if (!m_bHas_factory) { if (HXR_OK != m_fpCreateInstance(ppUnk)) { return CREATE_INSTANCHXR_FAILURE; } } else { if (uIndex > (ULONG32)(m_NumOfPlugins-1) && m_NumOfPlugins) { return CANT_LOAD_INTERFACE; } IUnknown* pUnk; IHXPluginFactory* pPluginFactory; m_fpCreateInstance(&pUnk); if (HXR_OK != pUnk->QueryInterface (IID_IHXPluginFactory, (void**) &pPluginFactory)) { HX_RELEASE(pUnk); return CREATE_INSTANCHXR_FAILURE; } else { HX_RELEASE(pUnk); if (HXR_OK != pPluginFactory->GetPlugin((UINT16)uIndex, ppUnk)) { HX_RELEASE(pPluginFactory); return CREATE_INSTANCHXR_FAILURE; } HX_RELEASE(pPluginFactory); } } //m_pPlugin2Handler->AddtoLRU(this); //m_pPlugin2Handler->UpdateCache(); return NO_ERRORS;}IHXBuffer* BaseHandler::PluginDLL::GetFileName(){ m_pFileName->AddRef(); return m_pFileName;}IHXBuffer* BaseHandler::PluginDLL::GetNamespace(){ if (m_pNamespace) { m_pNamespace->AddRef(); } return m_pNamespace;}void BaseHandler::PluginDLL::SetNamespace(IHXBuffer* pNamespace){ m_pNamespace = pNamespace; if (m_pNamespace) { m_pNamespace->AddRef(); }}UINT32 BaseHandler::PluginDLL::AddDLLReference(){ return ++m_nActiveReferences;}UINT32 BaseHandler::PluginDLL::ReleaseDLLReference(){ --m_nActiveReferences; Unload(); //XXXAH this should only happen if we have set DLL unloading to true. return 0;}/////////////////////////////////////////////////////////////////////////// Method:// BaseHandler::PluginDLL::QueryInterface// Purpose:// Implement this to export the interfaces supported by your// object.//STDMETHODIMPBaseHandler::PluginDLL::QueryInterface(REFIID riid, void** ppvObj){ if (IsEqualIID(riid, IID_IUnknown)) { AddRef(); *ppvObj = (IUnknown*)this; return HXR_OK; } *ppvObj = NULL; return HXR_NOINTERFACE;}/////////////////////////////////////////////////////////////////////////// Method:// BaseHandler::PluginDLL::AddRef// Purpose:// Everyone usually implements this the same... feel free to use// this implementation.//STDMETHODIMP_(ULONG32)BaseHandler::PluginDLL::AddRef(){ return InterlockedIncrement(&m_lRefCount);}/////////////////////////////////////////////////////////////////////////// Method:// BaseHandler::PluginDLL::Release// Purpose:// Everyone usually implements this the same... feel free to use// this implementation.//STDMETHODIMP_(ULONG32)BaseHandler::PluginDLL::Release(){ if (InterlockedDecrement(&m_lRefCount) > 0) { return m_lRefCount; } delete this; return 0;}/************************************************************************************* BaseHandler::PluginMountPoint **************************************************************************************/BaseHandler::PluginMountPoint::PluginMountPoint( BaseHandler* pContext, const char* pName, UINT32 majorVersion, UINT32 minorVersion, IHXBuffer* pPath ) : m_lRefCount( 0 ){#if !defined(_STATICALLY_LINKED) || defined(HELIX_CONFIG_CONSOLIDATED_CORE) m_pPath = pPath; if (m_pPath) { m_pPath->AddRef(); }#endif}#if !defined(_STATICALLY_LINKED) || defined(HELIX_CONFIG_CONSOLIDATED_CORE)IHXBuffer*BaseHandler::PluginMountPoint::Path(){ if (m_pPath) { m_pPath->AddRef(); } return m_pPath;}#endifBaseHandler::PluginMountPoint::~PluginMountPoint(){#if !defined(_STATICALLY_LINKED) || defined(HELIX_CONFIG_CONSOLIDATED_CORE) HX_RELEASE(m_pPath);#endif}STDMETHODIMP_(ULONG32)BaseHandler::PluginMountPoint::AddRef(){ return InterlockedIncrement(&m_lRefCount);}STDMETHODIMP_(ULONG32)BaseHandler::PluginMountPoint::Release(){ if (InterlockedDecrement(&m_lRefCount) > 0) { return m_lRefCount; } delete this; return 0;}/////////////////////////////////////////////////////////////////////////////////// BaseHandler::CheckDirectory/////////////////////////////////////////////////////////////////////////////////BaseHandler::Errors BaseHandler::Stat(const char* pszFilename, struct stat* pStatBuffer){ CHXString strFileName; memset(pStatBuffer,0,sizeof(*pStatBuffer));#if !defined(_STATICALLY_LINKED) if(stat(pszFilename, pStatBuffer) < 0) return CANT_OPEN_DLL;#endif pStatBuffer->st_atime = 0; return NO_ERRORS ;}IHXBuffer* BaseHandler::ConvertToAsciiString(char* pBuffer, UINT32 nBuffLen){ char* pszOut = new char[nBuffLen*2+1]; char* pszStartOut = pszOut; char Nibble; IHXBuffer* pOutBuffer = new CHXBuffer(); // This is the ONLY place where this is done! pOutBuffer->AddRef(); for (int i = 0; i<(int)nBuffLen; i++) { Nibble = (*pBuffer >> 4) & 15; *pszOut= (Nibble > 9 ) ? Nibble+55 : Nibble +48; pszOut++; Nibble = *pBuffer & 15; *pszOut= (Nibble> 9 ) ? Nibble+ 55 : Nibble+48; pszOut++; pBuffer++; } *pszOut = 0; pOutBuffer->Set((UCHAR*)pszStartOut, strlen(pszStartOut)+1); delete[] pszStartOut; return pOutBuffer;}IHXBuffer* BaseHandler::ChecksumFile(char* pszFileName, IHXBuffer* pPathBuffer){ return ConvertToAsciiString("abc", 3);}/********************************************************************** Plugin Enumeration*********************************************************************/BEGIN_INTERFACE_LIST_NOCREATE( CPluginEnumerator ) INTERFACE_LIST_ENTRY_SIMPLE( IHXPluginSearchEnumerator )END_INTERFACE_LISTCPluginEnumerator::CPluginEnumerator() : m_nIndex(0){}CPluginEnumerator::~CPluginEnumerator(){}STDMETHODIMP_( UINT32 )CPluginEnumerator::GetNumPlugins(){ return m_ListOfPlugins.GetCount();}STDMETHODIMP_( void )CPluginEnumerator::GoHead(){ m_nIndex = 0;}STDMETHODIMPCPluginEnumerator::GetNextPlugin( REF(IUnknown*) pIUnkResult, IUnknown* pIUnkOuter ){ // Initialize out params pIUnkResult = NULL; HX_RESULT res = GetPluginAt( m_nIndex, pIUnkResult, pIUnkOuter ); m_nIndex++; return res;}STDMETHODIMPCPluginEnumerator::GetNextPluginInfo( REF(IHXValues*) pRetValues ){ // Initialize out params pRetValues = NULL; HX_RESULT res = GetPluginInfoAt( m_nIndex, pRetValues ); m_nIndex++; return res;}STDMETHODIMPCPluginEnumerator::GetPluginAt( UINT32 index, REF(IUnknown*) pIUnkResult, IUnknown* pIUnkOuter ){ // Initialize out params pIUnkResult = NULL; HX_RESULT res = HXR_FAIL; LISTPOSITION pos = m_ListOfPlugins.FindIndex(index); if (pos) { BaseHandler::Plugin* pPlugin = (BaseHandler::Plugin*) m_ListOfPlugins.GetAt(pos); if (pPlugin) { if (BaseHandler::NO_ERRORS == pPlugin->GetInstance( pIUnkResult, pIUnkOuter )) { res = HXR_OK; } } } return res;}STDMETHODIMPCPluginEnumerator::GetPluginInfoAt( UINT32 index, REF(IHXValues*) pRetValues ){ // Initialize out params pRetValues = NULL; HX_RESULT res = HXR_FAIL; LISTPOSITION pos = m_ListOfPlugins.FindIndex(m_nIndex); m_nIndex++; if (pos) { BaseHandler::Plugin* pPlugin = (BaseHandler::Plugin*) m_ListOfPlugins.GetAt(pos); if (pPlugin) { res = pPlugin->GetPluginInfo( pRetValues ); } } return res;}void CPluginEnumerator::Add(BaseHandler::Plugin* pPlugin){ IHXValues* pPluginValues = NULL; IHXBuffer* pBuffer = NULL; BOOL bAdded = FALSE; if (HXR_OK == pPlugin->GetPluginInfo(pPluginValues) && pPluginValues) { if (HXR_OK == pPluginValues->GetPropertyCString(PLUGIN_DESCRIPTION2, pBuffer) && pBuffer) { if (strstr((const char*)pBuffer->GetBuffer(), "RealNetworks")) { m_ListOfPlugins.AddHead(pPlugin); bAdded = TRUE; } } HX_RELEASE(pBuffer); } if (!bAdded) { m_ListOfPlugins.AddTail(pPlugin); }}HX_RESULT CPluginEnumerator::GetNext(REF(IUnknown*) pRetUnk){ pRetUnk = NULL; return GetNextPlugin( pRetUnk, NULL );}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -