hxplugin.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 755 行 · 第 1/2 页

CPP
755
字号
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: hxplugin.cpp,v 1.1.2.1 2004/07/09 02:07:27 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 ***** */

#include "hxtypes.h"
#include "hxresult.h"
#include "hxassert.h"
#include "hxcom.h"
#include "hxcomm.h"
#include "hxstring.h"
#include "hxccf.h"    // IHXCommonClassFactory
#include "ihxpckts.h" // IHXBuffer
#include "hxplugn.h" //IHXComponentPlugin
#include "hxformt.h" //IHXFileFormatObject
#include "hxfwrtr.h" //IHXFileWriter
#include "hxfiles.h" //IHXFileSystemObject
#include "hxrendr.h" //IHXRenderer
#include "hxdtcvt.h" //IHXDataRevert
#include "hxsdesc.h" //IHXStreamDescription
#include "hxplgns.h" //IHXPluginProperties
#include "hxmeta1.h" //IHXMetaFileFormatObject
#include "chxpckts.h" //CHXHeader
#include "hxpluginarchive.h"

#include "hxstrutl.h" //SafeStrCat

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

#include "debug.h"

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

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

#include "hxplugindll.h"
#include "hxplugin.h"

BEGIN_INTERFACE_LIST_NOCREATE(HXPlugin)
END_INTERFACE_LIST

const char* const k_pszValueSeperator = "|";

HXPlugin::HXPlugin(IUnknown* pContext)
: m_pValues(0)
, m_pDll(0)
, m_pContext(pContext)
, m_idxPlugin(0)
, m_pClassFactory(NULL)
{
    HX_ASSERT(m_pContext);
    m_pContext->AddRef();
    m_pContext->QueryInterface(IID_IHXCommonClassFactory, (void**)&m_pClassFactory);
    HX_ASSERT(m_pClassFactory);
    m_pClassFactory->CreateInstance(CLSID_IHXValues,(void**)&m_pValues);
}

// deserializing constructor
HXPlugin::HXPlugin(IUnknown* pContext, HXPluginArchiveReader& ar)
: m_pValues(0)
, m_pDll(0)
, m_pContext(pContext)
, m_idxPlugin(0)
, m_pClassFactory(NULL)
{
    m_pContext->AddRef();
    m_pContext->QueryInterface(IID_IHXCommonClassFactory, (void**)&m_pClassFactory);

    ar.Read(m_pValues);
}

// serialize object
void HXPlugin::Archive(HXPluginArchiveWriter& ar)
{
    ar.Write(m_pValues);
}


HXPlugin::~HXPlugin()
{
    HX_RELEASE(m_pValues);
    //HX_RELEASE(m_pDll); weak ref
    HX_RELEASE(m_pClassFactory);
    HX_RELEASE(m_pContext);
}

void HXPlugin::SetPluginProperty(const char* pszPluginType)
{
    DPRINTF(D_INFO, ("HXPlugin()::SetPluginProperty(): type = %s\n", pszPluginType));
    IHXBuffer* pBuffer = NULL;
    m_pClassFactory->CreateInstance(CLSID_IHXBuffer,(void**)&pBuffer);
    HX_ASSERT(pBuffer);
    pBuffer->Set((UCHAR*)pszPluginType, strlen(pszPluginType)+1);
    m_pValues->SetPropertyCString(PLUGIN_CLASS, pBuffer);
    pBuffer->Release();
}


BOOL HXPlugin::DoesMatch(IHXValues* pValues)
{
    CHXSimpleList   PossibleValues1;
    CHXSimpleList   PossibleValues2;
    const char*	    pPropName = NULL;
    ULONG32	    nInValue;
    ULONG32	    nOutValue;
    IHXBuffer*	    pInBuffer = NULL;
    IHXBuffer*	    pOutBuffer = NULL;

    // Check ULONGS 1st
    if (HXR_OK == pValues->GetFirstPropertyULONG32(pPropName, nInValue))
    {
	if (HXR_OK==m_pValues->GetPropertyULONG32(pPropName, nOutValue))
	{
	    if (nInValue != nOutValue)
	    {
		goto notFoundexit;
	    }
	}
	else
	{
	    goto notFoundexit;
	}
	while (HXR_OK == pValues->GetNextPropertyULONG32(pPropName, nInValue))
	{
	    if (HXR_OK == m_pValues->GetPropertyULONG32(pPropName, nOutValue))
	    {
		if (nInValue != nOutValue)
		{
		    goto notFoundexit;
		}
	    }
	    else
	    {
		goto notFoundexit;
	    }
	}
    }


    // Check String Props.
    if (HXR_OK == pValues->GetFirstPropertyCString(pPropName, pInBuffer))
    {
	if (HXR_OK == m_pValues->GetPropertyCString(pPropName, pOutBuffer))
	{
	    if (!AreBufferEqual(pOutBuffer, pInBuffer))
	    {
		goto notFoundexit;
	    }
	}
	else
	{
	    goto notFoundexit;
	}

	HX_RELEASE(pInBuffer);
	HX_RELEASE(pOutBuffer);

	while (HXR_OK == pValues->GetNextPropertyCString(pPropName, pInBuffer))
	{
	    if (HXR_OK == m_pValues->GetPropertyCString(pPropName, pOutBuffer))
	    {
		if ( !AreBufferEqual(pOutBuffer, pInBuffer))
		{
		    goto notFoundexit;
		}
	    }
	    else
	    {
		goto notFoundexit;
	    }

	    HX_RELEASE(pInBuffer);
	    HX_RELEASE(pOutBuffer);
	}
    }


     // Check Buffer Properties
    if (HXR_OK == pValues->GetFirstPropertyBuffer(pPropName, pInBuffer))
    {
	// XXXND  Make some utility functions for doing this...
	if (HXR_OK == m_pValues->GetPropertyBuffer(pPropName, pOutBuffer))
	{
	    if( pOutBuffer->GetSize() == pInBuffer->GetSize() )
	    {
		if( ::memcmp( pOutBuffer->GetBuffer(), pInBuffer->GetBuffer(), pOutBuffer->GetSize() ) )
		{
		    goto notFoundexit;
		}
	    }
	}
	else
	{
	    goto notFoundexit;
	}

	HX_RELEASE(pInBuffer);
	HX_RELEASE(pOutBuffer);

	while (HXR_OK == pValues->GetNextPropertyBuffer(pPropName, pInBuffer))
	{
	    if (HXR_OK == m_pValues->GetPropertyBuffer(pPropName, pOutBuffer))
	    {
		// XXXND  Make some utility functions for doing this...
		if( pOutBuffer->GetSize() == pInBuffer->GetSize() )
		{
		    if( ::memcmp( pOutBuffer->GetBuffer(), pInBuffer->GetBuffer(), pOutBuffer->GetSize() ) )
		    {
			goto notFoundexit;
		    }
		}
	    }
	    else
	    {
		goto notFoundexit;
	    }

	    HX_RELEASE(pInBuffer);
	    HX_RELEASE(pOutBuffer);
	}
    }

    return TRUE;    // we made it!

notFoundexit:
    HX_RELEASE(pInBuffer);
    HX_RELEASE(pOutBuffer);
    return FALSE;
}

HX_RESULT HXPlugin::Init(HXPluginDLL* pDll, UINT16 idxPlugin)
{
    HX_ASSERT(!m_pDll);
    HX_ASSERT(pDll);
    m_pDll = pDll; // weak ref

    m_idxPlugin = idxPlugin;
    m_pValues->SetPropertyULONG32(PLUGIN_INDEX, idxPlugin);
    
    IHXBuffer* pBuff = HXBufferUtil::CreateBuffer(m_pClassFactory, m_pDll->GetFileName());
    m_pValues->SetPropertyCString(PLUGIN_FILENAME, pBuff);
    HX_RELEASE(pBuff);
    
    return HXR_OK;
}


BOOL HXPlugin::AreBufferEqual(IHXBuffer* pBigBuff,
					   IHXBuffer* pSmallBuff)
{
    char*   pTemp;
    BOOL    bRetVal = FALSE;

    pTemp = new char[pBigBuff->GetSize()];
    strcpy(pTemp, (char*)pBigBuff->GetBuffer()); /* Flawfinder: ignore */

    char* token;
    token = strtok(pTemp, k_pszValueSeperator);
    while (token)
    {
	CHXString tokenCHXstring;
	CHXString smallCHXstring;

	tokenCHXstring = token;
	smallCHXstring = (char*)pSmallBuff->GetBuffer();
	tokenCHXstring.TrimLeft();
	tokenCHXstring.TrimRight();
	smallCHXstring.TrimLeft();
	smallCHXstring.TrimRight();

	if (!strcasecmp(tokenCHXstring, smallCHXstring))
	{
	    bRetVal = TRUE;
	    break;
	}
	token = strtok(NULL, k_pszValueSeperator);
    }
    delete[] pTemp;

    return bRetVal;
}

HX_RESULT HXPlugin::GetValuesFromDLL(IHXPlugin* pHXPlugin)
{
    HX_RESULT hr = GetBasicValues(pHXPlugin);
    if(SUCCEEDED(hr))
    {
	hr = GetExtendedValues(pHXPlugin);
    }
    return hr;
}

HX_RESULT HXPlugin::GetPlugin(IUnknown*& pUnknown )
{
    pUnknown = NULL;

    HX_RESULT hr = HXR_FAIL;

    HX_ASSERT(m_pDll);
    if (m_pDll)
    {
        // load DLL if not loaded
        if (!m_pDll->IsLoaded())
        {
	    hr = m_pDll->Load();
        }
        
        if(m_pDll->IsLoaded())
        {
            hr = m_pDll->CreateInstance(&pUnknown, m_idxPlugin);
        }
    }

    return hr;
}

HX_RESULT HXPlugin::GetInstance(IUnknown*& pUnknown, IUnknown* pIUnkOuter )
{
    // Initialize out parameter
    pUnknown = NULL;

    IUnknown* pUnkPlugin = NULL;
    HX_RESULT hr = GetPlugin( pUnkPlugin );
    if( SUCCEEDED(hr) )
    {
        hr = HXR_FAIL;
	IHXComponentPlugin* pComponentPlugin = NULL;

⌨️ 快捷键说明

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