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

📄 plghand2.cpp

📁 linux下的一款播放器
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/* ***** BEGIN LICENSE BLOCK ***** * Source last modified: $Id: plghand2.cpp,v 1.26.8.4 2004/07/09 02:07:28 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 ***** *//**************************************************************************** * * *  Plugin information are stored into the registry in the following format: * *	File Format Plugins: {dllpath;description;copyright;moreinfo;loadmultiple;mimetype1|mimetype2;extension1|extension2}{ ... } *			     --------------------------------------------------------------------------------------------------- *								One Plugin * *	File System Plugins: {dllpath;description;copyright;moreinfo;loadmultiple;protocol;shortname}{ ... } *			     ---------------------------------------------------------------------------- *								One Plugin * *	Renderer Plugins:    {dllpath;description;copyright;moreinfo;loadmultiple;mimetype1|mimetype2}{ ... } *			     ----------------------------------------------------------------------------- *								One Plugin * *	Broadcast Plugins:   {dllpath;description;copyright;moreinfo;loadmultiple;type}{ ... } *			     -------------------------------------------------------------- *								One Plugin * *	Stream Description Plugins: {dllpath;description;copyright;moreinfo;loadmultiple;mimetype}{ ... } *			     ---------------------------------------------------------------------------- *								One Plugin * *	Allowance Plugins:   {dllpath;description;copyright;moreinfo;loadmultiple}{ ... } *                           --------------------------------------------------------- *								One Plugin * *	Misc. Plugins:	     {dllpath;description;copyright;moreinfo;loadmultiple}{ ... } *                           --------------------------------------------------------- *								One Plugin * *	Plugins:	     {dllpath;description;copyright;moreinfo;loadmultiple}{ ... } *                           --------------------------------------------------------- *								One Plugin * */#include "hxtypes.h"#ifdef _WINDOWS#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 (_MACINTOSH)#include <stdlib.h>#include "fullpathname.h"#include "chxdataf.h"#ifdef _MAC_MACHO#include <sys/stat.h>#else#include <stat.h>#endif#include <fcntl.h>#endif#include <stdio.h>#include "hlxclib/sys/stat.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 "plghand2.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_FILEstatic const char HX_THIS_FILE[] = __FILE__;#endif#ifdef _STATICALLY_LINKED#include "staticff.h"#endif#if defined(HELIX_FEATURE_PREFERENCES)#include "hxprefs.h"#include "hxprefutil.h"#endif /* HELIX_FEATURE_PREFERENCES *//* * 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 Plugin2Handler::zm_pszValueSeperator = "|";const char* const Plugin2Handler::zm_pszListStart	= "{";const char* const Plugin2Handler::zm_pszListEnd	= "}";const char* const Plugin2Handler::zm_pszValueSeperator2= ",";const char* const Plugin2Handler::zm_pszKeyNameRegKey = "~KeyNames~";const char* const Plugin2Handler::zm_pszRegKeySeperator = "\\";#if !defined(HELIX_CONFIG_NOSTATICS)BOOL Plugin2Handler::zm_bFasterPrefs = 0;#elseconst BOOL Plugin2Handler::zm_bFasterPrefs = 0;#endifconst char* const Plugin2Handler::zm_pszFileExtension = OS_DLL_PATTERN_STRING;const char* const Plugin2Handler::zm_pszDirectorySeperator = OS_SEPARATOR_STRING;const char Plugin2Handler::zm_cDirectorySeperator = OS_SEPARATOR_CHAR;// XXXHP - temporary changes to track PR70528#ifdef REALPLAYER_PLUGIN_HANDLER_RESEARCH_    inline FILE* OpenErrorLog_ ()    {        static char const* const realPlayerErrorsLog = "rperrors.log";        static char const* const appendMode = "a+";        return fopen (realPlayerErrorsLog, appendMode);    }    inline void LogRegistryRegeneration_ (char const* pKey, IHXBuffer* pIEntry)    {       FILE* const logStream = OpenErrorLog_ ();       PRE_REQUIRE_VOID_RETURN (logStream);       fprintf (logStream, "--------------- INVALID REGISTRY ENTRY: ----------------------------\n");       fprintf (logStream, "Key: %s\n", pKey);       fprintf (logStream, "\tData: [%s]\n", pIEntry->GetBuffer ());       fprintf (logStream, "--------------------------------------------------------------------\n");       fclose (logStream);    }    inline void LogCriticalError_ (char const* pErrorReport)    {       FILE* const logStream = OpenErrorLog_ ();       PRE_REQUIRE_VOID_RETURN (logStream);       fprintf (logStream, "---------------- CRITICAL ERROR ------------------------------------\n");       fprintf (logStream, "%s\n", pErrorReport);       fprintf (logStream, "--------------------------------------------------------------------\n");       fclose (logStream);    }#else    inline void LogRegistryRegeneration_ (char const*, IHXBuffer*)    {    }#endif/******************************************************************************************************Plugin2Handler************************************************************************************************************/IMPLEMENT_COM_CREATE_FUNCS( Plugin2Handler )BEGIN_INTERFACE_LIST_NOCREATE( Plugin2Handler )    INTERFACE_LIST_ENTRY_SIMPLE( IHXCallback )    INTERFACE_LIST_ENTRY_SIMPLE( IHXPluginEnumerator )    INTERFACE_LIST_ENTRY_SIMPLE( IHXPluginReloader )    INTERFACE_LIST_ENTRY_SIMPLE( IHXPlugin2Handler )    INTERFACE_LIST_ENTRY_SIMPLE( IHXPlugin2HandlerEnumeratorInterface )    INTERFACE_LIST_ENTRY_SIMPLE( IHXPluginHandler3 )    INTERFACE_LIST_ENTRY_SIMPLE( IHXPluginDatabase )END_INTERFACE_LISTinline HX_RESULT Plugin2Handler::VerifyChecksum_ (const char* pData){    REQUIRE_RETURN (pData, HXR_INVALID_PARAMETER);    static const char endEntry = '}';    static const int error = -1;    // find the last end-marker of the last entry.    const CHXString data = pData;    const int lastEntry = data.ReverseFind (endEntry);    REQUIRE_RETURN_QUIET (lastEntry != error, HXR_FAIL);    // the checksum should be equal to the position of the end of the last entry plus 1.    const int calculatedChecksum = lastEntry + 1;    // read in the actual checksum.    const CHXString checksumString = pData + calculatedChecksum;    const int actualChecksum = ::atoi (checksumString);    return actualChecksum == calculatedChecksum ? HXR_OK : HXR_FAIL;}Plugin2Handler::Plugin2Handler() :	m_pPluginDir( NULL )    ,	m_pPreferences(NULL)    ,	m_pErrorMessages(NULL)    ,	m_pContext(NULL)    ,	m_nCacheSizeBites( (1<<24) )    ,	m_pIScheduler(NULL)    ,	m_hScheduler( 0 ){}Plugin2Handler::~Plugin2Handler(){    // Make sure Close() got called    if( m_pContext )    {	Close();    }}STDMETHODIMP Plugin2Handler::Init(IUnknown* pContext){    HX_RESULT result = HXR_FAIL;    if( SUCCEEDED( result = RegisterContext( pContext ) ) )    {	result = ReadFromRegistry();    }    return result;}STDMETHODIMP_(ULONG32) Plugin2Handler::GetNumOfPlugins2(){    return m_PluginList.GetCount();}STDMETHODIMP  Plugin2Handler::GetPluginInfo (UINT32 unIndex,				REF(IHXValues*) /*OUT*/ pValues){    HX_RESULT retVal = HXR_FAIL;    LISTPOSITION pPos = m_PluginList.FindIndex(unIndex);    if (pPos)    {	Plugin2Handler::Plugin* pPlugin = (Plugin2Handler::Plugin*) m_PluginList.GetAt(pPos);	if (pPlugin)	{	    retVal = pPlugin->GetPluginInfo(pValues);	    pValues->AddRef();	}    }    return retVal;}// ---------------------------------------------------------- IHXCallback// **********************************************STDMETHODIMPPlugin2Handler::Func( THIS ){    if ( !m_pIScheduler || !m_hScheduler )    {	return( HXR_UNEXPECTED );    }    HX_RESULT outResult = HXR_OK;    // Our timer is infinite.    m_hScheduler = m_pIScheduler->RelativeEnter( this, kPingDuration );    if ( !m_hScheduler )    {	outResult = HXR_FAIL;    }    UnloadDeadDLLs();    return( outResult );}// **********************************************// This function is called periodically when the plugin handler// object is pinged by the scheduler.void Plugin2Handler::UnloadDeadDLLs( void ){    HX_LOG_BLOCK( "Plugin2Handler::UnloadDeadDLLs" );    LISTPOSITION posCanUnload = m_CanUnload2DllList.GetHeadPosition();    while ( posCanUnload )    {	// Save off current position for delete.	LISTPOSITION posAt = posCanUnload;	// Get current item, and increment position.	Plugin2Handler::PluginDLL* pPluginDLLCanUnload = (Plugin2Handler::PluginDLL*) m_CanUnload2DllList.GetNext( posCanUnload );	if ( pPluginDLLCanUnload )	{	    pPluginDLLCanUnload->Unload( TRUE );  // TRUE: "safe" unload	}    }}/*    ReconnectDLL()    This replaces one PluginDLL in m_PluginDLLList with a new instance.    It removes any plugins that refered to the old DLL. */void Plugin2Handler::ReconnectDLL(const char* pszDLLName, Plugin2Handler::PluginDLL* pNewDLL){    HX_LOG_BLOCK( "Plugin2Handler::ReconnectDLL" );    // before we add this to the tail we must check to see if this    // plugin is already within the list....    Plugin2Handler::PluginDLL*	pOldPluginDll	= NULL;    LISTPOSITION		pPos		= NULL;    if (m_FileNameMap.Lookup(pszDLLName, (void*&)pOldPluginDll))    {	pPos = m_PluginDLLList.Find(pOldPluginDll);	if (pPos)	{	    m_PluginDLLList.RemoveAt(pPos);	}	// now see who the heck was connected to this pluginDLL	pPos = m_PluginList.GetHeadPosition();	while( pPos )	{	    // Save off current position for delete	    LISTPOSITION posAt = pPos;	    // Get current item, and increment position	    Plugin2Handler::Plugin* pPlugin = (Plugin2Handler::Plugin*) m_PluginList.GetNext( pPos );	    // If this plugin belongs to the old DLL, remove it.	    if( pPlugin && pPlugin->GetDLL() == pOldPluginDll )	    {		// Delete from the saved position		m_PluginList.RemoveAt( posAt );		HX_RELEASE( pPlugin );	    }	}	HX_RELEASE(pOldPluginDll);    }    m_PluginDLLList.AddTail(pNewDLL);    m_FileNameMap.SetAt(pszDLLName, pNewDLL);}/*    LoadDLL()    This is called during a Refresh() (which is deprecated)    or if we determine that the DLL is dirty and needs to be updated */Plugin2Handler::Errors Plugin2Handler::LoadDLL( char* pszDllName,					PluginMountPoint* pMountPoint ){    Errors			result	    = NO_ERRORS;    UINT32			i	    = 0;    struct stat			stat_stuct;    IHXBuffer*			pPathBuffer = pMountPoint->Path();    // Make sure there is no path in the pszDllName    HX_ASSERT( !strrchr(pszDllName, Plugin2Handler::zm_cDirectorySeperator) );

⌨️ 快捷键说明

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