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

📄 basehand.cpp

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

#include "hxtypes.h"

#ifdef _WINDOWS
#if defined(_WINCE)
#include <stdlib.h>
#define itoa _itoa
#endif
#include <windows.h>
#include <ctype.h>
#endif
#ifdef _MACINTOSH
#include <ctype.h>
#include "filespec.h"
#include "filespecutils.h"
#endif

#if defined _UNIX
#include <stdlib.h>
#include <sys/param.h>
#define _MAX_PATH	MAXPATHLEN
#elif defined (__MWERKS__)
#include <stdlib.h>
#include "fullpathname.h"
#include "chxdataf.h"
#include <stat.h>
#include <fcntl.h>
#else
#include "hlxclib/sys/stat.h"
#endif

#include "hlxclib/stdio.h"

#include "hxresult.h"
#include "hxassert.h"
#include "hxcom.h"
#include "ihxpckts.h"
#include "hxfiles.h"
#include "hxformt.h"
#include "hxfwrtr.h"
#include "hxrendr.h"
#include "hxprefs.h"
#include "hxplugn.h"
#include "hxdtcvt.h"
#include "hxphand.h"
#include "hxmeta.h"
#include "hxsdesc.h"
#include "hxauth.h"
#include "hxallow.h"
#include "hxerror.h"
#include "hxcomm.h"
#include "hxengin.h"
#include "hxshtdn.h"
#include "hxplgns.h"
#include "hxmon.h"
#include "chxpckts.h"
#include "hxstring.h"
#include "hxslist.h"
#include "hxmap.h"
#include "hxstrutl.h"
#include "hxdir.h"
#include "findfile.h"
#include "dbcs.h"
#include "hxbdwdth.h"
#include "basehand.h"
#include "chxuuid.h"
#include "md5.h"

#include "dllacces.h"
#include "dllpath.h"

#include "hxperf.h"
#include "rtsputil.h"

#include "hxver.h"

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

#ifdef _WINCE
#include <wincestr.h>
#endif

#if defined(_STATICALLY_LINKED)
#include "staticff.h"
#endif

/*
 * XXXND These are also defined in geminc/gemplatformdata.h
 */

#define NAMESPACE_SEPARATOR ':'

/*
 *  Win98 does not allow reg keys that are larger than 16k a pop. we used this value to break up into more manageable bites
 */

#define PREF_CACHE_SIZE 10000

/*
    Load each plug-in, read info, store in memory and update prefs
    This is only done if the plugin hash within the registery is not the same
    as the plugin hash of the plugins directory.
*/

const char* const BaseHandler::zm_pszValueSeperator = "|";
const char* const BaseHandler::zm_pszListStart	= "{";
const char* const BaseHandler::zm_pszListEnd	= "}";
const char* const BaseHandler::zm_pszValueSeperator2= ",";

const char* const BaseHandler::zm_pszKeyNameRegKey = "~KeyNames~";
const char* const BaseHandler::zm_pszRegKeySeperator = "\\";

const char* const BaseHandler::zm_pszFileExtension = OS_DLL_PATTERN_STRING;
const char* const BaseHandler::zm_pszDirectorySeperator = OS_SEPARATOR_STRING;
const char BaseHandler::zm_cDirectorySeperator = OS_SEPARATOR_CHAR;

IMPLEMENT_COM_CREATE_FUNCS( BaseHandler )

BEGIN_INTERFACE_LIST_NOCREATE( BaseHandler )
    INTERFACE_LIST_ENTRY_SIMPLE( IHXPluginEnumerator )
    INTERFACE_LIST_ENTRY_SIMPLE( IHXPlugin2Handler )
    INTERFACE_LIST_ENTRY_SIMPLE( IHXPluginHandler3 )
END_INTERFACE_LIST

BaseHandler::BaseHandler() :
    	    m_pContext(NULL)
{
}

BaseHandler::~BaseHandler()
{
    // Make sure Close() got called
    if( m_pContext )
    {
	Close();
    }
}

STDMETHODIMP BaseHandler::Init(IUnknown* pContext)
{
    HX_RESULT result = HXR_FAIL;

    if( SUCCEEDED( result = RegisterContext( pContext ) ) )
    {
	result = ReadFromRegistry();
    }

    return result;
}


STDMETHODIMP_(ULONG32) BaseHandler::GetNumOfPlugins2()
{
    return m_PluginList.GetCount();
}


STDMETHODIMP
BaseHandler::GetPluginInfo(UINT32 unIndex,
			   REF(IHXValues*) /*OUT*/ pValues)
{
    return HXR_NOTIMPL;
}

BaseHandler::Errors
BaseHandler::LoadDLL(char* pszDllName,
		     PluginMountPoint* pMountPoint )
{
    Errors			result	    = NO_ERRORS;
    UINT32			i	    = 0;
    struct stat			stat_stuct;

    // Make sure there is no path in the pszDllName
    HX_ASSERT( !strrchr(pszDllName, BaseHandler::zm_cDirectorySeperator) );

    BaseHandler::PluginDLL* pPluginDll  = NULL;
    if( !( pPluginDll = new BaseHandler::PluginDLL( pszDllName, pMountPoint, this ) ) )
    {
	return MEMORY_ERROR;
    }

    pPluginDll->AddRef();

    CHXString sFileWithPath = pszDllName;
    if (NO_ERRORS==Stat(sFileWithPath, &stat_stuct))
    {
        pPluginDll->SetFileSize((INT32)stat_stuct.st_size);
    }

    result = pPluginDll->Load(m_pContext);
    if (NO_ERRORS != result )
    {
	goto cleanup;
    }

    for(i=0;i<pPluginDll->GetNumPlugins();i++)
    {
	Plugin*	pPlugin	= NULL;

    	// create a new plugin object
	if (!(pPlugin = new Plugin(m_pContext)))
	{
	    return MEMORY_ERROR;
	}

	// Setup plugin information
	pPlugin->AddRef();
	pPlugin->SetDLL(pPluginDll);
	pPlugin->SetIndex((UINT16)i);
	pPlugin->SetInfoNeedsRefresh(TRUE);

	IUnknown* pUnk = NULL;
	if( NO_ERRORS != pPlugin->GetPlugin( pUnk ) )
	{
	    // This plugin doesn't work.  Delete it.
	    HX_RELEASE( pPlugin );
	}
	else
	{
	    IHXPluginNamespace* pPluginNamespace = NULL;
	    if (SUCCEEDED(pUnk->QueryInterface(IID_IHXPluginNamespace, (void**) &pPluginNamespace)))
	    {
		/*
		 * Memory for the IHXBuffer is allocated in the plugin
		 */
		IHXBuffer* pBuffer = NULL;
		if (SUCCEEDED(pPluginNamespace->GetPluginNamespace(pBuffer)))
		{
		    pPluginDll->SetNamespace(pBuffer);
		    HX_RELEASE(pBuffer);
		}
		HX_RELEASE(pPluginNamespace);
	    }

	    IHXComponentPlugin* pIIterator = NULL;
	    if( SUCCEEDED( pUnk->QueryInterface( IID_IHXComponentPlugin, (void**) &pIIterator ) ) )
	    {
		// We don't need this.
		HX_RELEASE( pPlugin );

		LoadPluginsFromComponentDLL( pPluginDll, pIIterator );
		HX_RELEASE( pIIterator );
	    }
	    else
	    {
		IHXPlugin* pIHXPlugin;
		if( SUCCEEDED( pUnk->QueryInterface(IID_IHXPlugin, (void**)&pIHXPlugin ) ) )
		{
		    pPlugin->GetValuesFromDLL(pIHXPlugin);
		    m_PluginList.AddTail(pPlugin);
		    pIHXPlugin->Release();
		}
	    }
	}
	HX_RELEASE( pUnk );
    }

cleanup:

    HX_RELEASE( pPluginDll );

    return result;
}


void BaseHandler::LoadPluginsFromComponentDLL( BaseHandler::PluginDLL* pPluginDll,
						    IHXComponentPlugin* pIIterator )
{
    IHXPlugin* pIHXPlugin = NULL;
    if( SUCCEEDED( pIIterator->QueryInterface(IID_IHXPlugin, (void**)&pIHXPlugin ) ) )
    {
	for( UINT32 index = 0; index < pIIterator->GetNumComponents(); index++ )
	{
	    IHXValues* pIValues = NULL;
	    if( SUCCEEDED( pIIterator->GetComponentInfoAtIndex( index, pIValues ) ) )
	    {
		IHXBuffer* pBuffer = NULL;

		if (SUCCEEDED(pIValues->GetPropertyCString(PLUGIN_COMPONENT_NAME, pBuffer)))
		{
		    IHXBuffer* pNamespace = pPluginDll->GetNamespace();

		    if (pNamespace)
		    {
			CHXString TempNamespace = pNamespace->GetBuffer();
			TempNamespace += NAMESPACE_SEPARATOR;
			TempNamespace += pBuffer->GetBuffer();

			IHXBuffer* pTempBuffer = new CHXBuffer();
			pTempBuffer->AddRef();
			pTempBuffer->Set((BYTE*)(const char*)TempNamespace, TempNamespace.GetLength()+1);
			pIValues->SetPropertyCString(PLUGIN_COMPONENT_NAME, pTempBuffer);
			HX_RELEASE(pTempBuffer);
			HX_RELEASE(pNamespace);
		    }

		    HX_RELEASE(pBuffer);
		}

		// create a new plugin object
		Plugin* pPlugin = new Plugin( m_pContext );
		HX_ASSERT( pPlugin );

		// Setup plugin object
		pPlugin->AddRef();
		pPlugin->SetDLL( pPluginDll );

		pPlugin->SetInfoNeedsRefresh( TRUE );

		pPlugin->InitializeComponentPlugin( pIHXPlugin, pIValues );

		// Put in plugin list
		m_PluginList.AddTail(pPlugin);

		HX_RELEASE( pIValues );
	    }
	}

	HX_RELEASE (pIHXPlugin);
    }
}

///////////////////////////////////////////////////////////////////////////////
//  These functions will find all plugins which are different
//  then those loaded into the registry.
//  It will then load them into memory, get their data, and unload them.
//  It will return HXR_FAIL if some DLL has different values within the
//  registry, and is presently in memory (how could this happen??)

//  If anyone was keeping an index to a loaded DLL and assuming that it
//  would remain constant ... that's not going to work!!!

HX_RESULT BaseHandler::ReloadPluginsNoPropagate()
{
    HX_LOG_BLOCK( "BaseHandler::ReloadPluginsNoPropagate" );

    HX_RESULT result = HXR_OK;

    // Reload them all.
    for(CHXMapStringToOb::Iterator mp = m_MountPoints.Begin(); mp!=m_MountPoints.End(); ++mp)
    {
	PluginMountPoint* pMountPoint = (PluginMountPoint*) *mp;
	if( FAILED( ReloadPluginsNoPropagate( pMountPoint ) ) )
	{
	    result = HXR_FAIL;
	}
    }

    return result;
}


HX_RESULT BaseHandler::ReloadPluginsNoPropagateWithFindFile(
               PluginMountPoint* pMountPoint, CFindFile* pFileFinder,
               IHXBuffer* pPathBuffer, char* pszPluginDir)
{
    HX_LOG_BLOCK( "BaseHandler::ReloadPluginsNoPropagateWithFindFile" );
    char*	    pszDllName	    = 0;
    IHXBuffer*	    pNewChecksum    = 0;

    // if we have no context do not proceed.
    if (!m_pContext)
    {
	return INVALID_CONTEXT;
    }

    // If this is the 1st time, load everything into the registry.

    pszDllName = pFileFinder->FindFirst();

    while (pszDllName)
    {
	BaseHandler::Errors loadResult;
	loadResult = LoadDLL( pszDllName, pMountPoint );

	if (loadResult!= NO_ERRORS)
	{
	    // The DLL had one of the following problems:
	    // (1) the DLL was unloadable
	    // (2) the DLL did not have an HXCreateInstance
	    // (3) an instance could not be created.
	    // (4) It did not implement the PLUGIN interface

	    // if it was case 2,3,4 then we can safely never attempt to
	    // load the DLL again. However if it was (1) then we must attempt
	    // to load the DLL ever time through since it was possibly unloadable due
	    // to an imp-lib that will be satisfied lated (without modifing the
	    // dll). Jeeze. That comment is UNREADABLE. I have to take effective written
	    // english again!

	    if (loadResult!=CANT_OPEN_DLL)
	    {
		BaseHandler::OtherDLL* pDLLData = new BaseHandler::OtherDLL;
		pDLLData->m_filename = pszDllName;
		pDLLData->m_pMountPoint = pMountPoint;

		pNewChecksum = ChecksumFile(pszDllName, pPathBuffer);
		if (pNewChecksum)
		{
		    pDLLData->m_fileChecksum = (char*)pNewChecksum->GetBuffer();
		    HX_RELEASE(pNewChecksum);
		    m_MiscDLLList.AddTail(pDLLData);
		}
		else
		{
		    HX_DELETE(pDLLData);
		}
	    }
	}

	pszDllName = pFileFinder->FindNext();
    }

    return HXR_OK;
}

HX_RESULT BaseHandler::ReloadPluginsNoPropagate( PluginMountPoint* pMountPoint )
{
    CFindFile*	pFileFinder = NULL;
    IHXBuffer*	pPathBuffer = NULL;
    char*	pszPluginDir = NULL;
    ULONG32	nPluginDirLen = NULL;

    if (!m_pContext)
    {
        return INVALID_CONTEXT;
    }

    HX_RESULT retVal = HXR_FAIL;

#if !defined(_STATICALLY_LINKED) || defined(HELIX_CONFIG_CONSOLIDATED_CORE)
    pPathBuffer = pMountPoint->Path();
    if (pPathBuffer)
    {
        pPathBuffer->Get((UCHAR*&)pszPluginDir, nPluginDirLen);

        if (nPluginDirLen)
        {
            pFileFinder = CFindFile::CreateFindFile(pszPluginDir,
                        0, BaseHandler::zm_pszFileExtension);
            if (pFileFinder)
            {
                retVal = ReloadPluginsNoPropagateWithFindFile(pMountPoint,
                        pFileFinder, pPathBuffer, pszPluginDir);

                HX_DELETE(pFileFinder);
            }
        }
    }
#endif

#if defined(_STATICALLY_LINKED)
	pszPluginDir="";
        pFileFinder = CStaticFindFile::CreateFindFile(pszPluginDir,
                0, BaseHandler::zm_pszFileExtension);
        if (pFileFinder)
        {
            retVal = ReloadPluginsNoPropagateWithFindFile(pMountPoint,
                    pFileFinder, pPathBuffer, pszPluginDir);

            HX_DELETE(pFileFinder);
        }
#endif

⌨️ 快捷键说明

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