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

📄 plghand2.cpp

📁 symbian 下的helix player源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    Errors retVal = pPlug->GetInstance( pIUnkResult, pIUnkOuter );

    return ( retVal == NO_ERRORS ) ? HXR_OK : HXR_FAIL;
}


STDMETHODIMP
Plugin2Handler::FindPluginUsingStrings( char* PropName1, char* PropVal1,
					char* PropName2, char* PropVal2,
					char* PropName3, char* PropVal3,
					REF(IUnknown*) pIUnkResult,
					IUnknown* pIUnkOuter )
{
    // Initialize out params
    pIUnkResult = NULL;

    // PropName and PropVal have to to valid tuple
    if ((PropName1 && !PropVal1)    ||
	(PropName2 && !PropVal2)    ||
	(PropName3 && !PropVal3)    ||
	(!PropName1 && PropVal1)    ||
	(!PropName2 && PropVal2)    ||
	(!PropName3 && PropVal3))
	return HXR_FAIL;

    IHXValues* pValues;
    HX_RESULT   retVal = HXR_FAIL;

    CHXHeader* pHeader = new CHXHeader();
    pHeader->QueryInterface(IID_IHXValues,  (void**)&pValues);
    AddToValues(pValues, PropName1, PropVal1, eString);
    AddToValues(pValues, PropName2, PropVal2, eString);
    AddToValues(pValues, PropName3, PropVal3, eString);
    retVal = FindPluginUsingValues( pValues, pIUnkResult, pIUnkOuter );
    pValues->Release();
    return retVal;
}


STDMETHODIMP
Plugin2Handler::GetPlugin( ULONG32 ulIndex, REF(IUnknown*) pIUnkResult,
					    IUnknown* pIUnkOuter )
{
    if( ulIndex <= (ULONG32)(m_PluginList.GetCount()-1) && m_PluginList.GetCount() )
    {
	LISTPOSITION pPos = m_PluginList.FindIndex( ulIndex );
	if (pPos)
	{
	    Plugin2Handler::Plugin* pPlugin = (Plugin2Handler::Plugin*) m_PluginList.GetAt( pPos );
	    if( pPlugin )
	    {
		if (NO_ERRORS == pPlugin->GetInstance( pIUnkResult, pIUnkOuter ))
		{
		    return HXR_OK;
		}
		else
		{
		    return HXR_FAIL;
		}
	    }
	}
    }
    return HXR_FAIL;

}



//------------------------------------ IHXPluginDatabase interface methods


STDMETHODIMP
Plugin2Handler::AddPluginIndex( THIS_ const char* pKeyName, EPluginIndexType indexType, BOOL bScanExisting )
{
    HX_LOG_BLOCK( "Plugin2Handler::AddPluginIndex" );

    HX_RESULT result = HXR_FAIL;

    CPluginDatabaseIndex* pNewIndex = CPluginDatabaseIndex::CreateIndex( indexType );
    if( pNewIndex )
    {
	m_dbIndices.SetAt( pKeyName, pNewIndex );

	if( bScanExisting )
	{
	    // XXXND FIX  Scan the existing plugins and add them to this index
	}

	result = HXR_OK;
    }


    return result;
}


STDMETHODIMP
Plugin2Handler::RemovePluginIndex( THIS_ const char* pKeyName )
{
    HX_RESULT result = HXR_UNEXPECTED;

    CPluginDatabaseIndex* pIndex = FindDBIndex( pKeyName );
    if( pIndex )
    {
	if( !m_dbIndices.RemoveKey( pKeyName ) )
	{
	    result = HXR_FAIL;
	}
	else
	{
	    HX_DELETE( pIndex );
	    result = HXR_OK;
	}
    }

    return result;
}


STDMETHODIMP
Plugin2Handler::FindPluginInfoViaIndex( THIS_ const char* pKeyName, const void* pValue, IHXValues** ppIInfo )
{
    HX_RESULT result = HXR_INVALID_PARAMETER;

    if( ppIInfo )
    {
	result = HXR_FAIL;
	*ppIInfo = NULL;

	CPluginDatabaseIndex* pIndex = FindDBIndex( pKeyName );
	if( pIndex )
	{
	    IUnknown* pIUnk = NULL;
	    if( SUCCEEDED( pIndex->FindItem( pValue, &pIUnk ) ) )
	    {
		Plugin2Handler::Plugin* pPlugin = (Plugin2Handler::Plugin*) pIUnk;
		if( SUCCEEDED( result = pPlugin->GetPluginInfo( *ppIInfo ) ) )
		{
		    // Since GetPluginInfo() doesn't addref, we have to here.
		    (*ppIInfo)->AddRef();
		}

		HX_RELEASE( pIUnk );
	    }
	}
    }

    return result;
}


STDMETHODIMP
Plugin2Handler::FindPluginSetViaIndex( THIS_ const char* pKeyName, const void* pValue, IHXPluginSearchEnumerator** ppIEnumerator )
{
    // XXXND  Implement this
    *ppIEnumerator = NULL;
    return HXR_NOTIMPL;
}


STDMETHODIMP
Plugin2Handler::CreatePluginViaIndex( THIS_ const char* pKeyName, const void* pValue, IUnknown** ppIUnkPlugin, IUnknown* pIUnkOuter )
{
    HX_RESULT result = HXR_INVALID_PARAMETER;

    if( ppIUnkPlugin )
    {
	result = HXR_FAIL;
	*ppIUnkPlugin = NULL;

	CPluginDatabaseIndex* pIndex = FindDBIndex( pKeyName );
	if( pIndex )
	{
	    IUnknown* pIUnk = NULL;
	    if( SUCCEEDED( pIndex->FindItem( pValue, &pIUnk ) ) )
	    {
		Plugin2Handler::Plugin* pPlugin = (Plugin2Handler::Plugin*) pIUnk;
		if( NO_ERRORS == pPlugin->GetInstance( *ppIUnkPlugin, pIUnkOuter ) )
		{
		    result = HXR_OK;
		}

		HX_RELEASE( pIUnk );
	    }
	}
    }

    return result;
}

STDMETHODIMP
Plugin2Handler::UnloadPluginFromClassID(REFGUID GUIDClassID)
{
    HX_RESULT res = HXR_FAIL;

    CPluginDatabaseIndex* pIndex = FindDBIndex( PLUGIN_COMPONENT_CLSID );
    if( pIndex )
    {
	IUnknown* pIUnk = NULL;
	if( SUCCEEDED( pIndex->FindItem( &GUIDClassID, &pIUnk ) ) )
	{
	    Plugin2Handler::Plugin* pPlugin = (Plugin2Handler::Plugin*) pIUnk;
	    if(pPlugin->GetDLL())
	    {
		res = pPlugin->GetDLL()->Unload();
	    }
	    HX_RELEASE( pIUnk );
	}
    }

    return res;
}

STDMETHODIMP
Plugin2Handler::UnloadPackageByName(const char* pName)
{
    if (!pName)
	return HXR_INVALID_PARAMETER;

    for (CHXSimpleList::Iterator i = m_PluginDLLList.Begin(); i != m_PluginDLLList.End(); ++i)
    {
	PluginDLL* pPluginDLL = (PluginDLL*) *i;
	if (pPluginDLL->GetPackageName() == pName)
	{
	    return pPluginDLL->Unload(FALSE);
	}
    }

    return HXR_FAIL;
}


//------------------------------------ Class Methods


HX_RESULT Plugin2Handler::FindImplementationFromClassIDInternal(
					    REFGUID GUIDClassID,
					    REF(IUnknown*) pIUnknownInstance,
					    IUnknown* pContext )
{
    // Initialize out params
    pIUnknownInstance = NULL;

    HX_RESULT HX_RESULTThis = HXR_OK;
    UINT32 ulNumClassFactories = 0;
    UINT32 ulCurrentClassFactory = 0;
    UINT32 ulCurrentClassFactoryIndex = 0;
    IUnknown* pIUnknownClassFactoryCurrent = NULL;
    IHXCommonClassFactory* pIHXCommonClassFactoryCurrent = NULL;
    IHXPlugin* pIHXPluginCurrent = NULL;
    IHXObjectConfiguration* pIHXObjectConfigurationCurrent = NULL;

   AddSupportedIID(IID_IHXCommonClassFactory);

    HX_RESULTThis = GetNumPluginsSupporting( IID_IHXCommonClassFactory, ulNumClassFactories );

    if( SUCCEEDED(HX_RESULTThis) && ulNumClassFactories > 0 )
    {
	for( ulCurrentClassFactory = 0, ulCurrentClassFactoryIndex = 0;
		ulCurrentClassFactoryIndex < ulNumClassFactories; ++ulCurrentClassFactoryIndex )
	{
	    HX_RESULTThis = GetPluginIndexSupportingIID( IID_IHXCommonClassFactory,
							    ulCurrentClassFactoryIndex,
							    ulCurrentClassFactory );

	    // Create an instance of the plugin at the index ulCurrentClassFactory
	    if( SUCCEEDED(HX_RESULTThis) )
	    {
		HX_RESULTThis = GetInstance( ulCurrentClassFactory, pIUnknownClassFactoryCurrent );
	    }

	    // If we got a plugin, see if we can get the correct object from it.
	    if( SUCCEEDED(HX_RESULTThis) && pIUnknownClassFactoryCurrent )
	    {
		// Initialize the plugin either through IHXPlugin or IHXObjectConfiguration
		if( SUCCEEDED( pIUnknownClassFactoryCurrent->QueryInterface( IID_IHXPlugin,
									    (void**)&pIHXPluginCurrent ) )
									    && pIHXPluginCurrent )
		{
		    pIHXPluginCurrent->InitPlugin( pContext );
		}
		HX_RELEASE(pIHXPluginCurrent);

		if( SUCCEEDED( pIUnknownClassFactoryCurrent->QueryInterface( IID_IHXObjectConfiguration,
									    (void**)&pIHXObjectConfigurationCurrent ) )
									    && pIHXObjectConfigurationCurrent )
		{
		    pIHXObjectConfigurationCurrent->SetContext( pContext );
		}
		HX_RELEASE(pIHXObjectConfigurationCurrent);


		// Now that it's initialized, get the IHXCommonClassFactory interface
		HX_RESULTThis = pIUnknownClassFactoryCurrent->QueryInterface( IID_IHXCommonClassFactory,
									    (void**)&pIHXCommonClassFactoryCurrent );
	    }

	    HX_RELEASE(pIUnknownClassFactoryCurrent);


	    // We have IHXCommonClassFactory on an intialized plugin.
	    // See if it can create the object we want
	    if( SUCCEEDED(HX_RESULTThis) && pIHXCommonClassFactoryCurrent )
	    {
		HX_RESULTThis = pIHXCommonClassFactoryCurrent->CreateInstance( GUIDClassID, (void **)&pIUnknownInstance );
	    }

	    HX_RELEASE(pIHXCommonClassFactoryCurrent);

	    // Check to see if CreateInstance succeeded.  If so, this is the plugin we want
	    if( SUCCEEDED(HX_RESULTThis) && pIUnknownInstance )
	    {
		// got It!
		break;
	    }

	    // If CreateInstance allocated something, but returned a failure code, clean up
	    HX_RELEASE(pIUnknownInstance);
	}
    }
    else
    {
	// there are no Class factories.
	HX_RESULTThis = HXR_FAIL;
    }

    return HX_RESULTThis;
}




HX_RESULT Plugin2Handler::RefreshPluginInfo( PluginMountPoint* pMountPoint )
{
    HX_LOG_BLOCK( "Plugin2Handler::RefreshPluginInfo" );

    HX_RESULT result = HXR_FAIL;

    IHXPreferences* pIPrefs = pMountPoint->Prefs();

    if( pIPrefs )
    {
	if( zm_bFasterPrefs )
	{
	    result = ReadPluginInfoFast( pMountPoint );
	}
	else
	{
	    result = ReadPluginInfoSlow( pMountPoint );
	}
    }

    if (FAILED (result))
    {
	result = ClearMountPoint_ (pMountPoint);
    }

    if( !pIPrefs || SUCCEEDED( result ) )
	result = ReloadPluginsNoPropagate( pMountPoint );

    HX_RELEASE( pIPrefs );

    return result;
}

HX_RESULT Plugin2Handler::ClearMountPoint_ (PluginMountPoint* pMountPoint)
{
    HX_LOG_BLOCK( "Plugin2Handler::ClearMountPoint_" );

    IHXPreferences* pIPrefs = pMountPoint->Prefs();
    REQUIRE_RETURN_QUIET (pIPrefs, HXR_FAIL);

    IHXPreferences3* pIPrefs3 = NULL;
    if (FAILED (pIPrefs->QueryInterface(IID_IHXPreferences3, (void**)&pIPrefs3)))
    {
	HX_RELEASE (pIPrefs);
	return HXR_FAIL;
    }

    char szRegKey[255]; /* Flawfinder: ignore */

    // delete file info
    SafeStrCpy(szRegKey,  PLUGIN_REGKEY_ROOT, 255);
    SafeStrCat(szRegKey,  zm_pszRegKeySeperator, 255);
    SafeStrCat(szRegKey,  PLUGIN_FILENAMES, 255);

    DeleteHugePref_ (pIPrefs, pIPrefs3, szRegKey);

    // delete plugin info
    SafeStrCpy(szRegKey,  PLUGIN_REGKEY_ROOT, 255);
    SafeStrCat(szRegKey,  zm_pszRegKeySeperator, 255);
    SafeStrCat(szRegKey,  PLUGIN_PLUGININFO, 255);

    DeleteHugePref_ (pIPrefs, pIPrefs3, szRegKey);

    // delete guid info
    SafeStrCpy(szRegKey,  PLUGIN_REGKEY_ROOT, 255);
    SafeStrCat(szRegKey,  zm_pszRegKeySeperator, 255);
    SafeStrCat(szRegKey,  PLUGIN_GUIDINFO, 255);

    DeleteHugePref_ (pIPrefs, pIPrefs3, szRegKey);

    // delete non RMA plugin info
    SafeStrCpy(szRegKey,  PLUGIN_REGKEY_ROOT, 255);
    SafeStrCat(szRegKey,  zm_pszRegKeySeperator, 255);
    SafeStrCat(szRegKey,  PLUGIN_NONHXINFO, 255);

    DeleteHugePref_ (pIPrefs, pIPrefs3, szRegKey);

    HX_RELEASE (pIPrefs);
    HX_RELEASE (pIPrefs3);

    return HXR_OK;
}

void Plugin2Handler::DeleteHugePref_ (IHXPreferences* pIPrefs, IHXPreferences3* pIPrefs3, const char* pszKeyName)
{
    HX_LOG_BLOCK( "Plugin2Handler::DeleteHugePref_" );

    char szNewKeyName [1024]; /* Flawfinder: ignore */
    char szNumber [16]; /* Flawfinder: ignore */
    IHXBuffer* pIBuffer = NULL;

    for (int i = 0; ; ++i)
    {
	SafeStrCpy(szNewKeyName,  pszKeyName, 1024);
	sprintf (szNumber, "%d", i); /* Flawfinder: ignore */
	SafeStrCat(szNewKeyName,  szNumber, 1024);

        // unfortunately delete pref doesn't give us the return value we want so we will read the prefs for now to
	// determine if they are there.
	if (FAILED (pIPrefs->ReadPref (szNewKeyName, pIBuffer))) break;

        LogRegistryRegeneration_ (szNewKeyName, pIBuffer);

	HX_RELEASE (pIBuffer);
	pIPrefs3->DeletePref (szNewKeyName);
    }
}

HX_RESULT Plugin2Handler::WritePluginInfo( PluginMountPoint* pMountPoint )
{
    HX_LOG_BLOCK( "Plugin2Handler::WritePluginInfo" );

    HX_RESULT result = HXR_FAIL;

⌨️ 快捷键说明

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